Chromium Code Reviews| Index: chrome/browser/media/desktop_media_list_ash.cc |
| diff --git a/chrome/browser/media/desktop_media_list_ash.cc b/chrome/browser/media/desktop_media_list_ash.cc |
| index 7bbd85ca20adb2b6845db9c3b82650a6a92e133f..ed4a320caaa5f986731faeb08cb9703169ce99b0 100644 |
| --- a/chrome/browser/media/desktop_media_list_ash.cc |
| +++ b/chrome/browser/media/desktop_media_list_ash.cc |
| @@ -13,8 +13,14 @@ |
| #include "base/strings/utf_string_conversions.h" |
| #include "base/threading/sequenced_worker_pool.h" |
| #include "chrome/browser/media/desktop_media_list_observer.h" |
| +#include "chrome/browser/profiles/profile_manager.h" |
| +#include "chrome/browser/ui/browser_finder.h" |
| +#include "chrome/browser/ui/tabs/tab_strip_model.h" |
| #include "chrome/grit/generated_resources.h" |
| +#include "components/favicon/content/content_favicon_driver.h" |
| #include "content/public/browser/browser_thread.h" |
| +#include "content/public/browser/render_frame_host.h" |
| +#include "content/public/browser/render_process_host.h" |
| #include "media/base/video_util.h" |
| #include "ui/base/l10n/l10n_util.h" |
| #include "ui/compositor/dip_util.h" |
| @@ -169,6 +175,61 @@ void DesktopMediaListAsh::EnumerateWindowsForRoot( |
| } |
| } |
| +void DesktopMediaListAsh::EnumerateTabs( |
| + std::vector<DesktopMediaListAsh::SourceDescription>* sources) { |
| + DCHECK_CURRENTLY_ON(content::BrowserThread::UI); |
| + |
| + Profile* profile = ProfileManager::GetLastUsedProfileAllowedByPolicy(); |
| + std::vector<Browser*> browsers = FindAllTabbedBrowsersWithProfile( |
| + profile, chrome::HOST_DESKTOP_TYPE_NATIVE); |
| + |
| + std::map<base::TimeTicks, SourceDescription> tab_map; |
| + |
| + for (auto browser : browsers) { |
|
Sergey Ulanov
2015/12/18 19:45:04
This code is duplicated in DesktopMediaListAsh and
GeorgeZ
2015/12/18 21:57:26
You are right, the duplication is not good. Howeve
GeorgeZ
2015/12/21 16:17:37
After I further think about this duplication issue
Sergey Ulanov
2016/01/04 18:59:29
With CombinedDesktopMediaList you get more classes
Sergey Ulanov
2016/01/04 18:59:29
Yes, CombinedDesktopMediaList will need to handle
GeorgeZ
2016/01/06 22:41:39
How about I address this issue in another CL right
|
| + TabStripModel* tab_strip_model = browser->tab_strip_model(); |
| + DCHECK(tab_strip_model); |
| + for (int i = 0; i < tab_strip_model->count(); i++) { |
| + // Create DesktopMediaID. |
| + content::WebContents* contents = tab_strip_model->GetWebContentsAt(i); |
| + gfx::NativeWindow tab_window = contents->GetTopLevelNativeWindow(); |
| + DesktopMediaID media_id = DesktopMediaID::RegisterAuraWindow( |
| + DesktopMediaID::TYPE_TAB, tab_window); |
| + |
| + content::RenderFrameHost* const main_frame = contents->GetMainFrame(); |
| + DCHECK(main_frame); |
| + |
| + media_id.tab_id.render_process_id = main_frame->GetProcess()->GetID(); |
| + media_id.tab_id.main_render_frame_id = main_frame->GetRoutingID(); |
| + |
| + // Get tab title. |
| + base::string16 title = l10n_util::GetStringFUTF16( |
| + IDS_DESKTOP_MEDIA_PICKER_CHROME_TAB_TITLE, contents->GetTitle()); |
| + |
| + // Get tab's last active time stamp. |
| + base::TimeTicks t = contents->GetLastActiveTime(); |
| + tab_map.insert(std::make_pair(t, SourceDescription(media_id, title))); |
| + |
| + // Create thumbnail based on favicon for tab. |
| + favicon::FaviconDriver* favicon_driver = |
| + favicon::ContentFaviconDriver::FromWebContents(contents); |
| + if (favicon_driver) { |
| + ++pending_window_capture_requests_; |
| + gfx::Image tab_icon = favicon_driver->GetFavicon(); |
|
mark a. foltz
2016/01/04 20:11:41
What if the tab does not have a favicon?
Nit: In
GeorgeZ
2016/01/06 22:41:39
If there is no favicon, there is no drawing in the
|
| + tab_map[t].thumbnail = |
|
mark a. foltz
2016/01/04 20:11:41
How expensive is the creation of these favicon ima
GeorgeZ
2016/01/06 22:41:39
We use screen shot for media type of screen and wi
|
| + CreateEnlargedFaviconImage(thumbnail_size_, tab_icon); |
| + } |
| + } |
| + } |
| + |
| + // Add timely sorted tab sources into vector. Most recent one first. |
| + for (auto it = tab_map.rbegin(); it != tab_map.rend(); ++it) { |
| + SourceDescription& source = it->second; |
| + sources->push_back(source); |
| + if (!it->second.thumbnail.isNull()) |
| + OnThumbnailCaptured(source.id, gfx::Image(source.thumbnail)); |
| + } |
| +} |
| + |
| void DesktopMediaListAsh::EnumerateSources( |
| std::vector<DesktopMediaListAsh::SourceDescription>* sources) { |
| DCHECK_CURRENTLY_ON(content::BrowserThread::UI); |
| @@ -209,6 +270,9 @@ void DesktopMediaListAsh::EnumerateSources( |
| EnumerateWindowsForRoot( |
| sources, root_windows[i], ash::kShellWindowId_DockedContainer); |
| } |
| + |
| + if (source_types_ & TABS) |
| + EnumerateTabs(sources); |
| } |
| } |