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

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

Powered by Google App Engine
This is Rietveld 408576698