| 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/browser/debugger/devtools_manager.h" | 5 #include "chrome/browser/debugger/devtools_manager.h" |
| 6 | 6 |
| 7 #include "chrome/browser/debugger/devtools_window.h" | 7 #include "chrome/browser/debugger/devtools_window.h" |
| 8 #include "chrome/browser/debugger/devtools_client_host.h" | 8 #include "chrome/browser/debugger/devtools_client_host.h" |
| 9 #include "chrome/browser/renderer_host/render_view_host.h" | 9 #include "chrome/browser/renderer_host/render_view_host.h" |
| 10 #include "chrome/browser/tab_contents/tab_contents.h" | 10 #include "chrome/browser/tab_contents/tab_contents.h" |
| 11 #include "chrome/browser/tab_contents/web_contents.h" | 11 #include "chrome/browser/tab_contents/web_contents.h" |
| 12 #include "chrome/common/devtools_messages.h" | 12 #include "chrome/common/devtools_messages.h" |
| 13 #include "chrome/common/notification_registrar.h" | 13 #include "chrome/common/notification_registrar.h" |
| 14 #include "chrome/common/notification_type.h" | 14 #include "chrome/common/notification_type.h" |
| 15 | 15 |
| 16 DevToolsManager::DevToolsManager() : web_contents_listeners_(NULL) { | 16 DevToolsManager::DevToolsManager() : web_contents_listeners_(NULL) { |
| 17 } | 17 } |
| 18 | 18 |
| 19 DevToolsManager::~DevToolsManager() { | 19 DevToolsManager::~DevToolsManager() { |
| 20 DCHECK(!web_contents_listeners_.get()) << | 20 DCHECK(!web_contents_listeners_.get()) << |
| 21 "All devtools client hosts must alredy have been destroyed."; | 21 "All devtools client hosts must alredy have been destroyed."; |
| 22 DCHECK(navcontroller_to_client_host_.empty()); | 22 DCHECK(navcontroller_to_client_host_.empty()); |
| 23 DCHECK(client_host_to_navcontroller_.empty()); | 23 DCHECK(client_host_to_navcontroller_.empty()); |
| 24 } | 24 } |
| 25 | 25 |
| 26 void DevToolsManager::Observe(NotificationType type, | 26 void DevToolsManager::Observe(NotificationType type, |
| 27 const NotificationSource& source, | 27 const NotificationSource& source, |
| 28 const NotificationDetails& details) { | 28 const NotificationDetails& details) { |
| 29 DCHECK(type == NotificationType::WEB_CONTENTS_DISCONNECTED || | 29 DCHECK(type == NotificationType::WEB_CONTENTS_DISCONNECTED); |
| 30 type == NotificationType::WEB_CONTENTS_SWAPPED); | |
| 31 | 30 |
| 32 if (type == NotificationType::WEB_CONTENTS_DISCONNECTED) { | 31 if (type == NotificationType::WEB_CONTENTS_DISCONNECTED) { |
| 33 Source<WebContents> src(source); | 32 Source<WebContents> src(source); |
| 34 DevToolsClientHost* client_host = GetDevToolsClientHostFor(*src.ptr()); | 33 DevToolsClientHost* client_host = GetDevToolsClientHostFor(*src.ptr()); |
| 35 if (!client_host) { | 34 if (!client_host) { |
| 36 return; | 35 return; |
| 37 } | 36 } |
| 38 | 37 |
| 39 NavigationController* controller = src->controller(); | 38 NavigationController* controller = src->controller(); |
| 40 bool active = (controller->active_contents() == src.ptr()); | 39 bool active = (controller->active_contents() == src.ptr()); |
| 41 if (active) { | 40 if (active) { |
| 42 // Active tab contents disconnecting from its renderer means that the tab | 41 // Active tab contents disconnecting from its renderer means that the tab |
| 43 // is closing. | 42 // is closing. |
| 44 client_host->InspectedTabClosing(); | 43 client_host->InspectedTabClosing(); |
| 45 UnregisterDevToolsClientHost(client_host, controller); | 44 UnregisterDevToolsClientHost(client_host, controller); |
| 46 } | 45 } |
| 47 } else if (type == NotificationType::WEB_CONTENTS_SWAPPED) { | |
| 48 Source<WebContents> src(source); | |
| 49 DevToolsClientHost* client_host = GetDevToolsClientHostFor(*src.ptr()); | |
| 50 if (client_host) { | |
| 51 SendAttachToAgent(*src.ptr()); | |
| 52 } | |
| 53 } | 46 } |
| 54 } | 47 } |
| 55 | 48 |
| 56 DevToolsClientHost* DevToolsManager::GetDevToolsClientHostFor( | 49 DevToolsClientHost* DevToolsManager::GetDevToolsClientHostFor( |
| 57 const WebContents& web_contents) { | 50 const WebContents& web_contents) { |
| 58 NavigationController* navigation_controller = web_contents.controller(); | 51 NavigationController* navigation_controller = web_contents.controller(); |
| 59 ClientHostMap::const_iterator it = | 52 ClientHostMap::const_iterator it = |
| 60 navcontroller_to_client_host_.find(navigation_controller); | 53 navcontroller_to_client_host_.find(navigation_controller); |
| 61 if (it != navcontroller_to_client_host_.end()) { | 54 if (it != navcontroller_to_client_host_.end()) { |
| 62 return it->second; | 55 return it->second; |
| 63 } | 56 } |
| 64 return NULL; | 57 return NULL; |
| 65 } | 58 } |
| 66 | 59 |
| 67 void DevToolsManager::RegisterDevToolsClientHostFor( | 60 void DevToolsManager::RegisterDevToolsClientHostFor( |
| 68 const WebContents& web_contents, | 61 const WebContents& web_contents, |
| 69 DevToolsClientHost* client_host) { | 62 DevToolsClientHost* client_host) { |
| 70 DCHECK(!GetDevToolsClientHostFor(web_contents)); | 63 DCHECK(!GetDevToolsClientHostFor(web_contents)); |
| 71 | 64 |
| 72 NavigationController* navigation_controller = web_contents.controller(); | 65 NavigationController* navigation_controller = web_contents.controller(); |
| 73 navcontroller_to_client_host_[navigation_controller] = client_host; | 66 navcontroller_to_client_host_[navigation_controller] = client_host; |
| 74 client_host_to_navcontroller_[client_host] = navigation_controller; | 67 client_host_to_navcontroller_[client_host] = navigation_controller; |
| 75 client_host->set_close_listener(this); | 68 client_host->set_close_listener(this); |
| 76 | 69 |
| 77 StartListening(navigation_controller); | 70 StartListening(navigation_controller); |
| 78 SendAttachToAgent(web_contents); | 71 SendAttachToAgent(web_contents, web_contents.render_view_host()); |
| 79 } | 72 } |
| 80 | 73 |
| 81 void DevToolsManager::ForwardToDevToolsAgent( | 74 void DevToolsManager::ForwardToDevToolsAgent( |
| 82 const RenderViewHost& client_rvh, | 75 const RenderViewHost& client_rvh, |
| 83 const IPC::Message& message) { | 76 const IPC::Message& message) { |
| 84 for (ClientHostMap::const_iterator it = | 77 for (ClientHostMap::const_iterator it = |
| 85 navcontroller_to_client_host_.begin(); | 78 navcontroller_to_client_host_.begin(); |
| 86 it != navcontroller_to_client_host_.end(); | 79 it != navcontroller_to_client_host_.end(); |
| 87 ++it) { | 80 ++it) { |
| 88 DevToolsWindow* win = it->second->AsDevToolsWindow(); | 81 DevToolsWindow* win = it->second->AsDevToolsWindow(); |
| (...skipping 111 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 200 | 193 |
| 201 void DevToolsManager::StartListening( | 194 void DevToolsManager::StartListening( |
| 202 NavigationController* navigation_controller) { | 195 NavigationController* navigation_controller) { |
| 203 // TODO(yurys): add render host change listener | 196 // TODO(yurys): add render host change listener |
| 204 if (!web_contents_listeners_.get()) { | 197 if (!web_contents_listeners_.get()) { |
| 205 web_contents_listeners_.reset(new NotificationRegistrar); | 198 web_contents_listeners_.reset(new NotificationRegistrar); |
| 206 web_contents_listeners_->Add( | 199 web_contents_listeners_->Add( |
| 207 this, | 200 this, |
| 208 NotificationType::WEB_CONTENTS_DISCONNECTED, | 201 NotificationType::WEB_CONTENTS_DISCONNECTED, |
| 209 NotificationService::AllSources()); | 202 NotificationService::AllSources()); |
| 210 web_contents_listeners_->Add( | |
| 211 this, | |
| 212 NotificationType::WEB_CONTENTS_SWAPPED, | |
| 213 NotificationService::AllSources()); | |
| 214 } | 203 } |
| 215 } | 204 } |
| 216 | 205 |
| 217 void DevToolsManager::StopListening( | 206 void DevToolsManager::StopListening( |
| 218 NavigationController* navigation_controller) { | 207 NavigationController* navigation_controller) { |
| 219 DCHECK(web_contents_listeners_.get()); | 208 DCHECK(web_contents_listeners_.get()); |
| 220 if (navcontroller_to_client_host_.empty()) { | 209 if (navcontroller_to_client_host_.empty()) { |
| 221 DCHECK(client_host_to_navcontroller_.empty()); | 210 DCHECK(client_host_to_navcontroller_.empty()); |
| 222 web_contents_listeners_.reset(); | 211 web_contents_listeners_.reset(); |
| 223 } | 212 } |
| 224 } | 213 } |
| 225 | 214 |
| 226 void DevToolsManager::SendAttachToAgent(const WebContents& wc) { | 215 void DevToolsManager::SendAttachToAgent(const WebContents& wc, |
| 227 RenderViewHost* target_host = wc.render_view_host(); | 216 RenderViewHost* target_host) { |
| 228 if (target_host) { | 217 if (GetDevToolsClientHostFor(wc) && target_host) { |
| 229 IPC::Message* m = new DevToolsAgentMsg_Attach(); | 218 IPC::Message* m = new DevToolsAgentMsg_Attach(); |
| 230 m->set_routing_id(target_host->routing_id()); | 219 m->set_routing_id(target_host->routing_id()); |
| 231 target_host->Send(m); | 220 target_host->Send(m); |
| 232 } | 221 } |
| 233 } | 222 } |
| 234 | 223 |
| 235 void DevToolsManager::SendDetachToAgent(const WebContents& wc) { | 224 void DevToolsManager::SendDetachToAgent(const WebContents& wc) { |
| 236 RenderViewHost* target_host = wc.render_view_host(); | 225 RenderViewHost* target_host = wc.render_view_host(); |
| 237 if (target_host) { | 226 if (target_host) { |
| 238 IPC::Message* m = new DevToolsAgentMsg_Detach(); | 227 IPC::Message* m = new DevToolsAgentMsg_Detach(); |
| 239 m->set_routing_id(target_host->routing_id()); | 228 m->set_routing_id(target_host->routing_id()); |
| 240 target_host->Send(m); | 229 target_host->Send(m); |
| 241 } | 230 } |
| 242 } | 231 } |
| OLD | NEW |