| 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_request.h" | 11 #include "chrome/browser/permissions/permission_request.h" |
| 11 #include "chrome/browser/permissions/permission_util.h" | 12 #include "chrome/browser/permissions/permission_util.h" |
| 12 #include "chrome/browser/ui/android/infobars/grouped_permission_infobar.h" | 13 #include "chrome/browser/ui/android/infobars/grouped_permission_infobar.h" |
| 13 #include "chrome/grit/generated_resources.h" | 14 #include "chrome/grit/generated_resources.h" |
| 14 #include "chrome/grit/theme_resources.h" | 15 #include "chrome/grit/theme_resources.h" |
| 15 #include "components/infobars/core/infobar.h" | 16 #include "components/infobars/core/infobar.h" |
| 16 #include "components/url_formatter/elide_url.h" | 17 #include "components/url_formatter/elide_url.h" |
| 17 #include "ui/base/l10n/l10n_util.h" | 18 #include "ui/base/l10n/l10n_util.h" |
| 18 #include "ui/strings/grit/ui_strings.h" | 19 #include "ui/strings/grit/ui_strings.h" |
| 19 | 20 |
| (...skipping 36 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 56 DCHECK_LT(position, requests_.size()); | 57 DCHECK_LT(position, requests_.size()); |
| 57 accept_states_[position] = new_value; | 58 accept_states_[position] = new_value; |
| 58 } | 59 } |
| 59 | 60 |
| 60 base::string16 GroupedPermissionInfoBarDelegate::GetMessageText() const { | 61 base::string16 GroupedPermissionInfoBarDelegate::GetMessageText() const { |
| 61 return l10n_util::GetStringFUTF16( | 62 return l10n_util::GetStringFUTF16( |
| 62 IDS_PERMISSIONS_BUBBLE_PROMPT, | 63 IDS_PERMISSIONS_BUBBLE_PROMPT, |
| 63 url_formatter::FormatUrlForSecurityDisplay(requesting_origin_)); | 64 url_formatter::FormatUrlForSecurityDisplay(requesting_origin_)); |
| 64 } | 65 } |
| 65 | 66 |
| 67 bool GroupedPermissionInfoBarDelegate::Accept() { |
| 68 if (permission_prompt_) |
| 69 permission_prompt_->Accept(); |
| 70 return true; |
| 71 } |
| 72 |
| 73 bool GroupedPermissionInfoBarDelegate::Cancel() { |
| 74 if (permission_prompt_) |
| 75 permission_prompt_->Deny(); |
| 76 return true; |
| 77 } |
| 78 |
| 79 void GroupedPermissionInfoBarDelegate::SetPermissionPrompt( |
| 80 PermissionPromptAndroid* permission_prompt) { |
| 81 permission_prompt_ = permission_prompt; |
| 82 } |
| 83 |
| 84 void GroupedPermissionInfoBarDelegate::ResetPermissionPrompt() { |
| 85 permission_prompt_ = nullptr; |
| 86 } |
| 87 |
| 66 bool GroupedPermissionInfoBarDelegate::GetAcceptState(size_t position) { | 88 bool GroupedPermissionInfoBarDelegate::GetAcceptState(size_t position) { |
| 67 DCHECK_LT(position, requests_.size()); | 89 DCHECK_LT(position, requests_.size()); |
| 68 return accept_states_[position]; | 90 return accept_states_[position]; |
| 69 } | 91 } |
| 70 | 92 |
| 71 GroupedPermissionInfoBarDelegate::GroupedPermissionInfoBarDelegate( | 93 GroupedPermissionInfoBarDelegate::GroupedPermissionInfoBarDelegate( |
| 72 const GURL& requesting_origin, | 94 const GURL& requesting_origin, |
| 73 const std::vector<PermissionRequest*>& requests) | 95 const std::vector<PermissionRequest*>& requests) |
| 74 : requesting_origin_(requesting_origin), | 96 : requesting_origin_(requesting_origin), |
| 75 requests_(requests), | 97 requests_(requests), |
| 76 accept_states_(requests_.size(), true), | 98 accept_states_(requests_.size(), true), |
| 77 persist_(true) {} | 99 persist_(true), |
| 100 permission_prompt_(nullptr) {} |
| 78 | 101 |
| 79 infobars::InfoBarDelegate::InfoBarIdentifier | 102 infobars::InfoBarDelegate::InfoBarIdentifier |
| 80 GroupedPermissionInfoBarDelegate::GetIdentifier() const { | 103 GroupedPermissionInfoBarDelegate::GetIdentifier() const { |
| 81 return GROUPED_PERMISSION_INFOBAR_DELEGATE_ANDROID; | 104 return GROUPED_PERMISSION_INFOBAR_DELEGATE_ANDROID; |
| 82 } | 105 } |
| 83 | 106 |
| 84 infobars::InfoBarDelegate::Type | 107 infobars::InfoBarDelegate::Type |
| 85 GroupedPermissionInfoBarDelegate::GetInfoBarType() const { | 108 GroupedPermissionInfoBarDelegate::GetInfoBarType() const { |
| 86 return PAGE_ACTION_TYPE; | 109 return PAGE_ACTION_TYPE; |
| 87 } | 110 } |
| 88 | 111 |
| 89 int GroupedPermissionInfoBarDelegate::GetButtons() const { | 112 int GroupedPermissionInfoBarDelegate::GetButtons() const { |
| 90 // If there is only one permission in the infobar, we show both OK and CANCEL | 113 // If there is only one permission in the infobar, we show both OK and CANCEL |
| 91 // button to allow/deny it. If there are multiple, we only show OK button | 114 // button to allow/deny it. If there are multiple, we only show OK button |
| 92 // which means making decision for all permissions according to each accept | 115 // which means making decision for all permissions according to each accept |
| 93 // toggle. | 116 // toggle. |
| 94 return (permission_count() > 1) ? BUTTON_OK : (BUTTON_OK | BUTTON_CANCEL); | 117 return (permission_count() > 1) ? BUTTON_OK : (BUTTON_OK | BUTTON_CANCEL); |
| 95 } | 118 } |
| 96 | 119 |
| 97 base::string16 GroupedPermissionInfoBarDelegate::GetButtonLabel( | 120 base::string16 GroupedPermissionInfoBarDelegate::GetButtonLabel( |
| 98 InfoBarButton button) const { | 121 InfoBarButton button) const { |
| 99 if (permission_count() > 1) { | 122 if (permission_count() > 1) { |
| 100 return l10n_util::GetStringUTF16((button == BUTTON_OK) ? IDS_APP_OK | 123 return l10n_util::GetStringUTF16((button == BUTTON_OK) ? IDS_APP_OK |
| 101 : IDS_APP_CANCEL); | 124 : IDS_APP_CANCEL); |
| 102 } | 125 } |
| 103 | 126 |
| 104 return l10n_util::GetStringUTF16((button == BUTTON_OK) ? IDS_PERMISSION_ALLOW | 127 return l10n_util::GetStringUTF16((button == BUTTON_OK) ? IDS_PERMISSION_ALLOW |
| 105 : IDS_PERMISSION_DENY); | 128 : IDS_PERMISSION_DENY); |
| 106 } | 129 } |
| 130 |
| 131 GroupedPermissionInfoBarDelegate* |
| 132 GroupedPermissionInfoBarDelegate::AsGroupedPermissionInfoBarDelegate() { |
| 133 return this; |
| 134 } |
| OLD | NEW |