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/profiles/profile.h"
10 #include "components/content_settings/core/common/permission_request_id.h"
11 #include "content/public/browser/browser_thread.h"
12 #include "content/public/browser/geolocation_provider.h"
13 #include "content/public/browser/web_contents.h"
16 GeolocationPermissionContext::GeolocationPermissionContext(
18 : PermissionContextBase(profile
, CONTENT_SETTINGS_TYPE_GEOLOCATION
),
19 extensions_context_(profile
) {
22 GeolocationPermissionContext::~GeolocationPermissionContext() {
25 void GeolocationPermissionContext::RequestPermission(
26 content::WebContents
* web_contents
,
27 const PermissionRequestID
& id
,
28 const GURL
& requesting_frame_origin
,
30 const BrowserPermissionCallback
& callback
) {
31 DCHECK_CURRENTLY_ON(content::BrowserThread::UI
);
35 if (extensions_context_
.RequestPermission(
36 web_contents
, id
, id
.bridge_id(), requesting_frame_origin
, user_gesture
,
37 callback
, &permission_set
, &new_permission
)) {
39 ContentSetting content_setting
=
40 new_permission
? CONTENT_SETTING_ALLOW
: CONTENT_SETTING_BLOCK
;
41 NotifyPermissionSet(id
,
42 requesting_frame_origin
,
43 web_contents
->GetLastCommittedURL().GetOrigin(),
51 PermissionContextBase::RequestPermission(web_contents
, id
,
52 requesting_frame_origin
,
57 void GeolocationPermissionContext::CancelPermissionRequest(
58 content::WebContents
* web_contents
,
59 const PermissionRequestID
& id
) {
61 if (extensions_context_
.CancelPermissionRequest(
62 web_contents
, id
.bridge_id()))
64 PermissionContextBase::CancelPermissionRequest(web_contents
, id
);
67 void GeolocationPermissionContext::UpdateTabContext(
68 const PermissionRequestID
& id
,
69 const GURL
& requesting_frame
,
71 // WebContents may have gone away (or not exists for extension).
72 TabSpecificContentSettings
* content_settings
=
73 TabSpecificContentSettings::Get(id
.render_process_id(),
76 content_settings
->OnGeolocationPermissionSet(
77 requesting_frame
.GetOrigin(), allowed
);
80 content::GeolocationProvider::GetInstance()
81 ->UserDidOptIntoLocationServices();