OLD | NEW |
---|---|
1 // Copyright 2014 The Chromium Authors. All rights reserved. | 1 // Copyright 2014 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/devtools/chrome_devtools_manager_delegate.h" | 5 #include "chrome/browser/devtools/chrome_devtools_manager_delegate.h" |
6 | 6 |
7 #include "build/build_config.h" | 7 #include "build/build_config.h" |
8 #include "chrome/browser/devtools/devtools_network_protocol_handler.h" | 8 #include "chrome/browser/devtools/devtools_network_protocol_handler.h" |
9 #include "components/devtools_discovery/devtools_discovery_manager.h" | 9 #include "components/devtools_discovery/devtools_discovery_manager.h" |
10 | 10 |
11 #if !defined(OS_ANDROID) | 11 #if !defined(OS_ANDROID) |
12 #include "chrome/browser/devtools/devtools_window.h" | 12 #include "chrome/browser/devtools/devtools_window.h" |
13 #include "chrome/browser/extensions/extension_tab_util.h" | |
13 #include "chrome/browser/profiles/profile.h" | 14 #include "chrome/browser/profiles/profile.h" |
15 #include "chrome/browser/ui/tab_contents/tab_contents_iterator.h" | |
14 #include "content/public/browser/devtools_agent_host.h" | 16 #include "content/public/browser/devtools_agent_host.h" |
17 #include "content/public/browser/render_frame_host.h" | |
18 #include "content/public/browser/web_contents.h" | |
19 #include "extensions/browser/extension_host.h" | |
20 #include "extensions/browser/extension_registry.h" | |
21 #include "extensions/browser/process_manager.h" | |
15 #endif // !defined(OS_ANDROID) | 22 #endif // !defined(OS_ANDROID) |
16 | 23 |
17 using devtools_discovery::DevToolsDiscoveryManager; | 24 using devtools_discovery::DevToolsDiscoveryManager; |
18 | 25 |
19 ChromeDevToolsManagerDelegate::ChromeDevToolsManagerDelegate() | 26 ChromeDevToolsManagerDelegate::ChromeDevToolsManagerDelegate() |
20 : network_protocol_handler_(new DevToolsNetworkProtocolHandler()) { | 27 : network_protocol_handler_(new DevToolsNetworkProtocolHandler()) { |
21 } | 28 } |
22 | 29 |
23 ChromeDevToolsManagerDelegate::~ChromeDevToolsManagerDelegate() { | 30 ChromeDevToolsManagerDelegate::~ChromeDevToolsManagerDelegate() { |
24 } | 31 } |
25 | 32 |
26 void ChromeDevToolsManagerDelegate::Inspect( | 33 void ChromeDevToolsManagerDelegate::Inspect( |
27 content::BrowserContext* browser_context, | |
28 content::DevToolsAgentHost* agent_host) { | 34 content::DevToolsAgentHost* agent_host) { |
29 #if !defined(OS_ANDROID) | 35 #if !defined(OS_ANDROID) |
30 Profile* profile = Profile::FromBrowserContext(browser_context); | 36 Profile* profile = |
37 Profile::FromBrowserContext(agent_host->GetBrowserContext()); | |
31 if (!profile) | 38 if (!profile) |
32 return; | 39 return; |
33 content::DevToolsAgentHost::Type type = agent_host->GetType(); | 40 std::string type = agent_host->GetType(); |
34 if (type == content::DevToolsAgentHost::TYPE_SHARED_WORKER || | 41 if (type == content::DevToolsAgentHost::kTypeSharedWorker || |
35 type == content::DevToolsAgentHost::TYPE_SERVICE_WORKER) { | 42 type == content::DevToolsAgentHost::kTypeServiceWorker) { |
36 DevToolsWindow::OpenDevToolsWindowForWorker(profile, agent_host); | 43 DevToolsWindow::OpenDevToolsWindowForWorker(profile, agent_host); |
37 return; | 44 return; |
38 } | 45 } |
39 if (type == content::DevToolsAgentHost::TYPE_WEB_CONTENTS) { | 46 content::WebContents* web_contents = agent_host->GetWebContents(); |
40 content::WebContents* web_contents = agent_host->GetWebContents(); | 47 if (web_contents) |
41 DCHECK(web_contents); | |
42 DevToolsWindow::OpenDevToolsWindow(web_contents); | 48 DevToolsWindow::OpenDevToolsWindow(web_contents); |
43 } | |
44 #endif // !defined(OS_ANDROID) | 49 #endif // !defined(OS_ANDROID) |
45 } | 50 } |
46 | 51 |
47 base::DictionaryValue* ChromeDevToolsManagerDelegate::HandleCommand( | 52 base::DictionaryValue* ChromeDevToolsManagerDelegate::HandleCommand( |
48 content::DevToolsAgentHost* agent_host, | 53 content::DevToolsAgentHost* agent_host, |
49 base::DictionaryValue* command_dict) { | 54 base::DictionaryValue* command_dict) { |
50 std::unique_ptr<base::DictionaryValue> result = | 55 std::unique_ptr<base::DictionaryValue> result = |
51 DevToolsDiscoveryManager::GetInstance()->HandleCreateTargetCommand( | 56 DevToolsDiscoveryManager::GetInstance()->HandleCreateTargetCommand( |
52 command_dict); | 57 command_dict); |
53 if (result) | 58 if (result) |
54 return result.release(); // Caller takes ownership. | 59 return result.release(); // Caller takes ownership. |
55 return network_protocol_handler_->HandleCommand(agent_host, command_dict); | 60 return network_protocol_handler_->HandleCommand(agent_host, command_dict); |
56 } | 61 } |
57 | 62 |
63 std::string ChromeDevToolsManagerDelegate::GetTargetType( | |
64 content::RenderFrameHost* host) { | |
65 #if !defined(OS_ANDROID) | |
66 content::WebContents* web_contents = | |
67 content::WebContents::FromRenderFrameHost(host); | |
68 for (TabContentsIterator it; !it.done(); it.Next()) { | |
69 if (*it == web_contents) | |
70 return content::DevToolsAgentHost::kTypePage; | |
71 } | |
72 | |
73 if (host->GetParent()) | |
74 return content::DevToolsAgentHost::kTypeFrame; | |
75 | |
76 const extensions::Extension* extension = extensions::ExtensionRegistry::Get( | |
77 web_contents->GetBrowserContext())->enabled_extensions().GetByID( | |
78 host->GetLastCommittedURL().host()); | |
79 if (!extension) | |
80 return content::DevToolsAgentHost::kTypeOther; | |
81 | |
82 Profile* profile = | |
83 Profile::FromBrowserContext(web_contents->GetBrowserContext()); | |
84 if (!profile) | |
85 return content::DevToolsAgentHost::kTypeOther; | |
86 | |
87 extensions::ExtensionHost* extension_host = | |
88 extensions::ProcessManager::Get(profile) | |
89 ->GetBackgroundHostForExtension(extension->id()); | |
90 if (extension_host && | |
91 extension_host->host_contents() == web_contents) { | |
92 return "background_page"; | |
dgozman
2016/08/22 23:09:07
Let's expose these in the header.
| |
93 } else if (extension->is_hosted_app() | |
94 || extension->is_legacy_packaged_app() | |
95 || extension->is_platform_app()) { | |
96 return "app"; | |
97 } | |
98 #endif // !defined(OS_ANDROID) | |
99 return content::DevToolsAgentHost::kTypeOther; | |
dgozman
2016/08/22 23:09:07
Always other for android.
| |
100 } | |
101 | |
58 void ChromeDevToolsManagerDelegate::DevToolsAgentStateChanged( | 102 void ChromeDevToolsManagerDelegate::DevToolsAgentStateChanged( |
59 content::DevToolsAgentHost* agent_host, | 103 content::DevToolsAgentHost* agent_host, |
60 bool attached) { | 104 bool attached) { |
61 network_protocol_handler_->DevToolsAgentStateChanged(agent_host, attached); | 105 network_protocol_handler_->DevToolsAgentStateChanged(agent_host, attached); |
62 } | 106 } |
OLD | NEW |