content/gpu: Ownership and lifetime cleanup for CommandBufferProxyImpl.
[chromium-blink-merge.git] / content / renderer / pepper / pepper_browser_connection.cc
blobf8e08b21d17e606abb40507636ca51a8f36d551b
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"
7 #include <limits>
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"
17 namespace content {
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))
29 return true;
31 bool handled = true;
32 IPC_BEGIN_MESSAGE_MAP(PepperBrowserConnection, msg)
33 IPC_MESSAGE_HANDLER(PpapiHostMsg_CreateResourceHostsFromHostReply,
34 OnMsgCreateResourceHostsFromHostReply)
35 IPC_MESSAGE_UNHANDLED(handled = false)
36 IPC_END_MESSAGE_MAP()
37 return handled;
40 void PepperBrowserConnection::DidCreateInProcessInstance(
41 PP_Instance instance,
42 int render_frame_id,
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(
50 instance,
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(
61 int child_process_id,
62 PP_Instance instance,
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
76 // with.
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);
82 } else {
83 NOTREACHED();
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
90 // manually check.
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.
94 else
95 next_sequence_number_++;
96 return ret;
99 } // namespace content