1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. 2 // Use of this source code is governed by a BSD-style license that can be 3 // found in the LICENSE file. 4 5 #include "content/browser/devtools/devtools_frontend_host.h" 6 7 #include "content/browser/devtools/devtools_manager_impl.h" 8 #include "content/browser/renderer_host/render_view_host_impl.h" 9 #include "content/browser/web_contents/web_contents_impl.h" 10 #include "content/common/devtools_messages.h" 11 #include "content/public/browser/devtools_client_host.h" 12 #include "content/public/browser/devtools_frontend_host_delegate.h" 13 14 namespace content { 15 16 // static 17 DevToolsClientHost* DevToolsClientHost::CreateDevToolsFrontendHost( 18 WebContents* client_web_contents, 19 DevToolsFrontendHostDelegate* delegate) { 20 return new DevToolsFrontendHost( 21 static_cast<WebContentsImpl*>(client_web_contents), delegate); 22 } 23 24 // static 25 void DevToolsClientHost::SetupDevToolsFrontendClient( 26 RenderViewHost* frontend_rvh) { 27 frontend_rvh->Send(new DevToolsMsg_SetupDevToolsClient( 28 frontend_rvh->GetRoutingID())); 29 } 30 31 DevToolsFrontendHost::DevToolsFrontendHost( 32 WebContentsImpl* web_contents, 33 DevToolsFrontendHostDelegate* delegate) 34 : WebContentsObserver(web_contents), 35 delegate_(delegate) { 36 } 37 38 DevToolsFrontendHost::~DevToolsFrontendHost() { 39 DevToolsManager::GetInstance()->ClientHostClosing(this); 40 } 41 42 void DevToolsFrontendHost::DispatchOnInspectorFrontend( 43 const std::string& message) { 44 if (!web_contents()) 45 return; 46 RenderViewHostImpl* target_host = 47 static_cast<RenderViewHostImpl*>(web_contents()->GetRenderViewHost()); 48 target_host->Send(new DevToolsClientMsg_DispatchOnInspectorFrontend( 49 target_host->GetRoutingID(), 50 message)); 51 } 52 53 void DevToolsFrontendHost::InspectedContentsClosing() { 54 delegate_->InspectedContentsClosing(); 55 } 56 57 void DevToolsFrontendHost::ReplacedWithAnotherClient() { 58 } 59 60 bool DevToolsFrontendHost::OnMessageReceived( 61 const IPC::Message& message) { 62 bool handled = true; 63 IPC_BEGIN_MESSAGE_MAP(DevToolsFrontendHost, message) 64 IPC_MESSAGE_HANDLER(DevToolsAgentMsg_DispatchOnInspectorBackend, 65 OnDispatchOnInspectorBackend) 66 IPC_MESSAGE_HANDLER(DevToolsHostMsg_ActivateWindow, OnActivateWindow) 67 IPC_MESSAGE_HANDLER(DevToolsHostMsg_ChangeAttachedWindowHeight, 68 OnChangeAttachedWindowHeight) 69 IPC_MESSAGE_HANDLER(DevToolsHostMsg_CloseWindow, OnCloseWindow) 70 IPC_MESSAGE_HANDLER(DevToolsHostMsg_MoveWindow, OnMoveWindow) 71 IPC_MESSAGE_HANDLER(DevToolsHostMsg_RequestSetDockSide, 72 OnRequestSetDockSide) 73 IPC_MESSAGE_HANDLER(DevToolsHostMsg_OpenInNewTab, OnOpenInNewTab) 74 IPC_MESSAGE_HANDLER(DevToolsHostMsg_Save, OnSave) 75 IPC_MESSAGE_HANDLER(DevToolsHostMsg_Append, OnAppend) 76 IPC_MESSAGE_HANDLER(DevToolsHostMsg_RequestFileSystems, 77 OnRequestFileSystems) 78 IPC_MESSAGE_HANDLER(DevToolsHostMsg_AddFileSystem, OnAddFileSystem) 79 IPC_MESSAGE_HANDLER(DevToolsHostMsg_RemoveFileSystem, OnRemoveFileSystem) 80 IPC_MESSAGE_HANDLER(DevToolsHostMsg_IndexPath, OnIndexPath) 81 IPC_MESSAGE_HANDLER(DevToolsHostMsg_StopIndexing, OnStopIndexing) 82 IPC_MESSAGE_HANDLER(DevToolsHostMsg_SearchInPath, OnSearchInPath) 83 IPC_MESSAGE_UNHANDLED(handled = false) 84 IPC_END_MESSAGE_MAP() 85 return handled; 86 } 87 88 void DevToolsFrontendHost::RenderProcessGone( 89 base::TerminationStatus status) { 90 switch(status) { 91 case base::TERMINATION_STATUS_ABNORMAL_TERMINATION: 92 case base::TERMINATION_STATUS_PROCESS_WAS_KILLED: 93 case base::TERMINATION_STATUS_PROCESS_CRASHED: 94 DevToolsManager::GetInstance()->ClientHostClosing(this); 95 break; 96 default: 97 break; 98 } 99 } 100 101 void DevToolsFrontendHost::OnDispatchOnInspectorBackend( 102 const std::string& message) { 103 DevToolsManagerImpl::GetInstance()->DispatchOnInspectorBackend(this, message); 104 // delegate_->DispatchOnInspectorBackend(message); 105 } 106 107 void DevToolsFrontendHost::OnActivateWindow() { 108 delegate_->ActivateWindow(); 109 } 110 111 void DevToolsFrontendHost::OnChangeAttachedWindowHeight(unsigned height) { 112 delegate_->ChangeAttachedWindowHeight(height); 113 } 114 115 void DevToolsFrontendHost::OnCloseWindow() { 116 delegate_->CloseWindow(); 117 } 118 119 void DevToolsFrontendHost::OnMoveWindow(int x, int y) { 120 delegate_->MoveWindow(x, y); 121 } 122 123 void DevToolsFrontendHost::OnOpenInNewTab(const std::string& url) { 124 delegate_->OpenInNewTab(url); 125 } 126 127 void DevToolsFrontendHost::OnSave( 128 const std::string& url, 129 const std::string& content, 130 bool save_as) { 131 delegate_->SaveToFile(url, content, save_as); 132 } 133 134 void DevToolsFrontendHost::OnAppend( 135 const std::string& url, 136 const std::string& content) { 137 delegate_->AppendToFile(url, content); 138 } 139 140 void DevToolsFrontendHost::OnRequestFileSystems() { 141 delegate_->RequestFileSystems(); 142 } 143 144 void DevToolsFrontendHost::OnAddFileSystem() { 145 delegate_->AddFileSystem(); 146 } 147 148 void DevToolsFrontendHost::OnRemoveFileSystem( 149 const std::string& file_system_path) { 150 delegate_->RemoveFileSystem(file_system_path); 151 } 152 153 void DevToolsFrontendHost::OnIndexPath(int request_id, 154 const std::string& file_system_path) { 155 delegate_->IndexPath(request_id, file_system_path); 156 } 157 158 void DevToolsFrontendHost::OnStopIndexing(int request_id) { 159 delegate_->StopIndexing(request_id); 160 } 161 162 void DevToolsFrontendHost::OnSearchInPath(int request_id, 163 const std::string& file_system_path, 164 const std::string& query) { 165 delegate_->SearchInPath(request_id, file_system_path, query); 166 } 167 168 void DevToolsFrontendHost::OnRequestSetDockSide(const std::string& side) { 169 delegate_->SetDockSide(side); 170 } 171 172 } // namespace content 173