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 CHECK(m_element); | |
sof
2017/02/16 08:15:15
Could you xref the element() declaration's comment
hiroshige
2017/02/17 23:15:15
Done.
| |
106 return m_element.get(); | |
107 } | |
108 | |
89 void PendingScript::streamingFinished() { | 109 void PendingScript::streamingFinished() { |
90 DCHECK(resource()); | 110 DCHECK(resource()); |
91 if (m_client) | 111 if (m_client) |
92 m_client->pendingScriptFinished(this); | 112 m_client->pendingScriptFinished(this); |
93 } | 113 } |
94 | 114 |
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() { | 115 void PendingScript::markParserBlockingLoadStartTime() { |
104 DCHECK_EQ(m_parserBlockingLoadStartTime, 0.0); | 116 DCHECK_EQ(m_parserBlockingLoadStartTime, 0.0); |
105 m_parserBlockingLoadStartTime = monotonicallyIncreasingTime(); | 117 m_parserBlockingLoadStartTime = monotonicallyIncreasingTime(); |
106 } | 118 } |
107 | 119 |
108 void PendingScript::notifyFinished(Resource* resource) { | 120 void PendingScript::notifyFinished(Resource* resource) { |
109 // The following SRI checks need to be here because, unfortunately, fetches | 121 // The following SRI checks need to be here because, unfortunately, fetches |
110 // are not done purely according to the Fetch spec. In particular, | 122 // are not done purely according to the Fetch spec. In particular, |
111 // different requests for the same resource do not have different | 123 // different requests for the same resource do not have different |
112 // responses; the memory cache can (and will) return the exact same | 124 // responses; the memory cache can (and will) return the exact same |
113 // Resource object. | 125 // Resource object. |
114 // | 126 // |
115 // For different requests, the same Resource object will be returned and | 127 // For different requests, the same Resource object will be returned and |
116 // will not be associated with the particular request. Therefore, when the | 128 // 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 | 129 // 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 | 130 // of the Resource object against a particular request (since there may be |
119 // several pending requests all tied to the identical object, and the | 131 // several pending requests all tied to the identical object, and the |
120 // actual requests are not stored). | 132 // actual requests are not stored). |
121 // | 133 // |
122 // In order to simulate the correct behavior, Blink explicitly does the SRI | 134 // In order to simulate the correct behavior, Blink explicitly does the SRI |
123 // checks here, when a PendingScript tied to a particular request is | 135 // 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), | 136 // 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 | 137 // 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 | 138 // fetch JavaScript API. In a future world where the ResourceFetcher uses |
127 // the Fetch algorithm, this should be fixed by having separate Response | 139 // the Fetch algorithm, this should be fixed by having separate Response |
128 // objects (perhaps attached to identical Resource objects) per request. | 140 // objects (perhaps attached to identical Resource objects) per request. |
129 // | 141 // |
130 // See https://crbug.com/500701 for more information. | 142 // See https://crbug.com/500701 for more information. |
143 CHECK(m_isForTesting || m_element); | |
131 if (m_element) { | 144 if (m_element) { |
sof
2017/02/16 08:15:15
Not part of this CL at all, but moving this SRI-sp
hiroshige
2017/02/17 23:15:15
Created https://codereview.chromium.org/2698613007
| |
132 DCHECK_EQ(resource->getType(), Resource::Script); | 145 DCHECK_EQ(resource->getType(), Resource::Script); |
133 ScriptResource* scriptResource = toScriptResource(resource); | 146 ScriptResource* scriptResource = toScriptResource(resource); |
134 String integrityAttr = | 147 String integrityAttr = |
135 m_element->fastGetAttribute(HTMLNames::integrityAttr); | 148 m_element->fastGetAttribute(HTMLNames::integrityAttr); |
136 | 149 |
137 // It is possible to get back a script resource with integrity metadata | 150 // 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 | 151 // for a request with an empty integrity attribute. In that case, the |
139 // integrity check should be skipped, so this check ensures that the | 152 // integrity check should be skipped, so this check ensures that the |
140 // integrity attribute isn't empty in addition to checking if the | 153 // integrity attribute isn't empty in addition to checking if the |
141 // resource has empty integrity metadata. | 154 // resource has empty integrity metadata. |
(...skipping 77 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
219 } | 232 } |
220 | 233 |
221 void PendingScript::onPurgeMemory() { | 234 void PendingScript::onPurgeMemory() { |
222 if (!m_streamer) | 235 if (!m_streamer) |
223 return; | 236 return; |
224 m_streamer->cancel(); | 237 m_streamer->cancel(); |
225 m_streamer = nullptr; | 238 m_streamer = nullptr; |
226 } | 239 } |
227 | 240 |
228 } // namespace blink | 241 } // namespace blink |
OLD | NEW |