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

Side by Side Diff: content/browser/browser_plugin/browser_plugin_guest.cc

Issue 21297005: <webview>: Refactor Permission API to chrome (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@cleanup_permissions
Patch Set: Cleanup Created 7 years, 4 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 (c) 2012 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2012 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/browser_plugin/browser_plugin_guest.h" 5 #include "content/browser/browser_plugin/browser_plugin_guest.h"
6 6
7 #include <algorithm> 7 #include <algorithm>
8 8
9 #include "base/command_line.h" 9 #include "base/command_line.h"
10 #include "base/message_loop/message_loop.h" 10 #include "base/message_loop/message_loop.h"
(...skipping 328 matching lines...) Expand 10 before | Expand all | Expand 10 after
339 damage_buffer_sequence_id_(0), 339 damage_buffer_sequence_id_(0),
340 damage_buffer_size_(0), 340 damage_buffer_size_(0),
341 damage_buffer_scale_factor_(1.0f), 341 damage_buffer_scale_factor_(1.0f),
342 guest_device_scale_factor_(1.0f), 342 guest_device_scale_factor_(1.0f),
343 guest_hang_timeout_( 343 guest_hang_timeout_(
344 base::TimeDelta::FromMilliseconds(kHungRendererDelayMs)), 344 base::TimeDelta::FromMilliseconds(kHungRendererDelayMs)),
345 focused_(false), 345 focused_(false),
346 mouse_locked_(false), 346 mouse_locked_(false),
347 pending_lock_request_(false), 347 pending_lock_request_(false),
348 embedder_visible_(true), 348 embedder_visible_(true),
349 next_permission_request_id_(0), 349 next_permission_request_id_(browser_plugin::kInvalidPermissionRequestID),
350 has_render_view_(has_render_view) { 350 has_render_view_(has_render_view) {
351 DCHECK(web_contents); 351 DCHECK(web_contents);
352 web_contents->SetDelegate(this); 352 web_contents->SetDelegate(this);
353 if (opener) 353 if (opener)
354 opener_ = opener->AsWeakPtr(); 354 opener_ = opener->AsWeakPtr();
355 GetWebContents()->GetBrowserPluginGuestManager()->AddGuest(instance_id_, 355 GetWebContents()->GetBrowserPluginGuestManager()->AddGuest(instance_id_,
356 GetWebContents()); 356 GetWebContents());
357 } 357 }
358 358
359 bool BrowserPluginGuest::AddMessageToConsole(WebContents* source, 359 bool BrowserPluginGuest::AddMessageToConsole(WebContents* source,
(...skipping 16 matching lines...) Expand all
376 // Clean up unattached new windows opened by this guest. 376 // Clean up unattached new windows opened by this guest.
377 for (PendingWindowMap::const_iterator it = pending_new_windows.begin(); 377 for (PendingWindowMap::const_iterator it = pending_new_windows.begin();
378 it != pending_new_windows.end(); ++it) { 378 it != pending_new_windows.end(); ++it) {
379 it->first->Destroy(); 379 it->first->Destroy();
380 } 380 }
381 // All pending windows should be removed from the set after Destroy() is 381 // All pending windows should be removed from the set after Destroy() is
382 // called on all of them. 382 // called on all of them.
383 DCHECK_EQ(0ul, pending_new_windows_.size()); 383 DCHECK_EQ(0ul, pending_new_windows_.size());
384 } 384 }
385 385
386 void BrowserPluginGuest::RespondToPermissionRequest(
387 int request_id,
388 bool should_allow,
389 const std::string& user_input) {
390 RequestMap::iterator request_itr = permission_request_map_.find(request_id);
391 if (request_itr == permission_request_map_.end()) {
392 LOG(INFO) << "Not a valid request ID.";
393 return;
394 }
395 request_itr->second->Respond(should_allow, user_input);
396 permission_request_map_.erase(request_itr);
397 }
398
386 int BrowserPluginGuest::RequestPermission( 399 int BrowserPluginGuest::RequestPermission(
387 BrowserPluginPermissionType permission_type, 400 BrowserPluginPermissionType permission_type,
388 scoped_refptr<BrowserPluginGuest::PermissionRequest> request, 401 scoped_refptr<BrowserPluginGuest::PermissionRequest> request,
389 const base::DictionaryValue& request_info) { 402 const base::DictionaryValue& request_info) {
390 int request_id = next_permission_request_id_++; 403 if (!delegate_) {
404 request->Respond(false, "");
405 return browser_plugin::kInvalidPermissionRequestID;
406 }
407
408 int request_id = ++next_permission_request_id_;
391 permission_request_map_[request_id] = request; 409 permission_request_map_[request_id] = request;
392 410
393 SendMessageToEmbedder(new BrowserPluginMsg_RequestPermission( 411 BrowserPluginGuestDelegate::PermissionResponseCallback callback =
394 instance_id(), permission_type, request_id, request_info)); 412 base::Bind(&BrowserPluginGuest::RespondToPermissionRequest,
413 AsWeakPtr(),
414 request_id);
415 // If BrowserPluginGuestDelegate hasn't handled the permission then we simply
416 // reject it immediately.
417 if (!delegate_->RequestPermission(permission_type, request_info, callback))
418 callback.Run(false, "");
395 419
396 return request_id; 420 return request_id;
397 } 421 }
398 422
399 void BrowserPluginGuest::Destroy() { 423 void BrowserPluginGuest::Destroy() {
400 if (!attached() && opener()) 424 if (!attached() && opener())
401 opener()->pending_new_windows_.erase(this); 425 opener()->pending_new_windows_.erase(this);
402 DestroyUnattachedWindows(); 426 DestroyUnattachedWindows();
403 GetWebContents()->GetBrowserPluginGuestManager()->RemoveGuest(instance_id_); 427 GetWebContents()->GetBrowserPluginGuestManager()->RemoveGuest(instance_id_);
404 delete GetWebContents(); 428 delete GetWebContents();
(...skipping 10 matching lines...) Expand all
415 IPC_MESSAGE_HANDLER(BrowserPluginHostMsg_DragStatusUpdate, 439 IPC_MESSAGE_HANDLER(BrowserPluginHostMsg_DragStatusUpdate,
416 OnDragStatusUpdate) 440 OnDragStatusUpdate)
417 IPC_MESSAGE_HANDLER(BrowserPluginHostMsg_ExecuteEditCommand, 441 IPC_MESSAGE_HANDLER(BrowserPluginHostMsg_ExecuteEditCommand,
418 OnExecuteEditCommand) 442 OnExecuteEditCommand)
419 IPC_MESSAGE_HANDLER(BrowserPluginHostMsg_HandleInputEvent, 443 IPC_MESSAGE_HANDLER(BrowserPluginHostMsg_HandleInputEvent,
420 OnHandleInputEvent) 444 OnHandleInputEvent)
421 IPC_MESSAGE_HANDLER(BrowserPluginHostMsg_LockMouse_ACK, OnLockMouseAck) 445 IPC_MESSAGE_HANDLER(BrowserPluginHostMsg_LockMouse_ACK, OnLockMouseAck)
422 IPC_MESSAGE_HANDLER(BrowserPluginHostMsg_NavigateGuest, OnNavigateGuest) 446 IPC_MESSAGE_HANDLER(BrowserPluginHostMsg_NavigateGuest, OnNavigateGuest)
423 IPC_MESSAGE_HANDLER(BrowserPluginHostMsg_PluginDestroyed, OnPluginDestroyed) 447 IPC_MESSAGE_HANDLER(BrowserPluginHostMsg_PluginDestroyed, OnPluginDestroyed)
424 IPC_MESSAGE_HANDLER(BrowserPluginHostMsg_ResizeGuest, OnResizeGuest) 448 IPC_MESSAGE_HANDLER(BrowserPluginHostMsg_ResizeGuest, OnResizeGuest)
425 IPC_MESSAGE_HANDLER(BrowserPluginHostMsg_RespondPermission,
426 OnRespondPermission)
427 IPC_MESSAGE_HANDLER(BrowserPluginHostMsg_SetAutoSize, OnSetSize) 449 IPC_MESSAGE_HANDLER(BrowserPluginHostMsg_SetAutoSize, OnSetSize)
428 IPC_MESSAGE_HANDLER(BrowserPluginHostMsg_SetEditCommandsForNextKeyEvent, 450 IPC_MESSAGE_HANDLER(BrowserPluginHostMsg_SetEditCommandsForNextKeyEvent,
429 OnSetEditCommandsForNextKeyEvent) 451 OnSetEditCommandsForNextKeyEvent)
430 IPC_MESSAGE_HANDLER(BrowserPluginHostMsg_SetFocus, OnSetFocus) 452 IPC_MESSAGE_HANDLER(BrowserPluginHostMsg_SetFocus, OnSetFocus)
431 IPC_MESSAGE_HANDLER(BrowserPluginHostMsg_SetName, OnSetName) 453 IPC_MESSAGE_HANDLER(BrowserPluginHostMsg_SetName, OnSetName)
432 IPC_MESSAGE_HANDLER(BrowserPluginHostMsg_SetVisibility, OnSetVisibility) 454 IPC_MESSAGE_HANDLER(BrowserPluginHostMsg_SetVisibility, OnSetVisibility)
433 IPC_MESSAGE_HANDLER(BrowserPluginHostMsg_UnlockMouse_ACK, OnUnlockMouseAck) 455 IPC_MESSAGE_HANDLER(BrowserPluginHostMsg_UnlockMouse_ACK, OnUnlockMouseAck)
434 IPC_MESSAGE_HANDLER(BrowserPluginHostMsg_UpdateGeometry, OnUpdateGeometry) 456 IPC_MESSAGE_HANDLER(BrowserPluginHostMsg_UpdateGeometry, OnUpdateGeometry)
435 IPC_MESSAGE_HANDLER(BrowserPluginHostMsg_UpdateRect_ACK, OnUpdateRectACK) 457 IPC_MESSAGE_HANDLER(BrowserPluginHostMsg_UpdateRect_ACK, OnUpdateRectACK)
436 IPC_MESSAGE_UNHANDLED(handled = false) 458 IPC_MESSAGE_UNHANDLED(handled = false)
(...skipping 450 matching lines...) Expand 10 before | Expand all | Expand 10 after
887 909
888 DCHECK(bridge_id_to_request_id_map_.find(bridge_id) == 910 DCHECK(bridge_id_to_request_id_map_.find(bridge_id) ==
889 bridge_id_to_request_id_map_.end()); 911 bridge_id_to_request_id_map_.end());
890 bridge_id_to_request_id_map_[bridge_id] = request_id; 912 bridge_id_to_request_id_map_[bridge_id] = request_id;
891 } 913 }
892 914
893 int BrowserPluginGuest::RemoveBridgeID(int bridge_id) { 915 int BrowserPluginGuest::RemoveBridgeID(int bridge_id) {
894 std::map<int, int>::iterator bridge_itr = 916 std::map<int, int>::iterator bridge_itr =
895 bridge_id_to_request_id_map_.find(bridge_id); 917 bridge_id_to_request_id_map_.find(bridge_id);
896 if (bridge_itr == bridge_id_to_request_id_map_.end()) 918 if (bridge_itr == bridge_id_to_request_id_map_.end())
897 return -1; 919 return browser_plugin::kInvalidPermissionRequestID;
898 920
899 int request_id = bridge_itr->second; 921 int request_id = bridge_itr->second;
900 bridge_id_to_request_id_map_.erase(bridge_itr); 922 bridge_id_to_request_id_map_.erase(bridge_itr);
901 return request_id; 923 return request_id;
902 } 924 }
903 925
904 void BrowserPluginGuest::CancelGeolocationRequest(int bridge_id) { 926 void BrowserPluginGuest::CancelGeolocationRequest(int bridge_id) {
905 int request_id = RemoveBridgeID(bridge_id); 927 int request_id = RemoveBridgeID(bridge_id);
906 RequestMap::iterator request_itr = permission_request_map_.find(request_id); 928 RequestMap::iterator request_itr = permission_request_map_.find(request_id);
907 if (request_itr == permission_request_map_.end()) 929 if (request_itr == permission_request_map_.end())
(...skipping 101 matching lines...) Expand 10 before | Expand all | Expand 10 after
1009 switch (message.type()) { 1031 switch (message.type()) {
1010 case BrowserPluginHostMsg_BuffersSwappedACK::ID: 1032 case BrowserPluginHostMsg_BuffersSwappedACK::ID:
1011 case BrowserPluginHostMsg_CompositorFrameACK::ID: 1033 case BrowserPluginHostMsg_CompositorFrameACK::ID:
1012 case BrowserPluginHostMsg_DragStatusUpdate::ID: 1034 case BrowserPluginHostMsg_DragStatusUpdate::ID:
1013 case BrowserPluginHostMsg_ExecuteEditCommand::ID: 1035 case BrowserPluginHostMsg_ExecuteEditCommand::ID:
1014 case BrowserPluginHostMsg_HandleInputEvent::ID: 1036 case BrowserPluginHostMsg_HandleInputEvent::ID:
1015 case BrowserPluginHostMsg_LockMouse_ACK::ID: 1037 case BrowserPluginHostMsg_LockMouse_ACK::ID:
1016 case BrowserPluginHostMsg_NavigateGuest::ID: 1038 case BrowserPluginHostMsg_NavigateGuest::ID:
1017 case BrowserPluginHostMsg_PluginDestroyed::ID: 1039 case BrowserPluginHostMsg_PluginDestroyed::ID:
1018 case BrowserPluginHostMsg_ResizeGuest::ID: 1040 case BrowserPluginHostMsg_ResizeGuest::ID:
1019 case BrowserPluginHostMsg_RespondPermission::ID:
1020 case BrowserPluginHostMsg_SetAutoSize::ID: 1041 case BrowserPluginHostMsg_SetAutoSize::ID:
1021 case BrowserPluginHostMsg_SetEditCommandsForNextKeyEvent::ID: 1042 case BrowserPluginHostMsg_SetEditCommandsForNextKeyEvent::ID:
1022 case BrowserPluginHostMsg_SetFocus::ID: 1043 case BrowserPluginHostMsg_SetFocus::ID:
1023 case BrowserPluginHostMsg_SetName::ID: 1044 case BrowserPluginHostMsg_SetName::ID:
1024 case BrowserPluginHostMsg_SetVisibility::ID: 1045 case BrowserPluginHostMsg_SetVisibility::ID:
1025 case BrowserPluginHostMsg_UnlockMouse_ACK::ID: 1046 case BrowserPluginHostMsg_UnlockMouse_ACK::ID:
1026 case BrowserPluginHostMsg_UpdateGeometry::ID: 1047 case BrowserPluginHostMsg_UpdateGeometry::ID:
1027 case BrowserPluginHostMsg_UpdateRect_ACK::ID: 1048 case BrowserPluginHostMsg_UpdateRect_ACK::ID:
1028 return true; 1049 return true;
1029 default: 1050 default:
(...skipping 334 matching lines...) Expand 10 before | Expand all | Expand 10 after
1364 } 1385 }
1365 1386
1366 void BrowserPluginGuest::OnSetVisibility(int instance_id, bool visible) { 1387 void BrowserPluginGuest::OnSetVisibility(int instance_id, bool visible) {
1367 guest_visible_ = visible; 1388 guest_visible_ = visible;
1368 if (embedder_visible_ && guest_visible_) 1389 if (embedder_visible_ && guest_visible_)
1369 GetWebContents()->WasShown(); 1390 GetWebContents()->WasShown();
1370 else 1391 else
1371 GetWebContents()->WasHidden(); 1392 GetWebContents()->WasHidden();
1372 } 1393 }
1373 1394
1374 void BrowserPluginGuest::OnRespondPermission(
1375 int instance_id,
1376 int request_id,
1377 bool should_allow,
1378 const std::string& user_input) {
1379 RequestMap::iterator request_itr = permission_request_map_.find(request_id);
1380 if (request_itr == permission_request_map_.end()) {
1381 LOG(INFO) << "Not a valid request ID.";
1382 return;
1383 }
1384 request_itr->second->Respond(should_allow, user_input);
1385 permission_request_map_.erase(request_itr);
1386 }
1387
1388 void BrowserPluginGuest::OnSwapBuffersACK(int instance_id, 1395 void BrowserPluginGuest::OnSwapBuffersACK(int instance_id,
1389 int route_id, 1396 int route_id,
1390 int gpu_host_id, 1397 int gpu_host_id,
1391 const std::string& mailbox_name, 1398 const std::string& mailbox_name,
1392 uint32 sync_point) { 1399 uint32 sync_point) {
1393 AcknowledgeBufferPresent(route_id, gpu_host_id, mailbox_name, sync_point); 1400 AcknowledgeBufferPresent(route_id, gpu_host_id, mailbox_name, sync_point);
1394 1401
1395 // This is only relevant on MACOSX and WIN when threaded compositing 1402 // This is only relevant on MACOSX and WIN when threaded compositing
1396 // is not enabled. In threaded mode, above ACK is sufficient. 1403 // is not enabled. In threaded mode, above ACK is sufficient.
1397 #if defined(OS_MACOSX) || defined(OS_WIN) 1404 #if defined(OS_MACOSX) || defined(OS_WIN)
(...skipping 231 matching lines...) Expand 10 before | Expand all | Expand 10 after
1629 request_info.Set(browser_plugin::kRequestMethod, 1636 request_info.Set(browser_plugin::kRequestMethod,
1630 base::Value::CreateStringValue(request_method)); 1637 base::Value::CreateStringValue(request_method));
1631 request_info.Set(browser_plugin::kURL, base::Value::CreateStringValue(url)); 1638 request_info.Set(browser_plugin::kURL, base::Value::CreateStringValue(url));
1632 1639
1633 RequestPermission(BrowserPluginPermissionTypeDownload, 1640 RequestPermission(BrowserPluginPermissionTypeDownload,
1634 new DownloadRequest(callback), 1641 new DownloadRequest(callback),
1635 request_info); 1642 request_info);
1636 } 1643 }
1637 1644
1638 } // namespace content 1645 } // namespace content
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698