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 36 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
47 #include "bindings/core/v8/V8ScriptRunner.h" | 47 #include "bindings/core/v8/V8ScriptRunner.h" |
48 #include "bindings/core/v8/V8Window.h" | 48 #include "bindings/core/v8/V8Window.h" |
49 #include "bindings/core/v8/WindowProxy.h" | 49 #include "bindings/core/v8/WindowProxy.h" |
50 #include "bindings/core/v8/npruntime_impl.h" | 50 #include "bindings/core/v8/npruntime_impl.h" |
51 #include "bindings/core/v8/npruntime_priv.h" | 51 #include "bindings/core/v8/npruntime_priv.h" |
52 #include "core/dom/Document.h" | 52 #include "core/dom/Document.h" |
53 #include "core/dom/Node.h" | 53 #include "core/dom/Node.h" |
54 #include "core/dom/ScriptableDocumentParser.h" | 54 #include "core/dom/ScriptableDocumentParser.h" |
55 #include "core/events/Event.h" | 55 #include "core/events/Event.h" |
56 #include "core/events/EventListener.h" | 56 #include "core/events/EventListener.h" |
| 57 #include "core/frame/FrameProtector.h" |
57 #include "core/frame/LocalDOMWindow.h" | 58 #include "core/frame/LocalDOMWindow.h" |
58 #include "core/frame/LocalFrame.h" | 59 #include "core/frame/LocalFrame.h" |
59 #include "core/frame/Settings.h" | 60 #include "core/frame/Settings.h" |
60 #include "core/frame/UseCounter.h" | 61 #include "core/frame/UseCounter.h" |
61 #include "core/frame/csp/ContentSecurityPolicy.h" | 62 #include "core/frame/csp/ContentSecurityPolicy.h" |
62 #include "core/html/HTMLPlugInElement.h" | 63 #include "core/html/HTMLPlugInElement.h" |
63 #include "core/inspector/InspectorInstrumentation.h" | 64 #include "core/inspector/InspectorInstrumentation.h" |
64 #include "core/inspector/InspectorTraceEvents.h" | 65 #include "core/inspector/InspectorTraceEvents.h" |
65 #include "core/inspector/ScriptCallStack.h" | 66 #include "core/inspector/ScriptCallStack.h" |
66 #include "core/loader/DocumentLoader.h" | 67 #include "core/loader/DocumentLoader.h" |
(...skipping 68 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
135 } | 136 } |
136 | 137 |
137 void ScriptController::updateSecurityOrigin(SecurityOrigin* origin) | 138 void ScriptController::updateSecurityOrigin(SecurityOrigin* origin) |
138 { | 139 { |
139 m_windowProxy->updateSecurityOrigin(origin); | 140 m_windowProxy->updateSecurityOrigin(origin); |
140 } | 141 } |
141 | 142 |
142 v8::Local<v8::Value> ScriptController::callFunction(v8::Handle<v8::Function> fun
ction, v8::Handle<v8::Value> receiver, int argc, v8::Handle<v8::Value> info[]) | 143 v8::Local<v8::Value> ScriptController::callFunction(v8::Handle<v8::Function> fun
ction, v8::Handle<v8::Value> receiver, int argc, v8::Handle<v8::Value> info[]) |
143 { | 144 { |
144 // Keep LocalFrame (and therefore ScriptController) alive. | 145 // Keep LocalFrame (and therefore ScriptController) alive. |
145 RefPtr<LocalFrame> protect(m_frame); | 146 FrameProtector protect(m_frame); |
146 return ScriptController::callFunction(m_frame->document(), function, receive
r, argc, info, m_isolate); | 147 return ScriptController::callFunction(m_frame->document(), function, receive
r, argc, info, m_isolate); |
147 } | 148 } |
148 | 149 |
149 v8::Local<v8::Value> ScriptController::callFunction(ExecutionContext* context, v
8::Handle<v8::Function> function, v8::Handle<v8::Value> receiver, int argc, v8::
Handle<v8::Value> info[], v8::Isolate* isolate) | 150 v8::Local<v8::Value> ScriptController::callFunction(ExecutionContext* context, v
8::Handle<v8::Function> function, v8::Handle<v8::Value> receiver, int argc, v8::
Handle<v8::Value> info[], v8::Isolate* isolate) |
150 { | 151 { |
151 TRACE_EVENT1(TRACE_DISABLED_BY_DEFAULT("devtools.timeline"), "FunctionCall",
"data", devToolsTraceEventData(context, function, isolate)); | 152 TRACE_EVENT1(TRACE_DISABLED_BY_DEFAULT("devtools.timeline"), "FunctionCall",
"data", devToolsTraceEventData(context, function, isolate)); |
152 TRACE_EVENT_INSTANT1(TRACE_DISABLED_BY_DEFAULT("devtools.timeline.stack"), "
CallStack", "stack", InspectorCallStackEvent::currentCallStack()); | 153 TRACE_EVENT_INSTANT1(TRACE_DISABLED_BY_DEFAULT("devtools.timeline.stack"), "
CallStack", "stack", InspectorCallStackEvent::currentCallStack()); |
153 // FIXME(361045): remove InspectorInstrumentation calls once DevTools Timeli
ne migrates to tracing. | 154 // FIXME(361045): remove InspectorInstrumentation calls once DevTools Timeli
ne migrates to tracing. |
154 InspectorInstrumentationCookie cookie; | 155 InspectorInstrumentationCookie cookie; |
155 if (InspectorInstrumentation::timelineAgentEnabled(context)) { | 156 if (InspectorInstrumentation::timelineAgentEnabled(context)) { |
(...skipping 26 matching lines...) Expand all Loading... |
182 // Isolate exceptions that occur when compiling and executing | 183 // Isolate exceptions that occur when compiling and executing |
183 // the code. These exceptions should not interfere with | 184 // the code. These exceptions should not interfere with |
184 // javascript code we might evaluate from C++ when returning | 185 // javascript code we might evaluate from C++ when returning |
185 // from here. | 186 // from here. |
186 v8::TryCatch tryCatch; | 187 v8::TryCatch tryCatch; |
187 tryCatch.SetVerbose(true); | 188 tryCatch.SetVerbose(true); |
188 | 189 |
189 v8::Handle<v8::Script> script = V8ScriptRunner::compileScript(source, m_
isolate, corsStatus, v8CacheOptions); | 190 v8::Handle<v8::Script> script = V8ScriptRunner::compileScript(source, m_
isolate, corsStatus, v8CacheOptions); |
190 | 191 |
191 // Keep LocalFrame (and therefore ScriptController) alive. | 192 // Keep LocalFrame (and therefore ScriptController) alive. |
192 RefPtr<LocalFrame> protect(m_frame); | 193 FrameProtector protect(m_frame); |
193 result = V8ScriptRunner::runCompiledScript(script, m_frame->document(),
m_isolate); | 194 result = V8ScriptRunner::runCompiledScript(script, m_frame->document(),
m_isolate); |
194 ASSERT(!tryCatch.HasCaught() || result.IsEmpty()); | 195 ASSERT(!tryCatch.HasCaught() || result.IsEmpty()); |
195 } | 196 } |
196 | 197 |
197 InspectorInstrumentation::didEvaluateScript(cookie); | 198 InspectorInstrumentation::didEvaluateScript(cookie); |
198 TRACE_EVENT_INSTANT1(TRACE_DISABLED_BY_DEFAULT("devtools.timeline"), "Update
Counters", "data", InspectorUpdateCountersEvent::data()); | 199 TRACE_EVENT_INSTANT1(TRACE_DISABLED_BY_DEFAULT("devtools.timeline"), "Update
Counters", "data", InspectorUpdateCountersEvent::data()); |
199 | 200 |
200 return result; | 201 return result; |
201 } | 202 } |
202 | 203 |
(...skipping 323 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
526 { | 527 { |
527 if (!protocolIsJavaScript(url)) | 528 if (!protocolIsJavaScript(url)) |
528 return false; | 529 return false; |
529 | 530 |
530 if (!m_frame->page() | 531 if (!m_frame->page() |
531 || !m_frame->document()->contentSecurityPolicy()->allowJavaScriptURLs(m_
frame->document()->url(), eventHandlerPosition().m_line)) | 532 || !m_frame->document()->contentSecurityPolicy()->allowJavaScriptURLs(m_
frame->document()->url(), eventHandlerPosition().m_line)) |
532 return true; | 533 return true; |
533 | 534 |
534 // We need to hold onto the LocalFrame here because executing script can | 535 // We need to hold onto the LocalFrame here because executing script can |
535 // destroy the frame. | 536 // destroy the frame. |
536 RefPtr<LocalFrame> protector(m_frame); | 537 FrameProtector protect(m_frame); |
537 RefPtrWillBeRawPtr<Document> ownerDocument(m_frame->document()); | 538 RefPtrWillBeRawPtr<Document> ownerDocument(m_frame->document()); |
538 | 539 |
539 const int javascriptSchemeLength = sizeof("javascript:") - 1; | 540 const int javascriptSchemeLength = sizeof("javascript:") - 1; |
540 | 541 |
541 bool locationChangeBefore = m_frame->navigationScheduler().locationChangePen
ding(); | 542 bool locationChangeBefore = m_frame->navigationScheduler().locationChangePen
ding(); |
542 | 543 |
543 String decodedURL = decodeURLEscapeSequences(url.string()); | 544 String decodedURL = decodeURLEscapeSequences(url.string()); |
544 v8::HandleScope handleScope(m_isolate); | 545 v8::HandleScope handleScope(m_isolate); |
545 v8::Local<v8::Value> result = evaluateScriptInMainWorld(ScriptSourceCode(dec
odedURL.substring(javascriptSchemeLength)), NotSharableCrossOrigin, DoNotExecute
ScriptWhenScriptsDisabled); | 546 v8::Local<v8::Value> result = evaluateScriptInMainWorld(ScriptSourceCode(dec
odedURL.substring(javascriptSchemeLength)), NotSharableCrossOrigin, DoNotExecute
ScriptWhenScriptsDisabled); |
546 | 547 |
(...skipping 42 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
589 m_sourceURL = &sourceURL; | 590 m_sourceURL = &sourceURL; |
590 | 591 |
591 v8::EscapableHandleScope handleScope(m_isolate); | 592 v8::EscapableHandleScope handleScope(m_isolate); |
592 v8::Handle<v8::Context> context = toV8Context(m_frame, DOMWrapperWorld::main
World()); | 593 v8::Handle<v8::Context> context = toV8Context(m_frame, DOMWrapperWorld::main
World()); |
593 if (context.IsEmpty()) | 594 if (context.IsEmpty()) |
594 return v8::Local<v8::Value>(); | 595 return v8::Local<v8::Value>(); |
595 | 596 |
596 ScriptState* scriptState = ScriptState::from(context); | 597 ScriptState* scriptState = ScriptState::from(context); |
597 ScriptState::Scope scope(scriptState); | 598 ScriptState::Scope scope(scriptState); |
598 | 599 |
599 RefPtr<LocalFrame> protect(m_frame); | 600 FrameProtector protect(m_frame); |
600 if (m_frame->loader().stateMachine()->isDisplayingInitialEmptyDocument()) | 601 if (m_frame->loader().stateMachine()->isDisplayingInitialEmptyDocument()) |
601 m_frame->loader().didAccessInitialDocument(); | 602 m_frame->loader().didAccessInitialDocument(); |
602 | 603 |
603 OwnPtr<ScriptSourceCode> maybeProcessedSourceCode = InspectorInstrumentatio
n::preprocess(m_frame, sourceCode); | 604 OwnPtr<ScriptSourceCode> maybeProcessedSourceCode = InspectorInstrumentatio
n::preprocess(m_frame, sourceCode); |
604 const ScriptSourceCode& sourceCodeToCompile = maybeProcessedSourceCode ? *ma
ybeProcessedSourceCode : sourceCode; | 605 const ScriptSourceCode& sourceCodeToCompile = maybeProcessedSourceCode ? *ma
ybeProcessedSourceCode : sourceCode; |
605 | 606 |
606 v8::Local<v8::Value> object = executeScriptAndReturnValue(scriptState->conte
xt(), sourceCodeToCompile, corsStatus); | 607 v8::Local<v8::Value> object = executeScriptAndReturnValue(scriptState->conte
xt(), sourceCodeToCompile, corsStatus); |
607 m_sourceURL = savedSourceURL; | 608 m_sourceURL = savedSourceURL; |
608 | 609 |
609 if (object.IsEmpty()) | 610 if (object.IsEmpty()) |
(...skipping 23 matching lines...) Expand all Loading... |
633 resultArray->Set(i, evaluationResult); | 634 resultArray->Set(i, evaluationResult); |
634 } | 635 } |
635 | 636 |
636 if (results) { | 637 if (results) { |
637 for (size_t i = 0; i < resultArray->Length(); ++i) | 638 for (size_t i = 0; i < resultArray->Length(); ++i) |
638 results->append(handleScope.Escape(resultArray->Get(i))); | 639 results->append(handleScope.Escape(resultArray->Get(i))); |
639 } | 640 } |
640 } | 641 } |
641 | 642 |
642 } // namespace blink | 643 } // namespace blink |
OLD | NEW |