| OLD | NEW |
| 1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. | 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 | 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/extensions/extension_devtools_bridge.h" | 5 #include "chrome/browser/extensions/extension_devtools_bridge.h" |
| 6 | 6 |
| 7 #include "base/json/json_writer.h" | 7 #include "base/json/json_writer.h" |
| 8 #include "base/message_loop.h" | 8 #include "base/message_loop.h" |
| 9 #include "base/string_util.h" | 9 #include "base/string_util.h" |
| 10 #include "base/stringprintf.h" | 10 #include "base/stringprintf.h" |
| 11 #include "base/values.h" | 11 #include "base/values.h" |
| 12 #include "chrome/browser/extensions/extension_devtools_events.h" | 12 #include "chrome/browser/extensions/extension_devtools_events.h" |
| 13 #include "chrome/browser/extensions/extension_devtools_manager.h" | 13 #include "chrome/browser/extensions/extension_devtools_manager.h" |
| 14 #include "chrome/browser/extensions/extension_event_router.h" | 14 #include "chrome/browser/extensions/extension_event_router.h" |
| 15 #include "chrome/browser/extensions/extension_tab_util.h" | 15 #include "chrome/browser/extensions/extension_tab_util.h" |
| 16 #include "chrome/browser/profiles/profile.h" | 16 #include "chrome/browser/profiles/profile.h" |
| 17 #include "chrome/browser/ui/tab_contents/tab_contents_wrapper.h" | 17 #include "chrome/browser/ui/tab_contents/tab_contents_wrapper.h" |
| 18 #include "content/browser/tab_contents/tab_contents.h" | |
| 19 #include "content/public/browser/devtools_agent_host_registry.h" | 18 #include "content/public/browser/devtools_agent_host_registry.h" |
| 20 #include "content/public/browser/devtools_manager.h" | 19 #include "content/public/browser/devtools_manager.h" |
| 20 #include "content/public/browser/web_contents.h" |
| 21 | 21 |
| 22 using content::DevToolsAgentHost; | 22 using content::DevToolsAgentHost; |
| 23 using content::DevToolsAgentHostRegistry; | 23 using content::DevToolsAgentHostRegistry; |
| 24 using content::DevToolsManager; | 24 using content::DevToolsManager; |
| 25 using content::WebContents; |
| 25 | 26 |
| 26 ExtensionDevToolsBridge::ExtensionDevToolsBridge(int tab_id, | 27 ExtensionDevToolsBridge::ExtensionDevToolsBridge(int tab_id, |
| 27 Profile* profile) | 28 Profile* profile) |
| 28 : tab_id_(tab_id), | 29 : tab_id_(tab_id), |
| 29 profile_(profile), | 30 profile_(profile), |
| 30 on_page_event_name_( | 31 on_page_event_name_( |
| 31 ExtensionDevToolsEvents::OnPageEventNameForTab(tab_id)), | 32 ExtensionDevToolsEvents::OnPageEventNameForTab(tab_id)), |
| 32 on_tab_close_event_name_( | 33 on_tab_close_event_name_( |
| 33 ExtensionDevToolsEvents::OnTabCloseEventNameForTab(tab_id)) { | 34 ExtensionDevToolsEvents::OnTabCloseEventNameForTab(tab_id)) { |
| 34 extension_devtools_manager_ = profile_->GetExtensionDevToolsManager(); | 35 extension_devtools_manager_ = profile_->GetExtensionDevToolsManager(); |
| (...skipping 19 matching lines...) Expand all Loading... |
| 54 | 55 |
| 55 Browser* browser; | 56 Browser* browser; |
| 56 TabStripModel* tab_strip; | 57 TabStripModel* tab_strip; |
| 57 TabContentsWrapper* contents; | 58 TabContentsWrapper* contents; |
| 58 int tab_index; | 59 int tab_index; |
| 59 if (ExtensionTabUtil::GetTabById(tab_id_, profile_, true, | 60 if (ExtensionTabUtil::GetTabById(tab_id_, profile_, true, |
| 60 &browser, &tab_strip, | 61 &browser, &tab_strip, |
| 61 &contents, &tab_index)) { | 62 &contents, &tab_index)) { |
| 62 DevToolsManager* devtools_manager = DevToolsManager::GetInstance(); | 63 DevToolsManager* devtools_manager = DevToolsManager::GetInstance(); |
| 63 DevToolsAgentHost* agent = DevToolsAgentHostRegistry::GetDevToolsAgentHost( | 64 DevToolsAgentHost* agent = DevToolsAgentHostRegistry::GetDevToolsAgentHost( |
| 64 contents->tab_contents()->GetRenderViewHost()); | 65 contents->web_contents()->GetRenderViewHost()); |
| 65 if (devtools_manager->GetDevToolsClientHostFor(agent)) | 66 if (devtools_manager->GetDevToolsClientHostFor(agent)) |
| 66 return false; | 67 return false; |
| 67 | 68 |
| 68 devtools_manager->RegisterDevToolsClientHostFor(agent, this); | 69 devtools_manager->RegisterDevToolsClientHostFor(agent, this); |
| 69 | 70 |
| 70 // Following messages depend on inspector protocol that is not yet | 71 // Following messages depend on inspector protocol that is not yet |
| 71 // finalized. | 72 // finalized. |
| 72 | 73 |
| 73 // 1. Start timeline profiler. | 74 // 1. Start timeline profiler. |
| 74 devtools_manager->DispatchOnInspectorBackend( | 75 devtools_manager->DispatchOnInspectorBackend( |
| (...skipping 37 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 112 | 113 |
| 113 void ExtensionDevToolsBridge::DispatchOnInspectorFrontend( | 114 void ExtensionDevToolsBridge::DispatchOnInspectorFrontend( |
| 114 const std::string& data) { | 115 const std::string& data) { |
| 115 DCHECK_EQ(MessageLoop::current()->type(), MessageLoop::TYPE_UI); | 116 DCHECK_EQ(MessageLoop::current()->type(), MessageLoop::TYPE_UI); |
| 116 | 117 |
| 117 std::string json = base::StringPrintf("[%s]", data.c_str()); | 118 std::string json = base::StringPrintf("[%s]", data.c_str()); |
| 118 profile_->GetExtensionEventRouter()->DispatchEventToRenderers( | 119 profile_->GetExtensionEventRouter()->DispatchEventToRenderers( |
| 119 on_page_event_name_, json, profile_, GURL()); | 120 on_page_event_name_, json, profile_, GURL()); |
| 120 } | 121 } |
| 121 | 122 |
| 122 void ExtensionDevToolsBridge::TabReplaced(TabContents* new_tab) { | 123 void ExtensionDevToolsBridge::TabReplaced(WebContents* new_tab) { |
| 123 // We don't update the tab id as it needs to remain the same so that we can | 124 // We don't update the tab id as it needs to remain the same so that we can |
| 124 // properly unregister. | 125 // properly unregister. |
| 125 } | 126 } |
| OLD | NEW |