Chromium Code Reviews| OLD | NEW |
|---|---|
| 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 Loading... | |
| 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 | |
| 192 const int kNumTabs = tab_strip_model->count(); | |
|
miu
2015/12/08 01:54:38
naming: This variable is not assigned from a liter
GeorgeZ
2015/12/09 19:36:37
Changed for loop to
for (int i = 0; i < tab_st
| |
| 193 for (int i = 0; i < kNumTabs; i++) { | |
| 194 // Create DesktopMediaID. | |
| 195 content::WebContents* contents = tab_strip_model->GetWebContentsAt(i); | |
| 196 gfx::NativeWindow tab_window = contents->GetTopLevelNativeWindow(); | |
| 197 DesktopMediaID media_id = DesktopMediaID::RegisterAuraWindow( | |
| 198 DesktopMediaID::TYPE_TAB, tab_window); | |
| 199 | |
| 200 content::RenderFrameHost* const main_frame = contents->GetMainFrame(); | |
| 201 DCHECK(main_frame); | |
| 202 | |
| 203 media_id.render_process_id = main_frame->GetProcess()->GetID(); | |
| 204 media_id.main_render_frame_id = main_frame->GetRoutingID(); | |
| 205 | |
| 206 // Get tab title. | |
| 207 base::string16 title = | |
| 208 base::UTF8ToUTF16("Chrome tab_") + contents->GetTitle(); | |
|
qiangchen
2015/12/07 22:45:56
Just wonder do we need to throw "Chrome tab_" to r
miu
2015/12/08 01:54:38
1. This string needs to be in generated_resources.
GeorgeZ
2015/12/09 19:36:37
Done.
GeorgeZ
2015/12/09 19:36:37
For 1, I moved string into resources.grd. For 2, I
| |
| 209 | |
| 210 // Get tab's last active time stamp. | |
| 211 base::TimeTicks t = contents->GetLastActiveTime(); | |
| 212 tab_map.insert(std::make_pair(t, SourceDescription(media_id, title))); | |
| 213 | |
| 214 // Get thumbnail for tab. | |
|
miu
2015/12/08 01:54:38
These aren't tab thumbnails. They're favicons. P
GeorgeZ
2015/12/09 19:36:37
The whole block is for thumbnail creation. I will
| |
| 215 favicon::FaviconDriver* favicon_driver = | |
| 216 favicon::ContentFaviconDriver::FromWebContents(contents); | |
| 217 if (favicon_driver) { | |
| 218 ++pending_window_capture_requests_; | |
| 219 gfx::Image tab_icon = favicon_driver->GetFavicon(); | |
| 220 tab_map[t].thumbnail = | |
| 221 CreateImageEncloseFavicon(thumbnail_size_, tab_icon); | |
| 222 } | |
| 223 } | |
| 224 } | |
| 225 | |
| 226 // Add timely sorted tab sources into vector. Most recent one first. | |
| 227 for (auto it = tab_map.rbegin(); it != tab_map.rend(); ++it) { | |
| 228 SourceDescription& source = it->second; | |
| 229 sources->push_back(source); | |
| 230 if (!it->second.thumbnail.isNull()) | |
| 231 OnThumbnailCaptured(source.id, gfx::Image(source.thumbnail)); | |
| 232 } | |
| 233 } | |
| 234 | |
| 172 void DesktopMediaListAsh::EnumerateSources( | 235 void DesktopMediaListAsh::EnumerateSources( |
| 173 std::vector<DesktopMediaListAsh::SourceDescription>* sources) { | 236 std::vector<DesktopMediaListAsh::SourceDescription>* sources) { |
| 174 DCHECK_CURRENTLY_ON(content::BrowserThread::UI); | 237 DCHECK_CURRENTLY_ON(content::BrowserThread::UI); |
| 175 | 238 |
| 176 aura::Window::Windows root_windows = ash::Shell::GetAllRootWindows(); | 239 aura::Window::Windows root_windows = ash::Shell::GetAllRootWindows(); |
| 177 | 240 |
| 178 for (size_t i = 0; i < root_windows.size(); ++i) { | 241 for (size_t i = 0; i < root_windows.size(); ++i) { |
| 179 if (source_types_ & SCREENS) { | 242 if (source_types_ & SCREENS) { |
| 180 SourceDescription screen_source( | 243 SourceDescription screen_source( |
| 181 content::DesktopMediaID::RegisterAuraWindow( | 244 content::DesktopMediaID::RegisterAuraWindow( |
| (...skipping 20 matching lines...) Expand all Loading... | |
| 202 } | 265 } |
| 203 | 266 |
| 204 if (source_types_ & WINDOWS) { | 267 if (source_types_ & WINDOWS) { |
| 205 EnumerateWindowsForRoot( | 268 EnumerateWindowsForRoot( |
| 206 sources, root_windows[i], ash::kShellWindowId_DefaultContainer); | 269 sources, root_windows[i], ash::kShellWindowId_DefaultContainer); |
| 207 EnumerateWindowsForRoot( | 270 EnumerateWindowsForRoot( |
| 208 sources, root_windows[i], ash::kShellWindowId_AlwaysOnTopContainer); | 271 sources, root_windows[i], ash::kShellWindowId_AlwaysOnTopContainer); |
| 209 EnumerateWindowsForRoot( | 272 EnumerateWindowsForRoot( |
| 210 sources, root_windows[i], ash::kShellWindowId_DockedContainer); | 273 sources, root_windows[i], ash::kShellWindowId_DockedContainer); |
| 211 } | 274 } |
| 275 | |
| 276 if (source_types_ & TABS) | |
| 277 EnumerateTabs(sources); | |
| 212 } | 278 } |
| 213 } | 279 } |
| 214 | 280 |
| 215 void DesktopMediaListAsh::CaptureThumbnail(content::DesktopMediaID id, | 281 void DesktopMediaListAsh::CaptureThumbnail(content::DesktopMediaID id, |
| 216 aura::Window* window) { | 282 aura::Window* window) { |
| 217 gfx::Rect window_rect(window->bounds().width(), window->bounds().height()); | 283 gfx::Rect window_rect(window->bounds().width(), window->bounds().height()); |
| 218 gfx::Rect scaled_rect = media::ComputeLetterboxRegion( | 284 gfx::Rect scaled_rect = media::ComputeLetterboxRegion( |
| 219 gfx::Rect(thumbnail_size_), window_rect.size()); | 285 gfx::Rect(thumbnail_size_), window_rect.size()); |
| 220 | 286 |
| 221 ++pending_window_capture_requests_; | 287 ++pending_window_capture_requests_; |
| (...skipping 23 matching lines...) Expand all Loading... | |
| 245 if (!pending_window_capture_requests_) { | 311 if (!pending_window_capture_requests_) { |
| 246 // Once we've finished capturing all windows post a task for the next list | 312 // Once we've finished capturing all windows post a task for the next list |
| 247 // update. | 313 // update. |
| 248 BrowserThread::PostDelayedTask( | 314 BrowserThread::PostDelayedTask( |
| 249 BrowserThread::UI, FROM_HERE, | 315 BrowserThread::UI, FROM_HERE, |
| 250 base::Bind(&DesktopMediaListAsh::Refresh, | 316 base::Bind(&DesktopMediaListAsh::Refresh, |
| 251 weak_factory_.GetWeakPtr()), | 317 weak_factory_.GetWeakPtr()), |
| 252 update_period_); | 318 update_period_); |
| 253 } | 319 } |
| 254 } | 320 } |
| OLD | NEW |