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/basictypes.h" | 7 #include "base/basictypes.h" |
8 #include "base/bind.h" | 8 #include "base/bind.h" |
9 #include "base/compiler_specific.h" | 9 #include "base/compiler_specific.h" |
10 #include "base/strings/string_number_conversions.h" | 10 #include "base/strings/string_number_conversions.h" |
11 #include "base/strings/utf_string_conversions.h" | 11 #include "base/strings/utf_string_conversions.h" |
12 #include "chrome/browser/android/tab_android.h" | 12 #include "chrome/browser/android/tab_android.h" |
13 #include "chrome/browser/browser_process.h" | 13 #include "chrome/browser/browser_process.h" |
14 #include "chrome/browser/ui/android/tab_model/tab_model.h" | 14 #include "chrome/browser/ui/android/tab_model/tab_model.h" |
15 #include "chrome/browser/ui/android/tab_model/tab_model_list.h" | 15 #include "chrome/browser/ui/android/tab_model/tab_model_list.h" |
16 #include "components/devtools_discovery/basic_target_descriptor.h" | 16 #include "components/devtools_discovery/basic_target_descriptor.h" |
17 #include "components/devtools_discovery/devtools_discovery_manager.h" | 17 #include "components/devtools_discovery/devtools_discovery_manager.h" |
18 #include "content/public/browser/devtools_agent_host.h" | 18 #include "content/public/browser/devtools_agent_host.h" |
19 #include "content/public/browser/favicon_status.h" | 19 #include "content/public/browser/favicon_status.h" |
20 #include "content/public/browser/navigation_entry.h" | 20 #include "content/public/browser/navigation_entry.h" |
21 #include "content/public/browser/web_contents.h" | 21 #include "content/public/browser/web_contents.h" |
22 | 22 |
23 using content::DevToolsAgentHost; | 23 using content::DevToolsAgentHost; |
24 using content::WebContents; | 24 using content::WebContents; |
25 | 25 |
26 namespace { | 26 namespace { |
27 | 27 |
28 GURL GetFaviconURLForContents(WebContents* web_contents) { | |
29 content::NavigationController& controller = web_contents->GetController(); | |
30 content::NavigationEntry* entry = controller.GetActiveEntry(); | |
31 if (entry != NULL && entry->GetURL().is_valid()) | |
32 return entry->GetFavicon().url; | |
33 return GURL(); | |
34 } | |
35 | |
36 class TabDescriptor : public devtools_discovery::DevToolsTargetDescriptor { | 28 class TabDescriptor : public devtools_discovery::DevToolsTargetDescriptor { |
37 public: | 29 public: |
38 static TabDescriptor* CreateForWebContents(int tab_id, | 30 static TabDescriptor* CreateForWebContents(int tab_id, |
39 WebContents* web_contents) { | 31 WebContents* web_contents) { |
40 return new TabDescriptor(tab_id, web_contents); | 32 return new TabDescriptor(tab_id, web_contents); |
41 } | 33 } |
42 | 34 |
43 static TabDescriptor* CreateForUnloadedTab(int tab_id, | 35 static TabDescriptor* CreateForUnloadedTab(int tab_id, |
44 const base::string16& title, | 36 const base::string16& title, |
45 const GURL& url) { | 37 const GURL& url) { |
(...skipping 85 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
131 return false; | 123 return false; |
132 model->CloseTabAt(index); | 124 model->CloseTabAt(index); |
133 return true; | 125 return true; |
134 } | 126 } |
135 | 127 |
136 private: | 128 private: |
137 TabDescriptor(int tab_id, WebContents* web_contents) | 129 TabDescriptor(int tab_id, WebContents* web_contents) |
138 : tab_id_(tab_id), | 130 : tab_id_(tab_id), |
139 title_(base::UTF16ToUTF8(web_contents->GetTitle())), | 131 title_(base::UTF16ToUTF8(web_contents->GetTitle())), |
140 url_(web_contents->GetURL()), | 132 url_(web_contents->GetURL()), |
141 favicon_url_(GetFaviconURLForContents(web_contents)), | 133 favicon_url_(GetFaviconURL()), |
142 last_activity_time_(web_contents->GetLastActiveTime()) { | 134 last_activity_time_(web_contents->GetLastActiveTime()) { |
143 } | 135 } |
144 | 136 |
145 TabDescriptor(int tab_id, const base::string16& title, const GURL& url) | 137 TabDescriptor(int tab_id, const base::string16& title, const GURL& url) |
146 : tab_id_(tab_id), | 138 : tab_id_(tab_id), |
147 title_(base::UTF16ToUTF8(title)), | 139 title_(base::UTF16ToUTF8(title)), |
148 url_(url) { | 140 url_(url), |
141 favicon_url_(GetFaviconURL()) { | |
142 } | |
143 | |
144 GURL GetFaviconURL() { | |
dgozman
2015/05/08 11:37:03
There is a method with the same name in this class
vkuzkokov
2015/05/12 12:16:46
Was there? It's getFaviconBitmap now.
| |
145 TabModel* model; | |
146 int index; | |
147 if (FindTab(&model, &index)) { | |
148 if (TabAndroid* tab = model->GetTabAt(index)) | |
149 return tab->GetFaviconURL(); | |
150 } | |
151 return GURL(); | |
149 } | 152 } |
150 | 153 |
151 bool FindTab(TabModel** model_result, int* index_result) const { | 154 bool FindTab(TabModel** model_result, int* index_result) const { |
152 for (TabModelList::const_iterator iter = TabModelList::begin(); | 155 for (TabModelList::const_iterator iter = TabModelList::begin(); |
153 iter != TabModelList::end(); ++iter) { | 156 iter != TabModelList::end(); ++iter) { |
154 TabModel* model = *iter; | 157 TabModel* model = *iter; |
155 for (int i = 0; i < model->GetTabCount(); ++i) { | 158 for (int i = 0; i < model->GetTabCount(); ++i) { |
156 TabAndroid* tab = model->GetTabAt(i); | 159 TabAndroid* tab = model->GetTabAt(i); |
157 if (tab && tab->GetAndroidId() == tab_id_) { | 160 if (tab && tab->GetAndroidId() == tab_id_) { |
158 *model_result = model; | 161 *model_result = model; |
(...skipping 84 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
243 } | 246 } |
244 | 247 |
245 // static | 248 // static |
246 void DevToolsDiscoveryProviderAndroid::Install() { | 249 void DevToolsDiscoveryProviderAndroid::Install() { |
247 devtools_discovery::DevToolsDiscoveryManager* discovery_manager = | 250 devtools_discovery::DevToolsDiscoveryManager* discovery_manager = |
248 devtools_discovery::DevToolsDiscoveryManager::GetInstance(); | 251 devtools_discovery::DevToolsDiscoveryManager::GetInstance(); |
249 discovery_manager->AddProvider( | 252 discovery_manager->AddProvider( |
250 make_scoped_ptr(new DevToolsDiscoveryProviderAndroid())); | 253 make_scoped_ptr(new DevToolsDiscoveryProviderAndroid())); |
251 discovery_manager->SetCreateCallback(base::Bind(&CreateNewAndroidTab)); | 254 discovery_manager->SetCreateCallback(base::Bind(&CreateNewAndroidTab)); |
252 } | 255 } |
OLD | NEW |