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: | |
| 19 return PERMISSION_GEOLOCATION; | |
| 20 } | |
| 21 | |
| 22 NOTREACHED(); | |
| 23 return PERMISSION_NUM; | |
| 24 } | |
| 25 | |
| 26 } // anonymous namespace | |
| 27 | |
| 28 PermissionServiceImpl::PendingRequest::PendingRequest(PermissionType permission, | |
| 29 const GURL& origin) | |
| 30 : permission(permission), | |
| 31 origin(origin) { | |
| 32 } | |
| 33 | |
| 34 void PermissionServiceImpl::Create( | |
| 35 scoped_ptr<PermissionServiceContext> context, | |
| 36 mojo::InterfaceRequest<PermissionService> request) { | |
| 37 mojo::BindToRequest(new PermissionServiceImpl(context.Pass()), &request); | |
| 38 } | |
| 39 | |
| 40 PermissionServiceImpl::PermissionServiceImpl( | |
| 41 scoped_ptr<PermissionServiceContext> context) | |
| 42 : context_(context.Pass()) | |
| 43 , weak_factory_(this) { | |
|
nasko
2014/11/14 00:42:50
Another instance of the comma on new line :).
mlamouri (slow - plz ping)
2014/11/14 11:37:11
Damn coding style :)
| |
| 44 context_->set_service(this); | |
| 45 } | |
| 46 | |
| 47 PermissionServiceImpl::~PermissionServiceImpl() { | |
| 48 } | |
| 49 | |
| 50 void PermissionServiceImpl::RequestPermission( | |
| 51 PermissionPtr permission, | |
| 52 const mojo::String& origin, | |
| 53 const mojo::Callback<void(PermissionStatus)>& callback) { | |
| 54 if (!context_->render_frame_host()) { | |
| 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 | |
| 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 (allowed && | |
| 84 pending_requests_.Lookup(request_id)->permission == | |
| 85 PERMISSION_GEOLOCATION) { | |
| 86 GeolocationProviderImpl::GetInstance()->UserDidOptIntoLocationServices(); | |
| 87 } | |
| 88 | |
| 89 pending_requests_.Remove(request_id); | |
| 90 | |
| 91 // TODO(mlamouri): for now, we only get a boolean back, but we would ideally | |
| 92 // need a ContentSetting, see http://crbug.com/432978 | |
| 93 callback.Run(allowed ? PERMISSION_STATUS_GRANTED : PERMISSION_STATUS_ASK); | |
| 94 } | |
| 95 | |
| 96 void PermissionServiceImpl::CancelPendingRequests() { | |
| 97 DCHECK(context_->web_contents()); | |
| 98 | |
| 99 for (RequestsMap::Iterator<PendingRequest> it(&pending_requests_); | |
| 100 !it.IsAtEnd(); it.Advance()) { | |
| 101 GetContentClient()->browser()->CancelPermissionRequest( | |
| 102 it.GetCurrentValue()->permission, | |
| 103 context_->web_contents(), | |
| 104 it.GetCurrentKey(), | |
| 105 it.GetCurrentValue()->origin); | |
| 106 } | |
| 107 | |
| 108 pending_requests_.Clear(); | |
| 109 } | |
| 110 | |
| 111 void PermissionServiceImpl::RevokePermission( | |
|
qsr
2014/11/14 09:20:26
I wouldn't add those methods in the mojom until yo
mlamouri (slow - plz ping)
2014/11/14 11:37:11
Done. Except for HasPermission() because I use tha
qsr
2014/11/14 11:49:27
If you use it, shouldn't you implement it? With th
| |
| 112 PermissionPtr permission, | |
| 113 const mojo::String& origin, | |
| 114 const mojo::Callback<void(PermissionStatus)>& callback) { | |
| 115 NOTIMPLEMENTED(); | |
| 116 } | |
| 117 | |
| 118 void PermissionServiceImpl::HasPermission( | |
| 119 PermissionPtr permission, | |
| 120 const mojo::String& origin, | |
| 121 const mojo::Callback<void(PermissionStatus)>& callback) { | |
| 122 NOTIMPLEMENTED(); | |
| 123 } | |
| 124 | |
| 125 void PermissionServiceImpl::StartObserving( | |
| 126 PermissionPtr permission, | |
| 127 const mojo::String& origin) { | |
| 128 NOTIMPLEMENTED(); | |
| 129 } | |
| 130 | |
| 131 void PermissionServiceImpl::StopObserving( | |
| 132 PermissionPtr permission, | |
| 133 const mojo::String& origin) { | |
| 134 NOTIMPLEMENTED(); | |
| 135 } | |
| 136 | |
| 137 } // namespace content | |
| OLD | NEW |