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

Side by Side Diff: Source/core/html/imports/HTMLImportsController.cpp

Issue 301803002: Extract tree root responsibility out of HTMLImportsController. (Closed) Base URL: svn://svn.chromium.org/blink/trunk
Patch Set: Fix compile. Created 6 years, 6 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
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 14 matching lines...) Expand all
25 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 25 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
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/imports/HTMLImportsController.h" 32 #include "core/html/imports/HTMLImportsController.h"
33 33
34 #include "core/dom/Document.h" 34 #include "core/dom/Document.h"
35 #include "core/dom/StyleEngine.h"
36 #include "core/fetch/ResourceFetcher.h" 35 #include "core/fetch/ResourceFetcher.h"
37 #include "core/frame/LocalFrame.h" 36 #include "core/frame/LocalFrame.h"
38 #include "core/html/imports/HTMLImportChild.h" 37 #include "core/html/imports/HTMLImportChild.h"
39 #include "core/html/imports/HTMLImportChildClient.h" 38 #include "core/html/imports/HTMLImportChildClient.h"
40 #include "core/html/imports/HTMLImportLoader.h" 39 #include "core/html/imports/HTMLImportLoader.h"
40 #include "core/html/imports/HTMLImportTreeRoot.h"
41 41
42 namespace WebCore { 42 namespace WebCore {
43 43
44 void HTMLImportsController::provideTo(Document& master) 44 void HTMLImportsController::provideTo(Document& master)
45 { 45 {
46 DEFINE_STATIC_LOCAL(const char*, name, ("HTMLImportsController")); 46 DEFINE_STATIC_LOCAL(const char*, name, ("HTMLImportsController"));
47 OwnPtrWillBeRawPtr<HTMLImportsController> controller = adoptPtrWillBeNoop(ne w HTMLImportsController(master)); 47 OwnPtrWillBeRawPtr<HTMLImportsController> controller = adoptPtrWillBeNoop(ne w HTMLImportsController(master));
48 master.setImportsController(controller.get()); 48 master.setImportsController(controller.get());
49 DocumentSupplement::provideTo(master, name, controller.release()); 49 DocumentSupplement::provideTo(master, name, controller.release());
50 } 50 }
51 51
52 HTMLImportsController::HTMLImportsController(Document& master) 52 HTMLImportsController::HTMLImportsController(Document& master)
53 : HTMLImport(HTMLImport::Sync) 53 : m_master(&master)
54 , m_master(&master) 54 , m_root(HTMLImportTreeRoot::create(&master))
55 , m_recalcTimer(this, &HTMLImportsController::recalcTimerFired)
56 { 55 {
57 recalcTreeState(this); // This recomputes initial state.
58 } 56 }
59 57
60 HTMLImportsController::~HTMLImportsController() 58 HTMLImportsController::~HTMLImportsController()
61 { 59 {
62 ASSERT(!m_master); 60 ASSERT(!m_master);
63 } 61 }
64 62
65 void HTMLImportsController::clear() 63 void HTMLImportsController::clear()
66 { 64 {
67 for (size_t i = 0; i < m_imports.size(); ++i) 65 for (size_t i = 0; i < m_imports.size(); ++i)
68 m_imports[i]->importDestroyed(); 66 m_imports[i]->importDestroyed();
69 m_imports.clear(); 67 m_imports.clear();
70 68
71 for (size_t i = 0; i < m_loaders.size(); ++i) 69 for (size_t i = 0; i < m_loaders.size(); ++i)
72 m_loaders[i]->importDestroyed(); 70 m_loaders[i]->importDestroyed();
73 m_loaders.clear(); 71 m_loaders.clear();
74 72
75 if (m_master) 73 if (m_master)
76 m_master->setImportsController(0); 74 m_master->setImportsController(0);
77 m_master = 0; 75 m_master = 0;
78 76
79 m_recalcTimer.stop(); 77 m_root.clear();
80 } 78 }
81 79
82 static bool makesCycle(HTMLImport* parent, const KURL& url) 80 static bool makesCycle(HTMLImport* parent, const KURL& url)
83 { 81 {
84 for (HTMLImport* ancestor = parent; ancestor; ancestor = ancestor->parent()) { 82 for (HTMLImport* ancestor = parent; ancestor; ancestor = ancestor->parent()) {
85 if (!ancestor->isRoot() && equalIgnoringFragmentIdentifier(toHTMLImportC hild(parent)->url(), url)) 83 if (!ancestor->isRoot() && equalIgnoringFragmentIdentifier(toHTMLImportC hild(parent)->url(), url))
86 return true; 84 return true;
87 } 85 }
88 86
89 return false; 87 return false;
90 } 88 }
91 89
92 HTMLImportChild* HTMLImportsController::createChild(const KURL& url, HTMLImportL oader* loader, HTMLImport* parent, HTMLImportChildClient* client) 90 HTMLImportChild* HTMLImportsController::createChild(const KURL& url, HTMLImportL oader* loader, HTMLImport* parent, HTMLImportChildClient* client)
93 { 91 {
94 HTMLImport::SyncMode mode = client->isSync() && !makesCycle(parent, url) ? H TMLImport::Sync : HTMLImport::Async; 92 HTMLImport::SyncMode mode = client->isSync() && !makesCycle(parent, url) ? H TMLImport::Sync : HTMLImport::Async;
95 OwnPtr<HTMLImportChild> child = adoptPtr(new HTMLImportChild(url, loader, mo de)); 93 OwnPtr<HTMLImportChild> child = adoptPtr(new HTMLImportChild(url, loader, mo de));
96 child->setClient(client); 94 child->setClient(client);
97 parent->appendImport(child.get()); 95 parent->appendImport(child.get());
98 loader->addImport(child.get()); 96 loader->addImport(child.get());
99 m_imports.append(child.release()); 97 m_imports.append(child.release());
100 return m_imports.last().get(); 98 return m_imports.last().get();
101 } 99 }
102 100
103 HTMLImportChild* HTMLImportsController::load(HTMLImport* parent, HTMLImportChild Client* client, FetchRequest request) 101 HTMLImportChild* HTMLImportsController::load(HTMLImport* parent, HTMLImportChild Client* client, FetchRequest request)
104 { 102 {
105 ASSERT(!request.url().isEmpty() && request.url().isValid()); 103 ASSERT(!request.url().isEmpty() && request.url().isValid());
106 ASSERT(parent == this || toHTMLImportChild(parent)->loader()->isFirstImport( toHTMLImportChild(parent))); 104 ASSERT(parent == root() || toHTMLImportChild(parent)->loader()->isFirstImpor t(toHTMLImportChild(parent)));
107 105
108 if (HTMLImportChild* childToShareWith = findLinkFor(request.url())) { 106 if (HTMLImportChild* childToShareWith = findLinkFor(request.url())) {
109 HTMLImportLoader* loader = childToShareWith->loader(); 107 HTMLImportLoader* loader = childToShareWith->loader();
110 ASSERT(loader); 108 ASSERT(loader);
111 HTMLImportChild* child = createChild(request.url(), loader, parent, clie nt); 109 HTMLImportChild* child = createChild(request.url(), loader, parent, clie nt);
112 child->didShareLoader(); 110 child->didShareLoader();
113 return child; 111 return child;
114 } 112 }
115 113
116 bool sameOriginRequest = securityOrigin()->canRequest(request.url()); 114 bool sameOriginRequest = securityOrigin()->canRequest(request.url());
(...skipping 38 matching lines...) Expand 10 before | Expand all | Expand 10 after
155 ResourceFetcher* HTMLImportsController::fetcher() const 153 ResourceFetcher* HTMLImportsController::fetcher() const
156 { 154 {
157 return m_master->fetcher(); 155 return m_master->fetcher();
158 } 156 }
159 157
160 LocalFrame* HTMLImportsController::frame() const 158 LocalFrame* HTMLImportsController::frame() const
161 { 159 {
162 return m_master->frame(); 160 return m_master->frame();
163 } 161 }
164 162
165 Document* HTMLImportsController::document() const
166 {
167 return m_master;
168 }
169
170 bool HTMLImportsController::shouldBlockScriptExecution(const Document& document) const 163 bool HTMLImportsController::shouldBlockScriptExecution(const Document& document) const
171 { 164 {
172 ASSERT(document.importsController() == this); 165 ASSERT(document.importsController() == this);
173 if (HTMLImportLoader* loader = loaderFor(document)) 166 if (HTMLImportLoader* loader = loaderFor(document))
174 return loader->shouldBlockScriptExecution(); 167 return loader->shouldBlockScriptExecution();
175 return state().shouldBlockScriptExecution(); 168 return root()->state().shouldBlockScriptExecution();
176 } 169 }
177 170
178 void HTMLImportsController::wasDetachedFrom(const Document& document) 171 void HTMLImportsController::wasDetachedFrom(const Document& document)
179 { 172 {
180 ASSERT(document.importsController() == this); 173 ASSERT(document.importsController() == this);
181 if (m_master == &document) 174 if (m_master == &document)
182 clear(); 175 clear();
183 } 176 }
184 177
185 bool HTMLImportsController::isDone() const
186 {
187 return !m_master->parsing() && m_master->styleEngine()->haveStylesheetsLoade d();
188 }
189
190 void HTMLImportsController::stateWillChange()
191 {
192 scheduleRecalcState();
193 }
194
195 void HTMLImportsController::stateDidChange()
196 {
197 HTMLImport::stateDidChange();
198
199 if (!state().isReady())
200 return;
201 if (LocalFrame* frame = m_master->frame())
202 frame->loader().checkCompleted();
203 }
204
205 void HTMLImportsController::scheduleRecalcState()
206 {
207 if (m_recalcTimer.isActive() || !m_master)
208 return;
209 m_recalcTimer.startOneShot(0, FROM_HERE);
210 }
211
212 void HTMLImportsController::recalcTimerFired(Timer<HTMLImportsController>*)
213 {
214 ASSERT(m_master);
215
216 do {
217 m_recalcTimer.stop();
218 HTMLImport::recalcTreeState(this);
219 } while (m_recalcTimer.isActive());
220 }
221
222 HTMLImportLoader* HTMLImportsController::createLoader() 178 HTMLImportLoader* HTMLImportsController::createLoader()
223 { 179 {
224 m_loaders.append(HTMLImportLoader::create(this)); 180 m_loaders.append(HTMLImportLoader::create(this));
225 return m_loaders.last().get(); 181 return m_loaders.last().get();
226 } 182 }
227 183
228 HTMLImportLoader* HTMLImportsController::loaderFor(const Document& document) con st 184 HTMLImportLoader* HTMLImportsController::loaderFor(const Document& document) con st
229 { 185 {
230 for (size_t i = 0; i < m_loaders.size(); ++i) { 186 for (size_t i = 0; i < m_loaders.size(); ++i) {
231 if (m_loaders[i]->document() == &document) 187 if (m_loaders[i]->document() == &document)
232 return m_loaders[i].get(); 188 return m_loaders[i].get();
233 } 189 }
234 190
235 return 0; 191 return 0;
236 } 192 }
237 193
238 } // namespace WebCore 194 } // namespace WebCore
OLDNEW
« no previous file with comments | « Source/core/html/imports/HTMLImportsController.h ('k') | Source/core/html/imports/LinkImport.cpp » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698