Chromium Code Reviews| Index: content/browser/browser_plugin/browser_plugin_guest.cc |
| diff --git a/content/browser/browser_plugin/browser_plugin_guest.cc b/content/browser/browser_plugin/browser_plugin_guest.cc |
| index 7b6253d7dca9cef11a337d5cc38540580a944812..485f0c8944299b1f20063c641dc36f11e45a94fd 100644 |
| --- a/content/browser/browser_plugin/browser_plugin_guest.cc |
| +++ b/content/browser/browser_plugin/browser_plugin_guest.cc |
| @@ -346,7 +346,7 @@ BrowserPluginGuest::BrowserPluginGuest( |
| mouse_locked_(false), |
| pending_lock_request_(false), |
| embedder_visible_(true), |
| - next_permission_request_id_(0), |
| + next_permission_request_id_(browser_plugin::kInvalidPermissionRequestID), |
| has_render_view_(has_render_view) { |
| DCHECK(web_contents); |
| web_contents->SetDelegate(this); |
| @@ -383,15 +383,39 @@ void BrowserPluginGuest::DestroyUnattachedWindows() { |
| DCHECK_EQ(0ul, pending_new_windows_.size()); |
| } |
| +void BrowserPluginGuest::RespondToPermissionRequest( |
| + int request_id, |
| + bool should_allow, |
| + const std::string& user_input) { |
| + RequestMap::iterator request_itr = permission_request_map_.find(request_id); |
| + if (request_itr == permission_request_map_.end()) { |
| + LOG(INFO) << "Not a valid request ID."; |
| + return; |
| + } |
| + request_itr->second->Respond(should_allow, user_input); |
| + permission_request_map_.erase(request_itr); |
| +} |
| + |
| int BrowserPluginGuest::RequestPermission( |
| BrowserPluginPermissionType permission_type, |
| scoped_refptr<BrowserPluginGuest::PermissionRequest> request, |
| const base::DictionaryValue& request_info) { |
| - int request_id = next_permission_request_id_++; |
| + if (!delegate_) { |
| + request->Respond(false, ""); |
| + return browser_plugin::kInvalidPermissionRequestID; |
| + } |
| + |
| + int request_id = ++next_permission_request_id_; |
| permission_request_map_[request_id] = request; |
| - SendMessageToEmbedder(new BrowserPluginMsg_RequestPermission( |
| - instance_id(), permission_type, request_id, request_info)); |
| + BrowserPluginGuestDelegate::PermissionResponseCallback callback = |
| + base::Bind(&BrowserPluginGuest::RespondToPermissionRequest, |
| + AsWeakPtr(), |
| + request_id); |
| + // If BrowserPluginGuestDelegate hasn't handled the permission then we simply |
| + // reject it immediately. |
| + if (!delegate_->RequestPermission(permission_type, request_info, callback)) |
| + callback.Run(false, ""); |
|
lazyboy
2013/08/05 09:26:58
We should also not keep the request stored in perm
Fady Samuel
2013/08/06 07:14:40
That's exactly what callback.Run(false, "") does.
lazyboy
2013/08/08 19:58:01
Ah, I misread this part, for some reason I was thi
|
| return request_id; |
| } |
| @@ -422,8 +446,6 @@ bool BrowserPluginGuest::OnMessageReceivedFromEmbedder( |
| IPC_MESSAGE_HANDLER(BrowserPluginHostMsg_NavigateGuest, OnNavigateGuest) |
| IPC_MESSAGE_HANDLER(BrowserPluginHostMsg_PluginDestroyed, OnPluginDestroyed) |
| IPC_MESSAGE_HANDLER(BrowserPluginHostMsg_ResizeGuest, OnResizeGuest) |
| - IPC_MESSAGE_HANDLER(BrowserPluginHostMsg_RespondPermission, |
| - OnRespondPermission) |
| IPC_MESSAGE_HANDLER(BrowserPluginHostMsg_SetAutoSize, OnSetSize) |
| IPC_MESSAGE_HANDLER(BrowserPluginHostMsg_SetEditCommandsForNextKeyEvent, |
| OnSetEditCommandsForNextKeyEvent) |
| @@ -894,7 +916,7 @@ int BrowserPluginGuest::RemoveBridgeID(int bridge_id) { |
| std::map<int, int>::iterator bridge_itr = |
| bridge_id_to_request_id_map_.find(bridge_id); |
| if (bridge_itr == bridge_id_to_request_id_map_.end()) |
| - return -1; |
| + return browser_plugin::kInvalidPermissionRequestID; |
| int request_id = bridge_itr->second; |
| bridge_id_to_request_id_map_.erase(bridge_itr); |
| @@ -1016,7 +1038,6 @@ bool BrowserPluginGuest::ShouldForwardToBrowserPluginGuest( |
| case BrowserPluginHostMsg_NavigateGuest::ID: |
| case BrowserPluginHostMsg_PluginDestroyed::ID: |
| case BrowserPluginHostMsg_ResizeGuest::ID: |
| - case BrowserPluginHostMsg_RespondPermission::ID: |
| case BrowserPluginHostMsg_SetAutoSize::ID: |
| case BrowserPluginHostMsg_SetEditCommandsForNextKeyEvent::ID: |
| case BrowserPluginHostMsg_SetFocus::ID: |
| @@ -1371,20 +1392,6 @@ void BrowserPluginGuest::OnSetVisibility(int instance_id, bool visible) { |
| GetWebContents()->WasHidden(); |
| } |
| -void BrowserPluginGuest::OnRespondPermission( |
| - int instance_id, |
| - int request_id, |
| - bool should_allow, |
| - const std::string& user_input) { |
| - RequestMap::iterator request_itr = permission_request_map_.find(request_id); |
| - if (request_itr == permission_request_map_.end()) { |
| - LOG(INFO) << "Not a valid request ID."; |
| - return; |
| - } |
| - request_itr->second->Respond(should_allow, user_input); |
| - permission_request_map_.erase(request_itr); |
| -} |
| - |
| void BrowserPluginGuest::OnSwapBuffersACK(int instance_id, |
| int route_id, |
| int gpu_host_id, |