Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(343)

Side by Side Diff: third_party/WebKit/Source/bindings/core/v8/ScriptController.cpp

Issue 1878943003: Remove RawPtr from bindings/ (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 4 years, 8 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
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 98 matching lines...) Expand 10 before | Expand all | Expand 10 after
109 { 109 {
110 m_windowProxyManager->mainWorldProxy()->updateSecurityOrigin(origin); 110 m_windowProxyManager->mainWorldProxy()->updateSecurityOrigin(origin);
111 Vector<std::pair<ScriptState*, SecurityOrigin*>> isolatedContexts; 111 Vector<std::pair<ScriptState*, SecurityOrigin*>> isolatedContexts;
112 m_windowProxyManager->collectIsolatedContexts(isolatedContexts); 112 m_windowProxyManager->collectIsolatedContexts(isolatedContexts);
113 for (auto isolatedContext : isolatedContexts) 113 for (auto isolatedContext : isolatedContexts)
114 m_windowProxyManager->windowProxy(isolatedContext.first->world())->updat eSecurityOrigin(isolatedContext.second); 114 m_windowProxyManager->windowProxy(isolatedContext.first->world())->updat eSecurityOrigin(isolatedContext.second);
115 } 115 }
116 116
117 v8::MaybeLocal<v8::Value> ScriptController::callFunction(v8::Local<v8::Function> function, v8::Local<v8::Value> receiver, int argc, v8::Local<v8::Value> info[]) 117 v8::MaybeLocal<v8::Value> ScriptController::callFunction(v8::Local<v8::Function> function, v8::Local<v8::Value> receiver, int argc, v8::Local<v8::Value> info[])
118 { 118 {
119 // Keep LocalFrame (and therefore ScriptController) alive.
120 RawPtr<LocalFrame> protect(frame());
121 return ScriptController::callFunction(frame()->document(), function, receive r, argc, info, isolate()); 119 return ScriptController::callFunction(frame()->document(), function, receive r, argc, info, isolate());
122 } 120 }
123 121
124 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) 122 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)
125 { 123 {
126 v8::MaybeLocal<v8::Value> result = V8ScriptRunner::callFunction(function, co ntext, receiver, argc, info, isolate); 124 v8::MaybeLocal<v8::Value> result = V8ScriptRunner::callFunction(function, co ntext, receiver, argc, info, isolate);
127 return result; 125 return result;
128 } 126 }
129 127
130 v8::Local<v8::Value> ScriptController::executeScriptAndReturnValue(v8::Local<v8: :Context> context, const ScriptSourceCode& source, AccessControlStatus accessCon trolStatus, double* compilationFinishTime) 128 v8::Local<v8::Value> ScriptController::executeScriptAndReturnValue(v8::Local<v8: :Context> context, const ScriptSourceCode& source, AccessControlStatus accessCon trolStatus, double* compilationFinishTime)
(...skipping 14 matching lines...) Expand all
145 v8::TryCatch tryCatch(isolate()); 143 v8::TryCatch tryCatch(isolate());
146 tryCatch.SetVerbose(true); 144 tryCatch.SetVerbose(true);
147 145
148 v8::Local<v8::Script> script; 146 v8::Local<v8::Script> script;
149 if (!v8Call(V8ScriptRunner::compileScript(source, isolate(), accessContr olStatus, v8CacheOptions), script, tryCatch)) 147 if (!v8Call(V8ScriptRunner::compileScript(source, isolate(), accessContr olStatus, v8CacheOptions), script, tryCatch))
150 return result; 148 return result;
151 149
152 if (compilationFinishTime) { 150 if (compilationFinishTime) {
153 *compilationFinishTime = WTF::monotonicallyIncreasingTime(); 151 *compilationFinishTime = WTF::monotonicallyIncreasingTime();
154 } 152 }
155 // Keep LocalFrame (and therefore ScriptController) alive.
156 RawPtr<LocalFrame> protect(frame());
157 if (!v8Call(V8ScriptRunner::runCompiledScript(isolate(), script, frame() ->document()), result, tryCatch)) 153 if (!v8Call(V8ScriptRunner::runCompiledScript(isolate(), script, frame() ->document()), result, tryCatch))
158 return result; 154 return result;
159 } 155 }
160 156
161 TRACE_EVENT_INSTANT1(TRACE_DISABLED_BY_DEFAULT("devtools.timeline"), "Update Counters", TRACE_EVENT_SCOPE_THREAD, "data", InspectorUpdateCountersEvent::data( )); 157 TRACE_EVENT_INSTANT1(TRACE_DISABLED_BY_DEFAULT("devtools.timeline"), "Update Counters", TRACE_EVENT_SCOPE_THREAD, "data", InspectorUpdateCountersEvent::data( ));
162 158
163 return result; 159 return result;
164 } 160 }
165 161
166 bool ScriptController::initializeMainWorld() 162 bool ScriptController::initializeMainWorld()
(...skipping 174 matching lines...) Expand 10 before | Expand all | Expand 10 after
341 337
342 bool shouldBypassMainWorldContentSecurityPolicy = ContentSecurityPolicy::sho uldBypassMainWorld(frame()->document()); 338 bool shouldBypassMainWorldContentSecurityPolicy = ContentSecurityPolicy::sho uldBypassMainWorld(frame()->document());
343 if (!frame()->page() 339 if (!frame()->page()
344 || (!shouldBypassMainWorldContentSecurityPolicy && !frame()->document()- >contentSecurityPolicy()->allowJavaScriptURLs(frame()->document()->url(), eventH andlerPosition().m_line))) 340 || (!shouldBypassMainWorldContentSecurityPolicy && !frame()->document()- >contentSecurityPolicy()->allowJavaScriptURLs(frame()->document()->url(), eventH andlerPosition().m_line)))
345 return true; 341 return true;
346 342
347 bool progressNotificationsNeeded = frame()->loader().stateMachine()->isDispl ayingInitialEmptyDocument() && !frame()->isLoading(); 343 bool progressNotificationsNeeded = frame()->loader().stateMachine()->isDispl ayingInitialEmptyDocument() && !frame()->isLoading();
348 if (progressNotificationsNeeded) 344 if (progressNotificationsNeeded)
349 frame()->loader().progress().progressStarted(); 345 frame()->loader().progress().progressStarted();
350 346
351 // We need to hold onto the LocalFrame here because executing script can 347 Document* ownerDocument = frame()->document();
352 // destroy the frame.
353 RawPtr<LocalFrame> protect(frame());
354 RawPtr<Document> ownerDocument(frame()->document());
355 348
356 const int javascriptSchemeLength = sizeof("javascript:") - 1; 349 const int javascriptSchemeLength = sizeof("javascript:") - 1;
357 350
358 bool locationChangeBefore = frame()->navigationScheduler().locationChangePen ding(); 351 bool locationChangeBefore = frame()->navigationScheduler().locationChangePen ding();
359 352
360 String decodedURL = decodeURLEscapeSequences(url.getString()); 353 String decodedURL = decodeURLEscapeSequences(url.getString());
361 v8::HandleScope handleScope(isolate()); 354 v8::HandleScope handleScope(isolate());
362 v8::Local<v8::Value> result = evaluateScriptInMainWorld(ScriptSourceCode(dec odedURL.substring(javascriptSchemeLength)), NotSharableCrossOrigin, DoNotExecute ScriptWhenScriptsDisabled); 355 v8::Local<v8::Value> result = evaluateScriptInMainWorld(ScriptSourceCode(dec odedURL.substring(javascriptSchemeLength)), NotSharableCrossOrigin, DoNotExecute ScriptWhenScriptsDisabled);
363 356
364 // If executing script caused this frame to be removed from the page, we 357 // If executing script caused this frame to be removed from the page, we
365 // don't want to try to replace its document! 358 // don't want to try to replace its document!
366 if (!frame()->page()) 359 if (!frame()->page())
367 return true; 360 return true;
368 361
369 if (result.IsEmpty() || !result->IsString()) { 362 if (result.IsEmpty() || !result->IsString()) {
370 if (progressNotificationsNeeded) 363 if (progressNotificationsNeeded)
371 frame()->loader().progress().progressCompleted(); 364 frame()->loader().progress().progressCompleted();
372 return true; 365 return true;
373 } 366 }
374 String scriptResult = toCoreString(v8::Local<v8::String>::Cast(result)); 367 String scriptResult = toCoreString(v8::Local<v8::String>::Cast(result));
375 368
376 // We're still in a frame, so there should be a DocumentLoader. 369 // We're still in a frame, so there should be a DocumentLoader.
377 ASSERT(frame()->document()->loader()); 370 ASSERT(frame()->document()->loader());
378 if (!locationChangeBefore && frame()->navigationScheduler().locationChangePe nding()) 371 if (!locationChangeBefore && frame()->navigationScheduler().locationChangePe nding())
379 return true; 372 return true;
380 373
381 frame()->loader().replaceDocumentWhileExecutingJavaScriptURL(scriptResult, o wnerDocument.get()); 374 frame()->loader().replaceDocumentWhileExecutingJavaScriptURL(scriptResult, o wnerDocument);
382 return true; 375 return true;
383 } 376 }
384 377
385 void ScriptController::executeScriptInMainWorld(const String& script, ExecuteScr iptPolicy policy) 378 void ScriptController::executeScriptInMainWorld(const String& script, ExecuteScr iptPolicy policy)
386 { 379 {
387 v8::HandleScope handleScope(isolate()); 380 v8::HandleScope handleScope(isolate());
388 evaluateScriptInMainWorld(ScriptSourceCode(script), NotSharableCrossOrigin, policy); 381 evaluateScriptInMainWorld(ScriptSourceCode(script), NotSharableCrossOrigin, policy);
389 } 382 }
390 383
391 void ScriptController::executeScriptInMainWorld(const ScriptSourceCode& sourceCo de, AccessControlStatus accessControlStatus, double* compilationFinishTime) 384 void ScriptController::executeScriptInMainWorld(const ScriptSourceCode& sourceCo de, AccessControlStatus accessControlStatus, double* compilationFinishTime)
(...skipping 11 matching lines...) Expand all
403 { 396 {
404 if (policy == DoNotExecuteScriptWhenScriptsDisabled && !canExecuteScripts(Ab outToExecuteScript)) 397 if (policy == DoNotExecuteScriptWhenScriptsDisabled && !canExecuteScripts(Ab outToExecuteScript))
405 return v8::Local<v8::Value>(); 398 return v8::Local<v8::Value>();
406 399
407 ScriptState* scriptState = ScriptState::forMainWorld(frame()); 400 ScriptState* scriptState = ScriptState::forMainWorld(frame());
408 if (!scriptState) 401 if (!scriptState)
409 return v8::Local<v8::Value>(); 402 return v8::Local<v8::Value>();
410 v8::EscapableHandleScope handleScope(isolate()); 403 v8::EscapableHandleScope handleScope(isolate());
411 ScriptState::Scope scope(scriptState); 404 ScriptState::Scope scope(scriptState);
412 405
413 RawPtr<LocalFrame> protect(frame());
414 if (frame()->loader().stateMachine()->isDisplayingInitialEmptyDocument()) 406 if (frame()->loader().stateMachine()->isDisplayingInitialEmptyDocument())
415 frame()->loader().didAccessInitialDocument(); 407 frame()->loader().didAccessInitialDocument();
416 408
417 v8::Local<v8::Value> object = executeScriptAndReturnValue(scriptState->conte xt(), sourceCode, accessControlStatus, compilationFinishTime); 409 v8::Local<v8::Value> object = executeScriptAndReturnValue(scriptState->conte xt(), sourceCode, accessControlStatus, compilationFinishTime);
418 410
419 if (object.IsEmpty()) 411 if (object.IsEmpty())
420 return v8::Local<v8::Value>(); 412 return v8::Local<v8::Value>();
421 413
422 return handleScope.Escape(object); 414 return handleScope.Escape(object);
423 } 415 }
(...skipping 23 matching lines...) Expand all
447 for (size_t i = 0; i < resultArray->Length(); ++i) { 439 for (size_t i = 0; i < resultArray->Length(); ++i) {
448 v8::Local<v8::Value> value; 440 v8::Local<v8::Value> value;
449 if (!resultArray->Get(scriptState->context(), i).ToLocal(&value)) 441 if (!resultArray->Get(scriptState->context(), i).ToLocal(&value))
450 return; 442 return;
451 results->append(value); 443 results->append(value);
452 } 444 }
453 } 445 }
454 } 446 }
455 447
456 } // namespace blink 448 } // namespace blink
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698