OLD | NEW |
---|---|
1 // Copyright 2015 The Chromium Authors. All rights reserved. | 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 | 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/android/dev_tools_discovery_provider_android.h" | 5 #include "chrome/browser/android/dev_tools_discovery_provider_android.h" |
6 | 6 |
7 #include "base/bind.h" | 7 #include "base/bind.h" |
8 #include "base/compiler_specific.h" | 8 #include "base/compiler_specific.h" |
9 #include "base/macros.h" | 9 #include "base/macros.h" |
10 #include "base/memory/ptr_util.h" | 10 #include "base/memory/ptr_util.h" |
11 #include "base/strings/string_number_conversions.h" | 11 #include "base/strings/string_number_conversions.h" |
12 #include "base/strings/utf_string_conversions.h" | 12 #include "base/strings/utf_string_conversions.h" |
13 #include "chrome/browser/android/tab_android.h" | 13 #include "chrome/browser/android/tab_android.h" |
14 #include "chrome/browser/browser_process.h" | 14 #include "chrome/browser/browser_process.h" |
15 #include "chrome/browser/ui/android/tab_model/tab_model.h" | 15 #include "chrome/browser/ui/android/tab_model/tab_model.h" |
16 #include "chrome/browser/ui/android/tab_model/tab_model_list.h" | 16 #include "chrome/browser/ui/android/tab_model/tab_model_list.h" |
17 #include "components/devtools_discovery/devtools_discovery_manager.h" | |
18 #include "content/public/browser/devtools_agent_host.h" | 17 #include "content/public/browser/devtools_agent_host.h" |
19 #include "content/public/browser/devtools_agent_host_client.h" | 18 #include "content/public/browser/devtools_agent_host_client.h" |
20 #include "content/public/browser/devtools_external_agent_proxy.h" | 19 #include "content/public/browser/devtools_external_agent_proxy.h" |
21 #include "content/public/browser/devtools_external_agent_proxy_delegate.h" | 20 #include "content/public/browser/devtools_external_agent_proxy_delegate.h" |
22 #include "content/public/browser/favicon_status.h" | 21 #include "content/public/browser/favicon_status.h" |
23 #include "content/public/browser/navigation_entry.h" | 22 #include "content/public/browser/navigation_entry.h" |
24 #include "content/public/browser/web_contents.h" | 23 #include "content/public/browser/web_contents.h" |
25 | 24 |
26 using content::DevToolsAgentHost; | 25 using content::DevToolsAgentHost; |
27 using content::WebContents; | 26 using content::WebContents; |
(...skipping 121 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
149 } | 148 } |
150 | 149 |
151 const int tab_id_; | 150 const int tab_id_; |
152 const std::string title_; | 151 const std::string title_; |
153 const GURL url_; | 152 const GURL url_; |
154 scoped_refptr<content::DevToolsAgentHost> agent_host_; | 153 scoped_refptr<content::DevToolsAgentHost> agent_host_; |
155 content::DevToolsExternalAgentProxy* proxy_; | 154 content::DevToolsExternalAgentProxy* proxy_; |
156 DISALLOW_COPY_AND_ASSIGN(TabProxyDelegate); | 155 DISALLOW_COPY_AND_ASSIGN(TabProxyDelegate); |
157 }; | 156 }; |
158 | 157 |
159 scoped_refptr<content::DevToolsAgentHost> CreateNewAndroidTab(const GURL& url) { | 158 content::DevToolsAgentHost::List GetDescriptors() { |
160 if (TabModelList::empty()) | |
161 return nullptr; | |
162 | |
163 TabModel* tab_model = TabModelList::get(0); | |
164 if (!tab_model) | |
165 return nullptr; | |
166 | |
167 WebContents* web_contents = tab_model->CreateNewTabForDevTools(url); | |
168 if (!web_contents) | |
169 return nullptr; | |
170 | |
171 TabAndroid* tab = TabAndroid::FromWebContents(web_contents); | |
172 if (!tab) | |
173 return nullptr; | |
174 | |
175 return content::DevToolsAgentHost::Create(new TabProxyDelegate( | |
176 tab->GetAndroidId(), tab->GetTitle(), tab->GetURL())); | |
177 } | |
178 | |
179 } // namespace | |
180 | |
181 DevToolsDiscoveryProviderAndroid::DevToolsDiscoveryProviderAndroid() { | |
182 } | |
183 | |
184 DevToolsDiscoveryProviderAndroid::~DevToolsDiscoveryProviderAndroid() { | |
185 } | |
186 | |
187 content::DevToolsAgentHost::List | |
188 DevToolsDiscoveryProviderAndroid::GetDescriptors() { | |
189 content::DevToolsAgentHost::List result; | 159 content::DevToolsAgentHost::List result; |
190 | 160 |
191 // Enumerate existing tabs, including the ones with no WebContents. | 161 // Enumerate existing tabs, including the ones with no WebContents. |
192 std::set<WebContents*> tab_web_contents; | 162 std::set<WebContents*> tab_web_contents; |
193 for (TabModelList::const_iterator iter = TabModelList::begin(); | 163 for (TabModelList::const_iterator iter = TabModelList::begin(); |
194 iter != TabModelList::end(); ++iter) { | 164 iter != TabModelList::end(); ++iter) { |
195 TabModel* model = *iter; | 165 TabModel* model = *iter; |
196 for (int i = 0; i < model->GetTabCount(); ++i) { | 166 for (int i = 0; i < model->GetTabCount(); ++i) { |
197 TabAndroid* tab = model->GetTabAt(i); | 167 TabAndroid* tab = model->GetTabAt(i); |
198 if (!tab) | 168 if (!tab) |
(...skipping 20 matching lines...) Expand all Loading... | |
219 if (WebContents* web_contents = (*it)->GetWebContents()) { | 189 if (WebContents* web_contents = (*it)->GetWebContents()) { |
220 if (tab_web_contents.find(web_contents) != tab_web_contents.end()) | 190 if (tab_web_contents.find(web_contents) != tab_web_contents.end()) |
221 continue; | 191 continue; |
222 } | 192 } |
223 result.push_back(*it); | 193 result.push_back(*it); |
224 } | 194 } |
225 | 195 |
226 return result; | 196 return result; |
227 } | 197 } |
228 | 198 |
199 } // namespace | |
200 | |
201 DevToolsDiscoveryProviderAndroid::DevToolsDiscoveryProviderAndroid() { | |
202 } | |
203 | |
204 DevToolsDiscoveryProviderAndroid::~DevToolsDiscoveryProviderAndroid() { | |
205 } | |
206 | |
229 // static | 207 // static |
230 void DevToolsDiscoveryProviderAndroid::Install() { | 208 void DevToolsDiscoveryProviderAndroid::Install() { |
231 devtools_discovery::DevToolsDiscoveryManager* discovery_manager = | 209 scoped_refptr<DevToolsDiscoveryProviderAndroid> provider = |
232 devtools_discovery::DevToolsDiscoveryManager::GetInstance(); | 210 new DevToolsDiscoveryProviderAndroid(); |
dgozman
2016/08/25 01:08:11
style: 4 spaces
| |
233 discovery_manager->AddProvider( | 211 content::DevtoolsAgentHost::AddProvider(base::Bind(&GetDescriptors)); |
234 base::WrapUnique(new DevToolsDiscoveryProviderAndroid())); | |
235 discovery_manager->SetCreateCallback(base::Bind(&CreateNewAndroidTab)); | |
236 } | 212 } |
OLD | NEW |