OLD | NEW |
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; | |
22 import org.chromium.ui.base.WindowAndroid; | 21 import org.chromium.ui.base.WindowAndroid; |
23 import org.chromium.ui.text.NoUnderlineClickableSpan; | 22 import org.chromium.ui.text.NoUnderlineClickableSpan; |
24 import org.chromium.ui.text.SpanApplier; | 23 import org.chromium.ui.text.SpanApplier; |
25 import org.chromium.ui.text.SpanApplier.SpanInfo; | 24 import org.chromium.ui.text.SpanApplier.SpanInfo; |
26 | 25 |
27 /** | 26 /** |
28 * A dialog for picking available Bluetooth devices. This dialog is shown when a
website requests to | 27 * A dialog for picking available Bluetooth devices. This dialog is shown when a
website requests to |
29 * pair with a certain class of Bluetooth devices (e.g. through a bluetooth.requ
estDevice Javascript | 28 * pair with a certain class of Bluetooth devices (e.g. through a bluetooth.requ
estDevice Javascript |
30 * call). | 29 * call). |
31 */ | 30 */ |
(...skipping 123 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
155 } else { | 154 } else { |
156 checkLocationPermission(); | 155 checkLocationPermission(); |
157 } | 156 } |
158 return; | 157 return; |
159 } | 158 } |
160 } | 159 } |
161 // If the location permission is not present, leave the currently-shown
message in place. | 160 // If the location permission is not present, leave the currently-shown
message in place. |
162 } | 161 } |
163 | 162 |
164 private void checkLocationPermission() { | 163 private void checkLocationPermission() { |
165 if (LocationUtils.getInstance().hasAndroidLocationPermission(mActivity))
{ | 164 if (mWindowAndroid.hasPermission(Manifest.permission.ACCESS_COARSE_LOCAT
ION) |
| 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 Loading... |
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 (!LocationUtils.getInstance().hasAndroidLocationPermission( | 258 if (!windowAndroid.hasPermission(Manifest.permission.ACCESS_COARSE_LOCAT
ION) |
259 windowAndroid.getActivity().get()) | 259 && !windowAndroid.hasPermission(Manifest.permission.ACCESS_FINE_
LOCATION) |
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 Loading... |
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 } |
OLD | NEW |