summaryrefslogtreecommitdiffstats
path: root/webkit
diff options
context:
space:
mode:
authorpfeldman@chromium.org <pfeldman@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2009-09-21 15:26:31 +0000
committerpfeldman@chromium.org <pfeldman@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2009-09-21 15:26:31 +0000
commit3bd61de09a1aadbf57d61ace0d478b59bfd375f3 (patch)
tree04942387680d656e3140b087286a60c4a2a5559f /webkit
parent776775e2a12012b8747c3f2653140d0cf3036b6c (diff)
downloadchromium_src-3bd61de09a1aadbf57d61ace0d478b59bfd375f3.zip
chromium_src-3bd61de09a1aadbf57d61ace0d478b59bfd375f3.tar.gz
chromium_src-3bd61de09a1aadbf57d61ace0d478b59bfd375f3.tar.bz2
DevTools: Get rid of utility functions and ExecuteUtilityFunction as a whole. Eliminates the need in double-JSON of InjectedScript-related functions.
Review URL: http://codereview.chromium.org/201017 git-svn-id: svn://svn.chromium.org/chrome/trunk/src@26684 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'webkit')
-rw-r--r--webkit/glue/devtools/debugger_agent_impl.cc11
-rw-r--r--webkit/glue/devtools/debugger_agent_impl.h3
-rw-r--r--webkit/glue/devtools/js/devtools.js2
-rw-r--r--webkit/glue/devtools/js/devtools_host_stub.js81
-rw-r--r--webkit/glue/devtools/js/inject.js50
-rw-r--r--webkit/glue/devtools/js/inject_dispatch.js56
-rw-r--r--webkit/glue/devtools/js/inspector_controller_impl.js25
-rw-r--r--webkit/glue/devtools/js/profiler_processor.js11
-rw-r--r--webkit/glue/devtools/tools_agent.h16
-rw-r--r--webkit/glue/webdevtoolsagent_impl.cc18
-rw-r--r--webkit/glue/webdevtoolsagent_impl.h6
-rw-r--r--webkit/glue/webkit_resources.grd1
-rw-r--r--webkit/webkit.gyp1
13 files changed, 70 insertions, 211 deletions
diff --git a/webkit/glue/devtools/debugger_agent_impl.cc b/webkit/glue/devtools/debugger_agent_impl.cc
index 45b5470..5c1bfd8 100644
--- a/webkit/glue/devtools/debugger_agent_impl.cc
+++ b/webkit/glue/devtools/debugger_agent_impl.cc
@@ -139,11 +139,6 @@ void DebuggerAgentImpl::CreateUtilityContext(
webkit_glue::GetDataResource(IDR_DEVTOOLS_INJECT_WEBKIT_JS);
v8::Script::Compile(
v8::String::New(injectjs_webkit.as_string().c_str()))->Run();
-
- base::StringPiece injectjs = webkit_glue::GetDataResource(
- IDR_DEVTOOLS_INJECT_JS);
- v8::Script::Compile(v8::String::New(injectjs.as_string().c_str()))->Run();
-
base::StringPiece inject_dispatchjs = webkit_glue::GetDataResource(
IDR_DEVTOOLS_INJECT_DISPATCH_JS);
v8::Script::Compile(v8::String::New(
@@ -152,6 +147,7 @@ void DebuggerAgentImpl::CreateUtilityContext(
String DebuggerAgentImpl::ExecuteUtilityFunction(
v8::Handle<v8::Context> context,
+ const char* object,
const String &function_name,
const String& json_args,
String* exception) {
@@ -165,8 +161,11 @@ String DebuggerAgentImpl::ExecuteUtilityFunction(
DebuggerAgentManager::UtilityContextScope utility_scope;
+ v8::Handle<v8::Object> dispatch_object = v8::Handle<v8::Object>::Cast(
+ context->Global()->Get(v8::String::New(object)));
+
v8::Handle<v8::Value> dispatch_function =
- context->Global()->Get(v8::String::New("devtools$$dispatch"));
+ dispatch_object->Get(v8::String::New("dispatch"));
ASSERT(dispatch_function->IsFunction());
v8::Handle<v8::Function> function = v8::Handle<v8::Function>::Cast(dispatch_function);
diff --git a/webkit/glue/devtools/debugger_agent_impl.h b/webkit/glue/devtools/debugger_agent_impl.h
index ea1b0b3..c03d3cc 100644
--- a/webkit/glue/devtools/debugger_agent_impl.h
+++ b/webkit/glue/devtools/debugger_agent_impl.h
@@ -50,9 +50,10 @@ class DebuggerAgentImpl : public DebuggerAgent {
// Executes function with the given name in the utility context. Passes node
// and json args as parameters. Note that the function called must be
- // implemented in the inject.js file.
+ // implemented in the inject_dispatch.js file.
WebCore::String ExecuteUtilityFunction(
v8::Handle<v8::Context> context,
+ const char* object,
const WebCore::String& function_name,
const WebCore::String& json_args,
WebCore::String* exception);
diff --git a/webkit/glue/devtools/js/devtools.js b/webkit/glue/devtools/js/devtools.js
index 5086f80..8e1cd80 100644
--- a/webkit/glue/devtools/js/devtools.js
+++ b/webkit/glue/devtools/js/devtools.js
@@ -35,7 +35,7 @@ devtools$$dispatch = function(remoteName, methodName, param1, param2, param3) {
devtools.ToolsAgent = function() {
- RemoteToolsAgent.DidExecuteUtilityFunction =
+ RemoteToolsAgent.DidDispatchOn =
devtools.Callback.processCallback;
RemoteToolsAgent.FrameNavigate =
goog.bind(this.frameNavigate_, this);
diff --git a/webkit/glue/devtools/js/devtools_host_stub.js b/webkit/glue/devtools/js/devtools_host_stub.js
index 2f3da60..9a3c634 100644
--- a/webkit/glue/devtools/js/devtools_host_stub.js
+++ b/webkit/glue/devtools/js/devtools_host_stub.js
@@ -97,76 +97,11 @@ RemoteToolsAgentStub = function() {
};
-RemoteToolsAgentStub.prototype.HideDOMNodeHighlight = function() {
+RemoteToolsAgentStub.prototype.DispatchOnInjectedScript = function() {
};
-RemoteToolsAgentStub.prototype.HighlightDOMNode = function() {
-};
-
-
-RemoteToolsAgentStub.prototype.evaluate = function(expr) {
- window.eval(expr);
-};
-
-RemoteToolsAgentStub.prototype.EvaluateJavaScript = function(callId, script) {
- setTimeout(function() {
- var result = eval(script);
- RemoteToolsAgent.DidEvaluateJavaScript(callId, result);
- }, 0);
-};
-
-
-RemoteToolsAgentStub.prototype.ExecuteUtilityFunction = function(callId,
- functionName, args) {
- setTimeout(function() {
- var result = [];
- if (functionName == 'getProperties') {
- result = [
- 'undefined', 'undefined_key', undefined,
- 'string', 'string_key', 'value',
- 'function', 'func', undefined,
- 'array', 'array_key', [10],
- 'object', 'object_key', undefined,
- 'boolean', 'boolean_key', true,
- 'number', 'num_key', 911,
- 'date', 'date_key', new Date() ];
- } else if (functionName == 'getPrototypes') {
- result = ['Proto1', 'Proto2', 'Proto3'];
- } else if (functionName == 'getStyles') {
- result = {
- 'computedStyle' : [0, '0px', '0px', null, null, null, ['display', false, false, '', 'none']],
- 'inlineStyle' : [1, '0px', '0px', null, null, null, ['display', false, false, '', 'none']],
- 'styleAttributes' : {
- attr: [2, '0px', '0px', null, null, null, ['display', false, false, '', 'none']]
- },
- 'matchedCSSRules' : [
- { 'selector' : 'S',
- 'style' : [3, '0px', '0px', null, null, null, ['display', false, false, '', 'none']],
- 'parentStyleSheet' : { 'href' : 'http://localhost',
- 'ownerNodeName' : 'DIV' }
- }
- ]
- };
- } else if (functionName == 'toggleNodeStyle' ||
- functionName == 'applyStyleText' ||
- functionName == 'setStyleProperty') {
- alert(functionName + '(' + args + ')');
- } else if (functionName == 'evaluate') {
- try {
- result = [ window.eval(JSON.parse(args)[0]), false ];
- } catch (e) {
- result = [ e.toString(), true ];
- }
- } else if (functionName == 'InspectorController' ||
- functionName == 'InjectedScript') {
- // do nothing;
- } else {
- alert('Unexpected utility function:' + functionName);
- }
- RemoteToolsAgent.DidExecuteUtilityFunction(callId,
- JSON.stringify(result), '');
- }, 0);
+RemoteToolsAgentStub.prototype.DispatchOnInspectorController = function() {
};
@@ -174,17 +109,6 @@ RemoteToolsAgentStub.prototype.ExecuteVoidJavaScript = function() {
};
-RemoteToolsAgentStub.prototype.SetResourceTrackingEnabled = function(enabled, always) {
- RemoteToolsAgent.SetResourcesPanelEnabled(enabled);
- if (enabled) {
- WebInspector.resourceTrackingWasEnabled();
- } else {
- WebInspector.resourceTrackingWasDisabled();
- }
- addDummyResource();
-};
-
-
RemoteDebuggerAgentStub.ProfilerLogBuffer =
'profiler,begin,1\n' +
'profiler,resume\n' +
@@ -298,7 +222,6 @@ function addDummyResource() {
DevToolsHostStub.prototype.loaded = function() {
addDummyResource();
- uiTests.runAllTests();
};
diff --git a/webkit/glue/devtools/js/inject.js b/webkit/glue/devtools/js/inject.js
deleted file mode 100644
index 8a9b199..0000000
--- a/webkit/glue/devtools/js/inject.js
+++ /dev/null
@@ -1,50 +0,0 @@
-// 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.
-
-/**
- * @fileoverview Javascript that is being injected into the inspectable page
- * while debugging.
- */
-goog.provide('devtools.Injected');
-
-
-/**
- * Main injected object.
- * @constructor.
- */
-devtools.Injected = function() {
-};
-
-
-/**
- * Dispatches given method with given args on the host object.
- * @param {string} method Method name.
- */
-devtools.Injected.prototype.InspectorController = function(method, var_args) {
- var args = Array.prototype.slice.call(arguments, 1);
- return InspectorController[method].apply(InspectorController, args);
-};
-
-
-/**
- * Dispatches given method with given args on the InjectedScript.
- * @param {string} method Method name.
- */
-devtools.Injected.prototype.InjectedScript = function(method, var_args) {
- var args = Array.prototype.slice.call(arguments, 1);
- var result = InjectedScript[method].apply(InjectedScript, args);
- return result;
-};
-
-
-// Plugging into upstreamed support.
-InjectedScript._window = function() {
- return contentWindow;
-};
-
-
-// Plugging into upstreamed support.
-Object.className = function(obj) {
- return (obj == null) ? "null" : obj.constructor.name;
-};
diff --git a/webkit/glue/devtools/js/inject_dispatch.js b/webkit/glue/devtools/js/inject_dispatch.js
index 08f5ffb..16dd56f 100644
--- a/webkit/glue/devtools/js/inject_dispatch.js
+++ b/webkit/glue/devtools/js/inject_dispatch.js
@@ -6,47 +6,21 @@
* @fileoverview Injects 'injected' object into the inspectable page.
*/
-/**
- * Dispatches host calls into the injected function calls.
- */
-goog.require('devtools.Injected');
-
-/**
- * Injected singleton.
- */
-var devtools$$obj = new devtools.Injected();
+var InspectorControllerDispatcher = {};
/**
- * Main dispatch method, all calls from the host go through this one.
+ * Main dispatch method, all calls from the host to InspectorController go
+ * through this one.
* @param {string} functionName Function to call
* @param {string} json_args JSON-serialized call parameters.
* @return {string} JSON-serialized result of the dispatched call.
*/
-function devtools$$dispatch(functionName, json_args) {
+InspectorControllerDispatcher.dispatch = function(functionName, json_args) {
var params = JSON.parse(json_args);
- var result = devtools$$obj[functionName].apply(devtools$$obj, params);
- return JSON.stringify(result);
-}
-
-
-/**
- * Removes malicious functions from the objects so that the pure JSON.stringify
- * was used.
- */
-function sanitizeJson(obj) {
- for (var name in obj) {
- var property = obj[name];
- var type = typeof property;
- if (type === "function") {
- obj[name] = null;
- } else if (obj !== null && type === "object") {
- sanitizeJson(property);
- }
- }
- return obj;
-}
+ InspectorController[functionName].apply(InspectorController, params);
+};
/**
@@ -54,7 +28,7 @@ function sanitizeJson(obj) {
* We serialize the call and send it to the client over the IPC
* using dispatchOut bound method.
*/
-var dispatch = function(method, var_args) {
+function dispatch(method, var_args) {
// Handle all messages with non-primitieve arguments here.
var args = Array.prototype.slice.call(arguments);
@@ -67,14 +41,26 @@ var dispatch = function(method, var_args) {
return;
}
- var call = JSON.stringify(sanitizeJson(args));
+ var call = JSON.stringify(args);
DevToolsAgentHost.dispatch(call);
};
+// Plugging into upstreamed support.
+InjectedScript._window = function() {
+ return contentWindow;
+};
+
+
+// Plugging into upstreamed support.
+Object.className = function(obj) {
+ return (obj == null) ? "null" : obj.constructor.name;
+};
+
+
/**
* A no-op function that is called by debugger agent just to trigger v8
* execution.
*/
function devtools$$void() {
-} \ No newline at end of file
+}
diff --git a/webkit/glue/devtools/js/inspector_controller_impl.js b/webkit/glue/devtools/js/inspector_controller_impl.js
index 5bf19b7..f642194 100644
--- a/webkit/glue/devtools/js/inspector_controller_impl.js
+++ b/webkit/glue/devtools/js/inspector_controller_impl.js
@@ -240,14 +240,12 @@ devtools.InspectorControllerImpl.prototype.evaluateInCallFrame =
devtools.InspectorControllerImpl.prototype.dispatchOnInjectedScript = function(
callId, methodName, argsString) {
var callback = function(result, isException) {
- WebInspector.didDispatchOnInjectedScript(callId,
- isException ? result : JSON.parse(result),
- isException);
+ WebInspector.didDispatchOnInjectedScript(callId, result, isException);
};
- RemoteToolsAgent.ExecuteUtilityFunction(
+ RemoteToolsAgent.DispatchOnInjectedScript(
devtools.Callback.wrap(callback),
- 'InjectedScript',
- JSON.stringify(['dispatch', methodName, argsString]));
+ methodName,
+ argsString);
};
@@ -268,18 +266,11 @@ devtools.InspectorControllerImpl.prototype.installInspectorControllerDelegate_
*/
devtools.InspectorControllerImpl.prototype.callInspectorController_ =
function(methodName, var_arg) {
- var args = Array.prototype.slice.call(arguments);
- RemoteToolsAgent.ExecuteUtilityFunction(
+ var args = Array.prototype.slice.call(arguments, 1);
+ RemoteToolsAgent.DispatchOnInspectorController(
devtools.Callback.wrap(function(){}),
- 'InspectorController', JSON.stringify(args));
-};
-
-
-devtools.InspectorControllerImpl.parseWrap_ = function(callback) {
- return devtools.Callback.wrap(
- function(data) {
- callback.call(this, JSON.parse(data));
- });
+ methodName,
+ JSON.stringify(args));
};
diff --git a/webkit/glue/devtools/js/profiler_processor.js b/webkit/glue/devtools/js/profiler_processor.js
index 13aeee7..16b5d95 100644
--- a/webkit/glue/devtools/js/profiler_processor.js
+++ b/webkit/glue/devtools/js/profiler_processor.js
@@ -127,14 +127,6 @@ devtools.profiler.JsProfile.JS_NATIVE_FUNC_RE = /\ native\ \w+\.js:\d+$/;
*/
devtools.profiler.JsProfile.JS_NATIVE_SCRIPT_RE = /^Script:\ native/;
-/**
- * RegExp that filters out devtools functions. See inject.js and
- * inject_dispatch.js.
- * @type {RegExp}
- */
-devtools.profiler.JsProfile.JS_DEVTOOLS_FUNC_RE =
- /^\w+:\ devtools(\$\$|\.Injected)/;
-
/**
* @override
@@ -143,8 +135,7 @@ devtools.profiler.JsProfile.prototype.skipThisFunction = function(name) {
return !devtools.profiler.JsProfile.JS_FUNC_RE.test(name) ||
// To profile V8's natives comment out two lines below and '||' above.
devtools.profiler.JsProfile.JS_NATIVE_FUNC_RE.test(name) ||
- devtools.profiler.JsProfile.JS_NATIVE_SCRIPT_RE.test(name) ||
- devtools.profiler.JsProfile.JS_DEVTOOLS_FUNC_RE.test(name);
+ devtools.profiler.JsProfile.JS_NATIVE_SCRIPT_RE.test(name);
};
diff --git a/webkit/glue/devtools/tools_agent.h b/webkit/glue/devtools/tools_agent.h
index 853d7ae..39cb9c9 100644
--- a/webkit/glue/devtools/tools_agent.h
+++ b/webkit/glue/devtools/tools_agent.h
@@ -10,14 +10,18 @@
// Tools agent provides API for enabling / disabling other agents as well as
// API for auxiliary UI functions such as dom elements highlighting.
#define TOOLS_AGENT_STRUCT(METHOD0, METHOD1, METHOD2, METHOD3) \
- /* Requests that utility js function is executed with the given args. */ \
- METHOD3(ExecuteUtilityFunction, int /* call_id */, \
- String /* function_name */, String /* json_args */) \
- \
/* Request the agent to to run a no-op JavaScript function to trigger v8
execution. */ \
METHOD0(ExecuteVoidJavaScript) \
\
+ /* Dispatches given function on the InspectorController object */ \
+ METHOD3(DispatchOnInspectorController, int /* call_id */, \
+ String /* function_name */, String /* json_args */) \
+ \
+ /* Dispatches given function on the InjectedScript object */ \
+ METHOD3(DispatchOnInjectedScript, int /* call_id */, \
+ String /* function_name */, String /* json_args */) \
+ \
/* Requests that the agent sends content of the resource with given id to the
delegate. */ \
METHOD2(GetResourceContent, int /* call_id */, int /* identifier */)
@@ -28,8 +32,8 @@ DEFINE_RPC_CLASS(ToolsAgent, TOOLS_AGENT_STRUCT)
/* Updates focused node on the client. */ \
METHOD1(FrameNavigate, std::string /* url */) \
\
- /* Response to the GetNodeProperties. */ \
- METHOD3(DidExecuteUtilityFunction, int /* call_id */, String /* result */, \
+ /* Response to the DispatchOn*. */ \
+ METHOD3(DidDispatchOn, int /* call_id */, String /* result */, \
String /* exception */) \
\
/* Sends InspectorFrontend message to be dispatched on client. */ \
diff --git a/webkit/glue/webdevtoolsagent_impl.cc b/webkit/glue/webdevtoolsagent_impl.cc
index 787af9a..1e35128 100644
--- a/webkit/glue/webdevtoolsagent_impl.cc
+++ b/webkit/glue/webdevtoolsagent_impl.cc
@@ -162,15 +162,27 @@ void WebDevToolsAgentImpl::ForceRepaint() {
delegate_->ForceRepaint();
}
-void WebDevToolsAgentImpl::ExecuteUtilityFunction(
+void WebDevToolsAgentImpl::DispatchOnInspectorController(
int call_id,
const String& function_name,
const String& json_args) {
String result;
String exception;
result = debugger_agent_impl_->ExecuteUtilityFunction(utility_context_,
- function_name, json_args, &exception);
- tools_agent_delegate_stub_->DidExecuteUtilityFunction(call_id,
+ "InspectorControllerDispatcher", function_name, json_args, &exception);
+ tools_agent_delegate_stub_->DidDispatchOn(call_id,
+ result, exception);
+}
+
+void WebDevToolsAgentImpl::DispatchOnInjectedScript(
+ int call_id,
+ const String& function_name,
+ const String& json_args) {
+ String result;
+ String exception;
+ result = debugger_agent_impl_->ExecuteUtilityFunction(utility_context_,
+ "InjectedScript", function_name, json_args, &exception);
+ tools_agent_delegate_stub_->DidDispatchOn(call_id,
result, exception);
}
diff --git a/webkit/glue/webdevtoolsagent_impl.h b/webkit/glue/webdevtoolsagent_impl.h
index 6f85fd2..0a1ff97 100644
--- a/webkit/glue/webdevtoolsagent_impl.h
+++ b/webkit/glue/webdevtoolsagent_impl.h
@@ -43,7 +43,11 @@ class WebDevToolsAgentImpl
virtual ~WebDevToolsAgentImpl();
// ToolsAgent implementation.
- virtual void ExecuteUtilityFunction(
+ virtual void DispatchOnInspectorController(
+ int call_id,
+ const WebCore::String& function_name,
+ const WebCore::String& json_args);
+ virtual void DispatchOnInjectedScript(
int call_id,
const WebCore::String& function_name,
const WebCore::String& json_args);
diff --git a/webkit/glue/webkit_resources.grd b/webkit/glue/webkit_resources.grd
index f940b10b..5b5f3dc 100644
--- a/webkit/glue/webkit_resources.grd
+++ b/webkit/glue/webkit_resources.grd
@@ -20,7 +20,6 @@
<include name="IDR_TEXTAREA_RESIZER" file="resources\textarea_resize_corner.png" type="BINDATA" />
<include name="IDR_DEVTOOLS_BASE_JS" file="devtools\js\base.js" type="BINDATA" />
<include name="IDR_DEVTOOLS_INJECT_DISPATCH_JS" file="devtools\js\inject_dispatch.js" type="BINDATA" />
- <include name="IDR_DEVTOOLS_INJECT_JS" file="devtools\js\inject.js" type="BINDATA" />
<include name="IDR_DEVTOOLS_INJECT_WEBKIT_JS" file="..\..\third_party\WebKit\WebCore\inspector\front-end\InjectedScript.js" type="BINDATA" />
<include name="IDR_MEDIA_PLAY_BUTTON" file="resources\media_play.png" type="BINDATA" />
<include name="IDR_MEDIA_PLAY_BUTTON_DISABLED" file="resources\media_play_disabled.png" type="BINDATA" />
diff --git a/webkit/webkit.gyp b/webkit/webkit.gyp
index e085f5a..9c77a82 100644
--- a/webkit/webkit.gyp
+++ b/webkit/webkit.gyp
@@ -629,7 +629,6 @@
'glue/devtools/js/devtools_callback.js',
'glue/devtools/js/devtools_host_stub.js',
'glue/devtools/js/heap_profiler_panel.js',
- 'glue/devtools/js/inject.js',
'glue/devtools/js/inspector_controller.js',
'glue/devtools/js/inspector_controller_impl.js',
'glue/devtools/js/profiler_processor.js',