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 package org.chromium.chrome.browser.infobar; | 5 package org.chromium.chrome.browser.infobar; |
6 | 6 |
7 import android.app.Activity; | 7 import android.app.Activity; |
8 import android.content.DialogInterface; | 8 import android.content.DialogInterface; |
9 import android.content.pm.PackageManager; | 9 import android.content.pm.PackageManager; |
10 import android.graphics.Bitmap; | 10 import android.graphics.Bitmap; |
(...skipping 24 matching lines...) Expand all Loading... |
35 private WindowAndroid mWindowAndroid; | 35 private WindowAndroid mWindowAndroid; |
36 | 36 |
37 /** | 37 /** |
38 * Mapping between the required {@link ContentSettingsType}s and their assoc
iated Android | 38 * Mapping between the required {@link ContentSettingsType}s and their assoc
iated Android |
39 * runtime permissions. Only {@link ContentSettingsType}s that are associat
ed with runtime | 39 * runtime permissions. Only {@link ContentSettingsType}s that are associat
ed with runtime |
40 * permissions will be included in this list while all others will be exclud
ed. | 40 * permissions will be included in this list while all others will be exclud
ed. |
41 */ | 41 */ |
42 private SparseArray<String> mContentSettingsToPermissionsMap; | 42 private SparseArray<String> mContentSettingsToPermissionsMap; |
43 | 43 |
44 protected PermissionInfoBar(int iconDrawableId, Bitmap iconBitmap, String me
ssage, | 44 protected PermissionInfoBar(int iconDrawableId, Bitmap iconBitmap, String me
ssage, |
45 String linkText, String primaryButtonText, String secondaryButtonTex
t) { | 45 String linkText, String primaryButtonText, String secondaryButtonTex
t, |
| 46 boolean showPersistenceToggle) { |
46 super(iconDrawableId, iconBitmap, message, linkText, primaryButtonText, | 47 super(iconDrawableId, iconBitmap, message, linkText, primaryButtonText, |
47 secondaryButtonText); | 48 secondaryButtonText); |
48 mShowPersistenceToggle = false; | 49 mShowPersistenceToggle = showPersistenceToggle; |
49 } | 50 } |
50 | 51 |
51 @Override | 52 @Override |
52 public void createContent(InfoBarLayout layout) { | 53 public void createContent(InfoBarLayout layout) { |
53 super.createContent(layout); | 54 super.createContent(layout); |
54 | 55 |
55 if (mShowPersistenceToggle) { | 56 if (mShowPersistenceToggle) { |
56 InfoBarControlLayout controlLayout = layout.addControlLayout(); | 57 InfoBarControlLayout controlLayout = layout.addControlLayout(); |
57 String description = | 58 String description = |
58 layout.getContext().getString(R.string.permission_infobar_pe
rsist_text); | 59 layout.getContext().getString(R.string.permission_infobar_pe
rsist_text); |
(...skipping 17 matching lines...) Expand all Loading... |
76 */ | 77 */ |
77 protected void setContentSettings( | 78 protected void setContentSettings( |
78 WindowAndroid windowAndroid, int[] contentSettings) { | 79 WindowAndroid windowAndroid, int[] contentSettings) { |
79 mWindowAndroid = windowAndroid; | 80 mWindowAndroid = windowAndroid; |
80 assert windowAndroid != null | 81 assert windowAndroid != null |
81 : "A WindowAndroid must be specified to request access to conten
t settings"; | 82 : "A WindowAndroid must be specified to request access to conten
t settings"; |
82 | 83 |
83 mContentSettingsToPermissionsMap = generatePermissionsMapping(contentSet
tings); | 84 mContentSettingsToPermissionsMap = generatePermissionsMapping(contentSet
tings); |
84 } | 85 } |
85 | 86 |
86 /** | |
87 * Specifies whether or not this infobar should display a toggle asking the
user if they want to | |
88 * save their choice. | |
89 * | |
90 * @param showPersistenceToggle True if the toggle should be displayed. | |
91 */ | |
92 private void setShowPersistenceToggle(boolean showPersistenceToggle) { | |
93 mShowPersistenceToggle = showPersistenceToggle; | |
94 } | |
95 | |
96 private SparseArray<String> generatePermissionsMapping(int[] contentSettings
) { | 87 private SparseArray<String> generatePermissionsMapping(int[] contentSettings
) { |
97 SparseArray<String> permissionsToRequest = new SparseArray<String>(); | 88 SparseArray<String> permissionsToRequest = new SparseArray<String>(); |
98 for (int i = 0; i < contentSettings.length; i++) { | 89 for (int i = 0; i < contentSettings.length; i++) { |
99 String permission = PrefServiceBridge.getAndroidPermissionForContent
Setting( | 90 String permission = PrefServiceBridge.getAndroidPermissionForContent
Setting( |
100 contentSettings[i]); | 91 contentSettings[i]); |
101 if (permission != null && !mWindowAndroid.hasPermission(permission))
{ | 92 if (permission != null && !mWindowAndroid.hasPermission(permission))
{ |
102 permissionsToRequest.append(contentSettings[i], permission); | 93 permissionsToRequest.append(contentSettings[i], permission); |
103 } | 94 } |
104 } | 95 } |
105 return permissionsToRequest; | 96 return permissionsToRequest; |
(...skipping 97 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
203 } | 194 } |
204 | 195 |
205 private void onButtonClickedInternal(boolean isPrimaryButton) { | 196 private void onButtonClickedInternal(boolean isPrimaryButton) { |
206 super.onButtonClicked(isPrimaryButton); | 197 super.onButtonClicked(isPrimaryButton); |
207 } | 198 } |
208 | 199 |
209 /** | 200 /** |
210 * Returns true if the persist switch exists and is toggled on. | 201 * Returns true if the persist switch exists and is toggled on. |
211 */ | 202 */ |
212 @CalledByNative | 203 @CalledByNative |
213 private boolean isPersistSwitchOn() { | 204 protected boolean isPersistSwitchOn() { |
214 SwitchCompat persistSwitch = (SwitchCompat) getView().findViewById( | 205 SwitchCompat persistSwitch = (SwitchCompat) getView().findViewById( |
215 R.id.permission_infobar_persist_toggle); | 206 R.id.permission_infobar_persist_toggle); |
216 if (mShowPersistenceToggle && persistSwitch != null) { | 207 if (mShowPersistenceToggle && persistSwitch != null) { |
217 return persistSwitch.isChecked(); | 208 return persistSwitch.isChecked(); |
218 } | 209 } |
219 return false; | 210 return false; |
220 } | 211 } |
221 | 212 |
222 /** | 213 /** |
223 * Creates and begins the process for showing a PermissionInfoBar. | 214 * Creates and begins the process for showing a PermissionInfoBar. |
(...skipping 11 matching lines...) Expand all Loading... |
235 * @param showPersistenceToggle Whether or not a toggle to opt-out of persis
ting a decision | 226 * @param showPersistenceToggle Whether or not a toggle to opt-out of persis
ting a decision |
236 * should be displayed. | 227 * should be displayed. |
237 */ | 228 */ |
238 @CalledByNative | 229 @CalledByNative |
239 private static PermissionInfoBar create(WindowAndroid windowAndroid, int enu
meratedIconId, | 230 private static PermissionInfoBar create(WindowAndroid windowAndroid, int enu
meratedIconId, |
240 Bitmap iconBitmap, String message, String linkText, String buttonOk, | 231 Bitmap iconBitmap, String message, String linkText, String buttonOk, |
241 String buttonCancel, int[] contentSettings, boolean showPersistenceT
oggle) { | 232 String buttonCancel, int[] contentSettings, boolean showPersistenceT
oggle) { |
242 int drawableId = ResourceId.mapToDrawableId(enumeratedIconId); | 233 int drawableId = ResourceId.mapToDrawableId(enumeratedIconId); |
243 | 234 |
244 PermissionInfoBar infoBar = new PermissionInfoBar(drawableId, iconBitmap
, message, linkText, | 235 PermissionInfoBar infoBar = new PermissionInfoBar(drawableId, iconBitmap
, message, linkText, |
245 buttonOk, buttonCancel); | 236 buttonOk, buttonCancel, showPersistenceToggle); |
246 infoBar.setContentSettings(windowAndroid, contentSettings); | 237 infoBar.setContentSettings(windowAndroid, contentSettings); |
247 infoBar.setShowPersistenceToggle(showPersistenceToggle); | |
248 | 238 |
249 return infoBar; | 239 return infoBar; |
250 } | 240 } |
251 } | 241 } |
OLD | NEW |