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

Side by Side Diff: Source/bindings/v8/custom/V8InjectedScriptManager.cpp

Issue 24989007: Model each Dart library as its own ScriptState when devtools are enabled. (Closed) Base URL: svn://svn.chromium.org/multivm/trunk/webkit
Patch Set: Ready for review Created 7 years, 2 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 | Annotate | Revision Log
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 19 matching lines...) Expand all
30 30
31 #include "config.h" 31 #include "config.h"
32 #include "core/inspector/InjectedScriptManager.h" 32 #include "core/inspector/InjectedScriptManager.h"
33 33
34 #include "V8InjectedScriptHost.h" 34 #include "V8InjectedScriptHost.h"
35 #include "V8Window.h" 35 #include "V8Window.h"
36 #include "bindings/v8/BindingSecurity.h" 36 #include "bindings/v8/BindingSecurity.h"
37 #include "bindings/v8/ScriptDebugServer.h" 37 #include "bindings/v8/ScriptDebugServer.h"
38 #include "bindings/v8/ScriptObject.h" 38 #include "bindings/v8/ScriptObject.h"
39 #include "bindings/v8/V8Binding.h" 39 #include "bindings/v8/V8Binding.h"
40 #include "bindings/v8/V8HiddenPropertyName.h"
40 #include "bindings/v8/V8ObjectConstructor.h" 41 #include "bindings/v8/V8ObjectConstructor.h"
41 #include "bindings/v8/V8ScriptRunner.h" 42 #include "bindings/v8/V8ScriptRunner.h"
42 #include "core/inspector/InjectedScriptHost.h" 43 #include "core/inspector/InjectedScriptHost.h"
43 #include "core/page/DOMWindow.h" 44 #include "core/page/DOMWindow.h"
44 #include "wtf/RefPtr.h" 45 #include "wtf/RefPtr.h"
45 46
46 namespace WebCore { 47 namespace WebCore {
47 48
48 static v8::Local<v8::Object> createInjectedScriptHostV8Wrapper(InjectedScriptHos t* host, v8::Isolate* isolate) 49 static v8::Local<v8::Object> createInjectedScriptHostV8Wrapper(InjectedScriptHos t* host, v8::Isolate* isolate)
49 { 50 {
(...skipping 25 matching lines...) Expand all
75 v8::Context::Scope contextScope(inspectedContext); 76 v8::Context::Scope contextScope(inspectedContext);
76 77
77 // Call custom code to create InjectedScripHost wrapper specific for the con text 78 // Call custom code to create InjectedScripHost wrapper specific for the con text
78 // instead of calling toV8() that would create the 79 // instead of calling toV8() that would create the
79 // wrapper in the current context. 80 // wrapper in the current context.
80 // FIXME: make it possible to use generic bindings factory for InjectedScrip tHost. 81 // FIXME: make it possible to use generic bindings factory for InjectedScrip tHost.
81 v8::Local<v8::Object> scriptHostWrapper = createInjectedScriptHostV8Wrapper( m_injectedScriptHost.get(), inspectedContext->GetIsolate()); 82 v8::Local<v8::Object> scriptHostWrapper = createInjectedScriptHostV8Wrapper( m_injectedScriptHost.get(), inspectedContext->GetIsolate());
82 if (scriptHostWrapper.IsEmpty()) 83 if (scriptHostWrapper.IsEmpty())
83 return ScriptObject(); 84 return ScriptObject();
84 85
86 // Store the inspectedScriptState on the scriptHostWrapper if it is
87 // different from the ScriptState associated with the context.
88 // This is needed to support Dart as Dart does not create a separate V8
89 // context for every Dart library.
90 if (inspectedScriptState != ScriptState::forContext(inspectedContext))
91 scriptHostWrapper->SetHiddenValue(V8HiddenPropertyName::scriptState(), v 8::External::New(inspectedScriptState));
92
85 // Inject javascript into the context. The compiled script is supposed to ev aluate into 93 // Inject javascript into the context. The compiled script is supposed to ev aluate into
86 // a single anonymous function(it's anonymous to avoid cluttering the global object with 94 // a single anonymous function(it's anonymous to avoid cluttering the global object with
87 // inspector's stuff) the function is called a few lines below with Injected ScriptHost wrapper, 95 // inspector's stuff) the function is called a few lines below with Injected ScriptHost wrapper,
88 // injected script id and explicit reference to the inspected global object. The function is expected 96 // injected script id and explicit reference to the inspected global object. The function is expected
89 // to create and configure InjectedScript instance that is going to be used by the inspector. 97 // to create and configure InjectedScript instance that is going to be used by the inspector.
90 v8::Local<v8::Value> value = V8ScriptRunner::compileAndRunInternalScript(v8S tring(scriptSource, isolate), isolate); 98 v8::Local<v8::Value> value = V8ScriptRunner::compileAndRunInternalScript(v8S tring(scriptSource, isolate), isolate);
91 ASSERT(!value.IsEmpty()); 99 ASSERT(!value.IsEmpty());
92 ASSERT(value->IsFunction()); 100 ASSERT(value->IsFunction());
93 101
94 v8::Local<v8::Object> windowGlobal = inspectedContext->Global(); 102 v8::Local<v8::Object> windowGlobal = inspectedContext->Global();
95 v8::Handle<v8::Value> args[] = { scriptHostWrapper, windowGlobal, v8::Number ::New(id) }; 103 v8::Handle<v8::Value> args[] = { scriptHostWrapper, windowGlobal, v8::Number ::New(id) };
96 v8::Local<v8::Value> injectedScriptValue = V8ScriptRunner::callInternalFunct ion(v8::Local<v8::Function>::Cast(value), windowGlobal, WTF_ARRAY_LENGTH(args), args, inspectedContext->GetIsolate()); 104 v8::Local<v8::Value> injectedScriptValue = V8ScriptRunner::callInternalFunct ion(v8::Local<v8::Function>::Cast(value), windowGlobal, WTF_ARRAY_LENGTH(args), args, inspectedContext->GetIsolate());
105
97 return ScriptObject(inspectedScriptState, v8::Handle<v8::Object>::Cast(injec tedScriptValue)); 106 return ScriptObject(inspectedScriptState, v8::Handle<v8::Object>::Cast(injec tedScriptValue));
98 } 107 }
99 108
100 bool InjectedScriptManager::canAccessInspectedWindow(ScriptState* scriptState) 109 bool InjectedScriptManager::canAccessInspectedWindow(ScriptState* scriptState)
101 { 110 {
102 v8::HandleScope handleScope; 111 v8::HandleScope handleScope;
103 v8::Local<v8::Context> context = scriptState->context(); 112 v8::Local<v8::Context> context = scriptState->context();
104 v8::Local<v8::Object> global = context->Global(); 113 v8::Local<v8::Object> global = context->Global();
105 if (global.IsEmpty()) 114 if (global.IsEmpty())
106 return false; 115 return false;
107 v8::Handle<v8::Object> holder = global->FindInstanceInPrototypeChain(V8Windo w::GetTemplate(context->GetIsolate(), MainWorld)); 116 v8::Handle<v8::Object> holder = global->FindInstanceInPrototypeChain(V8Windo w::GetTemplate(context->GetIsolate(), MainWorld));
108 if (holder.IsEmpty()) 117 if (holder.IsEmpty())
109 holder = global->FindInstanceInPrototypeChain(V8Window::GetTemplate(cont ext->GetIsolate(), IsolatedWorld)); 118 holder = global->FindInstanceInPrototypeChain(V8Window::GetTemplate(cont ext->GetIsolate(), IsolatedWorld));
110 if (holder.IsEmpty()) 119 if (holder.IsEmpty())
111 return false; 120 return false;
112 Frame* frame = V8Window::toNative(holder)->frame(); 121 Frame* frame = V8Window::toNative(holder)->frame();
113 122
114 v8::Context::Scope contextScope(context); 123 v8::Context::Scope contextScope(context);
115 return BindingSecurity::shouldAllowAccessToFrame(frame, DoNotReportSecurityE rror); 124 return BindingSecurity::shouldAllowAccessToFrame(frame, DoNotReportSecurityE rror);
116 } 125 }
117 126
118 void InjectedScriptManager::makeWeakCallback(v8::Isolate* isolate, v8::Persisten t<v8::Object>* object, InjectedScriptHost* host) 127 void InjectedScriptManager::makeWeakCallback(v8::Isolate* isolate, v8::Persisten t<v8::Object>* object, InjectedScriptHost* host)
119 { 128 {
120 host->deref(); 129 host->deref();
121 object->Dispose(isolate); 130 object->Dispose(isolate);
122 } 131 }
123 132
124 } // namespace WebCore 133 } // namespace WebCore
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698