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
3 // found in the LICENSE file.
5 #include "content/renderer/pepper/pepper_browser_connection.h"
9 #include "base/logging.h"
10 #include "content/common/view_messages.h"
11 #include "content/renderer/pepper/pepper_in_process_router.h"
12 #include "content/renderer/render_frame_impl.h"
13 #include "ipc/ipc_message_macros.h"
14 #include "ppapi/proxy/ppapi_messages.h"
15 #include "ppapi/proxy/resource_message_params.h"
19 PepperBrowserConnection::PepperBrowserConnection(RenderFrame
* render_frame
)
20 : RenderFrameObserver(render_frame
),
21 RenderFrameObserverTracker
<PepperBrowserConnection
>(render_frame
),
22 next_sequence_number_(1) {}
24 PepperBrowserConnection::~PepperBrowserConnection() {}
26 bool PepperBrowserConnection::OnMessageReceived(const IPC::Message
& msg
) {
27 // Check if the message is an in-process reply.
28 if (PepperInProcessRouter::OnPluginMsgReceived(msg
))
32 IPC_BEGIN_MESSAGE_MAP(PepperBrowserConnection
, msg
)
33 IPC_MESSAGE_HANDLER(PpapiHostMsg_CreateResourceHostsFromHostReply
,
34 OnMsgCreateResourceHostsFromHostReply
)
35 IPC_MESSAGE_UNHANDLED(handled
= false)
40 void PepperBrowserConnection::DidCreateInProcessInstance(
43 const GURL
& document_url
,
44 const GURL
& plugin_url
) {
45 Send(new ViewHostMsg_DidCreateInProcessInstance(
47 // Browser provides the render process id.
48 PepperRendererInstanceData(
49 0, render_frame_id
, document_url
, plugin_url
)));
52 void PepperBrowserConnection::DidDeleteInProcessInstance(PP_Instance instance
) {
53 Send(new ViewHostMsg_DidDeleteInProcessInstance(instance
));
56 void PepperBrowserConnection::SendBrowserCreate(
59 const std::vector
<IPC::Message
>& nested_msgs
,
60 const PendingResourceIDCallback
& callback
) {
61 int32_t sequence_number
= GetNextSequence();
62 pending_create_map_
[sequence_number
] = callback
;
63 ppapi::proxy::ResourceMessageCallParams
params(0, sequence_number
);
64 Send(new PpapiHostMsg_CreateResourceHostsFromHost(
65 routing_id(), child_process_id
, params
, instance
, nested_msgs
));
68 void PepperBrowserConnection::OnMsgCreateResourceHostsFromHostReply(
69 int32_t sequence_number
,
70 const std::vector
<int>& pending_resource_host_ids
) {
71 // Check that the message is destined for the plugin this object is associated
73 std::map
<int32_t, PendingResourceIDCallback
>::iterator it
=
74 pending_create_map_
.find(sequence_number
);
75 if (it
!= pending_create_map_
.end()) {
76 it
->second
.Run(pending_resource_host_ids
);
77 pending_create_map_
.erase(it
);
83 int32_t PepperBrowserConnection::GetNextSequence() {
84 // 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
87 int32_t ret
= next_sequence_number_
;
88 if (next_sequence_number_
== std::numeric_limits
<int32_t>::max())
89 next_sequence_number_
= 1; // Skip 0 which is invalid.
91 next_sequence_number_
++;
95 } // namespace content