OLD | NEW |
---|---|
1 // Copyright 2014 The Chromium Authors. All rights reserved. | 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 | 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 "content/browser/permissions/permission_service_impl.h" | 5 #include "content/browser/permissions/permission_service_impl.h" |
6 | 6 |
7 #include "content/browser/geolocation/geolocation_provider_impl.h" | 7 #include "content/browser/geolocation/geolocation_provider_impl.h" |
8 #include "content/public/browser/content_browser_client.h" | 8 #include "content/public/browser/content_browser_client.h" |
9 #include "content/public/browser/render_process_host.h" | 9 #include "content/public/browser/render_process_host.h" |
10 | 10 |
(...skipping 39 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
50 // This condition is valid if the call is coming from a ChildThread instead of | 50 // This condition is valid if the call is coming from a ChildThread instead of |
51 // a RenderFrame. Some consumers of the service run in Workers and some in | 51 // a RenderFrame. Some consumers of the service run in Workers and some in |
52 // Frames. In the context of a Worker, it is not possible to show a | 52 // Frames. In the context of a Worker, it is not possible to show a |
53 // permission prompt because there is no tab. In the context of a Frame, we | 53 // permission prompt because there is no tab. In the context of a Frame, we |
54 // can. Even if the call comes from a context where it is not possible to show | 54 // can. Even if the call comes from a context where it is not possible to show |
55 // any UI, we want to still return something relevant so the current | 55 // any UI, we want to still return something relevant so the current |
56 // permission status is returned. | 56 // permission status is returned. |
57 if (!context_->web_contents()) { | 57 if (!context_->web_contents()) { |
58 // There is no way to show a UI so the call will simply return the current | 58 // There is no way to show a UI so the call will simply return the current |
59 // permission. | 59 // permission. |
60 HasPermission(permission, origin, callback); | 60 // Cannot use HasPermission() because it also needs context_->web_contents() |
61 // to obtain the profile. | |
qsr
2014/11/24 11:51:11
The previous comment is wrong. Could you remove it
mlamouri (slow - plz ping)
2014/11/24 16:01:19
We must implement HasPermission() to work in a non
timvolodine
2014/11/24 18:54:22
Done.
timvolodine
2014/11/24 18:54:22
Done.
permission_context has an additional constru
| |
62 callback.Run(PERMISSION_STATUS_ASK); | |
61 return; | 63 return; |
62 } | 64 } |
63 | 65 |
64 PermissionType permission_type = PermissionNameToPermissionType(permission); | 66 PermissionType permission_type = PermissionNameToPermissionType(permission); |
65 int request_id = pending_requests_.Add( | 67 int request_id = pending_requests_.Add( |
66 new PendingRequest(permission_type, GURL(origin))); | 68 new PendingRequest(permission_type, GURL(origin))); |
67 | 69 |
68 GetContentClient()->browser()->RequestPermission( | 70 GetContentClient()->browser()->RequestPermission( |
69 permission_type, | 71 permission_type, |
70 context_->web_contents(), | 72 context_->web_contents(), |
(...skipping 36 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
107 it.GetCurrentValue()->origin); | 109 it.GetCurrentValue()->origin); |
108 } | 110 } |
109 | 111 |
110 pending_requests_.Clear(); | 112 pending_requests_.Clear(); |
111 } | 113 } |
112 | 114 |
113 void PermissionServiceImpl::HasPermission( | 115 void PermissionServiceImpl::HasPermission( |
114 PermissionName permission, | 116 PermissionName permission, |
115 const mojo::String& origin, | 117 const mojo::String& origin, |
116 const mojo::Callback<void(PermissionStatus)>& callback) { | 118 const mojo::Callback<void(PermissionStatus)>& callback) { |
117 NOTIMPLEMENTED(); | 119 DCHECK(context_->web_contents()); |
120 | |
121 GetContentClient()->browser()->HasPermission( | |
122 PermissionNameToPermissionType(permission), | |
123 context_->web_contents(), | |
124 GURL(origin), | |
125 base::Bind(&PermissionServiceImpl::OnHasPermissionResponse, | |
126 weak_factory_.GetWeakPtr(), | |
127 callback)); | |
128 } | |
129 | |
130 void PermissionServiceImpl::OnHasPermissionResponse( | |
131 const mojo::Callback<void(PermissionStatus)>& callback, | |
132 bool allowed) { | |
133 callback.Run(allowed ? PERMISSION_STATUS_GRANTED : PERMISSION_STATUS_ASK); | |
118 } | 134 } |
119 | 135 |
120 } // namespace content | 136 } // namespace content |
OLD | NEW |