OLD | NEW |
1 // Copyright 2016 The Chromium Authors. All rights reserved. | 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 | 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/permissions/grouped_permission_infobar_delegate.h" | 5 #include "chrome/browser/permissions/grouped_permission_infobar_delegate.h" |
6 #include "chrome/grit/generated_resources.h" | 6 #include "chrome/grit/generated_resources.h" |
7 #include "components/url_formatter/elide_url.h" | 7 #include "components/url_formatter/elide_url.h" |
8 #include "grit/theme_resources.h" | 8 #include "grit/theme_resources.h" |
9 #include "ui/base/l10n/l10n_util.h" | 9 #include "ui/base/l10n/l10n_util.h" |
10 | 10 |
11 GroupedPermissionInfoBarDelegate::GroupedPermissionInfoBarDelegate( | 11 GroupedPermissionInfoBarDelegate::GroupedPermissionInfoBarDelegate( |
12 const GURL& requesting_origin, | 12 const GURL& requesting_origin, |
13 const std::vector<ContentSettingsType>& types) | 13 const std::vector<ContentSettingsType>& types) |
14 : requesting_origin_(requesting_origin), types_(types) {} | 14 : requesting_origin_(requesting_origin), |
| 15 types_(types), |
| 16 accept_states_(types_.size(), true) {} |
15 | 17 |
16 GroupedPermissionInfoBarDelegate::~GroupedPermissionInfoBarDelegate() {} | 18 GroupedPermissionInfoBarDelegate::~GroupedPermissionInfoBarDelegate() {} |
17 | 19 |
18 infobars::InfoBarDelegate::Type | 20 infobars::InfoBarDelegate::Type |
19 GroupedPermissionInfoBarDelegate::GetInfoBarType() const { | 21 GroupedPermissionInfoBarDelegate::GetInfoBarType() const { |
20 return PAGE_ACTION_TYPE; | 22 return PAGE_ACTION_TYPE; |
21 } | 23 } |
22 | 24 |
| 25 int GroupedPermissionInfoBarDelegate::GetButtons() const { |
| 26 if (GetPermissionCount() >= 2) |
| 27 return ConfirmInfoBarDelegate::InfoBarButton::BUTTON_OK; |
| 28 else |
| 29 return ConfirmInfoBarDelegate::GetButtons(); |
| 30 } |
| 31 |
23 base::string16 GroupedPermissionInfoBarDelegate::GetButtonLabel( | 32 base::string16 GroupedPermissionInfoBarDelegate::GetButtonLabel( |
24 InfoBarButton button) const { | 33 InfoBarButton button) const { |
25 return l10n_util::GetStringUTF16( | 34 if (GetPermissionCount() >= 2) { |
26 (button == BUTTON_OK) ? IDS_PERMISSION_ALLOW : IDS_PERMISSION_DENY); | 35 return ConfirmInfoBarDelegate::GetButtonLabel(button); |
| 36 } else { |
| 37 return l10n_util::GetStringUTF16( |
| 38 (button == BUTTON_OK) ? IDS_PERMISSION_ALLOW : IDS_PERMISSION_DENY); |
| 39 } |
27 } | 40 } |
28 | 41 |
29 base::string16 GroupedPermissionInfoBarDelegate::GetMessageText() const { | 42 base::string16 GroupedPermissionInfoBarDelegate::GetMessageText() const { |
30 return l10n_util::GetStringFUTF16( | 43 return l10n_util::GetStringFUTF16( |
31 IDS_PERMISSIONS_BUBBLE_PROMPT, | 44 IDS_PERMISSIONS_BUBBLE_PROMPT, |
32 url_formatter::FormatUrlForSecurityDisplay(requesting_origin_)); | 45 url_formatter::FormatUrlForSecurityDisplay(requesting_origin_)); |
33 } | 46 } |
34 | 47 |
35 int GroupedPermissionInfoBarDelegate::GetPermissionCount() const { | 48 int GroupedPermissionInfoBarDelegate::GetPermissionCount() const { |
36 return types_.size(); | 49 return types_.size(); |
(...skipping 24 matching lines...) Expand all Loading... |
61 if (type == CONTENT_SETTINGS_TYPE_MEDIASTREAM_MIC) { | 74 if (type == CONTENT_SETTINGS_TYPE_MEDIASTREAM_MIC) { |
62 message_id = IDS_MEDIA_CAPTURE_AUDIO_ONLY_PERMISSION_FRAGMENT; | 75 message_id = IDS_MEDIA_CAPTURE_AUDIO_ONLY_PERMISSION_FRAGMENT; |
63 } else if (type == CONTENT_SETTINGS_TYPE_MEDIASTREAM_CAMERA) { | 76 } else if (type == CONTENT_SETTINGS_TYPE_MEDIASTREAM_CAMERA) { |
64 message_id = IDS_MEDIA_CAPTURE_VIDEO_ONLY_PERMISSION_FRAGMENT; | 77 message_id = IDS_MEDIA_CAPTURE_VIDEO_ONLY_PERMISSION_FRAGMENT; |
65 } else { | 78 } else { |
66 NOTREACHED(); | 79 NOTREACHED(); |
67 return base::string16(); | 80 return base::string16(); |
68 } | 81 } |
69 return l10n_util::GetStringUTF16(message_id); | 82 return l10n_util::GetStringUTF16(message_id); |
70 } | 83 } |
| 84 |
| 85 void GroupedPermissionInfoBarDelegate::ToggleAccept(int position, |
| 86 bool new_value) { |
| 87 DCHECK(position >= 0 && position < static_cast<int>(types_.size())); |
| 88 accept_states_[position] = new_value; |
| 89 } |
| 90 |
| 91 bool GroupedPermissionInfoBarDelegate::GetAcceptState(int position) { |
| 92 DCHECK(position >= 0 && position < static_cast<int>(types_.size())); |
| 93 return accept_states_[position]; |
| 94 } |
OLD | NEW |