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 "base/bind.h" | 7 #include "base/bind.h" |
8 #include "content/public/browser/browser_context.h" | 8 #include "content/public/browser/browser_context.h" |
9 #include "content/public/browser/permission_manager.h" | 9 #include "content/public/browser/permission_manager.h" |
10 #include "content/public/browser/permission_type.h" | 10 #include "content/public/browser/permission_type.h" |
(...skipping 99 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
110 } | 110 } |
111 | 111 |
112 BrowserContext* browser_context = context_->GetBrowserContext(); | 112 BrowserContext* browser_context = context_->GetBrowserContext(); |
113 DCHECK(browser_context); | 113 DCHECK(browser_context); |
114 if (!browser_context->GetPermissionManager()) { | 114 if (!browser_context->GetPermissionManager()) { |
115 callback.Run(content::PERMISSION_STATUS_DENIED); | 115 callback.Run(content::PERMISSION_STATUS_DENIED); |
116 return; | 116 return; |
117 } | 117 } |
118 | 118 |
119 PermissionType permission_type = PermissionNameToPermissionType(permission); | 119 PermissionType permission_type = PermissionNameToPermissionType(permission); |
120 int request_id = pending_requests_.Add( | 120 int request_id = pending_requests_.Add( |
mlamouri (slow - plz ping)
2015/09/16 14:42:56
nit: rename to pending_request_id
Lalit Maganti
2015/09/16 16:41:10
Done.
| |
121 new PendingRequest(permission_type, GURL(origin), callback)); | 121 new PendingRequest(permission_type, GURL(origin), callback)); |
122 | 122 int manager_id = browser_context->GetPermissionManager()->RequestPermission( |
mlamouri (slow - plz ping)
2015/09/16 14:42:57
nit: keep that line
Lalit Maganti
2015/09/16 16:41:10
Done.
|
mlamouri (slow - plz ping)
2015/09/16 14:42:56
s/manager_id/id/
Lalit Maganti
2015/09/16 16:41:10
Done.
|
123 browser_context->GetPermissionManager()->RequestPermission( | |
124 permission_type, | 123 permission_type, |
125 context_->render_frame_host(), | 124 context_->render_frame_host(), |
126 request_id, | |
127 GURL(origin), | 125 GURL(origin), |
128 user_gesture, // TODO(mlamouri): should be removed (crbug.com/423770) | 126 user_gesture, // TODO(mlamouri): should be removed (crbug.com/423770) |
129 base::Bind(&PermissionServiceImpl::OnRequestPermissionResponse, | 127 base::Bind(&PermissionServiceImpl::OnRequestPermissionResponse, |
130 weak_factory_.GetWeakPtr(), | 128 weak_factory_.GetWeakPtr(), |
131 request_id)); | 129 request_id)); |
130 | |
131 // Check if the request still exists. It may have been removed by the | |
132 // the response callback. | |
133 PendingRequest* pending_request = pending_requests_.Lookup(request_id); | |
mlamouri (slow - plz ping)
2015/09/16 14:42:57
This is a bit unfortunate. Though, unless we call
Lalit Maganti
2015/09/16 16:41:10
Agreed.
| |
134 if (!pending_request) | |
135 return; | |
136 pending_request->manager_id = manager_id; | |
mlamouri (slow - plz ping)
2015/09/16 14:42:56
pending_request->id = id;
Lalit Maganti
2015/09/16 16:41:10
Done.
| |
132 } | 137 } |
133 | 138 |
134 void PermissionServiceImpl::RequestPermissions( | 139 void PermissionServiceImpl::RequestPermissions( |
135 mojo::Array<PermissionName> permissions, | 140 mojo::Array<PermissionName> permissions, |
136 const mojo::String& origin, | 141 const mojo::String& origin, |
137 bool user_gesture, | 142 bool user_gesture, |
138 const PermissionsStatusCallback& callback) { | 143 const PermissionsStatusCallback& callback) { |
139 NOTIMPLEMENTED(); | 144 NOTIMPLEMENTED(); |
140 | 145 |
141 // TODO(lalitm,mlamouri): this is returning the current permission statuses | 146 // TODO(lalitm,mlamouri): this is returning the current permission statuses |
142 // in order for the call to successfully return. It will be changed later. | 147 // in order for the call to successfully return. It will be changed later. |
143 // See https://crbug.com/516626 | 148 // See https://crbug.com/516626 |
144 mojo::Array<PermissionStatus> result(permissions.size()); | 149 mojo::Array<PermissionStatus> result(permissions.size()); |
145 for (size_t i = 0; i < permissions.size(); ++i) | 150 for (size_t i = 0; i < permissions.size(); ++i) |
146 result[i] = GetPermissionStatusFromName(permissions[i], GURL(origin)); | 151 result[i] = GetPermissionStatusFromName(permissions[i], GURL(origin)); |
147 callback.Run(result.Pass()); | 152 callback.Run(result.Pass()); |
148 } | 153 } |
149 | 154 |
150 void PermissionServiceImpl::OnRequestPermissionResponse( | 155 void PermissionServiceImpl::OnRequestPermissionResponse( |
151 int request_id, | 156 int request_id, |
152 PermissionStatus status) { | 157 PermissionStatus status) { |
153 PendingRequest* request = pending_requests_.Lookup(request_id); | 158 PendingRequest* request = pending_requests_.Lookup(request_id); |
154 PermissionStatusCallback callback(request->callback); | 159 PermissionStatusCallback callback(request->callback); |
155 request->callback.reset(); | 160 request->callback.reset(); |
156 pending_requests_.Remove(request_id); | 161 pending_requests_.Remove(request_id); |
157 callback.Run(status); | 162 callback.Run(status); |
158 } | 163 } |
159 | 164 |
160 void PermissionServiceImpl::CancelPendingOperations() { | 165 void PermissionServiceImpl::CancelPendingOperations() { |
161 DCHECK(context_->render_frame_host()); | |
162 DCHECK(context_->GetBrowserContext()); | 166 DCHECK(context_->GetBrowserContext()); |
163 | 167 |
164 PermissionManager* permission_manager = | 168 PermissionManager* permission_manager = |
165 context_->GetBrowserContext()->GetPermissionManager(); | 169 context_->GetBrowserContext()->GetPermissionManager(); |
166 if (!permission_manager) | 170 if (!permission_manager) |
167 return; | 171 return; |
168 | 172 |
169 // Cancel pending requests. | 173 // Cancel pending requests. |
170 for (RequestsMap::Iterator<PendingRequest> it(&pending_requests_); | 174 for (RequestsMap::Iterator<PendingRequest> it(&pending_requests_); |
171 !it.IsAtEnd(); it.Advance()) { | 175 !it.IsAtEnd(); it.Advance()) { |
172 permission_manager->CancelPermissionRequest( | 176 permission_manager->CancelPermissionRequest( |
173 it.GetCurrentValue()->permission, | 177 it.GetCurrentValue()->manager_id); |
174 context_->render_frame_host(), | |
175 it.GetCurrentKey(), | |
176 it.GetCurrentValue()->origin); | |
177 } | 178 } |
178 pending_requests_.Clear(); | 179 pending_requests_.Clear(); |
179 | 180 |
180 // Cancel pending subscriptions. | 181 // Cancel pending subscriptions. |
181 for (SubscriptionsMap::Iterator<PendingSubscription> | 182 for (SubscriptionsMap::Iterator<PendingSubscription> |
182 it(&pending_subscriptions_); !it.IsAtEnd(); it.Advance()) { | 183 it(&pending_subscriptions_); !it.IsAtEnd(); it.Advance()) { |
183 it.GetCurrentValue()->callback.Run(GetPermissionStatusFromType( | 184 it.GetCurrentValue()->callback.Run(GetPermissionStatusFromType( |
184 it.GetCurrentValue()->permission, it.GetCurrentValue()->origin)); | 185 it.GetCurrentValue()->permission, it.GetCurrentValue()->origin)); |
185 it.GetCurrentValue()->callback.reset(); | 186 it.GetCurrentValue()->callback.reset(); |
186 permission_manager->UnsubscribePermissionStatusChange( | 187 permission_manager->UnsubscribePermissionStatusChange( |
(...skipping 118 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
305 | 306 |
306 PermissionStatusCallback callback = subscription->callback; | 307 PermissionStatusCallback callback = subscription->callback; |
307 | 308 |
308 subscription->callback.reset(); | 309 subscription->callback.reset(); |
309 pending_subscriptions_.Remove(pending_subscription_id); | 310 pending_subscriptions_.Remove(pending_subscription_id); |
310 | 311 |
311 callback.Run(status); | 312 callback.Run(status); |
312 } | 313 } |
313 | 314 |
314 } // namespace content | 315 } // namespace content |
OLD | NEW |