• 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 "Frame.h"
27 #include "Page.h"
28 #include "Tokenizer.h"
29 #include "WMLCardElement.h"
30 #include "WMLErrorHandling.h"
31 #include "WMLPageState.h"
32 #include "WMLTemplateElement.h"
33 
34 namespace WebCore {
35 
WMLDocument(Frame * frame)36 WMLDocument::WMLDocument(Frame* frame)
37     : Document(frame, false)
38     , m_activeCard(0)
39 {
40     clearXMLVersion();
41 }
42 
~WMLDocument()43 WMLDocument::~WMLDocument()
44 {
45 }
46 
finishedParsing()47 void WMLDocument::finishedParsing()
48 {
49     if (Tokenizer* tokenizer = this->tokenizer()) {
50         if (!tokenizer->wellFormed()) {
51             Document::finishedParsing();
52             return;
53         }
54     }
55 
56     bool hasAccess = initialize(true);
57     Document::finishedParsing();
58 
59     if (!hasAccess) {
60         m_activeCard = 0;
61 
62         WMLPageState* wmlPageState = wmlPageStateForDocument(this);
63         if (!wmlPageState)
64             return;
65 
66         Page* page = wmlPageState->page();
67         if (!page)
68             return;
69 
70         BackForwardList* list = page->backForwardList();
71         if (!list)
72             return;
73 
74         HistoryItem* item = list->backItem();
75         if (!item)
76             return;
77 
78         page->goToItem(item, FrameLoadTypeBackWMLDeckNotAccessible);
79         return;
80     }
81 
82     if (m_activeCard) {
83         m_activeCard->handleIntrinsicEventIfNeeded();
84         m_activeCard = 0;
85     }
86 }
87 
initialize(bool aboutToFinishParsing)88 bool WMLDocument::initialize(bool aboutToFinishParsing)
89 {
90     WMLPageState* wmlPageState = wmlPageStateForDocument(this);
91     if (!wmlPageState || !wmlPageState->canAccessDeck())
92         return false;
93 
94     // Remember that we'e successfully entered the deck
95     wmlPageState->resetAccessControlData();
96 
97     // Notify the existance of templates to all cards of the current deck
98     WMLTemplateElement::registerTemplatesInDocument(this);
99 
100     // Set destination card
101     m_activeCard = WMLCardElement::determineActiveCard(this);
102     if (!m_activeCard) {
103         reportWMLError(this, WMLErrorNoCardInDocument);
104         return true;
105     }
106 
107     // Handle deck-level task overrides
108     m_activeCard->handleDeckLevelTaskOverridesIfNeeded();
109 
110     // Handle card-level intrinsic event
111     if (!aboutToFinishParsing)
112         m_activeCard->handleIntrinsicEventIfNeeded();
113 
114     return true;
115 }
116 
wmlPageStateForDocument(Document * doc)117 WMLPageState* wmlPageStateForDocument(Document* doc)
118 {
119     ASSERT(doc);
120 
121     Page* page = doc->page();
122     ASSERT(page);
123 
124     return page->wmlPageState();
125 }
126 
127 }
128 
129 #endif
130