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/web_contents.h"
15 GeolocationPermissionContext::GeolocationPermissionContext(
17 : PermissionContextBase(profile
, CONTENT_SETTINGS_TYPE_GEOLOCATION
),
18 extensions_context_(profile
) {
21 GeolocationPermissionContext::~GeolocationPermissionContext() {
24 void GeolocationPermissionContext::RequestPermission(
25 content::WebContents
* web_contents
,
26 const PermissionRequestID
& id
,
27 const GURL
& requesting_frame_origin
,
29 const BrowserPermissionCallback
& callback
) {
30 DCHECK_CURRENTLY_ON(content::BrowserThread::UI
);
31 GURL embedder_origin
= web_contents
->GetLastCommittedURL().GetOrigin();
35 if (extensions_context_
.RequestPermission(
36 web_contents
, id
, id
.bridge_id(), requesting_frame_origin
, user_gesture
,
37 callback
, &permission_set
, &new_permission
)) {
39 NotifyPermissionSet(id
, requesting_frame_origin
, embedder_origin
,
40 callback
, true, new_permission
);
45 if (!requesting_frame_origin
.is_valid() || !embedder_origin
.is_valid()) {
46 LOG(WARNING
) << "Attempt to use geolocation from an invalid URL: "
47 << requesting_frame_origin
<< "," << embedder_origin
48 << " (geolocation is not supported in popups)";
49 NotifyPermissionSet(id
, requesting_frame_origin
, embedder_origin
,
50 callback
, false /* persist */, false /* allowed */);
54 PermissionContextBase::RequestPermission(web_contents
, id
,
55 requesting_frame_origin
,
60 void GeolocationPermissionContext::CancelPermissionRequest(
61 content::WebContents
* web_contents
,
62 const PermissionRequestID
& id
) {
64 if (extensions_context_
.CancelPermissionRequest(
65 web_contents
, id
.bridge_id()))
67 PermissionContextBase::CancelPermissionRequest(web_contents
, id
);
70 void GeolocationPermissionContext::UpdateTabContext(
71 const PermissionRequestID
& id
,
72 const GURL
& requesting_frame
,
74 // WebContents may have gone away (or not exists for extension).
75 TabSpecificContentSettings
* content_settings
=
76 TabSpecificContentSettings::Get(id
.render_process_id(),
79 content_settings
->OnGeolocationPermissionSet(
80 requesting_frame
.GetOrigin(), allowed
);