OLD | NEW |
(Empty) | |
| 1 // Copyright 2016 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/permissions/grouped_permission_infobar_delegate.h" |
| 6 #include "chrome/grit/generated_resources.h" |
| 7 #include "components/url_formatter/elide_url.h" |
| 8 #include "grit/theme_resources.h" |
| 9 #include "ui/base/l10n/l10n_util.h" |
| 10 |
| 11 GroupedPermissionInfoBarDelegate::GroupedPermissionInfoBarDelegate( |
| 12 const GURL& requesting_origin, |
| 13 const std::vector<ContentSettingsType>& types) |
| 14 : requesting_origin_(requesting_origin), types_(types) {} |
| 15 |
| 16 GroupedPermissionInfoBarDelegate::~GroupedPermissionInfoBarDelegate() {} |
| 17 |
| 18 infobars::InfoBarDelegate::Type |
| 19 GroupedPermissionInfoBarDelegate::GetInfoBarType() const { |
| 20 return PAGE_ACTION_TYPE; |
| 21 } |
| 22 |
| 23 base::string16 GroupedPermissionInfoBarDelegate::GetButtonLabel( |
| 24 InfoBarButton button) const { |
| 25 return l10n_util::GetStringUTF16( |
| 26 (button == BUTTON_OK) ? IDS_PERMISSION_ALLOW : IDS_PERMISSION_DENY); |
| 27 } |
| 28 |
| 29 base::string16 GroupedPermissionInfoBarDelegate::GetMessageText() const { |
| 30 return l10n_util::GetStringFUTF16( |
| 31 IDS_PERMISSIONS_BUBBLE_PROMPT, |
| 32 url_formatter::FormatUrlForSecurityDisplay(requesting_origin_)); |
| 33 } |
| 34 |
| 35 int GroupedPermissionInfoBarDelegate::GetPermissionCount() const { |
| 36 return types_.size(); |
| 37 } |
| 38 |
| 39 ContentSettingsType GroupedPermissionInfoBarDelegate::GetContentSettingType( |
| 40 int index) const { |
| 41 DCHECK(index >= 0 && index < static_cast<int>(types_.size())); |
| 42 return types_[index]; |
| 43 } |
| 44 |
| 45 int GroupedPermissionInfoBarDelegate::GetIconIdForPermission(int index) const { |
| 46 DCHECK(index >= 0 && index < static_cast<int>(types_.size())); |
| 47 ContentSettingsType type = types_[index]; |
| 48 if (type == CONTENT_SETTINGS_TYPE_MEDIASTREAM_MIC) { |
| 49 return IDR_INFOBAR_MEDIA_STREAM_MIC; |
| 50 } else if (type == CONTENT_SETTINGS_TYPE_MEDIASTREAM_CAMERA) { |
| 51 return IDR_INFOBAR_MEDIA_STREAM_CAMERA; |
| 52 } |
| 53 return IDR_INFOBAR_WARNING; |
| 54 } |
| 55 |
| 56 base::string16 GroupedPermissionInfoBarDelegate::GetMessageTextFragment( |
| 57 int index) const { |
| 58 DCHECK(index >= 0 && index < static_cast<int>(types_.size())); |
| 59 ContentSettingsType type = types_[index]; |
| 60 int message_id; |
| 61 if (type == CONTENT_SETTINGS_TYPE_MEDIASTREAM_MIC) { |
| 62 message_id = IDS_MEDIA_CAPTURE_AUDIO_ONLY_PERMISSION_FRAGMENT; |
| 63 } else if (type == CONTENT_SETTINGS_TYPE_MEDIASTREAM_CAMERA) { |
| 64 message_id = IDS_MEDIA_CAPTURE_VIDEO_ONLY_PERMISSION_FRAGMENT; |
| 65 } else { |
| 66 NOTREACHED(); |
| 67 return base::string16(); |
| 68 } |
| 69 return l10n_util::GetStringUTF16(message_id); |
| 70 } |
OLD | NEW |