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/utf_string_conversions.h" | 9 #include "base/utf_string_conversions.h" |
10 #include "chrome/app/chrome_command_ids.h" | 10 #include "chrome/app/chrome_command_ids.h" |
(...skipping 196 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
207 } | 207 } |
208 | 208 |
209 void MediaStreamCaptureIndicator::DoDevicesClosedOnUIThread( | 209 void MediaStreamCaptureIndicator::DoDevicesClosedOnUIThread( |
210 int render_process_id, | 210 int render_process_id, |
211 int render_view_id, | 211 int render_view_id, |
212 const content::MediaStreamDevices& devices) { | 212 const content::MediaStreamDevices& devices) { |
213 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); | 213 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); |
214 if (!status_icon_) | 214 if (!status_icon_) |
215 return; | 215 return; |
216 | 216 |
217 DCHECK(!tabs_.empty()); | |
218 RemoveCaptureDeviceTab(render_process_id, render_view_id, devices); | 217 RemoveCaptureDeviceTab(render_process_id, render_view_id, devices); |
219 } | 218 } |
220 | 219 |
221 void MediaStreamCaptureIndicator::CreateStatusTray() { | 220 void MediaStreamCaptureIndicator::CreateStatusTray() { |
222 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); | 221 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); |
223 if (status_icon_) | 222 if (status_icon_) |
224 return; | 223 return; |
225 | 224 |
226 // If there is no browser process, we should not create the status tray. | 225 // If there is no browser process, we should not create the status tray. |
227 if (!g_browser_process) | 226 if (!g_browser_process) |
(...skipping 72 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
300 status_icon_->DisplayBalloon( | 299 status_icon_->DisplayBalloon( |
301 !image.IsEmpty() ? *image.ToImageSkia() : | 300 !image.IsEmpty() ? *image.ToImageSkia() : |
302 *ResourceBundle::GetSharedInstance().GetImageSkiaNamed( | 301 *ResourceBundle::GetSharedInstance().GetImageSkiaNamed( |
303 IDR_APP_DEFAULT_ICON), | 302 IDR_APP_DEFAULT_ICON), |
304 string16(), | 303 string16(), |
305 message); | 304 message); |
306 } | 305 } |
307 | 306 |
308 void MediaStreamCaptureIndicator::Hide() { | 307 void MediaStreamCaptureIndicator::Hide() { |
309 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); | 308 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); |
| 309 DCHECK(tabs_.empty()); |
310 if (!status_icon_) | 310 if (!status_icon_) |
311 return; | 311 return; |
312 | 312 |
313 // If there is no browser process, we should not do anything. | 313 // If there is no browser process, we should not do anything. |
314 if (!g_browser_process) | 314 if (!g_browser_process) |
315 return; | 315 return; |
316 | 316 |
317 StatusTray* status_tray = g_browser_process->status_tray(); | 317 StatusTray* status_tray = g_browser_process->status_tray(); |
318 if (status_tray != NULL) { | 318 if (status_tray != NULL) { |
319 status_tray->RemoveStatusIcon(status_icon_); | 319 status_tray->RemoveStatusIcon(status_icon_); |
320 status_icon_ = NULL; | 320 status_icon_ = NULL; |
321 } | 321 } |
322 } | 322 } |
323 | 323 |
324 void MediaStreamCaptureIndicator::UpdateStatusTrayIconContextMenu() { | 324 void MediaStreamCaptureIndicator::UpdateStatusTrayIconContextMenu() { |
325 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); | 325 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); |
326 scoped_ptr<ui::SimpleMenuModel> menu(new ui::SimpleMenuModel(this)); | 326 scoped_ptr<ui::SimpleMenuModel> menu(new ui::SimpleMenuModel(this)); |
327 | 327 |
328 bool audio = false; | 328 bool audio = false; |
329 bool video = false; | 329 bool video = false; |
330 int command_id = IDC_MEDIA_CONTEXT_MEDIA_STREAM_CAPTURE_LIST_FIRST; | 330 int command_id = IDC_MEDIA_CONTEXT_MEDIA_STREAM_CAPTURE_LIST_FIRST; |
331 for (CaptureDeviceTabs::iterator iter = tabs_.begin(); | 331 for (CaptureDeviceTabs::iterator iter = tabs_.begin(); |
332 iter != tabs_.end(); ++iter) { | 332 iter != tabs_.end(); ++iter) { |
333 string16 tab_title = GetTitle(iter->render_process_id, | 333 string16 tab_title = GetTitle(iter->render_process_id, |
334 iter->render_view_id); | 334 iter->render_view_id); |
335 // The tab has gone away. | 335 if (tab_title.empty()) { |
336 if (tab_title.empty()) | 336 // Delete the entry since the tab has gone away. |
| 337 tabs_.erase(iter); |
337 continue; | 338 continue; |
| 339 } |
338 | 340 |
339 // Check if any audio and video devices have been used. | 341 // Check if any audio and video devices have been used. |
340 audio = audio || iter->audio_ref_count > 0; | 342 audio = audio || iter->audio_ref_count > 0; |
341 video = video || iter->video_ref_count > 0; | 343 video = video || iter->video_ref_count > 0; |
342 | 344 |
343 string16 message = l10n_util::GetStringFUTF16( | 345 string16 message = l10n_util::GetStringFUTF16( |
344 IDS_MEDIA_STREAM_STATUS_TRAY_MENU_ITEM, tab_title); | 346 IDS_MEDIA_STREAM_STATUS_TRAY_MENU_ITEM, tab_title); |
345 menu->AddItem(command_id, message); | 347 menu->AddItem(command_id, message); |
346 | 348 |
347 // If reaching the maximum number, no more item will be added to the menu. | 349 // If reaching the maximum number, no more item will be added to the menu. |
348 if (command_id == IDC_MEDIA_CONTEXT_MEDIA_STREAM_CAPTURE_LIST_LAST) | 350 if (command_id == IDC_MEDIA_CONTEXT_MEDIA_STREAM_CAPTURE_LIST_LAST) |
349 break; | 351 break; |
350 | 352 |
351 ++command_id; | 353 ++command_id; |
352 } | 354 } |
353 | 355 |
354 // All the tabs have gone away. | 356 if (!audio && !video) { |
355 if (!audio && !video) | 357 Hide(); |
356 return; | 358 return; |
| 359 } |
357 | 360 |
358 // The icon will take the ownership of the passed context menu. | 361 // The icon will take the ownership of the passed context menu. |
359 status_icon_->SetContextMenu(menu.release()); | 362 status_icon_->SetContextMenu(menu.release()); |
360 UpdateStatusTrayIconDisplay(audio, video); | 363 UpdateStatusTrayIconDisplay(audio, video); |
361 } | 364 } |
362 | 365 |
363 void MediaStreamCaptureIndicator::UpdateStatusTrayIconDisplay( | 366 void MediaStreamCaptureIndicator::UpdateStatusTrayIconDisplay( |
364 bool audio, bool video) { | 367 bool audio, bool video) { |
365 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); | 368 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); |
366 DCHECK(audio || video); | 369 DCHECK(audio || video); |
(...skipping 65 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
432 --iter->video_ref_count; | 435 --iter->video_ref_count; |
433 | 436 |
434 DCHECK_GE(iter->audio_ref_count, 0); | 437 DCHECK_GE(iter->audio_ref_count, 0); |
435 DCHECK_GE(iter->video_ref_count, 0); | 438 DCHECK_GE(iter->video_ref_count, 0); |
436 } | 439 } |
437 | 440 |
438 // Remove the tab if all the devices have been closed. | 441 // Remove the tab if all the devices have been closed. |
439 if (iter->audio_ref_count == 0 && iter->video_ref_count == 0) | 442 if (iter->audio_ref_count == 0 && iter->video_ref_count == 0) |
440 tabs_.erase(iter); | 443 tabs_.erase(iter); |
441 | 444 |
442 if (tabs_.empty()) | 445 UpdateStatusTrayIconContextMenu(); |
443 Hide(); | |
444 else | |
445 UpdateStatusTrayIconContextMenu(); | |
446 } | 446 } |
447 | 447 |
OLD | NEW |