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 m_requestURL = loader->imageSourceToKURL(loader->element()->imageSourceU
RL()); |
110 } | 111 } |
111 | 112 |
112 void run() | 113 void run() |
113 { | 114 { |
114 if (!m_loader) | 115 if (!m_loader) |
115 return; | 116 return; |
116 ExecutionContext& context = m_loader->element()->document(); | 117 ExecutionContext& context = m_loader->element()->document(); |
117 InspectorInstrumentation::AsyncTask asyncTask(&context, this); | 118 InspectorInstrumentation::AsyncTask asyncTask(&context, this); |
118 if (m_scriptState->contextIsValid()) { | 119 if (m_scriptState->contextIsValid()) { |
119 ScriptState::Scope scope(m_scriptState.get()); | 120 ScriptState::Scope scope(m_scriptState.get()); |
120 m_loader->doUpdateFromElement(m_shouldBypassMainWorldCSP, m_updateBe
havior, m_referrerPolicy); | 121 m_loader->doUpdateFromElement(m_shouldBypassMainWorldCSP, m_updateBe
havior, m_requestURL, m_referrerPolicy); |
121 } else { | 122 } else { |
122 m_loader->doUpdateFromElement(m_shouldBypassMainWorldCSP, m_updateBe
havior, m_referrerPolicy); | 123 m_loader->doUpdateFromElement(m_shouldBypassMainWorldCSP, m_updateBe
havior, m_requestURL, m_referrerPolicy); |
123 } | 124 } |
124 } | 125 } |
125 | 126 |
126 void clearLoader() | 127 void clearLoader() |
127 { | 128 { |
128 m_loader = nullptr; | 129 m_loader = nullptr; |
129 m_scriptState.clear(); | 130 m_scriptState.clear(); |
130 } | 131 } |
131 | 132 |
132 WeakPtr<Task> createWeakPtr() | 133 WeakPtr<Task> createWeakPtr() |
133 { | 134 { |
134 return m_weakFactory.createWeakPtr(); | 135 return m_weakFactory.createWeakPtr(); |
135 } | 136 } |
136 | 137 |
137 private: | 138 private: |
138 WeakPersistent<ImageLoader> m_loader; | 139 WeakPersistent<ImageLoader> m_loader; |
139 BypassMainWorldBehavior m_shouldBypassMainWorldCSP; | 140 BypassMainWorldBehavior m_shouldBypassMainWorldCSP; |
140 UpdateFromElementBehavior m_updateBehavior; | 141 UpdateFromElementBehavior m_updateBehavior; |
141 RefPtr<ScriptState> m_scriptState; | 142 RefPtr<ScriptState> m_scriptState; |
142 WeakPtrFactory<Task> m_weakFactory; | 143 WeakPtrFactory<Task> m_weakFactory; |
143 ReferrerPolicy m_referrerPolicy; | 144 ReferrerPolicy m_referrerPolicy; |
| 145 KURL m_requestURL; |
144 }; | 146 }; |
145 | 147 |
146 ImageLoader::ImageLoader(Element* element) | 148 ImageLoader::ImageLoader(Element* element) |
147 : m_element(element) | 149 : m_element(element) |
148 , m_derefElementTimer(this, &ImageLoader::timerFired) | 150 , m_derefElementTimer(this, &ImageLoader::timerFired) |
149 , m_hasPendingLoadEvent(false) | 151 , m_hasPendingLoadEvent(false) |
150 , m_hasPendingErrorEvent(false) | 152 , m_hasPendingErrorEvent(false) |
151 , m_imageComplete(true) | 153 , m_imageComplete(true) |
152 , m_loadingImageDocument(false) | 154 , m_loadingImageDocument(false) |
153 , m_elementIsProtected(false) | 155 , m_elementIsProtected(false) |
(...skipping 90 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
244 } | 246 } |
245 | 247 |
246 inline void ImageLoader::enqueueImageLoadingMicroTask(UpdateFromElementBehavior
updateBehavior, ReferrerPolicy referrerPolicy) | 248 inline void ImageLoader::enqueueImageLoadingMicroTask(UpdateFromElementBehavior
updateBehavior, ReferrerPolicy referrerPolicy) |
247 { | 249 { |
248 std::unique_ptr<Task> task = Task::create(this, updateBehavior, referrerPoli
cy); | 250 std::unique_ptr<Task> task = Task::create(this, updateBehavior, referrerPoli
cy); |
249 m_pendingTask = task->createWeakPtr(); | 251 m_pendingTask = task->createWeakPtr(); |
250 Microtask::enqueueMicrotask(WTF::bind(&Task::run, passed(std::move(task)))); | 252 Microtask::enqueueMicrotask(WTF::bind(&Task::run, passed(std::move(task)))); |
251 m_loadDelayCounter = IncrementLoadEventDelayCount::create(m_element->documen
t()); | 253 m_loadDelayCounter = IncrementLoadEventDelayCount::create(m_element->documen
t()); |
252 } | 254 } |
253 | 255 |
254 void ImageLoader::doUpdateFromElement(BypassMainWorldBehavior bypassBehavior, Up
dateFromElementBehavior updateBehavior, ReferrerPolicy referrerPolicy) | 256 void ImageLoader::doUpdateFromElement(BypassMainWorldBehavior bypassBehavior, Up
dateFromElementBehavior updateBehavior, const KURL& url, ReferrerPolicy referrer
Policy) |
255 { | 257 { |
256 // FIXME: According to | 258 // 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 | 259 // 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. | 260 // 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. | 261 // That is currently not the case. |
260 // | 262 // |
261 // We don't need to call clearLoader here: Either we were called from the | 263 // 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 | 264 // task, or our caller updateFromElement cleared the task's loader (and set |
263 // m_pendingTask to null). | 265 // m_pendingTask to null). |
264 m_pendingTask.clear(); | 266 m_pendingTask.clear(); |
265 // Make sure to only decrement the count when we exit this function | 267 // Make sure to only decrement the count when we exit this function |
266 std::unique_ptr<IncrementLoadEventDelayCount> loadDelayCounter; | 268 std::unique_ptr<IncrementLoadEventDelayCount> loadDelayCounter; |
267 loadDelayCounter.swap(m_loadDelayCounter); | 269 loadDelayCounter.swap(m_loadDelayCounter); |
268 | 270 |
269 Document& document = m_element->document(); | 271 Document& document = m_element->document(); |
270 if (!document.isActive()) | 272 if (!document.isActive()) |
271 return; | 273 return; |
272 | 274 |
273 AtomicString imageSourceURL = m_element->imageSourceURL(); | 275 AtomicString imageSourceURL = m_element->imageSourceURL(); |
274 KURL url = imageSourceToKURL(imageSourceURL); | |
275 ImageResource* newImage = nullptr; | 276 ImageResource* newImage = nullptr; |
276 if (!url.isNull()) { | 277 if (!url.isNull()) { |
277 // Unlike raw <img>, we block mixed content inside of <picture> or <img
srcset>. | 278 // Unlike raw <img>, we block mixed content inside of <picture> or <img
srcset>. |
278 ResourceLoaderOptions resourceLoaderOptions = ResourceFetcher::defaultRe
sourceOptions(); | 279 ResourceLoaderOptions resourceLoaderOptions = ResourceFetcher::defaultRe
sourceOptions(); |
279 ResourceRequest resourceRequest(url); | 280 ResourceRequest resourceRequest(url); |
280 if (updateBehavior == UpdateForcedReload) { | 281 if (updateBehavior == UpdateForcedReload) { |
281 resourceRequest.setCachePolicy(WebCachePolicy::BypassingCache); | 282 resourceRequest.setCachePolicy(WebCachePolicy::BypassingCache); |
282 resourceRequest.setLoFiState(WebURLRequest::LoFiOff); | 283 resourceRequest.setLoFiState(WebURLRequest::LoFiOff); |
283 } | 284 } |
284 | 285 |
(...skipping 86 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
371 | 372 |
372 // If we have a pending task, we have to clear it -- either we're | 373 // 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. | 374 // now loading immediately, or we need to reset the task's state. |
374 if (m_pendingTask) { | 375 if (m_pendingTask) { |
375 m_pendingTask->clearLoader(); | 376 m_pendingTask->clearLoader(); |
376 m_pendingTask.clear(); | 377 m_pendingTask.clear(); |
377 } | 378 } |
378 | 379 |
379 KURL url = imageSourceToKURL(imageSourceURL); | 380 KURL url = imageSourceToKURL(imageSourceURL); |
380 if (shouldLoadImmediately(url)) { | 381 if (shouldLoadImmediately(url)) { |
381 doUpdateFromElement(DoNotBypassMainWorldCSP, updateBehavior, referrerPol
icy); | 382 doUpdateFromElement(DoNotBypassMainWorldCSP, updateBehavior, url, referr
erPolicy); |
382 return; | 383 return; |
383 } | 384 } |
384 // Allow the idiom "img.src=''; img.src='.." to clear down the image before | 385 // Allow the idiom "img.src=''; img.src='.." to clear down the image before |
385 // an asynchronous load completes. | 386 // an asynchronous load completes. |
386 if (imageSourceURL.isEmpty()) { | 387 if (imageSourceURL.isEmpty()) { |
387 ImageResource* image = m_image.get(); | 388 ImageResource* image = m_image.get(); |
388 if (image) { | 389 if (image) { |
389 image->removeObserver(this); | 390 image->removeObserver(this); |
390 } | 391 } |
391 m_image = nullptr; | 392 m_image = nullptr; |
(...skipping 211 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
603 | 604 |
604 void ImageLoader::elementDidMoveToNewDocument() | 605 void ImageLoader::elementDidMoveToNewDocument() |
605 { | 606 { |
606 if (m_loadDelayCounter) | 607 if (m_loadDelayCounter) |
607 m_loadDelayCounter->documentChanged(m_element->document()); | 608 m_loadDelayCounter->documentChanged(m_element->document()); |
608 clearFailedLoadURL(); | 609 clearFailedLoadURL(); |
609 setImage(0); | 610 setImage(0); |
610 } | 611 } |
611 | 612 |
612 } // namespace blink | 613 } // namespace blink |
OLD | NEW |