OLD | NEW |
1 /* | 1 /* |
2 * Copyright (C) 2008, 2009 Google Inc. All rights reserved. | 2 * Copyright (C) 2008, 2009 Google Inc. All rights reserved. |
3 * Copyright (C) 2009 Apple Inc. All rights reserved. | 3 * Copyright (C) 2009 Apple Inc. All rights reserved. |
4 * Copyright (C) 2014 Opera Software ASA. All rights reserved. | 4 * Copyright (C) 2014 Opera Software ASA. All rights reserved. |
5 * | 5 * |
6 * Redistribution and use in source and binary forms, with or without | 6 * Redistribution and use in source and binary forms, with or without |
7 * modification, are permitted provided that the following conditions are | 7 * modification, are permitted provided that the following conditions are |
8 * met: | 8 * met: |
9 * | 9 * |
10 * * Redistributions of source code must retain the above copyright | 10 * * Redistributions of source code must retain the above copyright |
(...skipping 106 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
117 m_windowProxyManager->mainWorldProxy()->updateSecurityOrigin(origin); | 117 m_windowProxyManager->mainWorldProxy()->updateSecurityOrigin(origin); |
118 Vector<std::pair<ScriptState*, SecurityOrigin*>> isolatedContexts; | 118 Vector<std::pair<ScriptState*, SecurityOrigin*>> isolatedContexts; |
119 m_windowProxyManager->collectIsolatedContexts(isolatedContexts); | 119 m_windowProxyManager->collectIsolatedContexts(isolatedContexts); |
120 for (auto isolatedContext : isolatedContexts) | 120 for (auto isolatedContext : isolatedContexts) |
121 m_windowProxyManager->windowProxy(isolatedContext.first->world())->updat
eSecurityOrigin(isolatedContext.second); | 121 m_windowProxyManager->windowProxy(isolatedContext.first->world())->updat
eSecurityOrigin(isolatedContext.second); |
122 } | 122 } |
123 | 123 |
124 v8::MaybeLocal<v8::Value> ScriptController::callFunction(v8::Local<v8::Function>
function, v8::Local<v8::Value> receiver, int argc, v8::Local<v8::Value> info[]) | 124 v8::MaybeLocal<v8::Value> ScriptController::callFunction(v8::Local<v8::Function>
function, v8::Local<v8::Value> receiver, int argc, v8::Local<v8::Value> info[]) |
125 { | 125 { |
126 // Keep LocalFrame (and therefore ScriptController) alive. | 126 // Keep LocalFrame (and therefore ScriptController) alive. |
127 RefPtrWillBeRawPtr<LocalFrame> protect(frame()); | 127 RawPtr<LocalFrame> protect(frame()); |
128 return ScriptController::callFunction(frame()->document(), function, receive
r, argc, info, isolate()); | 128 return ScriptController::callFunction(frame()->document(), function, receive
r, argc, info, isolate()); |
129 } | 129 } |
130 | 130 |
131 v8::MaybeLocal<v8::Value> ScriptController::callFunction(ExecutionContext* conte
xt, v8::Local<v8::Function> function, v8::Local<v8::Value> receiver, int argc, v
8::Local<v8::Value> info[], v8::Isolate* isolate) | 131 v8::MaybeLocal<v8::Value> ScriptController::callFunction(ExecutionContext* conte
xt, v8::Local<v8::Function> function, v8::Local<v8::Value> receiver, int argc, v
8::Local<v8::Value> info[], v8::Isolate* isolate) |
132 { | 132 { |
133 v8::MaybeLocal<v8::Value> result = V8ScriptRunner::callFunction(function, co
ntext, receiver, argc, info, isolate); | 133 v8::MaybeLocal<v8::Value> result = V8ScriptRunner::callFunction(function, co
ntext, receiver, argc, info, isolate); |
134 return result; | 134 return result; |
135 } | 135 } |
136 | 136 |
137 v8::Local<v8::Value> ScriptController::executeScriptAndReturnValue(v8::Local<v8:
:Context> context, const ScriptSourceCode& source, AccessControlStatus accessCon
trolStatus, double* compilationFinishTime) | 137 v8::Local<v8::Value> ScriptController::executeScriptAndReturnValue(v8::Local<v8:
:Context> context, const ScriptSourceCode& source, AccessControlStatus accessCon
trolStatus, double* compilationFinishTime) |
(...skipping 15 matching lines...) Expand all Loading... |
153 tryCatch.SetVerbose(true); | 153 tryCatch.SetVerbose(true); |
154 | 154 |
155 v8::Local<v8::Script> script; | 155 v8::Local<v8::Script> script; |
156 if (!v8Call(V8ScriptRunner::compileScript(source, isolate(), accessContr
olStatus, v8CacheOptions), script, tryCatch)) | 156 if (!v8Call(V8ScriptRunner::compileScript(source, isolate(), accessContr
olStatus, v8CacheOptions), script, tryCatch)) |
157 return result; | 157 return result; |
158 | 158 |
159 if (compilationFinishTime) { | 159 if (compilationFinishTime) { |
160 *compilationFinishTime = WTF::monotonicallyIncreasingTime(); | 160 *compilationFinishTime = WTF::monotonicallyIncreasingTime(); |
161 } | 161 } |
162 // Keep LocalFrame (and therefore ScriptController) alive. | 162 // Keep LocalFrame (and therefore ScriptController) alive. |
163 RefPtrWillBeRawPtr<LocalFrame> protect(frame()); | 163 RawPtr<LocalFrame> protect(frame()); |
164 if (!v8Call(V8ScriptRunner::runCompiledScript(isolate(), script, frame()
->document()), result, tryCatch)) | 164 if (!v8Call(V8ScriptRunner::runCompiledScript(isolate(), script, frame()
->document()), result, tryCatch)) |
165 return result; | 165 return result; |
166 } | 166 } |
167 | 167 |
168 TRACE_EVENT_INSTANT1(TRACE_DISABLED_BY_DEFAULT("devtools.timeline"), "Update
Counters", TRACE_EVENT_SCOPE_THREAD, "data", InspectorUpdateCountersEvent::data(
)); | 168 TRACE_EVENT_INSTANT1(TRACE_DISABLED_BY_DEFAULT("devtools.timeline"), "Update
Counters", TRACE_EVENT_SCOPE_THREAD, "data", InspectorUpdateCountersEvent::data(
)); |
169 | 169 |
170 return result; | 170 return result; |
171 } | 171 } |
172 | 172 |
173 bool ScriptController::initializeMainWorld() | 173 bool ScriptController::initializeMainWorld() |
(...skipping 176 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
350 if (!frame()->page() | 350 if (!frame()->page() |
351 || (!shouldBypassMainWorldContentSecurityPolicy && !frame()->document()-
>contentSecurityPolicy()->allowJavaScriptURLs(frame()->document()->url(), eventH
andlerPosition().m_line))) | 351 || (!shouldBypassMainWorldContentSecurityPolicy && !frame()->document()-
>contentSecurityPolicy()->allowJavaScriptURLs(frame()->document()->url(), eventH
andlerPosition().m_line))) |
352 return true; | 352 return true; |
353 | 353 |
354 bool progressNotificationsNeeded = frame()->loader().stateMachine()->isDispl
ayingInitialEmptyDocument() && !frame()->isLoading(); | 354 bool progressNotificationsNeeded = frame()->loader().stateMachine()->isDispl
ayingInitialEmptyDocument() && !frame()->isLoading(); |
355 if (progressNotificationsNeeded) | 355 if (progressNotificationsNeeded) |
356 frame()->loader().progress().progressStarted(); | 356 frame()->loader().progress().progressStarted(); |
357 | 357 |
358 // We need to hold onto the LocalFrame here because executing script can | 358 // We need to hold onto the LocalFrame here because executing script can |
359 // destroy the frame. | 359 // destroy the frame. |
360 RefPtrWillBeRawPtr<LocalFrame> protect(frame()); | 360 RawPtr<LocalFrame> protect(frame()); |
361 RefPtrWillBeRawPtr<Document> ownerDocument(frame()->document()); | 361 RawPtr<Document> ownerDocument(frame()->document()); |
362 | 362 |
363 const int javascriptSchemeLength = sizeof("javascript:") - 1; | 363 const int javascriptSchemeLength = sizeof("javascript:") - 1; |
364 | 364 |
365 bool locationChangeBefore = frame()->navigationScheduler().locationChangePen
ding(); | 365 bool locationChangeBefore = frame()->navigationScheduler().locationChangePen
ding(); |
366 | 366 |
367 String decodedURL = decodeURLEscapeSequences(url.getString()); | 367 String decodedURL = decodeURLEscapeSequences(url.getString()); |
368 v8::HandleScope handleScope(isolate()); | 368 v8::HandleScope handleScope(isolate()); |
369 v8::Local<v8::Value> result = evaluateScriptInMainWorld(ScriptSourceCode(dec
odedURL.substring(javascriptSchemeLength)), NotSharableCrossOrigin, DoNotExecute
ScriptWhenScriptsDisabled); | 369 v8::Local<v8::Value> result = evaluateScriptInMainWorld(ScriptSourceCode(dec
odedURL.substring(javascriptSchemeLength)), NotSharableCrossOrigin, DoNotExecute
ScriptWhenScriptsDisabled); |
370 | 370 |
371 // If executing script caused this frame to be removed from the page, we | 371 // If executing script caused this frame to be removed from the page, we |
(...skipping 42 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
414 String sourceURL = sourceCode.url(); | 414 String sourceURL = sourceCode.url(); |
415 const String* savedSourceURL = m_sourceURL; | 415 const String* savedSourceURL = m_sourceURL; |
416 m_sourceURL = &sourceURL; | 416 m_sourceURL = &sourceURL; |
417 | 417 |
418 ScriptState* scriptState = ScriptState::forMainWorld(frame()); | 418 ScriptState* scriptState = ScriptState::forMainWorld(frame()); |
419 if (!scriptState) | 419 if (!scriptState) |
420 return v8::Local<v8::Value>(); | 420 return v8::Local<v8::Value>(); |
421 v8::EscapableHandleScope handleScope(isolate()); | 421 v8::EscapableHandleScope handleScope(isolate()); |
422 ScriptState::Scope scope(scriptState); | 422 ScriptState::Scope scope(scriptState); |
423 | 423 |
424 RefPtrWillBeRawPtr<LocalFrame> protect(frame()); | 424 RawPtr<LocalFrame> protect(frame()); |
425 if (frame()->loader().stateMachine()->isDisplayingInitialEmptyDocument()) | 425 if (frame()->loader().stateMachine()->isDisplayingInitialEmptyDocument()) |
426 frame()->loader().didAccessInitialDocument(); | 426 frame()->loader().didAccessInitialDocument(); |
427 | 427 |
428 v8::Local<v8::Value> object = executeScriptAndReturnValue(scriptState->conte
xt(), sourceCode, accessControlStatus, compilationFinishTime); | 428 v8::Local<v8::Value> object = executeScriptAndReturnValue(scriptState->conte
xt(), sourceCode, accessControlStatus, compilationFinishTime); |
429 m_sourceURL = savedSourceURL; | 429 m_sourceURL = savedSourceURL; |
430 | 430 |
431 if (object.IsEmpty()) | 431 if (object.IsEmpty()) |
432 return v8::Local<v8::Value>(); | 432 return v8::Local<v8::Value>(); |
433 | 433 |
434 return handleScope.Escape(object); | 434 return handleScope.Escape(object); |
435 } | 435 } |
436 | 436 |
437 void ScriptController::executeScriptInIsolatedWorld(int worldID, const WillBeHea
pVector<ScriptSourceCode>& sources, int extensionGroup, Vector<v8::Local<v8::Val
ue>>* results) | 437 void ScriptController::executeScriptInIsolatedWorld(int worldID, const HeapVecto
r<ScriptSourceCode>& sources, int extensionGroup, Vector<v8::Local<v8::Value>>*
results) |
438 { | 438 { |
439 ASSERT(worldID > 0); | 439 ASSERT(worldID > 0); |
440 | 440 |
441 RefPtr<DOMWrapperWorld> world = DOMWrapperWorld::ensureIsolatedWorld(isolate
(), worldID, extensionGroup); | 441 RefPtr<DOMWrapperWorld> world = DOMWrapperWorld::ensureIsolatedWorld(isolate
(), worldID, extensionGroup); |
442 WindowProxy* isolatedWorldWindowProxy = windowProxy(*world); | 442 WindowProxy* isolatedWorldWindowProxy = windowProxy(*world); |
443 if (!isolatedWorldWindowProxy->isContextInitialized()) | 443 if (!isolatedWorldWindowProxy->isContextInitialized()) |
444 return; | 444 return; |
445 | 445 |
446 ScriptState* scriptState = isolatedWorldWindowProxy->getScriptState(); | 446 ScriptState* scriptState = isolatedWorldWindowProxy->getScriptState(); |
447 v8::Context::Scope scope(scriptState->context()); | 447 v8::Context::Scope scope(scriptState->context()); |
(...skipping 11 matching lines...) Expand all Loading... |
459 for (size_t i = 0; i < resultArray->Length(); ++i) { | 459 for (size_t i = 0; i < resultArray->Length(); ++i) { |
460 v8::Local<v8::Value> value; | 460 v8::Local<v8::Value> value; |
461 if (!resultArray->Get(scriptState->context(), i).ToLocal(&value)) | 461 if (!resultArray->Get(scriptState->context(), i).ToLocal(&value)) |
462 return; | 462 return; |
463 results->append(value); | 463 results->append(value); |
464 } | 464 } |
465 } | 465 } |
466 } | 466 } |
467 | 467 |
468 } // namespace blink | 468 } // namespace blink |
OLD | NEW |