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) |
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_documentWriteIntervention(DocumentWriteIntervention::DocumentWriteInterv
entionNone) |
73 { | 76 { |
74 DCHECK(m_element); | 77 DCHECK(m_element); |
75 if (parserInserted && element->document().scriptableDocumentParser() && !ele
ment->document().isInDocumentWrite()) | 78 if (parserInserted && element->document().scriptableDocumentParser() && !ele
ment->document().isInDocumentWrite()) |
76 m_startLineNumber = element->document().scriptableDocumentParser()->line
Number(); | 79 m_startLineNumber = element->document().scriptableDocumentParser()->line
Number(); |
77 } | 80 } |
78 | 81 |
79 ScriptLoader::~ScriptLoader() | 82 ScriptLoader::~ScriptLoader() |
80 { | 83 { |
81 } | 84 } |
82 | 85 |
83 DEFINE_TRACE(ScriptLoader) | 86 DEFINE_TRACE(ScriptLoader) |
84 { | 87 { |
85 visitor->trace(m_element); | 88 visitor->trace(m_element); |
86 visitor->trace(m_resource); | 89 visitor->trace(m_resource); |
87 visitor->trace(m_pendingScript); | 90 visitor->trace(m_pendingScript); |
88 ScriptResourceClient::trace(visitor); | 91 ScriptResourceClient::trace(visitor); |
89 } | 92 } |
90 | 93 |
| 94 void ScriptLoader::setBlockedDocWriteScriptAsyncFetch() |
| 95 { |
| 96 DCHECK(!m_createdDuringDocumentWrite); |
| 97 m_documentWriteIntervention = DocumentWriteIntervention::AsyncLowPriorityFet
chForBlockedScript; |
| 98 } |
| 99 |
91 void ScriptLoader::didNotifySubtreeInsertionsToDocument() | 100 void ScriptLoader::didNotifySubtreeInsertionsToDocument() |
92 { | 101 { |
93 if (!m_parserInserted) | 102 if (!m_parserInserted) |
94 prepareScript(); // FIXME: Provide a real starting line number here. | 103 prepareScript(); // FIXME: Provide a real starting line number here. |
95 } | 104 } |
96 | 105 |
97 void ScriptLoader::childrenChanged() | 106 void ScriptLoader::childrenChanged() |
98 { | 107 { |
99 if (!m_parserInserted && m_element->isConnected()) | 108 if (!m_parserInserted && m_element->isConnected()) |
100 prepareScript(); // FIXME: Provide a real starting line number here. | 109 prepareScript(); // FIXME: Provide a real starting line number here. |
(...skipping 130 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
231 if (!isScriptForEventSupported()) | 240 if (!isScriptForEventSupported()) |
232 return false; | 241 return false; |
233 | 242 |
234 if (!client->charsetAttributeValue().isEmpty()) | 243 if (!client->charsetAttributeValue().isEmpty()) |
235 m_characterEncoding = client->charsetAttributeValue(); | 244 m_characterEncoding = client->charsetAttributeValue(); |
236 else | 245 else |
237 m_characterEncoding = elementDocument.characterSet(); | 246 m_characterEncoding = elementDocument.characterSet(); |
238 | 247 |
239 if (client->hasSourceAttribute()) { | 248 if (client->hasSourceAttribute()) { |
240 FetchRequest::DeferOption defer = FetchRequest::NoDefer; | 249 FetchRequest::DeferOption defer = FetchRequest::NoDefer; |
241 if (!m_parserInserted || client->asyncAttributeValue() || client->deferA
ttributeValue()) | 250 if (!m_parserInserted || client->asyncAttributeValue() || client->deferA
ttributeValue() |
| 251 || m_documentWriteIntervention == DocumentWriteIntervention::AsyncLo
wPriorityFetchForBlockedScript) |
242 defer = FetchRequest::LazyLoad; | 252 defer = FetchRequest::LazyLoad; |
243 if (!fetchScript(client->sourceAttributeValue(), defer)) | 253 if (!fetchScript(client->sourceAttributeValue(), defer)) |
244 return false; | 254 return false; |
245 } | 255 } |
246 | 256 |
| 257 // Since the asynchronous, low priority fetch for doc.written blocked |
| 258 // script is not for execution, return early from here. Watch for its |
| 259 // completion to be able to remove it from the memory cache. |
| 260 if (m_documentWriteIntervention == DocumentWriteIntervention::AsyncLowPriori
tyFetchForBlockedScript) { |
| 261 m_pendingScript = PendingScript::create(m_element, m_resource.get()); |
| 262 m_pendingScript->watchForLoad(this); |
| 263 return true; |
| 264 } |
| 265 |
247 if (client->hasSourceAttribute() && client->deferAttributeValue() && m_parse
rInserted && !client->asyncAttributeValue()) { | 266 if (client->hasSourceAttribute() && client->deferAttributeValue() && m_parse
rInserted && !client->asyncAttributeValue()) { |
248 m_willExecuteWhenDocumentFinishedParsing = true; | 267 m_willExecuteWhenDocumentFinishedParsing = true; |
249 m_willBeParserExecuted = true; | 268 m_willBeParserExecuted = true; |
250 } else if (client->hasSourceAttribute() && m_parserInserted && !client->asyn
cAttributeValue()) { | 269 } else if (client->hasSourceAttribute() && m_parserInserted && !client->asyn
cAttributeValue()) { |
251 m_willBeParserExecuted = true; | 270 m_willBeParserExecuted = true; |
252 } else if (!client->hasSourceAttribute() && m_parserInserted && !elementDocu
ment.isScriptExecutionReady()) { | 271 } else if (!client->hasSourceAttribute() && m_parserInserted && !elementDocu
ment.isScriptExecutionReady()) { |
253 m_willBeParserExecuted = true; | 272 m_willBeParserExecuted = true; |
254 m_readyToBeParserExecuted = true; | 273 m_readyToBeParserExecuted = true; |
255 } else if (client->hasSourceAttribute() && !client->asyncAttributeValue() &&
!m_forceAsync) { | 274 } else if (client->hasSourceAttribute() && !client->asyncAttributeValue() &&
!m_forceAsync) { |
256 m_pendingScript = PendingScript::create(m_element, m_resource.get()); | 275 m_pendingScript = PendingScript::create(m_element, m_resource.get()); |
(...skipping 53 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
310 } | 329 } |
311 request.setDefer(defer); | 330 request.setDefer(defer); |
312 | 331 |
313 String integrityAttr = m_element->fastGetAttribute(HTMLNames::integrityA
ttr); | 332 String integrityAttr = m_element->fastGetAttribute(HTMLNames::integrityA
ttr); |
314 if (!integrityAttr.isEmpty()) { | 333 if (!integrityAttr.isEmpty()) { |
315 IntegrityMetadataSet metadataSet; | 334 IntegrityMetadataSet metadataSet; |
316 SubresourceIntegrity::parseIntegrityAttribute(integrityAttr, metadat
aSet, elementDocument); | 335 SubresourceIntegrity::parseIntegrityAttribute(integrityAttr, metadat
aSet, elementDocument); |
317 request.setIntegrityMetadata(metadataSet); | 336 request.setIntegrityMetadata(metadataSet); |
318 } | 337 } |
319 | 338 |
| 339 if (m_documentWriteIntervention == DocumentWriteIntervention::AsyncLowPr
iorityFetchForBlockedScript) { |
| 340 // Set interventions info in resourceRequest so that priority can |
| 341 // be set accordingly. |
| 342 request.mutableResourceRequest().setInterventionsInfo(InterventionsF
lag::InterventionBlockedDocWriteScriptAsyncFetch); |
| 343 request.mutableResourceRequest().setHTTPHeaderField("Intervention",
"<https://www.chromestatus.com/feature/5718547946799104>"); |
| 344 } |
| 345 |
320 m_resource = ScriptResource::fetch(request, elementDocument->fetcher()); | 346 m_resource = ScriptResource::fetch(request, elementDocument->fetcher()); |
321 | 347 |
322 m_isExternalScript = true; | 348 m_isExternalScript = true; |
323 } | 349 } |
324 | 350 |
325 if (m_resource) | 351 if (!m_resource) { |
326 return true; | 352 dispatchErrorEvent(); |
| 353 return false; |
| 354 } |
327 | 355 |
328 dispatchErrorEvent(); | 356 if (m_createdDuringDocumentWrite && m_resource->resourceRequest().getCachePo
licy() == WebCachePolicy::ReturnCacheDataDontLoad) { |
329 return false; | 357 m_documentWriteIntervention = DocumentWriteIntervention::DisallowedFetch
ForDocWrittenScript; |
| 358 } |
| 359 |
| 360 return true; |
330 } | 361 } |
331 | 362 |
332 bool isHTMLScriptLoader(Element* element) | 363 bool isHTMLScriptLoader(Element* element) |
333 { | 364 { |
334 DCHECK(element); | 365 DCHECK(element); |
335 return isHTMLScriptElement(*element); | 366 return isHTMLScriptElement(*element); |
336 } | 367 } |
337 | 368 |
338 bool isSVGScriptLoader(Element* element) | 369 bool isSVGScriptLoader(Element* element) |
339 { | 370 { |
(...skipping 112 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
452 else | 483 else |
453 dispatchErrorEvent(); | 484 dispatchErrorEvent(); |
454 } | 485 } |
455 m_resource = nullptr; | 486 m_resource = nullptr; |
456 } | 487 } |
457 | 488 |
458 void ScriptLoader::notifyFinished(Resource* resource) | 489 void ScriptLoader::notifyFinished(Resource* resource) |
459 { | 490 { |
460 DCHECK(!m_willBeParserExecuted); | 491 DCHECK(!m_willBeParserExecuted); |
461 | 492 |
| 493 // We do not need this script in the memory cache. The primary goals of |
| 494 // sending this fetch request are to let the third party server know |
| 495 // about the document.write scripts intervention and populate the http |
| 496 // cache for subsequent uses. |
| 497 if (m_documentWriteIntervention == DocumentWriteIntervention::AsyncLowPriori
tyFetchForBlockedScript) { |
| 498 memoryCache()->remove(resource); |
| 499 m_pendingScript->stopWatchingForLoad(); |
| 500 return; |
| 501 } |
| 502 |
462 Document* contextDocument = m_element->document().contextDocument(); | 503 Document* contextDocument = m_element->document().contextDocument(); |
463 if (!contextDocument) { | 504 if (!contextDocument) { |
464 detach(); | 505 detach(); |
465 return; | 506 return; |
466 } | 507 } |
467 | 508 |
468 ASSERT_UNUSED(resource, resource == m_resource); | 509 ASSERT_UNUSED(resource, resource == m_resource); |
469 | 510 |
470 ScriptRunner::ExecutionType runOrder = m_willExecuteInOrder ? ScriptRunner::
IN_ORDER_EXECUTION : ScriptRunner::ASYNC_EXECUTION; | 511 ScriptRunner::ExecutionType runOrder = m_willExecuteInOrder ? ScriptRunner::
IN_ORDER_EXECUTION : ScriptRunner::ASYNC_EXECUTION; |
471 if (m_resource->errorOccurred()) { | 512 if (m_resource->errorOccurred()) { |
(...skipping 47 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
519 if (isHTMLScriptLoader(element)) | 560 if (isHTMLScriptLoader(element)) |
520 return toHTMLScriptElement(element)->loader(); | 561 return toHTMLScriptElement(element)->loader(); |
521 | 562 |
522 if (isSVGScriptLoader(element)) | 563 if (isSVGScriptLoader(element)) |
523 return toSVGScriptElement(element)->loader(); | 564 return toSVGScriptElement(element)->loader(); |
524 | 565 |
525 return 0; | 566 return 0; |
526 } | 567 } |
527 | 568 |
528 } // namespace blink | 569 } // namespace blink |
OLD | NEW |