Chromium Code Reviews| 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 #include "base/values.h" |
| 8 #include "chrome/browser/devtools/devtools_target_impl.h" | |
| 8 #include "chrome/browser/devtools/devtools_window.h" | 9 #include "chrome/browser/devtools/devtools_window.h" |
| 10 #include "chrome/browser/history/top_sites.h" | |
| 9 #include "chrome/browser/profiles/profile.h" | 11 #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 "content/public/browser/browser_thread.h" | |
| 10 #include "content/public/browser/devtools_agent_host.h" | 16 #include "content/public/browser/devtools_agent_host.h" |
| 17 #include "content/public/browser/web_contents.h" | |
| 11 | 18 |
| 12 ChromeDevToolsManagerDelegate::ChromeDevToolsManagerDelegate() | 19 ChromeDevToolsManagerDelegate::ChromeDevToolsManagerDelegate() |
| 13 : network_protocol_handler_(new DevToolsNetworkProtocolHandler()) { | 20 : network_protocol_handler_(new DevToolsNetworkProtocolHandler()) { |
| 14 } | 21 } |
| 15 | 22 |
| 16 ChromeDevToolsManagerDelegate::~ChromeDevToolsManagerDelegate() { | 23 ChromeDevToolsManagerDelegate::~ChromeDevToolsManagerDelegate() { |
| 17 } | 24 } |
| 18 | 25 |
| 19 void ChromeDevToolsManagerDelegate::Inspect( | 26 void ChromeDevToolsManagerDelegate::Inspect( |
| 20 content::BrowserContext* browser_context, | 27 content::BrowserContext* browser_context, |
| 21 content::DevToolsAgentHost* agent_host) { | 28 content::DevToolsAgentHost* agent_host) { |
| 22 if (!agent_host->IsWorker()) { | 29 if (!agent_host->IsWorker()) { |
| 23 // TODO(horo): Support other types of DevToolsAgentHost when necessary. | 30 // TODO(horo): Support other types of DevToolsAgentHost when necessary. |
| 24 NOTREACHED() << "Inspect() only supports workers."; | 31 NOTREACHED() << "Inspect() only supports workers."; |
| 25 } | 32 } |
| 26 #if !defined(OS_ANDROID) | 33 #if !defined(OS_ANDROID) |
|
vkuzkokov
2014/09/16 11:46:40
This #if becomes redundant.
dgozman
2014/09/16 13:23:57
Done.
| |
| 27 if (Profile* profile = Profile::FromBrowserContext(browser_context)) | 34 if (Profile* profile = Profile::FromBrowserContext(browser_context)) |
| 28 DevToolsWindow::OpenDevToolsWindowForWorker(profile, agent_host); | 35 DevToolsWindow::OpenDevToolsWindowForWorker(profile, agent_host); |
| 29 #endif | 36 #endif |
| 30 } | 37 } |
| 31 | 38 |
| 32 base::DictionaryValue* ChromeDevToolsManagerDelegate::HandleCommand( | 39 base::DictionaryValue* ChromeDevToolsManagerDelegate::HandleCommand( |
| 33 content::DevToolsAgentHost* agent_host, | 40 content::DevToolsAgentHost* agent_host, |
| 34 base::DictionaryValue* command_dict) { | 41 base::DictionaryValue* command_dict) { |
| 35 return network_protocol_handler_->HandleCommand(agent_host, command_dict); | 42 return network_protocol_handler_->HandleCommand(agent_host, command_dict); |
| 36 } | 43 } |
| 37 | 44 |
| 38 void ChromeDevToolsManagerDelegate::DevToolsAgentStateChanged( | 45 void ChromeDevToolsManagerDelegate::DevToolsAgentStateChanged( |
| 39 content::DevToolsAgentHost* agent_host, | 46 content::DevToolsAgentHost* agent_host, |
| 40 bool attached) { | 47 bool attached) { |
| 41 network_protocol_handler_->DevToolsAgentStateChanged(agent_host, attached); | 48 network_protocol_handler_->DevToolsAgentStateChanged(agent_host, attached); |
| 42 } | 49 } |
| 50 | |
| 51 std::string ChromeDevToolsManagerDelegate::GetPageThumbnailData( | |
| 52 const GURL& url) { | |
| 53 for (chrome::BrowserIterator it; !it.done(); it.Next()) { | |
| 54 Profile* profile = (*it)->profile(); | |
| 55 history::TopSites* top_sites = profile->GetTopSites(); | |
| 56 if (!top_sites) | |
| 57 continue; | |
| 58 scoped_refptr<base::RefCountedMemory> data; | |
| 59 if (top_sites->GetPageThumbnail(url, false, &data)) | |
| 60 return std::string(data->front_as<char>(), data->size()); | |
| 61 } | |
| 62 return std::string(); | |
| 63 } | |
| 64 | |
| 65 scoped_ptr<content::DevToolsTarget> | |
| 66 ChromeDevToolsManagerDelegate::CreateNewTarget(const GURL& url) { | |
| 67 chrome::NavigateParams params(ProfileManager::GetLastUsedProfile(), | |
| 68 url, content::PAGE_TRANSITION_AUTO_TOPLEVEL); | |
| 69 params.disposition = NEW_FOREGROUND_TAB; | |
| 70 chrome::Navigate(¶ms); | |
| 71 if (!params.target_contents) | |
| 72 return scoped_ptr<content::DevToolsTarget>(); | |
| 73 return scoped_ptr<content::DevToolsTarget>( | |
| 74 DevToolsTargetImpl::CreateForWebContents(params.target_contents, true)); | |
| 75 } | |
| 76 | |
| 77 void ChromeDevToolsManagerDelegate::EnumerateTargets(TargetCallback callback) { | |
| 78 DevToolsTargetImpl::EnumerateAllTargets( | |
| 79 *reinterpret_cast<DevToolsTargetImpl::Callback*>(&callback)); | |
| 80 } | |
| 81 | |
| OLD | NEW |