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

Unified Diff: chrome/android/java/src/org/chromium/chrome/browser/infobar/PermissionGroupInfoBarAndroid.java

Issue 1332063003: permissions: implement coalesced permissions on Android (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@request-multiple
Patch Set: Switch to using other version of onButtonClicked Created 5 years, 3 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 side-by-side diff with in-line comments
Download patch
Index: chrome/android/java/src/org/chromium/chrome/browser/infobar/PermissionGroupInfoBarAndroid.java
diff --git a/chrome/android/java/src/org/chromium/chrome/browser/infobar/PermissionGroupInfoBarAndroid.java b/chrome/android/java/src/org/chromium/chrome/browser/infobar/PermissionGroupInfoBarAndroid.java
new file mode 100644
index 0000000000000000000000000000000000000000..77b692f9df00de5e7d3c4d479fd64e349702e543
--- /dev/null
+++ b/chrome/android/java/src/org/chromium/chrome/browser/infobar/PermissionGroupInfoBarAndroid.java
@@ -0,0 +1,112 @@
+// Copyright 2015 The Chromium Authors. All rights reserved.
+// Use of this source code is governed by a BSD-style license that can be
+// found in the LICENSE file.
+
+package org.chromium.chrome.browser.infobar;
+
+import android.view.LayoutInflater;
+import android.view.ViewGroup;
+import android.widget.ImageView;
+import android.widget.Switch;
+import android.widget.TextView;
+
+import org.chromium.base.ApplicationStatus;
+import org.chromium.base.annotations.CalledByNative;
+import org.chromium.chrome.R;
+import org.chromium.chrome.browser.ContentSettingsType;
+import org.chromium.ui.base.WindowAndroid;
+
+/**
+ * Infobar which are shown when multiple permissions are requested at the same time.
gone 2015/09/28 10:48:43 nit: are -> is
Lalit Maganti 2015/09/28 12:41:25 Hmmmm I would still use are TBH. Anyway, I've rewo
gone 2015/09/28 12:43:21 Split personalities then; from your permission_gro
+ */
+public class PermissionGroupInfoBarAndroid extends ConfirmInfoBar {
+
+ private final String[] mPermissionMessages;
+ private final int[] mContentSettings;
+
+ private long mNativePointer;
+ private ViewGroup mCustomView;
+
+ private PermissionGroupInfoBarAndroid(long nativePtr, String messageTitle,
+ String[] permissionMessages, int[] contentSettings) {
+ super(null, 0, null, messageTitle, null, getAcceptButtonText(), null);
+
+ mNativePointer = nativePtr;
+ mPermissionMessages = permissionMessages;
+ mContentSettings = contentSettings;
+ }
+
+ @CalledByNative
+ protected void onNativeDestroyed() {
+ super.onNativeDestroyed();
+ mNativePointer = 0;
+ }
+
+ @Override
+ public void createContent(InfoBarLayout layout) {
+ super.createContent(layout);
+
+ mCustomView = (ViewGroup) LayoutInflater.from(getContext())
+ .inflate(R.layout.permission_group_infobar, null);
+
+ for (int i = 0; i < mContentSettings.length; i++) {
+ ViewGroup subView = (ViewGroup) LayoutInflater.from(getContext())
+ .inflate(R.layout.permission_group_infobar_item, null);
+ TextView textView = (TextView) subView.findViewById(
+ R.id.permission_group_infobar_item_text);
+ ImageView iconView = (ImageView) subView.findViewById(
+ R.id.permission_group_infobar_item_icon);
+
+ textView.setText(mPermissionMessages[i]);
+ iconView.setImageResource(contentSettingToIconResource(mContentSettings[i]));
+ mCustomView.addView(subView);
+ }
+
+ layout.setCustomContent(mCustomView);
+ }
+
+ @Override
+ protected void onButtonClicked(int action) {
+ assert action == ActionType.CANCEL;
+
+ boolean[] checkedState = new boolean[mContentSettings.length];
+ for (int i = 0; i < mContentSettings.length; i++) {
+ Switch childSwitch = (Switch) mCustomView.getChildAt(i)
+ .findViewById(R.id.permission_group_infobar_item_switch);
+ checkedState[i] = childSwitch.isChecked();
+ }
+ nativeOnCheckedStateUpdate(mNativePointer, checkedState);
+
+ super.onButtonClicked(action);
+ }
+
+ private static int contentSettingToIconResource(int type) {
+ switch (type) {
+ case ContentSettingsType.CONTENT_SETTINGS_TYPE_GEOLOCATION:
+ return R.drawable.permission_location;
+ case ContentSettingsType.CONTENT_SETTINGS_TYPE_NOTIFICATIONS:
+ return R.drawable.permission_push_notification;
+ case ContentSettingsType.CONTENT_SETTINGS_TYPE_MIDI_SYSEX:
+ return R.drawable.permission_midi;
+ default:
gone 2015/09/28 10:48:43 Checked with Lalit -- apparently these other ones
Lalit Maganti 2015/09/28 12:41:25 Done.
+ assert false;
+ }
+ return R.drawable.permission_location;
+ }
+
+ private static String getAcceptButtonText() {
+ return ApplicationStatus.getApplicationContext().getString(R.string.ok);
+ }
+
+ @CalledByNative
+ private static InfoBar createInfoBar(long nativePtr, WindowAndroid windowAndroid,
+ String messageTitle, String[] permissionMessages, int[] contentSettings) {
+ PermissionGroupInfoBarAndroid infobar = new PermissionGroupInfoBarAndroid(
+ nativePtr, messageTitle, permissionMessages, contentSettings);
+ infobar.setContentSettings(windowAndroid, contentSettings);
+ return infobar;
+ }
+
+ private native void nativeOnCheckedStateUpdate(long nativePermissionGroupInfoBarAndroid,
+ boolean[] checked);
+}

Powered by Google App Engine
This is Rietveld 408576698