Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(6007)

Unified Diff: chrome/browser/media/desktop_media_list_ash.cc

Issue 1503563004: Desktop chrome tab capture-chooseDesktopMedia() (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: review round 4 Created 5 years ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
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..14c2c7089c68fa394536836202c4de2a5e70bbb4 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,62 @@ 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) {
+ 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::GetStringUTF16(
+ IDS_DESKTOP_MEDIA_PICKER_CHROME_TAB_PREFIX) +
+ contents->GetTitle();
qiangchen 2015/12/16 21:08:36 I'm not sure of google's I18N policy. But in my mi
GeorgeZ 2015/12/16 22:38:40 Done.
+
+ // 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();
+ tab_map[t].thumbnail =
+ 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 +271,9 @@ void DesktopMediaListAsh::EnumerateSources(
EnumerateWindowsForRoot(
sources, root_windows[i], ash::kShellWindowId_DockedContainer);
}
+
+ if (source_types_ & TABS)
+ EnumerateTabs(sources);
}
}

Powered by Google App Engine
This is Rietveld 408576698