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"
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(¶ms
);
19 if (!params
.target_contents
)
20 return scoped_ptr
<devtools_discovery::DevToolsTargetDescriptor
>();
21 return DevToolsTargetImpl::CreateForTab(params
.target_contents
).Pass();
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
);
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
));