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_android
.h" | 5 #include "chrome/browser/permissions/grouped_permission_infobar_delegate_android
.h" |
6 | 6 |
7 #include "base/memory/ptr_util.h" | 7 #include "base/memory/ptr_util.h" |
8 #include "chrome/browser/android/android_theme_resources.h" | 8 #include "chrome/browser/android/android_theme_resources.h" |
9 #include "chrome/browser/infobars/infobar_service.h" | 9 #include "chrome/browser/infobars/infobar_service.h" |
10 #include "chrome/browser/permissions/permission_prompt_android.h" | 10 #include "chrome/browser/permissions/permission_prompt_android.h" |
11 #include "chrome/browser/permissions/permission_request.h" | 11 #include "chrome/browser/permissions/permission_request.h" |
12 #include "chrome/browser/permissions/permission_util.h" | 12 #include "chrome/browser/permissions/permission_util.h" |
13 #include "chrome/browser/ui/android/infobars/grouped_permission_infobar.h" | 13 #include "chrome/browser/ui/android/infobars/grouped_permission_infobar.h" |
14 #include "chrome/grit/generated_resources.h" | 14 #include "chrome/grit/generated_resources.h" |
15 #include "chrome/grit/theme_resources.h" | 15 #include "chrome/grit/theme_resources.h" |
16 #include "components/infobars/core/infobar.h" | 16 #include "components/infobars/core/infobar.h" |
17 #include "components/url_formatter/elide_url.h" | 17 #include "components/url_formatter/elide_url.h" |
18 #include "ui/base/l10n/l10n_util.h" | 18 #include "ui/base/l10n/l10n_util.h" |
19 #include "ui/strings/grit/ui_strings.h" | 19 #include "ui/strings/grit/ui_strings.h" |
20 | 20 |
21 GroupedPermissionInfoBarDelegate::~GroupedPermissionInfoBarDelegate() {} | 21 GroupedPermissionInfoBarDelegate::~GroupedPermissionInfoBarDelegate() {} |
22 | 22 |
23 // static | 23 // static |
24 infobars::InfoBar* GroupedPermissionInfoBarDelegate::Create( | 24 infobars::InfoBar* GroupedPermissionInfoBarDelegate::Create( |
25 PermissionPromptAndroid* permission_prompt, | 25 PermissionPromptAndroid* permission_prompt, |
26 InfoBarService* infobar_service, | 26 InfoBarService* infobar_service, |
27 const GURL& requesting_origin, | 27 const GURL& requesting_origin) { |
28 const std::vector<PermissionRequest*>& requests) { | |
29 return infobar_service->AddInfoBar(base::MakeUnique<GroupedPermissionInfoBar>( | 28 return infobar_service->AddInfoBar(base::MakeUnique<GroupedPermissionInfoBar>( |
30 base::WrapUnique(new GroupedPermissionInfoBarDelegate( | 29 base::WrapUnique(new GroupedPermissionInfoBarDelegate( |
31 permission_prompt, requesting_origin, requests)))); | 30 permission_prompt, requesting_origin)))); |
| 31 } |
| 32 |
| 33 size_t GroupedPermissionInfoBarDelegate::PermissionCount() const { |
| 34 return permission_prompt_->permission_count(); |
32 } | 35 } |
33 | 36 |
34 bool GroupedPermissionInfoBarDelegate::ShouldShowPersistenceToggle() const { | 37 bool GroupedPermissionInfoBarDelegate::ShouldShowPersistenceToggle() const { |
35 return PermissionUtil::ShouldShowPersistenceToggle(); | 38 return PermissionUtil::ShouldShowPersistenceToggle(); |
36 } | 39 } |
37 | 40 |
38 ContentSettingsType GroupedPermissionInfoBarDelegate::GetContentSettingType( | 41 ContentSettingsType GroupedPermissionInfoBarDelegate::GetContentSettingType( |
39 size_t position) const { | 42 size_t position) const { |
40 DCHECK_LT(position, requests_.size()); | 43 return permission_prompt_->GetContentSettingType(position); |
41 return requests_[position]->GetContentSettingsType(); | |
42 } | 44 } |
43 | 45 |
44 int GroupedPermissionInfoBarDelegate::GetIconIdForPermission( | 46 int GroupedPermissionInfoBarDelegate::GetIconIdForPermission( |
45 size_t position) const { | 47 size_t position) const { |
46 DCHECK_LT(position, requests_.size()); | 48 return permission_prompt_->GetIconIdForPermission(position); |
47 return requests_[position]->GetIconId(); | |
48 } | 49 } |
49 | 50 |
50 base::string16 GroupedPermissionInfoBarDelegate::GetMessageTextFragment( | 51 base::string16 GroupedPermissionInfoBarDelegate::GetMessageTextFragment( |
51 size_t position) const { | 52 size_t position) const { |
52 DCHECK_LT(position, requests_.size()); | 53 return permission_prompt_->GetMessageTextFragment(position); |
53 return requests_[position]->GetMessageTextFragment(); | |
54 } | 54 } |
55 | 55 |
56 void GroupedPermissionInfoBarDelegate::ToggleAccept(size_t position, | 56 void GroupedPermissionInfoBarDelegate::ToggleAccept(size_t position, |
57 bool new_value) { | 57 bool new_value) { |
58 DCHECK_LT(position, requests_.size()); | 58 DCHECK_LT(position, PermissionCount()); |
59 if (permission_prompt_) | 59 if (permission_prompt_) |
60 permission_prompt_->ToggleAccept(position, new_value); | 60 permission_prompt_->ToggleAccept(position, new_value); |
61 } | 61 } |
62 | 62 |
63 base::string16 GroupedPermissionInfoBarDelegate::GetMessageText() const { | 63 base::string16 GroupedPermissionInfoBarDelegate::GetMessageText() const { |
64 return l10n_util::GetStringFUTF16( | 64 return l10n_util::GetStringFUTF16( |
65 IDS_PERMISSIONS_BUBBLE_PROMPT, | 65 IDS_PERMISSIONS_BUBBLE_PROMPT, |
66 url_formatter::FormatUrlForSecurityDisplay(requesting_origin_)); | 66 url_formatter::FormatUrlForSecurityDisplay(requesting_origin_)); |
67 } | 67 } |
68 | 68 |
(...skipping 13 matching lines...) Expand all Loading... |
82 if (permission_prompt_) | 82 if (permission_prompt_) |
83 permission_prompt_->Closing(); | 83 permission_prompt_->Closing(); |
84 } | 84 } |
85 | 85 |
86 void GroupedPermissionInfoBarDelegate::PermissionPromptDestroyed() { | 86 void GroupedPermissionInfoBarDelegate::PermissionPromptDestroyed() { |
87 permission_prompt_ = nullptr; | 87 permission_prompt_ = nullptr; |
88 } | 88 } |
89 | 89 |
90 GroupedPermissionInfoBarDelegate::GroupedPermissionInfoBarDelegate( | 90 GroupedPermissionInfoBarDelegate::GroupedPermissionInfoBarDelegate( |
91 PermissionPromptAndroid* permission_prompt, | 91 PermissionPromptAndroid* permission_prompt, |
92 const GURL& requesting_origin, | 92 const GURL& requesting_origin) |
93 const std::vector<PermissionRequest*>& requests) | |
94 : requesting_origin_(requesting_origin), | 93 : requesting_origin_(requesting_origin), |
95 requests_(requests), | |
96 persist_(true), | 94 persist_(true), |
97 permission_prompt_(permission_prompt) { | 95 permission_prompt_(permission_prompt) { |
98 DCHECK(permission_prompt); | 96 DCHECK(permission_prompt); |
99 } | 97 } |
100 | 98 |
101 infobars::InfoBarDelegate::InfoBarIdentifier | 99 infobars::InfoBarDelegate::InfoBarIdentifier |
102 GroupedPermissionInfoBarDelegate::GetIdentifier() const { | 100 GroupedPermissionInfoBarDelegate::GetIdentifier() const { |
103 return GROUPED_PERMISSION_INFOBAR_DELEGATE_ANDROID; | 101 return GROUPED_PERMISSION_INFOBAR_DELEGATE_ANDROID; |
104 } | 102 } |
105 | 103 |
106 infobars::InfoBarDelegate::Type | 104 infobars::InfoBarDelegate::Type |
107 GroupedPermissionInfoBarDelegate::GetInfoBarType() const { | 105 GroupedPermissionInfoBarDelegate::GetInfoBarType() const { |
108 return PAGE_ACTION_TYPE; | 106 return PAGE_ACTION_TYPE; |
109 } | 107 } |
110 | 108 |
111 int GroupedPermissionInfoBarDelegate::GetButtons() const { | 109 int GroupedPermissionInfoBarDelegate::GetButtons() const { |
112 // If there is only one permission in the infobar, we show both OK and CANCEL | 110 // If there is only one permission in the infobar, we show both OK and CANCEL |
113 // button to allow/deny it. If there are multiple, we only show OK button | 111 // button to allow/deny it. If there are multiple, we only show OK button |
114 // which means making decision for all permissions according to each accept | 112 // which means making decision for all permissions according to each accept |
115 // toggle. | 113 // toggle. |
116 return (permission_count() > 1) ? BUTTON_OK : (BUTTON_OK | BUTTON_CANCEL); | 114 return (PermissionCount() > 1) ? BUTTON_OK : (BUTTON_OK | BUTTON_CANCEL); |
117 } | 115 } |
118 | 116 |
119 base::string16 GroupedPermissionInfoBarDelegate::GetButtonLabel( | 117 base::string16 GroupedPermissionInfoBarDelegate::GetButtonLabel( |
120 InfoBarButton button) const { | 118 InfoBarButton button) const { |
121 if (permission_count() > 1) { | 119 if (PermissionCount() > 1) { |
122 return l10n_util::GetStringUTF16((button == BUTTON_OK) ? IDS_APP_OK | 120 return l10n_util::GetStringUTF16((button == BUTTON_OK) ? IDS_APP_OK |
123 : IDS_APP_CANCEL); | 121 : IDS_APP_CANCEL); |
124 } | 122 } |
125 | 123 |
126 return l10n_util::GetStringUTF16((button == BUTTON_OK) ? IDS_PERMISSION_ALLOW | 124 return l10n_util::GetStringUTF16((button == BUTTON_OK) ? IDS_PERMISSION_ALLOW |
127 : IDS_PERMISSION_DENY); | 125 : IDS_PERMISSION_DENY); |
128 } | 126 } |
OLD | NEW |