OLD | NEW |
1 // Copyright 2015 The Chromium Authors. All rights reserved. | 1 // Copyright 2015 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 "android_webview/browser/aw_permission_manager.h" | 5 #include "android_webview/browser/aw_permission_manager.h" |
6 | 6 |
7 #include <string> | 7 #include <string> |
8 | 8 |
9 #include "android_webview/browser/aw_browser_permission_request_delegate.h" | 9 #include "android_webview/browser/aw_browser_permission_request_delegate.h" |
10 #include "base/callback.h" | 10 #include "base/callback.h" |
11 #include "base/containers/hash_tables.h" | 11 #include "base/containers/hash_tables.h" |
12 #include "base/logging.h" | 12 #include "base/logging.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/render_process_host.h" | 15 #include "content/public/browser/render_process_host.h" |
16 #include "content/public/browser/web_contents.h" | 16 #include "content/public/browser/web_contents.h" |
17 | 17 |
18 using blink::mojom::PermissionStatus; | 18 using blink::mojom::PermissionStatus; |
19 using content::PermissionType; | 19 using content::PermissionType; |
20 | 20 |
| 21 using RequestPermissionsCallback = |
| 22 base::Callback<void(const std::vector<PermissionStatus>&)>; |
| 23 |
21 namespace android_webview { | 24 namespace android_webview { |
22 | 25 |
| 26 namespace { |
| 27 |
| 28 void PermissionRequestResponseCallbackWrapper( |
| 29 const base::Callback<void(PermissionStatus)>& callback, |
| 30 const std::vector<PermissionStatus>& vector) { |
| 31 DCHECK_EQ(vector.size(), 1ul); |
| 32 callback.Run(vector[0]); |
| 33 } |
| 34 |
| 35 } // namespace |
| 36 |
23 class LastRequestResultCache { | 37 class LastRequestResultCache { |
24 public: | 38 public: |
25 LastRequestResultCache() = default; | 39 LastRequestResultCache() = default; |
26 | 40 |
27 void SetResult(PermissionType permission, | 41 void SetResult(PermissionType permission, |
28 const GURL& requesting_origin, | 42 const GURL& requesting_origin, |
29 const GURL& embedding_origin, | 43 const GURL& embedding_origin, |
30 PermissionStatus status) { | 44 PermissionStatus status) { |
31 DCHECK(status == PermissionStatus::GRANTED || | 45 DCHECK(status == PermissionStatus::GRANTED || |
32 status == PermissionStatus::DENIED); | 46 status == PermissionStatus::DENIED); |
(...skipping 91 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
124 return std::string(); | 138 return std::string(); |
125 return requesting + "," + embedding; | 139 return requesting + "," + embedding; |
126 } | 140 } |
127 | 141 |
128 using StatusMap = base::hash_map<std::string, PermissionStatus>; | 142 using StatusMap = base::hash_map<std::string, PermissionStatus>; |
129 StatusMap pmi_result_cache_; | 143 StatusMap pmi_result_cache_; |
130 | 144 |
131 DISALLOW_COPY_AND_ASSIGN(LastRequestResultCache); | 145 DISALLOW_COPY_AND_ASSIGN(LastRequestResultCache); |
132 }; | 146 }; |
133 | 147 |
134 struct AwPermissionManager::PendingRequest { | 148 class AwPermissionManager::PendingRequest { |
135 public: | 149 public: |
136 PendingRequest(PermissionType permission, | 150 PendingRequest(const std::vector<PermissionType> permissions, |
137 GURL requesting_origin, | 151 GURL requesting_origin, |
138 GURL embedding_origin, | 152 GURL embedding_origin, |
139 content::RenderFrameHost* render_frame_host, | 153 int render_process_id, |
140 const base::Callback<void(PermissionStatus)>& callback) | 154 int render_frame_id, |
141 : permission(permission), | 155 const RequestPermissionsCallback callback) |
142 requesting_origin(requesting_origin), | 156 : permissions(permissions), |
143 embedding_origin(embedding_origin), | 157 requesting_origin(requesting_origin), |
144 render_process_id(render_frame_host->GetProcess()->GetID()), | 158 embedding_origin(embedding_origin), |
145 render_frame_id(render_frame_host->GetRoutingID()), | 159 render_process_id(render_process_id), |
146 callback(callback) { | 160 render_frame_id(render_frame_id), |
| 161 callback(callback), |
| 162 results(permissions.size(), PermissionStatus::DENIED), |
| 163 cancelled_(false) { |
| 164 for (size_t i = 0; i < permissions.size(); ++i) |
| 165 permission_index_map_.insert(std::make_pair(permissions[i], i)); |
147 } | 166 } |
148 | 167 |
149 ~PendingRequest() = default; | 168 ~PendingRequest() = default; |
150 | 169 |
151 PermissionType permission; | 170 void SetPermissionStatus(PermissionType type, PermissionStatus status) { |
| 171 auto result = permission_index_map_.find(type); |
| 172 if (result == permission_index_map_.end()) { |
| 173 NOTREACHED(); |
| 174 return; |
| 175 } |
| 176 DCHECK(!IsCompleted()); |
| 177 results[result->second] = status; |
| 178 resolved_permissions_.insert(type); |
| 179 } |
| 180 |
| 181 PermissionStatus GetPermissionStatus(PermissionType type) { |
| 182 auto result = permission_index_map_.find(type); |
| 183 if (result == permission_index_map_.end()) { |
| 184 NOTREACHED(); |
| 185 return PermissionStatus::DENIED; |
| 186 } |
| 187 return results[result->second]; |
| 188 } |
| 189 |
| 190 bool HasPermissionType(PermissionType type) { |
| 191 return permission_index_map_.find(type) != permission_index_map_.end(); |
| 192 } |
| 193 |
| 194 bool IsCompleted() const { |
| 195 return results.size() == resolved_permissions_.size(); |
| 196 } |
| 197 |
| 198 bool IsCompleted(PermissionType type) const { |
| 199 return resolved_permissions_.count(type) != 0; |
| 200 } |
| 201 |
| 202 void Cancel() { cancelled_ = true; } |
| 203 |
| 204 bool IsCancelled() const { return cancelled_; } |
| 205 |
| 206 std::vector<PermissionType> permissions; |
152 GURL requesting_origin; | 207 GURL requesting_origin; |
153 GURL embedding_origin; | 208 GURL embedding_origin; |
154 int render_process_id; | 209 int render_process_id; |
155 int render_frame_id; | 210 int render_frame_id; |
156 base::Callback<void(PermissionStatus)> callback; | 211 RequestPermissionsCallback callback; |
| 212 std::vector<PermissionStatus> results; |
| 213 |
| 214 private: |
| 215 std::map<PermissionType, size_t> permission_index_map_; |
| 216 std::set<PermissionType> resolved_permissions_; |
| 217 bool cancelled_; |
157 }; | 218 }; |
158 | 219 |
159 AwPermissionManager::AwPermissionManager() | 220 AwPermissionManager::AwPermissionManager() |
160 : content::PermissionManager(), | 221 : content::PermissionManager(), |
161 result_cache_(new LastRequestResultCache), | 222 result_cache_(new LastRequestResultCache), |
162 weak_ptr_factory_(this) { | 223 weak_ptr_factory_(this) { |
163 } | 224 } |
164 | 225 |
165 AwPermissionManager::~AwPermissionManager() { | 226 AwPermissionManager::~AwPermissionManager() { |
| 227 CancelPermissionRequests(); |
166 } | 228 } |
167 | 229 |
168 int AwPermissionManager::RequestPermission( | 230 int AwPermissionManager::RequestPermission( |
169 PermissionType permission, | 231 PermissionType permission, |
170 content::RenderFrameHost* render_frame_host, | 232 content::RenderFrameHost* render_frame_host, |
171 const GURL& requesting_origin, | 233 const GURL& requesting_origin, |
172 bool user_gesture, | 234 bool user_gesture, |
173 const base::Callback<void(PermissionStatus)>& callback) { | 235 const base::Callback<void(PermissionStatus)>& callback) { |
174 int render_process_id = render_frame_host->GetProcess()->GetID(); | 236 return RequestPermissions( |
175 int render_frame_id = render_frame_host->GetRoutingID(); | 237 std::vector<PermissionType>(1, permission), render_frame_host, |
176 AwBrowserPermissionRequestDelegate* delegate = | 238 requesting_origin, user_gesture, |
177 AwBrowserPermissionRequestDelegate::FromID(render_process_id, | 239 base::Bind(&PermissionRequestResponseCallbackWrapper, callback)); |
178 render_frame_id); | |
179 if (!delegate) { | |
180 DVLOG(0) << "Dropping permission request for " | |
181 << static_cast<int>(permission); | |
182 callback.Run(PermissionStatus::DENIED); | |
183 return kNoPendingOperation; | |
184 } | |
185 | |
186 // Do not delegate any requests which are already pending. | |
187 bool should_delegate_request = true; | |
188 for (PendingRequestsMap::Iterator<PendingRequest> it(&pending_requests_); | |
189 !it.IsAtEnd(); it.Advance()) { | |
190 if (permission == it.GetCurrentValue()->permission) { | |
191 should_delegate_request = false; | |
192 break; | |
193 } | |
194 } | |
195 | |
196 const GURL& embedding_origin = | |
197 content::WebContents::FromRenderFrameHost(render_frame_host) | |
198 ->GetLastCommittedURL().GetOrigin(); | |
199 | |
200 int request_id = kNoPendingOperation; | |
201 switch (permission) { | |
202 case PermissionType::GEOLOCATION: | |
203 request_id = pending_requests_.Add(new PendingRequest( | |
204 permission, requesting_origin, | |
205 embedding_origin, render_frame_host, | |
206 callback)); | |
207 if (should_delegate_request) { | |
208 delegate->RequestGeolocationPermission( | |
209 requesting_origin, | |
210 base::Bind(&OnRequestResponse, | |
211 weak_ptr_factory_.GetWeakPtr(), request_id, | |
212 callback)); | |
213 } | |
214 break; | |
215 case PermissionType::PROTECTED_MEDIA_IDENTIFIER: | |
216 request_id = pending_requests_.Add(new PendingRequest( | |
217 permission, requesting_origin, | |
218 embedding_origin, render_frame_host, | |
219 callback)); | |
220 if (should_delegate_request) { | |
221 delegate->RequestProtectedMediaIdentifierPermission( | |
222 requesting_origin, | |
223 base::Bind(&OnRequestResponse, | |
224 weak_ptr_factory_.GetWeakPtr(), request_id, | |
225 callback)); | |
226 } | |
227 break; | |
228 case PermissionType::MIDI_SYSEX: | |
229 request_id = pending_requests_.Add(new PendingRequest( | |
230 permission, requesting_origin, | |
231 embedding_origin, render_frame_host, | |
232 callback)); | |
233 if (should_delegate_request) { | |
234 delegate->RequestMIDISysexPermission( | |
235 requesting_origin, | |
236 base::Bind(&OnRequestResponse, | |
237 weak_ptr_factory_.GetWeakPtr(), request_id, | |
238 callback)); | |
239 } | |
240 break; | |
241 case PermissionType::AUDIO_CAPTURE: | |
242 case PermissionType::VIDEO_CAPTURE: | |
243 case PermissionType::NOTIFICATIONS: | |
244 case PermissionType::PUSH_MESSAGING: | |
245 case PermissionType::DURABLE_STORAGE: | |
246 case PermissionType::BACKGROUND_SYNC: | |
247 NOTIMPLEMENTED() << "RequestPermission is not implemented for " | |
248 << static_cast<int>(permission); | |
249 callback.Run(PermissionStatus::DENIED); | |
250 break; | |
251 case PermissionType::MIDI: | |
252 callback.Run(PermissionStatus::GRANTED); | |
253 break; | |
254 case PermissionType::NUM: | |
255 NOTREACHED() << "PermissionType::NUM was not expected here."; | |
256 callback.Run(PermissionStatus::DENIED); | |
257 break; | |
258 } | |
259 return request_id; | |
260 } | 240 } |
261 | 241 |
262 int AwPermissionManager::RequestPermissions( | 242 int AwPermissionManager::RequestPermissions( |
263 const std::vector<PermissionType>& permissions, | 243 const std::vector<PermissionType>& permissions, |
264 content::RenderFrameHost* render_frame_host, | 244 content::RenderFrameHost* render_frame_host, |
265 const GURL& requesting_origin, | 245 const GURL& requesting_origin, |
266 bool user_gesture, | 246 bool user_gesture, |
267 const base::Callback<void( | 247 const base::Callback<void(const std::vector<PermissionStatus>&)>& |
268 const std::vector<PermissionStatus>&)>& callback) { | 248 callback) { |
269 NOTIMPLEMENTED() << "RequestPermissions has not been implemented in WebView"; | 249 if (permissions.empty()) { |
270 | 250 callback.Run(std::vector<PermissionStatus>()); |
271 std::vector<PermissionStatus> result(permissions.size()); | 251 return kNoPendingOperation; |
272 const GURL& embedding_origin = | 252 } |
273 content::WebContents::FromRenderFrameHost(render_frame_host) | 253 |
274 ->GetLastCommittedURL().GetOrigin(); | 254 const GURL& embedding_origin = LastCommittedOrigin(render_frame_host); |
275 | 255 |
276 for (PermissionType type : permissions) { | 256 PendingRequest* pending_request = |
277 result.push_back(GetPermissionStatus( | 257 new PendingRequest(permissions, requesting_origin, embedding_origin, |
278 type, requesting_origin, embedding_origin)); | 258 GetRenderProcessID(render_frame_host), |
279 } | 259 GetRenderFrameID(render_frame_host), callback); |
280 | 260 std::vector<bool> should_delegate_requests = |
281 callback.Run(result); | 261 std::vector<bool>(permissions.size(), true); |
282 return kNoPendingOperation; | 262 for (size_t i = 0; i < permissions.size(); ++i) { |
| 263 for (PendingRequestsMap::Iterator<PendingRequest> it(&pending_requests_); |
| 264 !it.IsAtEnd(); it.Advance()) { |
| 265 if (it.GetCurrentValue()->HasPermissionType(permissions[i]) && |
| 266 it.GetCurrentValue()->requesting_origin == requesting_origin) { |
| 267 if (it.GetCurrentValue()->IsCompleted(permissions[i])) { |
| 268 pending_request->SetPermissionStatus( |
| 269 permissions[i], |
| 270 it.GetCurrentValue()->GetPermissionStatus(permissions[i])); |
| 271 } |
| 272 should_delegate_requests[i] = false; |
| 273 break; |
| 274 } |
| 275 } |
| 276 } |
| 277 |
| 278 int request_id = pending_requests_.Add(pending_request); |
| 279 |
| 280 AwBrowserPermissionRequestDelegate* delegate = GetDelegate( |
| 281 pending_request->render_process_id, pending_request->render_frame_id); |
| 282 |
| 283 for (size_t i = 0; i < permissions.size(); ++i) { |
| 284 if (!should_delegate_requests[i]) |
| 285 continue; |
| 286 |
| 287 if (!delegate) { |
| 288 DVLOG(0) << "Dropping permissions request for " |
| 289 << static_cast<int>(permissions[i]); |
| 290 pending_request->SetPermissionStatus(permissions[i], |
| 291 PermissionStatus::DENIED); |
| 292 continue; |
| 293 } |
| 294 |
| 295 switch (permissions[i]) { |
| 296 case PermissionType::GEOLOCATION: |
| 297 delegate->RequestGeolocationPermission( |
| 298 pending_request->requesting_origin, |
| 299 base::Bind(&OnRequestResponse, weak_ptr_factory_.GetWeakPtr(), |
| 300 request_id, permissions[i])); |
| 301 break; |
| 302 case PermissionType::PROTECTED_MEDIA_IDENTIFIER: |
| 303 delegate->RequestProtectedMediaIdentifierPermission( |
| 304 pending_request->requesting_origin, |
| 305 base::Bind(&OnRequestResponse, weak_ptr_factory_.GetWeakPtr(), |
| 306 request_id, permissions[i])); |
| 307 break; |
| 308 case PermissionType::MIDI_SYSEX: |
| 309 delegate->RequestMIDISysexPermission( |
| 310 pending_request->requesting_origin, |
| 311 base::Bind(&OnRequestResponse, weak_ptr_factory_.GetWeakPtr(), |
| 312 request_id, permissions[i])); |
| 313 break; |
| 314 case PermissionType::AUDIO_CAPTURE: |
| 315 case PermissionType::VIDEO_CAPTURE: |
| 316 case PermissionType::NOTIFICATIONS: |
| 317 case PermissionType::PUSH_MESSAGING: |
| 318 case PermissionType::DURABLE_STORAGE: |
| 319 case PermissionType::BACKGROUND_SYNC: |
| 320 NOTIMPLEMENTED() << "RequestPermissions is not implemented for " |
| 321 << static_cast<int>(permissions[i]); |
| 322 pending_request->SetPermissionStatus(permissions[i], |
| 323 PermissionStatus::DENIED); |
| 324 break; |
| 325 case PermissionType::MIDI: |
| 326 pending_request->SetPermissionStatus(permissions[i], |
| 327 PermissionStatus::GRANTED); |
| 328 break; |
| 329 case PermissionType::NUM: |
| 330 NOTREACHED() << "PermissionType::NUM was not expected here."; |
| 331 pending_request->SetPermissionStatus(permissions[i], |
| 332 PermissionStatus::DENIED); |
| 333 break; |
| 334 } |
| 335 } |
| 336 |
| 337 // If delegate resolve the permission synchronously, all requests could be |
| 338 // already resolved here. |
| 339 if (!pending_requests_.Lookup(request_id)) |
| 340 return kNoPendingOperation; |
| 341 |
| 342 // If requests are resolved without calling delegate functions, e.g. |
| 343 // PermissionType::MIDI is permitted within the previous for-loop, all |
| 344 // requests could be already resolved, but still in the |pending_requests_| |
| 345 // without invoking the callback. |
| 346 if (pending_request->IsCompleted()) { |
| 347 std::vector<PermissionStatus> results = pending_request->results; |
| 348 pending_requests_.Remove(request_id); |
| 349 callback.Run(results); |
| 350 return kNoPendingOperation; |
| 351 } |
| 352 |
| 353 return request_id; |
283 } | 354 } |
284 | 355 |
285 // static | 356 // static |
286 void AwPermissionManager::OnRequestResponse( | 357 void AwPermissionManager::OnRequestResponse( |
287 const base::WeakPtr<AwPermissionManager>& manager, | 358 const base::WeakPtr<AwPermissionManager>& manager, |
288 int request_id, | 359 int request_id, |
289 const base::Callback<void(PermissionStatus)>& callback, | 360 PermissionType permission, |
290 bool allowed) { | 361 bool allowed) { |
| 362 // All delegate functions should be cancelled when the manager runs |
| 363 // destructor. Therefore |manager| should be always valid here. |
| 364 DCHECK(manager); |
| 365 |
291 PermissionStatus status = | 366 PermissionStatus status = |
292 allowed ? PermissionStatus::GRANTED : PermissionStatus::DENIED; | 367 allowed ? PermissionStatus::GRANTED : PermissionStatus::DENIED; |
293 if (manager.get()) { | 368 PendingRequest* pending_request = |
294 PendingRequest* pending_request = | 369 manager->pending_requests_.Lookup(request_id); |
295 manager->pending_requests_.Lookup(request_id); | 370 |
296 | 371 manager->result_cache_->SetResult(permission, |
297 for (PendingRequestsMap::Iterator<PendingRequest> it( | 372 pending_request->requesting_origin, |
298 &manager->pending_requests_); | 373 pending_request->embedding_origin, status); |
299 !it.IsAtEnd(); it.Advance()) { | 374 |
300 if (pending_request->permission == it.GetCurrentValue()->permission && | 375 std::vector<int> complete_request_ids; |
301 it.GetCurrentKey() != request_id) { | 376 std::vector<std::pair<const RequestPermissionsCallback, |
302 it.GetCurrentValue()->callback.Run(status); | 377 std::vector<PermissionStatus>>> |
303 manager->pending_requests_.Remove(it.GetCurrentKey()); | 378 complete_request_pairs; |
| 379 for (PendingRequestsMap::Iterator<PendingRequest> it( |
| 380 &manager->pending_requests_); |
| 381 !it.IsAtEnd(); it.Advance()) { |
| 382 if (!it.GetCurrentValue()->HasPermissionType(permission) || |
| 383 it.GetCurrentValue()->requesting_origin != |
| 384 pending_request->requesting_origin) { |
| 385 continue; |
| 386 } |
| 387 it.GetCurrentValue()->SetPermissionStatus(permission, status); |
| 388 if (it.GetCurrentValue()->IsCompleted()) { |
| 389 complete_request_ids.push_back(it.GetCurrentKey()); |
| 390 if (!it.GetCurrentValue()->IsCancelled()) { |
| 391 complete_request_pairs.push_back(std::make_pair( |
| 392 it.GetCurrentValue()->callback, it.GetCurrentValue()->results)); |
304 } | 393 } |
305 } | 394 } |
306 | 395 } |
307 manager->result_cache_->SetResult( | 396 for (auto id : complete_request_ids) |
308 pending_request->permission, | 397 manager->pending_requests_.Remove(id); |
309 pending_request->requesting_origin, | 398 for (auto pair : complete_request_pairs) |
310 pending_request->embedding_origin, | 399 pair.first.Run(pair.second); |
311 status); | |
312 manager->pending_requests_.Remove(request_id); | |
313 } | |
314 callback.Run(status); | |
315 } | 400 } |
316 | 401 |
317 void AwPermissionManager::CancelPermissionRequest(int request_id) { | 402 void AwPermissionManager::CancelPermissionRequest(int request_id) { |
318 PendingRequest* pending_request = pending_requests_.Lookup(request_id); | 403 PendingRequest* pending_request = pending_requests_.Lookup(request_id); |
319 if (!pending_request) | 404 if (!pending_request || pending_request->IsCancelled()) |
320 return; | 405 return; |
321 | 406 pending_request->Cancel(); |
322 content::RenderFrameHost* render_frame_host = | 407 |
323 content::RenderFrameHost::FromID(pending_request->render_process_id, | 408 const GURL& embedding_origin = pending_request->embedding_origin; |
324 pending_request->render_frame_id); | 409 const GURL& requesting_origin = pending_request->requesting_origin; |
325 content::WebContents* web_contents = | 410 for (auto permission : pending_request->permissions) |
326 content::WebContents::FromRenderFrameHost(render_frame_host); | 411 result_cache_->ClearResult(permission, requesting_origin, embedding_origin); |
327 DCHECK(web_contents); | 412 |
328 | 413 AwBrowserPermissionRequestDelegate* delegate = GetDelegate( |
329 // The caller is canceling (presumably) the most recent request. Assuming the | 414 pending_request->render_process_id, pending_request->render_frame_id); |
330 // request did not complete, the user did not respond to the requset. | 415 |
331 // Thus, assume we do not know the result. | 416 for (auto permission : pending_request->permissions) { |
332 const GURL& embedding_origin = web_contents | 417 // If the permission was already resolved, we do not need to cancel it. |
333 ->GetLastCommittedURL().GetOrigin(); | 418 if (pending_request->IsCompleted(permission)) |
334 result_cache_->ClearResult( | 419 continue; |
335 pending_request->permission, | 420 |
336 pending_request->requesting_origin, | 421 // If another pending_request waits for the same permission being resolved, |
337 embedding_origin); | 422 // we should not cancel the delegate's request. |
338 | 423 bool should_not_cancel_ = false; |
339 AwBrowserPermissionRequestDelegate* delegate = | 424 for (PendingRequestsMap::Iterator<PendingRequest> it(&pending_requests_); |
340 AwBrowserPermissionRequestDelegate::FromID( | 425 !it.IsAtEnd(); it.Advance()) { |
341 pending_request->render_process_id, | 426 if (it.GetCurrentValue() != pending_request && |
342 pending_request->render_frame_id); | 427 it.GetCurrentValue()->HasPermissionType(permission) && |
343 if (!delegate) { | 428 it.GetCurrentValue()->requesting_origin == requesting_origin && |
| 429 !it.GetCurrentValue()->IsCompleted(permission)) { |
| 430 should_not_cancel_ = true; |
| 431 break; |
| 432 } |
| 433 } |
| 434 if (should_not_cancel_) |
| 435 continue; |
| 436 |
| 437 switch (permission) { |
| 438 case PermissionType::GEOLOCATION: |
| 439 if (delegate) |
| 440 delegate->CancelGeolocationPermissionRequests(requesting_origin); |
| 441 break; |
| 442 case PermissionType::PROTECTED_MEDIA_IDENTIFIER: |
| 443 if (delegate) |
| 444 delegate->CancelProtectedMediaIdentifierPermissionRequests( |
| 445 requesting_origin); |
| 446 break; |
| 447 case PermissionType::MIDI_SYSEX: |
| 448 if (delegate) |
| 449 delegate->CancelMIDISysexPermissionRequests(requesting_origin); |
| 450 break; |
| 451 case PermissionType::NOTIFICATIONS: |
| 452 case PermissionType::PUSH_MESSAGING: |
| 453 case PermissionType::DURABLE_STORAGE: |
| 454 case PermissionType::AUDIO_CAPTURE: |
| 455 case PermissionType::VIDEO_CAPTURE: |
| 456 case PermissionType::BACKGROUND_SYNC: |
| 457 NOTIMPLEMENTED() << "CancelPermission not implemented for " |
| 458 << static_cast<int>(permission); |
| 459 break; |
| 460 case PermissionType::MIDI: |
| 461 // There is nothing to cancel so this is simply ignored. |
| 462 break; |
| 463 case PermissionType::NUM: |
| 464 NOTREACHED() << "PermissionType::NUM was not expected here."; |
| 465 break; |
| 466 } |
| 467 pending_request->SetPermissionStatus(permission, PermissionStatus::DENIED); |
| 468 } |
| 469 |
| 470 // If there are still active requests, we should not remove request_id here, |
| 471 // but just do not invoke a relevant callback when the request is resolved in |
| 472 // OnRequestResponse(). |
| 473 if (pending_request->IsCompleted()) |
344 pending_requests_.Remove(request_id); | 474 pending_requests_.Remove(request_id); |
345 return; | |
346 } | |
347 | |
348 switch (pending_request->permission) { | |
349 case PermissionType::GEOLOCATION: | |
350 delegate->CancelGeolocationPermissionRequests( | |
351 pending_request->requesting_origin); | |
352 break; | |
353 case PermissionType::PROTECTED_MEDIA_IDENTIFIER: | |
354 delegate->CancelProtectedMediaIdentifierPermissionRequests( | |
355 pending_request->requesting_origin); | |
356 break; | |
357 case PermissionType::MIDI_SYSEX: | |
358 delegate->CancelMIDISysexPermissionRequests( | |
359 pending_request->requesting_origin); | |
360 break; | |
361 case PermissionType::NOTIFICATIONS: | |
362 case PermissionType::PUSH_MESSAGING: | |
363 case PermissionType::DURABLE_STORAGE: | |
364 case PermissionType::AUDIO_CAPTURE: | |
365 case PermissionType::VIDEO_CAPTURE: | |
366 case PermissionType::BACKGROUND_SYNC: | |
367 NOTIMPLEMENTED() << "CancelPermission not implemented for " | |
368 << static_cast<int>(pending_request->permission); | |
369 break; | |
370 case PermissionType::MIDI: | |
371 // There is nothing to cancel so this is simply ignored. | |
372 break; | |
373 case PermissionType::NUM: | |
374 NOTREACHED() << "PermissionType::NUM was not expected here."; | |
375 break; | |
376 } | |
377 | |
378 pending_requests_.Remove(request_id); | |
379 } | 475 } |
380 | 476 |
381 void AwPermissionManager::ResetPermission(PermissionType permission, | 477 void AwPermissionManager::ResetPermission(PermissionType permission, |
382 const GURL& requesting_origin, | 478 const GURL& requesting_origin, |
383 const GURL& embedding_origin) { | 479 const GURL& embedding_origin) { |
384 result_cache_->ClearResult(permission, requesting_origin, embedding_origin); | 480 result_cache_->ClearResult(permission, requesting_origin, embedding_origin); |
385 } | 481 } |
386 | 482 |
387 PermissionStatus AwPermissionManager::GetPermissionStatus( | 483 PermissionStatus AwPermissionManager::GetPermissionStatus( |
388 PermissionType permission, | 484 PermissionType permission, |
(...skipping 21 matching lines...) Expand all Loading... |
410 const GURL& requesting_origin, | 506 const GURL& requesting_origin, |
411 const GURL& embedding_origin, | 507 const GURL& embedding_origin, |
412 const base::Callback<void(PermissionStatus)>& callback) { | 508 const base::Callback<void(PermissionStatus)>& callback) { |
413 return kNoPendingOperation; | 509 return kNoPendingOperation; |
414 } | 510 } |
415 | 511 |
416 void AwPermissionManager::UnsubscribePermissionStatusChange( | 512 void AwPermissionManager::UnsubscribePermissionStatusChange( |
417 int subscription_id) { | 513 int subscription_id) { |
418 } | 514 } |
419 | 515 |
| 516 void AwPermissionManager::CancelPermissionRequests() { |
| 517 std::vector<int> request_ids; |
| 518 for (PendingRequestsMap::Iterator<PendingRequest> it(&pending_requests_); |
| 519 !it.IsAtEnd(); it.Advance()) { |
| 520 request_ids.push_back(it.GetCurrentKey()); |
| 521 } |
| 522 for (auto request_id : request_ids) |
| 523 CancelPermissionRequest(request_id); |
| 524 DCHECK(pending_requests_.IsEmpty()); |
| 525 } |
| 526 |
| 527 int AwPermissionManager::GetRenderProcessID( |
| 528 content::RenderFrameHost* render_frame_host) { |
| 529 return render_frame_host->GetProcess()->GetID(); |
| 530 } |
| 531 |
| 532 int AwPermissionManager::GetRenderFrameID( |
| 533 content::RenderFrameHost* render_frame_host) { |
| 534 return render_frame_host->GetRoutingID(); |
| 535 } |
| 536 |
| 537 GURL AwPermissionManager::LastCommittedOrigin( |
| 538 content::RenderFrameHost* render_frame_host) { |
| 539 return content::WebContents::FromRenderFrameHost(render_frame_host) |
| 540 ->GetLastCommittedURL().GetOrigin(); |
| 541 } |
| 542 |
| 543 AwBrowserPermissionRequestDelegate* AwPermissionManager::GetDelegate( |
| 544 int render_process_id, int render_frame_id) { |
| 545 return AwBrowserPermissionRequestDelegate::FromID(render_process_id, |
| 546 render_frame_id); |
| 547 } |
| 548 |
420 } // namespace android_webview | 549 } // namespace android_webview |
OLD | NEW |