diff options
-rw-r--r-- | chrome/renderer/devtools_agent.cc | 21 | ||||
-rw-r--r-- | chrome/renderer/devtools_agent.h | 2 | ||||
-rw-r--r-- | webkit/glue/devtools/js/devtools.js | 100 | ||||
-rw-r--r-- | webkit/glue/devtools/js/devtools_host_stub.js | 11 | ||||
-rw-r--r-- | webkit/glue/devtools/js/dom_agent.js | 53 | ||||
-rw-r--r-- | webkit/glue/devtools/js/inspector_controller_impl.js | 11 | ||||
-rw-r--r-- | webkit/glue/devtools/tools_agent.h | 11 | ||||
-rw-r--r-- | webkit/glue/webdevtoolsagent_impl.cc | 65 | ||||
-rw-r--r-- | webkit/glue/webdevtoolsagent_impl.h | 9 | ||||
-rw-r--r-- | webkit/glue/webframeloaderclient_impl.cc | 5 |
10 files changed, 212 insertions, 76 deletions
diff --git a/chrome/renderer/devtools_agent.cc b/chrome/renderer/devtools_agent.cc index 4d52fca1..1a60ed5 100644 --- a/chrome/renderer/devtools_agent.cc +++ b/chrome/renderer/devtools_agent.cc @@ -177,11 +177,26 @@ void DevToolsAgent::OnRpcMessage(const std::string& raw_msg) { } void DevToolsAgent::OnInspectElement(int x, int y) { - WebDevToolsAgent* web_agent = view_->webview()->GetWebDevToolsAgent(); - web_agent->InspectElement(x, y); + view_loop_->PostTask(FROM_HERE, NewRunnableMethod( + this, &DevToolsAgent::InspectElement, x, y)); } void DevToolsAgent::DispatchRpcMessage(const std::string& raw_msg) { - WebDevToolsAgent* web_agent = view_->webview()->GetWebDevToolsAgent(); + if (!view_) + return; + WebView* web_view = view_->webview(); + if (!web_view) + return; + WebDevToolsAgent* web_agent = web_view->GetWebDevToolsAgent(); web_agent->DispatchMessageFromClient(raw_msg); } + +void DevToolsAgent::InspectElement(int x, int y) { + if (!view_) + return; + WebView* web_view = view_->webview(); + if (!web_view) + return; + WebDevToolsAgent* web_agent = web_view->GetWebDevToolsAgent(); + web_agent->InspectElement(x, y); +} diff --git a/chrome/renderer/devtools_agent.h b/chrome/renderer/devtools_agent.h index a0c7bfa..15669df 100644 --- a/chrome/renderer/devtools_agent.h +++ b/chrome/renderer/devtools_agent.h @@ -56,6 +56,8 @@ class DevToolsAgent : public IPC::ChannelProxy::MessageFilter, void DispatchRpcMessage(const std::string& raw_msg); + void InspectElement(int x, int y); + // Evaluate javascript URL in the renderer void EvaluateScript(const std::wstring& script); diff --git a/webkit/glue/devtools/js/devtools.js b/webkit/glue/devtools/js/devtools.js index 3c3b41a..7456bd9 100644 --- a/webkit/glue/devtools/js/devtools.js +++ b/webkit/glue/devtools/js/devtools.js @@ -15,63 +15,114 @@ goog.require('devtools.NetAgent'); devtools.ToolsAgent = function() { RemoteToolsAgent.UpdateFocusedNode = goog.bind(this.updateFocusedNode, this); + RemoteToolsAgent.FrameNavigate = + goog.bind(this.frameNavigate, this); + this.domAgent_ = new devtools.DomAgent(); + this.netAgent_ = new devtools.NetAgent(); + this.reset(); }; -// ToolsAgent implementation. -devtools.ToolsAgent.prototype.updateFocusedNode = function(node_id) { - var node = domAgent.getNodeForId(node_id); +/** + * Rests tools agent to its initial state. + */ +devtools.ToolsAgent.prototype.reset = function() { + this.setEnabled(true); + this.domAgent_.reset(); + this.domAgent_.getDocumentElementAsync(); +}; + + +/** + * DomAgent accessor. + * @return {devtools.DomAgent} Dom agent instance. + */ +devtools.ToolsAgent.prototype.getDomAgent = function() { + return this.domAgent_; +}; + + +/** + * NetAgent accessor. + * @return {devtools.NetAgent} Net agent instance. + */ +devtools.ToolsAgent.prototype.getNetAgent = function() { + return this.netAgent_; +}; + + +/** + * @see tools_agent.h + */ +devtools.ToolsAgent.prototype.updateFocusedNode = function(nodeId) { + var node = this.domAgent_.getNodeForId(nodeId); WebInspector.updateFocusedNode(node); }; -devtools.ToolsAgent.prototype.setDomAgentEnabled = function(enabled) { - RemoteToolsAgent.SetDomAgentEnabled(enabled); +/** + * @see tools_agent.h + */ +devtools.ToolsAgent.prototype.frameNavigate = function(url, topLevel) { + this.reset(); + WebInspector.reset(); }; -devtools.ToolsAgent.prototype.setNetAgentEnabled = function(enabled) { - RemoteToolsAgent.SetNetAgentEnabled(enabled); +/** + * @see tools_agent.h + */ +devtools.ToolsAgent.prototype.setEnabled = function(enabled) { + RemoteToolsAgent.SetEnabled(enabled); +}; + + + +/** + * Evaluates js expression. + * @param {string} expr + */ +devtools.ToolsAgent.prototype.evaluate = function(expr) { + RemoteToolsAgent.evaluate(expr); }; // Frontend global objects. -var domAgent; -var netAgent; -var toolsAgent; +var devtools.tools; var context = {}; // Used by WebCore's inspector routines. -// Overrides for existing WebInspector methods. +/////////////////////////////////////////////////////////////////////////////// +// Here and below are overrides to existing WebInspector methods only. // TODO(pfeldman): Patch WebCore and upstream changes. var oldLoaded = WebInspector.loaded; WebInspector.loaded = function() { - domAgent = new devtools.DomAgent(); - netAgent = new devtools.NetAgent(); - toolsAgent = new devtools.ToolsAgent(); + devtools.tools = new devtools.ToolsAgent(); Preferences.ignoreWhitespace = false; - toolsAgent.setDomAgentEnabled(true); - toolsAgent.setNetAgentEnabled(true); oldLoaded.call(this); - domAgent.getDocumentElementAsync(); + + DevToolsHost.loaded(); }; var webkitUpdateChildren = WebInspector.ElementsTreeElement.prototype.updateChildren; + WebInspector.ElementsTreeElement.prototype.updateChildren = function() { var self = this; - domAgent.getChildNodesAsync(this.representedObject.id, function() { - webkitUpdateChildren.call(self); - }); + devtools.tools.getDomAgent().getChildNodesAsync(this.representedObject.id, + function() { + webkitUpdateChildren.call(self); + }); }; + WebInspector.ElementsPanel.prototype.performSearch = function(query) { this.searchCanceled(); var self = this; - domAgent.performSearch(query, function(node) { + devtools.tools.getDomAgent().performSearch(query, function(node) { var treeElement = self.treeOutline.findTreeElement(node); if (treeElement) treeElement.highlighted = true; @@ -81,7 +132,7 @@ WebInspector.ElementsPanel.prototype.performSearch = function(query) { WebInspector.ElementsPanel.prototype.searchCanceled = function() { var self = this; - domAgent.searchCanceled(function(node) { + devtools.tools.getDomAgent().searchCanceled(function(node) { var treeElement = self.treeOutline.findTreeElement(node); if (treeElement) treeElement.highlighted = false; @@ -95,3 +146,8 @@ WebInspector.ElementsPanel.prototype.jumpToNextSearchResult = function() { WebInspector.ElementsPanel.prototype.jumpToPreviousSearchResult = function() { }; + + +WebInspector.Console.prototype._evalInInspectedWindow = function(expr) { + return devtools.tools.evaluate(expr); +}; diff --git a/webkit/glue/devtools/js/devtools_host_stub.js b/webkit/glue/devtools/js/devtools_host_stub.js index 8eebe54..a0a696b 100644 --- a/webkit/glue/devtools/js/devtools_host_stub.js +++ b/webkit/glue/devtools/js/devtools_host_stub.js @@ -95,6 +95,10 @@ RemoteDomAgentStub.prototype.PerformSearch = function(callId, query) { }; +RemoteDomAgentStub.prototype.DiscardBindings = function() { +}; + + /** * @constructor */ @@ -110,11 +114,12 @@ RemoteToolsAgentStub.prototype.HighlightDOMNode = function() { }; -RemoteToolsAgentStub.prototype.SetDomAgentEnabled = function() { +RemoteToolsAgentStub.prototype.SetEnabled = function() { }; -RemoteToolsAgentStub.prototype.SetNetAgentEnabled = function() { +RemoteToolsAgentStub.prototype.evaluate = function(expr) { + window.eval(expr); }; @@ -136,7 +141,7 @@ DevToolsHostStub.prototype.loaded = function() { RemoteDomAgentStub.sendDocumentElement_(); RemoteDomAgentStub.sendChildNodes_(1); RemoteDomAgentStub.sendChildNodes_(2); - toolsAgent.updateFocusedNode(4); + devtools.tools.updateFocusedNode(4); }; diff --git a/webkit/glue/devtools/js/dom_agent.js b/webkit/glue/devtools/js/dom_agent.js index 0eb642a..0590e6b 100644 --- a/webkit/glue/devtools/js/dom_agent.js +++ b/webkit/glue/devtools/js/dom_agent.js @@ -252,8 +252,6 @@ devtools.DomDocument.prototype.fireDomEvent_ = function(name, event) { * @constructor */ devtools.DomAgent = function() { - this.document = new devtools.DomDocument(); - this.idToDomNode_ = { 0 : this.document }; RemoteDomAgent.DidGetChildNodes = devtools.Callback.processCallback; RemoteDomAgent.DidPerformSearch = @@ -270,18 +268,55 @@ devtools.DomAgent = function() { goog.bind(this.childNodeInserted, this); RemoteDomAgent.ChildNodeRemoved = goog.bind(this.childNodeRemoved, this); + + /** + * Top-level (and the only) document. + * @type {devtools.DomDocument} + * @private + */ + this.document_ = null; + + /** + * Id to node mapping. + * @type {Object} + * @private + */ + this.idToDomNode_ = null; + /** * @type {Array.<number>} Node ids for search results. + * @private */ + this.searchResults_ = null; + + this.reset(); +}; + + +/** + * Rests dom agent to its initial state. + */ +devtools.DomAgent.prototype.reset = function() { + RemoteDomAgent.DiscardBindings(); + this.document_ = new devtools.DomDocument(); + this.idToDomNode_ = { 0 : this.document_ }; this.searchResults_ = []; }; /** + * @return {devtools.DomDocument} Top level (and the only) document. + */ +devtools.DomAgent.prototype.getDocument = function() { + return this.document_; +}; + + +/** * Requests that the document element is sent from the agent. */ devtools.DomAgent.prototype.getDocumentElementAsync = function() { - if (this.document.documentElement) { + if (this.document_.documentElement) { return; } RemoteDomAgent.GetDocumentElement(); @@ -337,13 +372,13 @@ devtools.DomAgent.prototype.getNodeForId = function(nodeId) { * {@inheritDoc}. */ devtools.DomAgent.prototype.setDocumentElement = function(payload) { - if (this.document.documentElement) { + if (this.document_.documentElement) { return; } this.setChildNodes(0, [payload]); - this.document.documentElement = this.document.firstChild; - this.document.documentElement.ownerDocument = this.document; - this.document.fireDomEvent_("DOMContentLoaded"); + this.document_.documentElement = this.document_.firstChild; + this.document_.documentElement.ownerDocument = this.document_; + this.document_.fireDomEvent_("DOMContentLoaded"); }; @@ -395,7 +430,7 @@ devtools.DomAgent.prototype.childNodeInserted = function( var node = parent.insertChild_(prev, payload); this.idToDomNode_[node.id] = node; var event = { target : node, relatedNode : parent }; - this.document.fireDomEvent_("DOMNodeInserted", event); + this.document_.fireDomEvent_("DOMNodeInserted", event); }; @@ -409,7 +444,7 @@ devtools.DomAgent.prototype.childNodeRemoved = function( var node = this.idToDomNode_[nodeId]; parent.removeChild_(node); var event = { target : node, relatedNode : parent }; - this.document.fireDomEvent_("DOMNodeRemoved", event); + this.document_.fireDomEvent_("DOMNodeRemoved", event); delete this.idToDomNode_[nodeId]; }; diff --git a/webkit/glue/devtools/js/inspector_controller_impl.js b/webkit/glue/devtools/js/inspector_controller_impl.js index 5045a7c..9c6028c 100644 --- a/webkit/glue/devtools/js/inspector_controller_impl.js +++ b/webkit/glue/devtools/js/inspector_controller_impl.js @@ -15,7 +15,7 @@ devtools.InspectorControllerImpl = function() { this.window_ = { get document() { - return domAgent.document; + return devtools.tools.getDomAgent().getDocument(); }, get Node() { return devtools.DomNode; @@ -56,7 +56,7 @@ devtools.InspectorControllerImpl.prototype.addSourceToFrame = devtools.InspectorController.prototype.addResourceSourceToFrame = function(identifier, element) { var self = this; - netAgent.getResourceContentAsync(identifier, function(source) { + tools.getNetAgent().getResourceContentAsync(identifier, function(source) { var resource = netAgent.getResource(identifier); self.addSourceToFrame(resource.mimeType, source, element); }); @@ -89,11 +89,4 @@ devtools.InspectorControllerImpl.prototype.inspectedWindow = function() { }; -/** - * {@inheritDoc}. - */ -devtools.InspectorController.prototype.loaded = function() { - DevToolsHost.loaded(); -}; - var InspectorController = new devtools.InspectorControllerImpl(); diff --git a/webkit/glue/devtools/tools_agent.h b/webkit/glue/devtools/tools_agent.h index 0d1bde9..cc905bc 100644 --- a/webkit/glue/devtools/tools_agent.h +++ b/webkit/glue/devtools/tools_agent.h @@ -10,11 +10,8 @@ // 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) \ - /* Enables / disables Dom agent. */ \ - METHOD1(SetDomAgentEnabled, bool /* enabled */) \ - \ - /* Enables / disables Net agent */ \ - METHOD1(SetNetAgentEnabled, bool /* enabled */) \ + /* Enables / disables the agent */ \ + METHOD1(SetEnabled, bool /* enabled */) \ \ /* Highlights Dom node with given ID */ \ METHOD1(HighlightDOMNode, int /* node_id */) \ @@ -25,7 +22,11 @@ DEFINE_RPC_CLASS(ToolsAgent, TOOLS_AGENT_STRUCT) #define TOOLS_AGENT_DELEGATE_STRUCT(METHOD0, METHOD1, METHOD2, METHOD3) \ + /* Updates focused node on the client. */ \ METHOD1(UpdateFocusedNode, int /* node_id */) \ + \ + /* Updates focused node on the client. */ \ + METHOD2(FrameNavigate, std::string /* url */, bool /* top_level */) DEFINE_RPC_CLASS(ToolsAgentDelegate, TOOLS_AGENT_DELEGATE_STRUCT) diff --git a/webkit/glue/webdevtoolsagent_impl.cc b/webkit/glue/webdevtoolsagent_impl.cc index e7c3be5..1c41145 100644 --- a/webkit/glue/webdevtoolsagent_impl.cc +++ b/webkit/glue/webdevtoolsagent_impl.cc @@ -19,8 +19,10 @@ #include "webkit/glue/devtools/dom_agent_impl.h" #include "webkit/glue/devtools/net_agent_impl.h" #include "webkit/glue/glue_util.h" +#include "webkit/glue/webdatasource.h" #include "webkit/glue/webdevtoolsagent_delegate.h" #include "webkit/glue/webdevtoolsagent_impl.h" +#include "webkit/glue/weburlrequest.h" #include "webkit/glue/webview_impl.h" using WebCore::Document; @@ -34,7 +36,8 @@ WebDevToolsAgentImpl::WebDevToolsAgentImpl( WebDevToolsAgentDelegate* delegate) : delegate_(delegate), web_view_impl_(web_view_impl), - document_(NULL) { + document_(NULL), + enabled_(false) { dom_agent_delegate_stub_.reset(new DomAgentDelegateStub(this)); net_agent_delegate_stub_.reset(new NetAgentDelegateStub(this)); tools_agent_delegate_stub_.reset(new ToolsAgentDelegateStub(this)); @@ -43,23 +46,19 @@ WebDevToolsAgentImpl::WebDevToolsAgentImpl( WebDevToolsAgentImpl::~WebDevToolsAgentImpl() { } -void WebDevToolsAgentImpl::SetDomAgentEnabled(bool enabled) { - if (enabled && !dom_agent_impl_.get()) { +void WebDevToolsAgentImpl::SetEnabled(bool enabled) { + if (enabled && !enabled_) { dom_agent_impl_.reset(new DomAgentImpl(dom_agent_delegate_stub_.get())); - if (document_) - dom_agent_impl_->SetDocument(document_); - } else if (!enabled && dom_agent_impl_.get()) { - dom_agent_impl_.reset(NULL); - } -} - -void WebDevToolsAgentImpl::SetNetAgentEnabled(bool enabled) { - if (enabled && !net_agent_impl_.get()) { net_agent_impl_.reset(new NetAgentImpl(net_agent_delegate_stub_.get())); - if (document_) + if (document_) { + dom_agent_impl_->SetDocument(document_); net_agent_impl_->SetDocument(document_); - } else if (!enabled && net_agent_impl_.get()) { + } + enabled_ = true; + } else if (!enabled) { + dom_agent_impl_.reset(NULL); net_agent_impl_.reset(NULL); + enabled_ = false; } } @@ -70,14 +69,32 @@ void WebDevToolsAgentImpl::SetMainFrameDocumentReady(bool ready) { } else { document_ = NULL; } - if (dom_agent_impl_.get()) + if (enabled_) { dom_agent_impl_->SetDocument(document_); - if (net_agent_impl_.get()) net_agent_impl_->SetDocument(document_); + } +} + +void WebDevToolsAgentImpl::DidCommitLoadForFrame( + WebViewImpl* webview, + WebFrame* frame, + bool is_new_navigation) { + if (!enabled_) { + return; + } + dom_agent_impl_->DiscardBindings(); + WebDataSource* ds = frame->GetDataSource(); + const WebRequest& request = ds->GetRequest(); + GURL url = ds->HasUnreachableURL() ? + ds->GetUnreachableURL() : + request.GetURL(); + tools_agent_delegate_stub_->FrameNavigate( + url.possibly_invalid_spec(), + webview->GetMainFrame() == frame); } void WebDevToolsAgentImpl::HighlightDOMNode(int node_id) { - if (!dom_agent_impl_.get()) + if (!enabled_) return; Node* node = dom_agent_impl_->GetNodeForId(node_id); if (!node) @@ -95,13 +112,15 @@ void WebDevToolsAgentImpl::DispatchMessageFromClient( const std::string& raw_msg) { OwnPtr<ListValue> message( static_cast<ListValue*>(DevToolsRpc::ParseMessage(raw_msg))); - if (dom_agent_impl_.get() && - DomAgentDispatch::Dispatch(dom_agent_impl_.get(), *message.get())) + if (ToolsAgentDispatch::Dispatch(this, *message.get())) + return; + + if (!enabled_) + return; + if (DomAgentDispatch::Dispatch(dom_agent_impl_.get(), *message.get())) return; - if (net_agent_impl_.get() && - NetAgentDispatch::Dispatch(net_agent_impl_.get(), *message.get())) + if (NetAgentDispatch::Dispatch(net_agent_impl_.get(), *message.get())) return; - ToolsAgentDispatch::Dispatch(this, *message.get()); } void WebDevToolsAgentImpl::InspectElement(int x, int y) { @@ -109,7 +128,7 @@ void WebDevToolsAgentImpl::InspectElement(int x, int y) { if (!node) return; - SetDomAgentEnabled(true); + SetEnabled(true); int node_id = dom_agent_impl_->PushNodePathToClient(node); tools_agent_delegate_stub_->UpdateFocusedNode(node_id); } diff --git a/webkit/glue/webdevtoolsagent_impl.h b/webkit/glue/webdevtoolsagent_impl.h index c06bcd6..454f082 100644 --- a/webkit/glue/webdevtoolsagent_impl.h +++ b/webkit/glue/webdevtoolsagent_impl.h @@ -24,6 +24,8 @@ class DomAgentImpl; class NetAgentImpl; class Value; class WebDevToolsAgentDelegate; +class WebFrame; +class WebFrame; class WebViewImpl; class WebDevToolsAgentImpl @@ -36,8 +38,7 @@ class WebDevToolsAgentImpl virtual ~WebDevToolsAgentImpl(); // ToolsAgent implementation. - virtual void SetDomAgentEnabled(bool enabled); - virtual void SetNetAgentEnabled(bool enabled); + virtual void SetEnabled(bool enabled); virtual void HighlightDOMNode(int node_id); virtual void HideDOMNodeHighlight(); @@ -50,6 +51,9 @@ class WebDevToolsAgentImpl // Methods called by the glue. void SetMainFrameDocumentReady(bool ready); + void DidCommitLoadForFrame(WebViewImpl* webview, + WebFrame* frame, + bool is_new_navigation); DomAgentImpl* dom_agent_impl() { return dom_agent_impl_.get(); } NetAgentImpl* net_agent_impl() { return net_agent_impl_.get(); } @@ -64,6 +68,7 @@ class WebDevToolsAgentImpl scoped_ptr<DomAgentDelegateStub> dom_agent_delegate_stub_; scoped_ptr<NetAgentDelegateStub> net_agent_delegate_stub_; scoped_ptr<ToolsAgentDelegateStub> tools_agent_delegate_stub_; + bool enabled_; DISALLOW_COPY_AND_ASSIGN(WebDevToolsAgentImpl); }; diff --git a/webkit/glue/webframeloaderclient_impl.cc b/webkit/glue/webframeloaderclient_impl.cc index 1eda695..3ba3057 100644 --- a/webkit/glue/webframeloaderclient_impl.cc +++ b/webkit/glue/webframeloaderclient_impl.cc @@ -768,6 +768,11 @@ void WebFrameLoaderClient::dispatchDidCommitLoad() { WebViewDelegate* d = webview->delegate(); if (d) d->DidCommitLoadForFrame(webview, webframe_, is_new_navigation); + + WebDevToolsAgentImpl* tools_agent = webview->GetWebDevToolsAgentImpl(); + if (tools_agent) { + tools_agent->DidCommitLoadForFrame(webview, webframe_, is_new_navigation); + } } void WebFrameLoaderClient::dispatchDidFailProvisionalLoad( |