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

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 4 years, 11 months 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 a9ab1a4224b0d9c05d9e9ecf0fe2c367df90dc2b..74f1161bbf4e8b283ecddce3ba1dd0c98b86ecaf 100644
--- a/chrome/browser/media/desktop_media_list_ash.cc
+++ b/chrome/browser/media/desktop_media_list_ash.cc
@@ -15,8 +15,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"
@@ -171,6 +177,72 @@ void DesktopMediaListAsh::EnumerateWindowsForRoot(
}
}
+void DesktopMediaListAsh::EnumerateTabs(
+ std::vector<DesktopMediaListAsh::SourceDescription>* sources) {
+ DCHECK_CURRENTLY_ON(content::BrowserThread::UI);
+
+ std::map<base::TimeTicks, SourceDescription> tab_map;
+
+ // 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.
+ Profile* profile = ProfileManager::GetLastUsedProfileAllowedByPolicy();
+ std::vector<Browser*> browsers = FindAllTabbedBrowsersWithProfile(
+ profile, chrome::HOST_DESKTOP_TYPE_NATIVE);
+
+ std::vector<scoped_ptr<MediaListWebContentsObserver>> observers;
+ 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++) {
+ content::WebContents* contents = tab_strip_model->GetWebContentsAt(i);
+ // Use observer to keep track the state of WebContents.
+ scoped_ptr<MediaListWebContentsObserver> observer(
+ new MediaListWebContentsObserver(contents));
+ observers.push_back(std::move(observer));
+ }
+ }
+
+ // For each tab, get its title and favicon.
+ for (size_t i = 0; i < observers.size(); i++) {
+ // 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.
+ content::WebContents* contents = observers[i]->web_contents();
+ if (contents == nullptr)
+ continue;
+
+ content::RenderFrameHost* const main_frame = contents->GetMainFrame();
+ DCHECK(main_frame);
+ DesktopMediaID media_id(
+ DesktopMediaID::TYPE_TAB, DesktopMediaID::kNullId,
+ content::WebContentsMediaCaptureId(main_frame->GetProcess()->GetID(),
+ main_frame->GetRoutingID()));
+
+ // Create display 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) {
+ 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);
@@ -211,6 +283,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