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..5ef19435dc6add430e4371df71f442e6af59d5c0 |
--- /dev/null |
+++ b/chrome/android/java/src/org/chromium/chrome/browser/infobar/PermissionGroupInfoBarAndroid.java |
@@ -0,0 +1,148 @@ |
+// 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; |
+ |
+/** |
+ * TODO(lalitm) |
+ */ |
+public class PermissionGroupInfoBarAndroid extends ConfirmInfoBar |
+ implements InfoBarListeners.Confirm { |
+ |
+ private final int[] mContentSettings; |
+ |
+ private long mNativePointer; |
+ private ViewGroup mCustomView; |
+ |
+ private PermissionGroupInfoBarAndroid( |
+ long nativePtr, String messageTitle, int[] contentSettings) { |
+ super(null, 0, null, messageTitle, null, getAcceptButtonText(), null); |
+ setConfirmListener(this); |
+ |
+ mNativePointer = nativePtr; |
+ mContentSettings = contentSettings; |
+ } |
+ |
+ @CalledByNative |
+ private void destroy() { |
+ mNativePointer = 0; |
gone
2015/09/18 21:02:43
Doesn't make sense to call this destroy() if it's
Lalit Maganti
2015/09/21 11:20:08
Done.
|
+ } |
+ |
+ @Override |
+ public void createContent(InfoBarLayout layout) { |
+ super.createContent(layout); |
+ |
+ mCustomView = (ViewGroup) LayoutInflater.from(getContext()) |
+ .inflate(R.layout.permission_group_infobar, null); |
+ |
+ for (int contentSetting : mContentSettings) { |
+ 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(contentSettingToString(contentSetting)); |
+ iconView.setImageResource(contentSettingToIconResource(contentSetting)); |
+ mCustomView.addView(subView); |
+ } |
+ |
+ layout.setCustomContent(mCustomView); |
+ } |
+ |
+ @Override |
+ public void onConfirmInfoBarButtonClicked(ConfirmInfoBar infoBar, boolean confirm) { |
+ 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); |
+ } |
+ |
+ @Override |
+ public void onInfoBarDismissed(InfoBar infoBar) { |
+ } |
+ |
+ private String contentSettingToString(int type) { |
+ switch (type) { |
+ case ContentSettingsType.CONTENT_SETTINGS_TYPE_GEOLOCATION: |
+ return getContext().getString(R.string.coalesced_permission_infobar_geolocation); |
+ case ContentSettingsType.CONTENT_SETTINGS_TYPE_NOTIFICATIONS: |
+ return getContext().getString(R.string.coalesced_permission_infobar_notifications); |
+ case ContentSettingsType.CONTENT_SETTINGS_TYPE_MIDI_SYSEX: |
+ return getContext().getString(R.string.coalesced_permission_infobar_notifications); |
+ case ContentSettingsType.CONTENT_SETTINGS_TYPE_PUSH_MESSAGING: |
+ return getContext().getString(R.string.coalesced_permission_infobar_push); |
+ case ContentSettingsType.CONTENT_SETTINGS_TYPE_PROTECTED_MEDIA_IDENTIFIER: |
+ return getContext().getString( |
+ R.string.coalesced_permission_infobar_protected_media); |
+ case ContentSettingsType.CONTENT_SETTINGS_TYPE_DURABLE_STORAGE: |
+ return getContext().getString( |
+ R.string.coalesced_permission_infobar_protected_media); |
+ case ContentSettingsType.CONTENT_SETTINGS_TYPE_MEDIASTREAM_MIC: |
+ return getContext().getString( |
+ R.string.coalesced_permission_infobar_audio_capture); |
+ case ContentSettingsType.CONTENT_SETTINGS_TYPE_MEDIASTREAM_CAMERA: |
+ return getContext().getString( |
+ R.string.coalesced_permission_infobar_video_capture); |
+ } |
+ assert false; |
+ return null; |
+ } |
+ |
+ 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: |
+ return R.drawable.permission_push_notification; |
+ case ContentSettingsType.CONTENT_SETTINGS_TYPE_PROTECTED_MEDIA_IDENTIFIER: |
+ return R.drawable.permission_protected_media; |
+ case ContentSettingsType.CONTENT_SETTINGS_TYPE_DURABLE_STORAGE: |
+ return R.drawable.permission_cookie; |
+ case ContentSettingsType.CONTENT_SETTINGS_TYPE_MEDIASTREAM_MIC: |
+ return R.drawable.permission_mic; |
+ case ContentSettingsType.CONTENT_SETTINGS_TYPE_MEDIASTREAM_CAMERA: |
+ return R.drawable.permission_camera; |
+ } |
+ 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, |
+ int[] contentSettings) { |
+ PermissionGroupInfoBarAndroid infobar = new PermissionGroupInfoBarAndroid( |
+ nativePtr, messageTitle, contentSettings); |
+ infobar.setContentSettings(windowAndroid, contentSettings); |
+ return infobar; |
+ } |
+ |
+ private native void nativeOnCheckedStateUpdate(long nativePermissionGroupInfoBarAndroid, |
+ boolean[] checked); |
+} |