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