| 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 59 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 70 #include "public/platform/Platform.h" | 70 #include "public/platform/Platform.h" |
| 71 #include "wtf/CurrentTime.h" | 71 #include "wtf/CurrentTime.h" |
| 72 #include "wtf/StdLibExtras.h" | 72 #include "wtf/StdLibExtras.h" |
| 73 #include "wtf/StringExtras.h" | 73 #include "wtf/StringExtras.h" |
| 74 #include "wtf/text/CString.h" | 74 #include "wtf/text/CString.h" |
| 75 #include "wtf/text/StringBuilder.h" | 75 #include "wtf/text/StringBuilder.h" |
| 76 #include "wtf/text/TextPosition.h" | 76 #include "wtf/text/TextPosition.h" |
| 77 | 77 |
| 78 namespace blink { | 78 namespace blink { |
| 79 | 79 |
| 80 ScriptController::ScriptController(LocalFrame* frame) | 80 ScriptController::ScriptController(LocalFrame& frame) |
| 81 : m_windowProxyManager(LocalWindowProxyManager::create(*frame)) {} | 81 : LocalWindowProxyManager(frame) {} |
| 82 | |
| 83 DEFINE_TRACE(ScriptController) { | |
| 84 visitor->trace(m_windowProxyManager); | |
| 85 } | |
| 86 | |
| 87 void ScriptController::clearForClose() { | |
| 88 m_windowProxyManager->clearForClose(); | |
| 89 MainThreadDebugger::instance()->didClearContextsForFrame(frame()); | |
| 90 } | |
| 91 | |
| 92 void ScriptController::updateSecurityOrigin(SecurityOrigin* securityOrigin) { | |
| 93 m_windowProxyManager->updateSecurityOrigin(securityOrigin); | |
| 94 } | |
| 95 | 82 |
| 96 namespace { | 83 namespace { |
| 97 | 84 |
| 98 V8CacheOptions cacheOptions(const ScriptResource* resource, | 85 V8CacheOptions cacheOptions(const ScriptResource* resource, |
| 99 const Settings* settings) { | 86 const Settings* settings) { |
| 100 V8CacheOptions v8CacheOptions(V8CacheOptionsDefault); | 87 V8CacheOptions v8CacheOptions(V8CacheOptionsDefault); |
| 101 if (settings) | 88 if (settings) |
| 102 v8CacheOptions = settings->getV8CacheOptions(); | 89 v8CacheOptions = settings->getV8CacheOptions(); |
| 103 if (resource && !resource->response().cacheStorageCacheName().isNull()) { | 90 if (resource && !resource->response().cacheStorageCacheName().isNull()) { |
| 104 switch (settings->getV8CacheStrategiesForCacheStorage()) { | 91 switch (settings->getV8CacheStrategiesForCacheStorage()) { |
| (...skipping 48 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 153 return result; | 140 return result; |
| 154 } | 141 } |
| 155 | 142 |
| 156 TRACE_EVENT_INSTANT1(TRACE_DISABLED_BY_DEFAULT("devtools.timeline"), | 143 TRACE_EVENT_INSTANT1(TRACE_DISABLED_BY_DEFAULT("devtools.timeline"), |
| 157 "UpdateCounters", TRACE_EVENT_SCOPE_THREAD, "data", | 144 "UpdateCounters", TRACE_EVENT_SCOPE_THREAD, "data", |
| 158 InspectorUpdateCountersEvent::data()); | 145 InspectorUpdateCountersEvent::data()); |
| 159 | 146 |
| 160 return result; | 147 return result; |
| 161 } | 148 } |
| 162 | 149 |
| 163 LocalWindowProxy* ScriptController::windowProxy(DOMWrapperWorld& world) { | |
| 164 LocalWindowProxy* windowProxy = m_windowProxyManager->windowProxy(world); | |
| 165 windowProxy->initializeIfNeeded(); | |
| 166 return windowProxy; | |
| 167 } | |
| 168 | |
| 169 bool ScriptController::shouldBypassMainWorldCSP() { | 150 bool ScriptController::shouldBypassMainWorldCSP() { |
| 170 v8::HandleScope handleScope(isolate()); | 151 v8::HandleScope handleScope(isolate()); |
| 171 v8::Local<v8::Context> context = isolate()->GetCurrentContext(); | 152 v8::Local<v8::Context> context = isolate()->GetCurrentContext(); |
| 172 if (context.IsEmpty() || !toDOMWindow(context)) | 153 if (context.IsEmpty() || !toDOMWindow(context)) |
| 173 return false; | 154 return false; |
| 174 DOMWrapperWorld& world = DOMWrapperWorld::current(isolate()); | 155 DOMWrapperWorld& world = DOMWrapperWorld::current(isolate()); |
| 175 return world.isIsolatedWorld() ? world.isolatedWorldHasContentSecurityPolicy() | 156 return world.isIsolatedWorld() ? world.isolatedWorldHasContentSecurityPolicy() |
| 176 : false; | 157 : false; |
| 177 } | 158 } |
| 178 | 159 |
| 179 TextPosition ScriptController::eventHandlerPosition() const { | 160 TextPosition ScriptController::eventHandlerPosition() const { |
| 180 ScriptableDocumentParser* parser = | 161 ScriptableDocumentParser* parser = |
| 181 frame()->document()->scriptableDocumentParser(); | 162 frame()->document()->scriptableDocumentParser(); |
| 182 if (parser) | 163 if (parser) |
| 183 return parser->textPosition(); | 164 return parser->textPosition(); |
| 184 return TextPosition::minimumPosition(); | 165 return TextPosition::minimumPosition(); |
| 185 } | 166 } |
| 186 | 167 |
| 168 void ScriptController::namedItemAdded(HTMLDocument* document, |
| 169 const AtomicString& name) { |
| 170 initializeMainWorld(); |
| 171 |
| 172 mainWorldProxy()->namedItemAdded(document, name); |
| 173 } |
| 174 |
| 175 void ScriptController::namedItemRemoved(HTMLDocument* document, |
| 176 const AtomicString& name) { |
| 177 initializeMainWorld(); |
| 178 |
| 179 mainWorldProxy()->namedItemRemoved(document, name); |
| 180 } |
| 181 |
| 187 void ScriptController::enableEval() { | 182 void ScriptController::enableEval() { |
| 188 v8::HandleScope handleScope(isolate()); | 183 v8::HandleScope handleScope(isolate()); |
| 189 v8::Local<v8::Context> v8Context = | 184 v8::Local<v8::Context> v8Context = mainWorldProxy()->contextIfInitialized(); |
| 190 m_windowProxyManager->mainWorldProxy()->contextIfInitialized(); | |
| 191 if (v8Context.IsEmpty()) | 185 if (v8Context.IsEmpty()) |
| 192 return; | 186 return; |
| 193 v8Context->AllowCodeGenerationFromStrings(true); | 187 v8Context->AllowCodeGenerationFromStrings(true); |
| 194 } | 188 } |
| 195 | 189 |
| 196 void ScriptController::disableEval(const String& errorMessage) { | 190 void ScriptController::disableEval(const String& errorMessage) { |
| 197 v8::HandleScope handleScope(isolate()); | 191 v8::HandleScope handleScope(isolate()); |
| 198 v8::Local<v8::Context> v8Context = | 192 v8::Local<v8::Context> v8Context = mainWorldProxy()->contextIfInitialized(); |
| 199 m_windowProxyManager->mainWorldProxy()->contextIfInitialized(); | |
| 200 if (v8Context.IsEmpty()) | 193 if (v8Context.IsEmpty()) |
| 201 return; | 194 return; |
| 202 v8Context->AllowCodeGenerationFromStrings(false); | 195 v8Context->AllowCodeGenerationFromStrings(false); |
| 203 v8Context->SetErrorMessageForCodeGenerationFromStrings( | 196 v8Context->SetErrorMessageForCodeGenerationFromStrings( |
| 204 v8String(isolate(), errorMessage)); | 197 v8String(isolate(), errorMessage)); |
| 205 } | 198 } |
| 206 | 199 |
| 207 PassRefPtr<SharedPersistent<v8::Object>> ScriptController::createPluginWrapper( | 200 PassRefPtr<SharedPersistent<v8::Object>> ScriptController::createPluginWrapper( |
| 208 Widget* widget) { | 201 Widget* widget) { |
| 209 ASSERT(widget); | 202 ASSERT(widget); |
| 210 | 203 |
| 211 if (!widget->isPluginView()) | 204 if (!widget->isPluginView()) |
| 212 return nullptr; | 205 return nullptr; |
| 213 | 206 |
| 214 v8::HandleScope handleScope(isolate()); | 207 v8::HandleScope handleScope(isolate()); |
| 215 v8::Local<v8::Object> scriptableObject = | 208 v8::Local<v8::Object> scriptableObject = |
| 216 toPluginView(widget)->scriptableObject(isolate()); | 209 toPluginView(widget)->scriptableObject(isolate()); |
| 217 | 210 |
| 218 if (scriptableObject.IsEmpty()) | 211 if (scriptableObject.IsEmpty()) |
| 219 return nullptr; | 212 return nullptr; |
| 220 | 213 |
| 221 return SharedPersistent<v8::Object>::create(scriptableObject, isolate()); | 214 return SharedPersistent<v8::Object>::create(scriptableObject, isolate()); |
| 222 } | 215 } |
| 223 | 216 |
| 217 void ScriptController::clearForClose() { |
| 218 LocalWindowProxyManager::clearForClose(); |
| 219 MainThreadDebugger::instance()->didClearContextsForFrame(frame()); |
| 220 } |
| 221 |
| 222 void ScriptController::clearForNavigation() { |
| 223 // V8 binding expects ScriptController::clearForNavigation() only be called |
| 224 // when a frame is loading a new page. |
| 225 LocalWindowProxyManager::clearForNavigation(); |
| 226 MainThreadDebugger::instance()->didClearContextsForFrame(frame()); |
| 227 } |
| 228 |
| 229 void ScriptController::updateDocument() { |
| 230 mainWorldProxy()->updateDocument(); |
| 231 } |
| 232 |
| 233 void ScriptController::updateSecurityOrigin(SecurityOrigin* securityOrigin) { |
| 234 mainWorldProxy()->updateSecurityOrigin(securityOrigin); |
| 235 for (auto& entry : isolatedWorlds()) { |
| 236 // This is a little hacky, but a LocalWindowProxyManager can only hold |
| 237 // LocalWindowProxy objects, so the downcast to LocalWindowProxy is safe. |
| 238 auto* isolatedWindowProxy = |
| 239 static_cast<LocalWindowProxy*>(entry.value.get()); |
| 240 SecurityOrigin* isolatedSecurityOrigin = |
| 241 isolatedWindowProxy->world().isolatedWorldSecurityOrigin(); |
| 242 isolatedWindowProxy->updateSecurityOrigin(isolatedSecurityOrigin); |
| 243 } |
| 244 } |
| 245 |
| 246 void ScriptController::initializeMainWorld() { |
| 247 mainWorldProxy()->initializeIfNeeded(); |
| 248 } |
| 249 |
| 224 V8Extensions& ScriptController::registeredExtensions() { | 250 V8Extensions& ScriptController::registeredExtensions() { |
| 225 DEFINE_STATIC_LOCAL(V8Extensions, extensions, ()); | 251 DEFINE_STATIC_LOCAL(V8Extensions, extensions, ()); |
| 226 return extensions; | 252 return extensions; |
| 227 } | 253 } |
| 228 | 254 |
| 229 void ScriptController::registerExtensionIfNeeded(v8::Extension* extension) { | 255 void ScriptController::registerExtensionIfNeeded(v8::Extension* extension) { |
| 230 const V8Extensions& extensions = registeredExtensions(); | 256 const V8Extensions& extensions = registeredExtensions(); |
| 231 for (size_t i = 0; i < extensions.size(); ++i) { | 257 for (size_t i = 0; i < extensions.size(); ++i) { |
| 232 if (extensions[i] == extension) | 258 if (extensions[i] == extension) |
| 233 return; | 259 return; |
| 234 } | 260 } |
| 235 v8::RegisterExtension(extension); | 261 v8::RegisterExtension(extension); |
| 236 registeredExtensions().push_back(extension); | 262 registeredExtensions().push_back(extension); |
| 237 } | 263 } |
| 238 | 264 |
| 239 void ScriptController::clearWindowProxy() { | |
| 240 // V8 binding expects ScriptController::clearWindowProxy only be called when a | |
| 241 // frame is loading a new page. This creates a new context for the new page. | |
| 242 m_windowProxyManager->clearForNavigation(); | |
| 243 MainThreadDebugger::instance()->didClearContextsForFrame(frame()); | |
| 244 } | |
| 245 | |
| 246 void ScriptController::updateDocument() { | |
| 247 m_windowProxyManager->mainWorldProxy()->updateDocument(); | |
| 248 } | |
| 249 | |
| 250 bool ScriptController::canExecuteScripts( | 265 bool ScriptController::canExecuteScripts( |
| 251 ReasonForCallingCanExecuteScripts reason) { | 266 ReasonForCallingCanExecuteScripts reason) { |
| 252 | 267 |
| 253 if (frame()->document() && frame()->document()->isSandboxed(SandboxScripts)) { | 268 if (frame()->document() && frame()->document()->isSandboxed(SandboxScripts)) { |
| 254 // FIXME: This message should be moved off the console once a solution to | 269 // FIXME: This message should be moved off the console once a solution to |
| 255 // https://bugs.webkit.org/show_bug.cgi?id=103274 exists. | 270 // https://bugs.webkit.org/show_bug.cgi?id=103274 exists. |
| 256 if (reason == AboutToExecuteScript) | 271 if (reason == AboutToExecuteScript) |
| 257 frame()->document()->addConsoleMessage(ConsoleMessage::create( | 272 frame()->document()->addConsoleMessage(ConsoleMessage::create( |
| 258 SecurityMessageSource, ErrorMessageLevel, | 273 SecurityMessageSource, ErrorMessageLevel, |
| 259 "Blocked script execution in '" + | 274 "Blocked script execution in '" + |
| (...skipping 153 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 413 for (size_t i = 0; i < resultArray->Length(); ++i) { | 428 for (size_t i = 0; i < resultArray->Length(); ++i) { |
| 414 v8::Local<v8::Value> value; | 429 v8::Local<v8::Value> value; |
| 415 if (!resultArray->Get(scriptState->context(), i).ToLocal(&value)) | 430 if (!resultArray->Get(scriptState->context(), i).ToLocal(&value)) |
| 416 return; | 431 return; |
| 417 results->push_back(value); | 432 results->push_back(value); |
| 418 } | 433 } |
| 419 } | 434 } |
| 420 } | 435 } |
| 421 | 436 |
| 422 } // namespace blink | 437 } // namespace blink |
| OLD | NEW |