| 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 "base/values.h" | 7 #if !defined(OS_ANDROID) |
| 8 #include "chrome/browser/devtools/devtools_target_impl.h" | |
| 9 #include "chrome/browser/devtools/devtools_window.h" | 8 #include "chrome/browser/devtools/devtools_window.h" |
| 10 #include "chrome/browser/history/top_sites_factory.h" | |
| 11 #include "chrome/browser/profiles/profile.h" | 9 #include "chrome/browser/profiles/profile.h" |
| 12 #include "chrome/browser/profiles/profile_manager.h" | |
| 13 #include "chrome/browser/ui/browser.h" | |
| 14 #include "chrome/browser/ui/browser_iterator.h" | |
| 15 #include "components/devtools_discovery/devtools_discovery_manager.h" | |
| 16 #include "components/history/core/browser/top_sites.h" | |
| 17 #include "content/public/browser/browser_thread.h" | |
| 18 #include "content/public/browser/devtools_agent_host.h" | 10 #include "content/public/browser/devtools_agent_host.h" |
| 19 #include "content/public/browser/web_contents.h" | 11 #endif // !defined(OS_ANDROID) |
| 20 | 12 |
| 21 ChromeDevToolsManagerDelegate::ChromeDevToolsManagerDelegate() | 13 ChromeDevToolsManagerDelegate::ChromeDevToolsManagerDelegate() |
| 22 : network_protocol_handler_(new DevToolsNetworkProtocolHandler()) { | 14 : network_protocol_handler_(new DevToolsNetworkProtocolHandler()) { |
| 23 } | 15 } |
| 24 | 16 |
| 25 ChromeDevToolsManagerDelegate::~ChromeDevToolsManagerDelegate() { | 17 ChromeDevToolsManagerDelegate::~ChromeDevToolsManagerDelegate() { |
| 26 } | 18 } |
| 27 | 19 |
| 28 void ChromeDevToolsManagerDelegate::Inspect( | 20 void ChromeDevToolsManagerDelegate::Inspect( |
| 29 content::BrowserContext* browser_context, | 21 content::BrowserContext* browser_context, |
| 30 content::DevToolsAgentHost* agent_host) { | 22 content::DevToolsAgentHost* agent_host) { |
| 23 #if !defined(OS_ANDROID) |
| 31 content::DevToolsAgentHost::Type type = agent_host->GetType(); | 24 content::DevToolsAgentHost::Type type = agent_host->GetType(); |
| 32 if (type != content::DevToolsAgentHost::TYPE_SHARED_WORKER && | 25 if (type != content::DevToolsAgentHost::TYPE_SHARED_WORKER && |
| 33 type != content::DevToolsAgentHost::TYPE_SERVICE_WORKER) { | 26 type != content::DevToolsAgentHost::TYPE_SERVICE_WORKER) { |
| 34 // TODO(horo): Support other types of DevToolsAgentHost when necessary. | 27 // TODO(horo): Support other types of DevToolsAgentHost when necessary. |
| 35 NOTREACHED() << "Inspect() only supports workers."; | 28 NOTREACHED() << "Inspect() only supports workers."; |
| 36 } | 29 } |
| 37 if (Profile* profile = Profile::FromBrowserContext(browser_context)) | 30 if (Profile* profile = Profile::FromBrowserContext(browser_context)) |
| 38 DevToolsWindow::OpenDevToolsWindowForWorker(profile, agent_host); | 31 DevToolsWindow::OpenDevToolsWindowForWorker(profile, agent_host); |
| 32 #endif // !defined(OS_ANDROID) |
| 39 } | 33 } |
| 40 | 34 |
| 41 base::DictionaryValue* ChromeDevToolsManagerDelegate::HandleCommand( | 35 base::DictionaryValue* ChromeDevToolsManagerDelegate::HandleCommand( |
| 42 content::DevToolsAgentHost* agent_host, | 36 content::DevToolsAgentHost* agent_host, |
| 43 base::DictionaryValue* command_dict) { | 37 base::DictionaryValue* command_dict) { |
| 44 return network_protocol_handler_->HandleCommand(agent_host, command_dict); | 38 return network_protocol_handler_->HandleCommand(agent_host, command_dict); |
| 45 } | 39 } |
| 46 | 40 |
| 47 void ChromeDevToolsManagerDelegate::DevToolsAgentStateChanged( | 41 void ChromeDevToolsManagerDelegate::DevToolsAgentStateChanged( |
| 48 content::DevToolsAgentHost* agent_host, | 42 content::DevToolsAgentHost* agent_host, |
| 49 bool attached) { | 43 bool attached) { |
| 50 network_protocol_handler_->DevToolsAgentStateChanged(agent_host, attached); | 44 network_protocol_handler_->DevToolsAgentStateChanged(agent_host, attached); |
| 51 } | 45 } |
| 52 | |
| 53 std::string ChromeDevToolsManagerDelegate::GetPageThumbnailData( | |
| 54 const GURL& url) { | |
| 55 for (chrome::BrowserIterator it; !it.done(); it.Next()) { | |
| 56 Profile* profile = (*it)->profile(); | |
| 57 scoped_refptr<history::TopSites> top_sites = | |
| 58 TopSitesFactory::GetForProfile(profile); | |
| 59 if (!top_sites) | |
| 60 continue; | |
| 61 scoped_refptr<base::RefCountedMemory> data; | |
| 62 if (top_sites->GetPageThumbnail(url, false, &data)) | |
| 63 return std::string(data->front_as<char>(), data->size()); | |
| 64 } | |
| 65 return std::string(); | |
| 66 } | |
| 67 | |
| 68 scoped_ptr<content::DevToolsTarget> | |
| 69 ChromeDevToolsManagerDelegate::CreateNewTarget(const GURL& url) { | |
| 70 return devtools_discovery::DevToolsDiscoveryManager::GetInstance()-> | |
| 71 CreateNew(url); | |
| 72 } | |
| 73 | |
| 74 void ChromeDevToolsManagerDelegate::EnumerateTargets(TargetCallback callback) { | |
| 75 TargetList targets; | |
| 76 devtools_discovery::DevToolsDiscoveryManager* discovery_manager = | |
| 77 devtools_discovery::DevToolsDiscoveryManager::GetInstance(); | |
| 78 for (const auto& descriptor : discovery_manager->GetDescriptors()) | |
| 79 targets.push_back(descriptor); | |
| 80 callback.Run(targets); | |
| 81 } | |
| 82 | |
| OLD | NEW |