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

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

Issue 1163543002: Reland "Correctly set ScriptState in the image loader microtask" (Closed) Base URL: svn://svn.chromium.org/blink/trunk
Patch Set: updates 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 42 matching lines...) Expand 10 before | Expand all | Expand 10 after
78 { 81 {
79 return adoptPtr(new Task(loader, updateBehavior)); 82 return adoptPtr(new Task(loader, updateBehavior));
80 } 83 }
81 84
82 Task(ImageLoader* loader, UpdateFromElementBehavior updateBehavior) 85 Task(ImageLoader* loader, UpdateFromElementBehavior updateBehavior)
83 : m_loader(loader) 86 : m_loader(loader)
84 , m_shouldBypassMainWorldCSP(shouldBypassMainWorldCSP(loader)) 87 , m_shouldBypassMainWorldCSP(shouldBypassMainWorldCSP(loader))
85 , m_updateBehavior(updateBehavior) 88 , m_updateBehavior(updateBehavior)
86 , m_weakFactory(this) 89 , m_weakFactory(this)
87 { 90 {
91 v8::Isolate* isolate = V8PerIsolateData::mainThreadIsolate();
92 v8::HandleScope scope(isolate);
93 v8::Local<v8::Context> context = isolate->GetCurrentContext();
94 // If we're invoked from C++ without a V8 context on the stack, we shoul d
95 // run the microtask in the context of the element's document's main wor ld.
96 if (context.IsEmpty())
97 m_scriptState = ScriptState::from(toV8Context(&loader->element()->do cument(), DOMWrapperWorld::mainWorld()));
98 else
99 m_scriptState = ScriptState::from(context);
88 } 100 }
89 101
90 virtual void run() override 102 ~Task() override
103 {
104 }
105
106 void run() override
91 { 107 {
92 if (m_loader) { 108 if (m_loader) {
93 #if ENABLE(OILPAN) 109 #if ENABLE(OILPAN)
94 // Oilpan: this WebThread::Task microtask may run after the 110 // Oilpan: this WebThread::Task microtask may run after the
95 // loader has been GCed, but not yet lazily swept & finalized 111 // loader has been GCed, but not yet lazily swept & finalized
96 // (when this task's loader reference will be cleared.) 112 // (when this task's loader reference will be cleared.)
97 // 113 //
98 // Handle this transient condition by explicitly checking here 114 // Handle this transient condition by explicitly checking here
99 // before going ahead with the update operation. Unsafe to do it 115 // before going ahead with the update operation. Unsafe to do it
100 // if so, as the objects that the loader refers to may have been 116 // if so, as the objects that the loader refers to may have been
101 // finalized by this time. 117 // finalized by this time.
102 if (Heap::willObjectBeLazilySwept(m_loader)) 118 if (Heap::willObjectBeLazilySwept(m_loader))
103 return; 119 return;
104 #endif 120 #endif
105 m_loader->doUpdateFromElement(m_shouldBypassMainWorldCSP, m_updateBe havior); 121 if (m_scriptState->contextIsValid()) {
122 ScriptState::Scope scope(m_scriptState.get());
123 m_loader->doUpdateFromElement(m_shouldBypassMainWorldCSP, m_upda teBehavior);
124 } else {
125 m_loader->doUpdateFromElement(m_shouldBypassMainWorldCSP, m_upda teBehavior);
haraken 2015/05/28 11:48:58 It's not clear that this never reaches shouldBypas
126 }
106 } 127 }
107 } 128 }
108 129
109 void clearLoader() 130 void clearLoader()
110 { 131 {
111 m_loader = 0; 132 m_loader = 0;
133 m_scriptState.clear();
112 } 134 }
113 135
114 WeakPtr<Task> createWeakPtr() 136 WeakPtr<Task> createWeakPtr()
115 { 137 {
116 return m_weakFactory.createWeakPtr(); 138 return m_weakFactory.createWeakPtr();
117 } 139 }
118 140
119 private: 141 private:
120 ImageLoader* m_loader; 142 ImageLoader* m_loader;
121 BypassMainWorldBehavior m_shouldBypassMainWorldCSP; 143 BypassMainWorldBehavior m_shouldBypassMainWorldCSP;
122 UpdateFromElementBehavior m_updateBehavior; 144 UpdateFromElementBehavior m_updateBehavior;
145 RefPtr<ScriptState> m_scriptState;
123 WeakPtrFactory<Task> m_weakFactory; 146 WeakPtrFactory<Task> m_weakFactory;
124 }; 147 };
125 148
126 ImageLoader::ImageLoader(Element* element) 149 ImageLoader::ImageLoader(Element* element)
127 : m_element(element) 150 : m_element(element)
128 , m_image(0) 151 , m_image(0)
129 , m_derefElementTimer(this, &ImageLoader::timerFired) 152 , m_derefElementTimer(this, &ImageLoader::timerFired)
130 , m_hasPendingLoadEvent(false) 153 , m_hasPendingLoadEvent(false)
131 , m_hasPendingErrorEvent(false) 154 , m_hasPendingErrorEvent(false)
132 , m_imageComplete(true) 155 , m_imageComplete(true)
(...skipping 489 matching lines...) Expand 10 before | Expand all | Expand 10 after
622 #endif 645 #endif
623 } 646 }
624 647
625 #if ENABLE(OILPAN) 648 #if ENABLE(OILPAN)
626 ImageLoader::ImageLoaderClientRemover::~ImageLoaderClientRemover() 649 ImageLoader::ImageLoaderClientRemover::~ImageLoaderClientRemover()
627 { 650 {
628 m_loader.willRemoveClient(m_client); 651 m_loader.willRemoveClient(m_client);
629 } 652 }
630 #endif 653 #endif
631 } 654 }
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