OLD | NEW |
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 32 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
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 : m_master(&master) | 53 : m_root(HTMLImportTreeRoot::create(&master)) |
54 , m_root(HTMLImportTreeRoot::create(&master)) | |
55 { | 54 { |
56 } | 55 } |
57 | 56 |
58 HTMLImportsController::~HTMLImportsController() | 57 HTMLImportsController::~HTMLImportsController() |
59 { | 58 { |
60 ASSERT(!m_master); | 59 ASSERT(!m_root); |
61 } | 60 } |
62 | 61 |
63 void HTMLImportsController::clear() | 62 void HTMLImportsController::clear() |
64 { | 63 { |
| 64 Document* master = root()->document(); |
65 m_root.clear(); | 65 m_root.clear(); |
66 | 66 |
67 for (size_t i = 0; i < m_loaders.size(); ++i) | 67 for (size_t i = 0; i < m_loaders.size(); ++i) |
68 m_loaders[i]->importDestroyed(); | 68 m_loaders[i]->importDestroyed(); |
69 m_loaders.clear(); | 69 m_loaders.clear(); |
70 | 70 |
71 if (m_master) | 71 if (master) |
72 m_master->setImportsController(0); | 72 master->setImportsController(0); |
73 m_master = 0; | 73 master = 0; |
74 | |
75 m_root.clear(); | |
76 } | 74 } |
77 | 75 |
78 static bool makesCycle(HTMLImport* parent, const KURL& url) | 76 static bool makesCycle(HTMLImport* parent, const KURL& url) |
79 { | 77 { |
80 for (HTMLImport* ancestor = parent; ancestor; ancestor = ancestor->parent())
{ | 78 for (HTMLImport* ancestor = parent; ancestor; ancestor = ancestor->parent())
{ |
81 if (!ancestor->isRoot() && equalIgnoringFragmentIdentifier(toHTMLImportC
hild(parent)->url(), url)) | 79 if (!ancestor->isRoot() && equalIgnoringFragmentIdentifier(toHTMLImportC
hild(parent)->url(), url)) |
82 return true; | 80 return true; |
83 } | 81 } |
84 | 82 |
85 return false; | 83 return false; |
(...skipping 15 matching lines...) Expand all Loading... |
101 ASSERT(parent == root() || toHTMLImportChild(parent)->loader()->isFirstImpor
t(toHTMLImportChild(parent))); | 99 ASSERT(parent == root() || toHTMLImportChild(parent)->loader()->isFirstImpor
t(toHTMLImportChild(parent))); |
102 | 100 |
103 if (HTMLImportChild* childToShareWith = root()->find(request.url())) { | 101 if (HTMLImportChild* childToShareWith = root()->find(request.url())) { |
104 HTMLImportLoader* loader = childToShareWith->loader(); | 102 HTMLImportLoader* loader = childToShareWith->loader(); |
105 ASSERT(loader); | 103 ASSERT(loader); |
106 HTMLImportChild* child = createChild(request.url(), loader, parent, clie
nt); | 104 HTMLImportChild* child = createChild(request.url(), loader, parent, clie
nt); |
107 child->didShareLoader(); | 105 child->didShareLoader(); |
108 return child; | 106 return child; |
109 } | 107 } |
110 | 108 |
111 bool sameOriginRequest = securityOrigin()->canRequest(request.url()); | 109 bool sameOriginRequest = master()->securityOrigin()->canRequest(request.url(
)); |
112 request.setCrossOriginAccessControl( | 110 request.setCrossOriginAccessControl( |
113 securityOrigin(), sameOriginRequest ? AllowStoredCredentials : DoNotAllo
wStoredCredentials, | 111 master()->securityOrigin(), sameOriginRequest ? AllowStoredCredentials :
DoNotAllowStoredCredentials, |
114 ClientDidNotRequestCredentials); | 112 ClientDidNotRequestCredentials); |
115 ResourcePtr<RawResource> resource = parent->document()->fetcher()->fetchImpo
rt(request); | 113 ResourcePtr<RawResource> resource = parent->document()->fetcher()->fetchImpo
rt(request); |
116 if (!resource) | 114 if (!resource) |
117 return 0; | 115 return 0; |
118 | 116 |
119 HTMLImportLoader* loader = createLoader(); | 117 HTMLImportLoader* loader = createLoader(); |
120 HTMLImportChild* child = createChild(request.url(), loader, parent, client); | 118 HTMLImportChild* child = createChild(request.url(), loader, parent, client); |
121 // We set resource after the import tree is built since | 119 // We set resource after the import tree is built since |
122 // Resource::addClient() immediately calls back to feed the bytes when the r
esource is cached. | 120 // Resource::addClient() immediately calls back to feed the bytes when the r
esource is cached. |
123 loader->startLoading(resource); | 121 loader->startLoading(resource); |
124 child->didStartLoading(); | 122 child->didStartLoading(); |
125 | 123 |
126 return child; | 124 return child; |
127 } | 125 } |
128 | 126 |
129 void HTMLImportsController::showSecurityErrorMessage(const String& message) | 127 void HTMLImportsController::showSecurityErrorMessage(const String& message) |
130 { | 128 { |
131 m_master->addConsoleMessage(JSMessageSource, ErrorMessageLevel, message); | 129 master()->addConsoleMessage(JSMessageSource, ErrorMessageLevel, message); |
132 } | 130 } |
133 | 131 |
134 SecurityOrigin* HTMLImportsController::securityOrigin() const | 132 Document* HTMLImportsController::master() const |
135 { | 133 { |
136 return m_master->securityOrigin(); | 134 return root()->document(); |
137 } | |
138 | |
139 ResourceFetcher* HTMLImportsController::fetcher() const | |
140 { | |
141 return m_master->fetcher(); | |
142 } | |
143 | |
144 LocalFrame* HTMLImportsController::frame() const | |
145 { | |
146 return m_master->frame(); | |
147 } | 135 } |
148 | 136 |
149 bool HTMLImportsController::shouldBlockScriptExecution(const Document& document)
const | 137 bool HTMLImportsController::shouldBlockScriptExecution(const Document& document)
const |
150 { | 138 { |
151 ASSERT(document.importsController() == this); | 139 ASSERT(document.importsController() == this); |
152 if (HTMLImportLoader* loader = loaderFor(document)) | 140 if (HTMLImportLoader* loader = loaderFor(document)) |
153 return loader->shouldBlockScriptExecution(); | 141 return loader->shouldBlockScriptExecution(); |
154 return root()->state().shouldBlockScriptExecution(); | 142 return root()->state().shouldBlockScriptExecution(); |
155 } | 143 } |
156 | 144 |
157 void HTMLImportsController::wasDetachedFrom(const Document& document) | 145 void HTMLImportsController::wasDetachedFrom(const Document& document) |
158 { | 146 { |
159 ASSERT(document.importsController() == this); | 147 ASSERT(document.importsController() == this); |
160 if (m_master == &document) | 148 if (master() == &document) |
161 clear(); | 149 clear(); |
162 } | 150 } |
163 | 151 |
164 HTMLImportLoader* HTMLImportsController::createLoader() | 152 HTMLImportLoader* HTMLImportsController::createLoader() |
165 { | 153 { |
166 m_loaders.append(HTMLImportLoader::create(this)); | 154 m_loaders.append(HTMLImportLoader::create(this)); |
167 return m_loaders.last().get(); | 155 return m_loaders.last().get(); |
168 } | 156 } |
169 | 157 |
170 HTMLImportLoader* HTMLImportsController::loaderFor(const Document& document) con
st | 158 HTMLImportLoader* HTMLImportsController::loaderFor(const Document& document) con
st |
171 { | 159 { |
172 for (size_t i = 0; i < m_loaders.size(); ++i) { | 160 for (size_t i = 0; i < m_loaders.size(); ++i) { |
173 if (m_loaders[i]->document() == &document) | 161 if (m_loaders[i]->document() == &document) |
174 return m_loaders[i].get(); | 162 return m_loaders[i].get(); |
175 } | 163 } |
176 | 164 |
177 return 0; | 165 return 0; |
178 } | 166 } |
179 | 167 |
180 } // namespace WebCore | 168 } // namespace WebCore |
OLD | NEW |