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