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.h"
8 #include "chrome/browser/content_settings/tab_specific_content_settings.h"
9 #include "chrome/browser/permissions/permission_request_id.h"
10 #include "chrome/browser/profiles/profile.h"
11 #include "content/public/browser/browser_thread.h"
12 #include "content/public/browser/geolocation_provider.h"
13 #include "content/public/browser/render_frame_host.h"
14 #include "content/public/browser/web_contents.h"
17 GeolocationPermissionContext::GeolocationPermissionContext(
19 : PermissionContextBase(profile
, CONTENT_SETTINGS_TYPE_GEOLOCATION
),
20 extensions_context_(profile
) {
23 GeolocationPermissionContext::~GeolocationPermissionContext() {
26 void GeolocationPermissionContext::RequestPermission(
27 content::WebContents
* web_contents
,
28 const PermissionRequestID
& id
,
29 const GURL
& requesting_frame_origin
,
31 const BrowserPermissionCallback
& callback
) {
32 DCHECK_CURRENTLY_ON(content::BrowserThread::UI
);
36 if (extensions_context_
.RequestPermission(
37 web_contents
, id
, id
.request_id(), requesting_frame_origin
, user_gesture
,
38 callback
, &permission_set
, &new_permission
)) {
40 ContentSetting content_setting
=
41 new_permission
? CONTENT_SETTING_ALLOW
: CONTENT_SETTING_BLOCK
;
42 NotifyPermissionSet(id
,
43 requesting_frame_origin
,
44 web_contents
->GetLastCommittedURL().GetOrigin(),
52 PermissionContextBase::RequestPermission(web_contents
, id
,
53 requesting_frame_origin
,
58 void GeolocationPermissionContext::CancelPermissionRequest(
59 content::WebContents
* web_contents
,
60 const PermissionRequestID
& id
) {
62 if (extensions_context_
.CancelPermissionRequest(
63 web_contents
, id
.request_id()))
65 PermissionContextBase::CancelPermissionRequest(web_contents
, id
);
68 void GeolocationPermissionContext::UpdateTabContext(
69 const PermissionRequestID
& id
,
70 const GURL
& requesting_frame
,
72 TabSpecificContentSettings
* content_settings
=
73 TabSpecificContentSettings::GetForFrame(id
.render_process_id(),
74 id
.render_frame_id());
76 // WebContents might not exist (extensions) or no longer exist. In which case,
77 // TabSpecificContentSettings will be null.
79 content_settings
->OnGeolocationPermissionSet(
80 requesting_frame
.GetOrigin(), allowed
);
83 content::GeolocationProvider::GetInstance()
84 ->UserDidOptIntoLocationServices();
88 bool GeolocationPermissionContext::IsRestrictedToSecureOrigins() const {