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, boolean showPersistenceToggle) { | 28 int[] contentSettings) { |
29 super(0, null, message, null, buttonOk, buttonCancel, showPersistenceTog
gle); | 29 super(0, null, message, null, buttonOk, buttonCancel); |
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); |
38 InfoBarControlLayout control = layout.addControlLayout(); | 39 InfoBarControlLayout control = layout.addControlLayout(); |
39 | 40 |
40 if (mPermissionIcons.length == 1) { | 41 if (mPermissionIcons.length == 1) { |
41 control.addIcon(ResourceId.mapToDrawableId(mPermissionIcons[0]), | 42 control.addIcon(ResourceId.mapToDrawableId(mPermissionIcons[0]), |
42 R.color.light_normal_color, mPermissionText[0], null); | 43 R.color.light_normal_color, mPermissionText[0], null); |
43 } else { | 44 } else { |
44 for (int i = 0; i < mPermissionIcons.length; i++) { | 45 for (int i = 0; i < mPermissionIcons.length; i++) { |
45 control.addSwitch(ResourceId.mapToDrawableId(mPermissionIcons[i]
), | 46 control.addSwitch(ResourceId.mapToDrawableId(mPermissionIcons[i]
), |
46 R.color.light_normal_color, mPermissionText[i], i, true)
; | 47 R.color.light_normal_color, mPermissionText[i], i, true)
; |
47 } | 48 } |
48 } | 49 } |
49 | |
50 // Call this last to ensure that if a persistence toggle is added, it's
added last. | |
51 super.createContent(layout); | |
52 } | 50 } |
53 | 51 |
54 @Override | 52 @Override |
55 public void onButtonClicked(final boolean isPrimaryButton) { | 53 public void onButtonClicked(final boolean isPrimaryButton) { |
56 if (isPrimaryButton) { | 54 if (isPrimaryButton) { |
57 boolean[] toggleStatus = new boolean[mPermissionIcons.length]; | 55 boolean[] toggleStatus = new boolean[mPermissionIcons.length]; |
58 | 56 |
59 if (mPermissionIcons.length == 1) { | 57 if (mPermissionIcons.length == 1) { |
60 toggleStatus[0] = true; | 58 toggleStatus[0] = true; |
61 } else { | 59 } else { |
(...skipping 16 matching lines...) Expand all Loading... |
78 } | 76 } |
79 | 77 |
80 if (mNativeGroupedPermissionInfoBar != 0) { | 78 if (mNativeGroupedPermissionInfoBar != 0) { |
81 nativeSetPermissionState(mNativeGroupedPermissionInfoBar, toggle
Status); | 79 nativeSetPermissionState(mNativeGroupedPermissionInfoBar, toggle
Status); |
82 setContentSettings(mWindowAndroid, selectedArray); | 80 setContentSettings(mWindowAndroid, selectedArray); |
83 } | 81 } |
84 } | 82 } |
85 super.onButtonClicked(isPrimaryButton); | 83 super.onButtonClicked(isPrimaryButton); |
86 } | 84 } |
87 | 85 |
88 @CalledByNative | |
89 protected boolean isPersistSwitchOn() { | |
90 return super.isPersistSwitchOn(); | |
91 } | |
92 | |
93 /** | 86 /** |
94 * Create an infobar for a given set of permission requests. | 87 * Create an infobar for a given set of permission requests. |
95 * | 88 * |
96 * @param message Message to display at the top of the infobar. | 89 * @param message Message to display at the top of the infobar. |
97 * @param buttonOk String to display on the 'Allow' button. | 90 * @param buttonOk String to display on the 'Allow' button. |
98 * @param buttonCancel String to display on the 'Block' button. | 91 * @param buttonCancel String to display on the 'Block' button. |
99 * @param permissionIcons Enumerated ID (from ResourceMapper) of an icon to
display next to each | 92 * @param permissionIcons Enumerated ID (from ResourceMapper) of an icon to
display next to each |
100 * permission. | 93 * permission. |
101 * @param permissionText String to display for each permission request. | 94 * @param permissionText String to display for each permission request. |
102 * @param windowAndroid The window which owns the infobar. | 95 * @param windowAndroid The window which owns the infobar. |
103 * @param contentSettings The list of ContentSettingsTypes requested by the
infobar. | 96 * @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. | |
106 */ | 97 */ |
107 @CalledByNative | 98 @CalledByNative |
108 private static InfoBar create(String message, String buttonOk, String button
Cancel, | 99 private static InfoBar create(String message, String buttonOk, String button
Cancel, |
109 int[] permissionIcons, String[] permissionText, WindowAndroid window
Android, | 100 int[] permissionIcons, String[] permissionText, WindowAndroid window
Android, |
110 int[] contentSettings, boolean showPersistenceToggle) { | 101 int[] contentSettings) { |
111 GroupedPermissionInfoBar infobar = | 102 GroupedPermissionInfoBar infobar = new GroupedPermissionInfoBar(message,
buttonOk, |
112 new GroupedPermissionInfoBar(message, buttonOk, buttonCancel, pe
rmissionIcons, | 103 buttonCancel, permissionIcons, permissionText, windowAndroid, co
ntentSettings); |
113 permissionText, windowAndroid, contentSettings, showPers
istenceToggle); | |
114 return infobar; | 104 return infobar; |
115 } | 105 } |
116 | 106 |
117 @CalledByNative | 107 @CalledByNative |
118 private void setNativePtr(long nativePtr) { | 108 private void setNativePtr(long nativePtr) { |
119 mNativeGroupedPermissionInfoBar = nativePtr; | 109 mNativeGroupedPermissionInfoBar = nativePtr; |
120 } | 110 } |
121 | 111 |
122 @Override | 112 @Override |
123 protected void onNativeDestroyed() { | 113 protected void onNativeDestroyed() { |
124 mNativeGroupedPermissionInfoBar = 0; | 114 mNativeGroupedPermissionInfoBar = 0; |
125 super.onNativeDestroyed(); | 115 super.onNativeDestroyed(); |
126 } | 116 } |
127 | 117 |
128 private native void nativeSetPermissionState( | 118 private native void nativeSetPermissionState( |
129 long nativeGroupedPermissionInfoBar, boolean[] permissions); | 119 long nativeGroupedPermissionInfoBar, boolean[] permissions); |
130 } | 120 } |
OLD | NEW |