summaryrefslogtreecommitdiffstats
path: root/webkit
diff options
context:
space:
mode:
authorjamesr@chromium.org <jamesr@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2009-10-12 23:57:18 +0000
committerjamesr@chromium.org <jamesr@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2009-10-12 23:57:18 +0000
commit2f7f4d591192cfdebee227b72e3cf57c7c604450 (patch)
tree181fc0fc257b6203c3ca2affb33f4b143de5fd3c /webkit
parent5a8459aa45b09a6cdcdd90ca190ba353799e3464 (diff)
downloadchromium_src-2f7f4d591192cfdebee227b72e3cf57c7c604450.zip
chromium_src-2f7f4d591192cfdebee227b72e3cf57c7c604450.tar.gz
chromium_src-2f7f4d591192cfdebee227b72e3cf57c7c604450.tar.bz2
Enables the sending of Timeline Agent and Resource messages to the devtools api in extensions.
Review URL: http://codereview.chromium.org/267013 git-svn-id: svn://svn.chromium.org/chrome/trunk/src@28761 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'webkit')
-rw-r--r--webkit/glue/devtools/apu_agent_delegate.h16
-rw-r--r--webkit/glue/devtools/js/inject_dispatch.js27
-rw-r--r--webkit/glue/webdevtoolsagent.h2
-rw-r--r--webkit/glue/webdevtoolsagent_impl.cc54
-rw-r--r--webkit/glue/webdevtoolsagent_impl.h6
-rw-r--r--webkit/webkit.gyp1
6 files changed, 105 insertions, 1 deletions
diff --git a/webkit/glue/devtools/apu_agent_delegate.h b/webkit/glue/devtools/apu_agent_delegate.h
new file mode 100644
index 0000000..17965d9
--- /dev/null
+++ b/webkit/glue/devtools/apu_agent_delegate.h
@@ -0,0 +1,16 @@
+// Copyright (c) 2009 The Chromium Authors. All rights reserved.
+// Use of this source code is governed by a BSD-style license that can be
+// found in the LICENSE file.
+
+#ifndef WEBKIT_GLUE_DEVTOOLS_APU_AGENT_DELEGATE_H_
+#define WEBKIT_GLUE_DEVTOOLS_APU_AGENT_DELEGATE_H_
+
+#include "webkit/glue/devtools/devtools_rpc.h"
+
+#define APU_AGENT_DELEGATE_STRUCT(METHOD0, METHOD1, METHOD2, METHOD3) \
+ /* Sends a json object to apu. */ \
+ METHOD1(DispatchToApu, String /* data */)
+
+DEFINE_RPC_CLASS(ApuAgentDelegate, APU_AGENT_DELEGATE_STRUCT)
+
+#endif // WEBKIT_GLUE_DEVTOOLS_APU_AGENT_DELEGATE_H_
diff --git a/webkit/glue/devtools/js/inject_dispatch.js b/webkit/glue/devtools/js/inject_dispatch.js
index 16dd56f..96c3fac 100644
--- a/webkit/glue/devtools/js/inject_dispatch.js
+++ b/webkit/glue/devtools/js/inject_dispatch.js
@@ -9,7 +9,6 @@
var InspectorControllerDispatcher = {};
-
/**
* Main dispatch method, all calls from the host to InspectorController go
* through this one.
@@ -22,6 +21,27 @@ InspectorControllerDispatcher.dispatch = function(functionName, json_args) {
InspectorController[functionName].apply(InspectorController, params);
};
+/**
+ * Special controller object for APU related messages. Outgoing messages
+ * are sent to this object if the ApuAgentDispatcher is enabled.
+ **/
+var ApuAgentDispatcher = { enabled : false };
+
+/**
+ * Dispatches messages to APU. This filters and transforms
+ * outgoing messages that are used by APU.
+ * @param {string} method name of the dispatch method.
+ **/
+ApuAgentDispatcher.dispatchToApu = function(method, args) {
+ if (method != 'addItemToTimeline' &&
+ method != 'updateResource' &&
+ method != 'addResource') {
+ return;
+ }
+ // TODO(knorton): Transform args so they can be used
+ // by APU.
+ DevToolsAgentHost.dispatchToApu(JSON.stringify(args));
+};
/**
* This is called by the InspectorFrontend for serialization.
@@ -41,6 +61,11 @@ function dispatch(method, var_args) {
return;
}
+ if (ApuAgentDispatcher.enabled) {
+ ApuAgentDispatcher.dispatchToApu(method, args);
+ return;
+ }
+
var call = JSON.stringify(args);
DevToolsAgentHost.dispatch(call);
};
diff --git a/webkit/glue/webdevtoolsagent.h b/webkit/glue/webdevtoolsagent.h
index 37ab24f..aca37ee 100644
--- a/webkit/glue/webdevtoolsagent.h
+++ b/webkit/glue/webdevtoolsagent.h
@@ -38,6 +38,8 @@ class WebDevToolsAgent {
virtual void InspectElement(int x, int y) = 0;
+ virtual void SetApuAgentEnabled(bool enabled) = 0;
+
// Asynchronously executes debugger command in the render thread.
// |caller_id| will be used for sending response.
static void ExecuteDebuggerCommand(const std::string& command,
diff --git a/webkit/glue/webdevtoolsagent_impl.cc b/webkit/glue/webdevtoolsagent_impl.cc
index a96143a..680033d 100644
--- a/webkit/glue/webdevtoolsagent_impl.cc
+++ b/webkit/glue/webdevtoolsagent_impl.cc
@@ -64,6 +64,18 @@ void InspectorBackendWeakReferenceCallback(v8::Persistent<v8::Value> object,
object.Dispose();
}
+void SetApuAgentEnabledInUtilityContext(v8::Handle<v8::Context> context,
+ bool enabled) {
+ v8::HandleScope handle_scope;
+ v8::Context::Scope context_scope(context);
+ v8::Handle<v8::Object> dispatcher = v8::Local<v8::Object>::Cast(
+ context->Global()->Get(v8::String::New("ApuAgentDispatcher")));
+ if (dispatcher.IsEmpty()) {
+ return;
+ }
+ dispatcher->Set(v8::String::New("enabled"), v8::Boolean::New(enabled));
+}
+
} // namespace
WebDevToolsAgentImpl::WebDevToolsAgentImpl(
@@ -72,10 +84,13 @@ WebDevToolsAgentImpl::WebDevToolsAgentImpl(
: host_id_(delegate->GetHostId()),
delegate_(delegate),
web_view_impl_(web_view_impl),
+ apu_agent_enabled_(false),
+ resource_tracking_was_enabled_(false),
attached_(false) {
debugger_agent_delegate_stub_.set(new DebuggerAgentDelegateStub(this));
tools_agent_delegate_stub_.set(new ToolsAgentDelegateStub(this));
tools_agent_native_delegate_stub_.set(new ToolsAgentNativeDelegateStub(this));
+ apu_agent_delegate_stub_.set(new ApuAgentDelegateStub(this));
}
WebDevToolsAgentImpl::~WebDevToolsAgentImpl() {
@@ -146,6 +161,7 @@ void WebDevToolsAgentImpl::DidCommitLoadForFrame(
ResetInspectorFrontendProxy();
tools_agent_delegate_stub_->FrameNavigate(
url.possibly_invalid_spec());
+ SetApuAgentEnabledInUtilityContext(utility_context_, apu_agent_enabled_);
}
UnhideResourcesPanelIfNecessary();
}
@@ -213,6 +229,27 @@ void WebDevToolsAgentImpl::GetResourceContent(
tools_agent_native_delegate_stub_->DidGetResourceContent(call_id, content);
}
+void WebDevToolsAgentImpl::SetApuAgentEnabled(bool enable) {
+ apu_agent_enabled_ = enable;
+ SetApuAgentEnabledInUtilityContext(utility_context_, enable);
+ InspectorController* ic = web_view_impl_->page()->inspectorController();
+ if (enable) {
+ resource_tracking_was_enabled_ = ic->resourceTrackingEnabled();
+ ic->enableTimeline(false);
+ if (!resource_tracking_was_enabled_) {
+ // TODO(knorton): Introduce some kind of agents dependency here so that
+ // user could turn off resource tracking while apu agent is on.
+ ic->enableResourceTracking(false);
+ }
+ } else {
+ ic->disableTimeline(false);
+ if (!resource_tracking_was_enabled_) {
+ ic->disableResourceTracking(false);
+ }
+ resource_tracking_was_enabled_ = false;
+ }
+}
+
void WebDevToolsAgentImpl::DispatchMessageFromClient(
const std::string& class_name,
const std::string& method_name,
@@ -261,6 +298,9 @@ void WebDevToolsAgentImpl::InitDevToolsAgentHost() {
devtools_agent_host_->AddProtoFunction(
"dispatch",
WebDevToolsAgentImpl::JsDispatchOnClient);
+ devtools_agent_host_->AddProtoFunction(
+ "dispatchToApu",
+ WebDevToolsAgentImpl::JsDispatchToApu);
devtools_agent_host_->Build();
v8::HandleScope scope;
@@ -340,6 +380,20 @@ v8::Handle<v8::Value> WebDevToolsAgentImpl::JsDispatchOnClient(
}
// static
+v8::Handle<v8::Value> WebDevToolsAgentImpl::JsDispatchToApu(
+ const v8::Arguments& args) {
+ v8::TryCatch exception_catcher;
+ String message = WebCore::toWebCoreStringWithNullCheck(args[0]);
+ if (message.isEmpty() || exception_catcher.HasCaught()) {
+ return v8::Undefined();
+ }
+ WebDevToolsAgentImpl* agent = static_cast<WebDevToolsAgentImpl*>(
+ v8::External::Cast(*args.Data())->Value());
+ agent->apu_agent_delegate_stub_->DispatchToApu(message);
+ return v8::Undefined();
+}
+
+// static
void WebDevToolsAgent::ExecuteDebuggerCommand(
const std::string& command,
int caller_id) {
diff --git a/webkit/glue/webdevtoolsagent_impl.h b/webkit/glue/webdevtoolsagent_impl.h
index 0a1ff97..b4efbe0 100644
--- a/webkit/glue/webdevtoolsagent_impl.h
+++ b/webkit/glue/webdevtoolsagent_impl.h
@@ -11,6 +11,7 @@
#include "v8.h"
#include "webkit/glue/devtools/devtools_rpc.h"
+#include "webkit/glue/devtools/apu_agent_delegate.h"
#include "webkit/glue/devtools/tools_agent.h"
#include "webkit/glue/webdevtoolsagent.h"
@@ -55,6 +56,7 @@ class WebDevToolsAgentImpl
virtual void GetResourceContent(
int call_id,
int identifier);
+ virtual void SetApuAgentEnabled(bool enable);
// WebDevToolsAgent implementation.
virtual void Attach();
@@ -88,6 +90,7 @@ class WebDevToolsAgentImpl
private:
static v8::Handle<v8::Value> JsDispatchOnClient(const v8::Arguments& args);
+ static v8::Handle<v8::Value> JsDispatchToApu(const v8::Arguments& args);
void DisposeUtilityContext();
void UnhideResourcesPanelIfNecessary();
@@ -107,6 +110,9 @@ class WebDevToolsAgentImpl
OwnPtr<ToolsAgentDelegateStub> tools_agent_delegate_stub_;
OwnPtr<ToolsAgentNativeDelegateStub> tools_agent_native_delegate_stub_;
OwnPtr<DebuggerAgentImpl> debugger_agent_impl_;
+ OwnPtr<ApuAgentDelegateStub> apu_agent_delegate_stub_;
+ bool apu_agent_enabled_;
+ bool resource_tracking_was_enabled_;
bool attached_;
// TODO(pfeldman): This should not be needed once GC styles issue is fixed
// for matching rules.
diff --git a/webkit/webkit.gyp b/webkit/webkit.gyp
index 5c04aac..30268fc 100644
--- a/webkit/webkit.gyp
+++ b/webkit/webkit.gyp
@@ -475,6 +475,7 @@
# This list contains all .h, .cc, and .mm files in glue except for
# those in the test subdirectory and those with unittest in in their
# names.
+ 'glue/devtools/apu_agent_delegate.h',
'glue/devtools/devtools_rpc.h',
'glue/devtools/devtools_rpc_js.h',
'glue/devtools/bound_object.cc',