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

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: Address review comment 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..cd115feb88e2812bf73d3fd5f239b8a54346461f
--- /dev/null
+++ b/chrome/android/java/src/org/chromium/chrome/browser/infobar/PermissionGroupInfoBarAndroid.java
@@ -0,0 +1,119 @@
+// 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 a website requests multiple permissions at the same time.
+ */
+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;
+ case ContentSettingsType.CONTENT_SETTINGS_TYPE_PUSH_MESSAGING:
+ case ContentSettingsType.CONTENT_SETTINGS_TYPE_PROTECTED_MEDIA_IDENTIFIER:
+ case ContentSettingsType.CONTENT_SETTINGS_TYPE_DURABLE_STORAGE:
+ case ContentSettingsType.CONTENT_SETTINGS_TYPE_MEDIASTREAM_MIC:
+ case ContentSettingsType.CONTENT_SETTINGS_TYPE_MEDIASTREAM_CAMERA:
+ assert false;
+ return R.drawable.infobar_warning;
+ default:
+ 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);
+}
« no previous file with comments | « chrome/android/java/res/layout/permission_group_infobar_item.xml ('k') | chrome/app/generated_resources.grd » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698