[Presentation API, Android] Implement basic messaging
[chromium-blink-merge.git] / chrome / browser / devtools / chrome_devtools_discovery_provider.cc
blob530405d0da42e97c81b34e1ad7ebf1a920278afb
1 // Copyright 2015 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_discovery_provider.h"
7 #include "chrome/browser/devtools/devtools_target_impl.h"
8 #include "chrome/browser/profiles/profile_manager.h"
9 #include "chrome/browser/ui/browser_navigator.h"
11 namespace {
13 scoped_ptr<devtools_discovery::DevToolsTargetDescriptor>
14 CreateNewChromeTab(const GURL& url) {
15 chrome::NavigateParams params(ProfileManager::GetLastUsedProfile(),
16 url, ui::PAGE_TRANSITION_AUTO_TOPLEVEL);
17 params.disposition = NEW_FOREGROUND_TAB;
18 chrome::Navigate(&params);
19 if (!params.target_contents)
20 return scoped_ptr<devtools_discovery::DevToolsTargetDescriptor>();
21 return DevToolsTargetImpl::CreateForTab(params.target_contents).Pass();
24 } // namespace
26 ChromeDevToolsDiscoveryProvider::ChromeDevToolsDiscoveryProvider() {
29 ChromeDevToolsDiscoveryProvider::~ChromeDevToolsDiscoveryProvider() {
32 devtools_discovery::DevToolsTargetDescriptor::List
33 ChromeDevToolsDiscoveryProvider::GetDescriptors() {
34 std::vector<DevToolsTargetImpl*> list = DevToolsTargetImpl::EnumerateAll();
35 devtools_discovery::DevToolsTargetDescriptor::List result;
36 result.reserve(list.size());
37 for (const auto& descriptor : list)
38 result.push_back(descriptor);
39 return result;
42 // static
43 void ChromeDevToolsDiscoveryProvider::Install() {
44 devtools_discovery::DevToolsDiscoveryManager* discovery_manager =
45 devtools_discovery::DevToolsDiscoveryManager::GetInstance();
46 discovery_manager->AddProvider(
47 make_scoped_ptr(new ChromeDevToolsDiscoveryProvider()));
48 discovery_manager->SetCreateCallback(base::Bind(&CreateNewChromeTab));