Chromium Code Reviews| Index: chrome/browser/media/media_stream_capture_indicator.cc |
| diff --git a/chrome/browser/media/media_stream_capture_indicator.cc b/chrome/browser/media/media_stream_capture_indicator.cc |
| index 9467b7e60516654c23fd79697f47d10bb2a24984..5511ad2cef66797fa7ac05c80cc0d4e57aa40aec 100644 |
| --- a/chrome/browser/media/media_stream_capture_indicator.cc |
| +++ b/chrome/browser/media/media_stream_capture_indicator.cc |
| @@ -9,6 +9,8 @@ |
| #include "base/utf_string_conversions.h" |
| #include "chrome/app/chrome_command_ids.h" |
| #include "chrome/browser/browser_process.h" |
| +#include "chrome/browser/extensions/extension_service.h" |
| +#include "chrome/browser/profiles/profile.h" |
| #include "chrome/browser/status_icons/status_icon.h" |
| #include "chrome/browser/status_icons/status_tray.h" |
| #include "chrome/browser/tab_contents/tab_util.h" |
| @@ -27,6 +29,83 @@ |
| using content::BrowserThread; |
| using content::WebContents; |
| +namespace { |
| + |
| +const extensions::Extension* GetExtension(int render_process_id, |
| + int render_view_id) { |
| + DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); |
| + |
| + WebContents* web_contents = tab_util::GetWebContentsByID( |
| + render_process_id, render_view_id); |
| + if (!web_contents) |
| + return NULL; |
| + |
| + Profile* profile = |
| + Profile::FromBrowserContext(web_contents->GetBrowserContext()); |
| + if (!profile) |
| + return NULL; |
| + |
| + ExtensionService* extensions = profile->GetExtensionService(); |
|
Mihai Parparita -not on Chrome
2012/08/01 05:12:37
Nit: can you call this extensions_service, so that
Evan Stade
2012/08/07 02:18:32
Done.
|
| + if (!extensions) |
| + return NULL; |
| + |
| + return extensions->extensions()->GetExtensionOrAppByURL( |
| + ExtensionURLInfo(web_contents->GetURL())); |
| +} |
| + |
| +// Gets the security originator of the tab. It returns a string with no '/' |
| +// at the end to display in the UI. |
| +string16 GetSecurityOrigin(int render_process_id, int render_view_id) { |
| + DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); |
| + WebContents* tab_content = tab_util::GetWebContentsByID( |
| + render_process_id, render_view_id); |
| + if (!tab_content) |
| + return string16(); |
| + |
| + std::string security_origin = tab_content->GetURL().GetOrigin().spec(); |
| + |
| + // Remove the last character if it is a '/'. |
| + if (!security_origin.empty()) { |
| + std::string::iterator it = security_origin.end() - 1; |
| + if (*it == '/') |
| + security_origin.erase(it); |
| + } |
| + |
| + return UTF8ToUTF16(security_origin); |
| +} |
| + |
| +string16 GetTitle(int render_process_id, int render_view_id) { |
| + DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); |
| + |
| + const extensions::Extension* extension = |
| + GetExtension(render_process_id, render_view_id); |
| + if (extension) |
| + return UTF8ToUTF16(extension->name()); |
| + |
| + WebContents* tab_content = tab_util::GetWebContentsByID( |
| + render_process_id, render_view_id); |
| + if (!tab_content) |
| + return string16(); |
| + |
| + string16 tab_title = tab_content->GetTitle(); |
| + |
| + if (tab_title.empty()) { |
| + // If the page's title is empty use its security originator. |
| + tab_title = GetSecurityOrigin(render_process_id, render_view_id); |
| + } else { |
| + // If the page's title matches its URL, use its security originator. |
| + std::string languages = |
| + content::GetContentClient()->browser()->GetAcceptLangs( |
| + tab_content->GetBrowserContext()); |
| + if (tab_title == net::FormatUrl(tab_content->GetURL(), languages)) |
| + tab_title = GetSecurityOrigin(render_process_id, render_view_id); |
| + } |
| + |
| + return tab_title; |
| +} |
| + |
| +} // namespace |
| + |
| MediaStreamCaptureIndicator::TabEquals::TabEquals(int render_process_id, |
| int render_view_id) |
| : render_process_id_(render_process_id), |
| @@ -42,7 +121,8 @@ MediaStreamCaptureIndicator::MediaStreamCaptureIndicator() |
| : status_icon_(NULL), |
| mic_image_(NULL), |
| camera_image_(NULL), |
| - balloon_image_(NULL) { |
| + balloon_image_(NULL), |
| + ALLOW_THIS_IN_INITIALIZER_LIST(tracker_(this)) { |
| } |
| MediaStreamCaptureIndicator::~MediaStreamCaptureIndicator() { |
| @@ -178,10 +258,9 @@ void MediaStreamCaptureIndicator::ShowBalloon( |
| int render_process_id, |
| int render_view_id, |
| bool audio, |
| - bool video) const { |
| + bool video) { |
| DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); |
| DCHECK(audio || video); |
| - string16 title = l10n_util::GetStringUTF16(IDS_PRODUCT_NAME); |
| int message_id = IDS_MEDIA_STREAM_STATUS_TRAY_BALLOON_BODY_AUDIO_AND_VIDEO; |
| if (audio && !video) |
| @@ -189,12 +268,41 @@ void MediaStreamCaptureIndicator::ShowBalloon( |
| else if (!audio && video) |
| message_id = IDS_MEDIA_STREAM_STATUS_TRAY_BALLOON_BODY_VIDEO_ONLY; |
| - string16 body = l10n_util::GetStringFUTF16( |
| - message_id, GetSecurityOrigin(render_process_id, render_view_id)); |
| + const extensions::Extension* extension = |
| + GetExtension(render_process_id, render_view_id); |
| + if (extension) { |
| + pending_messages_.push_back( |
| + l10n_util::GetStringFUTF16(message_id, |
| + UTF8ToUTF16(extension->name()))); |
| + tracker_.LoadImage( |
| + extension, |
| + extension->GetIconResource(32, ExtensionIconSet::MATCH_BIGGER), |
| + gfx::Size(32, 32), |
| + ImageLoadingTracker::CACHE); |
| + return; |
| + } |
| + string16 title = l10n_util::GetStringUTF16(IDS_PRODUCT_NAME); |
| + string16 body = l10n_util::GetStringFUTF16(message_id, |
| + GetSecurityOrigin(render_process_id, render_view_id)); |
| status_icon_->DisplayBalloon(*balloon_image_, title, body); |
| } |
| +void MediaStreamCaptureIndicator::OnImageLoaded( |
| + const gfx::Image& image, |
| + const std::string& extension_id, |
| + int index) { |
| + string16 message; |
| + message.swap(pending_messages_[index]); |
|
Evan Stade
2012/07/31 23:19:29
this leaks... the vector never gets smaller. But i
scherkus (not reviewing)
2012/08/01 00:18:17
I'm not super familiar with ImageLoadingTracker bu
no longer working on chromium
2012/08/01 07:54:14
should we just use erase to completely delete the
Evan Stade
2012/08/01 22:25:15
erase will move the rest of the elements in the ve
scherkus (not reviewing)
2012/08/01 22:40:08
I was thinking ImageLoadingTracker::Observer could
|
| + |
| + status_icon_->DisplayBalloon( |
| + !image.IsEmpty() ? *image.ToImageSkia() : |
| + *ResourceBundle::GetSharedInstance().GetImageSkiaNamed( |
| + IDR_APP_DEFAULT_ICON), |
| + string16(), |
| + message); |
| +} |
| + |
| void MediaStreamCaptureIndicator::Hide() { |
| DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); |
| if (!status_icon_) |
| @@ -335,47 +443,3 @@ void MediaStreamCaptureIndicator::RemoveCaptureDeviceTab( |
| UpdateStatusTrayIconContextMenu(); |
| } |
| -string16 MediaStreamCaptureIndicator::GetTitle(int render_process_id, |
| - int render_view_id) const { |
| - DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); |
| - WebContents* tab_content = tab_util::GetWebContentsByID( |
| - render_process_id, render_view_id); |
| - if (!tab_content) |
| - return string16(); |
| - |
| - string16 tab_title = tab_content->GetTitle(); |
| - |
| - if (tab_title.empty()) { |
| - // If the page's title is empty use its security originator. |
| - tab_title = GetSecurityOrigin(render_process_id, render_view_id); |
| - } else { |
| - // If the page's title matches its URL, use its security originator. |
| - std::string languages = |
| - content::GetContentClient()->browser()->GetAcceptLangs( |
| - tab_content->GetBrowserContext()); |
| - if (tab_title == net::FormatUrl(tab_content->GetURL(), languages)) |
| - tab_title = GetSecurityOrigin(render_process_id, render_view_id); |
| - } |
| - |
| - return tab_title; |
| -} |
| - |
| -string16 MediaStreamCaptureIndicator::GetSecurityOrigin( |
| - int render_process_id, int render_view_id) const { |
| - DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); |
| - WebContents* tab_content = tab_util::GetWebContentsByID( |
| - render_process_id, render_view_id); |
| - if (!tab_content) |
| - return string16(); |
| - |
| - std::string security_origin = tab_content->GetURL().GetOrigin().spec(); |
| - |
| - // Remove the last character if it is a '/'. |
| - if (!security_origin.empty()) { |
| - std::string::iterator it = security_origin.end() - 1; |
| - if (*it == '/') |
| - security_origin.erase(it); |
| - } |
| - |
| - return UTF8ToUTF16(security_origin); |
| -} |