Chromium Code Reviews| OLD | NEW |
|---|---|
| (Empty) | |
| 1 // Copyright 2014 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. | |
| 4 | |
| 5 #include "content/browser/permissions/permission_service_impl.h" | |
| 6 | |
| 7 #include "content/browser/geolocation/geolocation_provider_impl.h" | |
| 8 #include "content/public/browser/content_browser_client.h" | |
| 9 #include "content/public/browser/render_frame_host.h" | |
| 10 #include "content/public/browser/render_process_host.h" | |
| 11 | |
| 12 namespace content { | |
| 13 | |
| 14 namespace { | |
| 15 | |
| 16 PermissionType PermissionNameToPermissionType(PermissionName name) { | |
| 17 switch(name) { | |
| 18 case PERMISSION_NAME_GEOLOCATION: | |
|
nasko
2014/11/13 23:57:37
Where is this defined? Is it auto-generated someho
mlamouri (slow - plz ping)
2014/11/14 00:16:33
Auto-generated from the .mojom file.
| |
| 19 return PERMISSION_GEOLOCATION; | |
| 20 } | |
| 21 | |
| 22 NOTREACHED(); | |
| 23 return PERMISSION_NUM; | |
|
Tom Sepez
2014/11/13 22:51:42
nit: name doesn't make sense to me - did you want
mlamouri (slow - plz ping)
2014/11/13 22:58:42
I'm just returning something because I have to - t
nasko
2014/11/13 23:57:38
Why not rename the constant, since the name doesn'
mlamouri (slow - plz ping)
2014/11/14 00:16:33
Sounds reasonable. I think miguelg@ wrote that. I
| |
| 24 } | |
| 25 | |
| 26 } // anonymous namespace | |
| 27 | |
| 28 PermissionServiceImpl::PendingRequest::PendingRequest(PermissionType permission, | |
| 29 const GURL& origin) | |
| 30 : permission(permission) | |
| 31 , origin(origin) { | |
|
nasko
2014/11/13 23:57:37
nit: Chromium style puts commas at the end of the
mlamouri (slow - plz ping)
2014/11/14 00:16:33
Acknowledged.
| |
| 32 } | |
| 33 | |
| 34 void PermissionServiceImpl::Create( | |
| 35 scoped_ptr<PermissionServiceContext> context, | |
| 36 mojo::InterfaceRequest<PermissionService> request) { | |
| 37 BindToRequest(new PermissionServiceImpl(context.Pass()), &request); | |
|
nasko
2014/11/13 23:57:38
nit: prefix with mojo:: to be clear that this isn'
mlamouri (slow - plz ping)
2014/11/14 00:16:33
Done in my local copy. Actually, I wonder if the w
| |
| 38 } | |
| 39 | |
| 40 PermissionServiceImpl::PermissionServiceImpl( | |
| 41 scoped_ptr<PermissionServiceContext> context) | |
| 42 : context_(context.Pass()) | |
| 43 , weak_factory_(this) { | |
| 44 context_->set_service(this); | |
| 45 } | |
| 46 | |
| 47 PermissionServiceImpl::~PermissionServiceImpl() { | |
| 48 } | |
| 49 | |
| 50 void PermissionServiceImpl::RequestPermission( | |
| 51 PermissionPtr permission, | |
|
nasko
2014/11/13 23:57:38
I assume PermissionPtr is a generated pointer type
| |
| 52 const mojo::String& origin, | |
| 53 const mojo::Callback<void(PermissionStatus)>& callback) { | |
| 54 if (!context_->render_frame_host()) { | |
|
nasko
2014/11/13 23:57:37
When is this valid?
mlamouri (slow - plz ping)
2014/11/14 00:16:33
The condition is valid if the call is coming from
nasko
2014/11/14 00:42:50
What you just described to me will fit very well a
| |
| 55 // There is no way to show a UI so the call will simply return the current | |
| 56 // permission. | |
| 57 HasPermission(permission.Clone(), origin, callback); | |
| 58 return; | |
| 59 } | |
| 60 | |
| 61 PermissionType permission_type = | |
| 62 PermissionNameToPermissionType(permission->name); | |
| 63 int request_id = pending_requests_.Add( | |
| 64 new PendingRequest(permission_type, GURL(origin))); | |
| 65 | |
| 66 GetContentClient()->browser()->RequestPermission( | |
| 67 permission_type, | |
| 68 context_->web_contents(), | |
| 69 request_id, | |
| 70 GURL(origin), | |
| 71 true, // TODO(mlamouri): should be removed, see http://crbug.com/423770 | |
|
nasko
2014/11/13 23:57:38
Do we plan to remove user gesture indicator in gen
mlamouri (slow - plz ping)
2014/11/14 00:16:33
Yes, we want to remove it, see the linked bug. The
| |
| 72 base::Bind(&PermissionServiceImpl::OnRequestPermissionResponse, | |
| 73 weak_factory_.GetWeakPtr(), | |
| 74 callback, | |
| 75 request_id)); | |
| 76 } | |
| 77 | |
| 78 void PermissionServiceImpl::OnRequestPermissionResponse( | |
| 79 const mojo::Callback<void(PermissionStatus)>& callback, | |
| 80 int request_id, | |
| 81 bool allowed) { | |
| 82 // TODO(mlamouri): we might want a generic way to handle those things. | |
| 83 if (pending_requests_.Lookup(request_id)->permission == | |
| 84 PERMISSION_GEOLOCATION) { | |
| 85 GeolocationProviderImpl::GetInstance()->UserDidOptIntoLocationServices(); | |
|
nasko
2014/11/13 23:57:37
Why are we calling this without checking the value
mlamouri (slow - plz ping)
2014/11/14 00:16:33
Because I added it at the last minute when I reali
| |
| 86 } | |
| 87 | |
| 88 pending_requests_.Remove(request_id); | |
| 89 | |
| 90 // TODO(mlamouri): for now, we only get a boolean back, but we would ideally | |
| 91 // need a ContentSetting, see http://crbug.com/432978 | |
| 92 callback.Run(allowed ? PERMISSION_STATUS_GRANTED : PERMISSION_STATUS_ASK); | |
| 93 } | |
| 94 | |
| 95 void PermissionServiceImpl::CancelPendingRequests() { | |
| 96 DCHECK(context_->web_contents()); | |
| 97 | |
| 98 for (RequestsMap::Iterator<PendingRequest> it(&pending_requests_); | |
| 99 !it.IsAtEnd(); it.Advance()) { | |
| 100 GetContentClient()->browser()->CancelPermissionRequest( | |
| 101 it.GetCurrentValue()->permission, | |
| 102 context_->web_contents(), | |
| 103 it.GetCurrentKey(), | |
| 104 it.GetCurrentValue()->origin); | |
| 105 } | |
| 106 | |
| 107 pending_requests_.Clear(); | |
| 108 } | |
| 109 | |
| 110 void PermissionServiceImpl::RevokePermission( | |
| 111 PermissionPtr permission, | |
| 112 const mojo::String& origin, | |
| 113 const mojo::Callback<void(PermissionStatus)>& callback) { | |
| 114 NOTIMPLEMENTED(); | |
| 115 } | |
| 116 | |
| 117 void PermissionServiceImpl::HasPermission( | |
| 118 PermissionPtr permission, | |
| 119 const mojo::String& origin, | |
| 120 const mojo::Callback<void(PermissionStatus)>& callback) { | |
| 121 NOTIMPLEMENTED(); | |
| 122 } | |
| 123 | |
| 124 void PermissionServiceImpl::StartObserving( | |
| 125 PermissionPtr permission, | |
| 126 const mojo::String& origin) { | |
| 127 NOTIMPLEMENTED(); | |
| 128 } | |
| 129 | |
| 130 void PermissionServiceImpl::StopObserving( | |
| 131 PermissionPtr permission, | |
| 132 const mojo::String& origin) { | |
| 133 NOTIMPLEMENTED(); | |
| 134 } | |
| 135 | |
| 136 } // namespace content | |
| OLD | NEW |