| 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 71 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 82 static bool makesCycle(HTMLImport* parent, const KURL& url) | 82 static bool makesCycle(HTMLImport* parent, const KURL& url) |
| 83 { | 83 { |
| 84 for (HTMLImport* ancestor = parent; ancestor; ancestor = ancestor->parent())
{ | 84 for (HTMLImport* ancestor = parent; ancestor; ancestor = ancestor->parent())
{ |
| 85 if (!ancestor->isRoot() && equalIgnoringFragmentIdentifier(toHTMLImportC
hild(parent)->url(), url)) | 85 if (!ancestor->isRoot() && equalIgnoringFragmentIdentifier(toHTMLImportC
hild(parent)->url(), url)) |
| 86 return true; | 86 return true; |
| 87 } | 87 } |
| 88 | 88 |
| 89 return false; | 89 return false; |
| 90 } | 90 } |
| 91 | 91 |
| 92 HTMLImportChild* HTMLImportsController::createChild(const KURL& url, HTMLImport*
parent, HTMLImportChildClient* client) | 92 HTMLImportChild* HTMLImportsController::createChild(const KURL& url, HTMLImportL
oader* loader, HTMLImport* parent, HTMLImportChildClient* client) |
| 93 { | 93 { |
| 94 HTMLImport::SyncMode mode = client->isSync() && !makesCycle(parent, url) ? H
TMLImport::Sync : HTMLImport::Async; | 94 HTMLImport::SyncMode mode = client->isSync() && !makesCycle(parent, url) ? H
TMLImport::Sync : HTMLImport::Async; |
| 95 OwnPtr<HTMLImportChild> loader = adoptPtr(new HTMLImportChild(url, mode)); | 95 OwnPtr<HTMLImportChild> child = adoptPtr(new HTMLImportChild(url, loader, mo
de)); |
| 96 loader->setClient(client); | 96 child->setClient(client); |
| 97 parent->appendImport(loader.get()); | 97 parent->appendImport(child.get()); |
| 98 m_imports.append(loader.release()); | 98 loader->addImport(child.get()); |
| 99 m_imports.append(child.release()); |
| 99 return m_imports.last().get(); | 100 return m_imports.last().get(); |
| 100 } | 101 } |
| 101 | 102 |
| 102 HTMLImportChild* HTMLImportsController::load(HTMLImport* parent, HTMLImportChild
Client* client, FetchRequest request) | 103 HTMLImportChild* HTMLImportsController::load(HTMLImport* parent, HTMLImportChild
Client* client, FetchRequest request) |
| 103 { | 104 { |
| 104 ASSERT(!request.url().isEmpty() && request.url().isValid()); | 105 ASSERT(!request.url().isEmpty() && request.url().isValid()); |
| 105 ASSERT(parent == this || toHTMLImportChild(parent)->loader()->isFirstImport(
toHTMLImportChild(parent))); | 106 ASSERT(parent == this || toHTMLImportChild(parent)->loader()->isFirstImport(
toHTMLImportChild(parent))); |
| 106 | 107 |
| 107 if (findLinkFor(request.url())) { | 108 if (HTMLImportChild* childToShareWith = findLinkFor(request.url())) { |
| 108 HTMLImportChild* child = createChild(request.url(), parent, client); | 109 HTMLImportLoader* loader = childToShareWith->loader(); |
| 109 child->wasAlreadyLoaded(); | 110 ASSERT(loader); |
| 111 HTMLImportChild* child = createChild(request.url(), loader, parent, clie
nt); |
| 112 child->didShareLoader(); |
| 110 return child; | 113 return child; |
| 111 } | 114 } |
| 112 | 115 |
| 113 bool sameOriginRequest = securityOrigin()->canRequest(request.url()); | 116 bool sameOriginRequest = securityOrigin()->canRequest(request.url()); |
| 114 request.setCrossOriginAccessControl( | 117 request.setCrossOriginAccessControl( |
| 115 securityOrigin(), sameOriginRequest ? AllowStoredCredentials : DoNotAllo
wStoredCredentials, | 118 securityOrigin(), sameOriginRequest ? AllowStoredCredentials : DoNotAllo
wStoredCredentials, |
| 116 ClientDidNotRequestCredentials); | 119 ClientDidNotRequestCredentials); |
| 117 ResourcePtr<RawResource> resource = parent->document()->fetcher()->fetchImpo
rt(request); | 120 ResourcePtr<RawResource> resource = parent->document()->fetcher()->fetchImpo
rt(request); |
| 118 if (!resource) | 121 if (!resource) |
| 119 return 0; | 122 return 0; |
| 120 | 123 |
| 121 HTMLImportChild* child = createChild(request.url(), parent, client); | 124 HTMLImportLoader* loader = createLoader(); |
| 125 HTMLImportChild* child = createChild(request.url(), loader, parent, client); |
| 122 // We set resource after the import tree is built since | 126 // We set resource after the import tree is built since |
| 123 // Resource::addClient() immediately calls back to feed the bytes when the r
esource is cached. | 127 // Resource::addClient() immediately calls back to feed the bytes when the r
esource is cached. |
| 124 child->startLoading(resource); | 128 loader->startLoading(resource); |
| 129 child->didStartLoading(); |
| 125 | 130 |
| 126 return child; | 131 return child; |
| 127 } | 132 } |
| 128 | 133 |
| 129 void HTMLImportsController::showSecurityErrorMessage(const String& message) | 134 void HTMLImportsController::showSecurityErrorMessage(const String& message) |
| 130 { | 135 { |
| 131 m_master->addConsoleMessage(JSMessageSource, ErrorMessageLevel, message); | 136 m_master->addConsoleMessage(JSMessageSource, ErrorMessageLevel, message); |
| 132 } | 137 } |
| 133 | 138 |
| 134 HTMLImportChild* HTMLImportsController::findLinkFor(const KURL& url, HTMLImport*
excluding) const | 139 HTMLImportChild* HTMLImportsController::findLinkFor(const KURL& url) const |
| 135 { | 140 { |
| 136 for (size_t i = 0; i < m_imports.size(); ++i) { | 141 for (size_t i = 0; i < m_imports.size(); ++i) { |
| 137 HTMLImportChild* candidate = m_imports[i].get(); | 142 HTMLImportChild* candidate = m_imports[i].get(); |
| 138 if (candidate != excluding && equalIgnoringFragmentIdentifier(candidate-
>url(), url) && candidate->loader()) | 143 if (equalIgnoringFragmentIdentifier(candidate->url(), url) && candidate-
>loader()) |
| 139 return candidate; | 144 return candidate; |
| 140 } | 145 } |
| 141 | 146 |
| 142 return 0; | 147 return 0; |
| 143 } | 148 } |
| 144 | 149 |
| 145 SecurityOrigin* HTMLImportsController::securityOrigin() const | 150 SecurityOrigin* HTMLImportsController::securityOrigin() const |
| 146 { | 151 { |
| 147 return m_master->securityOrigin(); | 152 return m_master->securityOrigin(); |
| 148 } | 153 } |
| (...skipping 75 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 224 { | 229 { |
| 225 for (size_t i = 0; i < m_loaders.size(); ++i) { | 230 for (size_t i = 0; i < m_loaders.size(); ++i) { |
| 226 if (m_loaders[i]->document() == &document) | 231 if (m_loaders[i]->document() == &document) |
| 227 return m_loaders[i].get(); | 232 return m_loaders[i].get(); |
| 228 } | 233 } |
| 229 | 234 |
| 230 return 0; | 235 return 0; |
| 231 } | 236 } |
| 232 | 237 |
| 233 } // namespace WebCore | 238 } // namespace WebCore |
| OLD | NEW |