Chromium Code Reviews| 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 #include "chrome/browser/android/location_settings_impl.h" | 5 #include "chrome/browser/android/location_settings_impl.h" |
| 6 | 6 |
| 7 #include "base/android/jni_android.h" | 7 #include "base/android/jni_android.h" |
| 8 #include "content/public/browser/web_contents.h" | 8 #include "content/public/browser/web_contents.h" |
| 9 #include "jni/LocationSettings_jni.h" | 9 #include "jni/LocationSettings_jni.h" |
| 10 | 10 |
| 11 using base::android::AttachCurrentThread; | 11 using base::android::AttachCurrentThread; |
| 12 | 12 |
| 13 using LocationSettingsDialogOutcome = | |
| 14 LocationSettings::LocationSettingsDialogOutcome; | |
| 15 using LocationSettingsDialogOutcomeCallback = | |
| 16 LocationSettings::LocationSettingsDialogOutcomeCallback; | |
| 17 | |
| 13 LocationSettingsImpl::LocationSettingsImpl() {} | 18 LocationSettingsImpl::LocationSettingsImpl() {} |
| 14 | 19 |
| 15 LocationSettingsImpl::~LocationSettingsImpl() {} | 20 LocationSettingsImpl::~LocationSettingsImpl() {} |
| 16 | 21 |
| 17 bool LocationSettingsImpl::CanSitesRequestLocationPermission( | 22 bool LocationSettingsImpl::CanSitesRequestLocationPermission( |
| 18 content::WebContents* web_contents) { | 23 content::WebContents* web_contents) { |
| 19 JNIEnv* env = AttachCurrentThread(); | 24 JNIEnv* env = AttachCurrentThread(); |
| 20 return Java_LocationSettings_canSitesRequestLocationPermission( | 25 return Java_LocationSettings_canSitesRequestLocationPermission( |
| 21 env, web_contents->GetJavaWebContents()); | 26 env, web_contents->GetJavaWebContents()); |
| 22 } | 27 } |
| 28 | |
| 29 bool LocationSettingsImpl::CanPromptToEnableSystemLocationSetting() { | |
| 30 JNIEnv* env = AttachCurrentThread(); | |
| 31 return Java_LocationSettings_canPromptToEnableSystemLocationSetting(env); | |
| 32 } | |
| 33 | |
| 34 void LocationSettingsImpl::PromptToEnableSystemLocationSetting( | |
| 35 const LocationSettingsDialogContext prompt_context, | |
| 36 content::WebContents* web_contents, | |
| 37 LocationSettingsDialogOutcomeCallback callback) { | |
| 38 JNIEnv* env = AttachCurrentThread(); | |
| 39 auto* callback_ptr = new LocationSettingsDialogOutcomeCallback( | |
|
Ted C
2017/03/02 00:21:56
maybe a comment around ownership and that Outcome
qfiard
2017/03/02 13:28:13
Done.
| |
| 40 std::move(callback)); | |
| 41 Java_LocationSettings_promptToEnableSystemLocationSetting( | |
| 42 env, prompt_context, web_contents->GetJavaWebContents(), | |
| 43 reinterpret_cast<jlong>(callback_ptr)); | |
| 44 } | |
| 45 | |
| 46 static void OnLocationSettingsDialogOutcome( | |
| 47 JNIEnv* env, | |
| 48 const base::android::JavaParamRef<jclass>& jcaller, | |
| 49 jlong callback_ptr, | |
| 50 int result) { | |
| 51 auto* callback = | |
| 52 reinterpret_cast<LocationSettingsDialogOutcomeCallback*>( | |
| 53 callback_ptr); | |
| 54 std::move(*callback).Run(static_cast<LocationSettingsDialogOutcome>( | |
| 55 result)); | |
| 56 delete callback; | |
| 57 } | |
| 58 | |
| 59 bool LocationSettingsImpl::Register(JNIEnv* env) { | |
| 60 return RegisterNativesImpl(env); | |
| 61 } | |
| OLD | NEW |