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"
10 #include "chrome/browser/android/location_settings.h"
11 #include "chrome/browser/android/location_settings_impl.h"
12 #include "chrome/browser/permissions/permission_request_id.h"
13 #include "chrome/browser/permissions/permission_update_infobar_delegate_android.h"
14 #include "content/public/browser/browser_thread.h"
15 #include "content/public/browser/web_contents.h"
18 GeolocationPermissionContextAndroid::
19 GeolocationPermissionContextAndroid(Profile
* profile
)
20 : GeolocationPermissionContext(profile
),
21 location_settings_(new LocationSettingsImpl()),
25 GeolocationPermissionContextAndroid::~GeolocationPermissionContextAndroid() {
28 void GeolocationPermissionContextAndroid::RequestPermission(
29 content::WebContents
* web_contents
,
30 const PermissionRequestID
& id
,
31 const GURL
& requesting_frame_origin
,
33 const BrowserPermissionCallback
& callback
) {
34 if (!location_settings_
->CanSitesRequestLocationPermission(web_contents
)) {
35 PermissionDecided(id
, requesting_frame_origin
,
36 web_contents
->GetLastCommittedURL().GetOrigin(),
37 callback
, false /* persist */, CONTENT_SETTING_BLOCK
);
41 GURL embedding_origin
= web_contents
->GetLastCommittedURL().GetOrigin();
42 ContentSetting content_setting
=
43 GeolocationPermissionContext::GetPermissionStatus(requesting_frame_origin
,
45 std::vector
<ContentSettingsType
> content_settings_types
;
46 content_settings_types
.push_back(CONTENT_SETTINGS_TYPE_GEOLOCATION
);
47 if (content_setting
== CONTENT_SETTING_ALLOW
&&
48 PermissionUpdateInfoBarDelegate::ShouldShowPermissionInfobar(
49 web_contents
, content_settings_types
)) {
50 PermissionUpdateInfoBarDelegate::Create(
51 web_contents
, content_settings_types
,
53 &GeolocationPermissionContextAndroid
54 ::HandleUpdateAndroidPermissions
,
55 weak_factory_
.GetWeakPtr(), id
, requesting_frame_origin
,
56 embedding_origin
, callback
));
60 GeolocationPermissionContext::RequestPermission(
61 web_contents
, id
, requesting_frame_origin
, user_gesture
, callback
);
64 void GeolocationPermissionContextAndroid::HandleUpdateAndroidPermissions(
65 const PermissionRequestID
& id
,
66 const GURL
& requesting_frame_origin
,
67 const GURL
& embedding_origin
,
68 const BrowserPermissionCallback
& callback
,
69 bool permissions_updated
) {
70 DCHECK_CURRENTLY_ON(content::BrowserThread::UI
);
71 ContentSetting new_setting
= permissions_updated
72 ? CONTENT_SETTING_ALLOW
: CONTENT_SETTING_BLOCK
;
74 NotifyPermissionSet(id
, requesting_frame_origin
, embedding_origin
, callback
,
75 false /* persist */, new_setting
);
78 void GeolocationPermissionContextAndroid::SetLocationSettingsForTesting(
79 scoped_ptr
<LocationSettings
> settings
) {
80 location_settings_
= settings
.Pass();