| 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 |
| 20 GroupedPermissionInfoBarDelegate::~GroupedPermissionInfoBarDelegate() {} | 21 GroupedPermissionInfoBarDelegate::~GroupedPermissionInfoBarDelegate() {} |
| 21 | 22 |
| 22 // static | 23 // static |
| 23 infobars::InfoBar* GroupedPermissionInfoBarDelegate::Create( | 24 infobars::InfoBar* GroupedPermissionInfoBarDelegate::Create( |
| 25 PermissionPromptAndroid* permission_prompt, |
| 24 InfoBarService* infobar_service, | 26 InfoBarService* infobar_service, |
| 25 const GURL& requesting_origin, | 27 const GURL& requesting_origin, |
| 26 const std::vector<PermissionRequest*>& requests) { | 28 const std::vector<PermissionRequest*>& requests) { |
| 27 return infobar_service->AddInfoBar( | 29 return infobar_service->AddInfoBar(base::MakeUnique<GroupedPermissionInfoBar>( |
| 28 base::MakeUnique<GroupedPermissionInfoBar>(base::WrapUnique( | 30 base::WrapUnique(new GroupedPermissionInfoBarDelegate( |
| 29 new GroupedPermissionInfoBarDelegate(requesting_origin, requests)))); | 31 permission_prompt, requesting_origin, requests)))); |
| 30 } | 32 } |
| 31 | 33 |
| 32 bool GroupedPermissionInfoBarDelegate::ShouldShowPersistenceToggle() const { | 34 bool GroupedPermissionInfoBarDelegate::ShouldShowPersistenceToggle() const { |
| 33 return PermissionUtil::ShouldShowPersistenceToggle(); | 35 return PermissionUtil::ShouldShowPersistenceToggle(); |
| 34 } | 36 } |
| 35 | 37 |
| 36 ContentSettingsType GroupedPermissionInfoBarDelegate::GetContentSettingType( | 38 ContentSettingsType GroupedPermissionInfoBarDelegate::GetContentSettingType( |
| 37 size_t position) const { | 39 size_t position) const { |
| 38 DCHECK_LT(position, requests_.size()); | 40 DCHECK_LT(position, requests_.size()); |
| 39 return requests_[position]->GetContentSettingsType(); | 41 return requests_[position]->GetContentSettingsType(); |
| (...skipping 16 matching lines...) Expand all Loading... |
| 56 DCHECK_LT(position, requests_.size()); | 58 DCHECK_LT(position, requests_.size()); |
| 57 accept_states_[position] = new_value; | 59 accept_states_[position] = new_value; |
| 58 } | 60 } |
| 59 | 61 |
| 60 base::string16 GroupedPermissionInfoBarDelegate::GetMessageText() const { | 62 base::string16 GroupedPermissionInfoBarDelegate::GetMessageText() const { |
| 61 return l10n_util::GetStringFUTF16( | 63 return l10n_util::GetStringFUTF16( |
| 62 IDS_PERMISSIONS_BUBBLE_PROMPT, | 64 IDS_PERMISSIONS_BUBBLE_PROMPT, |
| 63 url_formatter::FormatUrlForSecurityDisplay(requesting_origin_)); | 65 url_formatter::FormatUrlForSecurityDisplay(requesting_origin_)); |
| 64 } | 66 } |
| 65 | 67 |
| 68 bool GroupedPermissionInfoBarDelegate::Accept() { |
| 69 if (permission_prompt_) |
| 70 permission_prompt_->Accept(); |
| 71 return true; |
| 72 } |
| 73 |
| 74 bool GroupedPermissionInfoBarDelegate::Cancel() { |
| 75 if (permission_prompt_) |
| 76 permission_prompt_->Deny(); |
| 77 return true; |
| 78 } |
| 79 |
| 80 void GroupedPermissionInfoBarDelegate::PermissionPromptDestroyed() { |
| 81 permission_prompt_ = nullptr; |
| 82 } |
| 83 |
| 66 bool GroupedPermissionInfoBarDelegate::GetAcceptState(size_t position) { | 84 bool GroupedPermissionInfoBarDelegate::GetAcceptState(size_t position) { |
| 67 DCHECK_LT(position, requests_.size()); | 85 DCHECK_LT(position, requests_.size()); |
| 68 return accept_states_[position]; | 86 return accept_states_[position]; |
| 69 } | 87 } |
| 70 | 88 |
| 71 GroupedPermissionInfoBarDelegate::GroupedPermissionInfoBarDelegate( | 89 GroupedPermissionInfoBarDelegate::GroupedPermissionInfoBarDelegate( |
| 90 PermissionPromptAndroid* permission_prompt, |
| 72 const GURL& requesting_origin, | 91 const GURL& requesting_origin, |
| 73 const std::vector<PermissionRequest*>& requests) | 92 const std::vector<PermissionRequest*>& requests) |
| 74 : requesting_origin_(requesting_origin), | 93 : requesting_origin_(requesting_origin), |
| 75 requests_(requests), | 94 requests_(requests), |
| 76 accept_states_(requests_.size(), true), | 95 accept_states_(requests_.size(), true), |
| 77 persist_(true) {} | 96 persist_(true), |
| 97 permission_prompt_(permission_prompt) { |
| 98 DCHECK(permission_prompt); |
| 99 } |
| 78 | 100 |
| 79 infobars::InfoBarDelegate::InfoBarIdentifier | 101 infobars::InfoBarDelegate::InfoBarIdentifier |
| 80 GroupedPermissionInfoBarDelegate::GetIdentifier() const { | 102 GroupedPermissionInfoBarDelegate::GetIdentifier() const { |
| 81 return GROUPED_PERMISSION_INFOBAR_DELEGATE_ANDROID; | 103 return GROUPED_PERMISSION_INFOBAR_DELEGATE_ANDROID; |
| 82 } | 104 } |
| 83 | 105 |
| 84 infobars::InfoBarDelegate::Type | 106 infobars::InfoBarDelegate::Type |
| 85 GroupedPermissionInfoBarDelegate::GetInfoBarType() const { | 107 GroupedPermissionInfoBarDelegate::GetInfoBarType() const { |
| 86 return PAGE_ACTION_TYPE; | 108 return PAGE_ACTION_TYPE; |
| 87 } | 109 } |
| 88 | 110 |
| 89 int GroupedPermissionInfoBarDelegate::GetButtons() const { | 111 int GroupedPermissionInfoBarDelegate::GetButtons() const { |
| 90 // If there is only one permission in the infobar, we show both OK and CANCEL | 112 // 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 | 113 // 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 | 114 // which means making decision for all permissions according to each accept |
| 93 // toggle. | 115 // toggle. |
| 94 return (permission_count() > 1) ? BUTTON_OK : (BUTTON_OK | BUTTON_CANCEL); | 116 return (permission_count() > 1) ? BUTTON_OK : (BUTTON_OK | BUTTON_CANCEL); |
| 95 } | 117 } |
| 96 | 118 |
| 97 base::string16 GroupedPermissionInfoBarDelegate::GetButtonLabel( | 119 base::string16 GroupedPermissionInfoBarDelegate::GetButtonLabel( |
| 98 InfoBarButton button) const { | 120 InfoBarButton button) const { |
| 99 if (permission_count() > 1) { | 121 if (permission_count() > 1) { |
| 100 return l10n_util::GetStringUTF16((button == BUTTON_OK) ? IDS_APP_OK | 122 return l10n_util::GetStringUTF16((button == BUTTON_OK) ? IDS_APP_OK |
| 101 : IDS_APP_CANCEL); | 123 : IDS_APP_CANCEL); |
| 102 } | 124 } |
| 103 | 125 |
| 104 return l10n_util::GetStringUTF16((button == BUTTON_OK) ? IDS_PERMISSION_ALLOW | 126 return l10n_util::GetStringUTF16((button == BUTTON_OK) ? IDS_PERMISSION_ALLOW |
| 105 : IDS_PERMISSION_DENY); | 127 : IDS_PERMISSION_DENY); |
| 106 } | 128 } |
| OLD | NEW |