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 * |
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 Loading... | |
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); | |
haraken
2015/05/28 11:37:50
Nit: I think we should have the handle scope in ha
| |
93 if (ScriptState::hasCurrentScriptState(isolate)) { | |
94 m_scriptState = ScriptState::current(isolate); | |
95 } else { | |
96 m_scriptState = ScriptState::from(toV8Context(&loader->element()->do cument(), DOMWrapperWorld::mainWorld())); | |
haraken
2015/05/28 10:57:38
Why can't we always use the line 96?
ScriptState:
jochen (gone - plz use gerrit)
2015/05/28 11:16:49
there might be no context at all, so I need two ca
haraken
2015/05/28 11:37:50
OK, understood.
If JS creates a micro task, we sh
| |
97 } | |
88 } | 98 } |
89 | 99 |
90 virtual void run() override | 100 ~Task() override |
101 { | |
102 } | |
103 | |
104 void run() override | |
91 { | 105 { |
92 if (m_loader) { | 106 if (m_loader) { |
93 #if ENABLE(OILPAN) | 107 #if ENABLE(OILPAN) |
94 // Oilpan: this WebThread::Task microtask may run after the | 108 // Oilpan: this WebThread::Task microtask may run after the |
95 // loader has been GCed, but not yet lazily swept & finalized | 109 // loader has been GCed, but not yet lazily swept & finalized |
96 // (when this task's loader reference will be cleared.) | 110 // (when this task's loader reference will be cleared.) |
97 // | 111 // |
98 // Handle this transient condition by explicitly checking here | 112 // Handle this transient condition by explicitly checking here |
99 // before going ahead with the update operation. Unsafe to do it | 113 // 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 | 114 // if so, as the objects that the loader refers to may have been |
101 // finalized by this time. | 115 // finalized by this time. |
102 if (Heap::willObjectBeLazilySwept(m_loader)) | 116 if (Heap::willObjectBeLazilySwept(m_loader)) |
103 return; | 117 return; |
104 #endif | 118 #endif |
105 m_loader->doUpdateFromElement(m_shouldBypassMainWorldCSP, m_updateBe havior); | 119 if (m_scriptState->contextIsValid()) { |
120 v8::HandleScope handleScope(m_scriptState->isolate()); | |
haraken
2015/05/28 10:57:38
This wouldn't be needed, since the ScriptState::Sc
jochen (gone - plz use gerrit)
2015/05/28 11:16:49
done
| |
121 ScriptState::Scope scope(m_scriptState.get()); | |
122 m_loader->doUpdateFromElement(m_shouldBypassMainWorldCSP, m_upda teBehavior); | |
123 } else { | |
124 m_loader->doUpdateFromElement(m_shouldBypassMainWorldCSP, m_upda teBehavior); | |
haraken
2015/05/28 10:57:38
Do we really want to execute this when the context
jochen (gone - plz use gerrit)
2015/05/28 11:16:49
yes, the loader needs to clean itself up.
haraken
2015/05/28 11:37:50
In that scenario, wouldn't there be any risk of ex
| |
125 } | |
106 } | 126 } |
107 } | 127 } |
108 | 128 |
109 void clearLoader() | 129 void clearLoader() |
110 { | 130 { |
111 m_loader = 0; | 131 m_loader = 0; |
132 m_scriptState.clear(); | |
112 } | 133 } |
113 | 134 |
114 WeakPtr<Task> createWeakPtr() | 135 WeakPtr<Task> createWeakPtr() |
115 { | 136 { |
116 return m_weakFactory.createWeakPtr(); | 137 return m_weakFactory.createWeakPtr(); |
117 } | 138 } |
118 | 139 |
119 private: | 140 private: |
120 ImageLoader* m_loader; | 141 ImageLoader* m_loader; |
121 BypassMainWorldBehavior m_shouldBypassMainWorldCSP; | 142 BypassMainWorldBehavior m_shouldBypassMainWorldCSP; |
122 UpdateFromElementBehavior m_updateBehavior; | 143 UpdateFromElementBehavior m_updateBehavior; |
144 RefPtr<ScriptState> m_scriptState; | |
123 WeakPtrFactory<Task> m_weakFactory; | 145 WeakPtrFactory<Task> m_weakFactory; |
124 }; | 146 }; |
125 | 147 |
126 ImageLoader::ImageLoader(Element* element) | 148 ImageLoader::ImageLoader(Element* element) |
127 : m_element(element) | 149 : m_element(element) |
128 , m_image(0) | 150 , m_image(0) |
129 , m_derefElementTimer(this, &ImageLoader::timerFired) | 151 , m_derefElementTimer(this, &ImageLoader::timerFired) |
130 , m_hasPendingLoadEvent(false) | 152 , m_hasPendingLoadEvent(false) |
131 , m_hasPendingErrorEvent(false) | 153 , m_hasPendingErrorEvent(false) |
132 , m_imageComplete(true) | 154 , m_imageComplete(true) |
(...skipping 489 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
622 #endif | 644 #endif |
623 } | 645 } |
624 | 646 |
625 #if ENABLE(OILPAN) | 647 #if ENABLE(OILPAN) |
626 ImageLoader::ImageLoaderClientRemover::~ImageLoaderClientRemover() | 648 ImageLoader::ImageLoaderClientRemover::~ImageLoaderClientRemover() |
627 { | 649 { |
628 m_loader.willRemoveClient(m_client); | 650 m_loader.willRemoveClient(m_client); |
629 } | 651 } |
630 #endif | 652 #endif |
631 } | 653 } |
OLD | NEW |