1 /* 2 * Copyright (C) 2010 Google, Inc. All Rights Reserved. 3 * 4 * Redistribution and use in source and binary forms, with or without 5 * modification, are permitted provided that the following conditions 6 * are met: 7 * 1. Redistributions of source code must retain the above copyright 8 * notice, this list of conditions and the following disclaimer. 9 * 2. Redistributions in binary form must reproduce the above copyright 10 * notice, this list of conditions and the following disclaimer in the 11 * documentation and/or other materials provided with the distribution. 12 * 13 * THIS SOFTWARE IS PROVIDED BY APPLE INC. ``AS IS'' AND ANY 14 * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 15 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR 16 * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL APPLE INC. OR 17 * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, 18 * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, 19 * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR 20 * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY 21 * OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 22 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 23 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 24 */ 25 26 #include "config.h" 27 #include "core/dom/DocumentParser.h" 28 29 #include "core/dom/Document.h" 30 #include "core/dom/DocumentParserClient.h" 31 #include "core/html/parser/TextResourceDecoder.h" 32 #include "wtf/Assertions.h" 33 34 namespace blink { 35 36 DocumentParser::DocumentParser(Document* document) 37 : m_state(ParsingState) 38 , m_documentWasLoadedAsPartOfNavigation(false) 39 , m_document(document) 40 { 41 ASSERT(document); 42 } 43 44 DocumentParser::~DocumentParser() 45 { 46 #if !ENABLE(OILPAN) 47 // Document is expected to call detach() before releasing its ref. 48 // This ASSERT is slightly awkward for parsers with a fragment case 49 // as there is no Document to release the ref. 50 ASSERT(!m_document); 51 #endif 52 } 53 54 void DocumentParser::trace(Visitor* visitor) 55 { 56 visitor->trace(m_document); 57 #if ENABLE(OILPAN) 58 visitor->trace(m_clients); 59 #endif 60 } 61 62 void DocumentParser::setDecoder(PassOwnPtr<TextResourceDecoder>) 63 { 64 ASSERT_NOT_REACHED(); 65 } 66 67 TextResourceDecoder* DocumentParser::decoder() 68 { 69 return 0; 70 } 71 72 void DocumentParser::prepareToStopParsing() 73 { 74 ASSERT(m_state == ParsingState); 75 m_state = StoppingState; 76 } 77 78 void DocumentParser::stopParsing() 79 { 80 m_state = StoppedState; 81 82 // Clients may be removed while in the loop. Make a snapshot for iteration. 83 WillBeHeapVector<RawPtrWillBeMember<DocumentParserClient> > clientsSnapshot; 84 copyToVector(m_clients, clientsSnapshot); 85 86 for (WillBeHeapVector<RawPtrWillBeMember<DocumentParserClient> >::const_iterator it = clientsSnapshot.begin(), itEnd = clientsSnapshot.end(); it != itEnd; ++it) { 87 DocumentParserClient* client = *it; 88 if (!m_clients.contains(client)) 89 continue; 90 91 client->notifyParserStopped(); 92 } 93 } 94 95 void DocumentParser::detach() 96 { 97 m_state = DetachedState; 98 m_document = nullptr; 99 } 100 101 void DocumentParser::suspendScheduledTasks() 102 { 103 } 104 105 void DocumentParser::resumeScheduledTasks() 106 { 107 } 108 109 void DocumentParser::addClient(DocumentParserClient* client) 110 { 111 m_clients.add(client); 112 } 113 114 void DocumentParser::removeClient(DocumentParserClient* client) 115 { 116 m_clients.remove(client); 117 } 118 119 }; 120 121