Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(514)

Side by Side Diff: android_webview/browser/aw_permission_manager.cc

Issue 1316863010: browser: implement multiple permission requesting (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@request-multiple-content
Patch Set: Rebase on master Created 5 years, 2 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
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"
(...skipping 240 matching lines...) Expand 10 before | Expand all | Expand 10 after
251 callback.Run(content::PERMISSION_STATUS_GRANTED); 251 callback.Run(content::PERMISSION_STATUS_GRANTED);
252 break; 252 break;
253 case PermissionType::NUM: 253 case PermissionType::NUM:
254 NOTREACHED() << "PermissionType::NUM was not expected here."; 254 NOTREACHED() << "PermissionType::NUM was not expected here.";
255 callback.Run(content::PERMISSION_STATUS_DENIED); 255 callback.Run(content::PERMISSION_STATUS_DENIED);
256 break; 256 break;
257 } 257 }
258 return request_id; 258 return request_id;
259 } 259 }
260 260
261 int AwPermissionManager::RequestPermissions(
262 const std::vector<PermissionType>& permissions,
263 content::RenderFrameHost* render_frame_host,
264 const GURL& requesting_origin,
265 bool user_gesture,
266 const base::Callback<void(
267 const std::vector<PermissionStatus>&)>& callback) {
268 NOTIMPLEMENTED() << "RequestPermissions has not been implemented in WebView";
269
270 std::vector<PermissionStatus> result;
271 const GURL& embedding_origin =
272 content::WebContents::FromRenderFrameHost(render_frame_host)
273 ->GetLastCommittedURL().GetOrigin();
274 for (PermissionType type : permissions) {
275 result.push_back(GetPermissionStatus(
276 type, requesting_origin, embedding_origin));
277 }
278 return kNoPendingOperation;
279 }
280
261 // static 281 // static
262 void AwPermissionManager::OnRequestResponse( 282 void AwPermissionManager::OnRequestResponse(
263 const base::WeakPtr<AwPermissionManager>& manager, 283 const base::WeakPtr<AwPermissionManager>& manager,
264 int request_id, 284 int request_id,
265 const base::Callback<void(PermissionStatus)>& callback, 285 const base::Callback<void(PermissionStatus)>& callback,
266 bool allowed) { 286 bool allowed) {
267 PermissionStatus status = allowed ? content::PERMISSION_STATUS_GRANTED 287 PermissionStatus status = allowed ? content::PERMISSION_STATUS_GRANTED
268 : content::PERMISSION_STATUS_DENIED; 288 : content::PERMISSION_STATUS_DENIED;
269 if (manager.get()) { 289 if (manager.get()) {
270 PendingRequest* pending_request = 290 PendingRequest* pending_request =
(...skipping 12 matching lines...) Expand all
283 manager->result_cache_->SetResult( 303 manager->result_cache_->SetResult(
284 pending_request->permission, 304 pending_request->permission,
285 pending_request->requesting_origin, 305 pending_request->requesting_origin,
286 pending_request->embedding_origin, 306 pending_request->embedding_origin,
287 status); 307 status);
288 manager->pending_requests_.Remove(request_id); 308 manager->pending_requests_.Remove(request_id);
289 } 309 }
290 callback.Run(status); 310 callback.Run(status);
291 } 311 }
292 312
293 void AwPermissionManager::CancelPermissionRequest( 313 void AwPermissionManager::CancelPermissionRequest(int request_id) {
294 PermissionType permission,
295 content::RenderFrameHost* render_frame_host,
296 int request_id,
297 const GURL& origin) {
298 PendingRequest* pending_request = pending_requests_.Lookup(request_id); 314 PendingRequest* pending_request = pending_requests_.Lookup(request_id);
299 if (!pending_request) 315 if (!pending_request)
300 return; 316 return;
301 317
318 content::RenderFrameHost* render_frame_host =
319 content::RenderFrameHost::FromID(pending_request->render_process_id,
320 pending_request->render_frame_id);
321 content::WebContents* web_contents =
322 content::WebContents::FromRenderFrameHost(render_frame_host);
323 DCHECK(web_contents);
324
302 // The caller is canceling (presumably) the most recent request. Assuming the 325 // The caller is canceling (presumably) the most recent request. Assuming the
303 // request did not complete, the user did not respond to the requset. 326 // request did not complete, the user did not respond to the requset.
304 // Thus, assume we do not know the result. 327 // Thus, assume we do not know the result.
305 const GURL& embedding_origin = 328 const GURL& embedding_origin = web_contents
306 content::WebContents::FromRenderFrameHost(render_frame_host)
307 ->GetLastCommittedURL().GetOrigin(); 329 ->GetLastCommittedURL().GetOrigin();
308 result_cache_->ClearResult(permission, origin, embedding_origin); 330 result_cache_->ClearResult(
331 pending_request->permission,
332 pending_request->requesting_origin,
333 embedding_origin);
309 334
310 int render_process_id = render_frame_host->GetProcess()->GetID();
311 int render_frame_id = render_frame_host->GetRoutingID();
312 AwBrowserPermissionRequestDelegate* delegate = 335 AwBrowserPermissionRequestDelegate* delegate =
313 AwBrowserPermissionRequestDelegate::FromID(render_process_id, 336 AwBrowserPermissionRequestDelegate::FromID(
314 render_frame_id); 337 pending_request->render_process_id,
338 pending_request->render_frame_id);
315 if (!delegate) { 339 if (!delegate) {
316 pending_requests_.Remove(request_id); 340 pending_requests_.Remove(request_id);
317 return; 341 return;
318 } 342 }
319 343
320 switch (permission) { 344 switch (pending_request->permission) {
321 case PermissionType::GEOLOCATION: 345 case PermissionType::GEOLOCATION:
322 delegate->CancelGeolocationPermissionRequests(origin); 346 delegate->CancelGeolocationPermissionRequests(
347 pending_request->requesting_origin);
323 break; 348 break;
324 case PermissionType::PROTECTED_MEDIA_IDENTIFIER: 349 case PermissionType::PROTECTED_MEDIA_IDENTIFIER:
325 delegate->CancelProtectedMediaIdentifierPermissionRequests(origin); 350 delegate->CancelProtectedMediaIdentifierPermissionRequests(
351 pending_request->requesting_origin);
326 break; 352 break;
327 case PermissionType::MIDI_SYSEX: 353 case PermissionType::MIDI_SYSEX:
328 delegate->CancelMIDISysexPermissionRequests(origin); 354 delegate->CancelMIDISysexPermissionRequests(
355 pending_request->requesting_origin);
329 break; 356 break;
330 case PermissionType::NOTIFICATIONS: 357 case PermissionType::NOTIFICATIONS:
331 case PermissionType::PUSH_MESSAGING: 358 case PermissionType::PUSH_MESSAGING:
332 case PermissionType::DURABLE_STORAGE: 359 case PermissionType::DURABLE_STORAGE:
333 case PermissionType::AUDIO_CAPTURE: 360 case PermissionType::AUDIO_CAPTURE:
334 case PermissionType::VIDEO_CAPTURE: 361 case PermissionType::VIDEO_CAPTURE:
335 NOTIMPLEMENTED() << "CancelPermission not implemented for " 362 NOTIMPLEMENTED() << "CancelPermission not implemented for "
336 << static_cast<int>(permission); 363 << static_cast<int>(pending_request->permission);
337 break; 364 break;
338 case PermissionType::MIDI: 365 case PermissionType::MIDI:
339 // There is nothing to cancel so this is simply ignored. 366 // There is nothing to cancel so this is simply ignored.
340 break; 367 break;
341 case PermissionType::NUM: 368 case PermissionType::NUM:
342 NOTREACHED() << "PermissionType::NUM was not expected here."; 369 NOTREACHED() << "PermissionType::NUM was not expected here.";
343 break; 370 break;
344 } 371 }
345 372
346 pending_requests_.Remove(request_id); 373 pending_requests_.Remove(request_id);
(...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after
379 const GURL& embedding_origin, 406 const GURL& embedding_origin,
380 const base::Callback<void(PermissionStatus)>& callback) { 407 const base::Callback<void(PermissionStatus)>& callback) {
381 return kNoPendingOperation; 408 return kNoPendingOperation;
382 } 409 }
383 410
384 void AwPermissionManager::UnsubscribePermissionStatusChange( 411 void AwPermissionManager::UnsubscribePermissionStatusChange(
385 int subscription_id) { 412 int subscription_id) {
386 } 413 }
387 414
388 } // namespace android_webview 415 } // namespace android_webview
OLDNEW
« no previous file with comments | « android_webview/browser/aw_permission_manager.h ('k') | chrome/browser/permissions/permission_manager.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698