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

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 patch 5 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) {
Sergey Ulanov 2015/12/18 19:45:04 This code is duplicated in DesktopMediaListAsh and
GeorgeZ 2015/12/18 21:57:26 You are right, the duplication is not good. Howeve
GeorgeZ 2015/12/21 16:17:37 After I further think about this duplication issue
Sergey Ulanov 2016/01/04 18:59:29 With CombinedDesktopMediaList you get more classes
Sergey Ulanov 2016/01/04 18:59:29 Yes, CombinedDesktopMediaList will need to handle
GeorgeZ 2016/01/06 22:41:39 How about I address this issue in another CL right
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::GetStringFUTF16(
206 IDS_DESKTOP_MEDIA_PICKER_CHROME_TAB_TITLE, contents->GetTitle());
207
208 // Get tab's last active time stamp.
209 base::TimeTicks t = contents->GetLastActiveTime();
210 tab_map.insert(std::make_pair(t, SourceDescription(media_id, title)));
211
212 // Create thumbnail based on favicon for tab.
213 favicon::FaviconDriver* favicon_driver =
214 favicon::ContentFaviconDriver::FromWebContents(contents);
215 if (favicon_driver) {
216 ++pending_window_capture_requests_;
217 gfx::Image tab_icon = favicon_driver->GetFavicon();
mark a. foltz 2016/01/04 20:11:41 What if the tab does not have a favicon? Nit: In
GeorgeZ 2016/01/06 22:41:39 If there is no favicon, there is no drawing in the
218 tab_map[t].thumbnail =
mark a. foltz 2016/01/04 20:11:41 How expensive is the creation of these favicon ima
GeorgeZ 2016/01/06 22:41:39 We use screen shot for media type of screen and wi
219 CreateEnlargedFaviconImage(thumbnail_size_, tab_icon);
220 }
221 }
222 }
223
224 // Add timely sorted tab sources into vector. Most recent one first.
225 for (auto it = tab_map.rbegin(); it != tab_map.rend(); ++it) {
226 SourceDescription& source = it->second;
227 sources->push_back(source);
228 if (!it->second.thumbnail.isNull())
229 OnThumbnailCaptured(source.id, gfx::Image(source.thumbnail));
230 }
231 }
232
172 void DesktopMediaListAsh::EnumerateSources( 233 void DesktopMediaListAsh::EnumerateSources(
173 std::vector<DesktopMediaListAsh::SourceDescription>* sources) { 234 std::vector<DesktopMediaListAsh::SourceDescription>* sources) {
174 DCHECK_CURRENTLY_ON(content::BrowserThread::UI); 235 DCHECK_CURRENTLY_ON(content::BrowserThread::UI);
175 236
176 aura::Window::Windows root_windows = ash::Shell::GetAllRootWindows(); 237 aura::Window::Windows root_windows = ash::Shell::GetAllRootWindows();
177 238
178 for (size_t i = 0; i < root_windows.size(); ++i) { 239 for (size_t i = 0; i < root_windows.size(); ++i) {
179 if (source_types_ & SCREENS) { 240 if (source_types_ & SCREENS) {
180 SourceDescription screen_source( 241 SourceDescription screen_source(
181 content::DesktopMediaID::RegisterAuraWindow( 242 content::DesktopMediaID::RegisterAuraWindow(
(...skipping 20 matching lines...) Expand all
202 } 263 }
203 264
204 if (source_types_ & WINDOWS) { 265 if (source_types_ & WINDOWS) {
205 EnumerateWindowsForRoot( 266 EnumerateWindowsForRoot(
206 sources, root_windows[i], ash::kShellWindowId_DefaultContainer); 267 sources, root_windows[i], ash::kShellWindowId_DefaultContainer);
207 EnumerateWindowsForRoot( 268 EnumerateWindowsForRoot(
208 sources, root_windows[i], ash::kShellWindowId_AlwaysOnTopContainer); 269 sources, root_windows[i], ash::kShellWindowId_AlwaysOnTopContainer);
209 EnumerateWindowsForRoot( 270 EnumerateWindowsForRoot(
210 sources, root_windows[i], ash::kShellWindowId_DockedContainer); 271 sources, root_windows[i], ash::kShellWindowId_DockedContainer);
211 } 272 }
273
274 if (source_types_ & TABS)
275 EnumerateTabs(sources);
212 } 276 }
213 } 277 }
214 278
215 void DesktopMediaListAsh::CaptureThumbnail(content::DesktopMediaID id, 279 void DesktopMediaListAsh::CaptureThumbnail(content::DesktopMediaID id,
216 aura::Window* window) { 280 aura::Window* window) {
217 gfx::Rect window_rect(window->bounds().width(), window->bounds().height()); 281 gfx::Rect window_rect(window->bounds().width(), window->bounds().height());
218 gfx::Rect scaled_rect = media::ComputeLetterboxRegion( 282 gfx::Rect scaled_rect = media::ComputeLetterboxRegion(
219 gfx::Rect(thumbnail_size_), window_rect.size()); 283 gfx::Rect(thumbnail_size_), window_rect.size());
220 284
221 ++pending_window_capture_requests_; 285 ++pending_window_capture_requests_;
(...skipping 23 matching lines...) Expand all
245 if (!pending_window_capture_requests_) { 309 if (!pending_window_capture_requests_) {
246 // Once we've finished capturing all windows post a task for the next list 310 // Once we've finished capturing all windows post a task for the next list
247 // update. 311 // update.
248 BrowserThread::PostDelayedTask( 312 BrowserThread::PostDelayedTask(
249 BrowserThread::UI, FROM_HERE, 313 BrowserThread::UI, FROM_HERE,
250 base::Bind(&DesktopMediaListAsh::Refresh, 314 base::Bind(&DesktopMediaListAsh::Refresh,
251 weak_factory_.GetWeakPtr()), 315 weak_factory_.GetWeakPtr()),
252 update_period_); 316 update_period_);
253 } 317 }
254 } 318 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698