Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(98)

Side by Side Diff: chrome/browser/geolocation/geolocation_permission_context.cc

Issue 1726323002: Have Permission{Manager,Service} use Origin. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Rebase. Created 4 years, 8 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
1 // Copyright 2012 The Chromium Authors. All rights reserved. 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 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 #include "chrome/browser/geolocation/geolocation_permission_context.h" 5 #include "chrome/browser/geolocation/geolocation_permission_context.h"
6 6
7 #include "base/bind.h" 7 #include "base/bind.h"
8 #include "chrome/browser/content_settings/tab_specific_content_settings.h" 8 #include "chrome/browser/content_settings/tab_specific_content_settings.h"
9 #include "chrome/browser/permissions/permission_request_id.h" 9 #include "chrome/browser/permissions/permission_request_id.h"
10 #include "chrome/browser/profiles/profile.h" 10 #include "chrome/browser/profiles/profile.h"
11 #include "content/public/browser/browser_thread.h" 11 #include "content/public/browser/browser_thread.h"
12 #include "content/public/browser/geolocation_provider.h" 12 #include "content/public/browser/geolocation_provider.h"
13 #include "content/public/browser/permission_type.h" 13 #include "content/public/browser/permission_type.h"
14 #include "content/public/browser/render_frame_host.h" 14 #include "content/public/browser/render_frame_host.h"
15 #include "content/public/browser/web_contents.h" 15 #include "content/public/browser/web_contents.h"
16 16
17 GeolocationPermissionContext::GeolocationPermissionContext(Profile* profile) 17 GeolocationPermissionContext::GeolocationPermissionContext(Profile* profile)
18 : PermissionContextBase(profile, 18 : PermissionContextBase(profile,
19 content::PermissionType::GEOLOCATION, 19 content::PermissionType::GEOLOCATION,
20 CONTENT_SETTINGS_TYPE_GEOLOCATION), 20 CONTENT_SETTINGS_TYPE_GEOLOCATION),
21 extensions_context_(profile) {} 21 extensions_context_(profile) {}
22 22
23 GeolocationPermissionContext::~GeolocationPermissionContext() { 23 GeolocationPermissionContext::~GeolocationPermissionContext() {
24 } 24 }
25 25
26 void GeolocationPermissionContext::DecidePermission( 26 void GeolocationPermissionContext::DecidePermission(
27 content::WebContents* web_contents, 27 content::WebContents* web_contents,
28 const PermissionRequestID& id, 28 const PermissionRequestID& id,
29 const GURL& requesting_origin, 29 const url::Origin& requesting_origin,
30 const GURL& embedding_origin, 30 const url::Origin& embedding_origin,
31 const BrowserPermissionCallback& callback) { 31 const BrowserPermissionCallback& callback) {
32 DCHECK_CURRENTLY_ON(content::BrowserThread::UI); 32 DCHECK_CURRENTLY_ON(content::BrowserThread::UI);
33 33
34 bool permission_set; 34 bool permission_set;
35 bool new_permission; 35 bool new_permission;
36 if (extensions_context_.DecidePermission( 36 if (extensions_context_.DecidePermission(
37 web_contents, id, id.request_id(), requesting_origin, callback, 37 web_contents, id, id.request_id(), requesting_origin, callback,
38 &permission_set, &new_permission)) { 38 &permission_set, &new_permission)) {
39 if (permission_set) { 39 if (permission_set) {
40 ContentSetting content_setting = 40 ContentSetting content_setting =
41 new_permission ? CONTENT_SETTING_ALLOW : CONTENT_SETTING_BLOCK; 41 new_permission ? CONTENT_SETTING_ALLOW : CONTENT_SETTING_BLOCK;
42 NotifyPermissionSet(id, 42 NotifyPermissionSet(id, requesting_origin,
43 requesting_origin, 43 url::Origin(web_contents->GetLastCommittedURL()),
44 web_contents->GetLastCommittedURL().GetOrigin(), 44 callback, false /* persist */, content_setting);
45 callback,
46 false /* persist */,
47 content_setting);
48 } 45 }
49 return; 46 return;
50 } 47 }
51 48
52 PermissionContextBase::DecidePermission(web_contents, 49 PermissionContextBase::DecidePermission(web_contents,
53 id, 50 id,
54 requesting_origin, 51 requesting_origin,
55 embedding_origin, 52 embedding_origin,
56 callback); 53 callback);
57 } 54 }
58 55
59 void GeolocationPermissionContext::CancelPermissionRequest( 56 void GeolocationPermissionContext::CancelPermissionRequest(
60 content::WebContents* web_contents, 57 content::WebContents* web_contents,
61 const PermissionRequestID& id) { 58 const PermissionRequestID& id) {
62 59
63 if (extensions_context_.CancelPermissionRequest( 60 if (extensions_context_.CancelPermissionRequest(
64 web_contents, id.request_id())) 61 web_contents, id.request_id()))
65 return; 62 return;
66 PermissionContextBase::CancelPermissionRequest(web_contents, id); 63 PermissionContextBase::CancelPermissionRequest(web_contents, id);
67 } 64 }
68 65
69 void GeolocationPermissionContext::UpdateTabContext( 66 void GeolocationPermissionContext::UpdateTabContext(
70 const PermissionRequestID& id, 67 const PermissionRequestID& id,
71 const GURL& requesting_frame, 68 const url::Origin& requesting_frame,
72 bool allowed) { 69 bool allowed) {
73 TabSpecificContentSettings* content_settings = 70 TabSpecificContentSettings* content_settings =
74 TabSpecificContentSettings::GetForFrame(id.render_process_id(), 71 TabSpecificContentSettings::GetForFrame(id.render_process_id(),
75 id.render_frame_id()); 72 id.render_frame_id());
76 73
77 // WebContents might not exist (extensions) or no longer exist. In which case, 74 // WebContents might not exist (extensions) or no longer exist. In which case,
78 // TabSpecificContentSettings will be null. 75 // TabSpecificContentSettings will be null.
76 //
77 // TODO(mkwst): Update TabSpecificContentSettings::OnGeolocationPermissionSet
78 // to use url::Origin. crbug.com/591799
79 if (content_settings) 79 if (content_settings)
80 content_settings->OnGeolocationPermissionSet( 80 content_settings->OnGeolocationPermissionSet(
81 requesting_frame.GetOrigin(), allowed); 81 GURL(requesting_frame.Serialize()), allowed);
82 82
83 if (allowed) { 83 if (allowed) {
84 content::GeolocationProvider::GetInstance() 84 content::GeolocationProvider::GetInstance()
85 ->UserDidOptIntoLocationServices(); 85 ->UserDidOptIntoLocationServices();
86 } 86 }
87 } 87 }
88 88
89 bool GeolocationPermissionContext::IsRestrictedToSecureOrigins() const { 89 bool GeolocationPermissionContext::IsRestrictedToSecureOrigins() const {
90 return true; 90 return true;
91 } 91 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698