| 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) | |
| 81 : m_windowProxyManager(LocalWindowProxyManager::create(*frame)) {} | |
| 82 | |
| 83 DEFINE_TRACE(ScriptController) { | 80 DEFINE_TRACE(ScriptController) { |
| 84 visitor->trace(m_windowProxyManager); | 81 visitor->trace(m_windowProxyManager); |
| 85 } | 82 } |
| 86 | 83 |
| 87 void ScriptController::clearForClose() { | 84 void ScriptController::clearForClose() { |
| 88 m_windowProxyManager->clearForClose(); | 85 m_windowProxyManager->clearForClose(); |
| 89 MainThreadDebugger::instance()->didClearContextsForFrame(frame()); | 86 MainThreadDebugger::instance()->didClearContextsForFrame(frame()); |
| 90 } | 87 } |
| 91 | 88 |
| 92 void ScriptController::updateSecurityOrigin(SecurityOrigin* securityOrigin) { | 89 void ScriptController::updateSecurityOrigin(SecurityOrigin* securityOrigin) { |
| (...skipping 60 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 153 return result; | 150 return result; |
| 154 } | 151 } |
| 155 | 152 |
| 156 TRACE_EVENT_INSTANT1(TRACE_DISABLED_BY_DEFAULT("devtools.timeline"), | 153 TRACE_EVENT_INSTANT1(TRACE_DISABLED_BY_DEFAULT("devtools.timeline"), |
| 157 "UpdateCounters", TRACE_EVENT_SCOPE_THREAD, "data", | 154 "UpdateCounters", TRACE_EVENT_SCOPE_THREAD, "data", |
| 158 InspectorUpdateCountersEvent::data()); | 155 InspectorUpdateCountersEvent::data()); |
| 159 | 156 |
| 160 return result; | 157 return result; |
| 161 } | 158 } |
| 162 | 159 |
| 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() { | 160 bool ScriptController::shouldBypassMainWorldCSP() { |
| 170 v8::HandleScope handleScope(isolate()); | 161 v8::HandleScope handleScope(isolate()); |
| 171 v8::Local<v8::Context> context = isolate()->GetCurrentContext(); | 162 v8::Local<v8::Context> context = isolate()->GetCurrentContext(); |
| 172 if (context.IsEmpty() || !toDOMWindow(context)) | 163 if (context.IsEmpty() || !toDOMWindow(context)) |
| 173 return false; | 164 return false; |
| 174 DOMWrapperWorld& world = DOMWrapperWorld::current(isolate()); | 165 DOMWrapperWorld& world = DOMWrapperWorld::current(isolate()); |
| 175 return world.isIsolatedWorld() ? world.isolatedWorldHasContentSecurityPolicy() | 166 return world.isIsolatedWorld() ? world.isolatedWorldHasContentSecurityPolicy() |
| 176 : false; | 167 : false; |
| 177 } | 168 } |
| 178 | 169 |
| 179 TextPosition ScriptController::eventHandlerPosition() const { | 170 TextPosition ScriptController::eventHandlerPosition() const { |
| 180 ScriptableDocumentParser* parser = | 171 ScriptableDocumentParser* parser = |
| 181 frame()->document()->scriptableDocumentParser(); | 172 frame()->document()->scriptableDocumentParser(); |
| 182 if (parser) | 173 if (parser) |
| 183 return parser->textPosition(); | 174 return parser->textPosition(); |
| 184 return TextPosition::minimumPosition(); | 175 return TextPosition::minimumPosition(); |
| 185 } | 176 } |
| 186 | 177 |
| 187 void ScriptController::enableEval() { | 178 void ScriptController::enableEval() { |
| 188 v8::HandleScope handleScope(isolate()); | 179 v8::HandleScope handleScope(isolate()); |
| 189 v8::Local<v8::Context> v8Context = | 180 v8::Local<v8::Context> v8Context = |
| 190 m_windowProxyManager->mainWorldProxy()->contextIfInitialized(); | 181 m_windowProxyManager->mainWorldProxyMaybeUninitialized() |
| 182 ->contextIfInitialized(); |
| 191 if (v8Context.IsEmpty()) | 183 if (v8Context.IsEmpty()) |
| 192 return; | 184 return; |
| 193 v8Context->AllowCodeGenerationFromStrings(true); | 185 v8Context->AllowCodeGenerationFromStrings(true); |
| 194 } | 186 } |
| 195 | 187 |
| 196 void ScriptController::disableEval(const String& errorMessage) { | 188 void ScriptController::disableEval(const String& errorMessage) { |
| 197 v8::HandleScope handleScope(isolate()); | 189 v8::HandleScope handleScope(isolate()); |
| 198 v8::Local<v8::Context> v8Context = | 190 v8::Local<v8::Context> v8Context = |
| 199 m_windowProxyManager->mainWorldProxy()->contextIfInitialized(); | 191 m_windowProxyManager->mainWorldProxyMaybeUninitialized() |
| 192 ->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); |
| (...skipping 27 matching lines...) Expand all Loading... |
| 237 } | 230 } |
| 238 | 231 |
| 239 void ScriptController::clearWindowProxy() { | 232 void ScriptController::clearWindowProxy() { |
| 240 // V8 binding expects ScriptController::clearWindowProxy only be called when a | 233 // 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. | 234 // frame is loading a new page. This creates a new context for the new page. |
| 242 m_windowProxyManager->clearForNavigation(); | 235 m_windowProxyManager->clearForNavigation(); |
| 243 MainThreadDebugger::instance()->didClearContextsForFrame(frame()); | 236 MainThreadDebugger::instance()->didClearContextsForFrame(frame()); |
| 244 } | 237 } |
| 245 | 238 |
| 246 void ScriptController::updateDocument() { | 239 void ScriptController::updateDocument() { |
| 247 m_windowProxyManager->mainWorldProxy()->updateDocument(); | 240 m_windowProxyManager->mainWorldProxyMaybeUninitialized()->updateDocument(); |
| 248 } | 241 } |
| 249 | 242 |
| 250 bool ScriptController::executeScriptIfJavaScriptURL(const KURL& url, | 243 bool ScriptController::executeScriptIfJavaScriptURL(const KURL& url, |
| 251 Element* element) { | 244 Element* element) { |
| 252 if (!url.protocolIsJavaScript()) | 245 if (!url.protocolIsJavaScript()) |
| 253 return false; | 246 return false; |
| 254 | 247 |
| 255 bool shouldBypassMainWorldContentSecurityPolicy = | 248 bool shouldBypassMainWorldContentSecurityPolicy = |
| 256 ContentSecurityPolicy::shouldBypassMainWorld(frame()->document()); | 249 ContentSecurityPolicy::shouldBypassMainWorld(frame()->document()); |
| 257 if (!frame()->page() || | 250 if (!frame()->page() || |
| (...skipping 123 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 381 for (size_t i = 0; i < resultArray->Length(); ++i) { | 374 for (size_t i = 0; i < resultArray->Length(); ++i) { |
| 382 v8::Local<v8::Value> value; | 375 v8::Local<v8::Value> value; |
| 383 if (!resultArray->Get(scriptState->context(), i).ToLocal(&value)) | 376 if (!resultArray->Get(scriptState->context(), i).ToLocal(&value)) |
| 384 return; | 377 return; |
| 385 results->push_back(value); | 378 results->push_back(value); |
| 386 } | 379 } |
| 387 } | 380 } |
| 388 } | 381 } |
| 389 | 382 |
| 390 } // namespace blink | 383 } // namespace blink |
| OLD | NEW |