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

Side by Side Diff: chrome/android/java/src/org/chromium/chrome/browser/permissions/PermissionDialogDelegate.java

Issue 2446063002: Implement a modal permission dialog on Android gated by a feature. (Closed)
Patch Set: Rebase Created 4 years, 1 month 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 unified diff | Download patch
OLDNEW
(Empty)
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
3 // found in the LICENSE file.
4
5 package org.chromium.chrome.browser.permissions;
6
7 import android.app.Activity;
8
9 import org.chromium.base.annotations.CalledByNative;
10 import org.chromium.chrome.browser.ResourceId;
11 import org.chromium.ui.base.WindowAndroid;
12
13 /**
14 * Delegate class for modal permission dialogs. Contains all of the data display ed in a prompt,
15 * including the button strings, message text, link text, the icon, and whether or not to display
16 * a persistence toggle.
17 *
18 * This class is also the interface to the native-side permissions code. When th e user responds to
19 * the permission dialog, the decision is conveyed across the JNI so that the na tive code can
20 * respond appropriately.
21 */
22 public class PermissionDialogDelegate {
23 /** The native-side counterpart of this class */
24 private long mNativeDelegatePtr;
25
26 /** The activity for which to create the dialog. */
27 private Activity mActivity;
28
29 /** The icon to display in the dialog. */
30 private int mDrawableId;
31
32 /** Text shown in the dialog. */
33 private String mMessageText;
34
35 /** Text shown on the link, e.g. "Learn more". */
36 private String mLinkText;
37
38 /** Text shown on the primary button, e.g. "Allow". */
39 private String mPrimaryButtonText;
40
41 /** Text shown on the secondary button, e.g. "Block". */
42 private String mSecondaryButtonText;
43
44 /** Whether or not to show a toggle for opting out of persisting the decisio n. */
45 private boolean mShowPersistenceToggle;
46
47 /** Whether or not a decision has been made for this delegate */
48 private boolean mDecided;
49
50 public Activity getActivity() {
51 return mActivity;
52 }
53
54 public int getDrawableId() {
55 return mDrawableId;
56 }
gone 2016/10/27 20:33:34 nit: Stick newlines in between
dominickn 2016/10/27 23:37:12 Done.
57 public String getMessageText() {
58 return mMessageText;
59 }
60 public String getLinkText() {
61 return mLinkText;
62 }
63 public String getPrimaryButtonText() {
64 return mPrimaryButtonText;
65 }
66 public String getSecondaryButtonText() {
67 return mSecondaryButtonText;
68 }
69 public boolean shouldShowPersistenceToggle() {
70 return mShowPersistenceToggle;
71 }
72
73 public void onAccept(boolean persist) {
74 assert mNativeDelegatePtr != 0;
75 mDecided = true;
76 nativeAccept(mNativeDelegatePtr, persist);
77 }
78
79 public void onCancel(boolean persist) {
80 assert mNativeDelegatePtr != 0;
81 mDecided = true;
82 nativeCancel(mNativeDelegatePtr, persist);
83 }
84
85 public void onDismiss() {
86 assert mNativeDelegatePtr != 0;
87 if (!mDecided) nativeDismissed(mNativeDelegatePtr);
88 nativeDestroy(mNativeDelegatePtr);
89 mNativeDelegatePtr = 0;
90 }
91
92 public void onLinkClicked() {
93 assert mNativeDelegatePtr != 0;
94 nativeLinkClicked(mNativeDelegatePtr);
95 }
96
97 /**
98 * Called from C++ by |nativeDelegatePtr| to instantiate this class.
99 *
100 * @param nativeDelegatePtr The native counterpart that this object owns .
101 * @param window The window to create the dialog for.
102 * @param iconResourceId The id of the icon to display in the dialog.
103 * @param message The message to display in the dialog.
104 * @param linkText The text to display in the link (if any).
105 * @param primaryTextButton The text to display on the primary button.
106 * @param secondaryTextButton The text to display on the primary button.
107 * @param showPersistenceToggle Whether or not to display a persistence togg le.
108 */
109 @CalledByNative
110 private static PermissionDialogDelegate create(long nativeDelegatePtr, Windo wAndroid window,
111 int enumeratedIconId, String message, String linkText, String primar yButtonText,
112 String secondaryButtonText, boolean showPersistenceToggle) {
113 return new PermissionDialogDelegate(nativeDelegatePtr, window, enumerate dIconId, message,
114 linkText, primaryButtonText, secondaryButtonText, showPersistenc eToggle);
115 }
116
117 /**
118 * Upon construction, this class takes ownership of the passed in native del egate.
119 */
120 private PermissionDialogDelegate(long nativeDelegatePtr, WindowAndroid windo w,
121 int enumeratedIconId, String message, String linkText, String primar yButtonText,
122 String secondaryButtonText, boolean showPersistenceToggle) {
123 mNativeDelegatePtr = nativeDelegatePtr;
124 mActivity = window.getActivity().get();
125 mDrawableId = ResourceId.mapToDrawableId(enumeratedIconId);
126 mMessageText = message;
127 mLinkText = linkText;
128 mPrimaryButtonText = primaryButtonText;
129 mSecondaryButtonText = secondaryButtonText;
130 mShowPersistenceToggle = showPersistenceToggle;
131 }
132
133 private native void nativeAccept(long nativePermissionDialogDelegate, boolea n persist);
134 private native void nativeCancel(long nativePermissionDialogDelegate, boolea n persist);
135 private native void nativeDismissed(long nativePermissionDialogDelegate);
136 private native void nativeLinkClicked(long nativePermissionDialogDelegate);
137 private native void nativeDestroy(long nativePermissionDialogDelegate);
138 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698