| 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/memory/scoped_ptr.h" | 10 #include "base/memory/scoped_ptr.h" |
| 11 #include "base/prefs/pref_service.h" | 11 #include "base/prefs/pref_service.h" |
| 12 #include "base/strings/utf_string_conversions.h" | 12 #include "base/strings/utf_string_conversions.h" |
| 13 #include "chrome/app/chrome_command_ids.h" | 13 #include "chrome/app/chrome_command_ids.h" |
| 14 #include "chrome/browser/browser_process.h" | 14 #include "chrome/browser/browser_process.h" |
| 15 #include "chrome/browser/profiles/profile.h" | 15 #include "chrome/browser/profiles/profile.h" |
| 16 #include "chrome/browser/status_icons/status_icon.h" | 16 #include "chrome/browser/status_icons/status_icon.h" |
| 17 #include "chrome/browser/status_icons/status_tray.h" | 17 #include "chrome/browser/status_icons/status_tray.h" |
| 18 #include "chrome/browser/tab_contents/tab_util.h" | 18 #include "chrome/browser/tab_contents/tab_util.h" |
| 19 #include "chrome/common/extensions/extension_constants.h" | |
| 20 #include "chrome/common/pref_names.h" | 19 #include "chrome/common/pref_names.h" |
| 21 #include "content/public/browser/browser_thread.h" | 20 #include "content/public/browser/browser_thread.h" |
| 22 #include "content/public/browser/content_browser_client.h" | 21 #include "content/public/browser/content_browser_client.h" |
| 23 #include "content/public/browser/invalidate_type.h" | 22 #include "content/public/browser/invalidate_type.h" |
| 24 #include "content/public/browser/web_contents.h" | 23 #include "content/public/browser/web_contents.h" |
| 25 #include "content/public/browser/web_contents_delegate.h" | 24 #include "content/public/browser/web_contents_delegate.h" |
| 26 #include "content/public/browser/web_contents_observer.h" | 25 #include "content/public/browser/web_contents_observer.h" |
| 27 #include "extensions/browser/extension_registry.h" | |
| 28 #include "extensions/common/extension.h" | |
| 29 #include "grit/chromium_strings.h" | 26 #include "grit/chromium_strings.h" |
| 30 #include "grit/generated_resources.h" | 27 #include "grit/generated_resources.h" |
| 31 #include "grit/theme_resources.h" | 28 #include "grit/theme_resources.h" |
| 32 #include "net/base/net_util.h" | 29 #include "net/base/net_util.h" |
| 33 #include "ui/base/l10n/l10n_util.h" | 30 #include "ui/base/l10n/l10n_util.h" |
| 34 #include "ui/base/resource/resource_bundle.h" | 31 #include "ui/base/resource/resource_bundle.h" |
| 35 #include "ui/gfx/image/image_skia.h" | 32 #include "ui/gfx/image/image_skia.h" |
| 36 | 33 |
| 34 #if defined(ENABLE_EXTENSIONS) |
| 35 #include "chrome/common/extensions/extension_constants.h" |
| 36 #include "extensions/browser/extension_registry.h" |
| 37 #include "extensions/common/extension.h" |
| 38 #endif |
| 39 |
| 37 using content::BrowserThread; | 40 using content::BrowserThread; |
| 38 using content::WebContents; | 41 using content::WebContents; |
| 39 | 42 |
| 40 namespace { | 43 namespace { |
| 41 | 44 |
| 45 #if defined(ENABLE_EXTENSIONS) |
| 42 const extensions::Extension* GetExtension(WebContents* web_contents) { | 46 const extensions::Extension* GetExtension(WebContents* web_contents) { |
| 43 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); | 47 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); |
| 44 | 48 |
| 45 if (!web_contents) | 49 if (!web_contents) |
| 46 return NULL; | 50 return NULL; |
| 47 | 51 |
| 48 extensions::ExtensionRegistry* registry = | 52 extensions::ExtensionRegistry* registry = |
| 49 extensions::ExtensionRegistry::Get(web_contents->GetBrowserContext()); | 53 extensions::ExtensionRegistry::Get(web_contents->GetBrowserContext()); |
| 50 return registry->enabled_extensions().GetExtensionOrAppByURL( | 54 return registry->enabled_extensions().GetExtensionOrAppByURL( |
| 51 web_contents->GetURL()); | 55 web_contents->GetURL()); |
| 52 } | 56 } |
| 53 | 57 |
| 54 #if !defined(OS_ANDROID) | |
| 55 | |
| 56 bool IsWhitelistedExtension(const extensions::Extension* extension) { | 58 bool IsWhitelistedExtension(const extensions::Extension* extension) { |
| 57 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); | 59 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); |
| 58 | 60 |
| 59 static const char* const kExtensionWhitelist[] = { | 61 static const char* const kExtensionWhitelist[] = { |
| 60 extension_misc::kHotwordExtensionId, | 62 extension_misc::kHotwordExtensionId, |
| 61 }; | 63 }; |
| 62 | 64 |
| 63 for (size_t i = 0; i < arraysize(kExtensionWhitelist); ++i) { | 65 for (size_t i = 0; i < arraysize(kExtensionWhitelist); ++i) { |
| 64 if (extension->id() == kExtensionWhitelist[i]) | 66 if (extension->id() == kExtensionWhitelist[i]) |
| 65 return true; | 67 return true; |
| 66 } | 68 } |
| 67 | 69 |
| 68 return false; | 70 return false; |
| 69 } | 71 } |
| 70 | 72 #endif // defined(ENABLE_EXTENSIONS) |
| 71 #endif // !defined(OS_ANDROID) | |
| 72 | 73 |
| 73 // Gets the security originator of the tab. It returns a string with no '/' | 74 // Gets the security originator of the tab. It returns a string with no '/' |
| 74 // at the end to display in the UI. | 75 // at the end to display in the UI. |
| 75 base::string16 GetSecurityOrigin(WebContents* web_contents) { | 76 base::string16 GetSecurityOrigin(WebContents* web_contents) { |
| 76 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); | 77 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); |
| 77 | 78 |
| 78 if (!web_contents) | 79 if (!web_contents) |
| 79 return base::string16(); | 80 return base::string16(); |
| 80 | 81 |
| 81 std::string security_origin = web_contents->GetURL().GetOrigin().spec(); | 82 std::string security_origin = web_contents->GetURL().GetOrigin().spec(); |
| 82 | 83 |
| 83 // Remove the last character if it is a '/'. | 84 // Remove the last character if it is a '/'. |
| 84 if (!security_origin.empty()) { | 85 if (!security_origin.empty()) { |
| 85 std::string::iterator it = security_origin.end() - 1; | 86 std::string::iterator it = security_origin.end() - 1; |
| 86 if (*it == '/') | 87 if (*it == '/') |
| 87 security_origin.erase(it); | 88 security_origin.erase(it); |
| 88 } | 89 } |
| 89 | 90 |
| 90 return base::UTF8ToUTF16(security_origin); | 91 return base::UTF8ToUTF16(security_origin); |
| 91 } | 92 } |
| 92 | 93 |
| 93 base::string16 GetTitle(WebContents* web_contents) { | 94 base::string16 GetTitle(WebContents* web_contents) { |
| 94 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); | 95 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); |
| 95 | 96 |
| 96 if (!web_contents) | 97 if (!web_contents) |
| 97 return base::string16(); | 98 return base::string16(); |
| 98 | 99 |
| 100 #if defined(ENABLE_EXTENSIONS) |
| 99 const extensions::Extension* const extension = GetExtension(web_contents); | 101 const extensions::Extension* const extension = GetExtension(web_contents); |
| 100 if (extension) | 102 if (extension) |
| 101 return base::UTF8ToUTF16(extension->name()); | 103 return base::UTF8ToUTF16(extension->name()); |
| 104 #endif |
| 102 | 105 |
| 103 base::string16 tab_title = web_contents->GetTitle(); | 106 base::string16 tab_title = web_contents->GetTitle(); |
| 104 | 107 |
| 105 if (tab_title.empty()) { | 108 if (tab_title.empty()) { |
| 106 // If the page's title is empty use its security originator. | 109 // If the page's title is empty use its security originator. |
| 107 tab_title = GetSecurityOrigin(web_contents); | 110 tab_title = GetSecurityOrigin(web_contents); |
| 108 } else { | 111 } else { |
| 109 // If the page's title matches its URL, use its security originator. | 112 // If the page's title matches its URL, use its security originator. |
| 110 Profile* profile = | 113 Profile* profile = |
| 111 Profile::FromBrowserContext(web_contents->GetBrowserContext()); | 114 Profile::FromBrowserContext(web_contents->GetBrowserContext()); |
| (...skipping 307 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 419 // Check if any audio and video devices have been used. | 422 // Check if any audio and video devices have been used. |
| 420 const WebContentsDeviceUsage& usage = *iter->second; | 423 const WebContentsDeviceUsage& usage = *iter->second; |
| 421 if (!usage.IsCapturingAudio() && !usage.IsCapturingVideo()) | 424 if (!usage.IsCapturingAudio() && !usage.IsCapturingVideo()) |
| 422 continue; | 425 continue; |
| 423 | 426 |
| 424 WebContents* const web_contents = iter->first; | 427 WebContents* const web_contents = iter->first; |
| 425 | 428 |
| 426 // The audio/video icon is shown only for non-whitelisted extensions or on | 429 // The audio/video icon is shown only for non-whitelisted extensions or on |
| 427 // Android. For regular tabs on desktop, we show an indicator in the tab | 430 // Android. For regular tabs on desktop, we show an indicator in the tab |
| 428 // icon. | 431 // icon. |
| 429 #if !defined(OS_ANDROID) | 432 #if defined(ENABLE_EXTENSIONS) |
| 430 const extensions::Extension* extension = GetExtension(web_contents); | 433 const extensions::Extension* extension = GetExtension(web_contents); |
| 431 if (!extension || IsWhitelistedExtension(extension)) | 434 if (!extension || IsWhitelistedExtension(extension)) |
| 432 continue; | 435 continue; |
| 433 #endif | 436 #endif |
| 434 | 437 |
| 435 audio = audio || usage.IsCapturingAudio(); | 438 audio = audio || usage.IsCapturingAudio(); |
| 436 video = video || usage.IsCapturingVideo(); | 439 video = video || usage.IsCapturingVideo(); |
| 437 | 440 |
| 438 command_targets_.push_back(web_contents); | 441 command_targets_.push_back(web_contents); |
| 439 menu->AddItem(command_id, GetTitle(web_contents)); | 442 menu->AddItem(command_id, GetTitle(web_contents)); |
| (...skipping 35 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 475 } else if (audio && !video) { | 478 } else if (audio && !video) { |
| 476 message_id = IDS_MEDIA_STREAM_STATUS_TRAY_TEXT_AUDIO_ONLY; | 479 message_id = IDS_MEDIA_STREAM_STATUS_TRAY_TEXT_AUDIO_ONLY; |
| 477 *image = *mic_image_; | 480 *image = *mic_image_; |
| 478 } else if (!audio && video) { | 481 } else if (!audio && video) { |
| 479 message_id = IDS_MEDIA_STREAM_STATUS_TRAY_TEXT_VIDEO_ONLY; | 482 message_id = IDS_MEDIA_STREAM_STATUS_TRAY_TEXT_VIDEO_ONLY; |
| 480 *image = *camera_image_; | 483 *image = *camera_image_; |
| 481 } | 484 } |
| 482 | 485 |
| 483 *tool_tip = l10n_util::GetStringUTF16(message_id); | 486 *tool_tip = l10n_util::GetStringUTF16(message_id); |
| 484 } | 487 } |
| OLD | NEW |