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
);
32 GURL embedder_origin
= web_contents
->GetLastCommittedURL().GetOrigin();
36 if (extensions_context_
.RequestPermission(
37 web_contents
, id
, id
.bridge_id(), requesting_frame_origin
, user_gesture
,
38 callback
, &permission_set
, &new_permission
)) {
40 NotifyPermissionSet(id
, requesting_frame_origin
, embedder_origin
,
41 callback
, true, new_permission
);
46 if (!requesting_frame_origin
.is_valid() || !embedder_origin
.is_valid()) {
47 LOG(WARNING
) << "Attempt to use geolocation from an invalid URL: "
48 << requesting_frame_origin
<< "," << embedder_origin
49 << " (geolocation is not supported in popups)";
50 NotifyPermissionSet(id
, requesting_frame_origin
, embedder_origin
,
51 callback
, false /* persist */, false /* allowed */);
55 PermissionContextBase::RequestPermission(web_contents
, id
,
56 requesting_frame_origin
,
61 void GeolocationPermissionContext::CancelPermissionRequest(
62 content::WebContents
* web_contents
,
63 const PermissionRequestID
& id
) {
65 if (extensions_context_
.CancelPermissionRequest(
66 web_contents
, id
.bridge_id()))
68 PermissionContextBase::CancelPermissionRequest(web_contents
, id
);
71 void GeolocationPermissionContext::UpdateTabContext(
72 const PermissionRequestID
& id
,
73 const GURL
& requesting_frame
,
75 // WebContents may have gone away (or not exists for extension).
76 TabSpecificContentSettings
* content_settings
=
77 TabSpecificContentSettings::Get(id
.render_process_id(),
80 content_settings
->OnGeolocationPermissionSet(
81 requesting_frame
.GetOrigin(), allowed
);
84 content::GeolocationProvider::GetInstance()
85 ->UserDidOptIntoLocationServices();