| OLD | NEW |
| 1 /* | 1 /* |
| 2 * Copyright (C) 2010 Google, Inc. All Rights Reserved. | 2 * Copyright (C) 2010 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 | 5 * modification, are permitted provided that the following conditions |
| 6 * are met: | 6 * are met: |
| 7 * 1. Redistributions of source code must retain the above copyright | 7 * 1. Redistributions of source code must retain the above copyright |
| 8 * notice, this list of conditions and the following disclaimer. | 8 * notice, this list of conditions and the following disclaimer. |
| 9 * 2. Redistributions in binary form must reproduce the above copyright | 9 * 2. Redistributions in binary form must reproduce the above copyright |
| 10 * notice, this list of conditions and the following disclaimer in the | 10 * notice, this list of conditions and the following disclaimer in the |
| (...skipping 17 matching lines...) Expand all Loading... |
| 28 #include "bindings/core/v8/ScriptSourceCode.h" | 28 #include "bindings/core/v8/ScriptSourceCode.h" |
| 29 #include "core/dom/Element.h" | 29 #include "core/dom/Element.h" |
| 30 #include "core/frame/SubresourceIntegrity.h" | 30 #include "core/frame/SubresourceIntegrity.h" |
| 31 #include "platform/SharedBuffer.h" | 31 #include "platform/SharedBuffer.h" |
| 32 #include "wtf/CurrentTime.h" | 32 #include "wtf/CurrentTime.h" |
| 33 | 33 |
| 34 namespace blink { | 34 namespace blink { |
| 35 | 35 |
| 36 PendingScript* PendingScript::create(Element* element, | 36 PendingScript* PendingScript::create(Element* element, |
| 37 ScriptResource* resource) { | 37 ScriptResource* resource) { |
| 38 return new PendingScript(element, resource); | 38 return new PendingScript(element, resource, TextPosition()); |
| 39 } | 39 } |
| 40 | 40 |
| 41 PendingScript::PendingScript(Element* element, ScriptResource* resource) | 41 PendingScript* PendingScript::create(Element* element, |
| 42 const TextPosition& startingPosition) { |
| 43 return new PendingScript(element, nullptr, startingPosition); |
| 44 } |
| 45 |
| 46 PendingScript* PendingScript::createForTesting(ScriptResource* resource) { |
| 47 return new PendingScript(nullptr, resource, TextPosition(), true); |
| 48 } |
| 49 |
| 50 PendingScript::PendingScript(Element* element, |
| 51 ScriptResource* resource, |
| 52 const TextPosition& startingPosition, |
| 53 bool isForTesting) |
| 42 : m_watchingForLoad(false), | 54 : m_watchingForLoad(false), |
| 43 m_element(element), | 55 m_element(element), |
| 56 m_startingPosition(startingPosition), |
| 44 m_integrityFailure(false), | 57 m_integrityFailure(false), |
| 45 m_parserBlockingLoadStartTime(0), | 58 m_parserBlockingLoadStartTime(0), |
| 46 m_client(nullptr) { | 59 m_client(nullptr), |
| 47 setScriptResource(resource); | 60 m_isForTesting(isForTesting) { |
| 61 CHECK(m_isForTesting || m_element); |
| 62 setResource(resource); |
| 48 MemoryCoordinator::instance().registerClient(this); | 63 MemoryCoordinator::instance().registerClient(this); |
| 49 } | 64 } |
| 50 | 65 |
| 51 PendingScript::~PendingScript() {} | 66 PendingScript::~PendingScript() {} |
| 52 | 67 |
| 53 void PendingScript::dispose() { | 68 void PendingScript::dispose() { |
| 54 stopWatchingForLoad(); | 69 stopWatchingForLoad(); |
| 55 DCHECK(!m_client); | 70 DCHECK(!m_client); |
| 56 DCHECK(!m_watchingForLoad); | 71 DCHECK(!m_watchingForLoad); |
| 57 | 72 |
| 58 setScriptResource(nullptr); | 73 setResource(nullptr); |
| 59 m_startingPosition = TextPosition::belowRangePosition(); | 74 m_startingPosition = TextPosition::belowRangePosition(); |
| 60 m_integrityFailure = false; | 75 m_integrityFailure = false; |
| 61 m_parserBlockingLoadStartTime = 0; | 76 m_parserBlockingLoadStartTime = 0; |
| 62 if (m_streamer) | 77 if (m_streamer) |
| 63 m_streamer->cancel(); | 78 m_streamer->cancel(); |
| 64 m_streamer = nullptr; | 79 m_streamer = nullptr; |
| 65 m_element = nullptr; | 80 m_element = nullptr; |
| 66 } | 81 } |
| 67 | 82 |
| 68 void PendingScript::watchForLoad(PendingScriptClient* client) { | 83 void PendingScript::watchForLoad(PendingScriptClient* client) { |
| (...skipping 10 matching lines...) Expand all Loading... |
| 79 } | 94 } |
| 80 | 95 |
| 81 void PendingScript::stopWatchingForLoad() { | 96 void PendingScript::stopWatchingForLoad() { |
| 82 if (!m_watchingForLoad) | 97 if (!m_watchingForLoad) |
| 83 return; | 98 return; |
| 84 DCHECK(resource()); | 99 DCHECK(resource()); |
| 85 m_client = nullptr; | 100 m_client = nullptr; |
| 86 m_watchingForLoad = false; | 101 m_watchingForLoad = false; |
| 87 } | 102 } |
| 88 | 103 |
| 104 Element* PendingScript::element() const { |
| 105 // As mentioned in the comment at |m_element| declaration, |m_element| |
| 106 // must points to the corresponding ScriptLoader's element. |
| 107 CHECK(m_element); |
| 108 return m_element.get(); |
| 109 } |
| 110 |
| 89 void PendingScript::streamingFinished() { | 111 void PendingScript::streamingFinished() { |
| 90 DCHECK(resource()); | 112 DCHECK(resource()); |
| 91 if (m_client) | 113 if (m_client) |
| 92 m_client->pendingScriptFinished(this); | 114 m_client->pendingScriptFinished(this); |
| 93 } | 115 } |
| 94 | 116 |
| 95 void PendingScript::setElement(Element* element) { | |
| 96 m_element = element; | |
| 97 } | |
| 98 | |
| 99 void PendingScript::setScriptResource(ScriptResource* resource) { | |
| 100 setResource(resource); | |
| 101 } | |
| 102 | |
| 103 void PendingScript::markParserBlockingLoadStartTime() { | 117 void PendingScript::markParserBlockingLoadStartTime() { |
| 104 DCHECK_EQ(m_parserBlockingLoadStartTime, 0.0); | 118 DCHECK_EQ(m_parserBlockingLoadStartTime, 0.0); |
| 105 m_parserBlockingLoadStartTime = monotonicallyIncreasingTime(); | 119 m_parserBlockingLoadStartTime = monotonicallyIncreasingTime(); |
| 106 } | 120 } |
| 107 | 121 |
| 108 void PendingScript::notifyFinished(Resource* resource) { | 122 void PendingScript::notifyFinished(Resource* resource) { |
| 109 // The following SRI checks need to be here because, unfortunately, fetches | 123 // The following SRI checks need to be here because, unfortunately, fetches |
| 110 // are not done purely according to the Fetch spec. In particular, | 124 // are not done purely according to the Fetch spec. In particular, |
| 111 // different requests for the same resource do not have different | 125 // different requests for the same resource do not have different |
| 112 // responses; the memory cache can (and will) return the exact same | 126 // responses; the memory cache can (and will) return the exact same |
| 113 // Resource object. | 127 // Resource object. |
| 114 // | 128 // |
| 115 // For different requests, the same Resource object will be returned and | 129 // For different requests, the same Resource object will be returned and |
| 116 // will not be associated with the particular request. Therefore, when the | 130 // will not be associated with the particular request. Therefore, when the |
| 117 // body of the response comes in, there's no way to validate the integrity | 131 // body of the response comes in, there's no way to validate the integrity |
| 118 // of the Resource object against a particular request (since there may be | 132 // of the Resource object against a particular request (since there may be |
| 119 // several pending requests all tied to the identical object, and the | 133 // several pending requests all tied to the identical object, and the |
| 120 // actual requests are not stored). | 134 // actual requests are not stored). |
| 121 // | 135 // |
| 122 // In order to simulate the correct behavior, Blink explicitly does the SRI | 136 // In order to simulate the correct behavior, Blink explicitly does the SRI |
| 123 // checks here, when a PendingScript tied to a particular request is | 137 // checks here, when a PendingScript tied to a particular request is |
| 124 // finished (and in the case of a StyleSheet, at the point of execution), | 138 // finished (and in the case of a StyleSheet, at the point of execution), |
| 125 // while having proper Fetch checks in the fetch module for use in the | 139 // while having proper Fetch checks in the fetch module for use in the |
| 126 // fetch JavaScript API. In a future world where the ResourceFetcher uses | 140 // fetch JavaScript API. In a future world where the ResourceFetcher uses |
| 127 // the Fetch algorithm, this should be fixed by having separate Response | 141 // the Fetch algorithm, this should be fixed by having separate Response |
| 128 // objects (perhaps attached to identical Resource objects) per request. | 142 // objects (perhaps attached to identical Resource objects) per request. |
| 129 // | 143 // |
| 130 // See https://crbug.com/500701 for more information. | 144 // See https://crbug.com/500701 for more information. |
| 145 CHECK(m_isForTesting || m_element); |
| 131 if (m_element) { | 146 if (m_element) { |
| 132 DCHECK_EQ(resource->getType(), Resource::Script); | 147 DCHECK_EQ(resource->getType(), Resource::Script); |
| 133 ScriptResource* scriptResource = toScriptResource(resource); | 148 ScriptResource* scriptResource = toScriptResource(resource); |
| 134 String integrityAttr = | 149 String integrityAttr = |
| 135 m_element->fastGetAttribute(HTMLNames::integrityAttr); | 150 m_element->fastGetAttribute(HTMLNames::integrityAttr); |
| 136 | 151 |
| 137 // It is possible to get back a script resource with integrity metadata | 152 // It is possible to get back a script resource with integrity metadata |
| 138 // for a request with an empty integrity attribute. In that case, the | 153 // for a request with an empty integrity attribute. In that case, the |
| 139 // integrity check should be skipped, so this check ensures that the | 154 // integrity check should be skipped, so this check ensures that the |
| 140 // integrity attribute isn't empty in addition to checking if the | 155 // integrity attribute isn't empty in addition to checking if the |
| (...skipping 78 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 219 } | 234 } |
| 220 | 235 |
| 221 void PendingScript::onPurgeMemory() { | 236 void PendingScript::onPurgeMemory() { |
| 222 if (!m_streamer) | 237 if (!m_streamer) |
| 223 return; | 238 return; |
| 224 m_streamer->cancel(); | 239 m_streamer->cancel(); |
| 225 m_streamer = nullptr; | 240 m_streamer = nullptr; |
| 226 } | 241 } |
| 227 | 242 |
| 228 } // namespace blink | 243 } // namespace blink |
| OLD | NEW |