Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(104)

Side by Side Diff: chrome/android/java/src/org/chromium/chrome/browser/infobar/PermissionInfoBar.java

Issue 2254763002: Enable the optional permission prompt persistence toggle on grouped infobars (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@permission-infobardelegate-clean
Patch Set: Add CL dependency; improve media impl Created 4 years, 4 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
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.Context; 8 import android.content.Context;
9 import android.content.DialogInterface; 9 import android.content.DialogInterface;
10 import android.content.pm.PackageManager; 10 import android.content.pm.PackageManager;
(...skipping 25 matching lines...) Expand all
36 private WindowAndroid mWindowAndroid; 36 private WindowAndroid mWindowAndroid;
37 37
38 /** 38 /**
39 * Mapping between the required {@link ContentSettingsType}s and their assoc iated Android 39 * Mapping between the required {@link ContentSettingsType}s and their assoc iated Android
40 * runtime permissions. Only {@link ContentSettingsType}s that are associat ed with runtime 40 * runtime permissions. Only {@link ContentSettingsType}s that are associat ed with runtime
41 * permissions will be included in this list while all others will be exclud ed. 41 * permissions will be included in this list while all others will be exclud ed.
42 */ 42 */
43 private SparseArray<String> mContentSettingsToPermissionsMap; 43 private SparseArray<String> mContentSettingsToPermissionsMap;
44 44
45 protected PermissionInfoBar(int iconDrawableId, Bitmap iconBitmap, String me ssage, 45 protected PermissionInfoBar(int iconDrawableId, Bitmap iconBitmap, String me ssage,
46 String linkText, String primaryButtonText, String secondaryButtonTex t) { 46 String linkText, String primaryButtonText, String secondaryButtonTex t,
47 boolean showPersistenceToggle) {
47 super(iconDrawableId, iconBitmap, message, linkText, primaryButtonText, 48 super(iconDrawableId, iconBitmap, message, linkText, primaryButtonText,
48 secondaryButtonText); 49 secondaryButtonText);
49 mShowPersistenceToggle = false; 50 mShowPersistenceToggle = showPersistenceToggle;
50 } 51 }
51 52
52 @Override 53 @Override
53 public void createContent(InfoBarLayout layout) { 54 public void createContent(InfoBarLayout layout) {
54 super.createContent(layout); 55 super.createContent(layout);
55 56
56 if (mShowPersistenceToggle) { 57 if (mShowPersistenceToggle) {
57 InfoBarControlLayout controlLayout = layout.addControlLayout(); 58 InfoBarControlLayout controlLayout = layout.addControlLayout();
58 String description = 59 String description =
59 layout.getContext().getString(R.string.permission_infobar_pe rsist_text); 60 layout.getContext().getString(R.string.permission_infobar_pe rsist_text);
(...skipping 12 matching lines...) Expand all
72 */ 73 */
73 protected void setContentSettings( 74 protected void setContentSettings(
74 WindowAndroid windowAndroid, int[] contentSettings) { 75 WindowAndroid windowAndroid, int[] contentSettings) {
75 mWindowAndroid = windowAndroid; 76 mWindowAndroid = windowAndroid;
76 assert windowAndroid != null 77 assert windowAndroid != null
77 : "A WindowAndroid must be specified to request access to conten t settings"; 78 : "A WindowAndroid must be specified to request access to conten t settings";
78 79
79 mContentSettingsToPermissionsMap = generatePermissionsMapping(contentSet tings); 80 mContentSettingsToPermissionsMap = generatePermissionsMapping(contentSet tings);
80 } 81 }
81 82
82 /**
83 * Specifies whether or not this infobar should display a toggle asking the user if they want to
84 * save their choice.
85 *
86 * @param showPersistenceToggle True if the toggle should be displayed.
87 */
88 private void setShowPersistenceToggle(boolean showPersistenceToggle) {
89 mShowPersistenceToggle = showPersistenceToggle;
90 }
91
92 private static boolean hasPermission(Context context, String permission) { 83 private static boolean hasPermission(Context context, String permission) {
93 return context.checkPermission(permission, Process.myPid(), Process.myUi d()) 84 return context.checkPermission(permission, Process.myPid(), Process.myUi d())
94 != PackageManager.PERMISSION_DENIED; 85 != PackageManager.PERMISSION_DENIED;
95 } 86 }
96 87
97 private SparseArray<String> generatePermissionsMapping(int[] contentSettings ) { 88 private SparseArray<String> generatePermissionsMapping(int[] contentSettings ) {
98 Context context = mWindowAndroid.getApplicationContext(); 89 Context context = mWindowAndroid.getApplicationContext();
99 SparseArray<String> permissionsToRequest = new SparseArray<String>(); 90 SparseArray<String> permissionsToRequest = new SparseArray<String>();
100 for (int i = 0; i < contentSettings.length; i++) { 91 for (int i = 0; i < contentSettings.length; i++) {
101 String permission = PrefServiceBridge.getAndroidPermissionForContent Setting( 92 String permission = PrefServiceBridge.getAndroidPermissionForContent Setting(
(...skipping 105 matching lines...) Expand 10 before | Expand all | Expand 10 after
207 } 198 }
208 199
209 private void onButtonClickedInternal(boolean isPrimaryButton) { 200 private void onButtonClickedInternal(boolean isPrimaryButton) {
210 super.onButtonClicked(isPrimaryButton); 201 super.onButtonClicked(isPrimaryButton);
211 } 202 }
212 203
213 /** 204 /**
214 * Returns true if the persist switch exists and is toggled on. 205 * Returns true if the persist switch exists and is toggled on.
215 */ 206 */
216 @CalledByNative 207 @CalledByNative
217 private boolean isPersistSwitchOn() { 208 protected boolean isPersistSwitchOn() {
218 SwitchCompat persistSwitch = (SwitchCompat) getView().findViewById( 209 SwitchCompat persistSwitch = (SwitchCompat) getView().findViewById(
219 R.id.permission_infobar_persist_toggle); 210 R.id.permission_infobar_persist_toggle);
220 if (mShowPersistenceToggle && persistSwitch != null) { 211 if (mShowPersistenceToggle && persistSwitch != null) {
221 return persistSwitch.isChecked(); 212 return persistSwitch.isChecked();
222 } 213 }
223 return false; 214 return false;
224 } 215 }
225 216
226 /** 217 /**
227 * Creates and begins the process for showing a PermissionInfoBar. 218 * Creates and begins the process for showing a PermissionInfoBar.
(...skipping 11 matching lines...) Expand all
239 * @param showPersistenceToggle Whether or not a toggle to opt-out of persis ting a decision 230 * @param showPersistenceToggle Whether or not a toggle to opt-out of persis ting a decision
240 * should be displayed. 231 * should be displayed.
241 */ 232 */
242 @CalledByNative 233 @CalledByNative
243 private static PermissionInfoBar create(WindowAndroid windowAndroid, int enu meratedIconId, 234 private static PermissionInfoBar create(WindowAndroid windowAndroid, int enu meratedIconId,
244 Bitmap iconBitmap, String message, String linkText, String buttonOk, 235 Bitmap iconBitmap, String message, String linkText, String buttonOk,
245 String buttonCancel, int[] contentSettings, boolean showPersistenceT oggle) { 236 String buttonCancel, int[] contentSettings, boolean showPersistenceT oggle) {
246 int drawableId = ResourceId.mapToDrawableId(enumeratedIconId); 237 int drawableId = ResourceId.mapToDrawableId(enumeratedIconId);
247 238
248 PermissionInfoBar infoBar = new PermissionInfoBar(drawableId, iconBitmap , message, linkText, 239 PermissionInfoBar infoBar = new PermissionInfoBar(drawableId, iconBitmap , message, linkText,
249 buttonOk, buttonCancel); 240 buttonOk, buttonCancel, showPersistenceToggle);
250 infoBar.setContentSettings(windowAndroid, contentSettings); 241 infoBar.setContentSettings(windowAndroid, contentSettings);
251 infoBar.setShowPersistenceToggle(showPersistenceToggle);
252 242
253 return infoBar; 243 return infoBar;
254 } 244 }
255 } 245 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698