| 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(), |
| 105 BrowserList::GetInstance(host_desktop_type_); | 106 url, content::PAGE_TRANSITION_AUTO_TOPLEVEL); |
| 106 WebContents* web_contents; | 107 params.disposition = NEW_FOREGROUND_TAB; |
| 107 if (browser_list->empty()) { | 108 chrome::Navigate(¶ms); |
| 108 chrome::NewEmptyWindow(ProfileManager::GetLastUsedProfile(), | 109 if (!params.target_contents) |
| 109 host_desktop_type_); | 110 return scoped_ptr<DevToolsTarget>(); |
| 110 if (browser_list->empty()) | 111 content::RenderViewHost* rvh = params.target_contents->GetRenderViewHost(); |
| 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) | 112 if (!rvh) |
| 124 return scoped_ptr<DevToolsTarget>(); | 113 return scoped_ptr<DevToolsTarget>(); |
| 125 return scoped_ptr<DevToolsTarget>( | 114 return scoped_ptr<DevToolsTarget>( |
| 126 DevToolsTargetImpl::CreateForRenderViewHost(rvh, true)); | 115 DevToolsTargetImpl::CreateForRenderViewHost(rvh, true)); |
| 127 } | 116 } |
| 128 | 117 |
| 129 void BrowserListTabContentsProvider::EnumerateTargets(TargetCallback callback) { | 118 void BrowserListTabContentsProvider::EnumerateTargets(TargetCallback callback) { |
| 130 DevToolsTargetImpl::EnumerateAllTargets( | 119 DevToolsTargetImpl::EnumerateAllTargets( |
| 131 *reinterpret_cast<DevToolsTargetImpl::Callback*>(&callback)); | 120 *reinterpret_cast<DevToolsTargetImpl::Callback*>(&callback)); |
| 132 } | 121 } |
| 133 | 122 |
| 134 scoped_ptr<net::StreamListenSocket> | 123 scoped_ptr<net::StreamListenSocket> |
| 135 BrowserListTabContentsProvider::CreateSocketForTethering( | 124 BrowserListTabContentsProvider::CreateSocketForTethering( |
| 136 net::StreamListenSocket::Delegate* delegate, | 125 net::StreamListenSocket::Delegate* delegate, |
| 137 std::string* name) { | 126 std::string* name) { |
| 138 if (!g_tethering_enabled.Get()) | 127 if (!g_tethering_enabled.Get()) |
| 139 return scoped_ptr<net::StreamListenSocket>(); | 128 return scoped_ptr<net::StreamListenSocket>(); |
| 140 | 129 |
| 141 if (last_tethering_port_ == kMaxTetheringPort) | 130 if (last_tethering_port_ == kMaxTetheringPort) |
| 142 last_tethering_port_ = kMinTetheringPort; | 131 last_tethering_port_ = kMinTetheringPort; |
| 143 int port = ++last_tethering_port_; | 132 int port = ++last_tethering_port_; |
| 144 *name = base::IntToString(port); | 133 *name = base::IntToString(port); |
| 145 return net::TCPListenSocket::CreateAndListen("127.0.0.1", port, delegate) | 134 return net::TCPListenSocket::CreateAndListen("127.0.0.1", port, delegate) |
| 146 .PassAs<net::StreamListenSocket>(); | 135 .PassAs<net::StreamListenSocket>(); |
| 147 } | 136 } |
| OLD | NEW |