Revert of Add button to add new FSP services to Files app. (patchset #8 id:140001...
[chromium-blink-merge.git] / chrome / browser / geolocation / geolocation_permission_context.cc
blob7110b4fdbfea8829568a0c5db7e0787421c463f3
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/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(
17 Profile* profile)
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,
29 bool user_gesture,
30 const BrowserPermissionCallback& callback) {
31 DCHECK_CURRENTLY_ON(content::BrowserThread::UI);
33 bool permission_set;
34 bool new_permission;
35 if (extensions_context_.RequestPermission(
36 web_contents, id, id.bridge_id(), requesting_frame_origin, user_gesture,
37 callback, &permission_set, &new_permission)) {
38 if (permission_set) {
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(),
44 callback,
45 true,
46 content_setting);
48 return;
51 PermissionContextBase::RequestPermission(web_contents, id,
52 requesting_frame_origin,
53 user_gesture,
54 callback);
57 void GeolocationPermissionContext::CancelPermissionRequest(
58 content::WebContents* web_contents,
59 const PermissionRequestID& id) {
61 if (extensions_context_.CancelPermissionRequest(
62 web_contents, id.bridge_id()))
63 return;
64 PermissionContextBase::CancelPermissionRequest(web_contents, id);
67 void GeolocationPermissionContext::UpdateTabContext(
68 const PermissionRequestID& id,
69 const GURL& requesting_frame,
70 bool allowed) {
71 // WebContents may have gone away (or not exists for extension).
72 TabSpecificContentSettings* content_settings =
73 TabSpecificContentSettings::Get(id.render_process_id(),
74 id.render_view_id());
75 if (content_settings)
76 content_settings->OnGeolocationPermissionSet(
77 requesting_frame.GetOrigin(), allowed);
79 if (allowed) {
80 content::GeolocationProvider::GetInstance()
81 ->UserDidOptIntoLocationServices();