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.support.v7.widget.SwitchCompat; | 7 import android.support.v7.widget.SwitchCompat; |
8 | 8 |
9 import org.chromium.base.annotations.CalledByNative; | 9 import org.chromium.base.annotations.CalledByNative; |
10 import org.chromium.chrome.R; | 10 import org.chromium.chrome.R; |
11 import org.chromium.chrome.browser.ResourceId; | 11 import org.chromium.chrome.browser.ResourceId; |
12 import org.chromium.ui.base.WindowAndroid; | 12 import org.chromium.ui.base.WindowAndroid; |
13 | 13 |
14 import java.util.ArrayList; | 14 import java.util.ArrayList; |
15 | 15 |
16 /** | 16 /** |
17 * An infobar for showing several permission requests which can be allowed or bl
ocked. | 17 * An infobar for showing several permission requests which can be allowed or bl
ocked. |
18 */ | 18 */ |
19 public class GroupedPermissionInfoBar extends PermissionInfoBar { | 19 public class GroupedPermissionInfoBar extends PermissionInfoBar { |
20 private final int[] mPermissionIcons; | 20 private final int[] mPermissionIcons; |
21 private final String[] mPermissionText; | 21 private final String[] mPermissionText; |
22 private final int[] mContentSettings; | 22 private final int[] mContentSettings; |
23 private final WindowAndroid mWindowAndroid; | 23 private final WindowAndroid mWindowAndroid; |
24 private long mNativeGroupedPermissionInfoBar; | 24 private long mNativeGroupedPermissionInfoBar; |
25 | 25 |
26 GroupedPermissionInfoBar(String message, String buttonOk, String buttonCance
l, | 26 GroupedPermissionInfoBar(String message, String buttonOk, String buttonCance
l, |
27 int[] permissionIcons, String[] permissionText, WindowAndroid window
Android, | 27 int[] permissionIcons, String[] permissionText, WindowAndroid window
Android, |
28 int[] contentSettings) { | 28 int[] contentSettings, boolean showPersistenceToggle) { |
29 super(0, null, message, null, buttonOk, buttonCancel); | 29 super(0, null, message, null, buttonOk, buttonCancel, showPersistenceTog
gle); |
30 mPermissionIcons = permissionIcons; | 30 mPermissionIcons = permissionIcons; |
31 mPermissionText = permissionText; | 31 mPermissionText = permissionText; |
32 mWindowAndroid = windowAndroid; | 32 mWindowAndroid = windowAndroid; |
33 mContentSettings = contentSettings; | 33 mContentSettings = contentSettings; |
34 } | 34 } |
35 | 35 |
36 @Override | 36 @Override |
37 public void createContent(InfoBarLayout layout) { | 37 public void createContent(InfoBarLayout layout) { |
38 super.createContent(layout); | |
39 InfoBarControlLayout control = layout.addControlLayout(); | 38 InfoBarControlLayout control = layout.addControlLayout(); |
40 | 39 |
41 if (mPermissionIcons.length == 1) { | 40 if (mPermissionIcons.length == 1) { |
42 control.addIcon(ResourceId.mapToDrawableId(mPermissionIcons[0]), | 41 control.addIcon(ResourceId.mapToDrawableId(mPermissionIcons[0]), |
43 R.color.light_normal_color, mPermissionText[0], null); | 42 R.color.light_normal_color, mPermissionText[0], null); |
44 } else { | 43 } else { |
45 for (int i = 0; i < mPermissionIcons.length; i++) { | 44 for (int i = 0; i < mPermissionIcons.length; i++) { |
46 control.addSwitch(ResourceId.mapToDrawableId(mPermissionIcons[i]
), | 45 control.addSwitch(ResourceId.mapToDrawableId(mPermissionIcons[i]
), |
47 R.color.light_normal_color, mPermissionText[i], i, true)
; | 46 R.color.light_normal_color, mPermissionText[i], i, true)
; |
48 } | 47 } |
49 } | 48 } |
| 49 |
| 50 // Call this last to ensure that if a persistence toggle is added, it's
added last. |
| 51 super.createContent(layout); |
50 } | 52 } |
51 | 53 |
52 @Override | 54 @Override |
53 public void onButtonClicked(final boolean isPrimaryButton) { | 55 public void onButtonClicked(final boolean isPrimaryButton) { |
54 if (isPrimaryButton) { | 56 if (isPrimaryButton) { |
55 boolean[] toggleStatus = new boolean[mPermissionIcons.length]; | 57 boolean[] toggleStatus = new boolean[mPermissionIcons.length]; |
56 | 58 |
57 if (mPermissionIcons.length == 1) { | 59 if (mPermissionIcons.length == 1) { |
58 toggleStatus[0] = true; | 60 toggleStatus[0] = true; |
59 } else { | 61 } else { |
(...skipping 16 matching lines...) Expand all Loading... |
76 } | 78 } |
77 | 79 |
78 if (mNativeGroupedPermissionInfoBar != 0) { | 80 if (mNativeGroupedPermissionInfoBar != 0) { |
79 nativeSetPermissionState(mNativeGroupedPermissionInfoBar, toggle
Status); | 81 nativeSetPermissionState(mNativeGroupedPermissionInfoBar, toggle
Status); |
80 setContentSettings(mWindowAndroid, selectedArray); | 82 setContentSettings(mWindowAndroid, selectedArray); |
81 } | 83 } |
82 } | 84 } |
83 super.onButtonClicked(isPrimaryButton); | 85 super.onButtonClicked(isPrimaryButton); |
84 } | 86 } |
85 | 87 |
| 88 @CalledByNative |
| 89 protected boolean isPersistSwitchOn() { |
| 90 return super.isPersistSwitchOn(); |
| 91 } |
| 92 |
86 /** | 93 /** |
87 * Create an infobar for a given set of permission requests. | 94 * Create an infobar for a given set of permission requests. |
88 * | 95 * |
89 * @param message Message to display at the top of the infobar. | 96 * @param message Message to display at the top of the infobar. |
90 * @param buttonOk String to display on the 'Allow' button. | 97 * @param buttonOk String to display on the 'Allow' button. |
91 * @param buttonCancel String to display on the 'Block' button. | 98 * @param buttonCancel String to display on the 'Block' button. |
92 * @param permissionIcons Enumerated ID (from ResourceMapper) of an icon to
display next to each | 99 * @param permissionIcons Enumerated ID (from ResourceMapper) of an icon to
display next to each |
93 * permission. | 100 * permission. |
94 * @param permissionText String to display for each permission request. | 101 * @param permissionText String to display for each permission request. |
95 * @param windowAndroid The window which owns the infobar. | 102 * @param windowAndroid The window which owns the infobar. |
96 * @param contentSettings The list of ContentSettingsTypes requested by the
infobar. | 103 * @param contentSettings The list of ContentSettingsTypes requested by the
infobar. |
| 104 * @param showPersistenceToggle Whether or not a toggle to opt-out of persis
ting a decision |
| 105 * should be displayed. |
97 */ | 106 */ |
98 @CalledByNative | 107 @CalledByNative |
99 private static InfoBar create(String message, String buttonOk, String button
Cancel, | 108 private static InfoBar create(String message, String buttonOk, String button
Cancel, |
100 int[] permissionIcons, String[] permissionText, WindowAndroid window
Android, | 109 int[] permissionIcons, String[] permissionText, WindowAndroid window
Android, |
101 int[] contentSettings) { | 110 int[] contentSettings, boolean showPersistenceToggle) { |
102 GroupedPermissionInfoBar infobar = new GroupedPermissionInfoBar(message,
buttonOk, | 111 GroupedPermissionInfoBar infobar = |
103 buttonCancel, permissionIcons, permissionText, windowAndroid, co
ntentSettings); | 112 new GroupedPermissionInfoBar(message, buttonOk, buttonCancel, pe
rmissionIcons, |
| 113 permissionText, windowAndroid, contentSettings, showPers
istenceToggle); |
104 return infobar; | 114 return infobar; |
105 } | 115 } |
106 | 116 |
107 @CalledByNative | 117 @CalledByNative |
108 private void setNativePtr(long nativePtr) { | 118 private void setNativePtr(long nativePtr) { |
109 mNativeGroupedPermissionInfoBar = nativePtr; | 119 mNativeGroupedPermissionInfoBar = nativePtr; |
110 } | 120 } |
111 | 121 |
112 @Override | 122 @Override |
113 protected void onNativeDestroyed() { | 123 protected void onNativeDestroyed() { |
114 mNativeGroupedPermissionInfoBar = 0; | 124 mNativeGroupedPermissionInfoBar = 0; |
115 super.onNativeDestroyed(); | 125 super.onNativeDestroyed(); |
116 } | 126 } |
117 | 127 |
118 private native void nativeSetPermissionState( | 128 private native void nativeSetPermissionState( |
119 long nativeGroupedPermissionInfoBar, boolean[] permissions); | 129 long nativeGroupedPermissionInfoBar, boolean[] permissions); |
120 } | 130 } |
OLD | NEW |