Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(378)

Side by Side Diff: Source/core/loader/ImageLoader.cpp

Issue 1146223008: Merge 196071 "Reland "Correctly set ScriptState in the image loa..." (Closed) Base URL: svn://svn.chromium.org/blink/branches/chromium/2403/
Patch Set: Created 5 years, 6 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
« no previous file with comments | « Source/core/dom/Microtask.h ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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 *
11 * This library is distributed in the hope that it will be useful, 11 * This library is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of 12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14 * Library General Public License for more details. 14 * Library General Public License for more details.
15 * 15 *
16 * You should have received a copy of the GNU Library General Public License 16 * You should have received a copy of the GNU Library General Public License
17 * along with this library; see the file COPYING.LIB. If not, write to 17 * along with this library; see the file COPYING.LIB. If not, write to
18 * the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, 18 * the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
19 * Boston, MA 02110-1301, USA. 19 * Boston, MA 02110-1301, USA.
20 */ 20 */
21 21
22 #include "config.h" 22 #include "config.h"
23 #include "core/loader/ImageLoader.h" 23 #include "core/loader/ImageLoader.h"
24 24
25 #include "bindings/core/v8/ScriptController.h" 25 #include "bindings/core/v8/ScriptController.h"
26 #include "bindings/core/v8/ScriptState.h"
27 #include "bindings/core/v8/V8Binding.h"
28 #include "bindings/core/v8/V8PerIsolateData.h"
26 #include "core/dom/Document.h" 29 #include "core/dom/Document.h"
27 #include "core/dom/Element.h" 30 #include "core/dom/Element.h"
28 #include "core/dom/IncrementLoadEventDelayCount.h" 31 #include "core/dom/IncrementLoadEventDelayCount.h"
29 #include "core/dom/Microtask.h" 32 #include "core/dom/Microtask.h"
30 #include "core/events/Event.h" 33 #include "core/events/Event.h"
31 #include "core/events/EventSender.h" 34 #include "core/events/EventSender.h"
32 #include "core/fetch/FetchRequest.h" 35 #include "core/fetch/FetchRequest.h"
33 #include "core/fetch/MemoryCache.h" 36 #include "core/fetch/MemoryCache.h"
34 #include "core/fetch/ResourceFetcher.h" 37 #include "core/fetch/ResourceFetcher.h"
35 #include "core/frame/LocalFrame.h" 38 #include "core/frame/LocalFrame.h"
(...skipping 43 matching lines...) Expand 10 before | Expand all | Expand 10 after
79 { 82 {
80 return adoptPtr(new Task(loader, updateBehavior)); 83 return adoptPtr(new Task(loader, updateBehavior));
81 } 84 }
82 85
83 Task(ImageLoader* loader, UpdateFromElementBehavior updateBehavior) 86 Task(ImageLoader* loader, UpdateFromElementBehavior updateBehavior)
84 : m_loader(loader) 87 : m_loader(loader)
85 , m_shouldBypassMainWorldCSP(shouldBypassMainWorldCSP(loader)) 88 , m_shouldBypassMainWorldCSP(shouldBypassMainWorldCSP(loader))
86 , m_updateBehavior(updateBehavior) 89 , m_updateBehavior(updateBehavior)
87 , m_weakFactory(this) 90 , m_weakFactory(this)
88 { 91 {
92 v8::Isolate* isolate = V8PerIsolateData::mainThreadIsolate();
93 v8::HandleScope scope(isolate);
94 v8::Local<v8::Context> context = isolate->GetCurrentContext();
95 // If we're invoked from C++ without a V8 context on the stack, we shoul d
96 // run the microtask in the context of the element's document's main wor ld.
97 if (context.IsEmpty())
98 m_scriptState = ScriptState::from(toV8Context(&loader->element()->do cument(), DOMWrapperWorld::mainWorld()));
99 else
100 m_scriptState = ScriptState::from(context);
89 } 101 }
90 102
91 virtual void run() override 103 ~Task() override
104 {
105 }
106
107 void run() override
92 { 108 {
93 if (m_loader) { 109 if (m_loader) {
94 #if ENABLE(OILPAN) 110 #if ENABLE(OILPAN)
95 // Oilpan: this WebThread::Task microtask may run after the 111 // Oilpan: this WebThread::Task microtask may run after the
96 // loader has been GCed, but not yet lazily swept & finalized 112 // loader has been GCed, but not yet lazily swept & finalized
97 // (when this task's loader reference will be cleared.) 113 // (when this task's loader reference will be cleared.)
98 // 114 //
99 // Handle this transient condition by explicitly checking here 115 // Handle this transient condition by explicitly checking here
100 // before going ahead with the update operation. Unsafe to do it 116 // before going ahead with the update operation. Unsafe to do it
101 // if so, as the objects that the loader refers to may have been 117 // if so, as the objects that the loader refers to may have been
102 // finalized by this time. 118 // finalized by this time.
103 if (Heap::willObjectBeLazilySwept(m_loader)) 119 if (Heap::willObjectBeLazilySwept(m_loader))
104 return; 120 return;
105 #endif 121 #endif
106 m_loader->doUpdateFromElement(m_shouldBypassMainWorldCSP, m_updateBe havior); 122 if (m_scriptState->contextIsValid()) {
123 ScriptState::Scope scope(m_scriptState.get());
124 m_loader->doUpdateFromElement(m_shouldBypassMainWorldCSP, m_upda teBehavior);
125 } else {
126 m_loader->doUpdateFromElement(m_shouldBypassMainWorldCSP, m_upda teBehavior);
127 }
107 } 128 }
108 } 129 }
109 130
110 void clearLoader() 131 void clearLoader()
111 { 132 {
112 m_loader = 0; 133 m_loader = 0;
134 m_scriptState.clear();
113 } 135 }
114 136
115 WeakPtr<Task> createWeakPtr() 137 WeakPtr<Task> createWeakPtr()
116 { 138 {
117 return m_weakFactory.createWeakPtr(); 139 return m_weakFactory.createWeakPtr();
118 } 140 }
119 141
120 private: 142 private:
121 ImageLoader* m_loader; 143 ImageLoader* m_loader;
122 BypassMainWorldBehavior m_shouldBypassMainWorldCSP; 144 BypassMainWorldBehavior m_shouldBypassMainWorldCSP;
123 UpdateFromElementBehavior m_updateBehavior; 145 UpdateFromElementBehavior m_updateBehavior;
146 RefPtr<ScriptState> m_scriptState;
124 WeakPtrFactory<Task> m_weakFactory; 147 WeakPtrFactory<Task> m_weakFactory;
125 }; 148 };
126 149
127 ImageLoader::ImageLoader(Element* element) 150 ImageLoader::ImageLoader(Element* element)
128 : m_element(element) 151 : m_element(element)
129 , m_image(0) 152 , m_image(0)
130 , m_derefElementTimer(this, &ImageLoader::timerFired) 153 , m_derefElementTimer(this, &ImageLoader::timerFired)
131 , m_hasPendingLoadEvent(false) 154 , m_hasPendingLoadEvent(false)
132 , m_hasPendingErrorEvent(false) 155 , m_hasPendingErrorEvent(false)
133 , m_imageComplete(true) 156 , m_imageComplete(true)
(...skipping 235 matching lines...) Expand 10 before | Expand all | Expand 10 after
369 return; 392 return;
370 } 393 }
371 // Allow the idiom "img.src=''; img.src='.." to clear down the image before 394 // Allow the idiom "img.src=''; img.src='.." to clear down the image before
372 // an asynchronous load completes. 395 // an asynchronous load completes.
373 if (imageSourceURL.isEmpty()) { 396 if (imageSourceURL.isEmpty()) {
374 ImageResource* image = m_image.get(); 397 ImageResource* image = m_image.get();
375 if (image) 398 if (image)
376 image->removeClient(this); 399 image->removeClient(this);
377 m_image = nullptr; 400 m_image = nullptr;
378 } 401 }
379 enqueueImageLoadingMicroTask(updateBehavior); 402
403 // Don't load images for inactive documents. We don't want to slow down the
404 // raw HTML parsing case by loading images we don't intend to display.
405 Document& document = m_element->document();
406 if (document.isActive())
407 enqueueImageLoadingMicroTask(updateBehavior);
380 } 408 }
381 409
382 KURL ImageLoader::imageSourceToKURL(AtomicString imageSourceURL) const 410 KURL ImageLoader::imageSourceToKURL(AtomicString imageSourceURL) const
383 { 411 {
384 KURL url; 412 KURL url;
385 413
386 // Don't load images for inactive documents. We don't want to slow down the 414 // Don't load images for inactive documents. We don't want to slow down the
387 // raw HTML parsing case by loading images we don't intend to display. 415 // raw HTML parsing case by loading images we don't intend to display.
388 Document& document = m_element->document(); 416 Document& document = m_element->document();
389 if (!document.isActive()) 417 if (!document.isActive())
(...skipping 239 matching lines...) Expand 10 before | Expand all | Expand 10 after
629 #endif 657 #endif
630 } 658 }
631 659
632 #if ENABLE(OILPAN) 660 #if ENABLE(OILPAN)
633 ImageLoader::ImageLoaderClientRemover::~ImageLoaderClientRemover() 661 ImageLoader::ImageLoaderClientRemover::~ImageLoaderClientRemover()
634 { 662 {
635 m_loader.willRemoveClient(m_client); 663 m_loader.willRemoveClient(m_client);
636 } 664 }
637 #endif 665 #endif
638 } 666 }
OLDNEW
« no previous file with comments | « Source/core/dom/Microtask.h ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698