OLD | NEW |
(Empty) | |
| 1 // Copyright (c) 2011 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. |
| 4 |
| 5 #include "content/renderer/pepper/pepper_browser_connection.h" |
| 6 |
| 7 #include <limits> |
| 8 |
| 9 #include "base/logging.h" |
| 10 #include "ipc/ipc_message_macros.h" |
| 11 #include "ppapi/proxy/ppapi_messages.h" |
| 12 #include "ppapi/proxy/resource_message_params.h" |
| 13 |
| 14 namespace content { |
| 15 |
| 16 PepperBrowserConnection::PepperBrowserConnection(RenderView* render_view) |
| 17 : RenderViewObserver(render_view), |
| 18 next_sequence_number_(1) { |
| 19 } |
| 20 |
| 21 PepperBrowserConnection::~PepperBrowserConnection() { |
| 22 } |
| 23 |
| 24 bool PepperBrowserConnection::OnMessageReceived(const IPC::Message& msg) { |
| 25 bool handled = true; |
| 26 IPC_BEGIN_MESSAGE_MAP(PepperBrowserConnection, msg) |
| 27 IPC_MESSAGE_HANDLER(PpapiHostMsg_CreateResourceHostFromHostReply, |
| 28 OnMsgCreateResourceHostFromHostReply) |
| 29 IPC_MESSAGE_UNHANDLED(handled = false) |
| 30 IPC_END_MESSAGE_MAP() |
| 31 |
| 32 return handled; |
| 33 } |
| 34 |
| 35 void PepperBrowserConnection::SendBrowserCreate( |
| 36 int child_process_id, |
| 37 PP_Instance instance, |
| 38 const IPC::Message& nested_msg, |
| 39 PendingResourceIDCallback callback) { |
| 40 int32_t sequence_number = GetNextSequence(); |
| 41 pending_create_map_[sequence_number] = callback; |
| 42 ppapi::proxy::ResourceMessageCallParams params(0, sequence_number); |
| 43 Send(new PpapiHostMsg_CreateResourceHostFromHost( |
| 44 child_process_id, params, instance, nested_msg)); |
| 45 } |
| 46 |
| 47 void PepperBrowserConnection::OnMsgCreateResourceHostFromHostReply( |
| 48 int32_t sequence_number, |
| 49 int pending_resource_host_id) { |
| 50 // Check that the message is destined for the plugin this object is associated |
| 51 // with. |
| 52 std::map<int32_t, PendingResourceIDCallback>::iterator it = |
| 53 pending_create_map_.find(sequence_number); |
| 54 if (it != pending_create_map_.end()) { |
| 55 it->second.Run(pending_resource_host_id); |
| 56 pending_create_map_.erase(it); |
| 57 } else { |
| 58 NOTREACHED(); |
| 59 } |
| 60 } |
| 61 |
| 62 int32_t PepperBrowserConnection::GetNextSequence() { |
| 63 // Return the value with wraparound, making sure we don't make a sequence |
| 64 // number with a 0 ID. Note that signed wraparound is undefined in C++ so we |
| 65 // manually check. |
| 66 int32_t ret = next_sequence_number_; |
| 67 if (next_sequence_number_ == std::numeric_limits<int32_t>::max()) |
| 68 next_sequence_number_ = 1; // Skip 0 which is invalid. |
| 69 else |
| 70 next_sequence_number_++; |
| 71 return ret; |
| 72 } |
| 73 |
| 74 } // namespace content |
OLD | NEW |