Chromium Code Reviews| 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 60 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 71 #include "public/platform/Platform.h" | 71 #include "public/platform/Platform.h" |
| 72 #include "wtf/CurrentTime.h" | 72 #include "wtf/CurrentTime.h" |
| 73 #include "wtf/StdLibExtras.h" | 73 #include "wtf/StdLibExtras.h" |
| 74 #include "wtf/StringExtras.h" | 74 #include "wtf/StringExtras.h" |
| 75 #include "wtf/text/CString.h" | 75 #include "wtf/text/CString.h" |
| 76 #include "wtf/text/StringBuilder.h" | 76 #include "wtf/text/StringBuilder.h" |
| 77 #include "wtf/text/TextPosition.h" | 77 #include "wtf/text/TextPosition.h" |
| 78 | 78 |
| 79 namespace blink { | 79 namespace blink { |
| 80 | 80 |
| 81 ScriptController::ScriptController(LocalFrame* frame) | 81 ScriptController::ScriptController(LocalFrame& frame) |
| 82 : m_windowProxyManager(LocalWindowProxyManager::create(*frame)) {} | 82 : LocalWindowProxyManager(frame) {} |
| 83 | |
| 84 DEFINE_TRACE(ScriptController) { | |
| 85 visitor->trace(m_windowProxyManager); | |
| 86 } | |
| 87 | 83 |
| 88 void ScriptController::clearForClose() { | 84 void ScriptController::clearForClose() { |
| 89 m_windowProxyManager->clearForClose(); | 85 LocalWindowProxyManager::clearForClose(); |
| 90 MainThreadDebugger::instance()->didClearContextsForFrame(frame()); | 86 MainThreadDebugger::instance()->didClearContextsForFrame(frame()); |
| 91 } | 87 } |
| 92 | 88 |
| 93 void ScriptController::updateSecurityOrigin(SecurityOrigin* securityOrigin) { | 89 void ScriptController::updateSecurityOrigin(SecurityOrigin* securityOrigin) { |
| 94 m_windowProxyManager->updateSecurityOrigin(securityOrigin); | 90 // This is a little hacky, but a LocalWindowProxyManager can only hold |
| 91 // LocalWindowProxy objects, so the downcast to LocalWindowProxy is safe. | |
| 92 static_cast<LocalWindowProxy*>(mainWorldProxy()) | |
|
Yuki
2017/01/13 10:41:59
Did you make WindowProxyManagerImplHelper::mainWor
dcheng
2017/01/13 18:57:30
Originally, I wrote it this way for consistency or
| |
| 93 ->updateSecurityOrigin(securityOrigin); | |
| 94 for (auto& entry : isolatedWorlds()) { | |
| 95 auto* isolatedWindowProxy = | |
| 96 static_cast<LocalWindowProxy*>(entry.value.get()); | |
| 97 SecurityOrigin* isolatedSecurityOrigin = | |
| 98 isolatedWindowProxy->world().isolatedWorldSecurityOrigin(); | |
| 99 isolatedWindowProxy->updateSecurityOrigin(isolatedSecurityOrigin); | |
| 100 } | |
| 95 } | 101 } |
| 96 | 102 |
| 97 namespace { | 103 namespace { |
| 98 | 104 |
| 99 V8CacheOptions cacheOptions(const ScriptResource* resource, | 105 V8CacheOptions cacheOptions(const ScriptResource* resource, |
| 100 const Settings* settings) { | 106 const Settings* settings) { |
| 101 V8CacheOptions v8CacheOptions(V8CacheOptionsDefault); | 107 V8CacheOptions v8CacheOptions(V8CacheOptionsDefault); |
| 102 if (settings) | 108 if (settings) |
| 103 v8CacheOptions = settings->getV8CacheOptions(); | 109 v8CacheOptions = settings->getV8CacheOptions(); |
| 104 if (resource && !resource->response().cacheStorageCacheName().isNull()) { | 110 if (resource && !resource->response().cacheStorageCacheName().isNull()) { |
| (...skipping 97 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 202 V8ScriptRunner::runCompiledScript( | 208 V8ScriptRunner::runCompiledScript( |
| 203 isolate(), compiledScript.script(isolate()), frame()->document()), | 209 isolate(), compiledScript.script(isolate()), frame()->document()), |
| 204 result, tryCatch)) | 210 result, tryCatch)) |
| 205 return; | 211 return; |
| 206 | 212 |
| 207 TRACE_EVENT_INSTANT1(TRACE_DISABLED_BY_DEFAULT("devtools.timeline"), | 213 TRACE_EVENT_INSTANT1(TRACE_DISABLED_BY_DEFAULT("devtools.timeline"), |
| 208 "UpdateCounters", TRACE_EVENT_SCOPE_THREAD, "data", | 214 "UpdateCounters", TRACE_EVENT_SCOPE_THREAD, "data", |
| 209 InspectorUpdateCountersEvent::data()); | 215 InspectorUpdateCountersEvent::data()); |
| 210 } | 216 } |
| 211 | 217 |
| 212 LocalWindowProxy* ScriptController::windowProxy(DOMWrapperWorld& world) { | |
| 213 LocalWindowProxy* windowProxy = m_windowProxyManager->windowProxy(world); | |
| 214 windowProxy->initializeIfNeeded(); | |
| 215 return windowProxy; | |
| 216 } | |
| 217 | |
| 218 bool ScriptController::shouldBypassMainWorldCSP() { | 218 bool ScriptController::shouldBypassMainWorldCSP() { |
| 219 v8::HandleScope handleScope(isolate()); | 219 v8::HandleScope handleScope(isolate()); |
| 220 v8::Local<v8::Context> context = isolate()->GetCurrentContext(); | 220 v8::Local<v8::Context> context = isolate()->GetCurrentContext(); |
| 221 if (context.IsEmpty() || !toDOMWindow(context)) | 221 if (context.IsEmpty() || !toDOMWindow(context)) |
| 222 return false; | 222 return false; |
| 223 DOMWrapperWorld& world = DOMWrapperWorld::current(isolate()); | 223 DOMWrapperWorld& world = DOMWrapperWorld::current(isolate()); |
| 224 return world.isIsolatedWorld() ? world.isolatedWorldHasContentSecurityPolicy() | 224 return world.isIsolatedWorld() ? world.isolatedWorldHasContentSecurityPolicy() |
| 225 : false; | 225 : false; |
| 226 } | 226 } |
| 227 | 227 |
| 228 TextPosition ScriptController::eventHandlerPosition() const { | 228 TextPosition ScriptController::eventHandlerPosition() const { |
| 229 ScriptableDocumentParser* parser = | 229 ScriptableDocumentParser* parser = |
| 230 frame()->document()->scriptableDocumentParser(); | 230 frame()->document()->scriptableDocumentParser(); |
| 231 if (parser) | 231 if (parser) |
| 232 return parser->textPosition(); | 232 return parser->textPosition(); |
| 233 return TextPosition::minimumPosition(); | 233 return TextPosition::minimumPosition(); |
| 234 } | 234 } |
| 235 | 235 |
| 236 void ScriptController::enableEval() { | 236 void ScriptController::enableEval() { |
| 237 v8::HandleScope handleScope(isolate()); | 237 v8::HandleScope handleScope(isolate()); |
| 238 v8::Local<v8::Context> v8Context = | 238 v8::Local<v8::Context> v8Context = mainWorldProxy()->contextIfInitialized(); |
| 239 m_windowProxyManager->mainWorldProxy()->contextIfInitialized(); | |
| 240 if (v8Context.IsEmpty()) | 239 if (v8Context.IsEmpty()) |
| 241 return; | 240 return; |
| 242 v8Context->AllowCodeGenerationFromStrings(true); | 241 v8Context->AllowCodeGenerationFromStrings(true); |
| 243 } | 242 } |
| 244 | 243 |
| 245 void ScriptController::disableEval(const String& errorMessage) { | 244 void ScriptController::disableEval(const String& errorMessage) { |
| 246 v8::HandleScope handleScope(isolate()); | 245 v8::HandleScope handleScope(isolate()); |
| 247 v8::Local<v8::Context> v8Context = | 246 v8::Local<v8::Context> v8Context = mainWorldProxy()->contextIfInitialized(); |
| 248 m_windowProxyManager->mainWorldProxy()->contextIfInitialized(); | |
| 249 if (v8Context.IsEmpty()) | 247 if (v8Context.IsEmpty()) |
| 250 return; | 248 return; |
| 251 v8Context->AllowCodeGenerationFromStrings(false); | 249 v8Context->AllowCodeGenerationFromStrings(false); |
| 252 v8Context->SetErrorMessageForCodeGenerationFromStrings( | 250 v8Context->SetErrorMessageForCodeGenerationFromStrings( |
| 253 v8String(isolate(), errorMessage)); | 251 v8String(isolate(), errorMessage)); |
| 254 } | 252 } |
| 255 | 253 |
| 256 PassRefPtr<SharedPersistent<v8::Object>> ScriptController::createPluginWrapper( | 254 PassRefPtr<SharedPersistent<v8::Object>> ScriptController::createPluginWrapper( |
| 257 Widget* widget) { | 255 Widget* widget) { |
| 258 ASSERT(widget); | 256 ASSERT(widget); |
| (...skipping 19 matching lines...) Expand all Loading... | |
| 278 void ScriptController::registerExtensionIfNeeded(v8::Extension* extension) { | 276 void ScriptController::registerExtensionIfNeeded(v8::Extension* extension) { |
| 279 const V8Extensions& extensions = registeredExtensions(); | 277 const V8Extensions& extensions = registeredExtensions(); |
| 280 for (size_t i = 0; i < extensions.size(); ++i) { | 278 for (size_t i = 0; i < extensions.size(); ++i) { |
| 281 if (extensions[i] == extension) | 279 if (extensions[i] == extension) |
| 282 return; | 280 return; |
| 283 } | 281 } |
| 284 v8::RegisterExtension(extension); | 282 v8::RegisterExtension(extension); |
| 285 registeredExtensions().push_back(extension); | 283 registeredExtensions().push_back(extension); |
| 286 } | 284 } |
| 287 | 285 |
| 288 void ScriptController::clearWindowProxy() { | 286 void ScriptController::clearForNavigation() { |
|
Yuki
2017/01/13 10:42:00
nit: Could you put clearForClose and clearForNavig
dcheng
2017/01/13 18:57:30
Done.
| |
| 289 // V8 binding expects ScriptController::clearWindowProxy only be called when a | 287 // V8 binding expects ScriptController::clearForNavigation() only be called |
| 290 // frame is loading a new page. This creates a new context for the new page. | 288 // when a frame is loading a new page. |
| 291 m_windowProxyManager->clearForNavigation(); | 289 WindowProxyManagerBase::clearForNavigation(); |
|
Yuki
2017/01/13 10:42:00
Given LocalWindowProxyManager is a direct base cla
dcheng
2017/01/13 18:57:30
Done.
| |
| 292 MainThreadDebugger::instance()->didClearContextsForFrame(frame()); | 290 MainThreadDebugger::instance()->didClearContextsForFrame(frame()); |
| 293 } | 291 } |
| 294 | 292 |
| 295 void ScriptController::updateDocument() { | 293 void ScriptController::updateDocument() { |
| 296 m_windowProxyManager->mainWorldProxy()->updateDocument(); | 294 mainWorldProxy()->updateDocument(); |
| 297 } | 295 } |
| 298 | 296 |
| 299 bool ScriptController::canExecuteScripts( | 297 bool ScriptController::canExecuteScripts( |
| 300 ReasonForCallingCanExecuteScripts reason) { | 298 ReasonForCallingCanExecuteScripts reason) { |
| 301 | 299 |
| 302 if (frame()->document() && frame()->document()->isSandboxed(SandboxScripts)) { | 300 if (frame()->document() && frame()->document()->isSandboxed(SandboxScripts)) { |
| 303 // FIXME: This message should be moved off the console once a solution to | 301 // FIXME: This message should be moved off the console once a solution to |
| 304 // https://bugs.webkit.org/show_bug.cgi?id=103274 exists. | 302 // https://bugs.webkit.org/show_bug.cgi?id=103274 exists. |
| 305 if (reason == AboutToExecuteScript) | 303 if (reason == AboutToExecuteScript) |
| 306 frame()->document()->addConsoleMessage(ConsoleMessage::create( | 304 frame()->document()->addConsoleMessage(ConsoleMessage::create( |
| (...skipping 156 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 463 for (size_t i = 0; i < resultArray->Length(); ++i) { | 461 for (size_t i = 0; i < resultArray->Length(); ++i) { |
| 464 v8::Local<v8::Value> value; | 462 v8::Local<v8::Value> value; |
| 465 if (!resultArray->Get(scriptState->context(), i).ToLocal(&value)) | 463 if (!resultArray->Get(scriptState->context(), i).ToLocal(&value)) |
| 466 return; | 464 return; |
| 467 results->push_back(value); | 465 results->push_back(value); |
| 468 } | 466 } |
| 469 } | 467 } |
| 470 } | 468 } |
| 471 | 469 |
| 472 } // namespace blink | 470 } // namespace blink |
| OLD | NEW |