• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (C) 2008 Torch Mobile Inc. All rights reserved. (http://www.torchmobile.com/)
3  *
4  * This library is free software; you can redistribute it and/or
5  * modify it under the terms of the GNU Library General Public
6  * License as published by the Free Software Foundation; either
7  * version 2 of the License, or (at your option) any later version.
8  *
9  * This library is distributed in the hope that it will be useful,
10  * but WITHOUT ANY WARRANTY; without even the implied warranty of
11  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
12  * Library General Public License for more details.
13  *
14  * You should have received a copy of the GNU Library General Public License
15  * along with this library; see the file COPYING.LIB.  If not, write to
16  * the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
17  * Boston, MA 02110-1301, USA.
18  *
19  */
20 
21 #include "config.h"
22 
23 #if ENABLE(WML)
24 #include "WMLDocument.h"
25 
26 #include "BackForwardController.h"
27 #include "BackForwardList.h"
28 #include "Frame.h"
29 #include "Page.h"
30 #include "ScriptableDocumentParser.h"
31 #include "WMLCardElement.h"
32 #include "WMLErrorHandling.h"
33 #include "WMLPageState.h"
34 #include "WMLTemplateElement.h"
35 
36 namespace WebCore {
37 
WMLDocument(Frame * frame,const KURL & url)38 WMLDocument::WMLDocument(Frame* frame, const KURL& url)
39     : Document(frame, url, false, false)
40     , m_activeCard(0)
41 {
42     clearXMLVersion();
43 }
44 
~WMLDocument()45 WMLDocument::~WMLDocument()
46 {
47 }
48 
finishedParsing()49 void WMLDocument::finishedParsing()
50 {
51     if (ScriptableDocumentParser* parser = this->scriptableDocumentParser()) {
52         if (!parser->wellFormed()) {
53             Document::finishedParsing();
54             return;
55         }
56     }
57 
58     bool hasAccess = initialize(true);
59     Document::finishedParsing();
60 
61     if (!hasAccess) {
62         m_activeCard = 0;
63 
64         WMLPageState* wmlPageState = wmlPageStateForDocument(this);
65         if (!wmlPageState)
66             return;
67 
68         Page* page = wmlPageState->page();
69         if (!page)
70             return;
71 
72         HistoryItem* item = page->backForward()->backItem();
73         if (!item)
74             return;
75 
76         page->goToItem(item, FrameLoadTypeBackWMLDeckNotAccessible);
77         return;
78     }
79 
80     if (m_activeCard)
81         m_activeCard->handleIntrinsicEventIfNeeded();
82 }
83 
initialize(bool aboutToFinishParsing)84 bool WMLDocument::initialize(bool aboutToFinishParsing)
85 {
86     WMLPageState* wmlPageState = wmlPageStateForDocument(this);
87     if (!wmlPageState || !wmlPageState->canAccessDeck())
88         return false;
89 
90     // Remember that we'e successfully entered the deck
91     wmlPageState->resetAccessControlData();
92 
93     // Notify the existance of templates to all cards of the current deck
94     WMLTemplateElement::registerTemplatesInDocument(this);
95 
96     // Set destination card
97     m_activeCard = WMLCardElement::determineActiveCard(this);
98     if (!m_activeCard) {
99         reportWMLError(this, WMLErrorNoCardInDocument);
100         return true;
101     }
102 
103     // Handle deck-level task overrides
104     m_activeCard->handleDeckLevelTaskOverridesIfNeeded();
105 
106     // Handle card-level intrinsic event
107     if (!aboutToFinishParsing)
108         m_activeCard->handleIntrinsicEventIfNeeded();
109 
110     return true;
111 }
112 
wmlPageStateForDocument(Document * doc)113 WMLPageState* wmlPageStateForDocument(Document* doc)
114 {
115     ASSERT(doc);
116 
117     Page* page = doc->page();
118     ASSERT(page);
119 
120     return page->wmlPageState();
121 }
122 
123 }
124 
125 #endif
126