Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(12)

Side by Side Diff: third_party/WebKit/Source/platform/v8_inspector/InjectedScript.cpp

Issue 1924713002: [DevTools] Removed InjectedScriptHost (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@move-inspect-to-native
Patch Set: Created 4 years, 7 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
1 /* 1 /*
2 * Copyright (C) 2012 Google Inc. All rights reserved. 2 * Copyright (C) 2012 Google Inc. All rights reserved.
3 * 3 *
4 * Redistribution and use in source and binary forms, with or without 4 * Redistribution and use in source and binary forms, with or without
5 * modification, are permitted provided that the following conditions are 5 * modification, are permitted provided that the following conditions are
6 * met: 6 * met:
7 * 7 *
8 * * Redistributions of source code must retain the above copyright 8 * * Redistributions of source code must retain the above copyright
9 * notice, this list of conditions and the following disclaimer. 9 * notice, this list of conditions and the following disclaimer.
10 * * Redistributions in binary form must reproduce the above 10 * * Redistributions in binary form must reproduce the above
(...skipping 15 matching lines...) Expand all
26 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 26 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
27 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 27 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
28 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 28 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
29 */ 29 */
30 30
31 #include "platform/v8_inspector/InjectedScript.h" 31 #include "platform/v8_inspector/InjectedScript.h"
32 32
33 #include "platform/inspector_protocol/Parser.h" 33 #include "platform/inspector_protocol/Parser.h"
34 #include "platform/inspector_protocol/String16.h" 34 #include "platform/inspector_protocol/String16.h"
35 #include "platform/inspector_protocol/Values.h" 35 #include "platform/inspector_protocol/Values.h"
36 #include "platform/v8_inspector/InjectedScriptHost.h"
37 #include "platform/v8_inspector/InjectedScriptNative.h" 36 #include "platform/v8_inspector/InjectedScriptNative.h"
38 #include "platform/v8_inspector/InjectedScriptSource.h" 37 #include "platform/v8_inspector/InjectedScriptSource.h"
39 #include "platform/v8_inspector/InspectedContext.h" 38 #include "platform/v8_inspector/InspectedContext.h"
40 #include "platform/v8_inspector/RemoteObjectId.h" 39 #include "platform/v8_inspector/RemoteObjectId.h"
41 #include "platform/v8_inspector/V8Compat.h" 40 #include "platform/v8_inspector/V8Compat.h"
42 #include "platform/v8_inspector/V8Console.h" 41 #include "platform/v8_inspector/V8Console.h"
43 #include "platform/v8_inspector/V8DebuggerImpl.h" 42 #include "platform/v8_inspector/V8DebuggerImpl.h"
44 #include "platform/v8_inspector/V8FunctionCall.h" 43 #include "platform/v8_inspector/V8FunctionCall.h"
45 #include "platform/v8_inspector/V8InjectedScriptHost.h" 44 #include "platform/v8_inspector/V8InjectedScriptHost.h"
46 #include "platform/v8_inspector/V8InspectorSessionImpl.h" 45 #include "platform/v8_inspector/V8InspectorSessionImpl.h"
(...skipping 15 matching lines...) Expand all
62 61
63 namespace blink { 62 namespace blink {
64 63
65 static bool hasInternalError(ErrorString* errorString, bool hasError) 64 static bool hasInternalError(ErrorString* errorString, bool hasError)
66 { 65 {
67 if (hasError) 66 if (hasError)
68 *errorString = "Internal error"; 67 *errorString = "Internal error";
69 return hasError; 68 return hasError;
70 } 69 }
71 70
72 PassOwnPtr<InjectedScript> InjectedScript::create(InspectedContext* inspectedCon text, InjectedScriptHost* injectedScriptHost) 71 PassOwnPtr<InjectedScript> InjectedScript::create(InspectedContext* inspectedCon text)
73 { 72 {
74 v8::Isolate* isolate = inspectedContext->isolate(); 73 v8::Isolate* isolate = inspectedContext->isolate();
75 v8::HandleScope handles(isolate); 74 v8::HandleScope handles(isolate);
76 v8::Local<v8::Context> context = inspectedContext->context(); 75 v8::Local<v8::Context> context = inspectedContext->context();
77 v8::Context::Scope scope(context); 76 v8::Context::Scope scope(context);
78 77
79 OwnPtr<InjectedScriptNative> injectedScriptNative = adoptPtr(new InjectedScr iptNative(isolate)); 78 OwnPtr<InjectedScriptNative> injectedScriptNative = adoptPtr(new InjectedScr iptNative(isolate));
80 String16 injectedScriptSource(reinterpret_cast<const char*>(InjectedScriptSo urce_js), sizeof(InjectedScriptSource_js)); 79 v8::Local<v8::Object> scriptHostWrapper = V8InjectedScriptHost::create(conte xt, inspectedContext->debugger());
81
82 v8::Local<v8::FunctionTemplate> wrapperTemplate = injectedScriptHost->wrappe rTemplate(isolate);
83 if (wrapperTemplate.IsEmpty()) {
84 wrapperTemplate = V8InjectedScriptHost::createWrapperTemplate(isolate);
85 injectedScriptHost->setWrapperTemplate(wrapperTemplate, isolate);
86 }
87
88 v8::Local<v8::Object> scriptHostWrapper = V8InjectedScriptHost::wrap(wrapper Template, context, injectedScriptHost);
89 if (scriptHostWrapper.IsEmpty())
90 return nullptr;
91
92 injectedScriptNative->setOnInjectedScriptHost(scriptHostWrapper); 80 injectedScriptNative->setOnInjectedScriptHost(scriptHostWrapper);
93 81
94 // Inject javascript into the context. The compiled script is supposed to ev aluate into 82 // Inject javascript into the context. The compiled script is supposed to ev aluate into
95 // a single anonymous function(it's anonymous to avoid cluttering the global object with 83 // a single anonymous function(it's anonymous to avoid cluttering the global object with
96 // inspector's stuff) the function is called a few lines below with Injected ScriptHost wrapper, 84 // inspector's stuff) the function is called a few lines below with Injected ScriptHost wrapper,
97 // injected script id and explicit reference to the inspected global object. The function is expected 85 // injected script id and explicit reference to the inspected global object. The function is expected
98 // to create and configure InjectedScript instance that is going to be used by the inspector. 86 // to create and configure InjectedScript instance that is going to be used by the inspector.
87 String16 injectedScriptSource(reinterpret_cast<const char*>(InjectedScriptSo urce_js), sizeof(InjectedScriptSource_js));
99 v8::Local<v8::Value> value; 88 v8::Local<v8::Value> value;
100 if (!inspectedContext->debugger()->compileAndRunInternalScript(context, toV8 String(isolate, injectedScriptSource)).ToLocal(&value)) 89 if (!inspectedContext->debugger()->compileAndRunInternalScript(context, toV8 String(isolate, injectedScriptSource)).ToLocal(&value))
101 return nullptr; 90 return nullptr;
102 ASSERT(value->IsFunction()); 91 ASSERT(value->IsFunction());
103 v8::Local<v8::Function> function = v8::Local<v8::Function>::Cast(value); 92 v8::Local<v8::Function> function = v8::Local<v8::Function>::Cast(value);
104 v8::Local<v8::Object> windowGlobal = context->Global(); 93 v8::Local<v8::Object> windowGlobal = context->Global();
105 v8::Local<v8::Value> info[] = { scriptHostWrapper, windowGlobal, v8::Number: :New(isolate, inspectedContext->contextId()) }; 94 v8::Local<v8::Value> info[] = { scriptHostWrapper, windowGlobal, v8::Number: :New(isolate, inspectedContext->contextId()) };
106 v8::MicrotasksScope microtasksScope(isolate, v8::MicrotasksScope::kDoNotRunM icrotasks); 95 v8::MicrotasksScope microtasksScope(isolate, v8::MicrotasksScope::kDoNotRunM icrotasks);
107 v8::Local<v8::Value> injectedScriptValue; 96 v8::Local<v8::Value> injectedScriptValue;
108 if (!function->Call(context, windowGlobal, WTF_ARRAY_LENGTH(info), info).ToL ocal(&injectedScriptValue)) 97 if (!function->Call(context, windowGlobal, WTF_ARRAY_LENGTH(info), info).ToL ocal(&injectedScriptValue))
(...skipping 442 matching lines...) Expand 10 before | Expand all | Expand 10 after
551 void InjectedScript::CallFrameScope::findInjectedScript(V8InspectorSessionImpl* session) 540 void InjectedScript::CallFrameScope::findInjectedScript(V8InspectorSessionImpl* session)
552 { 541 {
553 OwnPtr<RemoteCallFrameId> remoteId = RemoteCallFrameId::parse(m_errorString, m_remoteCallFrameId); 542 OwnPtr<RemoteCallFrameId> remoteId = RemoteCallFrameId::parse(m_errorString, m_remoteCallFrameId);
554 if (!remoteId) 543 if (!remoteId)
555 return; 544 return;
556 m_frameOrdinal = static_cast<size_t>(remoteId->frameOrdinal()); 545 m_frameOrdinal = static_cast<size_t>(remoteId->frameOrdinal());
557 m_injectedScript = session->findInjectedScript(m_errorString, remoteId.get() ); 546 m_injectedScript = session->findInjectedScript(m_errorString, remoteId.get() );
558 } 547 }
559 548
560 } // namespace blink 549 } // namespace blink
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698