Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(93)

Side by Side Diff: Source/core/html/HTMLImportLoader.cpp

Issue 22573005: [HTML Imports] Implement "load" and "error" events. (Closed) Base URL: svn://svn.chromium.org/blink/trunk
Patch Set: For landing Created 7 years, 4 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
« no previous file with comments | « Source/core/html/HTMLImportLoader.h ('k') | Source/core/html/HTMLImportLoaderClient.h » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 /* 1 /*
2 * Copyright (C) 2013 Google Inc. All rights reserved. 2 * Copyright (C) 2013 Google Inc. All rights reserved.
3 * 3 *
4 * Redistribution and use in source and binary forms, with or without 4 * Redistribution and use in source and binary forms, with or without
5 * modification, are permitted provided that the following conditions are 5 * modification, are permitted provided that the following conditions are
6 * met: 6 * met:
7 * 7 *
8 * * Redistributions of source code must retain the above copyright 8 * * Redistributions of source code must retain the above copyright
9 * notice, this list of conditions and the following disclaimer. 9 * notice, this list of conditions and the following disclaimer.
10 * * Redistributions in binary form must reproduce the above 10 * * Redistributions in binary form must reproduce the above
(...skipping 15 matching lines...) Expand all
26 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 26 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
27 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 27 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
28 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 28 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
29 */ 29 */
30 30
31 #include "config.h" 31 #include "config.h"
32 #include "core/html/HTMLImportLoader.h" 32 #include "core/html/HTMLImportLoader.h"
33 33
34 #include "core/dom/Document.h" 34 #include "core/dom/Document.h"
35 #include "core/html/HTMLDocument.h" 35 #include "core/html/HTMLDocument.h"
36 #include "core/html/HTMLImportLoaderClient.h"
36 #include "core/loader/DocumentWriter.h" 37 #include "core/loader/DocumentWriter.h"
37 #include "core/loader/cache/ResourceFetcher.h" 38 #include "core/loader/cache/ResourceFetcher.h"
38 #include "core/page/ContentSecurityPolicyResponseHeaders.h" 39 #include "core/page/ContentSecurityPolicyResponseHeaders.h"
39 40
40 namespace WebCore { 41 namespace WebCore {
41 42
42 HTMLImportLoader::HTMLImportLoader(HTMLImport* parent, const KURL& url, const Re sourcePtr<CachedRawResource>& resource) 43 HTMLImportLoader::HTMLImportLoader(HTMLImport* parent, const KURL& url, const Re sourcePtr<CachedRawResource>& resource)
43 : m_parent(parent) 44 : m_parent(parent)
44 , m_state(StateLoading) 45 , m_state(StateLoading)
45 , m_resource(resource) 46 , m_resource(resource)
(...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after
78 if (m_state == state) 79 if (m_state == state)
79 return; 80 return;
80 81
81 m_state = state; 82 m_state = state;
82 83
83 if (m_state == StateReady || m_state == StateError || m_state == StateWritte n) { 84 if (m_state == StateReady || m_state == StateError || m_state == StateWritte n) {
84 if (RefPtr<DocumentWriter> writer = m_writer.release()) 85 if (RefPtr<DocumentWriter> writer = m_writer.release())
85 writer->end(); 86 writer->end();
86 } 87 }
87 88
88 if (m_state == StateReady || m_state == StateError) 89 // Since DocumentWriter::end() let setState() reenter, we shouldn't refer to m_state here.
89 dispose(); 90 if (state == StateReady || state == StateError)
91 didFinish();
90 } 92 }
91 93
92 void HTMLImportLoader::dispose() 94 void HTMLImportLoader::didFinish()
93 { 95 {
96 for (size_t i = 0; i < m_clients.size(); ++i)
97 m_clients[i]->didFinish();
98
94 if (m_resource) { 99 if (m_resource) {
95 m_resource->removeClient(this); 100 m_resource->removeClient(this);
96 m_resource = 0; 101 m_resource = 0;
97 } 102 }
98 103
99 ASSERT(!document() || !document()->parsing()); 104 ASSERT(!document() || !document()->parsing());
100 root()->importWasDisposed(); 105 root()->importWasDisposed();
101 } 106 }
102 107
103 HTMLImportLoader::State HTMLImportLoader::startWritingAndParsing(const ResourceR esponse& response) 108 HTMLImportLoader::State HTMLImportLoader::startWritingAndParsing(const ResourceR esponse& response)
(...skipping 28 matching lines...) Expand all
132 return StateReady; 137 return StateReady;
133 } 138 }
134 139
135 Document* HTMLImportLoader::importedDocument() const 140 Document* HTMLImportLoader::importedDocument() const
136 { 141 {
137 if (m_state == StateError) 142 if (m_state == StateError)
138 return 0; 143 return 0;
139 return m_importedDocument.get(); 144 return m_importedDocument.get();
140 } 145 }
141 146
147 void HTMLImportLoader::addClient(HTMLImportLoaderClient* client)
148 {
149 ASSERT(notFound == m_clients.find(client));
150 m_clients.append(client);
151 if (isDone())
152 client->didFinish();
153 }
154
155 void HTMLImportLoader::removeClient(HTMLImportLoaderClient* client)
156 {
157 ASSERT(notFound != m_clients.find(client));
158 m_clients.remove(m_clients.find(client));
159 }
160
142 void HTMLImportLoader::importDestroyed() 161 void HTMLImportLoader::importDestroyed()
143 { 162 {
144 m_parent = 0; 163 m_parent = 0;
145 if (RefPtr<Document> document = m_importedDocument.release()) 164 if (RefPtr<Document> document = m_importedDocument.release())
146 document->setImport(0); 165 document->setImport(0);
147 } 166 }
148 167
149 HTMLImportRoot* HTMLImportLoader::root() 168 HTMLImportRoot* HTMLImportLoader::root()
150 { 169 {
151 return m_parent ? m_parent->root() : 0; 170 return m_parent ? m_parent->root() : 0;
(...skipping 22 matching lines...) Expand all
174 } 193 }
175 194
176 bool HTMLImportLoader::isProcessing() const 195 bool HTMLImportLoader::isProcessing() const
177 { 196 {
178 if (!m_importedDocument) 197 if (!m_importedDocument)
179 return !isDone(); 198 return !isDone();
180 return m_importedDocument->parsing(); 199 return m_importedDocument->parsing();
181 } 200 }
182 201
183 } // namespace WebCore 202 } // namespace WebCore
OLDNEW
« no previous file with comments | « Source/core/html/HTMLImportLoader.h ('k') | Source/core/html/HTMLImportLoaderClient.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698