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

Side by Side 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 unified diff | Download patch
OLDNEW
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.h"
20 #include "chrome/browser/ui/browser_iterator.h"
21 #include "chrome/browser/ui/tabs/tab_strip_model.h"
18 #include "chrome/grit/generated_resources.h" 22 #include "chrome/grit/generated_resources.h"
23 #include "components/favicon/content/content_favicon_driver.h"
19 #include "content/public/browser/browser_thread.h" 24 #include "content/public/browser/browser_thread.h"
25 #include "content/public/browser/render_frame_host.h"
26 #include "content/public/browser/render_process_host.h"
20 #include "media/base/video_util.h" 27 #include "media/base/video_util.h"
21 #include "ui/base/l10n/l10n_util.h" 28 #include "ui/base/l10n/l10n_util.h"
22 #include "ui/compositor/dip_util.h" 29 #include "ui/compositor/dip_util.h"
23 #include "ui/gfx/image/image.h" 30 #include "ui/gfx/image/image.h"
24 #include "ui/snapshot/snapshot.h" 31 #include "ui/snapshot/snapshot.h"
25 32
26 using content::BrowserThread; 33 using content::BrowserThread;
27 using content::DesktopMediaID; 34 using content::DesktopMediaID;
28 35
29 namespace { 36 namespace {
(...skipping 134 matching lines...) Expand 10 before | Expand all | Expand 10 after
164 content::DesktopMediaID::TYPE_WINDOW, *it); 171 content::DesktopMediaID::TYPE_WINDOW, *it);
165 if (id.aura_id == view_dialog_id_.aura_id) 172 if (id.aura_id == view_dialog_id_.aura_id)
166 continue; 173 continue;
167 SourceDescription window_source(id, (*it)->title()); 174 SourceDescription window_source(id, (*it)->title());
168 sources->push_back(window_source); 175 sources->push_back(window_source);
169 176
170 CaptureThumbnail(window_source.id, *it); 177 CaptureThumbnail(window_source.id, *it);
171 } 178 }
172 } 179 }
173 180
181 void DesktopMediaListAsh::EnumerateTabs(
182 std::vector<DesktopMediaListAsh::SourceDescription>* sources) {
183 DCHECK_CURRENTLY_ON(content::BrowserThread::UI);
184
185 std::map<base::TimeTicks, SourceDescription> tab_map;
186
187 // Enumerate all tabs with their titles and favicons for a user profile.
188 Profile* profile = ProfileManager::GetLastUsedProfileAllowedByPolicy();
189 std::vector<Browser*> browsers;
190 for (chrome::BrowserIterator it; !it.done(); it.Next()) {
191 if (it->profile()->GetOriginalProfile() == profile->GetOriginalProfile())
192 browsers.push_back(*it);
193 }
194
195 for (auto browser : browsers) {
196 TabStripModel* tab_strip_model = browser->tab_strip_model();
197 DCHECK(tab_strip_model);
198
199 for (int i = 0; i < tab_strip_model->count(); i++) {
200 content::WebContents* contents = tab_strip_model->GetWebContentsAt(i);
201 content::RenderFrameHost* const main_frame = contents->GetMainFrame();
202 DCHECK(main_frame);
203 DesktopMediaID media_id(
204 DesktopMediaID::TYPE_TAB, DesktopMediaID::kNullId,
205 content::WebContentsMediaCaptureId(main_frame->GetProcess()->GetID(),
206 main_frame->GetRoutingID()));
207
208 // Create display tab title.
209 base::string16 title = l10n_util::GetStringFUTF16(
210 IDS_DESKTOP_MEDIA_PICKER_CHROME_TAB_TITLE, contents->GetTitle());
211
212 // Get tab's last active time stamp.
213 base::TimeTicks t = contents->GetLastActiveTime();
214 tab_map.insert(std::make_pair(t, SourceDescription(media_id, title)));
215
216 // Create thumbnail based on favicon for tab.
217 favicon::FaviconDriver* favicon_driver =
218 favicon::ContentFaviconDriver::FromWebContents(contents);
219 if (favicon_driver) {
220 gfx::Image tab_icon = favicon_driver->GetFavicon();
221 tab_map[t].thumbnail =
222 CreateEnlargedFaviconImage(thumbnail_size_, tab_icon);
223 }
224 }
225 }
226
227 // Add timely sorted tab sources into vector. Most recent one first.
228 for (auto it = tab_map.rbegin(); it != tab_map.rend(); ++it) {
229 SourceDescription& source = it->second;
230 sources->push_back(source);
231 if (!it->second.thumbnail.isNull())
232 OnThumbnailCaptured(source.id, gfx::Image(source.thumbnail));
233 }
234 }
235
174 void DesktopMediaListAsh::EnumerateSources( 236 void DesktopMediaListAsh::EnumerateSources(
175 std::vector<DesktopMediaListAsh::SourceDescription>* sources) { 237 std::vector<DesktopMediaListAsh::SourceDescription>* sources) {
176 DCHECK_CURRENTLY_ON(content::BrowserThread::UI); 238 DCHECK_CURRENTLY_ON(content::BrowserThread::UI);
177 239
178 aura::Window::Windows root_windows = ash::Shell::GetAllRootWindows(); 240 aura::Window::Windows root_windows = ash::Shell::GetAllRootWindows();
179 241
180 for (size_t i = 0; i < root_windows.size(); ++i) { 242 for (size_t i = 0; i < root_windows.size(); ++i) {
181 if (source_types_ & SCREENS) { 243 if (source_types_ & SCREENS) {
182 SourceDescription screen_source( 244 SourceDescription screen_source(
183 content::DesktopMediaID::RegisterAuraWindow( 245 content::DesktopMediaID::RegisterAuraWindow(
(...skipping 20 matching lines...) Expand all
204 } 266 }
205 267
206 if (source_types_ & WINDOWS) { 268 if (source_types_ & WINDOWS) {
207 EnumerateWindowsForRoot( 269 EnumerateWindowsForRoot(
208 sources, root_windows[i], ash::kShellWindowId_DefaultContainer); 270 sources, root_windows[i], ash::kShellWindowId_DefaultContainer);
209 EnumerateWindowsForRoot( 271 EnumerateWindowsForRoot(
210 sources, root_windows[i], ash::kShellWindowId_AlwaysOnTopContainer); 272 sources, root_windows[i], ash::kShellWindowId_AlwaysOnTopContainer);
211 EnumerateWindowsForRoot( 273 EnumerateWindowsForRoot(
212 sources, root_windows[i], ash::kShellWindowId_DockedContainer); 274 sources, root_windows[i], ash::kShellWindowId_DockedContainer);
213 } 275 }
276
277 if (source_types_ & TABS)
278 EnumerateTabs(sources);
214 } 279 }
215 } 280 }
216 281
217 void DesktopMediaListAsh::CaptureThumbnail(content::DesktopMediaID id, 282 void DesktopMediaListAsh::CaptureThumbnail(content::DesktopMediaID id,
218 aura::Window* window) { 283 aura::Window* window) {
219 gfx::Rect window_rect(window->bounds().width(), window->bounds().height()); 284 gfx::Rect window_rect(window->bounds().width(), window->bounds().height());
220 gfx::Rect scaled_rect = media::ComputeLetterboxRegion( 285 gfx::Rect scaled_rect = media::ComputeLetterboxRegion(
221 gfx::Rect(thumbnail_size_), window_rect.size()); 286 gfx::Rect(thumbnail_size_), window_rect.size());
222 287
223 ++pending_window_capture_requests_; 288 ++pending_window_capture_requests_;
(...skipping 23 matching lines...) Expand all
247 if (!pending_window_capture_requests_) { 312 if (!pending_window_capture_requests_) {
248 // Once we've finished capturing all windows post a task for the next list 313 // Once we've finished capturing all windows post a task for the next list
249 // update. 314 // update.
250 BrowserThread::PostDelayedTask( 315 BrowserThread::PostDelayedTask(
251 BrowserThread::UI, FROM_HERE, 316 BrowserThread::UI, FROM_HERE,
252 base::Bind(&DesktopMediaListAsh::Refresh, 317 base::Bind(&DesktopMediaListAsh::Refresh,
253 weak_factory_.GetWeakPtr()), 318 weak_factory_.GetWeakPtr()),
254 update_period_); 319 update_period_);
255 } 320 }
256 } 321 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698