Pin Chrome's shortcut to the Win10 Start menu on install and OS upgrade.
[chromium-blink-merge.git] / chrome / browser / geolocation / geolocation_permission_context.cc
blobdf90856286a8020f0e7e1faf670f7f871cea882c
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"
7 #include "base/bind.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(
18 Profile* profile)
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,
30 bool user_gesture,
31 const BrowserPermissionCallback& callback) {
32 DCHECK_CURRENTLY_ON(content::BrowserThread::UI);
34 bool permission_set;
35 bool new_permission;
36 if (extensions_context_.RequestPermission(
37 web_contents, id, id.request_id(), requesting_frame_origin, user_gesture,
38 callback, &permission_set, &new_permission)) {
39 if (permission_set) {
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(),
45 callback,
46 false /* persist */,
47 content_setting);
49 return;
52 PermissionContextBase::RequestPermission(web_contents, id,
53 requesting_frame_origin,
54 user_gesture,
55 callback);
58 void GeolocationPermissionContext::CancelPermissionRequest(
59 content::WebContents* web_contents,
60 const PermissionRequestID& id) {
62 if (extensions_context_.CancelPermissionRequest(
63 web_contents, id.request_id()))
64 return;
65 PermissionContextBase::CancelPermissionRequest(web_contents, id);
68 void GeolocationPermissionContext::UpdateTabContext(
69 const PermissionRequestID& id,
70 const GURL& requesting_frame,
71 bool allowed) {
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.
78 if (content_settings)
79 content_settings->OnGeolocationPermissionSet(
80 requesting_frame.GetOrigin(), allowed);
82 if (allowed) {
83 content::GeolocationProvider::GetInstance()
84 ->UserDidOptIntoLocationServices();
88 bool GeolocationPermissionContext::IsRestrictedToSecureOrigins() const {
89 return false;