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