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 "chrome/common/pref_names.h"
11 #include "content/public/browser/browser_thread.h"
12 #include "content/public/browser/web_contents.h"
14 GeolocationPermissionContextAndroid::
15 PermissionRequestInfo::PermissionRequestInfo()
16 : id(0, 0, 0, GURL()),
20 GeolocationPermissionContextAndroid::
21 GeolocationPermissionContextAndroid(Profile
* profile
)
22 : GeolocationPermissionContext(profile
),
23 google_location_settings_helper_(
24 GoogleLocationSettingsHelper::Create()),
28 GeolocationPermissionContextAndroid::~GeolocationPermissionContextAndroid() {
31 void GeolocationPermissionContextAndroid::ProceedDecidePermission(
32 content::WebContents
* web_contents
,
33 const PermissionRequestInfo
& info
,
34 base::Callback
<void(bool)> callback
) {
36 // The super class implementation expects everything in UI thread.
37 DCHECK_CURRENTLY_ON(content::BrowserThread::UI
);
38 GeolocationPermissionContext::RequestPermission(
39 web_contents
, info
.id
,
40 info
.requesting_origin
,
47 void GeolocationPermissionContextAndroid::RequestPermission(
48 content::WebContents
* web_contents
,
49 const PermissionRequestID
& id
,
50 const GURL
& requesting_frame_origin
,
52 const BrowserPermissionCallback
& callback
) {
53 PermissionRequestInfo info
;
55 info
.requesting_origin
= requesting_frame_origin
;
56 info
.embedder_origin
= web_contents
->GetLastCommittedURL().GetOrigin();
57 info
.user_gesture
= user_gesture
;
59 // Called on the UI thread. However, do the work on a separate thread
60 // to avoid strict mode violation.
61 DCHECK_CURRENTLY_ON(content::BrowserThread::UI
);
62 content::BrowserThread::PostBlockingPoolTask(FROM_HERE
,
64 &GeolocationPermissionContextAndroid::CheckMasterLocation
,
65 weak_factory_
.GetWeakPtr(), web_contents
, info
, callback
));
68 // Blocking pool thread
69 void GeolocationPermissionContextAndroid::CheckMasterLocation(
70 content::WebContents
* web_contents
,
71 const PermissionRequestInfo
& info
,
72 const BrowserPermissionCallback
& callback
) {
73 // Check to see if the feature in its entirety has been disabled.
74 // This must happen before other services (e.g. tabs, extensions)
75 // get an opportunity to allow the geolocation request.
77 google_location_settings_helper_
->IsSystemLocationEnabled();
79 base::Closure ui_closure
;
81 ui_closure
= base::Bind(
82 &GeolocationPermissionContextAndroid::ProceedDecidePermission
,
83 base::Unretained(this), web_contents
, info
, callback
);
85 ui_closure
= base::Bind(
86 &GeolocationPermissionContextAndroid::PermissionDecided
,
87 base::Unretained(this), info
.id
, info
.requesting_origin
,
88 info
.embedder_origin
, callback
, false, false);
91 // This method is executed from the BlockingPool, post the result
92 // back to the UI thread.
93 content::BrowserThread::PostTask(
94 content::BrowserThread::UI
, FROM_HERE
, ui_closure
);
98 void GeolocationPermissionContextAndroid::InterceptPermissionCheck(
99 const BrowserPermissionCallback
& callback
, bool granted
) {
100 callback
.Run(granted
);