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 * Copyright (C) 2004, 2005, 2006, 2007, 2009, 2010 Apple Inc. All rights reserv
ed. | 4 * Copyright (C) 2004, 2005, 2006, 2007, 2009, 2010 Apple Inc. All rights reserv
ed. |
5 * | 5 * |
6 * This library is free software; you can redistribute it and/or | 6 * This library is free software; you can redistribute it and/or |
7 * modify it under the terms of the GNU Library General Public | 7 * modify it under the terms of the GNU Library General Public |
8 * License as published by the Free Software Foundation; either | 8 * License as published by the Free Software Foundation; either |
9 * version 2 of the License, or (at your option) any later version. | 9 * version 2 of the License, or (at your option) any later version. |
10 * | 10 * |
(...skipping 89 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
100 v8::Isolate* isolate = V8PerIsolateData::mainThreadIsolate(); | 100 v8::Isolate* isolate = V8PerIsolateData::mainThreadIsolate(); |
101 v8::HandleScope scope(isolate); | 101 v8::HandleScope scope(isolate); |
102 // If we're invoked from C++ without a V8 context on the stack, we shoul
d | 102 // If we're invoked from C++ without a V8 context on the stack, we shoul
d |
103 // run the microtask in the context of the element's document's main wor
ld. | 103 // run the microtask in the context of the element's document's main wor
ld. |
104 if (ScriptState::hasCurrentScriptState(isolate)) { | 104 if (ScriptState::hasCurrentScriptState(isolate)) { |
105 m_scriptState = ScriptState::current(isolate); | 105 m_scriptState = ScriptState::current(isolate); |
106 } else { | 106 } else { |
107 m_scriptState = ScriptState::forMainWorld(loader->element()->documen
t().frame()); | 107 m_scriptState = ScriptState::forMainWorld(loader->element()->documen
t().frame()); |
108 ASSERT(m_scriptState); | 108 ASSERT(m_scriptState); |
109 } | 109 } |
| 110 AtomicString imageSourceURL = loader->element()->imageSourceURL(); |
| 111 m_requestURL = loader->imageSourceToKURL(imageSourceURL); |
110 } | 112 } |
111 | 113 |
112 void run() | 114 void run() |
113 { | 115 { |
114 if (!m_loader) | 116 if (!m_loader) |
115 return; | 117 return; |
116 ExecutionContext& context = m_loader->element()->document(); | 118 ExecutionContext& context = m_loader->element()->document(); |
117 InspectorInstrumentation::AsyncTask asyncTask(&context, this); | 119 InspectorInstrumentation::AsyncTask asyncTask(&context, this); |
118 if (m_scriptState->contextIsValid()) { | 120 if (m_scriptState->contextIsValid()) { |
119 ScriptState::Scope scope(m_scriptState.get()); | 121 ScriptState::Scope scope(m_scriptState.get()); |
120 m_loader->doUpdateFromElement(m_shouldBypassMainWorldCSP, m_updateBe
havior, m_referrerPolicy); | 122 m_loader->doUpdateFromElement(m_shouldBypassMainWorldCSP, m_updateBe
havior, m_requestURL, m_referrerPolicy); |
121 } else { | 123 } else { |
122 m_loader->doUpdateFromElement(m_shouldBypassMainWorldCSP, m_updateBe
havior, m_referrerPolicy); | 124 m_loader->doUpdateFromElement(m_shouldBypassMainWorldCSP, m_updateBe
havior, m_requestURL, m_referrerPolicy); |
123 } | 125 } |
124 } | 126 } |
125 | 127 |
126 void clearLoader() | 128 void clearLoader() |
127 { | 129 { |
128 m_loader = nullptr; | 130 m_loader = nullptr; |
129 m_scriptState.clear(); | 131 m_scriptState.clear(); |
130 } | 132 } |
131 | 133 |
132 WeakPtr<Task> createWeakPtr() | 134 WeakPtr<Task> createWeakPtr() |
133 { | 135 { |
134 return m_weakFactory.createWeakPtr(); | 136 return m_weakFactory.createWeakPtr(); |
135 } | 137 } |
136 | 138 |
137 private: | 139 private: |
138 WeakPersistent<ImageLoader> m_loader; | 140 WeakPersistent<ImageLoader> m_loader; |
139 BypassMainWorldBehavior m_shouldBypassMainWorldCSP; | 141 BypassMainWorldBehavior m_shouldBypassMainWorldCSP; |
140 UpdateFromElementBehavior m_updateBehavior; | 142 UpdateFromElementBehavior m_updateBehavior; |
141 RefPtr<ScriptState> m_scriptState; | 143 RefPtr<ScriptState> m_scriptState; |
142 WeakPtrFactory<Task> m_weakFactory; | 144 WeakPtrFactory<Task> m_weakFactory; |
143 ReferrerPolicy m_referrerPolicy; | 145 ReferrerPolicy m_referrerPolicy; |
| 146 KURL m_requestURL; |
144 }; | 147 }; |
145 | 148 |
146 ImageLoader::ImageLoader(Element* element) | 149 ImageLoader::ImageLoader(Element* element) |
147 : m_element(element) | 150 : m_element(element) |
148 , m_derefElementTimer(this, &ImageLoader::timerFired) | 151 , m_derefElementTimer(this, &ImageLoader::timerFired) |
149 , m_hasPendingLoadEvent(false) | 152 , m_hasPendingLoadEvent(false) |
150 , m_hasPendingErrorEvent(false) | 153 , m_hasPendingErrorEvent(false) |
151 , m_imageComplete(true) | 154 , m_imageComplete(true) |
152 , m_loadingImageDocument(false) | 155 , m_loadingImageDocument(false) |
153 , m_elementIsProtected(false) | 156 , m_elementIsProtected(false) |
(...skipping 90 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
244 } | 247 } |
245 | 248 |
246 inline void ImageLoader::enqueueImageLoadingMicroTask(UpdateFromElementBehavior
updateBehavior, ReferrerPolicy referrerPolicy) | 249 inline void ImageLoader::enqueueImageLoadingMicroTask(UpdateFromElementBehavior
updateBehavior, ReferrerPolicy referrerPolicy) |
247 { | 250 { |
248 std::unique_ptr<Task> task = Task::create(this, updateBehavior, referrerPoli
cy); | 251 std::unique_ptr<Task> task = Task::create(this, updateBehavior, referrerPoli
cy); |
249 m_pendingTask = task->createWeakPtr(); | 252 m_pendingTask = task->createWeakPtr(); |
250 Microtask::enqueueMicrotask(WTF::bind(&Task::run, passed(std::move(task)))); | 253 Microtask::enqueueMicrotask(WTF::bind(&Task::run, passed(std::move(task)))); |
251 m_loadDelayCounter = IncrementLoadEventDelayCount::create(m_element->documen
t()); | 254 m_loadDelayCounter = IncrementLoadEventDelayCount::create(m_element->documen
t()); |
252 } | 255 } |
253 | 256 |
254 void ImageLoader::doUpdateFromElement(BypassMainWorldBehavior bypassBehavior, Up
dateFromElementBehavior updateBehavior, ReferrerPolicy referrerPolicy) | 257 void ImageLoader::doUpdateFromElement(BypassMainWorldBehavior bypassBehavior, Up
dateFromElementBehavior updateBehavior, const KURL& url, ReferrerPolicy referrer
Policy) |
255 { | 258 { |
256 // FIXME: According to | 259 // FIXME: According to |
257 // http://www.whatwg.org/specs/web-apps/current-work/multipage/embedded-cont
ent.html#the-img-element:the-img-element-55 | 260 // http://www.whatwg.org/specs/web-apps/current-work/multipage/embedded-cont
ent.html#the-img-element:the-img-element-55 |
258 // When "update image" is called due to environment changes and the load fai
ls, onerror should not be called. | 261 // When "update image" is called due to environment changes and the load fai
ls, onerror should not be called. |
259 // That is currently not the case. | 262 // That is currently not the case. |
260 // | 263 // |
261 // We don't need to call clearLoader here: Either we were called from the | 264 // We don't need to call clearLoader here: Either we were called from the |
262 // task, or our caller updateFromElement cleared the task's loader (and set | 265 // task, or our caller updateFromElement cleared the task's loader (and set |
263 // m_pendingTask to null). | 266 // m_pendingTask to null). |
264 m_pendingTask.clear(); | 267 m_pendingTask.clear(); |
265 // Make sure to only decrement the count when we exit this function | 268 // Make sure to only decrement the count when we exit this function |
266 std::unique_ptr<IncrementLoadEventDelayCount> loadDelayCounter; | 269 std::unique_ptr<IncrementLoadEventDelayCount> loadDelayCounter; |
267 loadDelayCounter.swap(m_loadDelayCounter); | 270 loadDelayCounter.swap(m_loadDelayCounter); |
268 | 271 |
269 Document& document = m_element->document(); | 272 Document& document = m_element->document(); |
270 if (!document.isActive()) | 273 if (!document.isActive()) |
271 return; | 274 return; |
272 | 275 |
273 AtomicString imageSourceURL = m_element->imageSourceURL(); | 276 AtomicString imageSourceURL = m_element->imageSourceURL(); |
274 KURL url = imageSourceToKURL(imageSourceURL); | |
275 ImageResource* newImage = nullptr; | 277 ImageResource* newImage = nullptr; |
276 if (!url.isNull()) { | 278 if (!url.isNull()) { |
277 // Unlike raw <img>, we block mixed content inside of <picture> or <img
srcset>. | 279 // Unlike raw <img>, we block mixed content inside of <picture> or <img
srcset>. |
278 ResourceLoaderOptions resourceLoaderOptions = ResourceFetcher::defaultRe
sourceOptions(); | 280 ResourceLoaderOptions resourceLoaderOptions = ResourceFetcher::defaultRe
sourceOptions(); |
279 ResourceRequest resourceRequest(url); | 281 ResourceRequest resourceRequest(url); |
280 if (updateBehavior == UpdateForcedReload) { | 282 if (updateBehavior == UpdateForcedReload) { |
281 resourceRequest.setCachePolicy(WebCachePolicy::BypassingCache); | 283 resourceRequest.setCachePolicy(WebCachePolicy::BypassingCache); |
282 resourceRequest.setLoFiState(WebURLRequest::LoFiOff); | 284 resourceRequest.setLoFiState(WebURLRequest::LoFiOff); |
283 } | 285 } |
284 | 286 |
(...skipping 86 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
371 | 373 |
372 // If we have a pending task, we have to clear it -- either we're | 374 // If we have a pending task, we have to clear it -- either we're |
373 // now loading immediately, or we need to reset the task's state. | 375 // now loading immediately, or we need to reset the task's state. |
374 if (m_pendingTask) { | 376 if (m_pendingTask) { |
375 m_pendingTask->clearLoader(); | 377 m_pendingTask->clearLoader(); |
376 m_pendingTask.clear(); | 378 m_pendingTask.clear(); |
377 } | 379 } |
378 | 380 |
379 KURL url = imageSourceToKURL(imageSourceURL); | 381 KURL url = imageSourceToKURL(imageSourceURL); |
380 if (shouldLoadImmediately(url)) { | 382 if (shouldLoadImmediately(url)) { |
381 doUpdateFromElement(DoNotBypassMainWorldCSP, updateBehavior, referrerPol
icy); | 383 doUpdateFromElement(DoNotBypassMainWorldCSP, updateBehavior, url, referr
erPolicy); |
382 return; | 384 return; |
383 } | 385 } |
384 // Allow the idiom "img.src=''; img.src='.." to clear down the image before | 386 // Allow the idiom "img.src=''; img.src='.." to clear down the image before |
385 // an asynchronous load completes. | 387 // an asynchronous load completes. |
386 if (imageSourceURL.isEmpty()) { | 388 if (imageSourceURL.isEmpty()) { |
387 ImageResource* image = m_image.get(); | 389 ImageResource* image = m_image.get(); |
388 if (image) { | 390 if (image) { |
389 image->removeObserver(this); | 391 image->removeObserver(this); |
390 } | 392 } |
391 m_image = nullptr; | 393 m_image = nullptr; |
(...skipping 211 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
603 | 605 |
604 void ImageLoader::elementDidMoveToNewDocument() | 606 void ImageLoader::elementDidMoveToNewDocument() |
605 { | 607 { |
606 if (m_loadDelayCounter) | 608 if (m_loadDelayCounter) |
607 m_loadDelayCounter->documentChanged(m_element->document()); | 609 m_loadDelayCounter->documentChanged(m_element->document()); |
608 clearFailedLoadURL(); | 610 clearFailedLoadURL(); |
609 setImage(0); | 611 setImage(0); |
610 } | 612 } |
611 | 613 |
612 } // namespace blink | 614 } // namespace blink |
OLD | NEW |