Chromium Code Reviews| 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( |
|
raymes
2016/10/27 01:32:33
nit: can this be MakeUnique too?
lshang
2016/10/28 03:18:48
No, because the constructor of GroupedPermissionIn
| |
| 29 new GroupedPermissionInfoBarDelegate(requesting_origin, requests)))); | 31 requesting_origin, requests, permission_prompt)))); |
| 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 permission_prompt_->Accept(); | |
| 70 return true; | |
| 71 } | |
| 72 | |
| 73 bool GroupedPermissionInfoBarDelegate::Cancel() { | |
| 74 permission_prompt_->Deny(); | |
| 75 return true; | |
| 76 } | |
| 77 | |
| 66 bool GroupedPermissionInfoBarDelegate::GetAcceptState(size_t position) { | 78 bool GroupedPermissionInfoBarDelegate::GetAcceptState(size_t position) { |
| 67 DCHECK_LT(position, requests_.size()); | 79 DCHECK_LT(position, requests_.size()); |
| 68 return accept_states_[position]; | 80 return accept_states_[position]; |
| 69 } | 81 } |
| 70 | 82 |
| 71 GroupedPermissionInfoBarDelegate::GroupedPermissionInfoBarDelegate( | 83 GroupedPermissionInfoBarDelegate::GroupedPermissionInfoBarDelegate( |
| 72 const GURL& requesting_origin, | 84 const GURL& requesting_origin, |
| 73 const std::vector<PermissionRequest*>& requests) | 85 const std::vector<PermissionRequest*>& requests, |
| 86 PermissionPromptAndroid* permission_prompt) | |
| 74 : requesting_origin_(requesting_origin), | 87 : requesting_origin_(requesting_origin), |
| 75 requests_(requests), | 88 requests_(requests), |
| 76 accept_states_(requests_.size(), true), | 89 accept_states_(requests_.size(), true), |
| 77 persist_(true) {} | 90 persist_(true), |
| 91 permission_prompt_(permission_prompt) { | |
| 92 DCHECK(permission_prompt); | |
| 93 } | |
| 78 | 94 |
| 79 infobars::InfoBarDelegate::InfoBarIdentifier | 95 infobars::InfoBarDelegate::InfoBarIdentifier |
| 80 GroupedPermissionInfoBarDelegate::GetIdentifier() const { | 96 GroupedPermissionInfoBarDelegate::GetIdentifier() const { |
| 81 return GROUPED_PERMISSION_INFOBAR_DELEGATE_ANDROID; | 97 return GROUPED_PERMISSION_INFOBAR_DELEGATE_ANDROID; |
| 82 } | 98 } |
| 83 | 99 |
| 84 infobars::InfoBarDelegate::Type | 100 infobars::InfoBarDelegate::Type |
| 85 GroupedPermissionInfoBarDelegate::GetInfoBarType() const { | 101 GroupedPermissionInfoBarDelegate::GetInfoBarType() const { |
| 86 return PAGE_ACTION_TYPE; | 102 return PAGE_ACTION_TYPE; |
| 87 } | 103 } |
| 88 | 104 |
| 89 int GroupedPermissionInfoBarDelegate::GetButtons() const { | 105 int GroupedPermissionInfoBarDelegate::GetButtons() const { |
| 90 // If there is only one permission in the infobar, we show both OK and CANCEL | 106 // 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 | 107 // 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 | 108 // which means making decision for all permissions according to each accept |
| 93 // toggle. | 109 // toggle. |
| 94 return (permission_count() > 1) ? BUTTON_OK : (BUTTON_OK | BUTTON_CANCEL); | 110 return (permission_count() > 1) ? BUTTON_OK : (BUTTON_OK | BUTTON_CANCEL); |
| 95 } | 111 } |
| 96 | 112 |
| 97 base::string16 GroupedPermissionInfoBarDelegate::GetButtonLabel( | 113 base::string16 GroupedPermissionInfoBarDelegate::GetButtonLabel( |
| 98 InfoBarButton button) const { | 114 InfoBarButton button) const { |
| 99 if (permission_count() > 1) { | 115 if (permission_count() > 1) { |
| 100 return l10n_util::GetStringUTF16((button == BUTTON_OK) ? IDS_APP_OK | 116 return l10n_util::GetStringUTF16((button == BUTTON_OK) ? IDS_APP_OK |
| 101 : IDS_APP_CANCEL); | 117 : IDS_APP_CANCEL); |
| 102 } | 118 } |
| 103 | 119 |
| 104 return l10n_util::GetStringUTF16((button == BUTTON_OK) ? IDS_PERMISSION_ALLOW | 120 return l10n_util::GetStringUTF16((button == BUTTON_OK) ? IDS_PERMISSION_ALLOW |
| 105 : IDS_PERMISSION_DENY); | 121 : IDS_PERMISSION_DENY); |
| 106 } | 122 } |
| OLD | NEW |