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

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: 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..b2892b52e54c4b5a9510a986e83d90ed3792bd79 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,63 @@ 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);
+
+ const int kNumTabs = tab_strip_model->count();
miu 2015/12/08 01:54:38 naming: This variable is not assigned from a liter
GeorgeZ 2015/12/09 19:36:37 Changed for loop to for (int i = 0; i < tab_st
+ for (int i = 0; i < kNumTabs; 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.render_process_id = main_frame->GetProcess()->GetID();
+ media_id.main_render_frame_id = main_frame->GetRoutingID();
+
+ // Get tab title.
+ base::string16 title =
+ base::UTF8ToUTF16("Chrome tab_") + contents->GetTitle();
qiangchen 2015/12/07 22:45:56 Just wonder do we need to throw "Chrome tab_" to r
miu 2015/12/08 01:54:38 1. This string needs to be in generated_resources.
GeorgeZ 2015/12/09 19:36:37 Done.
GeorgeZ 2015/12/09 19:36:37 For 1, I moved string into resources.grd. For 2, I
+
+ // Get tab's last active time stamp.
+ base::TimeTicks t = contents->GetLastActiveTime();
+ tab_map.insert(std::make_pair(t, SourceDescription(media_id, title)));
+
+ // Get thumbnail for tab.
miu 2015/12/08 01:54:38 These aren't tab thumbnails. They're favicons. P
GeorgeZ 2015/12/09 19:36:37 The whole block is for thumbnail creation. I will
+ 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 =
+ CreateImageEncloseFavicon(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 +272,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