| 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 53 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 64 } | 64 } |
| 65 | 65 |
| 66 void LinkImport::process() | 66 void LinkImport::process() |
| 67 { | 67 { |
| 68 if (m_loader) | 68 if (m_loader) |
| 69 return; | 69 return; |
| 70 if (!m_owner) | 70 if (!m_owner) |
| 71 return; | 71 return; |
| 72 | 72 |
| 73 // FIXME(morrita): Should take care of sub-imports whose document doesn't ha
ve frame. | 73 // FIXME(morrita): Should take care of sub-imports whose document doesn't ha
ve frame. |
| 74 if (!m_owner->document()->frame()) | 74 if (!m_owner->document()->frame() && !m_owner->document()->imports()) |
| 75 return; | 75 return; |
| 76 | 76 |
| 77 LinkRequestBuilder builder(m_owner); | 77 LinkRequestBuilder builder(m_owner); |
| 78 if (!builder.isValid()) | 78 if (!builder.isValid()) |
| 79 return; | 79 return; |
| 80 | 80 |
| 81 HTMLImportsController* controller = m_owner->document()->ensureImports(); | 81 HTMLImportsController* controller = m_owner->document()->imports(); |
| 82 if (!controller) { |
| 83 ASSERT(m_owner->document()->frame()); // The document should be the mast
er. |
| 84 m_owner->document()->setImports(HTMLImportsController::create(m_owner->d
ocument())); |
| 85 controller = m_owner->document()->imports(); |
| 86 } |
| 87 |
| 82 if (RefPtr<HTMLImportLoader> found = controller->findLinkFor(builder.url()))
{ | 88 if (RefPtr<HTMLImportLoader> found = controller->findLinkFor(builder.url()))
{ |
| 83 m_loader = found; | 89 m_loader = found; |
| 84 return; | 90 return; |
| 85 } | 91 } |
| 86 | 92 |
| 87 CachedResourceRequest request = builder.build(true); | 93 CachedResourceRequest request = builder.build(true); |
| 88 CachedResourceHandle<CachedScript> resource = m_owner->document()->cachedRes
ourceLoader()->requestScript(request); | 94 CachedResourceHandle<CachedScript> resource = controller->cachedResourceLoad
er()->requestScript(request); |
| 95 if (!resource) |
| 96 return; |
| 97 |
| 89 m_loader = HTMLImportLoader::create(controller, builder.url(), resource); | 98 m_loader = HTMLImportLoader::create(controller, builder.url(), resource); |
| 90 } | 99 } |
| 91 | 100 |
| 92 void LinkImport::ownerRemoved() | 101 void LinkImport::ownerRemoved() |
| 93 { | 102 { |
| 94 m_owner = 0; | 103 m_owner = 0; |
| 95 m_loader.clear(); | 104 m_loader.clear(); |
| 96 } | 105 } |
| 97 | 106 |
| 98 | 107 |
| (...skipping 44 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 143 | 152 |
| 144 String error; | 153 String error; |
| 145 if (!m_controller->securityOrigin()->canRequest(m_resource->response().url()
) | 154 if (!m_controller->securityOrigin()->canRequest(m_resource->response().url()
) |
| 146 && !m_resource->passesAccessControlCheck(m_controller->securityOrigin(),
error)) { | 155 && !m_resource->passesAccessControlCheck(m_controller->securityOrigin(),
error)) { |
| 147 m_controller->showSecurityErrorMessage("Import from origin '" + Security
Origin::create(m_resource->response().url())->toString() + "' has been blocked f
rom loading by Cross-Origin Resource Sharing policy: " + error); | 156 m_controller->showSecurityErrorMessage("Import from origin '" + Security
Origin::create(m_resource->response().url())->toString() + "' has been blocked f
rom loading by Cross-Origin Resource Sharing policy: " + error); |
| 148 return StateError; | 157 return StateError; |
| 149 } | 158 } |
| 150 | 159 |
| 151 // FIXME(morrita): This should be done in incremental way. | 160 // FIXME(morrita): This should be done in incremental way. |
| 152 m_importedDocument = HTMLDocument::create(0, m_resource->response().url()); | 161 m_importedDocument = HTMLDocument::create(0, m_resource->response().url()); |
| 162 m_importedDocument->setImports(m_controller); |
| 153 m_importedDocument->setContent(m_resource->script()); | 163 m_importedDocument->setContent(m_resource->script()); |
| 154 | 164 |
| 155 return StateReady; | 165 return StateReady; |
| 156 } | 166 } |
| 157 | 167 |
| 158 Document* HTMLImportLoader::importedDocument() const | 168 Document* HTMLImportLoader::importedDocument() const |
| 159 { | 169 { |
| 160 if (m_state != StateReady) | 170 if (m_state != StateReady) |
| 161 return 0; | 171 return 0; |
| 162 return m_importedDocument.get(); | 172 return m_importedDocument.get(); |
| 163 } | 173 } |
| 164 | 174 |
| 165 void HTMLImportLoader::importDestroyed() | 175 void HTMLImportLoader::importDestroyed() |
| 166 { | 176 { |
| 167 m_controller = 0; | 177 m_controller = 0; |
| 168 m_importedDocument.clear(); | 178 m_importedDocument.clear(); |
| 169 } | 179 } |
| 170 | 180 |
| 171 | 181 |
| 172 PassOwnPtr<HTMLImportsController> HTMLImportsController::create(Document* master
) | 182 PassRefPtr<HTMLImportsController> HTMLImportsController::create(Document* master
) |
| 173 { | 183 { |
| 174 return adoptPtr(new HTMLImportsController(master)); | 184 return adoptRef(new HTMLImportsController(master)); |
| 175 } | 185 } |
| 176 | 186 |
| 177 HTMLImportsController::HTMLImportsController(Document* master) | 187 HTMLImportsController::HTMLImportsController(Document* master) |
| 178 : m_master(master) | 188 : m_master(master) |
| 179 { | 189 { |
| 180 } | 190 } |
| 181 | 191 |
| 182 HTMLImportsController::~HTMLImportsController() | 192 HTMLImportsController::~HTMLImportsController() |
| 183 { | 193 { |
| 184 for (size_t i = 0; i < m_imports.size(); ++i) | 194 for (size_t i = 0; i < m_imports.size(); ++i) |
| (...skipping 13 matching lines...) Expand all Loading... |
| 198 | 208 |
| 199 void HTMLImportsController::didLoad() | 209 void HTMLImportsController::didLoad() |
| 200 { | 210 { |
| 201 if (haveLoaded()) | 211 if (haveLoaded()) |
| 202 m_master->didLoadAllImports(); | 212 m_master->didLoadAllImports(); |
| 203 } | 213 } |
| 204 | 214 |
| 205 PassRefPtr<HTMLImportLoader> HTMLImportsController::findLinkFor(const KURL& url)
const | 215 PassRefPtr<HTMLImportLoader> HTMLImportsController::findLinkFor(const KURL& url)
const |
| 206 { | 216 { |
| 207 for (size_t i = 0; i < m_imports.size(); ++i) { | 217 for (size_t i = 0; i < m_imports.size(); ++i) { |
| 208 if (m_imports[i]->url() == url) | 218 if (equalIgnoringFragmentIdentifier(m_imports[i]->url(), url)) |
| 209 return m_imports[i]; | 219 return m_imports[i]; |
| 210 } | 220 } |
| 211 | 221 |
| 212 return 0; | 222 return 0; |
| 213 } | 223 } |
| 214 | 224 |
| 215 SecurityOrigin* HTMLImportsController::securityOrigin() const | 225 SecurityOrigin* HTMLImportsController::securityOrigin() const |
| 216 { | 226 { |
| 217 return m_master->securityOrigin(); | 227 return m_master->securityOrigin(); |
| 218 } | 228 } |
| 219 | 229 |
| 230 CachedResourceLoader* HTMLImportsController::cachedResourceLoader() const |
| 231 { |
| 232 return m_master->cachedResourceLoader(); |
| 233 } |
| 234 |
| 220 bool HTMLImportsController::haveLoaded() const | 235 bool HTMLImportsController::haveLoaded() const |
| 221 { | 236 { |
| 222 for (size_t i = 0; i < m_imports.size(); ++i) { | 237 for (size_t i = 0; i < m_imports.size(); ++i) { |
| 223 if (!m_imports[i]->isDone()) | 238 if (!m_imports[i]->isDone()) |
| 224 return false; | 239 return false; |
| 225 } | 240 } |
| 226 | 241 |
| 227 return true; | 242 return true; |
| 228 } | 243 } |
| 229 | 244 |
| 230 } // namespace WebCore | 245 } // namespace WebCore |
| OLD | NEW |