| OLD | NEW |
| 1 /* | 1 /* |
| 2 * Copyright (C) 1999 Lars Knoll (knoll@kde.org) | 2 * Copyright (C) 1999 Lars Knoll (knoll@kde.org) |
| 3 * (C) 1999 Antti Koivisto (koivisto@kde.org) | 3 * (C) 1999 Antti Koivisto (koivisto@kde.org) |
| 4 * (C) 2001 Dirk Mueller (mueller@kde.org) | 4 * (C) 2001 Dirk Mueller (mueller@kde.org) |
| 5 * Copyright (C) 2003, 2004, 2005, 2006, 2007, 2008 Apple Inc. All rights reserv
ed. | 5 * Copyright (C) 2003, 2004, 2005, 2006, 2007, 2008 Apple Inc. All rights reserv
ed. |
| 6 * Copyright (C) 2008 Nikolas Zimmermann <zimmermann@kde.org> | 6 * Copyright (C) 2008 Nikolas Zimmermann <zimmermann@kde.org> |
| 7 * | 7 * |
| 8 * This library is free software; you can redistribute it and/or | 8 * This library is free software; you can redistribute it and/or |
| 9 * modify it under the terms of the GNU Library General Public | 9 * modify it under the terms of the GNU Library General Public |
| 10 * License as published by the Free Software Foundation; either | 10 * License as published by the Free Software Foundation; either |
| (...skipping 18 matching lines...) Expand all Loading... |
| 29 #include "core/SVGNames.h" | 29 #include "core/SVGNames.h" |
| 30 #include "core/dom/Document.h" | 30 #include "core/dom/Document.h" |
| 31 #include "core/dom/IgnoreDestructiveWriteCountIncrementer.h" | 31 #include "core/dom/IgnoreDestructiveWriteCountIncrementer.h" |
| 32 #include "core/dom/ScriptLoaderClient.h" | 32 #include "core/dom/ScriptLoaderClient.h" |
| 33 #include "core/dom/ScriptRunner.h" | 33 #include "core/dom/ScriptRunner.h" |
| 34 #include "core/dom/ScriptableDocumentParser.h" | 34 #include "core/dom/ScriptableDocumentParser.h" |
| 35 #include "core/dom/Text.h" | 35 #include "core/dom/Text.h" |
| 36 #include "core/events/Event.h" | 36 #include "core/events/Event.h" |
| 37 #include "core/fetch/AccessControlStatus.h" | 37 #include "core/fetch/AccessControlStatus.h" |
| 38 #include "core/fetch/FetchRequest.h" | 38 #include "core/fetch/FetchRequest.h" |
| 39 #include "core/fetch/MemoryCache.h" |
| 39 #include "core/fetch/ResourceFetcher.h" | 40 #include "core/fetch/ResourceFetcher.h" |
| 40 #include "core/fetch/ScriptResource.h" | 41 #include "core/fetch/ScriptResource.h" |
| 41 #include "core/frame/LocalFrame.h" | 42 #include "core/frame/LocalFrame.h" |
| 42 #include "core/frame/SubresourceIntegrity.h" | 43 #include "core/frame/SubresourceIntegrity.h" |
| 43 #include "core/frame/UseCounter.h" | 44 #include "core/frame/UseCounter.h" |
| 44 #include "core/frame/csp/ContentSecurityPolicy.h" | 45 #include "core/frame/csp/ContentSecurityPolicy.h" |
| 45 #include "core/html/CrossOriginAttribute.h" | 46 #include "core/html/CrossOriginAttribute.h" |
| 46 #include "core/html/HTMLScriptElement.h" | 47 #include "core/html/HTMLScriptElement.h" |
| 47 #include "core/html/imports/HTMLImport.h" | 48 #include "core/html/imports/HTMLImport.h" |
| 48 #include "core/html/parser/HTMLParserIdioms.h" | 49 #include "core/html/parser/HTMLParserIdioms.h" |
| 49 #include "core/inspector/ConsoleMessage.h" | 50 #include "core/inspector/ConsoleMessage.h" |
| 50 #include "core/svg/SVGScriptElement.h" | 51 #include "core/svg/SVGScriptElement.h" |
| 51 #include "platform/MIMETypeRegistry.h" | 52 #include "platform/MIMETypeRegistry.h" |
| 52 #include "platform/weborigin/SecurityOrigin.h" | 53 #include "platform/weborigin/SecurityOrigin.h" |
| 54 #include "public/platform/WebCachePolicy.h" |
| 53 #include "public/platform/WebFrameScheduler.h" | 55 #include "public/platform/WebFrameScheduler.h" |
| 54 #include "wtf/StdLibExtras.h" | 56 #include "wtf/StdLibExtras.h" |
| 55 #include "wtf/text/StringBuilder.h" | 57 #include "wtf/text/StringBuilder.h" |
| 56 #include "wtf/text/StringHash.h" | 58 #include "wtf/text/StringHash.h" |
| 57 | 59 |
| 58 namespace blink { | 60 namespace blink { |
| 59 | 61 |
| 60 ScriptLoader::ScriptLoader(Element* element, bool parserInserted, bool alreadySt
arted, bool createdDuringDocumentWrite) | 62 ScriptLoader::ScriptLoader(Element* element, bool parserInserted, bool alreadySt
arted, bool createdDuringDocumentWrite, bool blockedDocWriteScriptAsyncFetch) |
| 61 : m_element(element) | 63 : m_element(element) |
| 62 , m_startLineNumber(WTF::OrdinalNumber::beforeFirst()) | 64 , m_startLineNumber(WTF::OrdinalNumber::beforeFirst()) |
| 63 , m_parserInserted(parserInserted) | 65 , m_parserInserted(parserInserted) |
| 64 , m_isExternalScript(false) | 66 , m_isExternalScript(false) |
| 65 , m_alreadyStarted(alreadyStarted) | 67 , m_alreadyStarted(alreadyStarted) |
| 66 , m_haveFiredLoad(false) | 68 , m_haveFiredLoad(false) |
| 67 , m_willBeParserExecuted(false) | 69 , m_willBeParserExecuted(false) |
| 68 , m_readyToBeParserExecuted(false) | 70 , m_readyToBeParserExecuted(false) |
| 69 , m_willExecuteInOrder(false) | 71 , m_willExecuteInOrder(false) |
| 70 , m_willExecuteWhenDocumentFinishedParsing(false) | 72 , m_willExecuteWhenDocumentFinishedParsing(false) |
| 71 , m_forceAsync(!parserInserted) | 73 , m_forceAsync(!parserInserted) |
| 72 , m_createdDuringDocumentWrite(createdDuringDocumentWrite) | 74 , m_createdDuringDocumentWrite(createdDuringDocumentWrite) |
| 75 , m_disallowedFetchForDocWrittenScript(false) |
| 76 , m_blockedDocWriteScriptAsyncFetch(blockedDocWriteScriptAsyncFetch) |
| 73 { | 77 { |
| 74 DCHECK(m_element); | 78 DCHECK(m_element); |
| 75 if (parserInserted && element->document().scriptableDocumentParser() && !ele
ment->document().isInDocumentWrite()) | 79 if (parserInserted && element->document().scriptableDocumentParser() && !ele
ment->document().isInDocumentWrite()) |
| 76 m_startLineNumber = element->document().scriptableDocumentParser()->line
Number(); | 80 m_startLineNumber = element->document().scriptableDocumentParser()->line
Number(); |
| 81 if (m_blockedDocWriteScriptAsyncFetch) |
| 82 DCHECK(!m_createdDuringDocumentWrite); |
| 77 } | 83 } |
| 78 | 84 |
| 79 ScriptLoader::~ScriptLoader() | 85 ScriptLoader::~ScriptLoader() |
| 80 { | 86 { |
| 81 } | 87 } |
| 82 | 88 |
| 83 DEFINE_TRACE(ScriptLoader) | 89 DEFINE_TRACE(ScriptLoader) |
| 84 { | 90 { |
| 85 visitor->trace(m_element); | 91 visitor->trace(m_element); |
| 86 visitor->trace(m_resource); | 92 visitor->trace(m_resource); |
| (...skipping 144 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 231 if (!isScriptForEventSupported()) | 237 if (!isScriptForEventSupported()) |
| 232 return false; | 238 return false; |
| 233 | 239 |
| 234 if (!client->charsetAttributeValue().isEmpty()) | 240 if (!client->charsetAttributeValue().isEmpty()) |
| 235 m_characterEncoding = client->charsetAttributeValue(); | 241 m_characterEncoding = client->charsetAttributeValue(); |
| 236 else | 242 else |
| 237 m_characterEncoding = elementDocument.characterSet(); | 243 m_characterEncoding = elementDocument.characterSet(); |
| 238 | 244 |
| 239 if (client->hasSourceAttribute()) { | 245 if (client->hasSourceAttribute()) { |
| 240 FetchRequest::DeferOption defer = FetchRequest::NoDefer; | 246 FetchRequest::DeferOption defer = FetchRequest::NoDefer; |
| 241 if (!m_parserInserted || client->asyncAttributeValue() || client->deferA
ttributeValue()) | 247 if (!m_parserInserted || client->asyncAttributeValue() || client->deferA
ttributeValue() || m_blockedDocWriteScriptAsyncFetch) |
| 242 defer = FetchRequest::LazyLoad; | 248 defer = FetchRequest::LazyLoad; |
| 243 if (!fetchScript(client->sourceAttributeValue(), defer)) | 249 if (!fetchScript(client->sourceAttributeValue(), defer)) |
| 244 return false; | 250 return false; |
| 245 } | 251 } |
| 246 | 252 |
| 253 // Since the asynchronous, low priority fetch for doc.written blocked |
| 254 // script is not for execution, return early from here. Watch for its |
| 255 // completion to be able to remove it from the memory cache. |
| 256 if (m_blockedDocWriteScriptAsyncFetch) { |
| 257 m_pendingScript = PendingScript::create(m_element, m_resource.get()); |
| 258 m_pendingScript->watchForLoad(this); |
| 259 return true; |
| 260 } |
| 261 |
| 247 if (client->hasSourceAttribute() && client->deferAttributeValue() && m_parse
rInserted && !client->asyncAttributeValue()) { | 262 if (client->hasSourceAttribute() && client->deferAttributeValue() && m_parse
rInserted && !client->asyncAttributeValue()) { |
| 248 m_willExecuteWhenDocumentFinishedParsing = true; | 263 m_willExecuteWhenDocumentFinishedParsing = true; |
| 249 m_willBeParserExecuted = true; | 264 m_willBeParserExecuted = true; |
| 250 } else if (client->hasSourceAttribute() && m_parserInserted && !client->asyn
cAttributeValue()) { | 265 } else if (client->hasSourceAttribute() && m_parserInserted && !client->asyn
cAttributeValue()) { |
| 251 m_willBeParserExecuted = true; | 266 m_willBeParserExecuted = true; |
| 252 } else if (!client->hasSourceAttribute() && m_parserInserted && !elementDocu
ment.isScriptExecutionReady()) { | 267 } else if (!client->hasSourceAttribute() && m_parserInserted && !elementDocu
ment.isScriptExecutionReady()) { |
| 253 m_willBeParserExecuted = true; | 268 m_willBeParserExecuted = true; |
| 254 m_readyToBeParserExecuted = true; | 269 m_readyToBeParserExecuted = true; |
| 255 } else if (client->hasSourceAttribute() && !client->asyncAttributeValue() &&
!m_forceAsync) { | 270 } else if (client->hasSourceAttribute() && !client->asyncAttributeValue() &&
!m_forceAsync) { |
| 256 m_pendingScript = PendingScript::create(m_element, m_resource.get()); | 271 m_pendingScript = PendingScript::create(m_element, m_resource.get()); |
| (...skipping 53 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 310 } | 325 } |
| 311 request.setDefer(defer); | 326 request.setDefer(defer); |
| 312 | 327 |
| 313 String integrityAttr = m_element->fastGetAttribute(HTMLNames::integrityA
ttr); | 328 String integrityAttr = m_element->fastGetAttribute(HTMLNames::integrityA
ttr); |
| 314 if (!integrityAttr.isEmpty()) { | 329 if (!integrityAttr.isEmpty()) { |
| 315 IntegrityMetadataSet metadataSet; | 330 IntegrityMetadataSet metadataSet; |
| 316 SubresourceIntegrity::parseIntegrityAttribute(integrityAttr, metadat
aSet, elementDocument); | 331 SubresourceIntegrity::parseIntegrityAttribute(integrityAttr, metadat
aSet, elementDocument); |
| 317 request.setIntegrityMetadata(metadataSet); | 332 request.setIntegrityMetadata(metadataSet); |
| 318 } | 333 } |
| 319 | 334 |
| 335 if (m_blockedDocWriteScriptAsyncFetch) { |
| 336 // Set interventions info in resourceRequest so that priority can |
| 337 // be set accordingly. |
| 338 request.mutableResourceRequest().setInterventionsInfo(InterventionsF
lag::InterventionBlockedDocWriteScriptAsyncFetch); |
| 339 request.mutableResourceRequest().setHTTPHeaderField("Intervention",
"<https://www.chromestatus.com/feature/5718547946799104>"); |
| 340 } |
| 341 |
| 320 m_resource = ScriptResource::fetch(request, elementDocument->fetcher()); | 342 m_resource = ScriptResource::fetch(request, elementDocument->fetcher()); |
| 321 | 343 |
| 322 m_isExternalScript = true; | 344 m_isExternalScript = true; |
| 323 } | 345 } |
| 324 | 346 |
| 325 if (m_resource) | 347 if (!m_resource) { |
| 326 return true; | 348 dispatchErrorEvent(); |
| 349 return false; |
| 350 } |
| 327 | 351 |
| 328 dispatchErrorEvent(); | 352 if (m_createdDuringDocumentWrite && m_resource->resourceRequest().getCachePo
licy() == WebCachePolicy::ReturnCacheDataDontLoad) { |
| 329 return false; | 353 DCHECK(!m_blockedDocWriteScriptAsyncFetch); |
| 354 m_disallowedFetchForDocWrittenScript = true; |
| 355 } |
| 356 |
| 357 return true; |
| 330 } | 358 } |
| 331 | 359 |
| 332 bool isHTMLScriptLoader(Element* element) | 360 bool isHTMLScriptLoader(Element* element) |
| 333 { | 361 { |
| 334 DCHECK(element); | 362 DCHECK(element); |
| 335 return isHTMLScriptElement(*element); | 363 return isHTMLScriptElement(*element); |
| 336 } | 364 } |
| 337 | 365 |
| 338 bool isSVGScriptLoader(Element* element) | 366 bool isSVGScriptLoader(Element* element) |
| 339 { | 367 { |
| (...skipping 112 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 452 else | 480 else |
| 453 dispatchErrorEvent(); | 481 dispatchErrorEvent(); |
| 454 } | 482 } |
| 455 m_resource = nullptr; | 483 m_resource = nullptr; |
| 456 } | 484 } |
| 457 | 485 |
| 458 void ScriptLoader::notifyFinished(Resource* resource) | 486 void ScriptLoader::notifyFinished(Resource* resource) |
| 459 { | 487 { |
| 460 DCHECK(!m_willBeParserExecuted); | 488 DCHECK(!m_willBeParserExecuted); |
| 461 | 489 |
| 490 // We do not need this script in the memory cache. The primary goals of |
| 491 // sending this fetch request is to let the third party server know |
| 492 // about the document.write scripts intervention and populate the http |
| 493 // cache for subsequent uses. |
| 494 if (m_blockedDocWriteScriptAsyncFetch) { |
| 495 memoryCache()->remove(resource); |
| 496 m_pendingScript->stopWatchingForLoad(); |
| 497 return; |
| 498 } |
| 499 |
| 462 Document* contextDocument = m_element->document().contextDocument(); | 500 Document* contextDocument = m_element->document().contextDocument(); |
| 463 if (!contextDocument) { | 501 if (!contextDocument) { |
| 464 detach(); | 502 detach(); |
| 465 return; | 503 return; |
| 466 } | 504 } |
| 467 | 505 |
| 468 ASSERT_UNUSED(resource, resource == m_resource); | 506 ASSERT_UNUSED(resource, resource == m_resource); |
| 469 | 507 |
| 470 ScriptRunner::ExecutionType runOrder = m_willExecuteInOrder ? ScriptRunner::
IN_ORDER_EXECUTION : ScriptRunner::ASYNC_EXECUTION; | 508 ScriptRunner::ExecutionType runOrder = m_willExecuteInOrder ? ScriptRunner::
IN_ORDER_EXECUTION : ScriptRunner::ASYNC_EXECUTION; |
| 471 if (m_resource->errorOccurred()) { | 509 if (m_resource->errorOccurred()) { |
| (...skipping 47 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 519 if (isHTMLScriptLoader(element)) | 557 if (isHTMLScriptLoader(element)) |
| 520 return toHTMLScriptElement(element)->loader(); | 558 return toHTMLScriptElement(element)->loader(); |
| 521 | 559 |
| 522 if (isSVGScriptLoader(element)) | 560 if (isSVGScriptLoader(element)) |
| 523 return toSVGScriptElement(element)->loader(); | 561 return toSVGScriptElement(element)->loader(); |
| 524 | 562 |
| 525 return 0; | 563 return 0; |
| 526 } | 564 } |
| 527 | 565 |
| 528 } // namespace blink | 566 } // namespace blink |
| OLD | NEW |