| 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/webrtc/media_stream_capture_indicator.h" | 5 #include "chrome/browser/media/webrtc/media_stream_capture_indicator.h" |
| 6 | 6 |
| 7 #include <stddef.h> | 7 #include <stddef.h> |
| 8 | 8 |
| 9 #include <memory> | 9 #include <memory> |
| 10 #include <string> | 10 #include <string> |
| 11 #include <utility> | 11 #include <utility> |
| 12 | 12 |
| 13 #include "base/logging.h" | 13 #include "base/logging.h" |
| 14 #include "base/macros.h" | 14 #include "base/macros.h" |
| 15 #include "base/memory/ptr_util.h" | 15 #include "base/memory/ptr_util.h" |
| 16 #include "base/strings/utf_string_conversions.h" | 16 #include "base/strings/utf_string_conversions.h" |
| 17 #include "chrome/app/chrome_command_ids.h" | 17 #include "chrome/app/chrome_command_ids.h" |
| 18 #include "chrome/browser/browser_process.h" | 18 #include "chrome/browser/browser_process.h" |
| 19 #include "chrome/browser/status_icons/status_icon.h" | 19 #include "chrome/browser/status_icons/status_icon.h" |
| 20 #include "chrome/browser/status_icons/status_tray.h" | 20 #include "chrome/browser/status_icons/status_tray.h" |
| 21 #include "chrome/browser/tab_contents/tab_util.h" | 21 #include "chrome/browser/tab_contents/tab_util.h" |
| 22 #include "chrome/grit/chromium_strings.h" | 22 #include "chrome/grit/chromium_strings.h" |
| 23 #include "chrome/grit/theme_resources.h" | 23 #include "chrome/grit/theme_resources.h" |
| 24 #include "components/url_formatter/elide_url.h" | 24 #include "components/url_formatter/elide_url.h" |
| 25 #include "content/public/browser/browser_thread.h" | 25 #include "content/public/browser/browser_thread.h" |
| 26 #include "content/public/browser/content_browser_client.h" | 26 #include "content/public/browser/content_browser_client.h" |
| 27 #include "content/public/browser/web_contents.h" | 27 #include "content/public/browser/web_contents.h" |
| 28 #include "content/public/browser/web_contents_delegate.h" | 28 #include "content/public/browser/web_contents_delegate.h" |
| 29 #include "content/public/browser/web_contents_observer.h" | 29 #include "content/public/browser/web_contents_observer.h" |
| 30 #include "extensions/features/features.h" |
| 30 #include "ui/base/l10n/l10n_util.h" | 31 #include "ui/base/l10n/l10n_util.h" |
| 31 #include "ui/base/resource/resource_bundle.h" | 32 #include "ui/base/resource/resource_bundle.h" |
| 32 #include "ui/gfx/image/image_skia.h" | 33 #include "ui/gfx/image/image_skia.h" |
| 33 | 34 |
| 34 #if defined(ENABLE_EXTENSIONS) | 35 #if BUILDFLAG(ENABLE_EXTENSIONS) |
| 35 #include "chrome/common/extensions/extension_constants.h" | 36 #include "chrome/common/extensions/extension_constants.h" |
| 36 #include "extensions/browser/extension_registry.h" | 37 #include "extensions/browser/extension_registry.h" |
| 37 #include "extensions/common/extension.h" | 38 #include "extensions/common/extension.h" |
| 38 #endif | 39 #endif |
| 39 | 40 |
| 40 using content::BrowserThread; | 41 using content::BrowserThread; |
| 41 using content::WebContents; | 42 using content::WebContents; |
| 42 | 43 |
| 43 namespace { | 44 namespace { |
| 44 | 45 |
| 45 #if defined(ENABLE_EXTENSIONS) | 46 #if BUILDFLAG(ENABLE_EXTENSIONS) |
| 46 const extensions::Extension* GetExtension(WebContents* web_contents) { | 47 const extensions::Extension* GetExtension(WebContents* web_contents) { |
| 47 DCHECK_CURRENTLY_ON(BrowserThread::UI); | 48 DCHECK_CURRENTLY_ON(BrowserThread::UI); |
| 48 | 49 |
| 49 if (!web_contents) | 50 if (!web_contents) |
| 50 return NULL; | 51 return NULL; |
| 51 | 52 |
| 52 extensions::ExtensionRegistry* registry = | 53 extensions::ExtensionRegistry* registry = |
| 53 extensions::ExtensionRegistry::Get(web_contents->GetBrowserContext()); | 54 extensions::ExtensionRegistry::Get(web_contents->GetBrowserContext()); |
| 54 return registry->enabled_extensions().GetExtensionOrAppByURL( | 55 return registry->enabled_extensions().GetExtensionOrAppByURL( |
| 55 web_contents->GetURL()); | 56 web_contents->GetURL()); |
| 56 } | 57 } |
| 57 | 58 |
| 58 bool IsWhitelistedExtension(const extensions::Extension* extension) { | 59 bool IsWhitelistedExtension(const extensions::Extension* extension) { |
| 59 DCHECK_CURRENTLY_ON(BrowserThread::UI); | 60 DCHECK_CURRENTLY_ON(BrowserThread::UI); |
| 60 | 61 |
| 61 static const char* const kExtensionWhitelist[] = { | 62 static const char* const kExtensionWhitelist[] = { |
| 62 extension_misc::kHotwordNewExtensionId, | 63 extension_misc::kHotwordNewExtensionId, |
| 63 }; | 64 }; |
| 64 | 65 |
| 65 for (size_t i = 0; i < arraysize(kExtensionWhitelist); ++i) { | 66 for (size_t i = 0; i < arraysize(kExtensionWhitelist); ++i) { |
| 66 if (extension->id() == kExtensionWhitelist[i]) | 67 if (extension->id() == kExtensionWhitelist[i]) |
| 67 return true; | 68 return true; |
| 68 } | 69 } |
| 69 | 70 |
| 70 return false; | 71 return false; |
| 71 } | 72 } |
| 72 #endif // defined(ENABLE_EXTENSIONS) | 73 #endif // BUILDFLAG(ENABLE_EXTENSIONS) |
| 73 | 74 |
| 74 base::string16 GetTitle(WebContents* web_contents) { | 75 base::string16 GetTitle(WebContents* web_contents) { |
| 75 DCHECK_CURRENTLY_ON(BrowserThread::UI); | 76 DCHECK_CURRENTLY_ON(BrowserThread::UI); |
| 76 | 77 |
| 77 if (!web_contents) | 78 if (!web_contents) |
| 78 return base::string16(); | 79 return base::string16(); |
| 79 | 80 |
| 80 #if defined(ENABLE_EXTENSIONS) | 81 #if BUILDFLAG(ENABLE_EXTENSIONS) |
| 81 const extensions::Extension* const extension = GetExtension(web_contents); | 82 const extensions::Extension* const extension = GetExtension(web_contents); |
| 82 if (extension) | 83 if (extension) |
| 83 return base::UTF8ToUTF16(extension->name()); | 84 return base::UTF8ToUTF16(extension->name()); |
| 84 #endif | 85 #endif |
| 85 | 86 |
| 86 return url_formatter::FormatUrlForSecurityDisplay(web_contents->GetURL()); | 87 return url_formatter::FormatUrlForSecurityDisplay(web_contents->GetURL()); |
| 87 } | 88 } |
| 88 | 89 |
| 89 } // namespace | 90 } // namespace |
| 90 | 91 |
| (...skipping 308 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 399 // Check if any audio and video devices have been used. | 400 // Check if any audio and video devices have been used. |
| 400 const WebContentsDeviceUsage& usage = *it.second; | 401 const WebContentsDeviceUsage& usage = *it.second; |
| 401 if (!usage.IsCapturingAudio() && !usage.IsCapturingVideo()) | 402 if (!usage.IsCapturingAudio() && !usage.IsCapturingVideo()) |
| 402 continue; | 403 continue; |
| 403 | 404 |
| 404 WebContents* const web_contents = it.first; | 405 WebContents* const web_contents = it.first; |
| 405 | 406 |
| 406 // The audio/video icon is shown only for non-whitelisted extensions or on | 407 // The audio/video icon is shown only for non-whitelisted extensions or on |
| 407 // Android. For regular tabs on desktop, we show an indicator in the tab | 408 // Android. For regular tabs on desktop, we show an indicator in the tab |
| 408 // icon. | 409 // icon. |
| 409 #if defined(ENABLE_EXTENSIONS) | 410 #if BUILDFLAG(ENABLE_EXTENSIONS) |
| 410 const extensions::Extension* extension = GetExtension(web_contents); | 411 const extensions::Extension* extension = GetExtension(web_contents); |
| 411 if (!extension || IsWhitelistedExtension(extension)) | 412 if (!extension || IsWhitelistedExtension(extension)) |
| 412 continue; | 413 continue; |
| 413 #endif | 414 #endif |
| 414 | 415 |
| 415 audio = audio || usage.IsCapturingAudio(); | 416 audio = audio || usage.IsCapturingAudio(); |
| 416 video = video || usage.IsCapturingVideo(); | 417 video = video || usage.IsCapturingVideo(); |
| 417 | 418 |
| 418 command_targets_.push_back(web_contents); | 419 command_targets_.push_back(web_contents); |
| 419 menu->AddItem(command_id, GetTitle(web_contents)); | 420 menu->AddItem(command_id, GetTitle(web_contents)); |
| (...skipping 36 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 456 } else if (audio && !video) { | 457 } else if (audio && !video) { |
| 457 message_id = IDS_MEDIA_STREAM_STATUS_TRAY_TEXT_AUDIO_ONLY; | 458 message_id = IDS_MEDIA_STREAM_STATUS_TRAY_TEXT_AUDIO_ONLY; |
| 458 *image = *mic_image_; | 459 *image = *mic_image_; |
| 459 } else if (!audio && video) { | 460 } else if (!audio && video) { |
| 460 message_id = IDS_MEDIA_STREAM_STATUS_TRAY_TEXT_VIDEO_ONLY; | 461 message_id = IDS_MEDIA_STREAM_STATUS_TRAY_TEXT_VIDEO_ONLY; |
| 461 *image = *camera_image_; | 462 *image = *camera_image_; |
| 462 } | 463 } |
| 463 | 464 |
| 464 *tool_tip = l10n_util::GetStringUTF16(message_id); | 465 *tool_tip = l10n_util::GetStringUTF16(message_id); |
| 465 } | 466 } |
| OLD | NEW |