| OLD | NEW |
| (Empty) |
| 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 | |
| 3 // found in the LICENSE file. | |
| 4 | |
| 5 #include "chrome/browser/ui/media_stream_infobar_delegate.h" | |
| 6 | |
| 7 #include "base/logging.h" | |
| 8 #include "base/utf_string_conversions.h" | |
| 9 #include "chrome/browser/content_settings/tab_specific_content_settings.h" | |
| 10 #include "chrome/browser/google/google_util.h" | |
| 11 #include "chrome/browser/infobars/infobar_service.h" | |
| 12 #include "chrome/browser/profiles/profile.h" | |
| 13 #include "chrome/common/url_constants.h" | |
| 14 #include "content/public/browser/web_contents.h" | |
| 15 #include "googleurl/src/gurl.h" | |
| 16 #include "grit/generated_resources.h" | |
| 17 #include "grit/theme_resources.h" | |
| 18 #include "ui/base/l10n/l10n_util.h" | |
| 19 #include "ui/base/resource/resource_bundle.h" | |
| 20 | |
| 21 MediaStreamInfoBarDelegate::~MediaStreamInfoBarDelegate() {} | |
| 22 | |
| 23 // static | |
| 24 bool MediaStreamInfoBarDelegate::Create( | |
| 25 content::WebContents* web_contents, | |
| 26 const content::MediaStreamRequest& request, | |
| 27 const content::MediaResponseCallback& callback) { | |
| 28 Profile* profile = | |
| 29 Profile::FromBrowserContext(web_contents->GetBrowserContext()); | |
| 30 TabSpecificContentSettings* content_settings = | |
| 31 TabSpecificContentSettings::FromWebContents(web_contents); | |
| 32 scoped_ptr<MediaStreamDevicesController> controller( | |
| 33 new MediaStreamDevicesController(profile, content_settings, | |
| 34 request, callback)); | |
| 35 if (controller->DismissInfoBarAndTakeActionOnSettings()) | |
| 36 return false; | |
| 37 | |
| 38 InfoBarService* infobar_service = | |
| 39 InfoBarService::FromWebContents(web_contents); | |
| 40 InfoBarDelegate* old_infobar = NULL; | |
| 41 for (size_t i = 0; i < infobar_service->GetInfoBarCount(); ++i) { | |
| 42 old_infobar = infobar_service->GetInfoBarDelegateAt(i)-> | |
| 43 AsMediaStreamInfoBarDelegate(); | |
| 44 if (old_infobar) | |
| 45 break; | |
| 46 } | |
| 47 scoped_ptr<InfoBarDelegate> infobar( | |
| 48 new MediaStreamInfoBarDelegate(infobar_service, controller.release())); | |
| 49 if (old_infobar) | |
| 50 infobar_service->ReplaceInfoBar(old_infobar, infobar.Pass()); | |
| 51 else | |
| 52 infobar_service->AddInfoBar(infobar.Pass()); | |
| 53 | |
| 54 return true; | |
| 55 } | |
| 56 | |
| 57 void MediaStreamInfoBarDelegate::InfoBarDismissed() { | |
| 58 // Deny the request if the infobar was closed with the 'x' button, since | |
| 59 // we don't want WebRTC to be waiting for an answer that will never come. | |
| 60 controller_->Deny(false); | |
| 61 } | |
| 62 | |
| 63 gfx::Image* MediaStreamInfoBarDelegate::GetIcon() const { | |
| 64 return &ResourceBundle::GetSharedInstance().GetNativeImageNamed( | |
| 65 controller_->has_video() ? | |
| 66 IDR_INFOBAR_MEDIA_STREAM_CAMERA : IDR_INFOBAR_MEDIA_STREAM_MIC); | |
| 67 } | |
| 68 | |
| 69 InfoBarDelegate::Type MediaStreamInfoBarDelegate::GetInfoBarType() const { | |
| 70 return PAGE_ACTION_TYPE; | |
| 71 } | |
| 72 | |
| 73 MediaStreamInfoBarDelegate* | |
| 74 MediaStreamInfoBarDelegate::AsMediaStreamInfoBarDelegate() { | |
| 75 return this; | |
| 76 } | |
| 77 | |
| 78 string16 MediaStreamInfoBarDelegate::GetMessageText() const { | |
| 79 int message_id = IDS_MEDIA_CAPTURE_AUDIO_AND_VIDEO; | |
| 80 if (!controller_->has_audio()) | |
| 81 message_id = IDS_MEDIA_CAPTURE_VIDEO_ONLY; | |
| 82 else if (!controller_->has_video()) | |
| 83 message_id = IDS_MEDIA_CAPTURE_AUDIO_ONLY; | |
| 84 return l10n_util::GetStringFUTF16( | |
| 85 message_id, UTF8ToUTF16(controller_->GetSecurityOriginSpec())); | |
| 86 } | |
| 87 | |
| 88 string16 MediaStreamInfoBarDelegate::GetButtonLabel( | |
| 89 InfoBarButton button) const { | |
| 90 return l10n_util::GetStringUTF16((button == BUTTON_OK) ? | |
| 91 IDS_MEDIA_CAPTURE_ALLOW : IDS_MEDIA_CAPTURE_DENY); | |
| 92 } | |
| 93 | |
| 94 bool MediaStreamInfoBarDelegate::Accept() { | |
| 95 controller_->Accept(true); | |
| 96 return true; | |
| 97 } | |
| 98 | |
| 99 bool MediaStreamInfoBarDelegate::Cancel() { | |
| 100 controller_->Deny(true); | |
| 101 return true; | |
| 102 } | |
| 103 | |
| 104 string16 MediaStreamInfoBarDelegate::GetLinkText() const { | |
| 105 return l10n_util::GetStringUTF16(IDS_LEARN_MORE); | |
| 106 } | |
| 107 | |
| 108 bool MediaStreamInfoBarDelegate::LinkClicked( | |
| 109 WindowOpenDisposition disposition) { | |
| 110 content::OpenURLParams params( | |
| 111 google_util::AppendGoogleLocaleParam( | |
| 112 GURL(chrome::kMediaAccessLearnMoreUrl)), | |
| 113 content::Referrer(), | |
| 114 (disposition == CURRENT_TAB) ? NEW_FOREGROUND_TAB : disposition, | |
| 115 content::PAGE_TRANSITION_LINK, | |
| 116 false); | |
| 117 owner()->GetWebContents()->OpenURL(params); | |
| 118 | |
| 119 return false; // Do not dismiss the info bar. | |
| 120 } | |
| 121 | |
| 122 MediaStreamInfoBarDelegate::MediaStreamInfoBarDelegate( | |
| 123 InfoBarService* infobar_service, | |
| 124 MediaStreamDevicesController* controller) | |
| 125 : ConfirmInfoBarDelegate(infobar_service), | |
| 126 controller_(controller) { | |
| 127 DCHECK(controller_.get()); | |
| 128 DCHECK(controller_->has_audio() || controller_->has_video()); | |
| 129 } | |
| OLD | NEW |