| OLD | NEW |
| 1 // Copyright (c) 2009 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2009 The Chromium Authors. All rights reserved. |
| 2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
| 4 | 4 |
| 5 #include "chrome/renderer/devtools_client.h" | 5 #include "chrome/renderer/devtools_client.h" |
| 6 | 6 |
| 7 #include "app/app_switches.h" | 7 #include "app/app_switches.h" |
| 8 #include "base/command_line.h" | 8 #include "base/command_line.h" |
| 9 #include "base/utf_string_conversions.h" | 9 #include "base/utf_string_conversions.h" |
| 10 #include "chrome/common/chrome_switches.h" | 10 #include "chrome/common/chrome_switches.h" |
| 11 #include "chrome/common/devtools_messages.h" | 11 #include "chrome/common/devtools_messages.h" |
| 12 #include "chrome/common/render_messages.h" | 12 #include "chrome/common/render_messages.h" |
| 13 #include "chrome/renderer/render_thread.h" | 13 #include "chrome/renderer/render_thread.h" |
| 14 #include "chrome/renderer/render_view.h" | |
| 15 #include "third_party/WebKit/WebKit/chromium/public/WebDevToolsFrontend.h" | 14 #include "third_party/WebKit/WebKit/chromium/public/WebDevToolsFrontend.h" |
| 16 #include "third_party/WebKit/WebKit/chromium/public/WebString.h" | 15 #include "third_party/WebKit/WebKit/chromium/public/WebString.h" |
| 17 | 16 |
| 18 using WebKit::WebDevToolsFrontend; | 17 using WebKit::WebDevToolsFrontend; |
| 19 using WebKit::WebString; | 18 using WebKit::WebString; |
| 20 | 19 |
| 21 DevToolsClient::DevToolsClient(RenderView* view) | 20 DevToolsClient::DevToolsClient(WebKit::WebView* webview) { |
| 22 : render_view_(view) { | |
| 23 const CommandLine& command_line = *CommandLine::ForCurrentProcess(); | 21 const CommandLine& command_line = *CommandLine::ForCurrentProcess(); |
| 24 web_tools_frontend_.reset( | 22 web_tools_frontend_.reset( |
| 25 WebDevToolsFrontend::create( | 23 WebDevToolsFrontend::create( |
| 26 view->webview(), | 24 webview, |
| 27 this, | 25 this, |
| 28 ASCIIToUTF16(command_line.GetSwitchValueASCII(switches::kLang)))); | 26 ASCIIToUTF16(command_line.GetSwitchValueASCII(switches::kLang)))); |
| 29 } | 27 } |
| 30 | 28 |
| 31 DevToolsClient::~DevToolsClient() { | 29 DevToolsClient::~DevToolsClient() { |
| 32 } | 30 } |
| 33 | 31 |
| 34 void DevToolsClient::Send(const IPC::Message& tools_agent_message) { | 32 void DevToolsClient::SendToAgent(const IPC::Message& tools_agent_message) { |
| 35 render_view_->Send(new ViewHostMsg_ForwardToDevToolsAgent( | 33 Send(new ViewHostMsg_ForwardToDevToolsAgent( |
| 36 render_view_->routing_id(), | 34 routing_id(), tools_agent_message)); |
| 37 tools_agent_message)); | |
| 38 } | 35 } |
| 39 | 36 |
| 40 bool DevToolsClient::OnMessageReceived(const IPC::Message& message) { | 37 bool DevToolsClient::OnMessageReceived(const IPC::Message& message) { |
| 41 DCHECK(RenderThread::current()->message_loop() == MessageLoop::current()); | 38 DCHECK(RenderThread::current()->message_loop() == MessageLoop::current()); |
| 42 | 39 |
| 43 bool handled = true; | 40 bool handled = true; |
| 44 IPC_BEGIN_MESSAGE_MAP(DevToolsClient, message) | 41 IPC_BEGIN_MESSAGE_MAP(DevToolsClient, message) |
| 45 IPC_MESSAGE_HANDLER(DevToolsClientMsg_DispatchOnInspectorFrontend, | 42 IPC_MESSAGE_HANDLER(DevToolsClientMsg_DispatchOnInspectorFrontend, |
| 46 OnDispatchOnInspectorFrontend) | 43 OnDispatchOnInspectorFrontend) |
| 47 IPC_MESSAGE_UNHANDLED(handled = false); | 44 IPC_MESSAGE_UNHANDLED(handled = false); |
| 48 IPC_END_MESSAGE_MAP() | 45 IPC_END_MESSAGE_MAP() |
| 49 | 46 |
| 50 return handled; | 47 return handled; |
| 51 } | 48 } |
| 52 | 49 |
| 53 void DevToolsClient::sendFrontendLoaded() { | 50 void DevToolsClient::sendFrontendLoaded() { |
| 54 Send(DevToolsAgentMsg_FrontendLoaded()); | 51 SendToAgent(DevToolsAgentMsg_FrontendLoaded()); |
| 55 } | 52 } |
| 56 | 53 |
| 57 void DevToolsClient::sendMessageToBackend(const WebString& message) { | 54 void DevToolsClient::sendMessageToBackend(const WebString& message) { |
| 58 Send(DevToolsAgentMsg_DispatchOnInspectorBackend(message.utf8())); | 55 SendToAgent(DevToolsAgentMsg_DispatchOnInspectorBackend(message.utf8())); |
| 59 } | 56 } |
| 60 | 57 |
| 61 void DevToolsClient::sendDebuggerCommandToAgent(const WebString& command) { | 58 void DevToolsClient::sendDebuggerCommandToAgent(const WebString& command) { |
| 62 Send(DevToolsAgentMsg_DebuggerCommand(command.utf8())); | 59 SendToAgent(DevToolsAgentMsg_DebuggerCommand(command.utf8())); |
| 63 } | 60 } |
| 64 | 61 |
| 65 void DevToolsClient::activateWindow() { | 62 void DevToolsClient::activateWindow() { |
| 66 render_view_->Send(new ViewHostMsg_ActivateDevToolsWindow( | 63 Send(new ViewHostMsg_ActivateDevToolsWindow(routing_id())); |
| 67 render_view_->routing_id())); | |
| 68 } | 64 } |
| 69 | 65 |
| 70 void DevToolsClient::closeWindow() { | 66 void DevToolsClient::closeWindow() { |
| 71 render_view_->Send(new ViewHostMsg_CloseDevToolsWindow( | 67 Send(new ViewHostMsg_CloseDevToolsWindow(routing_id())); |
| 72 render_view_->routing_id())); | |
| 73 } | 68 } |
| 74 | 69 |
| 75 void DevToolsClient::requestDockWindow() { | 70 void DevToolsClient::requestDockWindow() { |
| 76 render_view_->Send(new ViewHostMsg_RequestDockDevToolsWindow( | 71 Send(new ViewHostMsg_RequestDockDevToolsWindow(routing_id())); |
| 77 render_view_->routing_id())); | |
| 78 } | 72 } |
| 79 | 73 |
| 80 void DevToolsClient::requestUndockWindow() { | 74 void DevToolsClient::requestUndockWindow() { |
| 81 render_view_->Send(new ViewHostMsg_RequestUndockDevToolsWindow( | 75 Send(new ViewHostMsg_RequestUndockDevToolsWindow(routing_id())); |
| 82 render_view_->routing_id())); | |
| 83 } | 76 } |
| 84 | 77 |
| 85 void DevToolsClient::OnDispatchOnInspectorFrontend( | 78 void DevToolsClient::OnDispatchOnInspectorFrontend(const std::string& message) { |
| 86 const std::string& message) { | 79 web_tools_frontend_->dispatchOnInspectorFrontend( |
| 87 web_tools_frontend_->dispatchOnInspectorFrontend( | 80 WebString::fromUTF8(message)); |
| 88 WebString::fromUTF8(message)); | |
| 89 } | 81 } |
| 90 | 82 |
| 91 bool DevToolsClient::shouldHideScriptsPanel() { | 83 bool DevToolsClient::shouldHideScriptsPanel() { |
| 92 CommandLine* cmd = CommandLine::ForCurrentProcess(); | 84 CommandLine* cmd = CommandLine::ForCurrentProcess(); |
| 93 return cmd->HasSwitch(switches::kRemoteShellPort); | 85 return cmd->HasSwitch(switches::kRemoteShellPort); |
| 94 } | 86 } |
| OLD | NEW |