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 // We don't need to know if it's a privileged context for in-process plugins.
46 // In process plugins are deprecated and the only in-process plugin that
47 // exists is the "NaCl plugin" which will never need to know this.
48 bool is_privileged_context
= false;
49 Send(new ViewHostMsg_DidCreateInProcessInstance(
51 // Browser provides the render process id.
52 PepperRendererInstanceData(0, render_frame_id
, document_url
, plugin_url
,
53 is_privileged_context
)));
56 void PepperBrowserConnection::DidDeleteInProcessInstance(PP_Instance instance
) {
57 Send(new ViewHostMsg_DidDeleteInProcessInstance(instance
));
60 void PepperBrowserConnection::SendBrowserCreate(
63 const std::vector
<IPC::Message
>& nested_msgs
,
64 const PendingResourceIDCallback
& callback
) {
65 int32_t sequence_number
= GetNextSequence();
66 pending_create_map_
[sequence_number
] = callback
;
67 ppapi::proxy::ResourceMessageCallParams
params(0, sequence_number
);
68 Send(new PpapiHostMsg_CreateResourceHostsFromHost(
69 routing_id(), child_process_id
, params
, instance
, nested_msgs
));
72 void PepperBrowserConnection::OnMsgCreateResourceHostsFromHostReply(
73 int32_t sequence_number
,
74 const std::vector
<int>& pending_resource_host_ids
) {
75 // Check that the message is destined for the plugin this object is associated
77 std::map
<int32_t, PendingResourceIDCallback
>::iterator it
=
78 pending_create_map_
.find(sequence_number
);
79 if (it
!= pending_create_map_
.end()) {
80 it
->second
.Run(pending_resource_host_ids
);
81 pending_create_map_
.erase(it
);
87 int32_t PepperBrowserConnection::GetNextSequence() {
88 // Return the value with wraparound, making sure we don't make a sequence
89 // number with a 0 ID. Note that signed wraparound is undefined in C++ so we
91 int32_t ret
= next_sequence_number_
;
92 if (next_sequence_number_
== std::numeric_limits
<int32_t>::max())
93 next_sequence_number_
= 1; // Skip 0 which is invalid.
95 next_sequence_number_
++;
99 } // namespace content