summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authoryurys@google.com <yurys@google.com@0039d316-1c4b-4281-b951-d872f2087c98>2009-09-02 10:19:47 +0000
committeryurys@google.com <yurys@google.com@0039d316-1c4b-4281-b951-d872f2087c98>2009-09-02 10:19:47 +0000
commit4f3b21c1f75a48350ab918d01b4fdd2ed681d2b3 (patch)
tree9ffab64ffed721d5aef2a52e8f54fe2b3a6a2ec7
parent54b004dbd789fab3761f61dbb791abf0dd79bfaf (diff)
downloadchromium_src-4f3b21c1f75a48350ab918d01b4fdd2ed681d2b3.zip
chromium_src-4f3b21c1f75a48350ab918d01b4fdd2ed681d2b3.tar.gz
chromium_src-4f3b21c1f75a48350ab918d01b4fdd2ed681d2b3.tar.bz2
DevTools: create InspectorBackend v8 wrapper in the utility context so that it's methods prototype is Function.protoype object from the utility context. Otherwise some useful methods defined on Function.prototype(such as bind) are missing for InspectorController native methods.
It caused an exception in InjectedScript._ensureCommandLineAPIInstalled. Review URL: http://codereview.chromium.org/188006 git-svn-id: svn://svn.chromium.org/chrome/trunk/src@25163 0039d316-1c4b-4281-b951-d872f2087c98
-rw-r--r--webkit/glue/webdevtoolsagent_impl.cc53
-rw-r--r--webkit/glue/webdevtoolsagent_impl.h6
2 files changed, 56 insertions, 3 deletions
diff --git a/webkit/glue/webdevtoolsagent_impl.cc b/webkit/glue/webdevtoolsagent_impl.cc
index 779b41f..e6d267a 100644
--- a/webkit/glue/webdevtoolsagent_impl.cc
+++ b/webkit/glue/webdevtoolsagent_impl.cc
@@ -8,6 +8,7 @@
#include "Document.h"
#include "EventListener.h"
+#include "InspectorBackend.h"
#include "InspectorController.h"
#include "InspectorFrontend.h"
#include "InspectorResource.h"
@@ -19,6 +20,7 @@
#include "ScriptValue.h"
#include "V8Binding.h"
#include "V8Proxy.h"
+#include "V8Utilities.h"
#include <wtf/OwnPtr.h>
#undef LOG
@@ -34,11 +36,13 @@
#include "webkit/glue/webview_impl.h"
using WebCore::Document;
+using WebCore::InspectorBackend;
using WebCore::InspectorController;
using WebCore::InspectorFrontend;
using WebCore::InspectorResource;
using WebCore::Node;
using WebCore::Page;
+using WebCore::SafeAllocation;
using WebCore::ScriptObject;
using WebCore::ScriptState;
using WebCore::ScriptValue;
@@ -50,6 +54,18 @@ using WebKit::WebDataSource;
using WebKit::WebFrame;
using WebKit::WebURLRequest;
+
+namespace {
+
+void InspectorBackendWeakReferenceCallback(v8::Persistent<v8::Value> object,
+ void* parameter) {
+ InspectorBackend* backend = static_cast<InspectorBackend*>(parameter);
+ backend->deref();
+ object.Dispose();
+}
+
+} // namespace
+
WebDevToolsAgentImpl::WebDevToolsAgentImpl(
WebViewImpl* web_view_impl,
WebDevToolsAgentDelegate* delegate)
@@ -225,11 +241,42 @@ void WebDevToolsAgentImpl::InitDevToolsAgentHost() {
v8::HandleScope scope;
v8::Context::Scope utility_scope(utility_context_);
- InspectorController* ic = web_view_impl_->page()->inspectorController();
+ // Call custom code to create inspector backend wrapper in the utility context
+ // instead of calling V8DOMWrapper::convertToV8Object that would create the
+ // wrapper in the Page main frame context.
+ v8::Handle<v8::Object> backend_wrapper = CreateInspectorBackendV8Wrapper();
+ if (backend_wrapper.IsEmpty()) {
+ return;
+ }
utility_context_->Global()->Set(
v8::String::New("InspectorController"),
- V8DOMWrapper::convertToV8Object(V8ClassIndex::INSPECTORBACKEND,
- ic->inspectorBackend()));
+ backend_wrapper);
+}
+
+v8::Local<v8::Object> WebDevToolsAgentImpl::CreateInspectorBackendV8Wrapper() {
+ V8ClassIndex::V8WrapperType descriptorType = V8ClassIndex::INSPECTORBACKEND;
+ v8::Handle<v8::Function> function =
+ V8DOMWrapper::getTemplate(descriptorType)->GetFunction();
+ if (function.IsEmpty()) {
+ // Return if allocation failed.
+ return v8::Local<v8::Object>();
+ }
+ v8::Local<v8::Object> instance = SafeAllocation::newInstance(function);
+ if (instance.IsEmpty()) {
+ // Avoid setting the wrapper if allocation failed.
+ return v8::Local<v8::Object>();
+ }
+ InspectorBackend* backend =
+ web_view_impl_->page()->inspectorController()->inspectorBackend();
+ V8DOMWrapper::setDOMWrapper(instance, V8ClassIndex::ToInt(descriptorType),
+ backend);
+ // Create a weak reference to the v8 wrapper of InspectorBackend to deref
+ // InspectorBackend when the wrapper is garbage collected.
+ backend->ref();
+ v8::Persistent<v8::Object> weak_handle =
+ v8::Persistent<v8::Object>::New(instance);
+ weak_handle.MakeWeak(backend, &InspectorBackendWeakReferenceCallback);
+ return instance;
}
void WebDevToolsAgentImpl::ResetInspectorFrontendProxy() {
diff --git a/webkit/glue/webdevtoolsagent_impl.h b/webkit/glue/webdevtoolsagent_impl.h
index 0df46d9..14cd367 100644
--- a/webkit/glue/webdevtoolsagent_impl.h
+++ b/webkit/glue/webdevtoolsagent_impl.h
@@ -89,6 +89,12 @@ class WebDevToolsAgentImpl
void InitDevToolsAgentHost();
void ResetInspectorFrontendProxy();
+ // Creates InspectorBackend v8 wrapper in the utility context so that it's
+ // methods prototype is Function.protoype object from the utility context.
+ // Otherwise some useful methods defined on Function.prototype(such as bind)
+ // are missing for InspectorController native methods.
+ v8::Local<v8::Object> CreateInspectorBackendV8Wrapper();
+
int host_id_;
WebDevToolsAgentDelegate* delegate_;
WebViewImpl* web_view_impl_;