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 ResourceHostCreationCallback& 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(std::map<int32_t, PendingResource>::value_type( |
| 64 sequence_number, PendingResource(child_process_id, instance, callback))); |
63 ppapi::proxy::ResourceMessageCallParams params(0, sequence_number); | 65 ppapi::proxy::ResourceMessageCallParams params(0, sequence_number); |
64 Send(new PpapiHostMsg_CreateResourceHostsFromHost( | 66 Send(new PpapiHostMsg_CreateResourceHostsFromHost( |
65 routing_id(), child_process_id, params, instance, nested_msgs)); | 67 routing_id(), child_process_id, params, instance, nested_msgs)); |
| 68 return sequence_number; |
| 69 } |
| 70 |
| 71 PepperBrowserConnection::PendingResource::PendingResource( |
| 72 int child_process_id_param, |
| 73 PP_Instance instance_param, |
| 74 const ResourceHostCreationCallback& callback_param) |
| 75 : child_process_id(child_process_id_param), |
| 76 instance(instance_param), |
| 77 callback(callback_param) { |
| 78 } |
| 79 |
| 80 PepperBrowserConnection::PendingResource::~PendingResource() { |
66 } | 81 } |
67 | 82 |
68 void PepperBrowserConnection::OnMsgCreateResourceHostsFromHostReply( | 83 void PepperBrowserConnection::OnMsgCreateResourceHostsFromHostReply( |
69 int32_t sequence_number, | 84 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 | 85 // Check that the message is destined for the plugin this object is associated |
72 // with. | 86 // with. |
73 std::map<int32_t, PendingResourceIDCallback>::iterator it = | 87 std::map<int32_t, PendingResource>::iterator it = |
74 pending_create_map_.find(sequence_number); | 88 pending_create_map_.find(hosts.sequence_number); |
75 if (it != pending_create_map_.end()) { | 89 if (it != pending_create_map_.end()) { |
76 it->second.Run(pending_resource_host_ids); | 90 it->second.callback.Run(hosts); |
77 pending_create_map_.erase(it); | 91 pending_create_map_.erase(it); |
78 } else { | 92 } else { |
79 NOTREACHED(); | 93 NOTREACHED(); |
80 } | 94 } |
81 } | 95 } |
82 | 96 |
83 int32_t PepperBrowserConnection::GetNextSequence() { | 97 int32_t PepperBrowserConnection::GetNextSequence() { |
84 // Return the value with wraparound, making sure we don't make a sequence | 98 // 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 | 99 // number with a 0 ID. Note that signed wraparound is undefined in C++ so we |
86 // manually check. | 100 // manually check. |
87 int32_t ret = next_sequence_number_; | 101 int32_t ret = next_sequence_number_; |
88 if (next_sequence_number_ == std::numeric_limits<int32_t>::max()) | 102 if (next_sequence_number_ == std::numeric_limits<int32_t>::max()) |
89 next_sequence_number_ = 1; // Skip 0 which is invalid. | 103 next_sequence_number_ = 1; // Skip 0 which is invalid. |
90 else | 104 else |
91 next_sequence_number_++; | 105 next_sequence_number_++; |
92 return ret; | 106 return ret; |
93 } | 107 } |
94 | 108 |
95 } // namespace content | 109 } // namespace content |
OLD | NEW |