| 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/sessions/restore_tab_helper.h" | |
| 11 #include "chrome/browser/sessions/session_id.h" | |
| 12 #include "chrome/browser/tabs/tab_strip_model.h" | |
| 13 #include "chrome/browser/ui/browser_list.h" | |
| 14 #include "chrome/browser/ui/tab_contents/tab_contents_wrapper.h" | |
| 15 #include "content/browser/debugger/devtools_client_host.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::CloseImpl() { | |
| 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(TabContents* new_tab) { | |
| 53 map_->erase(id_); | |
| 54 TabContentsWrapper* new_tab_wrapper = | |
| 55 TabContentsWrapper::GetCurrentWrapperForContents(new_tab); | |
| 56 DCHECK(new_tab_wrapper); | |
| 57 if (!new_tab_wrapper) | |
| 58 return; | |
| 59 id_ = new_tab_wrapper->restore_tab_helper()->session_id().id(); | |
| 60 (*map_)[id_] = this; | |
| 61 } | |
| 62 | |
| 63 void DevToolsClientHostImpl::OnDebuggerOutput(const std::string& data) { | |
| 64 service_->DebuggerOutput(id_, data); | |
| 65 } | |
| 66 | |
| 67 void DevToolsClientHostImpl::FrameNavigating(const std::string& url) { | |
| 68 service_->FrameNavigate(id_, url); | |
| 69 } | |
| 70 | |
| 71 void DevToolsClientHostImpl::TabClosed() { | |
| 72 service_->TabClosed(id_); | |
| 73 } | |
| 74 | |
| 75 InspectableTabProxy::InspectableTabProxy() {} | |
| 76 | |
| 77 InspectableTabProxy::~InspectableTabProxy() {} | |
| 78 | |
| 79 const InspectableTabProxy::TabMap& InspectableTabProxy::tab_map() { | |
| 80 tab_map_.clear(); | |
| 81 for (BrowserList::const_iterator it = BrowserList::begin(), | |
| 82 end = BrowserList::end(); it != end; ++it) { | |
| 83 TabStripModel* model = (*it)->tabstrip_model(); | |
| 84 for (int i = 0, size = model->count(); i < size; ++i) { | |
| 85 TabContentsWrapper* tab = model->GetTabContentsAt(i); | |
| 86 tab_map_[tab->restore_tab_helper()->session_id().id()] = tab; | |
| 87 } | |
| 88 } | |
| 89 return tab_map_; | |
| 90 } | |
| 91 | |
| 92 DevToolsClientHostImpl* InspectableTabProxy::ClientHostForTabId( | |
| 93 int32 id) { | |
| 94 InspectableTabProxy::IdToClientHostMap::const_iterator it = | |
| 95 id_to_client_host_map_.find(id); | |
| 96 if (it == id_to_client_host_map_.end()) { | |
| 97 return NULL; | |
| 98 } | |
| 99 return it->second; | |
| 100 } | |
| 101 | |
| 102 DevToolsClientHost* InspectableTabProxy::NewClientHost( | |
| 103 int32 id, | |
| 104 DebuggerRemoteService* service) { | |
| 105 DevToolsClientHostImpl* client_host = | |
| 106 new DevToolsClientHostImpl(id, service, &id_to_client_host_map_); | |
| 107 id_to_client_host_map_[id] = client_host; | |
| 108 return client_host; | |
| 109 } | |
| 110 | |
| 111 void InspectableTabProxy::OnRemoteDebuggerDetached() { | |
| 112 while (!id_to_client_host_map_.empty()) { | |
| 113 IdToClientHostMap::iterator it = id_to_client_host_map_.begin(); | |
| 114 it->second->debugger_remote_service()->DetachFromTab( | |
| 115 base::IntToString(it->first), NULL); | |
| 116 } | |
| 117 } | |
| OLD | NEW |