| 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_request.h" |
| 10 #include "chrome/browser/permissions/permission_util.h" | 11 #include "chrome/browser/permissions/permission_util.h" |
| 11 #include "chrome/browser/ui/android/infobars/grouped_permission_infobar.h" | 12 #include "chrome/browser/ui/android/infobars/grouped_permission_infobar.h" |
| 12 #include "chrome/grit/generated_resources.h" | 13 #include "chrome/grit/generated_resources.h" |
| 13 #include "chrome/grit/theme_resources.h" | 14 #include "chrome/grit/theme_resources.h" |
| 14 #include "components/infobars/core/infobar.h" | 15 #include "components/infobars/core/infobar.h" |
| 15 #include "components/url_formatter/elide_url.h" | 16 #include "components/url_formatter/elide_url.h" |
| 16 #include "ui/base/l10n/l10n_util.h" | 17 #include "ui/base/l10n/l10n_util.h" |
| 17 #include "ui/strings/grit/ui_strings.h" | 18 #include "ui/strings/grit/ui_strings.h" |
| 18 | 19 |
| 19 GroupedPermissionInfoBarDelegate::~GroupedPermissionInfoBarDelegate() {} | 20 GroupedPermissionInfoBarDelegate::~GroupedPermissionInfoBarDelegate() {} |
| 20 | 21 |
| 21 // static | 22 // static |
| 22 infobars::InfoBar* GroupedPermissionInfoBarDelegate::Create( | 23 infobars::InfoBar* GroupedPermissionInfoBarDelegate::Create( |
| 23 InfoBarService* infobar_service, | 24 InfoBarService* infobar_service, |
| 24 const GURL& requesting_origin, | 25 const GURL& requesting_origin, |
| 25 const std::vector<ContentSettingsType>& types) { | 26 const std::vector<PermissionRequest*>& requests) { |
| 26 return infobar_service->AddInfoBar( | 27 return infobar_service->AddInfoBar( |
| 27 base::MakeUnique<GroupedPermissionInfoBar>(base::WrapUnique( | 28 base::MakeUnique<GroupedPermissionInfoBar>(base::WrapUnique( |
| 28 new GroupedPermissionInfoBarDelegate(requesting_origin, types)))); | 29 new GroupedPermissionInfoBarDelegate(requesting_origin, requests)))); |
| 29 } | 30 } |
| 30 | 31 |
| 31 bool GroupedPermissionInfoBarDelegate::ShouldShowPersistenceToggle() const { | 32 bool GroupedPermissionInfoBarDelegate::ShouldShowPersistenceToggle() const { |
| 32 return PermissionUtil::ShouldShowPersistenceToggle(); | 33 return PermissionUtil::ShouldShowPersistenceToggle(); |
| 33 } | 34 } |
| 34 | 35 |
| 35 ContentSettingsType GroupedPermissionInfoBarDelegate::GetContentSettingType( | 36 ContentSettingsType GroupedPermissionInfoBarDelegate::GetContentSettingType( |
| 36 size_t position) const { | 37 size_t position) const { |
| 37 DCHECK_LT(position, types_.size()); | 38 DCHECK_LT(position, requests_.size()); |
| 38 return types_[position]; | 39 return requests_[position]->GetContentSettingsType(); |
| 39 } | 40 } |
| 40 | 41 |
| 41 int GroupedPermissionInfoBarDelegate::GetIconIdForPermission( | 42 int GroupedPermissionInfoBarDelegate::GetIconIdForPermission( |
| 42 size_t position) const { | 43 size_t position) const { |
| 43 DCHECK_LT(position, types_.size()); | 44 DCHECK_LT(position, requests_.size()); |
| 44 ContentSettingsType type = types_[position]; | 45 return requests_[position]->GetIconId(); |
| 45 if (type == CONTENT_SETTINGS_TYPE_MEDIASTREAM_MIC) | |
| 46 return IDR_INFOBAR_MEDIA_STREAM_MIC; | |
| 47 if (type == CONTENT_SETTINGS_TYPE_MEDIASTREAM_CAMERA) | |
| 48 return IDR_INFOBAR_MEDIA_STREAM_CAMERA; | |
| 49 | |
| 50 return IDR_ANDROID_INFOBAR_WARNING; | |
| 51 } | 46 } |
| 52 | 47 |
| 53 base::string16 GroupedPermissionInfoBarDelegate::GetMessageTextFragment( | 48 base::string16 GroupedPermissionInfoBarDelegate::GetMessageTextFragment( |
| 54 size_t position) const { | 49 size_t position) const { |
| 55 DCHECK_LT(position, types_.size()); | 50 DCHECK_LT(position, requests_.size()); |
| 56 ContentSettingsType type = types_[position]; | 51 return requests_[position]->GetMessageTextFragment(); |
| 57 | |
| 58 const bool is_mic = (type == CONTENT_SETTINGS_TYPE_MEDIASTREAM_MIC); | |
| 59 DCHECK(is_mic || (type == CONTENT_SETTINGS_TYPE_MEDIASTREAM_CAMERA)); | |
| 60 return l10n_util::GetStringUTF16( | |
| 61 is_mic ? IDS_MEDIA_CAPTURE_AUDIO_ONLY_PERMISSION_FRAGMENT | |
| 62 : IDS_MEDIA_CAPTURE_VIDEO_ONLY_PERMISSION_FRAGMENT); | |
| 63 } | 52 } |
| 64 | 53 |
| 65 void GroupedPermissionInfoBarDelegate::ToggleAccept(size_t position, | 54 void GroupedPermissionInfoBarDelegate::ToggleAccept(size_t position, |
| 66 bool new_value) { | 55 bool new_value) { |
| 67 DCHECK_LT(position, types_.size()); | 56 DCHECK_LT(position, requests_.size()); |
| 68 accept_states_[position] = new_value; | 57 accept_states_[position] = new_value; |
| 69 } | 58 } |
| 70 | 59 |
| 71 base::string16 GroupedPermissionInfoBarDelegate::GetMessageText() const { | 60 base::string16 GroupedPermissionInfoBarDelegate::GetMessageText() const { |
| 72 return l10n_util::GetStringFUTF16( | 61 return l10n_util::GetStringFUTF16( |
| 73 IDS_PERMISSIONS_BUBBLE_PROMPT, | 62 IDS_PERMISSIONS_BUBBLE_PROMPT, |
| 74 url_formatter::FormatUrlForSecurityDisplay(requesting_origin_)); | 63 url_formatter::FormatUrlForSecurityDisplay(requesting_origin_)); |
| 75 } | 64 } |
| 76 | 65 |
| 77 bool GroupedPermissionInfoBarDelegate::GetAcceptState(size_t position) { | 66 bool GroupedPermissionInfoBarDelegate::GetAcceptState(size_t position) { |
| 78 DCHECK_LT(position, types_.size()); | 67 DCHECK_LT(position, requests_.size()); |
| 79 return accept_states_[position]; | 68 return accept_states_[position]; |
| 80 } | 69 } |
| 81 | 70 |
| 82 GroupedPermissionInfoBarDelegate::GroupedPermissionInfoBarDelegate( | 71 GroupedPermissionInfoBarDelegate::GroupedPermissionInfoBarDelegate( |
| 83 const GURL& requesting_origin, | 72 const GURL& requesting_origin, |
| 84 const std::vector<ContentSettingsType>& types) | 73 const std::vector<PermissionRequest*>& requests) |
| 85 : requesting_origin_(requesting_origin), | 74 : requesting_origin_(requesting_origin), |
| 86 types_(types), | 75 requests_(requests), |
| 87 accept_states_(types_.size(), true), | 76 accept_states_(requests_.size(), true), |
| 88 persist_(true) {} | 77 persist_(true) {} |
| 89 | 78 |
| 90 infobars::InfoBarDelegate::InfoBarIdentifier | 79 infobars::InfoBarDelegate::InfoBarIdentifier |
| 91 GroupedPermissionInfoBarDelegate::GetIdentifier() const { | 80 GroupedPermissionInfoBarDelegate::GetIdentifier() const { |
| 92 return GROUPED_PERMISSION_INFOBAR_DELEGATE_ANDROID; | 81 return GROUPED_PERMISSION_INFOBAR_DELEGATE_ANDROID; |
| 93 } | 82 } |
| 94 | 83 |
| 95 infobars::InfoBarDelegate::Type | 84 infobars::InfoBarDelegate::Type |
| 96 GroupedPermissionInfoBarDelegate::GetInfoBarType() const { | 85 GroupedPermissionInfoBarDelegate::GetInfoBarType() const { |
| 97 return PAGE_ACTION_TYPE; | 86 return PAGE_ACTION_TYPE; |
| (...skipping 10 matching lines...) Expand all Loading... |
| 108 base::string16 GroupedPermissionInfoBarDelegate::GetButtonLabel( | 97 base::string16 GroupedPermissionInfoBarDelegate::GetButtonLabel( |
| 109 InfoBarButton button) const { | 98 InfoBarButton button) const { |
| 110 if (permission_count() > 1) { | 99 if (permission_count() > 1) { |
| 111 return l10n_util::GetStringUTF16((button == BUTTON_OK) ? IDS_APP_OK | 100 return l10n_util::GetStringUTF16((button == BUTTON_OK) ? IDS_APP_OK |
| 112 : IDS_APP_CANCEL); | 101 : IDS_APP_CANCEL); |
| 113 } | 102 } |
| 114 | 103 |
| 115 return l10n_util::GetStringUTF16((button == BUTTON_OK) ? IDS_PERMISSION_ALLOW | 104 return l10n_util::GetStringUTF16((button == BUTTON_OK) ? IDS_PERMISSION_ALLOW |
| 116 : IDS_PERMISSION_DENY); | 105 : IDS_PERMISSION_DENY); |
| 117 } | 106 } |
| OLD | NEW |