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 19 matching lines...) Expand all Loading... |
30 #include "bindings/core/v8/SourceLocation.h" | 30 #include "bindings/core/v8/SourceLocation.h" |
31 #include "core/dom/ExecutionContextTask.h" | 31 #include "core/dom/ExecutionContextTask.h" |
32 #include "core/events/ErrorEvent.h" | 32 #include "core/events/ErrorEvent.h" |
33 #include "core/events/EventTarget.h" | 33 #include "core/events/EventTarget.h" |
34 #include "core/fetch/MemoryCache.h" | 34 #include "core/fetch/MemoryCache.h" |
35 #include "core/frame/UseCounter.h" | 35 #include "core/frame/UseCounter.h" |
36 #include "core/html/PublicURLManager.h" | 36 #include "core/html/PublicURLManager.h" |
37 #include "core/inspector/InspectorInstrumentation.h" | 37 #include "core/inspector/InspectorInstrumentation.h" |
38 #include "core/workers/WorkerGlobalScope.h" | 38 #include "core/workers/WorkerGlobalScope.h" |
39 #include "core/workers/WorkerThread.h" | 39 #include "core/workers/WorkerThread.h" |
40 #include "wtf/PtrUtil.h" | |
41 #include <memory> | |
42 | 40 |
43 namespace blink { | 41 namespace blink { |
44 | 42 |
45 class ExecutionContext::PendingException { | 43 class ExecutionContext::PendingException { |
46 WTF_MAKE_NONCOPYABLE(PendingException); | 44 WTF_MAKE_NONCOPYABLE(PendingException); |
47 public: | 45 public: |
48 PendingException(const String& errorMessage, std::unique_ptr<SourceLocation>
location) | 46 PendingException(const String& errorMessage, PassOwnPtr<SourceLocation> loca
tion) |
49 : m_errorMessage(errorMessage) | 47 : m_errorMessage(errorMessage) |
50 , m_location(std::move(location)) | 48 , m_location(std::move(location)) |
51 { | 49 { |
52 } | 50 } |
53 | 51 |
54 String m_errorMessage; | 52 String m_errorMessage; |
55 std::unique_ptr<SourceLocation> m_location; | 53 OwnPtr<SourceLocation> m_location; |
56 }; | 54 }; |
57 | 55 |
58 ExecutionContext::ExecutionContext() | 56 ExecutionContext::ExecutionContext() |
59 : m_circularSequentialID(0) | 57 : m_circularSequentialID(0) |
60 , m_inDispatchErrorEvent(false) | 58 , m_inDispatchErrorEvent(false) |
61 , m_activeDOMObjectsAreSuspended(false) | 59 , m_activeDOMObjectsAreSuspended(false) |
62 , m_activeDOMObjectsAreStopped(false) | 60 , m_activeDOMObjectsAreStopped(false) |
63 , m_windowInteractionTokens(0) | 61 , m_windowInteractionTokens(0) |
64 , m_isRunSuspendableTasksScheduled(false) | 62 , m_isRunSuspendableTasksScheduled(false) |
65 , m_referrerPolicy(ReferrerPolicyDefault) | 63 , m_referrerPolicy(ReferrerPolicyDefault) |
(...skipping 17 matching lines...) Expand all Loading... |
83 m_activeDOMObjectsAreSuspended = false; | 81 m_activeDOMObjectsAreSuspended = false; |
84 notifyResumingActiveDOMObjects(); | 82 notifyResumingActiveDOMObjects(); |
85 } | 83 } |
86 | 84 |
87 void ExecutionContext::stopActiveDOMObjects() | 85 void ExecutionContext::stopActiveDOMObjects() |
88 { | 86 { |
89 m_activeDOMObjectsAreStopped = true; | 87 m_activeDOMObjectsAreStopped = true; |
90 notifyStoppingActiveDOMObjects(); | 88 notifyStoppingActiveDOMObjects(); |
91 } | 89 } |
92 | 90 |
93 void ExecutionContext::postSuspendableTask(std::unique_ptr<SuspendableTask> task
) | 91 void ExecutionContext::postSuspendableTask(PassOwnPtr<SuspendableTask> task) |
94 { | 92 { |
95 m_suspendedTasks.append(std::move(task)); | 93 m_suspendedTasks.append(std::move(task)); |
96 if (!m_activeDOMObjectsAreSuspended) | 94 if (!m_activeDOMObjectsAreSuspended) |
97 postTask(BLINK_FROM_HERE, createSameThreadTask(&ExecutionContext::runSus
pendableTasks, this)); | 95 postTask(BLINK_FROM_HERE, createSameThreadTask(&ExecutionContext::runSus
pendableTasks, this)); |
98 } | 96 } |
99 | 97 |
100 void ExecutionContext::notifyContextDestroyed() | 98 void ExecutionContext::notifyContextDestroyed() |
101 { | 99 { |
102 Deque<std::unique_ptr<SuspendableTask>> suspendedTasks; | 100 Deque<OwnPtr<SuspendableTask>> suspendedTasks; |
103 suspendedTasks.swap(m_suspendedTasks); | 101 suspendedTasks.swap(m_suspendedTasks); |
104 for (Deque<std::unique_ptr<SuspendableTask>>::iterator it = suspendedTasks.b
egin(); it != suspendedTasks.end(); ++it) | 102 for (Deque<OwnPtr<SuspendableTask>>::iterator it = suspendedTasks.begin(); i
t != suspendedTasks.end(); ++it) |
105 (*it)->contextDestroyed(); | 103 (*it)->contextDestroyed(); |
106 ContextLifecycleNotifier::notifyContextDestroyed(); | 104 ContextLifecycleNotifier::notifyContextDestroyed(); |
107 } | 105 } |
108 | 106 |
109 void ExecutionContext::suspendScheduledTasks() | 107 void ExecutionContext::suspendScheduledTasks() |
110 { | 108 { |
111 suspendActiveDOMObjects(); | 109 suspendActiveDOMObjects(); |
112 tasksWereSuspended(); | 110 tasksWereSuspended(); |
113 } | 111 } |
114 | 112 |
(...skipping 22 matching lines...) Expand all Loading... |
137 { | 135 { |
138 if (corsStatus == OpaqueResource) | 136 if (corsStatus == OpaqueResource) |
139 return true; | 137 return true; |
140 return !(getSecurityOrigin()->canRequestNoSuborigin(completeURL(sourceURL))
|| corsStatus == SharableCrossOrigin); | 138 return !(getSecurityOrigin()->canRequestNoSuborigin(completeURL(sourceURL))
|| corsStatus == SharableCrossOrigin); |
141 } | 139 } |
142 | 140 |
143 void ExecutionContext::reportException(ErrorEvent* errorEvent, AccessControlStat
us corsStatus) | 141 void ExecutionContext::reportException(ErrorEvent* errorEvent, AccessControlStat
us corsStatus) |
144 { | 142 { |
145 if (m_inDispatchErrorEvent) { | 143 if (m_inDispatchErrorEvent) { |
146 if (!m_pendingExceptions) | 144 if (!m_pendingExceptions) |
147 m_pendingExceptions = wrapUnique(new Vector<std::unique_ptr<PendingE
xception>>()); | 145 m_pendingExceptions = adoptPtr(new Vector<OwnPtr<PendingException>>(
)); |
148 m_pendingExceptions->append(wrapUnique(new PendingException(errorEvent->
messageForConsole(), errorEvent->location()->clone()))); | 146 m_pendingExceptions->append(adoptPtr(new PendingException(errorEvent->me
ssageForConsole(), errorEvent->location()->clone()))); |
149 return; | 147 return; |
150 } | 148 } |
151 | 149 |
152 // First report the original exception and only then all the nested ones. | 150 // First report the original exception and only then all the nested ones. |
153 if (!dispatchErrorEvent(errorEvent, corsStatus)) | 151 if (!dispatchErrorEvent(errorEvent, corsStatus)) |
154 logExceptionToConsole(errorEvent->messageForConsole(), errorEvent->locat
ion()->clone()); | 152 logExceptionToConsole(errorEvent->messageForConsole(), errorEvent->locat
ion()->clone()); |
155 | 153 |
156 if (!m_pendingExceptions) | 154 if (!m_pendingExceptions) |
157 return; | 155 return; |
158 | 156 |
(...skipping 17 matching lines...) Expand all Loading... |
176 m_inDispatchErrorEvent = true; | 174 m_inDispatchErrorEvent = true; |
177 target->dispatchEvent(errorEvent); | 175 target->dispatchEvent(errorEvent); |
178 m_inDispatchErrorEvent = false; | 176 m_inDispatchErrorEvent = false; |
179 return errorEvent->defaultPrevented(); | 177 return errorEvent->defaultPrevented(); |
180 } | 178 } |
181 | 179 |
182 void ExecutionContext::runSuspendableTasks() | 180 void ExecutionContext::runSuspendableTasks() |
183 { | 181 { |
184 m_isRunSuspendableTasksScheduled = false; | 182 m_isRunSuspendableTasksScheduled = false; |
185 while (!m_activeDOMObjectsAreSuspended && m_suspendedTasks.size()) { | 183 while (!m_activeDOMObjectsAreSuspended && m_suspendedTasks.size()) { |
186 std::unique_ptr<SuspendableTask> task = m_suspendedTasks.takeFirst(); | 184 OwnPtr<SuspendableTask> task = m_suspendedTasks.takeFirst(); |
187 task->run(); | 185 task->run(); |
188 } | 186 } |
189 } | 187 } |
190 | 188 |
191 int ExecutionContext::circularSequentialID() | 189 int ExecutionContext::circularSequentialID() |
192 { | 190 { |
193 ++m_circularSequentialID; | 191 ++m_circularSequentialID; |
194 if (m_circularSequentialID > ((1U << 31) - 1U)) | 192 if (m_circularSequentialID > ((1U << 31) - 1U)) |
195 m_circularSequentialID = 1; | 193 m_circularSequentialID = 1; |
196 | 194 |
(...skipping 71 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
268 } | 266 } |
269 | 267 |
270 DEFINE_TRACE(ExecutionContext) | 268 DEFINE_TRACE(ExecutionContext) |
271 { | 269 { |
272 visitor->trace(m_publicURLManager); | 270 visitor->trace(m_publicURLManager); |
273 ContextLifecycleNotifier::trace(visitor); | 271 ContextLifecycleNotifier::trace(visitor); |
274 Supplementable<ExecutionContext>::trace(visitor); | 272 Supplementable<ExecutionContext>::trace(visitor); |
275 } | 273 } |
276 | 274 |
277 } // namespace blink | 275 } // namespace blink |
OLD | NEW |