OLD | NEW |
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 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/media_stream_capture_indicator.h" | 5 #include "chrome/browser/media/media_stream_capture_indicator.h" |
6 | 6 |
7 #include "base/bind.h" | 7 #include "base/bind.h" |
8 #include "base/i18n/rtl.h" | 8 #include "base/i18n/rtl.h" |
9 #include "base/logging.h" | 9 #include "base/logging.h" |
10 #include "base/utf_string_conversions.h" | 10 #include "base/utf_string_conversions.h" |
11 #include "chrome/app/chrome_command_ids.h" | 11 #include "chrome/app/chrome_command_ids.h" |
12 #include "chrome/browser/browser_process.h" | 12 #include "chrome/browser/browser_process.h" |
13 #include "chrome/browser/extensions/extension_service.h" | 13 #include "chrome/browser/extensions/extension_service.h" |
| 14 #include "chrome/browser/extensions/image_loader.h" |
14 #include "chrome/browser/profiles/profile.h" | 15 #include "chrome/browser/profiles/profile.h" |
15 #include "chrome/browser/status_icons/status_icon.h" | 16 #include "chrome/browser/status_icons/status_icon.h" |
16 #include "chrome/browser/status_icons/status_tray.h" | 17 #include "chrome/browser/status_icons/status_tray.h" |
17 #include "chrome/browser/tab_contents/tab_util.h" | 18 #include "chrome/browser/tab_contents/tab_util.h" |
18 #include "content/public/browser/browser_thread.h" | 19 #include "content/public/browser/browser_thread.h" |
19 #include "content/public/browser/content_browser_client.h" | 20 #include "content/public/browser/content_browser_client.h" |
20 #include "content/public/browser/invalidate_type.h" | 21 #include "content/public/browser/invalidate_type.h" |
21 #include "content/public/browser/render_view_host.h" | 22 #include "content/public/browser/render_view_host.h" |
22 #include "content/public/browser/web_contents.h" | 23 #include "content/public/browser/web_contents.h" |
23 #include "content/public/browser/web_contents_delegate.h" | 24 #include "content/public/browser/web_contents_delegate.h" |
(...skipping 94 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
118 const MediaStreamCaptureIndicator::CaptureDeviceTab& tab) { | 119 const MediaStreamCaptureIndicator::CaptureDeviceTab& tab) { |
119 return (render_process_id_ == tab.render_process_id && | 120 return (render_process_id_ == tab.render_process_id && |
120 render_view_id_ == tab.render_view_id); | 121 render_view_id_ == tab.render_view_id); |
121 } | 122 } |
122 | 123 |
123 MediaStreamCaptureIndicator::MediaStreamCaptureIndicator() | 124 MediaStreamCaptureIndicator::MediaStreamCaptureIndicator() |
124 : status_icon_(NULL), | 125 : status_icon_(NULL), |
125 mic_image_(NULL), | 126 mic_image_(NULL), |
126 camera_image_(NULL), | 127 camera_image_(NULL), |
127 balloon_image_(NULL), | 128 balloon_image_(NULL), |
128 request_index_(0) { | 129 should_show_balloon_(false) { |
129 } | 130 } |
130 | 131 |
131 MediaStreamCaptureIndicator::~MediaStreamCaptureIndicator() { | 132 MediaStreamCaptureIndicator::~MediaStreamCaptureIndicator() { |
132 // The user is responsible for cleaning up by closing all the opened devices. | 133 // The user is responsible for cleaning up by closing all the opened devices. |
133 DCHECK(tabs_.empty()); | 134 DCHECK(tabs_.empty()); |
134 } | 135 } |
135 | 136 |
136 bool MediaStreamCaptureIndicator::IsCommandIdChecked( | 137 bool MediaStreamCaptureIndicator::IsCommandIdChecked( |
137 int command_id) const { | 138 int command_id) const { |
138 NOTIMPLEMENTED() << "There are no checked items in the MediaStream menu."; | 139 NOTIMPLEMENTED() << "There are no checked items in the MediaStream menu."; |
(...skipping 82 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
221 if (!g_browser_process) | 222 if (!g_browser_process) |
222 return; | 223 return; |
223 | 224 |
224 StatusTray* status_tray = g_browser_process->status_tray(); | 225 StatusTray* status_tray = g_browser_process->status_tray(); |
225 if (!status_tray) | 226 if (!status_tray) |
226 return; | 227 return; |
227 | 228 |
228 status_icon_ = status_tray->CreateStatusIcon(); | 229 status_icon_ = status_tray->CreateStatusIcon(); |
229 | 230 |
230 EnsureStatusTrayIconResources(); | 231 EnsureStatusTrayIconResources(); |
231 EnsureImageLoadingTracker(); | |
232 } | 232 } |
233 | 233 |
234 void MediaStreamCaptureIndicator::EnsureStatusTrayIconResources() { | 234 void MediaStreamCaptureIndicator::EnsureStatusTrayIconResources() { |
235 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); | 235 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); |
236 if (!mic_image_) { | 236 if (!mic_image_) { |
237 mic_image_ = ResourceBundle::GetSharedInstance().GetImageSkiaNamed( | 237 mic_image_ = ResourceBundle::GetSharedInstance().GetImageSkiaNamed( |
238 IDR_INFOBAR_MEDIA_STREAM_MIC); | 238 IDR_INFOBAR_MEDIA_STREAM_MIC); |
239 } | 239 } |
240 if (!camera_image_) { | 240 if (!camera_image_) { |
241 camera_image_ = ResourceBundle::GetSharedInstance().GetImageSkiaNamed( | 241 camera_image_ = ResourceBundle::GetSharedInstance().GetImageSkiaNamed( |
(...skipping 18 matching lines...) Expand all Loading... |
260 | 260 |
261 int message_id = IDS_MEDIA_STREAM_STATUS_TRAY_BALLOON_BODY_AUDIO_AND_VIDEO; | 261 int message_id = IDS_MEDIA_STREAM_STATUS_TRAY_BALLOON_BODY_AUDIO_AND_VIDEO; |
262 if (audio && !video) | 262 if (audio && !video) |
263 message_id = IDS_MEDIA_STREAM_STATUS_TRAY_BALLOON_BODY_AUDIO_ONLY; | 263 message_id = IDS_MEDIA_STREAM_STATUS_TRAY_BALLOON_BODY_AUDIO_ONLY; |
264 else if (!audio && video) | 264 else if (!audio && video) |
265 message_id = IDS_MEDIA_STREAM_STATUS_TRAY_BALLOON_BODY_VIDEO_ONLY; | 265 message_id = IDS_MEDIA_STREAM_STATUS_TRAY_BALLOON_BODY_VIDEO_ONLY; |
266 | 266 |
267 const extensions::Extension* extension = | 267 const extensions::Extension* extension = |
268 GetExtension(render_process_id, render_view_id); | 268 GetExtension(render_process_id, render_view_id); |
269 if (extension) { | 269 if (extension) { |
270 pending_messages_[request_index_++] = | 270 string16 message = |
271 l10n_util::GetStringFUTF16(message_id, | 271 l10n_util::GetStringFUTF16(message_id, |
272 UTF8ToUTF16(extension->name())); | 272 UTF8ToUTF16(extension->name())); |
273 tracker_->LoadImage( | 273 |
| 274 WebContents* web_contents = tab_util::GetWebContentsByID( |
| 275 render_process_id, render_view_id); |
| 276 |
| 277 Profile* profile = |
| 278 Profile::FromBrowserContext(web_contents->GetBrowserContext()); |
| 279 |
| 280 should_show_balloon_ = true; |
| 281 extensions::ImageLoader::Get(profile)->LoadImageAsync( |
274 extension, | 282 extension, |
275 extension->GetIconResource(32, ExtensionIconSet::MATCH_BIGGER), | 283 extension->GetIconResource(32, ExtensionIconSet::MATCH_BIGGER), |
276 gfx::Size(32, 32), | 284 gfx::Size(32, 32), |
277 ImageLoadingTracker::CACHE); | 285 base::Bind(&MediaStreamCaptureIndicator::OnImageLoaded, |
| 286 this, message)); |
278 return; | 287 return; |
279 } | 288 } |
280 | 289 |
281 string16 title = l10n_util::GetStringUTF16(IDS_PRODUCT_NAME); | 290 string16 title = l10n_util::GetStringUTF16(IDS_PRODUCT_NAME); |
282 string16 body = l10n_util::GetStringFUTF16(message_id, | 291 string16 body = l10n_util::GetStringFUTF16(message_id, |
283 GetSecurityOrigin(render_process_id, render_view_id)); | 292 GetSecurityOrigin(render_process_id, render_view_id)); |
284 status_icon_->DisplayBalloon(*balloon_image_, title, body); | 293 status_icon_->DisplayBalloon(*balloon_image_, title, body); |
285 } | 294 } |
286 | 295 |
287 void MediaStreamCaptureIndicator::OnImageLoaded( | 296 void MediaStreamCaptureIndicator::OnImageLoaded( |
288 const gfx::Image& image, | 297 const string16& message, |
289 const std::string& extension_id, | 298 const gfx::Image& image) { |
290 int index) { | 299 if (!should_show_balloon_) |
291 string16 message; | 300 return; |
292 message.swap(pending_messages_[index]); | |
293 pending_messages_.erase(index); | |
294 | 301 |
295 const gfx::ImageSkia* image_skia = !image.IsEmpty() ? image.ToImageSkia() : | 302 const gfx::ImageSkia* image_skia = !image.IsEmpty() ? image.ToImageSkia() : |
296 ui::ResourceBundle::GetSharedInstance().GetImageSkiaNamed( | 303 ui::ResourceBundle::GetSharedInstance().GetImageSkiaNamed( |
297 IDR_APP_DEFAULT_ICON); | 304 IDR_APP_DEFAULT_ICON); |
298 status_icon_->DisplayBalloon(*image_skia, string16(), message); | 305 status_icon_->DisplayBalloon(*image_skia, string16(), message); |
299 } | 306 } |
300 | 307 |
301 void MediaStreamCaptureIndicator::Hide() { | 308 void MediaStreamCaptureIndicator::Hide() { |
302 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); | 309 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); |
303 DCHECK(tabs_.empty()); | 310 DCHECK(tabs_.empty()); |
304 | 311 |
305 // We have to destroy |tracker_| on the UI thread. | 312 // Make sure images that finish loading don't cause a balloon to be shown. |
306 tracker_.reset(); | 313 should_show_balloon_ = false; |
307 | 314 |
308 if (!status_icon_) | 315 if (!status_icon_) |
309 return; | 316 return; |
310 | 317 |
311 // If there is no browser process, we should not do anything. | 318 // If there is no browser process, we should not do anything. |
312 if (!g_browser_process) | 319 if (!g_browser_process) |
313 return; | 320 return; |
314 | 321 |
315 StatusTray* status_tray = g_browser_process->status_tray(); | 322 StatusTray* status_tray = g_browser_process->status_tray(); |
316 if (status_tray != NULL) { | 323 if (status_tray != NULL) { |
(...skipping 144 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
461 | 468 |
462 bool MediaStreamCaptureIndicator::IsProcessCapturing(int render_process_id, | 469 bool MediaStreamCaptureIndicator::IsProcessCapturing(int render_process_id, |
463 int render_view_id) const { | 470 int render_view_id) const { |
464 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); | 471 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); |
465 CaptureDeviceTabs::const_iterator iter = std::find_if( | 472 CaptureDeviceTabs::const_iterator iter = std::find_if( |
466 tabs_.begin(), tabs_.end(), TabEquals(render_process_id, render_view_id)); | 473 tabs_.begin(), tabs_.end(), TabEquals(render_process_id, render_view_id)); |
467 if (iter == tabs_.end()) | 474 if (iter == tabs_.end()) |
468 return false; | 475 return false; |
469 return (iter->audio_ref_count > 0 || iter->video_ref_count > 0); | 476 return (iter->audio_ref_count > 0 || iter->video_ref_count > 0); |
470 } | 477 } |
471 | |
472 void MediaStreamCaptureIndicator::EnsureImageLoadingTracker() { | |
473 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); | |
474 if (tracker_.get()) | |
475 return; | |
476 | |
477 tracker_.reset(new ImageLoadingTracker(this)); | |
478 pending_messages_.clear(); | |
479 request_index_ = 0; | |
480 } | |
OLD | NEW |