Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(83)

Side by Side Diff: content/renderer/pepper/pepper_browser_connection.cc

Issue 15947004: Allow renderer to create pepper ResourceHosts in the browser (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Created 7 years, 6 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
OLDNEW
(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 "content/renderer/pepper/pepper_plugin_delegate_impl.h"
11 #include "content/renderer/render_view_impl.h"
12 #include "ipc/ipc_message_macros.h"
13 #include "ppapi/proxy/ppapi_messages.h"
14 #include "ppapi/proxy/resource_message_params.h"
15
16 namespace content {
17
18 PepperBrowserConnection::PepperBrowserConnection(
19 PepperPluginDelegateImpl* plugin_delegate)
20 : plugin_delegate_(plugin_delegate),
21 next_sequence_number_(1) {
22 }
23
24 PepperBrowserConnection::~PepperBrowserConnection() {
25 }
26
27 bool PepperBrowserConnection::OnMessageReceived(const IPC::Message& msg) {
28 bool handled = true;
29 IPC_BEGIN_MESSAGE_MAP(PepperBrowserConnection, msg)
30 IPC_MESSAGE_HANDLER(PpapiHostMsg_CreateResourceHostFromHostReply,
31 OnMsgCreateResourceHostFromHostReply)
32 IPC_MESSAGE_UNHANDLED(handled = false)
33 IPC_END_MESSAGE_MAP()
34
35 return handled;
36 }
37
38 void PepperBrowserConnection::SendBrowserCreate(
39 int child_process_id,
40 PP_Instance instance,
41 const IPC::Message& nested_msg,
42 const PendingResourceIDCallback& callback) {
43 int32_t sequence_number = GetNextSequence();
44 pending_create_map_[sequence_number] = callback;
45 ppapi::proxy::ResourceMessageCallParams params(0, sequence_number);
46 plugin_delegate_->render_view()->Send(
47 new PpapiHostMsg_CreateResourceHostFromHost(
48 child_process_id, params, instance, nested_msg));
49 }
50
51 void PepperBrowserConnection::OnMsgCreateResourceHostFromHostReply(
52 int32_t sequence_number,
53 int pending_resource_host_id) {
54 // Check that the message is destined for the plugin this object is associated
55 // with.
56 std::map<int32_t, PendingResourceIDCallback>::iterator it =
57 pending_create_map_.find(sequence_number);
58 if (it != pending_create_map_.end()) {
59 it->second.Run(pending_resource_host_id);
60 pending_create_map_.erase(it);
61 } else {
62 NOTREACHED();
63 }
64 }
65
66 int32_t PepperBrowserConnection::GetNextSequence() {
67 // Return the value with wraparound, making sure we don't make a sequence
68 // number with a 0 ID. Note that signed wraparound is undefined in C++ so we
69 // manually check.
70 int32_t ret = next_sequence_number_;
71 if (next_sequence_number_ == std::numeric_limits<int32_t>::max())
72 next_sequence_number_ = 1; // Skip 0 which is invalid.
73 else
74 next_sequence_number_++;
75 return ret;
76 }
77
78 } // namespace content
OLDNEW
« no previous file with comments | « content/renderer/pepper/pepper_browser_connection.h ('k') | content/renderer/pepper/pepper_plugin_delegate_impl.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698