OLD | NEW |
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 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/browser_list_tabcontents_provider.h" | 5 #include "chrome/browser/devtools/browser_list_tabcontents_provider.h" |
6 | 6 |
7 #include "base/path_service.h" | 7 #include "base/path_service.h" |
8 #include "base/strings/string_number_conversions.h" | 8 #include "base/strings/string_number_conversions.h" |
9 #include "chrome/browser/devtools/devtools_target_impl.h" | |
10 #include "chrome/browser/history/top_sites.h" | 9 #include "chrome/browser/history/top_sites.h" |
11 #include "chrome/browser/profiles/profile_manager.h" | 10 #include "chrome/browser/profiles/profile.h" |
12 #include "chrome/browser/ui/browser.h" | 11 #include "chrome/browser/ui/browser.h" |
13 #include "chrome/browser/ui/browser_commands.h" | |
14 #include "chrome/browser/ui/browser_iterator.h" | 12 #include "chrome/browser/ui/browser_iterator.h" |
15 #include "chrome/browser/ui/browser_list.h" | |
16 #include "chrome/browser/ui/browser_navigator.h" | |
17 #include "chrome/browser/ui/browser_tabstrip.h" | |
18 #include "chrome/browser/ui/host_desktop.h" | 13 #include "chrome/browser/ui/host_desktop.h" |
19 #include "chrome/browser/ui/tabs/tab_strip_model.h" | |
20 #include "chrome/common/chrome_paths.h" | 14 #include "chrome/common/chrome_paths.h" |
21 #include "content/public/browser/web_contents.h" | |
22 #include "content/public/common/url_constants.h" | 15 #include "content/public/common/url_constants.h" |
23 #include "grit/browser_resources.h" | 16 #include "grit/browser_resources.h" |
24 #include "net/socket/tcp_listen_socket.h" | 17 #include "net/socket/tcp_listen_socket.h" |
25 #include "net/url_request/url_request_context_getter.h" | 18 #include "net/url_request/url_request_context_getter.h" |
26 #include "ui/base/resource/resource_bundle.h" | 19 #include "ui/base/resource/resource_bundle.h" |
27 | 20 |
28 using content::DevToolsTarget; | |
29 using content::RenderViewHost; | |
30 using content::WebContents; | |
31 | |
32 namespace { | 21 namespace { |
33 | 22 |
34 const int kMinTetheringPort = 9333; | 23 const int kMinTetheringPort = 9333; |
35 const int kMaxTetheringPort = 9444; | 24 const int kMaxTetheringPort = 9444; |
36 | 25 |
37 base::LazyInstance<bool>::Leaky g_tethering_enabled = LAZY_INSTANCE_INITIALIZER; | 26 base::LazyInstance<bool>::Leaky g_tethering_enabled = LAZY_INSTANCE_INITIALIZER; |
38 | 27 |
39 } | 28 } |
40 | 29 |
41 // static | 30 // static |
(...skipping 36 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
78 base::FilePath BrowserListTabContentsProvider::GetDebugFrontendDir() { | 67 base::FilePath BrowserListTabContentsProvider::GetDebugFrontendDir() { |
79 #if defined(DEBUG_DEVTOOLS) | 68 #if defined(DEBUG_DEVTOOLS) |
80 base::FilePath inspector_dir; | 69 base::FilePath inspector_dir; |
81 PathService::Get(chrome::DIR_INSPECTOR, &inspector_dir); | 70 PathService::Get(chrome::DIR_INSPECTOR, &inspector_dir); |
82 return inspector_dir; | 71 return inspector_dir; |
83 #else | 72 #else |
84 return base::FilePath(); | 73 return base::FilePath(); |
85 #endif | 74 #endif |
86 } | 75 } |
87 | 76 |
88 std::string BrowserListTabContentsProvider::GetPageThumbnailData( | |
89 const GURL& url) { | |
90 for (chrome::BrowserIterator it; !it.done(); it.Next()) { | |
91 Profile* profile = (*it)->profile(); | |
92 history::TopSites* top_sites = profile->GetTopSites(); | |
93 if (!top_sites) | |
94 continue; | |
95 scoped_refptr<base::RefCountedMemory> data; | |
96 if (top_sites->GetPageThumbnail(url, false, &data)) | |
97 return std::string(data->front_as<char>(), data->size()); | |
98 } | |
99 | |
100 return std::string(); | |
101 } | |
102 | |
103 scoped_ptr<DevToolsTarget> | |
104 BrowserListTabContentsProvider::CreateNewTarget(const GURL& url) { | |
105 chrome::NavigateParams params(ProfileManager::GetLastUsedProfile(), | |
106 url, ui::PAGE_TRANSITION_AUTO_TOPLEVEL); | |
107 params.disposition = NEW_FOREGROUND_TAB; | |
108 chrome::Navigate(¶ms); | |
109 if (!params.target_contents) | |
110 return scoped_ptr<DevToolsTarget>(); | |
111 return scoped_ptr<DevToolsTarget>( | |
112 DevToolsTargetImpl::CreateForWebContents(params.target_contents, true)); | |
113 } | |
114 | |
115 void BrowserListTabContentsProvider::EnumerateTargets(TargetCallback callback) { | |
116 DevToolsTargetImpl::EnumerateAllTargets( | |
117 *reinterpret_cast<DevToolsTargetImpl::Callback*>(&callback)); | |
118 } | |
119 | |
120 scoped_ptr<net::StreamListenSocket> | 77 scoped_ptr<net::StreamListenSocket> |
121 BrowserListTabContentsProvider::CreateSocketForTethering( | 78 BrowserListTabContentsProvider::CreateSocketForTethering( |
122 net::StreamListenSocket::Delegate* delegate, | 79 net::StreamListenSocket::Delegate* delegate, |
123 std::string* name) { | 80 std::string* name) { |
124 if (!g_tethering_enabled.Get()) | 81 if (!g_tethering_enabled.Get()) |
125 return scoped_ptr<net::StreamListenSocket>(); | 82 return scoped_ptr<net::StreamListenSocket>(); |
126 | 83 |
127 if (last_tethering_port_ == kMaxTetheringPort) | 84 if (last_tethering_port_ == kMaxTetheringPort) |
128 last_tethering_port_ = kMinTetheringPort; | 85 last_tethering_port_ = kMinTetheringPort; |
129 int port = ++last_tethering_port_; | 86 int port = ++last_tethering_port_; |
130 *name = base::IntToString(port); | 87 *name = base::IntToString(port); |
131 return net::TCPListenSocket::CreateAndListen("127.0.0.1", port, delegate) | 88 return net::TCPListenSocket::CreateAndListen("127.0.0.1", port, delegate) |
132 .PassAs<net::StreamListenSocket>(); | 89 .PassAs<net::StreamListenSocket>(); |
133 } | 90 } |
OLD | NEW |