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" | 9 #include "chrome/browser/devtools/devtools_target_impl.h" |
10 #include "chrome/browser/history/top_sites.h" | 10 #include "chrome/browser/history/top_sites.h" |
11 #include "chrome/browser/profiles/profile_manager.h" | 11 #include "chrome/browser/profiles/profile_manager.h" |
12 #include "chrome/browser/ui/browser.h" | 12 #include "chrome/browser/ui/browser.h" |
13 #include "chrome/browser/ui/browser_commands.h" | 13 #include "chrome/browser/ui/browser_commands.h" |
14 #include "chrome/browser/ui/browser_iterator.h" | 14 #include "chrome/browser/ui/browser_iterator.h" |
15 #include "chrome/browser/ui/browser_list.h" | 15 #include "chrome/browser/ui/browser_list.h" |
16 #include "chrome/browser/ui/browser_navigator.h" | |
16 #include "chrome/browser/ui/browser_tabstrip.h" | 17 #include "chrome/browser/ui/browser_tabstrip.h" |
17 #include "chrome/browser/ui/host_desktop.h" | 18 #include "chrome/browser/ui/host_desktop.h" |
18 #include "chrome/browser/ui/tabs/tab_strip_model.h" | 19 #include "chrome/browser/ui/tabs/tab_strip_model.h" |
19 #include "chrome/common/chrome_paths.h" | 20 #include "chrome/common/chrome_paths.h" |
20 #include "content/public/browser/web_contents.h" | 21 #include "content/public/browser/web_contents.h" |
21 #include "content/public/common/url_constants.h" | 22 #include "content/public/common/url_constants.h" |
22 #include "grit/browser_resources.h" | 23 #include "grit/browser_resources.h" |
23 #include "net/socket/tcp_listen_socket.h" | 24 #include "net/socket/tcp_listen_socket.h" |
24 #include "net/url_request/url_request_context_getter.h" | 25 #include "net/url_request/url_request_context_getter.h" |
25 #include "ui/base/resource/resource_bundle.h" | 26 #include "ui/base/resource/resource_bundle.h" |
(...skipping 68 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
94 scoped_refptr<base::RefCountedMemory> data; | 95 scoped_refptr<base::RefCountedMemory> data; |
95 if (top_sites->GetPageThumbnail(url, false, &data)) | 96 if (top_sites->GetPageThumbnail(url, false, &data)) |
96 return std::string(data->front_as<char>(), data->size()); | 97 return std::string(data->front_as<char>(), data->size()); |
97 } | 98 } |
98 | 99 |
99 return std::string(); | 100 return std::string(); |
100 } | 101 } |
101 | 102 |
102 scoped_ptr<DevToolsTarget> | 103 scoped_ptr<DevToolsTarget> |
103 BrowserListTabContentsProvider::CreateNewTarget(const GURL& url) { | 104 BrowserListTabContentsProvider::CreateNewTarget(const GURL& url) { |
104 const BrowserList* browser_list = | 105 chrome::NavigateParams params(ProfileManager::GetLastUsedProfile(), |
dgozman
2014/08/06 08:21:07
Are you sure this will be a new tab? Let's set
par
vkuzkokov
2014/08/06 08:47:45
I looked up in source. Adding anyway.
| |
105 BrowserList::GetInstance(host_desktop_type_); | 106 url, content::PAGE_TRANSITION_TYPED); |
sky
2014/08/05 17:47:00
Why is this PAGE_TRANSITION_TYPED?
dgozman
2014/08/06 08:21:07
I think this is more like PAGE_TRANSITION_AUTO_TOP
vkuzkokov
2014/08/06 08:47:45
Done.
| |
106 WebContents* web_contents; | 107 Navigate(¶ms); |
dgozman
2014/08/06 08:21:07
nit: chrome::Navigate for better readability.
vkuzkokov
2014/08/06 08:47:45
Done.
| |
107 if (browser_list->empty()) { | 108 if (!params.target_contents) |
108 chrome::NewEmptyWindow(ProfileManager::GetLastUsedProfile(), | 109 return scoped_ptr<DevToolsTarget>(); |
109 host_desktop_type_); | 110 content::RenderViewHost* rvh = params.target_contents->GetRenderViewHost(); |
110 if (browser_list->empty()) | |
111 return scoped_ptr<DevToolsTarget>(); | |
112 web_contents = | |
113 browser_list->get(0)->tab_strip_model()->GetActiveWebContents(); | |
114 web_contents->GetController().LoadURL(url, | |
115 content::Referrer(), content::PAGE_TRANSITION_TYPED, std::string()); | |
116 } else { | |
117 web_contents = chrome::AddSelectedTabWithURL( | |
118 browser_list->get(0), | |
119 url, | |
120 content::PAGE_TRANSITION_LINK); | |
121 } | |
122 content::RenderViewHost* rvh = web_contents->GetRenderViewHost(); | |
123 if (!rvh) | 111 if (!rvh) |
124 return scoped_ptr<DevToolsTarget>(); | 112 return scoped_ptr<DevToolsTarget>(); |
125 return scoped_ptr<DevToolsTarget>( | 113 return scoped_ptr<DevToolsTarget>( |
126 DevToolsTargetImpl::CreateForRenderViewHost(rvh, true)); | 114 DevToolsTargetImpl::CreateForRenderViewHost(rvh, true)); |
127 } | 115 } |
128 | 116 |
129 void BrowserListTabContentsProvider::EnumerateTargets(TargetCallback callback) { | 117 void BrowserListTabContentsProvider::EnumerateTargets(TargetCallback callback) { |
130 DevToolsTargetImpl::EnumerateAllTargets( | 118 DevToolsTargetImpl::EnumerateAllTargets( |
131 *reinterpret_cast<DevToolsTargetImpl::Callback*>(&callback)); | 119 *reinterpret_cast<DevToolsTargetImpl::Callback*>(&callback)); |
132 } | 120 } |
133 | 121 |
134 scoped_ptr<net::StreamListenSocket> | 122 scoped_ptr<net::StreamListenSocket> |
135 BrowserListTabContentsProvider::CreateSocketForTethering( | 123 BrowserListTabContentsProvider::CreateSocketForTethering( |
136 net::StreamListenSocket::Delegate* delegate, | 124 net::StreamListenSocket::Delegate* delegate, |
137 std::string* name) { | 125 std::string* name) { |
138 if (!g_tethering_enabled.Get()) | 126 if (!g_tethering_enabled.Get()) |
139 return scoped_ptr<net::StreamListenSocket>(); | 127 return scoped_ptr<net::StreamListenSocket>(); |
140 | 128 |
141 if (last_tethering_port_ == kMaxTetheringPort) | 129 if (last_tethering_port_ == kMaxTetheringPort) |
142 last_tethering_port_ = kMinTetheringPort; | 130 last_tethering_port_ = kMinTetheringPort; |
143 int port = ++last_tethering_port_; | 131 int port = ++last_tethering_port_; |
144 *name = base::IntToString(port); | 132 *name = base::IntToString(port); |
145 return net::TCPListenSocket::CreateAndListen("127.0.0.1", port, delegate) | 133 return net::TCPListenSocket::CreateAndListen("127.0.0.1", port, delegate) |
146 .PassAs<net::StreamListenSocket>(); | 134 .PassAs<net::StreamListenSocket>(); |
147 } | 135 } |
OLD | NEW |