| OLD | NEW |
| (Empty) |
| 1 // Copyright (c) 2011 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 "chrome/browser/debugger/inspectable_tab_proxy.h" | |
| 6 | |
| 7 #include "base/string_number_conversions.h" | |
| 8 #include "base/string_util.h" | |
| 9 #include "chrome/browser/debugger/debugger_remote_service.h" | |
| 10 #include "chrome/browser/debugger/devtools_client_host.h" | |
| 11 #include "chrome/browser/sessions/restore_tab_helper.h" | |
| 12 #include "chrome/browser/sessions/session_id.h" | |
| 13 #include "chrome/browser/tabs/tab_strip_model.h" | |
| 14 #include "chrome/browser/ui/browser_list.h" | |
| 15 #include "chrome/browser/ui/tab_contents/tab_contents_wrapper.h" | |
| 16 #include "content/browser/tab_contents/tab_contents.h" | |
| 17 #include "content/common/devtools_messages.h" | |
| 18 | |
| 19 DevToolsClientHostImpl::DevToolsClientHostImpl( | |
| 20 int32 id, | |
| 21 DebuggerRemoteService* service, | |
| 22 InspectableTabProxy::IdToClientHostMap* map) | |
| 23 : id_(id), | |
| 24 service_(service), | |
| 25 map_(map) {} | |
| 26 | |
| 27 DevToolsClientHostImpl::~DevToolsClientHostImpl() { | |
| 28 map_->erase(this->id_); | |
| 29 } | |
| 30 | |
| 31 // The debugged tab has closed. | |
| 32 void DevToolsClientHostImpl::InspectedTabClosing() { | |
| 33 TabClosed(); | |
| 34 delete this; | |
| 35 } | |
| 36 | |
| 37 // The remote debugger has detached. | |
| 38 void DevToolsClientHostImpl::Close() { | |
| 39 NotifyCloseListener(); | |
| 40 delete this; | |
| 41 } | |
| 42 | |
| 43 void DevToolsClientHostImpl::SendMessageToClient( | |
| 44 const IPC::Message& msg) { | |
| 45 // TODO(prybin): Restore FrameNavigate. | |
| 46 IPC_BEGIN_MESSAGE_MAP(DevToolsClientHostImpl, msg) | |
| 47 IPC_MESSAGE_HANDLER(DevToolsClientMsg_DebuggerOutput, OnDebuggerOutput); | |
| 48 IPC_MESSAGE_UNHANDLED_ERROR() | |
| 49 IPC_END_MESSAGE_MAP() | |
| 50 } | |
| 51 | |
| 52 void DevToolsClientHostImpl::TabReplaced(TabContentsWrapper* new_tab) { | |
| 53 map_->erase(id_); | |
| 54 id_ = new_tab->restore_tab_helper()->session_id().id(); | |
| 55 (*map_)[id_] = this; | |
| 56 } | |
| 57 | |
| 58 void DevToolsClientHostImpl::OnDebuggerOutput(const std::string& data) { | |
| 59 service_->DebuggerOutput(id_, data); | |
| 60 } | |
| 61 | |
| 62 void DevToolsClientHostImpl::FrameNavigating(const std::string& url) { | |
| 63 service_->FrameNavigate(id_, url); | |
| 64 } | |
| 65 | |
| 66 void DevToolsClientHostImpl::TabClosed() { | |
| 67 service_->TabClosed(id_); | |
| 68 } | |
| 69 | |
| 70 InspectableTabProxy::InspectableTabProxy() {} | |
| 71 | |
| 72 InspectableTabProxy::~InspectableTabProxy() {} | |
| 73 | |
| 74 const InspectableTabProxy::TabMap& InspectableTabProxy::tab_map() { | |
| 75 tab_map_.clear(); | |
| 76 for (BrowserList::const_iterator it = BrowserList::begin(), | |
| 77 end = BrowserList::end(); it != end; ++it) { | |
| 78 TabStripModel* model = (*it)->tabstrip_model(); | |
| 79 for (int i = 0, size = model->count(); i < size; ++i) { | |
| 80 TabContentsWrapper* tab = model->GetTabContentsAt(i); | |
| 81 tab_map_[tab->restore_tab_helper()->session_id().id()] = tab; | |
| 82 } | |
| 83 } | |
| 84 return tab_map_; | |
| 85 } | |
| 86 | |
| 87 DevToolsClientHostImpl* InspectableTabProxy::ClientHostForTabId( | |
| 88 int32 id) { | |
| 89 InspectableTabProxy::IdToClientHostMap::const_iterator it = | |
| 90 id_to_client_host_map_.find(id); | |
| 91 if (it == id_to_client_host_map_.end()) { | |
| 92 return NULL; | |
| 93 } | |
| 94 return it->second; | |
| 95 } | |
| 96 | |
| 97 DevToolsClientHost* InspectableTabProxy::NewClientHost( | |
| 98 int32 id, | |
| 99 DebuggerRemoteService* service) { | |
| 100 DevToolsClientHostImpl* client_host = | |
| 101 new DevToolsClientHostImpl(id, service, &id_to_client_host_map_); | |
| 102 id_to_client_host_map_[id] = client_host; | |
| 103 return client_host; | |
| 104 } | |
| 105 | |
| 106 void InspectableTabProxy::OnRemoteDebuggerDetached() { | |
| 107 while (!id_to_client_host_map_.empty()) { | |
| 108 IdToClientHostMap::iterator it = id_to_client_host_map_.begin(); | |
| 109 it->second->debugger_remote_service()->DetachFromTab( | |
| 110 base::IntToString(it->first), NULL); | |
| 111 } | |
| 112 } | |
| OLD | NEW |