1 // Copyright 2012 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.
5 #include "chrome/browser/geolocation/geolocation_permission_context_android.h"
7 #include "base/prefs/pref_service.h"
8 #include "chrome/browser/android/google_location_settings_helper.h"
9 #include "chrome/browser/profiles/profile.h"
10 #include "content/public/browser/browser_thread.h"
11 #include "content/public/browser/web_contents.h"
13 GeolocationPermissionContextAndroid::
14 PermissionRequestInfo::PermissionRequestInfo()
15 : id(0, 0, 0, GURL()),
19 GeolocationPermissionContextAndroid::
20 GeolocationPermissionContextAndroid(Profile
* profile
)
21 : GeolocationPermissionContext(profile
),
22 google_location_settings_helper_(
23 GoogleLocationSettingsHelper::Create()),
27 GeolocationPermissionContextAndroid::~GeolocationPermissionContextAndroid() {
30 void GeolocationPermissionContextAndroid::ProceedDecidePermission(
31 content::WebContents
* web_contents
,
32 const PermissionRequestInfo
& info
,
33 base::Callback
<void(bool)> callback
) {
35 // The super class implementation expects everything in UI thread.
36 DCHECK_CURRENTLY_ON(content::BrowserThread::UI
);
37 GeolocationPermissionContext::RequestPermission(
38 web_contents
, info
.id
,
39 info
.requesting_origin
,
46 void GeolocationPermissionContextAndroid::RequestPermission(
47 content::WebContents
* web_contents
,
48 const PermissionRequestID
& id
,
49 const GURL
& requesting_frame_origin
,
51 const BrowserPermissionCallback
& callback
) {
52 PermissionRequestInfo info
;
54 info
.requesting_origin
= requesting_frame_origin
;
55 info
.embedder_origin
= web_contents
->GetLastCommittedURL().GetOrigin();
56 info
.user_gesture
= user_gesture
;
58 // Called on the UI thread. However, do the work on a separate thread
59 // to avoid strict mode violation.
60 DCHECK_CURRENTLY_ON(content::BrowserThread::UI
);
61 content::BrowserThread::PostBlockingPoolTask(FROM_HERE
,
63 &GeolocationPermissionContextAndroid::CheckMasterLocation
,
64 weak_factory_
.GetWeakPtr(), web_contents
, info
, callback
));
67 // Blocking pool thread
68 void GeolocationPermissionContextAndroid::CheckMasterLocation(
69 content::WebContents
* web_contents
,
70 const PermissionRequestInfo
& info
,
71 const BrowserPermissionCallback
& callback
) {
72 // Check to see if the feature in its entirety has been disabled.
73 // This must happen before other services (e.g. tabs, extensions)
74 // get an opportunity to allow the geolocation request.
75 bool enabled
= google_location_settings_helper_
->IsLocationEnabled();
77 base::Closure ui_closure
;
79 ui_closure
= base::Bind(
80 &GeolocationPermissionContextAndroid::ProceedDecidePermission
,
81 base::Unretained(this), web_contents
, info
, callback
);
83 ui_closure
= base::Bind(
84 &GeolocationPermissionContextAndroid::PermissionDecided
,
85 base::Unretained(this), info
.id
, info
.requesting_origin
,
86 info
.embedder_origin
, callback
, false, false);
89 // This method is executed from the BlockingPool, post the result
90 // back to the UI thread.
91 content::BrowserThread::PostTask(
92 content::BrowserThread::UI
, FROM_HERE
, ui_closure
);
96 void GeolocationPermissionContextAndroid::InterceptPermissionCheck(
97 const BrowserPermissionCallback
& callback
, bool granted
) {
98 callback
.Run(granted
);