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 49 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
60 } | 60 } |
61 String m_errorMessage; | 61 String m_errorMessage; |
62 int m_lineNumber; | 62 int m_lineNumber; |
63 int m_columnNumber; | 63 int m_columnNumber; |
64 int m_scriptId; | 64 int m_scriptId; |
65 String m_sourceURL; | 65 String m_sourceURL; |
66 RefPtrWillBeMember<ScriptCallStack> m_callStack; | 66 RefPtrWillBeMember<ScriptCallStack> m_callStack; |
67 }; | 67 }; |
68 | 68 |
69 ExecutionContext::ExecutionContext() | 69 ExecutionContext::ExecutionContext() |
70 : m_client(0) | 70 : m_sandboxFlags(SandboxNone) |
71 , m_sandboxFlags(SandboxNone) | |
72 , m_circularSequentialID(0) | 71 , m_circularSequentialID(0) |
73 , m_inDispatchErrorEvent(false) | 72 , m_inDispatchErrorEvent(false) |
74 , m_activeDOMObjectsAreSuspended(false) | 73 , m_activeDOMObjectsAreSuspended(false) |
75 , m_activeDOMObjectsAreStopped(false) | 74 , m_activeDOMObjectsAreStopped(false) |
76 { | 75 { |
77 } | 76 } |
78 | 77 |
79 ExecutionContext::~ExecutionContext() | 78 ExecutionContext::~ExecutionContext() |
80 { | 79 { |
81 } | 80 } |
(...skipping 22 matching lines...) Expand all Loading... |
104 } | 103 } |
105 | 104 |
106 unsigned ExecutionContext::activeDOMObjectCount() | 105 unsigned ExecutionContext::activeDOMObjectCount() |
107 { | 106 { |
108 return lifecycleNotifier().activeDOMObjects().size(); | 107 return lifecycleNotifier().activeDOMObjects().size(); |
109 } | 108 } |
110 | 109 |
111 void ExecutionContext::suspendScheduledTasks() | 110 void ExecutionContext::suspendScheduledTasks() |
112 { | 111 { |
113 suspendActiveDOMObjects(); | 112 suspendActiveDOMObjects(); |
114 if (m_client) | 113 tasksWereSuspended(); |
115 m_client->tasksWereSuspended(); | |
116 } | 114 } |
117 | 115 |
118 void ExecutionContext::resumeScheduledTasks() | 116 void ExecutionContext::resumeScheduledTasks() |
119 { | 117 { |
120 resumeActiveDOMObjects(); | 118 resumeActiveDOMObjects(); |
121 if (m_client) | 119 tasksWereResumed(); |
122 m_client->tasksWereResumed(); | |
123 } | 120 } |
124 | 121 |
125 void ExecutionContext::suspendActiveDOMObjectIfNeeded(ActiveDOMObject* object) | 122 void ExecutionContext::suspendActiveDOMObjectIfNeeded(ActiveDOMObject* object) |
126 { | 123 { |
127 ASSERT(lifecycleNotifier().contains(object)); | 124 ASSERT(lifecycleNotifier().contains(object)); |
128 // Ensure all ActiveDOMObjects are suspended also newly created ones. | 125 // Ensure all ActiveDOMObjects are suspended also newly created ones. |
129 if (m_activeDOMObjectsAreSuspended) | 126 if (m_activeDOMObjectsAreSuspended) |
130 object->suspend(); | 127 object->suspend(); |
131 } | 128 } |
132 | 129 |
133 bool ExecutionContext::shouldSanitizeScriptError(const String& sourceURL, Access
ControlStatus corsStatus) | 130 bool ExecutionContext::shouldSanitizeScriptError(const String& sourceURL, Access
ControlStatus corsStatus) |
134 { | 131 { |
135 return !(securityOrigin()->canRequest(completeURL(sourceURL)) || corsStatus
== SharableCrossOrigin); | 132 return !(securityOrigin()->canRequest(completeURL(sourceURL)) || corsStatus
== SharableCrossOrigin); |
136 } | 133 } |
137 | 134 |
138 void ExecutionContext::reportException(PassRefPtrWillBeRawPtr<ErrorEvent> event,
int scriptId, PassRefPtrWillBeRawPtr<ScriptCallStack> callStack, AccessControlS
tatus corsStatus) | 135 void ExecutionContext::reportException(PassRefPtrWillBeRawPtr<ErrorEvent> event,
int scriptId, PassRefPtrWillBeRawPtr<ScriptCallStack> callStack, AccessControlS
tatus corsStatus) |
139 { | 136 { |
140 RefPtrWillBeRawPtr<ErrorEvent> errorEvent = event; | 137 RefPtrWillBeRawPtr<ErrorEvent> errorEvent = event; |
141 if (m_inDispatchErrorEvent) { | 138 if (m_inDispatchErrorEvent) { |
142 if (!m_pendingExceptions) | 139 if (!m_pendingExceptions) |
143 m_pendingExceptions = adoptPtrWillBeNoop(new WillBeHeapVector<OwnPtr
WillBeMember<PendingException> >()); | 140 m_pendingExceptions = adoptPtrWillBeNoop(new WillBeHeapVector<OwnPtr
WillBeMember<PendingException> >()); |
144 m_pendingExceptions->append(adoptPtrWillBeNoop(new PendingException(erro
rEvent->messageForConsole(), errorEvent->lineno(), errorEvent->colno(), scriptId
, errorEvent->filename(), callStack))); | 141 m_pendingExceptions->append(adoptPtrWillBeNoop(new PendingException(erro
rEvent->messageForConsole(), errorEvent->lineno(), errorEvent->colno(), scriptId
, errorEvent->filename(), callStack))); |
145 return; | 142 return; |
146 } | 143 } |
147 | 144 |
148 // First report the original exception and only then all the nested ones. | 145 // First report the original exception and only then all the nested ones. |
149 if (!dispatchErrorEvent(errorEvent, corsStatus) && m_client) | 146 if (!dispatchErrorEvent(errorEvent, corsStatus)) |
150 m_client->logExceptionToConsole(errorEvent->messageForConsole(), scriptI
d, errorEvent->filename(), errorEvent->lineno(), errorEvent->colno(), callStack)
; | 147 logExceptionToConsole(errorEvent->messageForConsole(), scriptId, errorEv
ent->filename(), errorEvent->lineno(), errorEvent->colno(), callStack); |
151 | 148 |
152 if (!m_pendingExceptions) | 149 if (!m_pendingExceptions) |
153 return; | 150 return; |
154 | 151 |
155 for (size_t i = 0; i < m_pendingExceptions->size(); i++) { | 152 for (size_t i = 0; i < m_pendingExceptions->size(); i++) { |
156 PendingException* e = m_pendingExceptions->at(i).get(); | 153 PendingException* e = m_pendingExceptions->at(i).get(); |
157 if (m_client) | 154 logExceptionToConsole(e->m_errorMessage, e->m_scriptId, e->m_sourceURL,
e->m_lineNumber, e->m_columnNumber, e->m_callStack); |
158 m_client->logExceptionToConsole(e->m_errorMessage, e->m_scriptId, e-
>m_sourceURL, e->m_lineNumber, e->m_columnNumber, e->m_callStack); | |
159 } | 155 } |
160 m_pendingExceptions.clear(); | 156 m_pendingExceptions.clear(); |
161 } | 157 } |
162 | 158 |
163 void ExecutionContext::addConsoleMessage(PassRefPtrWillBeRawPtr<ConsoleMessage>
consoleMessage) | |
164 { | |
165 if (!m_client) | |
166 return; | |
167 m_client->addMessage(consoleMessage); | |
168 } | |
169 | |
170 bool ExecutionContext::dispatchErrorEvent(PassRefPtrWillBeRawPtr<ErrorEvent> eve
nt, AccessControlStatus corsStatus) | 159 bool ExecutionContext::dispatchErrorEvent(PassRefPtrWillBeRawPtr<ErrorEvent> eve
nt, AccessControlStatus corsStatus) |
171 { | 160 { |
172 if (!m_client) | 161 EventTarget* target = errorEventTarget(); |
173 return false; | |
174 EventTarget* target = m_client->errorEventTarget(); | |
175 if (!target) | 162 if (!target) |
176 return false; | 163 return false; |
177 | 164 |
178 RefPtrWillBeRawPtr<ErrorEvent> errorEvent = event; | 165 RefPtrWillBeRawPtr<ErrorEvent> errorEvent = event; |
179 if (shouldSanitizeScriptError(errorEvent->filename(), corsStatus)) | 166 if (shouldSanitizeScriptError(errorEvent->filename(), corsStatus)) |
180 errorEvent = ErrorEvent::createSanitizedError(errorEvent->world()); | 167 errorEvent = ErrorEvent::createSanitizedError(errorEvent->world()); |
181 | 168 |
182 ASSERT(!m_inDispatchErrorEvent); | 169 ASSERT(!m_inDispatchErrorEvent); |
183 m_inDispatchErrorEvent = true; | 170 m_inDispatchErrorEvent = true; |
184 target->dispatchEvent(errorEvent); | 171 target->dispatchEvent(errorEvent); |
(...skipping 39 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
224 m_publicURLManager = PublicURLManager::create(this); | 211 m_publicURLManager = PublicURLManager::create(this); |
225 return *m_publicURLManager; | 212 return *m_publicURLManager; |
226 } | 213 } |
227 | 214 |
228 void ExecutionContext::didChangeTimerAlignmentInterval() | 215 void ExecutionContext::didChangeTimerAlignmentInterval() |
229 { | 216 { |
230 for (TimeoutMap::iterator iter = m_timeouts.begin(); iter != m_timeouts.end(
); ++iter) | 217 for (TimeoutMap::iterator iter = m_timeouts.begin(); iter != m_timeouts.end(
); ++iter) |
231 iter->value->didChangeAlignmentInterval(); | 218 iter->value->didChangeAlignmentInterval(); |
232 } | 219 } |
233 | 220 |
234 SecurityOrigin* ExecutionContext::securityOrigin() const | 221 SecurityOrigin* ExecutionContext::securityOrigin() |
235 { | 222 { |
236 RELEASE_ASSERT(m_client); | 223 return securityContext().securityOrigin(); |
237 return m_client->securityContext().securityOrigin(); | |
238 } | 224 } |
239 | 225 |
240 ContentSecurityPolicy* ExecutionContext::contentSecurityPolicy() const | 226 ContentSecurityPolicy* ExecutionContext::contentSecurityPolicy() |
241 { | 227 { |
242 RELEASE_ASSERT(m_client); | 228 return securityContext().contentSecurityPolicy(); |
243 return m_client->securityContext().contentSecurityPolicy(); | |
244 } | 229 } |
245 | 230 |
246 const KURL& ExecutionContext::url() const | 231 const KURL& ExecutionContext::url() const |
247 { | 232 { |
248 if (!m_client) { | |
249 DEFINE_STATIC_LOCAL(KURL, emptyURL, ()); | |
250 return emptyURL; | |
251 } | |
252 | |
253 return virtualURL(); | 233 return virtualURL(); |
254 } | 234 } |
255 | 235 |
256 KURL ExecutionContext::completeURL(const String& url) const | 236 KURL ExecutionContext::completeURL(const String& url) const |
257 { | 237 { |
258 | |
259 if (!m_client) { | |
260 DEFINE_STATIC_LOCAL(KURL, emptyURL, ()); | |
261 return emptyURL; | |
262 } | |
263 | |
264 return virtualCompleteURL(url); | 238 return virtualCompleteURL(url); |
265 } | 239 } |
266 | 240 |
267 void ExecutionContext::disableEval(const String& errorMessage) | |
268 { | |
269 if (!m_client) | |
270 return; | |
271 return m_client->disableEval(errorMessage); | |
272 } | |
273 | |
274 LocalDOMWindow* ExecutionContext::executingWindow() const | |
275 { | |
276 RELEASE_ASSERT(m_client); | |
277 return m_client->executingWindow(); | |
278 } | |
279 | |
280 String ExecutionContext::userAgent(const KURL& url) const | |
281 { | |
282 if (!m_client) | |
283 return String(); | |
284 return m_client->userAgent(url); | |
285 } | |
286 | |
287 double ExecutionContext::timerAlignmentInterval() const | |
288 { | |
289 if (!m_client) | |
290 return DOMTimer::visiblePageAlignmentInterval(); | |
291 return m_client->timerAlignmentInterval(); | |
292 } | |
293 | |
294 void ExecutionContext::postTask(PassOwnPtr<ExecutionContextTask> task) | |
295 { | |
296 if (!m_client) | |
297 return; | |
298 m_client->postTask(task); | |
299 } | |
300 | |
301 PassOwnPtr<LifecycleNotifier<ExecutionContext> > ExecutionContext::createLifecyc
leNotifier() | 241 PassOwnPtr<LifecycleNotifier<ExecutionContext> > ExecutionContext::createLifecyc
leNotifier() |
302 { | 242 { |
303 return ContextLifecycleNotifier::create(this); | 243 return ContextLifecycleNotifier::create(this); |
304 } | 244 } |
305 | 245 |
306 ContextLifecycleNotifier& ExecutionContext::lifecycleNotifier() | 246 ContextLifecycleNotifier& ExecutionContext::lifecycleNotifier() |
307 { | 247 { |
308 return static_cast<ContextLifecycleNotifier&>(LifecycleContext<ExecutionCont
ext>::lifecycleNotifier()); | 248 return static_cast<ContextLifecycleNotifier&>(LifecycleContext<ExecutionCont
ext>::lifecycleNotifier()); |
309 } | 249 } |
310 | 250 |
311 bool ExecutionContext::isIteratingOverObservers() const | 251 bool ExecutionContext::isIteratingOverObservers() const |
312 { | 252 { |
313 return m_lifecycleNotifier && m_lifecycleNotifier->isIteratingOverObservers(
); | 253 return m_lifecycleNotifier && m_lifecycleNotifier->isIteratingOverObservers(
); |
314 } | 254 } |
315 | 255 |
316 void ExecutionContext::enforceSandboxFlags(SandboxFlags mask) | 256 void ExecutionContext::enforceSandboxFlags(SandboxFlags mask) |
317 { | 257 { |
318 m_sandboxFlags |= mask; | 258 m_sandboxFlags |= mask; |
319 | 259 |
320 RELEASE_ASSERT(m_client); | |
321 // The SandboxOrigin is stored redundantly in the security origin. | 260 // The SandboxOrigin is stored redundantly in the security origin. |
322 if (isSandboxed(SandboxOrigin) && m_client->securityContext().securityOrigin
() && !m_client->securityContext().securityOrigin()->isUnique()) { | 261 if (isSandboxed(SandboxOrigin) && securityContext().securityOrigin() && !sec
urityContext().securityOrigin()->isUnique()) { |
323 m_client->securityContext().setSecurityOrigin(SecurityOrigin::createUniq
ue()); | 262 securityContext().setSecurityOrigin(SecurityOrigin::createUnique()); |
324 m_client->didUpdateSecurityOrigin(); | 263 didUpdateSecurityOrigin(); |
325 } | 264 } |
326 } | 265 } |
327 | 266 |
328 void ExecutionContext::trace(Visitor* visitor) | 267 void ExecutionContext::trace(Visitor* visitor) |
329 { | 268 { |
330 #if ENABLE(OILPAN) | 269 #if ENABLE(OILPAN) |
331 visitor->trace(m_pendingExceptions); | 270 visitor->trace(m_pendingExceptions); |
332 #endif | 271 #endif |
333 WillBeHeapSupplementable<ExecutionContext>::trace(visitor); | 272 WillBeHeapSupplementable<ExecutionContext>::trace(visitor); |
334 LifecycleContext<ExecutionContext>::trace(visitor); | 273 LifecycleContext<ExecutionContext>::trace(visitor); |
335 } | 274 } |
336 | 275 |
337 } // namespace blink | 276 } // namespace blink |
OLD | NEW |