diff options
author | pfeldman@chromium.org <pfeldman@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2009-04-10 13:15:31 +0000 |
---|---|---|
committer | pfeldman@chromium.org <pfeldman@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2009-04-10 13:15:31 +0000 |
commit | 198d8d43c5ccff8d0d48bbd3fef31917aa9d3db6 (patch) | |
tree | b09eb2c9ed8c7d60578859ff057ae299c8e002e7 /webkit | |
parent | fe7bad5497021cf0f3c20f2daf4c3ddb24ffda73 (diff) | |
download | chromium_src-198d8d43c5ccff8d0d48bbd3fef31917aa9d3db6.zip chromium_src-198d8d43c5ccff8d0d48bbd3fef31917aa9d3db6.tar.gz chromium_src-198d8d43c5ccff8d0d48bbd3fef31917aa9d3db6.tar.bz2 |
DevTools: Use v8 utility context in debugger agent.
Review URL: http://codereview.chromium.org/66030
git-svn-id: svn://svn.chromium.org/chrome/trunk/src@13501 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'webkit')
-rw-r--r-- | webkit/glue/devtools/debugger_agent_impl.cc | 50 |
1 files changed, 43 insertions, 7 deletions
diff --git a/webkit/glue/devtools/debugger_agent_impl.cc b/webkit/glue/devtools/debugger_agent_impl.cc index dc475ab..299af72 100644 --- a/webkit/glue/devtools/debugger_agent_impl.cc +++ b/webkit/glue/devtools/debugger_agent_impl.cc @@ -10,6 +10,7 @@ #include "grit/webkit_resources.h" #include "V8Binding.h" +#include "V8DOMWindow.h" #include "v8_index.h" #include "v8_proxy.h" #include "webkit/glue/devtools/debugger_agent_impl.h" @@ -18,10 +19,13 @@ #include "webkit/glue/webkit_glue.h" #include "webkit/glue/webview_impl.h" +using WebCore::DOMWindow; using WebCore::Document; using WebCore::Node; using WebCore::String; using WebCore::V8ClassIndex; +using WebCore::V8Custom; +using WebCore::V8DOMWindow; using WebCore::V8Proxy; DebuggerAgentImpl::DebuggerAgentImpl( @@ -48,18 +52,49 @@ void DebuggerAgentImpl::DebuggerOutput(const std::string& command) { void DebuggerAgentImpl::SetDocument(Document* document) { v8::HandleScope scope; - v8::Handle<v8::ObjectTemplate> global_template = v8::ObjectTemplate::New(); + if (!document) { - context_ = v8::Context::New(NULL /* no extensions */, global_template); + context_.Dispose(); return; } - // TODO(pfeldman): Do not modify existing context - introduce utility one - // instead. - context_ = v8::Persistent<v8::Context>::New( - V8Proxy::GetContext(document->frame())); + // TODO(pfeldman): Validate against Soeren. + // Set up the DOM window as the prototype of the new global object. + v8::Handle<v8::Context> window_context = + V8Proxy::GetContext(document->frame()); + v8::Handle<v8::Object> window_global = window_context->Global(); + v8::Handle<v8::Value> window_wrapper = + V8Proxy::LookupDOMWrapper(V8ClassIndex::DOMWINDOW, window_global); + + ASSERT(V8Proxy::DOMWrapperToNative<DOMWindow>(window_wrapper) == + document->frame()->domWindow()); + + // Create a new environment using an empty template for the shadow + // object. Reuse the global object if one has been created earlier. + v8::Handle<v8::ObjectTemplate> global_template = + V8DOMWindow::GetShadowObjectTemplate(); + + // Install a security handler with V8. + global_template->SetAccessCheckCallbacks( + V8Custom::v8DOMWindowNamedSecurityCheck, + V8Custom::v8DOMWindowIndexedSecurityCheck, + v8::Integer::New(V8ClassIndex::DOMWINDOW)); + + context_ = v8::Context::New( + NULL /* no extensions */, + global_template, + v8::Handle<v8::Object>()); v8::Context::Scope context_scope(context_); + v8::Handle<v8::Object> global = context_->Global(); + + v8::Handle<v8::String> implicit_proto_string = v8::String::New("__proto__"); + global->Set(implicit_proto_string, window_wrapper); + // Give the code running in the new context a way to get access to the + // original context. + global->Set(v8::String::New("contentWindow"), window_global); + + // Inject javascript into the context. StringPiece basejs = webkit_glue::GetDataResource(IDR_DEVTOOLS_BASE_JS); v8::Script::Compile(v8::String::New(basejs.as_string().c_str()))->Run(); StringPiece jsonjs = webkit_glue::GetDataResource(IDR_DEVTOOLS_JSON_JS); @@ -73,7 +108,8 @@ String DebuggerAgentImpl::ExecuteUtilityFunction( Node* node, const String& json_args) { v8::HandleScope scope; - v8::Context::Scope context_scope(v8::Local<v8::Context>::New(context_)); + ASSERT(!context_.IsEmpty()); + v8::Context::Scope context_scope(context_); v8::Handle<v8::Function> function = v8::Local<v8::Function>::Cast( context_->Global()->Get(v8::String::New(function_name.utf8().data()))); |