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

Side by Side Diff: ppapi/native_client/src/shared/ppapi_proxy/browser_ppp_instance.cc

Issue 7740013: Cloning a bunch of stuff from the native_client repository at r6528 (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src/
Patch Set: Created 9 years, 3 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 Native Client 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 "native_client/src/shared/ppapi_proxy/browser_ppp_instance.h"
6
7 #include <stdio.h>
8 #include <string.h>
9 #include <limits>
10
11 #include "native_client/src/include/checked_cast.h"
12 #include "native_client/src/include/nacl_scoped_ptr.h"
13 #include "native_client/src/include/portability.h"
14 #include "native_client/src/shared/ppapi_proxy/browser_globals.h"
15 #include "native_client/src/shared/ppapi_proxy/browser_ppp.h"
16 #include "native_client/src/shared/ppapi_proxy/trusted/srpcgen/ppp_rpc.h"
17 #include "native_client/src/shared/ppapi_proxy/utility.h"
18 #include "ppapi/c/pp_resource.h"
19 #include "ppapi/c/pp_var.h"
20 #include "ppapi/c/ppp_instance.h"
21
22 using nacl::scoped_array;
23
24 namespace ppapi_proxy {
25
26 namespace {
27
28 char* ArgArraySerialize(int argc,
29 const char* array[],
30 uint32_t* serial_size) {
31 uint32_t used = 0;
32 for (int i = 0; i < argc; ++i) {
33 // Note that strlen() cannot ever return SIZE_T_MAX, since that would imply
34 // that there were no nulls anywhere in memory, which would lead to
35 // strlen() never terminating. So this assignment is safe.
36 size_t len = strlen(array[i]) + 1;
37 if (len > std::numeric_limits<uint32_t>::max()) {
38 // Overflow, input string is too long.
39 return NULL;
40 }
41 if (used > std::numeric_limits<uint32_t>::max() - len) {
42 // Overflow, output string is too long.
43 return NULL;
44 }
45 used += static_cast<uint32_t>(len);
46 }
47 // Note that there is a check against numeric_limits<uint32_t> in the code
48 // above, which is why this cast is safe.
49 *serial_size = used;
50 char* serial_array = new char[used];
51
52 size_t pos = 0;
53 for (int i = 0; i < argc; ++i) {
54 size_t len = strlen(array[i]) + 1;
55 strncpy(serial_array + pos, array[i], len);
56 pos += len;
57 }
58 return serial_array;
59 }
60
61 PP_Bool DidCreate(PP_Instance instance,
62 uint32_t argc,
63 const char* argn[],
64 const char* argv[]) {
65 DebugPrintf("PPP_Instance::DidCreate: instance=%"NACL_PRIu32"\n", instance);
66 uint32_t argn_size;
67 scoped_array<char> argn_serial(ArgArraySerialize(argc, argn, &argn_size));
68 if (argn_serial.get() == NULL) {
69 return PP_FALSE;
70 }
71 uint32_t argv_size;
72 scoped_array<char> argv_serial(ArgArraySerialize(argc, argv, &argv_size));
73 if (argv_serial.get() == NULL) {
74 return PP_FALSE;
75 }
76 int32_t int_argc = static_cast<int32_t>(argc);
77 int32_t success;
78 NaClSrpcError srpc_result =
79 PppInstanceRpcClient::PPP_Instance_DidCreate(GetMainSrpcChannel(instance),
80 instance,
81 int_argc,
82 argn_size,
83 argn_serial.get(),
84 argv_size,
85 argv_serial.get(),
86 &success);
87 DebugPrintf("PPP_Instance::DidCreate: %s\n",
88 NaClSrpcErrorString(srpc_result));
89 if (srpc_result != NACL_SRPC_RESULT_OK) {
90 return PP_FALSE;
91 }
92 return static_cast<PP_Bool>(success != 0);
93 }
94
95 void DidDestroy(PP_Instance instance) {
96 DebugPrintf("PPP_Instance::DidDestroy: instance=%"NACL_PRIu32"\n", instance);
97 NaClSrpcError srpc_result = PppInstanceRpcClient::PPP_Instance_DidDestroy(
98 GetMainSrpcChannel(instance), instance);
99 DebugPrintf("PPP_Instance::DidDestroy: %s\n",
100 NaClSrpcErrorString(srpc_result));
101 }
102
103 void DidChangeView(PP_Instance instance,
104 const PP_Rect* position,
105 const PP_Rect* clip) {
106 DebugPrintf("PPP_Instance::DidChangeView: instance=%"NACL_PRIu32"\n",
107 instance);
108 int32_t position_array[4];
109 const uint32_t kPositionArraySize = NACL_ARRAY_SIZE(position_array);
110 position_array[0] = position->point.x;
111 position_array[1] = position->point.y;
112 position_array[2] = position->size.width;
113 position_array[3] = position->size.height;
114 int32_t clip_array[4];
115 const uint32_t kClipArraySize = NACL_ARRAY_SIZE(clip_array);
116 clip_array[0] = clip->point.x;
117 clip_array[1] = clip->point.y;
118 clip_array[2] = clip->size.width;
119 clip_array[3] = clip->size.height;
120 NaClSrpcError srpc_result = PppInstanceRpcClient::PPP_Instance_DidChangeView(
121 GetMainSrpcChannel(instance),
122 instance,
123 kPositionArraySize,
124 position_array,
125 kClipArraySize,
126 clip_array);
127 DebugPrintf("PPP_Instance::DidChangeView: %s\n",
128 NaClSrpcErrorString(srpc_result));
129 }
130
131 void DidChangeFocus(PP_Instance instance, PP_Bool has_focus) {
132 DebugPrintf("PPP_Instance::DidChangeFocus: instance=%"NACL_PRIu32", "
133 "has_focus = %d\n", instance, has_focus);
134 NaClSrpcError srpc_result = PppInstanceRpcClient::PPP_Instance_DidChangeFocus(
135 GetMainSrpcChannel(instance),
136 instance,
137 static_cast<bool>(PP_TRUE == has_focus));
138 DebugPrintf("PPP_Instance::DidChangeFocus: %s\n",
139 NaClSrpcErrorString(srpc_result));
140 }
141
142 PP_Bool HandleDocumentLoad(PP_Instance instance, PP_Resource url_loader) {
143 DebugPrintf("PPP_Instance::HandleDocumentLoad: instance=%"NACL_PRIu32", "
144 "url_loader=%"NACL_PRIu32"\n", instance, url_loader);
145
146 int32_t result = 0;
147 NaClSrpcError srpc_result =
148 PppInstanceRpcClient::PPP_Instance_HandleDocumentLoad(
149 GetMainSrpcChannel(instance),
150 instance,
151 url_loader,
152 &result);
153
154 DebugPrintf("PPP_Instance::HandleDocumentLoad: %s\n",
155 NaClSrpcErrorString(srpc_result));
156 if (srpc_result == NACL_SRPC_RESULT_OK && result)
157 return PP_TRUE;
158 return PP_FALSE;
159 }
160
161 } // namespace
162
163 const PPP_Instance* BrowserInstance::GetInterface() {
164 static const PPP_Instance instance_interface = {
165 DidCreate,
166 DidDestroy,
167 DidChangeView,
168 DidChangeFocus,
169 HandleDocumentLoad
170 };
171 return &instance_interface;
172 }
173
174 } // namespace ppapi_proxy
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698