| Index: third_party/WebKit/Source/core/dom/PendingScript.cpp
|
| diff --git a/third_party/WebKit/Source/core/dom/PendingScript.cpp b/third_party/WebKit/Source/core/dom/PendingScript.cpp
|
| index 7ea074252620e6ed402a035c3bbe8bfceba0d48e..7d040ebfa4f9e0b1be23638ff38eb8f934dab8c5 100644
|
| --- a/third_party/WebKit/Source/core/dom/PendingScript.cpp
|
| +++ b/third_party/WebKit/Source/core/dom/PendingScript.cpp
|
| @@ -26,33 +26,33 @@
|
| #include "core/dom/PendingScript.h"
|
|
|
| #include "bindings/core/v8/ScriptSourceCode.h"
|
| -#include "core/dom/Element.h"
|
| +#include "core/dom/ScriptLoaderClient.h"
|
| #include "core/frame/SubresourceIntegrity.h"
|
| #include "platform/SharedBuffer.h"
|
| #include "wtf/CurrentTime.h"
|
|
|
| namespace blink {
|
|
|
| -PendingScript* PendingScript::create(Element* element,
|
| +PendingScript* PendingScript::create(ScriptLoaderClient* scriptLoaderClient,
|
| ScriptResource* resource) {
|
| - return new PendingScript(element, resource, TextPosition());
|
| + return new PendingScript(scriptLoaderClient, resource, TextPosition());
|
| }
|
|
|
| -PendingScript* PendingScript::create(Element* element,
|
| +PendingScript* PendingScript::create(ScriptLoaderClient* scriptLoaderClient,
|
| const TextPosition& startingPosition) {
|
| - return new PendingScript(element, nullptr, startingPosition);
|
| + return new PendingScript(scriptLoaderClient, nullptr, startingPosition);
|
| }
|
|
|
| PendingScript* PendingScript::createForTesting(ScriptResource* resource) {
|
| return new PendingScript(nullptr, resource, TextPosition(), true);
|
| }
|
|
|
| -PendingScript::PendingScript(Element* element,
|
| +PendingScript::PendingScript(ScriptLoaderClient* scriptLoaderClient,
|
| ScriptResource* resource,
|
| const TextPosition& startingPosition,
|
| bool isForTesting)
|
| : m_watchingForLoad(false),
|
| - m_element(element),
|
| + m_scriptLoaderClient(scriptLoaderClient),
|
| m_startingPosition(startingPosition),
|
| m_integrityFailure(false),
|
| m_parserBlockingLoadStartTime(0),
|
| @@ -67,7 +67,7 @@ PendingScript::~PendingScript() {}
|
|
|
| NOINLINE void PendingScript::checkState() const {
|
| // TODO(hiroshige): Turn these CHECK()s into DCHECK() before going to beta.
|
| - CHECK(m_isForTesting || m_element);
|
| + CHECK(m_isForTesting || m_scriptLoaderClient);
|
| CHECK(resource() || !m_streamer);
|
| CHECK(!m_streamer || m_streamer->resource() == resource());
|
| }
|
| @@ -84,7 +84,7 @@ void PendingScript::dispose() {
|
| if (m_streamer)
|
| m_streamer->cancel();
|
| m_streamer = nullptr;
|
| - m_element = nullptr;
|
| + m_scriptLoaderClient = nullptr;
|
| }
|
|
|
| void PendingScript::watchForLoad(PendingScriptClient* client) {
|
| @@ -111,11 +111,12 @@ void PendingScript::stopWatchingForLoad() {
|
| m_watchingForLoad = false;
|
| }
|
|
|
| -Element* PendingScript::element() const {
|
| - // As mentioned in the comment at |m_element| declaration, |m_element|
|
| - // must points to the corresponding ScriptLoader's element.
|
| - CHECK(m_element);
|
| - return m_element.get();
|
| +ScriptLoaderClient* PendingScript::scriptLoaderClient() const {
|
| + // As mentioned in the comment at |m_scriptLoaderClient| declaration,
|
| + // |m_scriptLoaderClient| must point to the corresponding ScriptLoader's
|
| + // client.
|
| + CHECK(m_scriptLoaderClient);
|
| + return m_scriptLoaderClient.get();
|
| }
|
|
|
| void PendingScript::streamingFinished() {
|
| @@ -131,10 +132,12 @@ void PendingScript::markParserBlockingLoadStartTime() {
|
| }
|
|
|
| // Returns true if SRI check passed.
|
| -static bool checkScriptResourceIntegrity(Resource* resource, Element* element) {
|
| +static bool checkScriptResourceIntegrity(
|
| + Resource* resource,
|
| + ScriptLoaderClient* scriptLoaderClient) {
|
| DCHECK_EQ(resource->getType(), Resource::Script);
|
| ScriptResource* scriptResource = toScriptResource(resource);
|
| - String integrityAttr = element->fastGetAttribute(HTMLNames::integrityAttr);
|
| + String integrityAttr = scriptLoaderClient->integrityAttributeValue();
|
|
|
| // It is possible to get back a script resource with integrity metadata
|
| // for a request with an empty integrity attribute. In that case, the
|
| @@ -159,7 +162,7 @@ static bool checkScriptResourceIntegrity(Resource* resource, Element* element) {
|
| return true;
|
|
|
| bool passed = SubresourceIntegrity::CheckSubresourceIntegrity(
|
| - scriptResource->integrityMetadata(), *element,
|
| + scriptResource->integrityMetadata(), scriptLoaderClient->document(),
|
| resource->resourceBuffer()->data(),
|
| resource->resourceBuffer()->size(), resource->url(), *resource);
|
| scriptResource->setIntegrityDisposition(
|
| @@ -197,8 +200,10 @@ void PendingScript::notifyFinished(Resource* resource) {
|
| //
|
| // See https://crbug.com/500701 for more information.
|
| checkState();
|
| - if (m_element)
|
| - m_integrityFailure = !checkScriptResourceIntegrity(resource, m_element);
|
| + if (m_scriptLoaderClient) {
|
| + m_integrityFailure =
|
| + !checkScriptResourceIntegrity(resource, m_scriptLoaderClient);
|
| + }
|
|
|
| // If script streaming is in use, the client will be notified in
|
| // streamingFinished.
|
| @@ -214,7 +219,7 @@ void PendingScript::notifyAppendData(ScriptResource* resource) {
|
| }
|
|
|
| DEFINE_TRACE(PendingScript) {
|
| - visitor->trace(m_element);
|
| + visitor->trace(m_scriptLoaderClient);
|
| visitor->trace(m_streamer);
|
| visitor->trace(m_client);
|
| ResourceOwner<ScriptResource>::trace(visitor);
|
| @@ -233,7 +238,7 @@ ScriptSourceCode PendingScript::getSource(const KURL& documentURL,
|
| return ScriptSourceCode(resource());
|
| }
|
|
|
| - return ScriptSourceCode(m_element->textContent(), documentURL,
|
| + return ScriptSourceCode(m_scriptLoaderClient->textContent(), documentURL,
|
| startingPosition());
|
| }
|
|
|
|
|