diff options
author | pfeldman@chromium.org <pfeldman@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2009-04-07 09:21:32 +0000 |
---|---|---|
committer | pfeldman@chromium.org <pfeldman@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2009-04-07 09:21:32 +0000 |
commit | d6ee9e14d95013491f7f997644ff1daa80f0cbd7 (patch) | |
tree | 5c513ac7ae14b5291b2efdd9da2b46396a554671 /webkit/glue | |
parent | 7844fc5edc61e4e90509f90bf0ee0cb110889ca9 (diff) | |
download | chromium_src-d6ee9e14d95013491f7f997644ff1daa80f0cbd7.zip chromium_src-d6ee9e14d95013491f7f997644ff1daa80f0cbd7.tar.gz chromium_src-d6ee9e14d95013491f7f997644ff1daa80f0cbd7.tar.bz2 |
DevTools: add basic console support.
Review URL: http://codereview.chromium.org/62050
git-svn-id: svn://svn.chromium.org/chrome/trunk/src@13240 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'webkit/glue')
-rw-r--r-- | webkit/glue/chrome_client_impl.cc | 5 | ||||
-rw-r--r-- | webkit/glue/devtools/js/devtools.js | 88 | ||||
-rw-r--r-- | webkit/glue/devtools/js/devtools_host_stub.js | 5 | ||||
-rw-r--r-- | webkit/glue/devtools/js/inspector_controller_impl.js | 8 | ||||
-rw-r--r-- | webkit/glue/devtools/tools_agent.h | 11 | ||||
-rw-r--r-- | webkit/glue/webdevtoolsagent_impl.cc | 35 | ||||
-rw-r--r-- | webkit/glue/webdevtoolsagent_impl.h | 17 |
7 files changed, 132 insertions, 37 deletions
diff --git a/webkit/glue/chrome_client_impl.cc b/webkit/glue/chrome_client_impl.cc index f190551..02e891d 100644 --- a/webkit/glue/chrome_client_impl.cc +++ b/webkit/glue/chrome_client_impl.cc @@ -33,6 +33,7 @@ MSVC_POP_WARNING(); #include "third_party/WebKit/WebKit/chromium/public/WebInputEvent.h" #include "third_party/WebKit/WebKit/chromium/public/WebKit.h" #include "webkit/glue/glue_util.h" +#include "webkit/glue/webdevtoolsagent_impl.h" #include "webkit/glue/webframe_impl.h" #include "webkit/glue/webkit_glue.h" #include "webkit/glue/weburlrequest_impl.h" @@ -286,6 +287,10 @@ void ChromeClientImpl::addMessageToConsole(const WebCore::String& message, delegate->AddMessageToConsole(webview_, wstr_message, line_no, wstr_source_id); } + WebDevToolsAgentImpl* devtools_agent = webview_->GetWebDevToolsAgentImpl(); + if (devtools_agent) { + devtools_agent->AddMessageToConsole(message, source_id, line_no); + } } bool ChromeClientImpl::canRunBeforeUnloadConfirmPanel() { diff --git a/webkit/glue/devtools/js/devtools.js b/webkit/glue/devtools/js/devtools.js index b3b6266..4454213 100644 --- a/webkit/glue/devtools/js/devtools.js +++ b/webkit/glue/devtools/js/devtools.js @@ -21,6 +21,8 @@ devtools.ToolsAgent = function() { goog.bind(this.updateFocusedNode, this); RemoteToolsAgent.FrameNavigate = goog.bind(this.frameNavigate, this); + RemoteToolsAgent.AddMessageToConsole = + goog.bind(this.addMessageToConsole, this); this.debuggerAgent_ = new devtools.DebuggerAgent(); this.domAgent_ = new devtools.DomAgent(); this.netAgent_ = new devtools.NetAgent(); @@ -130,6 +132,22 @@ devtools.ToolsAgent.prototype.frameNavigate = function(url, topLevel) { /** + * @param {string} message Message to add. + * @param {string} source Source url. + * @param {number} line Line number in source. + * @see tools_agent.h + */ +devtools.ToolsAgent.prototype.addMessageToConsole = function(message, source, + line) { + var console = WebInspector.console; + if (console) { + console.addMessage(new WebInspector.ConsoleMessage( + "", undefined, line, source, undefined, 1, message)); + } +}; + + +/** * Evaluates js expression. * @param {string} expr */ @@ -451,38 +469,38 @@ WebInspector.didGetNodePropertiesAsync_ = function(treeOutline, constructor, * representation. Original method uses Object.prototype.toString.call to * learn if scope object is a JSActivation which doesn't work in Chrome. */ -WebInspector.ScopeChainSidebarPane.prototype.update = function(callFrame) {
- this.bodyElement.removeChildren();
-
- this.sections = [];
- this.callFrame = callFrame;
-
- if (!callFrame) {
- var infoElement = document.createElement("div");
- infoElement.className = "info";
- infoElement.textContent = WebInspector.UIString("Not Paused");
- this.bodyElement.appendChild(infoElement);
- return;
- }
-
- if (!callFrame._expandedProperties) {
- callFrame._expandedProperties = {};
- }
-
- var scopeObject = callFrame.localScope;
- var title = WebInspector.UIString("Local");
- var subtitle = Object.describe(scopeObject, true);
- var emptyPlaceholder = null;
- var extraProperties = null;
-
- var section = new WebInspector.ObjectPropertiesSection(scopeObject, title,
- subtitle, emptyPlaceholder, true, extraProperties,
- WebInspector.ScopeVariableTreeElement);
- section.editInSelectedCallFrameWhenPaused = true;
- section.pane = this;
-
- section.expanded = true;
-
- this.sections.push(section);
- this.bodyElement.appendChild(section.element);
-};
+WebInspector.ScopeChainSidebarPane.prototype.update = function(callFrame) { + this.bodyElement.removeChildren(); + + this.sections = []; + this.callFrame = callFrame; + + if (!callFrame) { + var infoElement = document.createElement("div"); + infoElement.className = "info"; + infoElement.textContent = WebInspector.UIString("Not Paused"); + this.bodyElement.appendChild(infoElement); + return; + } + + if (!callFrame._expandedProperties) { + callFrame._expandedProperties = {}; + } + + var scopeObject = callFrame.localScope; + var title = WebInspector.UIString("Local"); + var subtitle = Object.describe(scopeObject, true); + var emptyPlaceholder = null; + var extraProperties = null; + + var section = new WebInspector.ObjectPropertiesSection(scopeObject, title, + subtitle, emptyPlaceholder, true, extraProperties, + WebInspector.ScopeVariableTreeElement); + section.editInSelectedCallFrameWhenPaused = true; + section.pane = this; + + section.expanded = true; + + this.sections.push(section); + this.bodyElement.appendChild(section.element); +}; diff --git a/webkit/glue/devtools/js/devtools_host_stub.js b/webkit/glue/devtools/js/devtools_host_stub.js index 6bc9690..fd398bc 100644 --- a/webkit/glue/devtools/js/devtools_host_stub.js +++ b/webkit/glue/devtools/js/devtools_host_stub.js @@ -202,6 +202,10 @@ RemoteToolsAgentStub.prototype.GetNodePrototypes = function(callId, nodeId) { }; +RemoteToolsAgentStub.prototype.ClearConsoleMessages = function() { +}; + + /** * @constructor */ @@ -232,6 +236,7 @@ DevToolsHostStub.prototype.loaded = function() { RemoteDomAgentStub.sendChildNodes_(1); RemoteDomAgentStub.sendChildNodes_(2); devtools.tools.updateFocusedNode(4); + devtools.tools.addMessageToConsole('message', 'source', 3); }; diff --git a/webkit/glue/devtools/js/inspector_controller_impl.js b/webkit/glue/devtools/js/inspector_controller_impl.js index 2e88115..e6fa74d 100644 --- a/webkit/glue/devtools/js/inspector_controller_impl.js +++ b/webkit/glue/devtools/js/inspector_controller_impl.js @@ -20,6 +20,14 @@ goog.inherits(devtools.InspectorControllerImpl, /** * {@inheritDoc}. */ +devtools.InspectorController.prototype.clearMessages = function() { + RemoteToolsAgent.ClearConsoleMessages(); +}; + + +/** + * {@inheritDoc}. + */ devtools.InspectorControllerImpl.prototype.hiddenPanels = function() { return "profiles,databases"; }; diff --git a/webkit/glue/devtools/tools_agent.h b/webkit/glue/devtools/tools_agent.h index fb9268c..d98559e 100644 --- a/webkit/glue/devtools/tools_agent.h +++ b/webkit/glue/devtools/tools_agent.h @@ -22,7 +22,10 @@ /* Requests that utility js function is executed with the given args. */ \ METHOD4(ExecuteUtilityFunction, int /* call_id */, \ String /* function_name */, int /* context_node_id */, \ - String /* json_args */) + String /* json_args */) \ + \ + /* Clears cached console messages. */ \ + METHOD0(ClearConsoleMessages) DEFINE_RPC_CLASS(ToolsAgent, TOOLS_AGENT_STRUCT) @@ -38,7 +41,11 @@ DEFINE_RPC_CLASS(ToolsAgent, TOOLS_AGENT_STRUCT) METHOD2(FrameNavigate, std::string /* url */, bool /* top_level */) \ \ /* Response to the GetNodeProperties. */ \ - METHOD2(DidExecuteUtilityFunction, int /* call_id */, String /* json */) + METHOD2(DidExecuteUtilityFunction, int /* call_id */, String /* json */) \ + \ + /* Adds message to console. */ \ + METHOD3(AddMessageToConsole, String /* message */, \ + String /* source_id */, int /* line_no */) DEFINE_RPC_CLASS(ToolsAgentDelegate, TOOLS_AGENT_DELEGATE_STRUCT) diff --git a/webkit/glue/webdevtoolsagent_impl.cc b/webkit/glue/webdevtoolsagent_impl.cc index 690858c..5a4c4b4 100644 --- a/webkit/glue/webdevtoolsagent_impl.cc +++ b/webkit/glue/webdevtoolsagent_impl.cc @@ -35,6 +35,9 @@ using WebCore::Page; using WebCore::ScriptValue; using WebCore::String; +// Maximum size of the console message cache. +static const size_t kMaxConsoleMessages = 200; + WebDevToolsAgentImpl::WebDevToolsAgentImpl( WebViewImpl* web_view_impl, WebDevToolsAgentDelegate* delegate) @@ -69,6 +72,16 @@ void WebDevToolsAgentImpl::Attach() { dom_agent_impl_->SetDocument(doc, true); net_agent_impl_->SetDocument(doc); } + + // Populate console. + for (Vector<ConsoleMessage>::iterator it = console_log_.begin(); + it != console_log_.end(); ++it) { + tools_agent_delegate_stub_->AddMessageToConsole( + it->message, + it->source_id, + it->line_no); + } + attached_ = true; } @@ -114,6 +127,24 @@ void WebDevToolsAgentImpl::DidCommitLoadForFrame( webview->GetMainFrame() == frame); } +void WebDevToolsAgentImpl::AddMessageToConsole( + const String& message, + const String& source_id, + unsigned int line_no) { + ConsoleMessage cm(message, source_id, line_no); + console_log_.append(cm); + if (console_log_.size() >= kMaxConsoleMessages) { + // Batch shifts to save ticks. + console_log_.remove(0, kMaxConsoleMessages / 5); + } + if (attached_) { + tools_agent_delegate_stub_->AddMessageToConsole( + message, + source_id, + line_no); + } +} + void WebDevToolsAgentImpl::HighlightDOMNode(int node_id) { if (!attached_) { return; @@ -159,6 +190,10 @@ void WebDevToolsAgentImpl::ExecuteUtilityFunction( result); } +void WebDevToolsAgentImpl::ClearConsoleMessages() { + console_log_.clear(); +} + void WebDevToolsAgentImpl::DispatchMessageFromClient( const std::string& raw_msg) { OwnPtr<ListValue> message( diff --git a/webkit/glue/webdevtoolsagent_impl.h b/webkit/glue/webdevtoolsagent_impl.h index cb8fb86..216bf9c 100644 --- a/webkit/glue/webdevtoolsagent_impl.h +++ b/webkit/glue/webdevtoolsagent_impl.h @@ -8,6 +8,7 @@ #include <string> #include <wtf/OwnPtr.h> +#include <wtf/Vector.h> #include "webkit/glue/devtools/devtools_rpc.h" #include "webkit/glue/devtools/dom_agent.h" @@ -49,6 +50,7 @@ class WebDevToolsAgentImpl const WebCore::String& function_name, int node_id, const WebCore::String& json_args); + virtual void ClearConsoleMessages(); // WebDevToolsAgent implementation. virtual void Attach(); @@ -64,10 +66,24 @@ class WebDevToolsAgentImpl void DidCommitLoadForFrame(WebViewImpl* webview, WebFrame* frame, bool is_new_navigation); + void AddMessageToConsole( + const WebCore::String& message, + const WebCore::String& source_id, + unsigned int line_no); NetAgentImpl* net_agent_impl() { return net_agent_impl_.get(); } private: + struct ConsoleMessage { + ConsoleMessage(const String& m, const String& sid, unsigned li) + : message(m), + source_id(sid), + line_no(li) { + } + WebCore::String message; + WebCore::String source_id; + unsigned int line_no; + }; WebDevToolsAgentDelegate* delegate_; WebViewImpl* web_view_impl_; WebCore::Document* document_; @@ -78,6 +94,7 @@ class WebDevToolsAgentImpl OwnPtr<DebuggerAgentImpl> debugger_agent_impl_; OwnPtr<DomAgentImpl> dom_agent_impl_; OwnPtr<NetAgentImpl> net_agent_impl_; + Vector<ConsoleMessage> console_log_; bool attached_; DISALLOW_COPY_AND_ASSIGN(WebDevToolsAgentImpl); }; |