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 void PepperBrowserConnection::GetAllPendingBrowserHosts( |
| 74 PP_Instance instance, |
| 75 int child_process_id, |
| 76 std::vector<ppapi::proxy::CompletedBrowserResourceHosts>* result) { |
| 77 Send(new PpapiHostMsg_GetAllPendingResourceHosts(routing_id(), |
| 78 child_process_id, |
| 79 instance, |
| 80 result)); |
| 81 // We just got all the responses that were pending, and we may not receive a |
| 82 // reply for all of them. Just ignore any replies we do get. |
| 83 pending_create_map_.clear(); |
| 84 } |
| 85 |
| 86 PepperBrowserConnection::PendingResource::PendingResource( |
| 87 int child_process_id_param, |
| 88 PP_Instance instance_param, |
| 89 const PendingResourceCallback& callback_param) |
| 90 : child_process_id(child_process_id_param), |
| 91 instance(instance_param), |
| 92 callback(callback_param) { |
| 93 } |
| 94 |
| 95 PepperBrowserConnection::PendingResource::~PendingResource() { |
66 } | 96 } |
67 | 97 |
68 void PepperBrowserConnection::OnMsgCreateResourceHostsFromHostReply( | 98 void PepperBrowserConnection::OnMsgCreateResourceHostsFromHostReply( |
69 int32_t sequence_number, | 99 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 | 100 // Check that the message is destined for the plugin this object is associated |
72 // with. | 101 // with. |
73 std::map<int32_t, PendingResourceIDCallback>::iterator it = | 102 std::map<int32_t, PendingResource>::iterator it = |
74 pending_create_map_.find(sequence_number); | 103 pending_create_map_.find(hosts.sequence_id); |
75 if (it != pending_create_map_.end()) { | 104 if (it != pending_create_map_.end()) { |
76 it->second.Run(pending_resource_host_ids); | 105 it->second.callback.Run(hosts); |
| 106 Send(new PpapiHostMsg_CreateResourceHostsFromHostReplyAck( |
| 107 it->second.child_process_id, |
| 108 it->second.instance, |
| 109 hosts.sequence_id)); |
77 pending_create_map_.erase(it); | 110 pending_create_map_.erase(it); |
78 } else { | 111 } else { |
79 NOTREACHED(); | 112 // This can happen if we already received the pending hosts via |
| 113 // sending GetAllPendingResourceHosts synchronously. |
80 } | 114 } |
81 } | 115 } |
82 | 116 |
83 int32_t PepperBrowserConnection::GetNextSequence() { | 117 int32_t PepperBrowserConnection::GetNextSequence() { |
84 // Return the value with wraparound, making sure we don't make a sequence | 118 // 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 | 119 // number with a 0 ID. Note that signed wraparound is undefined in C++ so we |
86 // manually check. | 120 // manually check. |
87 int32_t ret = next_sequence_number_; | 121 int32_t ret = next_sequence_number_; |
88 if (next_sequence_number_ == std::numeric_limits<int32_t>::max()) | 122 if (next_sequence_number_ == std::numeric_limits<int32_t>::max()) |
89 next_sequence_number_ = 1; // Skip 0 which is invalid. | 123 next_sequence_number_ = 1; // Skip 0 which is invalid. |
90 else | 124 else |
91 next_sequence_number_++; | 125 next_sequence_number_++; |
92 return ret; | 126 return ret; |
93 } | 127 } |
94 | 128 |
95 } // namespace content | 129 } // namespace content |
OLD | NEW |