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

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: rebase 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_finder.h"
20 #include "chrome/browser/ui/tabs/tab_strip_model.h"
18 #include "chrome/grit/generated_resources.h" 21 #include "chrome/grit/generated_resources.h"
22 #include "components/favicon/content/content_favicon_driver.h"
19 #include "content/public/browser/browser_thread.h" 23 #include "content/public/browser/browser_thread.h"
24 #include "content/public/browser/render_frame_host.h"
25 #include "content/public/browser/render_process_host.h"
20 #include "media/base/video_util.h" 26 #include "media/base/video_util.h"
21 #include "ui/base/l10n/l10n_util.h" 27 #include "ui/base/l10n/l10n_util.h"
22 #include "ui/compositor/dip_util.h" 28 #include "ui/compositor/dip_util.h"
23 #include "ui/gfx/image/image.h" 29 #include "ui/gfx/image/image.h"
24 #include "ui/snapshot/snapshot.h" 30 #include "ui/snapshot/snapshot.h"
25 31
26 using content::BrowserThread; 32 using content::BrowserThread;
27 using content::DesktopMediaID; 33 using content::DesktopMediaID;
28 34
29 namespace { 35 namespace {
(...skipping 134 matching lines...) Expand 10 before | Expand all | Expand 10 after
164 content::DesktopMediaID::TYPE_WINDOW, *it); 170 content::DesktopMediaID::TYPE_WINDOW, *it);
165 if (id.aura_id == view_dialog_id_.aura_id) 171 if (id.aura_id == view_dialog_id_.aura_id)
166 continue; 172 continue;
167 SourceDescription window_source(id, (*it)->title()); 173 SourceDescription window_source(id, (*it)->title());
168 sources->push_back(window_source); 174 sources->push_back(window_source);
169 175
170 CaptureThumbnail(window_source.id, *it); 176 CaptureThumbnail(window_source.id, *it);
171 } 177 }
172 } 178 }
173 179
180 void DesktopMediaListAsh::EnumerateTabs(
181 std::vector<DesktopMediaListAsh::SourceDescription>* sources) {
182 DCHECK_CURRENTLY_ON(content::BrowserThread::UI);
183
184 std::map<base::TimeTicks, SourceDescription> tab_map;
185
186 // Get all tabs/webcontents' ids for a user profile
187 Profile* profile = ProfileManager::GetLastUsedProfileAllowedByPolicy();
188 std::vector<Browser*> browsers = FindAllTabbedBrowsersWithProfile(
189 profile, chrome::HOST_DESKTOP_TYPE_NATIVE);
190
191 std::vector<int> web_contents_ids;
192 for (auto browser : browsers) {
193 TabStripModel* tab_strip_model = browser->tab_strip_model();
194 DCHECK(tab_strip_model);
195
196 for (int i = 0; i < tab_strip_model->count(); i++) {
197 content::WebContents* contents = tab_strip_model->GetWebContentsAt(i);
198 // Register WebContent to get an id to reprent it.
199 web_contents_ids.push_back(
200 WebContentsRegistry::GetInstance()->RegisterWebContents(contents));
201 }
202 }
203
204 // For each tab, get its title and favicon.
205 for (int web_id : web_contents_ids) {
206 content::WebContents* contents =
207 WebContentsRegistry::GetInstance()->GetWebContentsById(web_id);
208 if (contents == nullptr)
209 continue;
210
211 content::RenderFrameHost* const main_frame = contents->GetMainFrame();
212 DCHECK(main_frame);
213 DesktopMediaID media_id(
214 DesktopMediaID::TYPE_TAB, DesktopMediaID::kNullId,
215 content::WebContentsMediaCaptureId(main_frame->GetProcess()->GetID(),
216 main_frame->GetRoutingID()));
217
218 // Get tab title. Treat specially in case a title is not available.
219 base::string16 title;
220 if (contents->GetTitle().size() != 0)
221 title = l10n_util::GetStringFUTF16(
222 IDS_DESKTOP_MEDIA_PICKER_CHROME_TAB_TITLE, contents->GetTitle());
223 else
224 title = l10n_util::GetStringUTF16(
225 IDS_DESKTOP_MEDIA_PICKER_CHROME_TAB_TITLE_NOT_AVAILABLE);
226
227 // Get tab's last active time stamp.
228 base::TimeTicks t = contents->GetLastActiveTime();
229 tab_map.insert(std::make_pair(t, SourceDescription(media_id, title)));
230
231 // Create thumbnail based on favicon for tab.
232 favicon::FaviconDriver* favicon_driver =
233 favicon::ContentFaviconDriver::FromWebContents(contents);
234 if (favicon_driver) {
235 gfx::Image tab_icon = favicon_driver->GetFavicon();
236 tab_map[t].thumbnail =
237 CreateEnlargedFaviconImage(thumbnail_size_, tab_icon);
238 }
239 }
240
241 // Add timely sorted tab sources into vector. Most recent one first.
242 for (auto it = tab_map.rbegin(); it != tab_map.rend(); ++it) {
243 SourceDescription& source = it->second;
244 sources->push_back(source);
245 if (!it->second.thumbnail.isNull())
246 OnThumbnailCaptured(source.id, gfx::Image(source.thumbnail));
247 }
248 }
249
174 void DesktopMediaListAsh::EnumerateSources( 250 void DesktopMediaListAsh::EnumerateSources(
175 std::vector<DesktopMediaListAsh::SourceDescription>* sources) { 251 std::vector<DesktopMediaListAsh::SourceDescription>* sources) {
176 DCHECK_CURRENTLY_ON(content::BrowserThread::UI); 252 DCHECK_CURRENTLY_ON(content::BrowserThread::UI);
177 253
178 aura::Window::Windows root_windows = ash::Shell::GetAllRootWindows(); 254 aura::Window::Windows root_windows = ash::Shell::GetAllRootWindows();
179 255
180 for (size_t i = 0; i < root_windows.size(); ++i) { 256 for (size_t i = 0; i < root_windows.size(); ++i) {
181 if (source_types_ & SCREENS) { 257 if (source_types_ & SCREENS) {
182 SourceDescription screen_source( 258 SourceDescription screen_source(
183 content::DesktopMediaID::RegisterAuraWindow( 259 content::DesktopMediaID::RegisterAuraWindow(
(...skipping 20 matching lines...) Expand all
204 } 280 }
205 281
206 if (source_types_ & WINDOWS) { 282 if (source_types_ & WINDOWS) {
207 EnumerateWindowsForRoot( 283 EnumerateWindowsForRoot(
208 sources, root_windows[i], ash::kShellWindowId_DefaultContainer); 284 sources, root_windows[i], ash::kShellWindowId_DefaultContainer);
209 EnumerateWindowsForRoot( 285 EnumerateWindowsForRoot(
210 sources, root_windows[i], ash::kShellWindowId_AlwaysOnTopContainer); 286 sources, root_windows[i], ash::kShellWindowId_AlwaysOnTopContainer);
211 EnumerateWindowsForRoot( 287 EnumerateWindowsForRoot(
212 sources, root_windows[i], ash::kShellWindowId_DockedContainer); 288 sources, root_windows[i], ash::kShellWindowId_DockedContainer);
213 } 289 }
290
291 if (source_types_ & TABS)
292 EnumerateTabs(sources);
214 } 293 }
215 } 294 }
216 295
217 void DesktopMediaListAsh::CaptureThumbnail(content::DesktopMediaID id, 296 void DesktopMediaListAsh::CaptureThumbnail(content::DesktopMediaID id,
218 aura::Window* window) { 297 aura::Window* window) {
219 gfx::Rect window_rect(window->bounds().width(), window->bounds().height()); 298 gfx::Rect window_rect(window->bounds().width(), window->bounds().height());
220 gfx::Rect scaled_rect = media::ComputeLetterboxRegion( 299 gfx::Rect scaled_rect = media::ComputeLetterboxRegion(
221 gfx::Rect(thumbnail_size_), window_rect.size()); 300 gfx::Rect(thumbnail_size_), window_rect.size());
222 301
223 ++pending_window_capture_requests_; 302 ++pending_window_capture_requests_;
(...skipping 23 matching lines...) Expand all
247 if (!pending_window_capture_requests_) { 326 if (!pending_window_capture_requests_) {
248 // Once we've finished capturing all windows post a task for the next list 327 // Once we've finished capturing all windows post a task for the next list
249 // update. 328 // update.
250 BrowserThread::PostDelayedTask( 329 BrowserThread::PostDelayedTask(
251 BrowserThread::UI, FROM_HERE, 330 BrowserThread::UI, FROM_HERE,
252 base::Bind(&DesktopMediaListAsh::Refresh, 331 base::Bind(&DesktopMediaListAsh::Refresh,
253 weak_factory_.GetWeakPtr()), 332 weak_factory_.GetWeakPtr()),
254 update_period_); 333 update_period_);
255 } 334 }
256 } 335 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698