summaryrefslogtreecommitdiffstats
path: root/content
diff options
context:
space:
mode:
authorpfeldman@chromium.org <pfeldman@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2012-03-12 17:47:13 +0000
committerpfeldman@chromium.org <pfeldman@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2012-03-12 17:47:13 +0000
commit9e1ee54c1043f807382dc77db107fe229722dde6 (patch)
tree460456ba868846842d31ac1c3fadc6935635aa8c /content
parent1cb5feecbe49bf66b45201d57635d7415383373d (diff)
downloadchromium_src-9e1ee54c1043f807382dc77db107fe229722dde6.zip
chromium_src-9e1ee54c1043f807382dc77db107fe229722dde6.tar.gz
chromium_src-9e1ee54c1043f807382dc77db107fe229722dde6.tar.bz2
DevTools: provide a way for browser process to log into the renderer's tools console.
BUG=116769 Review URL: http://codereview.chromium.org/9663051 git-svn-id: svn://svn.chromium.org/chrome/trunk/src@126164 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'content')
-rw-r--r--content/browser/debugger/devtools_agent_host.cc10
-rw-r--r--content/browser/debugger/devtools_agent_host.h5
-rw-r--r--content/browser/debugger/devtools_manager_impl.cc6
-rw-r--r--content/browser/debugger/devtools_manager_impl.h21
-rw-r--r--content/common/devtools_messages.cc44
-rw-r--r--content/common/devtools_messages.h26
-rw-r--r--content/content_common.gypi2
-rw-r--r--content/public/browser/devtools_manager.h9
-rw-r--r--content/public/common/console_message_level.h20
-rw-r--r--content/renderer/devtools_agent.cc36
-rw-r--r--content/renderer/devtools_agent.h6
11 files changed, 165 insertions, 20 deletions
diff --git a/content/browser/debugger/devtools_agent_host.cc b/content/browser/debugger/devtools_agent_host.cc
index ea9d37a..f54b88c 100644
--- a/content/browser/debugger/devtools_agent_host.cc
+++ b/content/browser/debugger/devtools_agent_host.cc
@@ -1,4 +1,4 @@
-// Copyright (c) 2011 The Chromium Authors. All rights reserved.
+// Copyright (c) 2012 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.
@@ -36,6 +36,14 @@ void DevToolsAgentHost::InspectElement(int x, int y) {
x, y));
}
+void DevToolsAgentHost::AddMessageToConsole(ConsoleMessageLevel level,
+ const std::string& message) {
+ SendMessageToAgent(new DevToolsAgentMsg_AddMessageToConsole(
+ MSG_ROUTING_NONE,
+ level,
+ message));
+}
+
void DevToolsAgentHost::NotifyCloseListener() {
if (close_listener_) {
close_listener_->AgentHostClosing(this);
diff --git a/content/browser/debugger/devtools_agent_host.h b/content/browser/debugger/devtools_agent_host.h
index b0621d4..ff33a65 100644
--- a/content/browser/debugger/devtools_agent_host.h
+++ b/content/browser/debugger/devtools_agent_host.h
@@ -1,4 +1,4 @@
-// Copyright (c) 2011 The Chromium Authors. All rights reserved.
+// Copyright (c) 2012 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.
@@ -9,6 +9,7 @@
#include <string>
#include "content/common/content_export.h"
+#include "content/public/common/console_message_level.h"
namespace IPC {
class Message;
@@ -32,6 +33,8 @@ class CONTENT_EXPORT DevToolsAgentHost {
void Detach();
void DipatchOnInspectorBackend(const std::string& message);
void InspectElement(int x, int y);
+ void AddMessageToConsole(ConsoleMessageLevel level,
+ const std::string& message);
// TODO(yurys): get rid of this method
virtual void NotifyClientClosing() = 0;
diff --git a/content/browser/debugger/devtools_manager_impl.cc b/content/browser/debugger/devtools_manager_impl.cc
index 359ec3e..ca75c07 100644
--- a/content/browser/debugger/devtools_manager_impl.cc
+++ b/content/browser/debugger/devtools_manager_impl.cc
@@ -98,6 +98,12 @@ void DevToolsManagerImpl::InspectElement(DevToolsAgentHost* agent_host,
agent_host->InspectElement(x, y);
}
+void DevToolsManagerImpl::AddMessageToConsole(DevToolsAgentHost* agent_host,
+ ConsoleMessageLevel level,
+ const std::string& message) {
+ agent_host->AddMessageToConsole(level, message);
+}
+
void DevToolsManagerImpl::ClientHostClosing(DevToolsClientHost* client_host) {
DevToolsAgentHost* agent_host = GetDevToolsAgentHostFor(client_host);
if (!agent_host) {
diff --git a/content/browser/debugger/devtools_manager_impl.h b/content/browser/debugger/devtools_manager_impl.h
index bfcff16..3efab10 100644
--- a/content/browser/debugger/devtools_manager_impl.h
+++ b/content/browser/debugger/devtools_manager_impl.h
@@ -1,4 +1,4 @@
-// Copyright (c) 2011 The Chromium Authors. All rights reserved.
+// Copyright (c) 2012 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.
@@ -45,8 +45,6 @@ class CONTENT_EXPORT DevToolsManagerImpl
DevToolsManagerImpl();
virtual ~DevToolsManagerImpl();
- virtual bool DispatchOnInspectorBackend(DevToolsClientHost* from,
- const std::string& message) OVERRIDE;
void DispatchOnInspectorFrontend(DevToolsAgentHost* agent_host,
const std::string& message);
@@ -61,13 +59,11 @@ class CONTENT_EXPORT DevToolsManagerImpl
void OnCancelPendingNavigation(RenderViewHost* pending,
RenderViewHost* current);
- // Invoked when a tab is replaced by another tab. This is triggered by
- // TabStripModel::ReplaceTabContentsAt.
+ // DevToolsManager implementation
+ virtual bool DispatchOnInspectorBackend(DevToolsClientHost* from,
+ const std::string& message) OVERRIDE;
virtual void TabReplaced(WebContents* old_tab, WebContents* new_tab) OVERRIDE;
-
- // Closes all open developer tools windows.
virtual void CloseAllClientHosts() OVERRIDE;
-
virtual void AttachClientHost(int client_host_cookie,
DevToolsAgentHost* to_agent) OVERRIDE;
virtual DevToolsClientHost* GetDevToolsClientHostFor(
@@ -80,15 +76,12 @@ class CONTENT_EXPORT DevToolsManagerImpl
virtual void UnregisterDevToolsClientHostFor(
DevToolsAgentHost* agent_host) OVERRIDE;
virtual int DetachClientHost(DevToolsAgentHost* from_agent) OVERRIDE;
-
- // This method will remove all references from the manager to the
- // DevToolsClientHost and unregister all listeners related to the
- // DevToolsClientHost.
virtual void ClientHostClosing(DevToolsClientHost* host) OVERRIDE;
-
- // Starts inspecting element at position (x, y) in the specified page.
virtual void InspectElement(DevToolsAgentHost* agent_host,
int x, int y) OVERRIDE;
+ virtual void AddMessageToConsole(DevToolsAgentHost* agent_host,
+ ConsoleMessageLevel level,
+ const std::string& message) OVERRIDE;
private:
friend struct DefaultSingletonTraits<DevToolsManagerImpl>;
diff --git a/content/common/devtools_messages.cc b/content/common/devtools_messages.cc
new file mode 100644
index 0000000..bc61d4c
--- /dev/null
+++ b/content/common/devtools_messages.cc
@@ -0,0 +1,44 @@
+// Copyright (c) 2012 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.
+
+#include "content/common/devtools_messages.h"
+
+namespace IPC {
+
+void ParamTraits<content::ConsoleMessageLevel>::Write(Message* m,
+ const param_type& p) {
+ m->WriteInt(static_cast<int>(p));
+}
+
+bool ParamTraits<content::ConsoleMessageLevel>::Read(const Message* m,
+ PickleIterator* iter,
+ param_type* p) {
+ int type;
+ if (!m->ReadInt(iter, &type))
+ return false;
+ *p = static_cast<param_type>(type);
+ return true;
+}
+
+void ParamTraits<content::ConsoleMessageLevel>::Log(const param_type& p,
+ std::string* l) {
+ std::string level;
+ switch (p) {
+ case content::CONSOLE_MESSAGE_LEVEL_TIP:
+ level = "CONSOLE_MESSAGE_LEVEL_TIP";
+ break;
+ case content::CONSOLE_MESSAGE_LEVEL_LOG:
+ level = "CONSOLE_MESSAGE_LEVEL_LOG";
+ break;
+ case content::CONSOLE_MESSAGE_LEVEL_WARNING:
+ level = "CONSOLE_MESSAGE_LEVEL_WARNING";
+ break;
+ case content::CONSOLE_MESSAGE_LEVEL_ERROR:
+ level = "CONSOLE_MESSAGE_LEVEL_ERROR";
+ break;
+ }
+ LogParam(level, l);
+}
+
+} // namespace IPC
diff --git a/content/common/devtools_messages.h b/content/common/devtools_messages.h
index f342e5de..f718bac 100644
--- a/content/common/devtools_messages.h
+++ b/content/common/devtools_messages.h
@@ -1,4 +1,4 @@
-// Copyright (c) 2011 The Chromium Authors. All rights reserved.
+// Copyright (c) 2012 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.
@@ -43,6 +43,7 @@
#include <string>
#include "content/common/content_export.h"
+#include "content/public/common/console_message_level.h"
#include "ipc/ipc_message_macros.h"
#undef IPC_MESSAGE_EXPORT
@@ -50,6 +51,24 @@
#define IPC_MESSAGE_START DevToolsMsgStart
+// Singly-included section since need custom serialization.
+#ifndef CONTENT_COMMON_DEVTOOLS_MESSAGES_H_
+#define CONTENT_COMMON_DEVTOOLS_MESSAGES_H_
+
+namespace IPC {
+
+template<>
+struct ParamTraits<content::ConsoleMessageLevel> {
+ typedef content::ConsoleMessageLevel param_type;
+ static void Write(Message* m, const param_type& p);
+ static bool Read(const Message* m, PickleIterator* iter, param_type* r);
+ static void Log(const param_type& p, std::string* l);
+};
+
+} // namespace IPC
+
+#endif // CONTENT_COMMON_DEVTOOLS_MESSAGES_H_
+
// These are messages sent from DevToolsAgent to DevToolsClient through the
// browser.
// WebKit-level transport.
@@ -79,6 +98,11 @@ IPC_MESSAGE_ROUTED2(DevToolsAgentMsg_InspectElement,
int /* x */,
int /* y */)
+// Add message to the devtools console.
+IPC_MESSAGE_ROUTED2(DevToolsAgentMsg_AddMessageToConsole,
+ content::ConsoleMessageLevel /* level */,
+ std::string /* message */)
+
// Notifies worker devtools agent that it should pause worker context
// when it starts and wait until either DevTools client is attached or
// explicit resume notification is received.
diff --git a/content/content_common.gypi b/content/content_common.gypi
index 4522e29..a300300 100644
--- a/content/content_common.gypi
+++ b/content/content_common.gypi
@@ -42,6 +42,7 @@
'public/common/content_switches.h',
'public/common/context_menu_params.cc',
'public/common/context_menu_params.h',
+ 'public/common/console_message_level.h',
'public/common/dx_diag_node.cc',
'public/common/dx_diag_node.h',
'public/common/file_chooser_params.cc',
@@ -124,6 +125,7 @@
'common/debug_flags.h',
'common/desktop_notification_messages.h',
'common/device_orientation_messages.h',
+ 'common/devtools_messages.cc',
'common/devtools_messages.h',
'common/dom_storage_common.h',
'common/dom_storage_messages.h',
diff --git a/content/public/browser/devtools_manager.h b/content/public/browser/devtools_manager.h
index 4fc937c..da3ec21 100644
--- a/content/public/browser/devtools_manager.h
+++ b/content/public/browser/devtools_manager.h
@@ -1,4 +1,4 @@
-// Copyright (c) 2011 The Chromium Authors. All rights reserved.
+// Copyright (c) 2012 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.
@@ -9,6 +9,7 @@
#include <string>
#include "content/common/content_export.h"
+#include "content/public/common/console_message_level.h"
class TabContents;
@@ -76,6 +77,12 @@ class CONTENT_EXPORT DevToolsManager {
// Starts inspecting element at position (x, y) in the specified page.
virtual void InspectElement(DevToolsAgentHost* agent_host, int x, int y) = 0;
+
+ // Logs given |message| on behalf of the given |agent_host|.
+ virtual void AddMessageToConsole(DevToolsAgentHost* agent_host,
+ ConsoleMessageLevel level,
+ const std::string& message) = 0;
+
};
} // namespace content
diff --git a/content/public/common/console_message_level.h b/content/public/common/console_message_level.h
new file mode 100644
index 0000000..daeae33
--- /dev/null
+++ b/content/public/common/console_message_level.h
@@ -0,0 +1,20 @@
+// Copyright (c) 2012 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 CONTENT_PUBLIC_COMMON_CONSOLE_MESSAGE_LEVEL_H_
+#define CONTENT_PUBLIC_COMMON_CONSOLE_MESSAGE_LEVEL_H_
+#pragma once
+
+namespace content {
+
+enum ConsoleMessageLevel {
+ CONSOLE_MESSAGE_LEVEL_TIP,
+ CONSOLE_MESSAGE_LEVEL_LOG,
+ CONSOLE_MESSAGE_LEVEL_WARNING,
+ CONSOLE_MESSAGE_LEVEL_ERROR
+};
+
+} // namespace content
+
+#endif // CONTENT_PUBLIC_COMMON_CONSOLE_MESSAGE_LEVEL_H_
diff --git a/content/renderer/devtools_agent.cc b/content/renderer/devtools_agent.cc
index 1d2c906..3f636bf 100644
--- a/content/renderer/devtools_agent.cc
+++ b/content/renderer/devtools_agent.cc
@@ -15,13 +15,18 @@
#include "content/renderer/devtools_agent_filter.h"
#include "content/renderer/devtools_client.h"
#include "content/renderer/render_view_impl.h"
+#include "third_party/WebKit/Source/WebKit/chromium/public/WebConsoleMessage.h"
#include "third_party/WebKit/Source/WebKit/chromium/public/WebDevToolsAgent.h"
#include "third_party/WebKit/Source/WebKit/chromium/public/platform/WebPoint.h"
#include "third_party/WebKit/Source/WebKit/chromium/public/platform/WebString.h"
+#include "third_party/WebKit/Source/WebKit/chromium/public/WebConsoleMessage.h"
+#include "third_party/WebKit/Source/WebKit/chromium/public/WebFrame.h"
#include "third_party/WebKit/Source/WebKit/chromium/public/WebView.h"
+using WebKit::WebConsoleMessage;
using WebKit::WebDevToolsAgent;
using WebKit::WebDevToolsAgentClient;
+using WebKit::WebFrame;
using WebKit::WebPoint;
using WebKit::WebString;
using WebKit::WebCString;
@@ -78,6 +83,8 @@ bool DevToolsAgent::OnMessageReceived(const IPC::Message& message) {
IPC_MESSAGE_HANDLER(DevToolsAgentMsg_DispatchOnInspectorBackend,
OnDispatchOnInspectorBackend)
IPC_MESSAGE_HANDLER(DevToolsAgentMsg_InspectElement, OnInspectElement)
+ IPC_MESSAGE_HANDLER(DevToolsAgentMsg_AddMessageToConsole,
+ OnAddMessageToConsole)
IPC_MESSAGE_HANDLER(DevToolsMsg_SetupDevToolsClient, OnSetupDevToolsClient)
IPC_MESSAGE_UNHANDLED(handled = false)
IPC_END_MESSAGE_MAP()
@@ -163,6 +170,35 @@ void DevToolsAgent::OnInspectElement(int x, int y) {
}
}
+void DevToolsAgent::OnAddMessageToConsole(content::ConsoleMessageLevel level,
+ const std::string& message) {
+ WebView* web_view = render_view()->GetWebView();
+ if (!web_view)
+ return;
+
+ WebFrame* main_frame = web_view-> mainFrame();
+ if (!main_frame)
+ return;
+
+ WebConsoleMessage::Level target_level = WebConsoleMessage::LevelLog;
+ switch (level) {
+ case content::CONSOLE_MESSAGE_LEVEL_TIP:
+ target_level = WebConsoleMessage::LevelTip;
+ break;
+ case content::CONSOLE_MESSAGE_LEVEL_LOG:
+ target_level = WebConsoleMessage::LevelLog;
+ break;
+ case content::CONSOLE_MESSAGE_LEVEL_WARNING:
+ target_level = WebConsoleMessage::LevelWarning;
+ break;
+ case content::CONSOLE_MESSAGE_LEVEL_ERROR:
+ target_level = WebConsoleMessage::LevelError;
+ break;
+ }
+ main_frame->addMessageToConsole(
+ WebConsoleMessage(target_level, WebString::fromUTF8(message)));
+}
+
void DevToolsAgent::OnNavigate() {
WebDevToolsAgent* web_agent = GetWebAgent();
if (web_agent) {
diff --git a/content/renderer/devtools_agent.h b/content/renderer/devtools_agent.h
index 847b9a0..363b03c 100644
--- a/content/renderer/devtools_agent.h
+++ b/content/renderer/devtools_agent.h
@@ -1,4 +1,4 @@
-// Copyright (c) 2011 The Chromium Authors. All rights reserved.
+// Copyright (c) 2012 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.
@@ -9,6 +9,7 @@
#include <string>
#include "base/basictypes.h"
+#include "content/public/common/console_message_level.h"
#include "content/public/renderer/render_view_observer.h"
#include "third_party/WebKit/Source/WebKit/chromium/public/WebDevToolsAgentClient.h"
@@ -56,7 +57,8 @@ class DevToolsAgent : public content::RenderViewObserver,
void OnDetach();
void OnDispatchOnInspectorBackend(const std::string& message);
void OnInspectElement(int x, int y);
- void OnSetApuAgentEnabled(bool enabled);
+ void OnAddMessageToConsole(content::ConsoleMessageLevel level,
+ const std::string& message);
void OnNavigate();
void OnSetupDevToolsClient();