diff options
author | yurys@chromium.org <yurys@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2010-01-19 10:12:11 +0000 |
---|---|---|
committer | yurys@chromium.org <yurys@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2010-01-19 10:12:11 +0000 |
commit | d58e172826d246e93777ba10087f73b63f206724 (patch) | |
tree | 9bcbafe4d100c4ae5cd0a57e871ae97aee8447eb /webkit | |
parent | 4ab8b525667ffa2fbf64c12a2993e9e98996b9ec (diff) | |
download | chromium_src-d58e172826d246e93777ba10087f73b63f206724.zip chromium_src-d58e172826d246e93777ba10087f73b63f206724.tar.gz chromium_src-d58e172826d246e93777ba10087f73b63f206724.tar.bz2 |
DevTools: prepare to injectiong inspector script into the inspected context.
BUG=29068
Review URL: http://codereview.chromium.org/552033
git-svn-id: svn://svn.chromium.org/chrome/trunk/src@36518 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'webkit')
-rw-r--r-- | webkit/glue/devtools/js/debugger_agent.js | 6 | ||||
-rw-r--r-- | webkit/glue/devtools/js/devtools.js | 35 | ||||
-rw-r--r-- | webkit/glue/devtools/js/inject_dispatch.js | 16 | ||||
-rw-r--r-- | webkit/glue/devtools/js/inspector_controller_impl.js | 36 | ||||
-rw-r--r-- | webkit/glue/devtools/js/tests.js | 15 | ||||
-rw-r--r-- | webkit/glue/devtools/tools_agent.h | 5 | ||||
-rw-r--r-- | webkit/glue/webdevtoolsagent_impl.cc | 44 | ||||
-rw-r--r-- | webkit/glue/webdevtoolsagent_impl.h | 1 | ||||
-rw-r--r-- | webkit/glue/webdevtoolsfrontend_impl.cc | 7 |
9 files changed, 139 insertions, 26 deletions
diff --git a/webkit/glue/devtools/js/debugger_agent.js b/webkit/glue/devtools/js/debugger_agent.js index 407bc8b..e836e12 100644 --- a/webkit/glue/devtools/js/debugger_agent.js +++ b/webkit/glue/devtools/js/debugger_agent.js @@ -1049,7 +1049,8 @@ devtools.DebuggerAgent.prototype.formatCallFrame_ = function(stackFrame) { for (var i = 0; i < stackFrame.scopes.length; i++) { var scope = stackFrame.scopes[i]; scope.frameNumber = stackFrame.index; - var scopeObjectProxy = new WebInspector.ObjectProxy(scope, [], 0, '', true); + var scopeObjectProxy = new WebInspector.ObjectProxy(0, scope, [], 0, '', + true); scopeObjectProxy.isScope = true; switch(scope.type) { case ScopeType.Global: @@ -1150,7 +1151,8 @@ devtools.DebuggerAgent.formatObjectProxy_ = function(v) { } else { description = '<unresolved ref: ' + v.ref + ', type: ' + v.type + '>'; } - var proxy = new WebInspector.ObjectProxy(v, [], 0, description, hasChildren); + var proxy = new WebInspector.ObjectProxy(0, v, [], 0, description, + hasChildren); proxy.type = v.type; proxy.isV8Ref = true; return proxy; diff --git a/webkit/glue/devtools/js/devtools.js b/webkit/glue/devtools/js/devtools.js index 5e57609..b562a2f4 100644 --- a/webkit/glue/devtools/js/devtools.js +++ b/webkit/glue/devtools/js/devtools.js @@ -400,8 +400,15 @@ WebInspector.UIString = function(string) { (function () { -var orig = InjectedScriptAccess.getProperties; -InjectedScriptAccess.getProperties = function( +// TODO(yurys): get rid of the if once WebKit change is rolled. +var accessor; +if (InjectedScriptAccess.getDefault) + accessor = InjectedScriptAccess.prototype; +else + accessor = InjectedScriptAccess; + +var orig = accessor.getProperties; +accessor.getProperties = function( objectProxy, ignoreHasOwnProperty, abbreviate, callback) { if (objectProxy.isScope) { devtools.tools.getDebuggerAgent().resolveScope(objectProxy.objectId, @@ -416,8 +423,16 @@ InjectedScriptAccess.getProperties = function( })(); -InjectedScriptAccess.evaluateInCallFrame = function(callFrameId, code, - objectGroup, callback) +(function() { +// TODO(yurys): get rid of the if once WebKit change is rolled. +var accessor; +if (InjectedScriptAccess.getDefault) + accessor = InjectedScriptAccess.prototype; +else + accessor = InjectedScriptAccess; + +accessor.evaluateInCallFrame = function(callFrameId, code, + objectGroup, callback) { //TODO(pfeldman): remove once 49084 is rolled. if (!callback) { @@ -426,6 +441,7 @@ InjectedScriptAccess.evaluateInCallFrame = function(callFrameId, code, devtools.tools.getDebuggerAgent().evaluateInCallFrame( callFrameId, code, callback); }; +})(); WebInspector.resourceTrackingWasEnabled = function() @@ -454,8 +470,15 @@ WebInspector.ConsoleMessage.prototype.setMessageBody = function(args) { (function() { -var orig = InjectedScriptAccess.getCompletions; -InjectedScriptAccess.getCompletions = function(expressionString, +// TODO(yurys): get rid of the if once WebKit change is rolled. +var accessor; +if (InjectedScriptAccess.getDefault) + accessor = InjectedScriptAccess.prototype; +else + accessor = InjectedScriptAccess; + +var orig = accessor.getCompletions; +accessor.getCompletions = function(expressionString, includeInspectorCommandLineAPI, callFrameId, reportCompletions) { if (goog.isDef(callFrameId)) { devtools.tools.getDebuggerAgent().resolveCompletionsOnFrame( diff --git a/webkit/glue/devtools/js/inject_dispatch.js b/webkit/glue/devtools/js/inject_dispatch.js index 151ddb2..f327c5a 100644 --- a/webkit/glue/devtools/js/inject_dispatch.js +++ b/webkit/glue/devtools/js/inject_dispatch.js @@ -83,6 +83,9 @@ function dispatch(method, var_args) { }; +// TODO(yurys): remove once injected script lives in the inspected context +if (this.InjectedScript) { + // Plugging into upstreamed support. InjectedScript._window = function() { return contentWindow; @@ -95,12 +98,6 @@ InjectedScript.evaluateOnSelf = function(funcBody) { }; -// Plugging into upstreamed support. -Object.className = function(obj) { - return (obj == null) ? "null" : obj.constructor.name; -}; - - // TODO(pfeldman): Remove once Object.getOwnPropertyNames is implemented. InjectedScript._getPropertyNames = function(object, resultSet) { @@ -108,6 +105,13 @@ InjectedScript._getPropertyNames = function(object, resultSet) resultSet[name] = true; } +} + +// 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 diff --git a/webkit/glue/devtools/js/inspector_controller_impl.js b/webkit/glue/devtools/js/inspector_controller_impl.js index 464477e..2e41017 100644 --- a/webkit/glue/devtools/js/inspector_controller_impl.js +++ b/webkit/glue/devtools/js/inspector_controller_impl.js @@ -33,6 +33,7 @@ devtools.InspectorBackendImpl = function() { this.installInspectorControllerDelegate_('saveFrontendSettings'); this.installInspectorControllerDelegate_('setAttribute'); this.installInspectorControllerDelegate_('setDOMStorageItem'); + this.installInspectorControllerDelegate_('setInjectedScriptSource'); this.installInspectorControllerDelegate_('setTextNodeValue'); this.installInspectorControllerDelegate_('startTimelineProfiler'); this.installInspectorControllerDelegate_('stopTimelineProfiler'); @@ -190,12 +191,43 @@ devtools.InspectorBackendImpl.prototype.takeHeapSnapshot = function() { }; +// TODO(yurys): remove the if once WebKit change is rolled. +if (InjectedScriptAccess.getDefault) { + /** * @override */ -devtools.InspectorBackendImpl.prototype.dispatchOnInjectedScript = - RemoteToolsAgent.DispatchOnInjectedScript.bind(RemoteToolsAgent); +devtools.InspectorBackendImpl.prototype.dispatchOnInjectedScript = function( + callId, injectedScriptId, methodName, argsString, async) { + // Encode injectedScriptId into callId + if (typeof injectedScriptId != 'number') { + injectedScriptId = 0; + } + RemoteToolsAgent.DispatchOnInjectedScript( + callId, + injectedScriptId, + methodName, + argsString, + async); +}; + +} else { + +/** + * @override + */ +devtools.InspectorBackendImpl.prototype.dispatchOnInjectedScript = function( + callId, methodName, argsString, async) { + var injectedScriptId = 0; + RemoteToolsAgent.DispatchOnInjectedScript( + callId, + injectedScriptId, + methodName, + argsString, + async); +}; +} /** * Installs delegating handler into the inspector controller. diff --git a/webkit/glue/devtools/js/tests.js b/webkit/glue/devtools/js/tests.js index 3186b1b..f3b5caf 100644 --- a/webkit/glue/devtools/js/tests.js +++ b/webkit/glue/devtools/js/tests.js @@ -1593,10 +1593,17 @@ TestSuite.prototype._findChildProperty = function( * @param {Function} code A code snippet to be executed. */ TestSuite.prototype._hookGetPropertiesCallback = function(hook, code) { - var orig = InjectedScriptAccess.getProperties; - InjectedScriptAccess.getProperties = function(objectProxy, + // TODO(yurys): get rid of the if once WebKit change is rolled. + var accessor; + if (InjectedScriptAccess.getDefault) + accessor = InjectedScriptAccess.prototype; + else + accessor = InjectedScriptAccess; + + var orig = accessor.getProperties; + accessor.getProperties = function(objectProxy, ignoreHasOwnProperty, abbreviate, callback) { - orig.call(InjectedScriptAccess, objectProxy, ignoreHasOwnProperty, abbreviate, + orig.call(this, objectProxy, ignoreHasOwnProperty, abbreviate, function() { callback.apply(this, arguments); hook(); @@ -1605,7 +1612,7 @@ TestSuite.prototype._hookGetPropertiesCallback = function(hook, code) { try { code(); } finally { - InjectedScriptAccess.getProperties = orig; + accessor.getProperties = orig; } }; diff --git a/webkit/glue/devtools/tools_agent.h b/webkit/glue/devtools/tools_agent.h index 02c6f5b..3f9e4ed 100644 --- a/webkit/glue/devtools/tools_agent.h +++ b/webkit/glue/devtools/tools_agent.h @@ -19,8 +19,9 @@ String /* function_name */, String /* json_args */) \ \ /* Dispatches given function on the InjectedScript object */ \ - METHOD4(DispatchOnInjectedScript, int /* call_id */, \ - String /* function_name */, String /* json_args */, bool /* async */) \ + METHOD5(DispatchOnInjectedScript, int /* call_id */, \ + int /* injected_script_id */, String /* function_name */, \ + String /* json_args */, bool /* async */) \ \ /* Requests that the agent sends content of the resource with given id to the delegate. */ \ diff --git a/webkit/glue/webdevtoolsagent_impl.cc b/webkit/glue/webdevtoolsagent_impl.cc index e3a647e..4cc154e1 100644 --- a/webkit/glue/webdevtoolsagent_impl.cc +++ b/webkit/glue/webdevtoolsagent_impl.cc @@ -175,9 +175,6 @@ void WebDevToolsAgentImpl::attach() { this)); ResetInspectorFrontendProxy(); UnhideResourcesPanelIfNecessary(); - // Allow controller to send messages to the frontend. - InspectorController* ic = web_view_impl_->page()->inspectorController(); - ic->setWindowVisible(true, false); attached_ = true; } @@ -244,6 +241,7 @@ void WebDevToolsAgentImpl::DispatchOnInspectorController( void WebDevToolsAgentImpl::DispatchOnInjectedScript( int call_id, + int, const String& function_name, const String& json_args, bool async) { @@ -286,6 +284,18 @@ void WebDevToolsAgentImpl::dispatchMessageFromFrontend( return; } + if (webkit_glue::WebStringToStdString(data.className) == + "WebDevToolsAgentImpl" && + webkit_glue::WebStringToStdString(data.methodName) == + "didLoadFrontend") { + // Allow controller to send messages to the frontend. We need to wait until + // front-end is loaded because it pushes injected script source + // to the backend and the injected script is used for console message + // serialization. + GetInspectorController()->setWindowVisible(true, false); + return; + } + if (debugger_agent_impl_.get() && DebuggerAgentDispatch::Dispatch(debugger_agent_impl_.get(), data)) { return; @@ -422,8 +432,34 @@ void WebDevToolsAgentImpl::ResetInspectorFrontendProxy() { inspector_frontend_script_state_.set(new ScriptState( web_view_impl_->page()->mainFrame(), utility_context_)); - v8::Handle<v8::Object> injected_script = v8::Local<v8::Object>::Cast( + v8::Local<v8::Object> injected_script = v8::Local<v8::Object>::Cast( utility_context_->Global()->Get(v8::String::New("InjectedScript"))); + // TODO(yurys): get rid of the 'if' once WebKit is rolled. + if (injected_script->IsUndefined()) { + v8::Local<v8::Object> global = utility_context_->Global(); + v8::Handle<v8::Function> injected_script_constructor = + v8::Local<v8::Function>::Cast(global->Get(v8::String::New( + "injectedScriptConstructor"))); + v8::Local<v8::Value> injected_script_host = + global->Get(v8::String::New("InjectedScriptHost")); + ASSERT(!injected_script_host->IsUndefined()); + v8::Local<v8::Value> inspected_window = + global->Get(v8::String::New("contentWindow")); + ASSERT(!inspected_window->IsUndefined()); + v8::Local<v8::Number> id = v8::Number::New(0); + + v8::Handle<v8::Value> args[] = { + injected_script_host, + inspected_window, + id + }; + v8::Local<v8::Value> injected_script_value = + injected_script_constructor->Call(global, 3, args); + injected_script = v8::Local<v8::Object>::Cast(injected_script_value); + utility_context_->Global()->Set(v8::String::New("InjectedScript"), + injected_script); + } + ScriptState* state = inspector_frontend_script_state_.get(); InspectorController* ic = web_view_impl_->page()->inspectorController(); ic->setFrontendProxyObject( diff --git a/webkit/glue/webdevtoolsagent_impl.h b/webkit/glue/webdevtoolsagent_impl.h index 5506962..b89913f 100644 --- a/webkit/glue/webdevtoolsagent_impl.h +++ b/webkit/glue/webdevtoolsagent_impl.h @@ -54,6 +54,7 @@ class WebDevToolsAgentImpl : public WebKit::WebDevToolsAgentPrivate, const WebCore::String& json_args); virtual void DispatchOnInjectedScript( int call_id, + int injected_script_id, const WebCore::String& function_name, const WebCore::String& json_args, bool async); diff --git a/webkit/glue/webdevtoolsfrontend_impl.cc b/webkit/glue/webdevtoolsfrontend_impl.cc index cce10b53..51e97bb 100644 --- a/webkit/glue/webdevtoolsfrontend_impl.cc +++ b/webkit/glue/webdevtoolsfrontend_impl.cc @@ -385,6 +385,13 @@ v8::Handle<v8::Value> WebDevToolsFrontendImpl::JsLoaded( frontend->ExecuteScript(*it); } frontend->pending_incoming_messages_.clear(); + + // Notify the agent that front-end is loaded. + WebKit::WebDevToolsMessageData data; + data.className = "WebDevToolsAgentImpl"; + data.methodName = "didLoadFrontend"; + frontend->SendRpcMessage(data); + return v8::Undefined(); } |