OLD | NEW |
(Empty) | |
| 1 // Copyright 2015 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/android/media/media_throttle_infobar_delegate.h" |
| 6 |
| 7 #include "chrome/browser/infobars/infobar_service.h" |
| 8 #include "chrome/grit/generated_resources.h" |
| 9 #include "components/infobars/core/infobar.h" |
| 10 #include "content/public/browser/web_contents.h" |
| 11 #include "grit/components_strings.h" |
| 12 #include "grit/theme_resources.h" |
| 13 #include "ui/base/l10n/l10n_util.h" |
| 14 #include "url/gurl.h" |
| 15 |
| 16 // static |
| 17 void MediaThrottleInfoBarDelegate::Create( |
| 18 content::WebContents* web_contents, |
| 19 const DecodeRequestGrantedCallback& callback) { |
| 20 InfoBarService* infobar_service = |
| 21 InfoBarService::FromWebContents(web_contents); |
| 22 scoped_ptr<infobars::InfoBar> new_infobar( |
| 23 infobar_service->CreateConfirmInfoBar(scoped_ptr<ConfirmInfoBarDelegate>( |
| 24 new MediaThrottleInfoBarDelegate(callback)))); |
| 25 |
| 26 for (size_t i = 0; i < infobar_service->infobar_count(); ++i) { |
| 27 infobars::InfoBar* old_infobar = infobar_service->infobar_at(i); |
| 28 MediaThrottleInfoBarDelegate* delegate = |
| 29 old_infobar->delegate()->AsMediaThrottleInfoBarDelegate(); |
| 30 if (delegate != nullptr) { |
| 31 infobar_service->ReplaceInfoBar(old_infobar, new_infobar.Pass()); |
| 32 return; |
| 33 } |
| 34 } |
| 35 |
| 36 infobar_service->AddInfoBar(new_infobar.Pass()); |
| 37 } |
| 38 |
| 39 MediaThrottleInfoBarDelegate::MediaThrottleInfoBarDelegate( |
| 40 const DecodeRequestGrantedCallback& callback) |
| 41 : decode_granted_callback_(callback) { |
| 42 } |
| 43 |
| 44 MediaThrottleInfoBarDelegate::~MediaThrottleInfoBarDelegate() {} |
| 45 |
| 46 MediaThrottleInfoBarDelegate* |
| 47 MediaThrottleInfoBarDelegate::AsMediaThrottleInfoBarDelegate() { |
| 48 return this; |
| 49 } |
| 50 |
| 51 base::string16 MediaThrottleInfoBarDelegate::GetMessageText() const { |
| 52 return l10n_util::GetStringUTF16(IDS_MEDIA_THROTTLE_INFOBAR_TEXT); |
| 53 } |
| 54 |
| 55 base::string16 MediaThrottleInfoBarDelegate::GetButtonLabel( |
| 56 InfoBarButton button) const { |
| 57 return l10n_util::GetStringUTF16((button == BUTTON_OK) ? |
| 58 IDS_MEDIA_THROTTLE_INFOBAR_BLOCK_BUTTON : |
| 59 IDS_MEDIA_THROTTLE_INFOBAR_ALLOW_BUTTON); |
| 60 } |
| 61 |
| 62 bool MediaThrottleInfoBarDelegate::Accept() { |
| 63 decode_granted_callback_.Run(false); |
| 64 return true; |
| 65 } |
| 66 |
| 67 bool MediaThrottleInfoBarDelegate::Cancel() { |
| 68 decode_granted_callback_.Run(true); |
| 69 return true; |
| 70 } |
| 71 |
| 72 void MediaThrottleInfoBarDelegate::InfoBarDismissed() { |
| 73 decode_granted_callback_.Run(false); |
| 74 } |
OLD | NEW |