OLD | NEW |
1 /* | 1 /* |
2 * Copyright (C) 2008 Apple Inc. All Rights Reserved. | 2 * Copyright (C) 2008 Apple Inc. All Rights Reserved. |
3 * Copyright (C) 2012 Google Inc. All Rights Reserved. | 3 * Copyright (C) 2012 Google Inc. All Rights Reserved. |
4 * | 4 * |
5 * Redistribution and use in source and binary forms, with or without | 5 * Redistribution and use in source and binary forms, with or without |
6 * modification, are permitted provided that the following conditions | 6 * modification, are permitted provided that the following conditions |
7 * are met: | 7 * are met: |
8 * 1. Redistributions of source code must retain the above copyright | 8 * 1. Redistributions of source code must retain the above copyright |
9 * notice, this list of conditions and the following disclaimer. | 9 * notice, this list of conditions and the following disclaimer. |
10 * 2. Redistributions in binary form must reproduce the above copyright | 10 * 2. Redistributions in binary form must reproduce the above copyright |
(...skipping 10 matching lines...) Expand all Loading... |
21 * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY | 21 * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY |
22 * OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT | 22 * OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT |
23 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE | 23 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE |
24 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. | 24 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. |
25 * | 25 * |
26 */ | 26 */ |
27 | 27 |
28 #include "config.h" | 28 #include "config.h" |
29 #include "core/dom/ExecutionContext.h" | 29 #include "core/dom/ExecutionContext.h" |
30 | 30 |
| 31 #include "core/dom/ContextLifecycleNotifier.h" |
31 #include "core/dom/ExecutionContextTask.h" | 32 #include "core/dom/ExecutionContextTask.h" |
32 #include "core/events/ErrorEvent.h" | 33 #include "core/events/ErrorEvent.h" |
33 #include "core/events/EventTarget.h" | 34 #include "core/events/EventTarget.h" |
34 #include "core/html/PublicURLManager.h" | 35 #include "core/html/PublicURLManager.h" |
35 #include "core/inspector/InspectorInstrumentation.h" | 36 #include "core/inspector/InspectorInstrumentation.h" |
36 #include "core/inspector/ScriptCallStack.h" | 37 #include "core/inspector/ScriptCallStack.h" |
37 #include "core/page/WindowFocusAllowedIndicator.h" | 38 #include "core/page/WindowFocusAllowedIndicator.h" |
38 #include "core/workers/WorkerGlobalScope.h" | 39 #include "core/workers/WorkerGlobalScope.h" |
39 #include "core/workers/WorkerThread.h" | 40 #include "core/workers/WorkerThread.h" |
40 #include "wtf/MainThread.h" | 41 #include "wtf/MainThread.h" |
(...skipping 18 matching lines...) Expand all Loading... |
59 } | 60 } |
60 String m_errorMessage; | 61 String m_errorMessage; |
61 int m_lineNumber; | 62 int m_lineNumber; |
62 int m_columnNumber; | 63 int m_columnNumber; |
63 int m_scriptId; | 64 int m_scriptId; |
64 String m_sourceURL; | 65 String m_sourceURL; |
65 RefPtrWillBeMember<ScriptCallStack> m_callStack; | 66 RefPtrWillBeMember<ScriptCallStack> m_callStack; |
66 }; | 67 }; |
67 | 68 |
68 ExecutionContext::ExecutionContext() | 69 ExecutionContext::ExecutionContext() |
69 : ContextLifecycleNotifier(this) | 70 : m_circularSequentialID(0) |
70 , m_circularSequentialID(0) | |
71 , m_inDispatchErrorEvent(false) | 71 , m_inDispatchErrorEvent(false) |
72 , m_activeDOMObjectsAreSuspended(false) | 72 , m_activeDOMObjectsAreSuspended(false) |
73 , m_activeDOMObjectsAreStopped(false) | 73 , m_activeDOMObjectsAreStopped(false) |
74 , m_strictMixedContentCheckingEnforced(false) | 74 , m_strictMixedContentCheckingEnforced(false) |
75 , m_windowInteractionTokens(0) | 75 , m_windowFocusTokens(0) |
76 { | 76 { |
77 } | 77 } |
78 | 78 |
79 ExecutionContext::~ExecutionContext() | 79 ExecutionContext::~ExecutionContext() |
80 { | 80 { |
81 } | 81 } |
82 | 82 |
| 83 bool ExecutionContext::hasPendingActivity() |
| 84 { |
| 85 return lifecycleNotifier().hasPendingActivity(); |
| 86 } |
| 87 |
83 void ExecutionContext::suspendActiveDOMObjects() | 88 void ExecutionContext::suspendActiveDOMObjects() |
84 { | 89 { |
85 ASSERT(!m_activeDOMObjectsAreSuspended); | 90 ASSERT(!m_activeDOMObjectsAreSuspended); |
86 notifySuspendingActiveDOMObjects(); | 91 lifecycleNotifier().notifySuspendingActiveDOMObjects(); |
87 m_activeDOMObjectsAreSuspended = true; | 92 m_activeDOMObjectsAreSuspended = true; |
88 } | 93 } |
89 | 94 |
90 void ExecutionContext::resumeActiveDOMObjects() | 95 void ExecutionContext::resumeActiveDOMObjects() |
91 { | 96 { |
92 ASSERT(m_activeDOMObjectsAreSuspended); | 97 ASSERT(m_activeDOMObjectsAreSuspended); |
93 m_activeDOMObjectsAreSuspended = false; | 98 m_activeDOMObjectsAreSuspended = false; |
94 notifyResumingActiveDOMObjects(); | 99 lifecycleNotifier().notifyResumingActiveDOMObjects(); |
95 } | 100 } |
96 | 101 |
97 void ExecutionContext::stopActiveDOMObjects() | 102 void ExecutionContext::stopActiveDOMObjects() |
98 { | 103 { |
99 m_activeDOMObjectsAreStopped = true; | 104 m_activeDOMObjectsAreStopped = true; |
100 notifyStoppingActiveDOMObjects(); | 105 lifecycleNotifier().notifyStoppingActiveDOMObjects(); |
101 } | 106 } |
102 | 107 |
103 unsigned ExecutionContext::activeDOMObjectCount() | 108 unsigned ExecutionContext::activeDOMObjectCount() |
104 { | 109 { |
105 return activeDOMObjects().size(); | 110 return lifecycleNotifier().activeDOMObjects().size(); |
106 } | 111 } |
107 | 112 |
108 void ExecutionContext::suspendScheduledTasks() | 113 void ExecutionContext::suspendScheduledTasks() |
109 { | 114 { |
110 suspendActiveDOMObjects(); | 115 suspendActiveDOMObjects(); |
111 tasksWereSuspended(); | 116 tasksWereSuspended(); |
112 } | 117 } |
113 | 118 |
114 void ExecutionContext::resumeScheduledTasks() | 119 void ExecutionContext::resumeScheduledTasks() |
115 { | 120 { |
116 resumeActiveDOMObjects(); | 121 resumeActiveDOMObjects(); |
117 tasksWereResumed(); | 122 tasksWereResumed(); |
118 } | 123 } |
119 | 124 |
120 void ExecutionContext::suspendActiveDOMObjectIfNeeded(ActiveDOMObject* object) | 125 void ExecutionContext::suspendActiveDOMObjectIfNeeded(ActiveDOMObject* object) |
121 { | 126 { |
122 ASSERT(contains(object)); | 127 ASSERT(lifecycleNotifier().contains(object)); |
123 // Ensure all ActiveDOMObjects are suspended also newly created ones. | 128 // Ensure all ActiveDOMObjects are suspended also newly created ones. |
124 if (m_activeDOMObjectsAreSuspended) | 129 if (m_activeDOMObjectsAreSuspended) |
125 object->suspend(); | 130 object->suspend(); |
126 } | 131 } |
127 | 132 |
128 bool ExecutionContext::shouldSanitizeScriptError(const String& sourceURL, Access
ControlStatus corsStatus) | 133 bool ExecutionContext::shouldSanitizeScriptError(const String& sourceURL, Access
ControlStatus corsStatus) |
129 { | 134 { |
130 return !(securityOrigin()->canRequest(completeURL(sourceURL)) || corsStatus
== SharableCrossOrigin); | 135 return !(securityOrigin()->canRequest(completeURL(sourceURL)) || corsStatus
== SharableCrossOrigin); |
131 } | 136 } |
132 | 137 |
(...skipping 66 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
199 const KURL& ExecutionContext::url() const | 204 const KURL& ExecutionContext::url() const |
200 { | 205 { |
201 return virtualURL(); | 206 return virtualURL(); |
202 } | 207 } |
203 | 208 |
204 KURL ExecutionContext::completeURL(const String& url) const | 209 KURL ExecutionContext::completeURL(const String& url) const |
205 { | 210 { |
206 return virtualCompleteURL(url); | 211 return virtualCompleteURL(url); |
207 } | 212 } |
208 | 213 |
209 void ExecutionContext::allowWindowInteraction() | 214 PassOwnPtr<LifecycleNotifier<ExecutionContext> > ExecutionContext::createLifecyc
leNotifier() |
210 { | 215 { |
211 ++m_windowInteractionTokens; | 216 return ContextLifecycleNotifier::create(this); |
212 } | 217 } |
213 | 218 |
214 void ExecutionContext::consumeWindowInteraction() | 219 ContextLifecycleNotifier& ExecutionContext::lifecycleNotifier() |
215 { | 220 { |
216 if (m_windowInteractionTokens == 0) | 221 return static_cast<ContextLifecycleNotifier&>(LifecycleContext<ExecutionCont
ext>::lifecycleNotifier()); |
217 return; | |
218 --m_windowInteractionTokens; | |
219 } | 222 } |
220 | 223 |
221 bool ExecutionContext::isWindowInteractionAllowed() const | 224 bool ExecutionContext::isIteratingOverObservers() const |
| 225 { |
| 226 return m_lifecycleNotifier && m_lifecycleNotifier->isIteratingOverObservers(
); |
| 227 } |
| 228 |
| 229 void ExecutionContext::allowWindowFocus() |
| 230 { |
| 231 ++m_windowFocusTokens; |
| 232 } |
| 233 |
| 234 void ExecutionContext::consumeWindowFocus() |
| 235 { |
| 236 if (m_windowFocusTokens == 0) |
| 237 return; |
| 238 --m_windowFocusTokens; |
| 239 } |
| 240 |
| 241 bool ExecutionContext::isWindowFocusAllowed() const |
222 { | 242 { |
223 // FIXME: WindowFocusAllowedIndicator::windowFocusAllowed() is temporary, | 243 // FIXME: WindowFocusAllowedIndicator::windowFocusAllowed() is temporary, |
224 // it will be removed as soon as WebScopedWindowFocusAllowedIndicator will | 244 // it will be removed as soon as WebScopedWindowFocusAllowedIndicator will |
225 // be updated to not use WindowFocusAllowedIndicator. | 245 // be updated to not use WindowFocusAllowedIndicator. |
226 return m_windowInteractionTokens > 0 || WindowFocusAllowedIndicator::windowF
ocusAllowed(); | 246 return m_windowFocusTokens > 0 || WindowFocusAllowedIndicator::windowFocusAl
lowed(); |
227 } | 247 } |
228 | 248 |
229 void ExecutionContext::trace(Visitor* visitor) | 249 void ExecutionContext::trace(Visitor* visitor) |
230 { | 250 { |
231 #if ENABLE(OILPAN) | 251 #if ENABLE(OILPAN) |
232 visitor->trace(m_pendingExceptions); | 252 visitor->trace(m_pendingExceptions); |
233 visitor->trace(m_publicURLManager); | 253 visitor->trace(m_publicURLManager); |
234 HeapSupplementable<ExecutionContext>::trace(visitor); | 254 HeapSupplementable<ExecutionContext>::trace(visitor); |
235 #endif | 255 #endif |
236 ContextLifecycleNotifier::trace(visitor); | 256 LifecycleContext<ExecutionContext>::trace(visitor); |
237 } | 257 } |
238 | 258 |
239 } // namespace blink | 259 } // namespace blink |
OLD | NEW |