Revert of Add button to add new FSP services to Files app. (patchset #8 id:140001...
[chromium-blink-merge.git] / chrome / browser / devtools / chrome_devtools_manager_delegate.cc
blob1529f26c15cbde18ff57d04c905e750a9ea19d62
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
3 // found in the LICENSE file.
5 #include "chrome/browser/devtools/chrome_devtools_manager_delegate.h"
7 #include "base/values.h"
8 #include "chrome/browser/devtools/devtools_target_impl.h"
9 #include "chrome/browser/devtools/devtools_window.h"
10 #include "chrome/browser/history/top_sites_factory.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 "components/history/core/browser/top_sites.h"
16 #include "content/public/browser/browser_thread.h"
17 #include "content/public/browser/devtools_agent_host.h"
18 #include "content/public/browser/web_contents.h"
20 ChromeDevToolsManagerDelegate::ChromeDevToolsManagerDelegate()
21 : network_protocol_handler_(new DevToolsNetworkProtocolHandler()) {
24 ChromeDevToolsManagerDelegate::~ChromeDevToolsManagerDelegate() {
27 void ChromeDevToolsManagerDelegate::Inspect(
28 content::BrowserContext* browser_context,
29 content::DevToolsAgentHost* agent_host) {
30 if (!agent_host->IsWorker()) {
31 // TODO(horo): Support other types of DevToolsAgentHost when necessary.
32 NOTREACHED() << "Inspect() only supports workers.";
34 if (Profile* profile = Profile::FromBrowserContext(browser_context))
35 DevToolsWindow::OpenDevToolsWindowForWorker(profile, agent_host);
38 base::DictionaryValue* ChromeDevToolsManagerDelegate::HandleCommand(
39 content::DevToolsAgentHost* agent_host,
40 base::DictionaryValue* command_dict) {
41 return network_protocol_handler_->HandleCommand(agent_host, command_dict);
44 void ChromeDevToolsManagerDelegate::DevToolsAgentStateChanged(
45 content::DevToolsAgentHost* agent_host,
46 bool attached) {
47 network_protocol_handler_->DevToolsAgentStateChanged(agent_host, attached);
50 std::string ChromeDevToolsManagerDelegate::GetPageThumbnailData(
51 const GURL& url) {
52 for (chrome::BrowserIterator it; !it.done(); it.Next()) {
53 Profile* profile = (*it)->profile();
54 scoped_refptr<history::TopSites> top_sites =
55 TopSitesFactory::GetForProfile(profile);
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());
62 return std::string();
65 scoped_ptr<content::DevToolsTarget>
66 ChromeDevToolsManagerDelegate::CreateNewTarget(const GURL& url) {
67 chrome::NavigateParams params(ProfileManager::GetLastUsedProfile(),
68 url, ui::PAGE_TRANSITION_AUTO_TOPLEVEL);
69 params.disposition = NEW_FOREGROUND_TAB;
70 chrome::Navigate(&params);
71 if (!params.target_contents)
72 return scoped_ptr<content::DevToolsTarget>();
73 return scoped_ptr<content::DevToolsTarget>(
74 DevToolsTargetImpl::CreateForWebContents(params.target_contents, true));
77 void ChromeDevToolsManagerDelegate::EnumerateTargets(TargetCallback callback) {
78 DevToolsTargetImpl::EnumerateAllTargets(
79 *reinterpret_cast<DevToolsTargetImpl::Callback*>(&callback));