| 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.permissions; | 5 package org.chromium.chrome.browser.permissions; |
| 6 | 6 |
| 7 import android.annotation.SuppressLint; | 7 import android.annotation.SuppressLint; |
| 8 import android.app.Activity; | 8 import android.app.Activity; |
| 9 import android.content.DialogInterface; | 9 import android.content.DialogInterface; |
| 10 import android.support.annotation.IntDef; | 10 import android.support.annotation.IntDef; |
| (...skipping 71 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 82 | 82 |
| 83 /** | 83 /** |
| 84 * Queues a modal permission dialog for display. If there are currently no d
ialogs on screen, it | 84 * Queues a modal permission dialog for display. If there are currently no d
ialogs on screen, it |
| 85 * will be displayed immediately. Otherwise, it will be displayed as soon as
the user responds | 85 * will be displayed immediately. Otherwise, it will be displayed as soon as
the user responds |
| 86 * to the current dialog. | 86 * to the current dialog. |
| 87 * @param context The context to use to get the dialog layout. | 87 * @param context The context to use to get the dialog layout. |
| 88 * @param delegate The wrapper for the native-side permission delegate. | 88 * @param delegate The wrapper for the native-side permission delegate. |
| 89 */ | 89 */ |
| 90 private void queueDialog(PermissionDialogDelegate delegate) { | 90 private void queueDialog(PermissionDialogDelegate delegate) { |
| 91 mRequestQueue.add(delegate); | 91 mRequestQueue.add(delegate); |
| 92 delegate.setDialogController(this); |
| 92 scheduleDisplay(); | 93 scheduleDisplay(); |
| 93 } | 94 } |
| 94 | 95 |
| 95 private void scheduleDisplay() { | 96 private void scheduleDisplay() { |
| 96 if (mDialog == null && !mRequestQueue.isEmpty()) showDialog(); | 97 if (mDialog == null && !mRequestQueue.isEmpty()) showDialog(); |
| 97 } | 98 } |
| 98 | 99 |
| 99 @VisibleForTesting | 100 @VisibleForTesting |
| 100 public AlertDialog getCurrentDialogForTesting() { | 101 public AlertDialog getCurrentDialogForTesting() { |
| 101 return mDialog; | 102 return mDialog; |
| 102 } | 103 } |
| 103 | 104 |
| 105 @VisibleForTesting |
| 106 public int getQueueLengthForTesting() { |
| 107 return mRequestQueue.size(); |
| 108 } |
| 109 |
| 104 @Override | 110 @Override |
| 105 public void onAndroidPermissionAccepted() { | 111 public void onAndroidPermissionAccepted() { |
| 106 mDialogDelegate.onAccept(mSwitchView.isChecked()); | 112 mDialogDelegate.onAccept(mSwitchView.isChecked()); |
| 107 destroyDelegate(); | 113 destroyDelegate(); |
| 108 scheduleDisplay(); | 114 scheduleDisplay(); |
| 109 } | 115 } |
| 110 | 116 |
| 111 @Override | 117 @Override |
| 112 public void onAndroidPermissionCanceled() { | 118 public void onAndroidPermissionCanceled() { |
| 113 mDialogDelegate.onDismiss(); | 119 mDialogDelegate.onDismiss(); |
| (...skipping 72 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 186 public void onClick(DialogInterface dialog, int id) { | 192 public void onClick(DialogInterface dialog, int id) { |
| 187 mDecision = CANCELED; | 193 mDecision = CANCELED; |
| 188 } | 194 } |
| 189 }); | 195 }); |
| 190 | 196 |
| 191 // Called when the dialog is dismissed. Interacting with either button i
n the dialog will | 197 // Called when the dialog is dismissed. Interacting with either button i
n the dialog will |
| 192 // call this handler after the primary/secondary handler. | 198 // call this handler after the primary/secondary handler. |
| 193 mDialog.setOnDismissListener(new DialogInterface.OnDismissListener() { | 199 mDialog.setOnDismissListener(new DialogInterface.OnDismissListener() { |
| 194 @Override | 200 @Override |
| 195 public void onDismiss(DialogInterface dialog) { | 201 public void onDismiss(DialogInterface dialog) { |
| 196 // For some reason this is ocassionally null. See crbug.com/7085
62. | 202 // Null if dismiss initiated by C++, or for some unknown reason
(crbug.com/708562). |
| 197 if (mDialogDelegate == null) { | 203 if (mDialogDelegate == null) { |
| 198 scheduleDisplay(); | 204 scheduleDisplay(); |
| 205 return; |
| 199 } | 206 } |
| 200 | 207 |
| 201 mDialog = null; | 208 mDialog = null; |
| 202 if (mDecision == ACCEPTED) { | 209 if (mDecision == ACCEPTED) { |
| 203 // Request Android permissions if necessary. This will call
back into either | 210 // Request Android permissions if necessary. This will call
back into either |
| 204 // onAndroidPermissionAccepted or onAndroidPermissionCancele
d, which will | 211 // onAndroidPermissionAccepted or onAndroidPermissionCancele
d, which will |
| 205 // schedule the next permission dialog. If it returns false,
no system level | 212 // schedule the next permission dialog. If it returns false,
no system level |
| 206 // permissions need to be requested, so just run the accept
callback. | 213 // permissions need to be requested, so just run the accept
callback. |
| 207 if (!AndroidPermissionRequester.requestAndroidPermissions( | 214 if (!AndroidPermissionRequester.requestAndroidPermissions( |
| 208 mDialogDelegate.getTab(), mDialogDelegate.getCon
tentSettingsTypes(), | 215 mDialogDelegate.getTab(), mDialogDelegate.getCon
tentSettingsTypes(), |
| (...skipping 37 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 246 mDecision = NOT_DECIDED; | 253 mDecision = NOT_DECIDED; |
| 247 delegate.onLinkClicked(); | 254 delegate.onLinkClicked(); |
| 248 if (mDialog != null) mDialog.dismiss(); | 255 if (mDialog != null) mDialog.dismiss(); |
| 249 } | 256 } |
| 250 }, spanStart, fullString.length(), Spanned.SPAN_EXCLUSIVE_EXCLUSIVE)
; | 257 }, spanStart, fullString.length(), Spanned.SPAN_EXCLUSIVE_EXCLUSIVE)
; |
| 251 } | 258 } |
| 252 | 259 |
| 253 return fullString; | 260 return fullString; |
| 254 } | 261 } |
| 255 | 262 |
| 263 public void dismissFromNative(PermissionDialogDelegate delegate) { |
| 264 if (mDialogDelegate == delegate) { |
| 265 mDialogDelegate = null; |
| 266 AlertDialog dialog = mDialog; |
| 267 mDialog = null; |
| 268 dialog.dismiss(); |
| 269 } else { |
| 270 assert mRequestQueue.contains(delegate); |
| 271 mRequestQueue.remove(delegate); |
| 272 } |
| 273 delegate.destroy(); |
| 274 } |
| 275 |
| 256 private void destroyDelegate() { | 276 private void destroyDelegate() { |
| 257 mDialogDelegate.destroy(); | 277 mDialogDelegate.destroy(); |
| 258 mDialogDelegate = null; | 278 mDialogDelegate = null; |
| 259 } | 279 } |
| 260 } | 280 } |
| OLD | NEW |