| OLD | NEW |
| 1 // Copyright 2013 The Chromium Authors. All rights reserved. | 1 // Copyright 2013 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/renderer/pepper/pepper_browser_connection.h" | 5 #include "content/renderer/pepper/pepper_browser_connection.h" |
| 6 | 6 |
| 7 #include <limits> | 7 #include <limits> |
| 8 | 8 |
| 9 #include "base/logging.h" | 9 #include "base/logging.h" |
| 10 #include "content/common/view_messages.h" | 10 #include "content/common/view_messages.h" |
| 11 #include "content/renderer/pepper/pepper_in_process_router.h" | 11 #include "content/renderer/pepper/pepper_in_process_router.h" |
| 12 #include "content/renderer/render_frame_impl.h" | 12 #include "content/renderer/render_frame_impl.h" |
| 13 #include "ipc/ipc_message_macros.h" | 13 #include "ipc/ipc_message_macros.h" |
| 14 #include "ppapi/proxy/ppapi_messages.h" | 14 #include "ppapi/proxy/ppapi_messages.h" |
| 15 #include "ppapi/proxy/resource_message_params.h" | 15 #include "ppapi/proxy/resource_message_params.h" |
| 16 #include "ppapi/proxy/serialized_structs.h" |
| 16 | 17 |
| 17 namespace content { | 18 namespace content { |
| 18 | 19 |
| 19 PepperBrowserConnection::PepperBrowserConnection(RenderFrame* render_frame) | 20 PepperBrowserConnection::PepperBrowserConnection(RenderFrame* render_frame) |
| 20 : RenderFrameObserver(render_frame), | 21 : RenderFrameObserver(render_frame), |
| 21 RenderFrameObserverTracker<PepperBrowserConnection>(render_frame), | 22 RenderFrameObserverTracker<PepperBrowserConnection>(render_frame), |
| 22 next_sequence_number_(1) {} | 23 next_sequence_number_(1) {} |
| 23 | 24 |
| 24 PepperBrowserConnection::~PepperBrowserConnection() {} | 25 PepperBrowserConnection::~PepperBrowserConnection() {} |
| 25 | 26 |
| (...skipping 20 matching lines...) Expand all Loading... |
| 46 instance, | 47 instance, |
| 47 // Browser provides the render process id. | 48 // Browser provides the render process id. |
| 48 PepperRendererInstanceData( | 49 PepperRendererInstanceData( |
| 49 0, render_frame_id, document_url, plugin_url))); | 50 0, render_frame_id, document_url, plugin_url))); |
| 50 } | 51 } |
| 51 | 52 |
| 52 void PepperBrowserConnection::DidDeleteInProcessInstance(PP_Instance instance) { | 53 void PepperBrowserConnection::DidDeleteInProcessInstance(PP_Instance instance) { |
| 53 Send(new ViewHostMsg_DidDeleteInProcessInstance(instance)); | 54 Send(new ViewHostMsg_DidDeleteInProcessInstance(instance)); |
| 54 } | 55 } |
| 55 | 56 |
| 56 void PepperBrowserConnection::SendBrowserCreate( | 57 int32_t PepperBrowserConnection::SendBrowserCreate( |
| 57 int child_process_id, | 58 int child_process_id, |
| 58 PP_Instance instance, | 59 PP_Instance instance, |
| 59 const std::vector<IPC::Message>& nested_msgs, | 60 const std::vector<IPC::Message>& nested_msgs, |
| 60 const PendingResourceIDCallback& callback) { | 61 const PendingResourceCallback& callback) { |
| 61 int32_t sequence_number = GetNextSequence(); | 62 int32_t sequence_number = GetNextSequence(); |
| 62 pending_create_map_[sequence_number] = callback; | 63 pending_create_map_.insert( |
| 64 std::map<int32_t, PendingResource>::value_type( |
| 65 sequence_number, |
| 66 PendingResource(child_process_id, instance, callback))); |
| 63 ppapi::proxy::ResourceMessageCallParams params(0, sequence_number); | 67 ppapi::proxy::ResourceMessageCallParams params(0, sequence_number); |
| 64 Send(new PpapiHostMsg_CreateResourceHostsFromHost( | 68 Send(new PpapiHostMsg_CreateResourceHostsFromHost( |
| 65 routing_id(), child_process_id, params, instance, nested_msgs)); | 69 routing_id(), child_process_id, params, instance, nested_msgs)); |
| 70 return sequence_number; |
| 71 } |
| 72 |
| 73 PepperBrowserConnection::PendingResource::PendingResource( |
| 74 int child_process_id_param, |
| 75 PP_Instance instance_param, |
| 76 const PendingResourceCallback& callback_param) |
| 77 : child_process_id(child_process_id_param), |
| 78 instance(instance_param), |
| 79 callback(callback_param) { |
| 80 } |
| 81 |
| 82 PepperBrowserConnection::PendingResource::~PendingResource() { |
| 66 } | 83 } |
| 67 | 84 |
| 68 void PepperBrowserConnection::OnMsgCreateResourceHostsFromHostReply( | 85 void PepperBrowserConnection::OnMsgCreateResourceHostsFromHostReply( |
| 69 int32_t sequence_number, | 86 const ppapi::proxy::CompletedBrowserResourceHosts& hosts) { |
| 70 const std::vector<int>& pending_resource_host_ids) { | |
| 71 // Check that the message is destined for the plugin this object is associated | 87 // Check that the message is destined for the plugin this object is associated |
| 72 // with. | 88 // with. |
| 73 std::map<int32_t, PendingResourceIDCallback>::iterator it = | 89 std::map<int32_t, PendingResource>::iterator it = |
| 74 pending_create_map_.find(sequence_number); | 90 pending_create_map_.find(hosts.sequence_num); |
| 75 if (it != pending_create_map_.end()) { | 91 if (it != pending_create_map_.end()) { |
| 76 it->second.Run(pending_resource_host_ids); | 92 it->second.callback.Run(hosts); |
| 77 pending_create_map_.erase(it); | 93 pending_create_map_.erase(it); |
| 78 } else { | 94 } else { |
| 79 NOTREACHED(); | 95 NOTREACHED(); |
| 80 } | 96 } |
| 81 } | 97 } |
| 82 | 98 |
| 83 int32_t PepperBrowserConnection::GetNextSequence() { | 99 int32_t PepperBrowserConnection::GetNextSequence() { |
| 84 // Return the value with wraparound, making sure we don't make a sequence | 100 // Return the value with wraparound, making sure we don't make a sequence |
| 85 // number with a 0 ID. Note that signed wraparound is undefined in C++ so we | 101 // number with a 0 ID. Note that signed wraparound is undefined in C++ so we |
| 86 // manually check. | 102 // manually check. |
| 87 int32_t ret = next_sequence_number_; | 103 int32_t ret = next_sequence_number_; |
| 88 if (next_sequence_number_ == std::numeric_limits<int32_t>::max()) | 104 if (next_sequence_number_ == std::numeric_limits<int32_t>::max()) |
| 89 next_sequence_number_ = 1; // Skip 0 which is invalid. | 105 next_sequence_number_ = 1; // Skip 0 which is invalid. |
| 90 else | 106 else |
| 91 next_sequence_number_++; | 107 next_sequence_number_++; |
| 92 return ret; | 108 return ret; |
| 93 } | 109 } |
| 94 | 110 |
| 95 } // namespace content | 111 } // namespace content |
| OLD | NEW |