| 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 15 matching lines...) Expand all Loading... |
| 26 * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, | 26 * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, |
| 27 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY | 27 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY |
| 28 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT | 28 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT |
| 29 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE | 29 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE |
| 30 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. | 30 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. |
| 31 */ | 31 */ |
| 32 | 32 |
| 33 #include "bindings/core/v8/ScriptController.h" | 33 #include "bindings/core/v8/ScriptController.h" |
| 34 | 34 |
| 35 #include "bindings/core/v8/ScriptSourceCode.h" | 35 #include "bindings/core/v8/ScriptSourceCode.h" |
| 36 #include "bindings/core/v8/ScriptValue.h" | |
| 37 #include "bindings/core/v8/V8Binding.h" | 36 #include "bindings/core/v8/V8Binding.h" |
| 38 #include "bindings/core/v8/V8Event.h" | |
| 39 #include "bindings/core/v8/V8GCController.h" | 37 #include "bindings/core/v8/V8GCController.h" |
| 40 #include "bindings/core/v8/V8HTMLElement.h" | |
| 41 #include "bindings/core/v8/V8PerContextData.h" | |
| 42 #include "bindings/core/v8/V8ScriptRunner.h" | 38 #include "bindings/core/v8/V8ScriptRunner.h" |
| 43 #include "bindings/core/v8/V8Window.h" | |
| 44 #include "bindings/core/v8/WindowProxy.h" | 39 #include "bindings/core/v8/WindowProxy.h" |
| 45 #include "core/dom/Document.h" | 40 #include "core/dom/Document.h" |
| 46 #include "core/dom/Node.h" | |
| 47 #include "core/dom/ScriptableDocumentParser.h" | 41 #include "core/dom/ScriptableDocumentParser.h" |
| 48 #include "core/events/Event.h" | 42 #include "core/frame/LocalFrame.h" |
| 49 #include "core/events/EventListener.h" | |
| 50 #include "core/frame/LocalDOMWindow.h" | |
| 51 #include "core/frame/LocalFrameClient.h" | 43 #include "core/frame/LocalFrameClient.h" |
| 52 #include "core/frame/Settings.h" | 44 #include "core/frame/Settings.h" |
| 53 #include "core/frame/UseCounter.h" | 45 #include "core/frame/UseCounter.h" |
| 54 #include "core/frame/csp/ContentSecurityPolicy.h" | 46 #include "core/frame/csp/ContentSecurityPolicy.h" |
| 55 #include "core/html/HTMLPlugInElement.h" | 47 #include "core/html/HTMLPlugInElement.h" |
| 56 #include "core/inspector/ConsoleMessage.h" | 48 #include "core/inspector/ConsoleMessage.h" |
| 57 #include "core/inspector/InspectorInstrumentation.h" | 49 #include "core/inspector/InspectorInstrumentation.h" |
| 58 #include "core/inspector/InspectorTraceEvents.h" | 50 #include "core/inspector/InspectorTraceEvents.h" |
| 59 #include "core/inspector/MainThreadDebugger.h" | 51 #include "core/inspector/MainThreadDebugger.h" |
| 60 #include "core/loader/DocumentLoader.h" | 52 #include "core/loader/DocumentLoader.h" |
| 61 #include "core/loader/FrameLoader.h" | 53 #include "core/loader/FrameLoader.h" |
| 62 #include "core/loader/NavigationScheduler.h" | 54 #include "core/loader/NavigationScheduler.h" |
| 63 #include "core/loader/ProgressTracker.h" | 55 #include "core/loader/ProgressTracker.h" |
| 64 #include "core/plugins/PluginView.h" | 56 #include "core/plugins/PluginView.h" |
| 65 #include "platform/FrameViewBase.h" | 57 #include "platform/FrameViewBase.h" |
| 66 #include "platform/Histogram.h" | 58 #include "platform/Histogram.h" |
| 67 #include "platform/UserGestureIndicator.h" | 59 #include "platform/UserGestureIndicator.h" |
| 68 #include "platform/instrumentation/tracing/TraceEvent.h" | 60 #include "platform/instrumentation/tracing/TraceEvent.h" |
| 69 #include "platform/weborigin/SecurityOrigin.h" | 61 #include "platform/weborigin/SecurityOrigin.h" |
| 70 #include "public/platform/Platform.h" | |
| 71 #include "wtf/CurrentTime.h" | 62 #include "wtf/CurrentTime.h" |
| 72 #include "wtf/StdLibExtras.h" | 63 #include "wtf/StdLibExtras.h" |
| 73 #include "wtf/StringExtras.h" | 64 #include "wtf/StringExtras.h" |
| 74 #include "wtf/text/CString.h" | 65 #include "wtf/text/CString.h" |
| 75 #include "wtf/text/StringBuilder.h" | 66 #include "wtf/text/StringBuilder.h" |
| 76 #include "wtf/text/TextPosition.h" | |
| 77 | 67 |
| 78 namespace blink { | 68 namespace blink { |
| 79 | 69 |
| 80 ScriptController::ScriptController(LocalFrame* frame) | |
| 81 : m_windowProxyManager(LocalWindowProxyManager::create(*frame)) {} | |
| 82 | |
| 83 DEFINE_TRACE(ScriptController) { | 70 DEFINE_TRACE(ScriptController) { |
| 71 visitor->trace(m_frame); |
| 84 visitor->trace(m_windowProxyManager); | 72 visitor->trace(m_windowProxyManager); |
| 85 } | 73 } |
| 86 | 74 |
| 87 void ScriptController::clearForClose() { | 75 void ScriptController::clearForClose() { |
| 88 m_windowProxyManager->clearForClose(); | 76 m_windowProxyManager->clearForClose(); |
| 89 MainThreadDebugger::instance()->didClearContextsForFrame(frame()); | 77 MainThreadDebugger::instance()->didClearContextsForFrame(frame()); |
| 90 } | 78 } |
| 91 | 79 |
| 92 void ScriptController::updateSecurityOrigin(SecurityOrigin* securityOrigin) { | 80 void ScriptController::updateSecurityOrigin(SecurityOrigin* securityOrigin) { |
| 93 m_windowProxyManager->updateSecurityOrigin(securityOrigin); | 81 m_windowProxyManager->updateSecurityOrigin(securityOrigin); |
| (...skipping 52 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 146 | 134 |
| 147 if (!v8Call(V8ScriptRunner::runCompiledScript(isolate(), script, | 135 if (!v8Call(V8ScriptRunner::runCompiledScript(isolate(), script, |
| 148 frame()->document()), | 136 frame()->document()), |
| 149 result, tryCatch)) | 137 result, tryCatch)) |
| 150 return result; | 138 return result; |
| 151 } | 139 } |
| 152 | 140 |
| 153 return result; | 141 return result; |
| 154 } | 142 } |
| 155 | 143 |
| 156 LocalWindowProxy* ScriptController::windowProxy(DOMWrapperWorld& world) { | |
| 157 LocalWindowProxy* windowProxy = m_windowProxyManager->windowProxy(world); | |
| 158 windowProxy->initializeIfNeeded(); | |
| 159 return windowProxy; | |
| 160 } | |
| 161 | |
| 162 bool ScriptController::shouldBypassMainWorldCSP() { | 144 bool ScriptController::shouldBypassMainWorldCSP() { |
| 163 v8::HandleScope handleScope(isolate()); | 145 v8::HandleScope handleScope(isolate()); |
| 164 v8::Local<v8::Context> context = isolate()->GetCurrentContext(); | 146 v8::Local<v8::Context> context = isolate()->GetCurrentContext(); |
| 165 if (context.IsEmpty() || !toDOMWindow(context)) | 147 if (context.IsEmpty() || !toDOMWindow(context)) |
| 166 return false; | 148 return false; |
| 167 DOMWrapperWorld& world = DOMWrapperWorld::current(isolate()); | 149 DOMWrapperWorld& world = DOMWrapperWorld::current(isolate()); |
| 168 return world.isIsolatedWorld() ? world.isolatedWorldHasContentSecurityPolicy() | 150 return world.isIsolatedWorld() ? world.isolatedWorldHasContentSecurityPolicy() |
| 169 : false; | 151 : false; |
| 170 } | 152 } |
| 171 | 153 |
| 172 TextPosition ScriptController::eventHandlerPosition() const { | 154 TextPosition ScriptController::eventHandlerPosition() const { |
| 173 ScriptableDocumentParser* parser = | 155 ScriptableDocumentParser* parser = |
| 174 frame()->document()->scriptableDocumentParser(); | 156 frame()->document()->scriptableDocumentParser(); |
| 175 if (parser) | 157 if (parser) |
| 176 return parser->textPosition(); | 158 return parser->textPosition(); |
| 177 return TextPosition::minimumPosition(); | 159 return TextPosition::minimumPosition(); |
| 178 } | 160 } |
| 179 | 161 |
| 180 void ScriptController::enableEval() { | 162 void ScriptController::enableEval() { |
| 163 if (!m_windowProxyManager->isMainWorldContextInitialized()) |
| 164 return; |
| 165 |
| 181 v8::HandleScope handleScope(isolate()); | 166 v8::HandleScope handleScope(isolate()); |
| 182 v8::Local<v8::Context> v8Context = | 167 v8::Local<v8::Context> v8Context = |
| 183 m_windowProxyManager->mainWorldProxy()->contextIfInitialized(); | 168 m_windowProxyManager->mainWorldProxy()->contextIfInitialized(); |
| 184 if (v8Context.IsEmpty()) | |
| 185 return; | |
| 186 v8Context->AllowCodeGenerationFromStrings(true); | 169 v8Context->AllowCodeGenerationFromStrings(true); |
| 187 } | 170 } |
| 188 | 171 |
| 189 void ScriptController::disableEval(const String& errorMessage) { | 172 void ScriptController::disableEval(const String& errorMessage) { |
| 173 if (!m_windowProxyManager->isMainWorldContextInitialized()) |
| 174 return; |
| 175 |
| 190 v8::HandleScope handleScope(isolate()); | 176 v8::HandleScope handleScope(isolate()); |
| 191 v8::Local<v8::Context> v8Context = | 177 v8::Local<v8::Context> v8Context = |
| 192 m_windowProxyManager->mainWorldProxy()->contextIfInitialized(); | 178 m_windowProxyManager->mainWorldProxy()->contextIfInitialized(); |
| 193 if (v8Context.IsEmpty()) | |
| 194 return; | |
| 195 v8Context->AllowCodeGenerationFromStrings(false); | 179 v8Context->AllowCodeGenerationFromStrings(false); |
| 196 v8Context->SetErrorMessageForCodeGenerationFromStrings( | 180 v8Context->SetErrorMessageForCodeGenerationFromStrings( |
| 197 v8String(isolate(), errorMessage)); | 181 v8String(isolate(), errorMessage)); |
| 198 } | 182 } |
| 199 | 183 |
| 200 PassRefPtr<SharedPersistent<v8::Object>> ScriptController::createPluginWrapper( | 184 PassRefPtr<SharedPersistent<v8::Object>> ScriptController::createPluginWrapper( |
| 201 FrameViewBase* frameViewBase) { | 185 FrameViewBase* frameViewBase) { |
| 202 DCHECK(frameViewBase); | 186 DCHECK(frameViewBase); |
| 203 | 187 |
| 204 if (!frameViewBase->isPluginView()) | 188 if (!frameViewBase->isPluginView()) |
| (...skipping 25 matching lines...) Expand all Loading... |
| 230 } | 214 } |
| 231 | 215 |
| 232 void ScriptController::clearWindowProxy() { | 216 void ScriptController::clearWindowProxy() { |
| 233 // V8 binding expects ScriptController::clearWindowProxy only be called when a | 217 // V8 binding expects ScriptController::clearWindowProxy only be called when a |
| 234 // frame is loading a new page. This creates a new context for the new page. | 218 // frame is loading a new page. This creates a new context for the new page. |
| 235 m_windowProxyManager->clearForNavigation(); | 219 m_windowProxyManager->clearForNavigation(); |
| 236 MainThreadDebugger::instance()->didClearContextsForFrame(frame()); | 220 MainThreadDebugger::instance()->didClearContextsForFrame(frame()); |
| 237 } | 221 } |
| 238 | 222 |
| 239 void ScriptController::updateDocument() { | 223 void ScriptController::updateDocument() { |
| 240 m_windowProxyManager->mainWorldProxy()->updateDocument(); | 224 m_windowProxyManager->mainWorldProxyMaybeUninitialized()->updateDocument(); |
| 241 } | 225 } |
| 242 | 226 |
| 243 bool ScriptController::executeScriptIfJavaScriptURL(const KURL& url, | 227 bool ScriptController::executeScriptIfJavaScriptURL(const KURL& url, |
| 244 Element* element) { | 228 Element* element) { |
| 245 if (!url.protocolIsJavaScript()) | 229 if (!url.protocolIsJavaScript()) |
| 246 return false; | 230 return false; |
| 247 | 231 |
| 248 const int javascriptSchemeLength = sizeof("javascript:") - 1; | 232 const int javascriptSchemeLength = sizeof("javascript:") - 1; |
| 249 String scriptSource = decodeURLEscapeSequences(url.getString()) | 233 String scriptSource = decodeURLEscapeSequences(url.getString()) |
| 250 .substring(javascriptSchemeLength); | 234 .substring(javascriptSchemeLength); |
| (...skipping 124 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 375 for (size_t i = 0; i < resultArray->Length(); ++i) { | 359 for (size_t i = 0; i < resultArray->Length(); ++i) { |
| 376 v8::Local<v8::Value> value; | 360 v8::Local<v8::Value> value; |
| 377 if (!resultArray->Get(scriptState->context(), i).ToLocal(&value)) | 361 if (!resultArray->Get(scriptState->context(), i).ToLocal(&value)) |
| 378 return; | 362 return; |
| 379 results->push_back(value); | 363 results->push_back(value); |
| 380 } | 364 } |
| 381 } | 365 } |
| 382 } | 366 } |
| 383 | 367 |
| 384 } // namespace blink | 368 } // namespace blink |
| OLD | NEW |