OLD | NEW |
---|---|
1 // Copyright 2013 The Chromium Authors. All rights reserved. | 1 // Copyright 2013 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/media/desktop_media_list_ash.h" | 5 #include "chrome/browser/media/desktop_media_list_ash.h" |
6 | 6 |
7 #include <stddef.h> | 7 #include <stddef.h> |
8 | 8 |
9 #include <set> | 9 #include <set> |
10 | 10 |
11 #include "ash/shell.h" | 11 #include "ash/shell.h" |
12 #include "ash/shell_window_ids.h" | 12 #include "ash/shell_window_ids.h" |
13 #include "base/hash.h" | 13 #include "base/hash.h" |
14 #include "base/logging.h" | 14 #include "base/logging.h" |
15 #include "base/strings/utf_string_conversions.h" | 15 #include "base/strings/utf_string_conversions.h" |
16 #include "base/threading/sequenced_worker_pool.h" | 16 #include "base/threading/sequenced_worker_pool.h" |
17 #include "chrome/browser/media/desktop_media_list_observer.h" | 17 #include "chrome/browser/media/desktop_media_list_observer.h" |
18 #include "chrome/browser/profiles/profile_manager.h" | |
19 #include "chrome/browser/ui/browser_finder.h" | |
20 #include "chrome/browser/ui/tabs/tab_strip_model.h" | |
18 #include "chrome/grit/generated_resources.h" | 21 #include "chrome/grit/generated_resources.h" |
22 #include "components/favicon/content/content_favicon_driver.h" | |
19 #include "content/public/browser/browser_thread.h" | 23 #include "content/public/browser/browser_thread.h" |
24 #include "content/public/browser/render_frame_host.h" | |
25 #include "content/public/browser/render_process_host.h" | |
20 #include "media/base/video_util.h" | 26 #include "media/base/video_util.h" |
21 #include "ui/base/l10n/l10n_util.h" | 27 #include "ui/base/l10n/l10n_util.h" |
22 #include "ui/compositor/dip_util.h" | 28 #include "ui/compositor/dip_util.h" |
23 #include "ui/gfx/image/image.h" | 29 #include "ui/gfx/image/image.h" |
24 #include "ui/snapshot/snapshot.h" | 30 #include "ui/snapshot/snapshot.h" |
25 | 31 |
26 using content::BrowserThread; | 32 using content::BrowserThread; |
27 using content::DesktopMediaID; | 33 using content::DesktopMediaID; |
28 | 34 |
29 namespace { | 35 namespace { |
(...skipping 134 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
164 content::DesktopMediaID::TYPE_WINDOW, *it); | 170 content::DesktopMediaID::TYPE_WINDOW, *it); |
165 if (id.aura_id == view_dialog_id_.aura_id) | 171 if (id.aura_id == view_dialog_id_.aura_id) |
166 continue; | 172 continue; |
167 SourceDescription window_source(id, (*it)->title()); | 173 SourceDescription window_source(id, (*it)->title()); |
168 sources->push_back(window_source); | 174 sources->push_back(window_source); |
169 | 175 |
170 CaptureThumbnail(window_source.id, *it); | 176 CaptureThumbnail(window_source.id, *it); |
171 } | 177 } |
172 } | 178 } |
173 | 179 |
180 void DesktopMediaListAsh::EnumerateTabs( | |
181 std::vector<DesktopMediaListAsh::SourceDescription>* sources) { | |
182 DCHECK_CURRENTLY_ON(content::BrowserThread::UI); | |
183 | |
184 std::map<base::TimeTicks, SourceDescription> tab_map; | |
185 | |
186 // Get all tabs/webcontents' ids for a user profile | |
Avi (use Gerrit)
2016/01/08 17:11:38
Full sentences; end it with a period.
GeorgeZ
2016/01/08 19:39:02
Done.
| |
187 Profile* profile = ProfileManager::GetLastUsedProfileAllowedByPolicy(); | |
188 std::vector<Browser*> browsers = FindAllTabbedBrowsersWithProfile( | |
189 profile, chrome::HOST_DESKTOP_TYPE_NATIVE); | |
190 | |
191 std::vector<scoped_ptr<MediaListWebContentsObserver>> observers; | |
192 for (auto browser : browsers) { | |
193 TabStripModel* tab_strip_model = browser->tab_strip_model(); | |
194 DCHECK(tab_strip_model); | |
195 | |
196 for (int i = 0; i < tab_strip_model->count(); i++) { | |
197 content::WebContents* contents = tab_strip_model->GetWebContentsAt(i); | |
198 // Use observer to keep track the state of WebContents. | |
199 scoped_ptr<MediaListWebContentsObserver> observer( | |
200 new MediaListWebContentsObserver(contents)); | |
201 observers.push_back(std::move(observer)); | |
202 } | |
203 } | |
204 | |
205 // For each tab, get its title and favicon. | |
206 for (size_t i = 0; i < observers.size(); i++) { | |
207 // If the WebContents has been destroyed, a nullptr will return; | |
Avi (use Gerrit)
2016/01/08 17:11:38
How could the WebContents have been destroyed from
GeorgeZ
2016/01/08 19:39:02
Thanks for the explanation here.
Done.
| |
208 content::WebContents* contents = observers[i]->web_contents(); | |
209 if (contents == nullptr) | |
210 continue; | |
211 | |
212 content::RenderFrameHost* const main_frame = contents->GetMainFrame(); | |
213 DCHECK(main_frame); | |
214 DesktopMediaID media_id( | |
215 DesktopMediaID::TYPE_TAB, DesktopMediaID::kNullId, | |
216 content::WebContentsMediaCaptureId(main_frame->GetProcess()->GetID(), | |
217 main_frame->GetRoutingID())); | |
218 | |
219 // Create display tab title. | |
220 base::string16 title = l10n_util::GetStringFUTF16( | |
221 IDS_DESKTOP_MEDIA_PICKER_CHROME_TAB_TITLE, contents->GetTitle()); | |
222 | |
223 // Get tab's last active time stamp. | |
224 base::TimeTicks t = contents->GetLastActiveTime(); | |
225 tab_map.insert(std::make_pair(t, SourceDescription(media_id, title))); | |
226 | |
227 // Create thumbnail based on favicon for tab. | |
228 favicon::FaviconDriver* favicon_driver = | |
229 favicon::ContentFaviconDriver::FromWebContents(contents); | |
230 if (favicon_driver) { | |
231 gfx::Image tab_icon = favicon_driver->GetFavicon(); | |
232 tab_map[t].thumbnail = | |
233 CreateEnlargedFaviconImage(thumbnail_size_, tab_icon); | |
234 } | |
235 } | |
236 | |
237 // Add timely sorted tab sources into vector. Most recent one first. | |
238 for (auto it = tab_map.rbegin(); it != tab_map.rend(); ++it) { | |
239 SourceDescription& source = it->second; | |
240 sources->push_back(source); | |
241 if (!it->second.thumbnail.isNull()) | |
242 OnThumbnailCaptured(source.id, gfx::Image(source.thumbnail)); | |
243 } | |
244 } | |
245 | |
174 void DesktopMediaListAsh::EnumerateSources( | 246 void DesktopMediaListAsh::EnumerateSources( |
175 std::vector<DesktopMediaListAsh::SourceDescription>* sources) { | 247 std::vector<DesktopMediaListAsh::SourceDescription>* sources) { |
176 DCHECK_CURRENTLY_ON(content::BrowserThread::UI); | 248 DCHECK_CURRENTLY_ON(content::BrowserThread::UI); |
177 | 249 |
178 aura::Window::Windows root_windows = ash::Shell::GetAllRootWindows(); | 250 aura::Window::Windows root_windows = ash::Shell::GetAllRootWindows(); |
179 | 251 |
180 for (size_t i = 0; i < root_windows.size(); ++i) { | 252 for (size_t i = 0; i < root_windows.size(); ++i) { |
181 if (source_types_ & SCREENS) { | 253 if (source_types_ & SCREENS) { |
182 SourceDescription screen_source( | 254 SourceDescription screen_source( |
183 content::DesktopMediaID::RegisterAuraWindow( | 255 content::DesktopMediaID::RegisterAuraWindow( |
(...skipping 20 matching lines...) Expand all Loading... | |
204 } | 276 } |
205 | 277 |
206 if (source_types_ & WINDOWS) { | 278 if (source_types_ & WINDOWS) { |
207 EnumerateWindowsForRoot( | 279 EnumerateWindowsForRoot( |
208 sources, root_windows[i], ash::kShellWindowId_DefaultContainer); | 280 sources, root_windows[i], ash::kShellWindowId_DefaultContainer); |
209 EnumerateWindowsForRoot( | 281 EnumerateWindowsForRoot( |
210 sources, root_windows[i], ash::kShellWindowId_AlwaysOnTopContainer); | 282 sources, root_windows[i], ash::kShellWindowId_AlwaysOnTopContainer); |
211 EnumerateWindowsForRoot( | 283 EnumerateWindowsForRoot( |
212 sources, root_windows[i], ash::kShellWindowId_DockedContainer); | 284 sources, root_windows[i], ash::kShellWindowId_DockedContainer); |
213 } | 285 } |
286 | |
287 if (source_types_ & TABS) | |
288 EnumerateTabs(sources); | |
214 } | 289 } |
215 } | 290 } |
216 | 291 |
217 void DesktopMediaListAsh::CaptureThumbnail(content::DesktopMediaID id, | 292 void DesktopMediaListAsh::CaptureThumbnail(content::DesktopMediaID id, |
218 aura::Window* window) { | 293 aura::Window* window) { |
219 gfx::Rect window_rect(window->bounds().width(), window->bounds().height()); | 294 gfx::Rect window_rect(window->bounds().width(), window->bounds().height()); |
220 gfx::Rect scaled_rect = media::ComputeLetterboxRegion( | 295 gfx::Rect scaled_rect = media::ComputeLetterboxRegion( |
221 gfx::Rect(thumbnail_size_), window_rect.size()); | 296 gfx::Rect(thumbnail_size_), window_rect.size()); |
222 | 297 |
223 ++pending_window_capture_requests_; | 298 ++pending_window_capture_requests_; |
(...skipping 23 matching lines...) Expand all Loading... | |
247 if (!pending_window_capture_requests_) { | 322 if (!pending_window_capture_requests_) { |
248 // Once we've finished capturing all windows post a task for the next list | 323 // Once we've finished capturing all windows post a task for the next list |
249 // update. | 324 // update. |
250 BrowserThread::PostDelayedTask( | 325 BrowserThread::PostDelayedTask( |
251 BrowserThread::UI, FROM_HERE, | 326 BrowserThread::UI, FROM_HERE, |
252 base::Bind(&DesktopMediaListAsh::Refresh, | 327 base::Bind(&DesktopMediaListAsh::Refresh, |
253 weak_factory_.GetWeakPtr()), | 328 weak_factory_.GetWeakPtr()), |
254 update_period_); | 329 update_period_); |
255 } | 330 } |
256 } | 331 } |
OLD | NEW |