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

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

Issue 2038753004: Add a LocationUtils class to give all Chromium Android code access to location helpers. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@lkcr
Patch Set: Adjust DEPS. Created 4 years, 6 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 unified diff | Download patch
OLDNEW
1 // Copyright 2015 The Chromium Authors. All rights reserved. 1 // Copyright 2015 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; 5 package org.chromium.chrome.browser;
6 6
7 import android.Manifest; 7 import android.Manifest;
8 import android.app.Activity; 8 import android.app.Activity;
9 import android.content.Context; 9 import android.content.Context;
10 import android.content.Intent; 10 import android.content.Intent;
11 import android.content.pm.PackageManager; 11 import android.content.pm.PackageManager;
12 import android.text.SpannableString; 12 import android.text.SpannableString;
13 import android.text.TextUtils; 13 import android.text.TextUtils;
14 import android.view.View; 14 import android.view.View;
15 15
16 import org.chromium.base.VisibleForTesting; 16 import org.chromium.base.VisibleForTesting;
17 import org.chromium.base.annotations.CalledByNative; 17 import org.chromium.base.annotations.CalledByNative;
18 import org.chromium.chrome.R; 18 import org.chromium.chrome.R;
19 import org.chromium.chrome.browser.omnibox.OmniboxUrlEmphasizer; 19 import org.chromium.chrome.browser.omnibox.OmniboxUrlEmphasizer;
20 import org.chromium.chrome.browser.profiles.Profile; 20 import org.chromium.chrome.browser.profiles.Profile;
21 import org.chromium.components.location.LocationUtils;
21 import org.chromium.ui.base.WindowAndroid; 22 import org.chromium.ui.base.WindowAndroid;
22 import org.chromium.ui.text.NoUnderlineClickableSpan; 23 import org.chromium.ui.text.NoUnderlineClickableSpan;
23 import org.chromium.ui.text.SpanApplier; 24 import org.chromium.ui.text.SpanApplier;
24 import org.chromium.ui.text.SpanApplier.SpanInfo; 25 import org.chromium.ui.text.SpanApplier.SpanInfo;
25 26
26 /** 27 /**
27 * A dialog for picking available Bluetooth devices. This dialog is shown when a website requests to 28 * A dialog for picking available Bluetooth devices. This dialog is shown when a website requests to
28 * pair with a certain class of Bluetooth devices (e.g. through a bluetooth.requ estDevice Javascript 29 * pair with a certain class of Bluetooth devices (e.g. through a bluetooth.requ estDevice Javascript
29 * call). 30 * call).
30 */ 31 */
(...skipping 123 matching lines...) Expand 10 before | Expand all | Expand 10 after
154 } else { 155 } else {
155 checkLocationPermission(); 156 checkLocationPermission();
156 } 157 }
157 return; 158 return;
158 } 159 }
159 } 160 }
160 // If the location permission is not present, leave the currently-shown message in place. 161 // If the location permission is not present, leave the currently-shown message in place.
161 } 162 }
162 163
163 private void checkLocationPermission() { 164 private void checkLocationPermission() {
164 if (mWindowAndroid.hasPermission(Manifest.permission.ACCESS_COARSE_LOCAT ION) 165 if (LocationUtils.getInstance().hasAndroidLocationPermission(mActivity)) {
165 || mWindowAndroid.hasPermission(Manifest.permission.ACCESS_FINE_ LOCATION)) {
166 return; 166 return;
167 } 167 }
168 168
169 if (!mWindowAndroid.canRequestPermission(Manifest.permission.ACCESS_COAR SE_LOCATION)) { 169 if (!mWindowAndroid.canRequestPermission(Manifest.permission.ACCESS_COAR SE_LOCATION)) {
170 if (mNativeBluetoothChooserDialogPtr != 0) { 170 if (mNativeBluetoothChooserDialogPtr != 0) {
171 nativeOnDialogFinished( 171 nativeOnDialogFinished(
172 mNativeBluetoothChooserDialogPtr, DIALOG_FINISHED_DENIED _PERMISSION, ""); 172 mNativeBluetoothChooserDialogPtr, DIALOG_FINISHED_DENIED _PERMISSION, "");
173 return; 173 return;
174 } 174 }
175 } 175 }
(...skipping 72 matching lines...) Expand 10 before | Expand all | Expand 10 after
248 } 248 }
249 249
250 // Get rid of the highlight background on selection. 250 // Get rid of the highlight background on selection.
251 view.invalidate(); 251 view.invalidate();
252 } 252 }
253 } 253 }
254 254
255 @CalledByNative 255 @CalledByNative
256 private static BluetoothChooserDialog create(WindowAndroid windowAndroid, St ring origin, 256 private static BluetoothChooserDialog create(WindowAndroid windowAndroid, St ring origin,
257 int securityLevel, long nativeBluetoothChooserDialogPtr) { 257 int securityLevel, long nativeBluetoothChooserDialogPtr) {
258 if (!windowAndroid.hasPermission(Manifest.permission.ACCESS_COARSE_LOCAT ION) 258 if (!LocationUtils.getInstance().hasAndroidLocationPermission(
259 && !windowAndroid.hasPermission(Manifest.permission.ACCESS_FINE_ LOCATION) 259 windowAndroid.getActivity().get())
260 && !windowAndroid.canRequestPermission( 260 && !windowAndroid.canRequestPermission(
261 Manifest.permission.ACCESS_COARSE_LOCATION)) { 261 Manifest.permission.ACCESS_COARSE_LOCATION)) {
262 // If we can't even ask for enough permission to scan for Bluetooth devices, don't open 262 // If we can't even ask for enough permission to scan for Bluetooth devices, don't open
263 // the dialog. 263 // the dialog.
264 return null; 264 return null;
265 } 265 }
266 BluetoothChooserDialog dialog = new BluetoothChooserDialog( 266 BluetoothChooserDialog dialog = new BluetoothChooserDialog(
267 windowAndroid, origin, securityLevel, nativeBluetoothChooserDial ogPtr); 267 windowAndroid, origin, securityLevel, nativeBluetoothChooserDial ogPtr);
268 dialog.show(); 268 dialog.show();
269 return dialog; 269 return dialog;
(...skipping 69 matching lines...) Expand 10 before | Expand all | Expand 10 after
339 @VisibleForTesting 339 @VisibleForTesting
340 native void nativeRestartSearch(long nativeBluetoothChooserAndroid); 340 native void nativeRestartSearch(long nativeBluetoothChooserAndroid);
341 // Help links. 341 // Help links.
342 @VisibleForTesting 342 @VisibleForTesting
343 native void nativeShowBluetoothOverviewLink(long nativeBluetoothChooserAndro id); 343 native void nativeShowBluetoothOverviewLink(long nativeBluetoothChooserAndro id);
344 @VisibleForTesting 344 @VisibleForTesting
345 native void nativeShowBluetoothAdapterOffLink(long nativeBluetoothChooserAnd roid); 345 native void nativeShowBluetoothAdapterOffLink(long nativeBluetoothChooserAnd roid);
346 @VisibleForTesting 346 @VisibleForTesting
347 native void nativeShowNeedLocationPermissionLink(long nativeBluetoothChooser Android); 347 native void nativeShowNeedLocationPermissionLink(long nativeBluetoothChooser Android);
348 } 348 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698