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

Side by Side Diff: ppapi/native_client/tests/ppapi_messaging/ppapi_messaging.c

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, 4 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 /*
2 * Copyright (c) 2011 The Native Client Authors. All rights reserved.
3 * Use of this source code is governed by a BSD-style license that can be
4 * found in the LICENSE file.
5 */
6
7 #include <stdio.h>
8 #include <string.h>
9
10 #include "native_client/src/include/portability.h"
11 #include "native_client/src/shared/platform/nacl_check.h"
12 #include "ppapi/c/pp_completion_callback.h"
13 #include "ppapi/c/pp_errors.h"
14 #include "ppapi/c/pp_module.h"
15 #include "ppapi/c/pp_var.h"
16 #include "ppapi/c/ppb.h"
17 #include "ppapi/c/ppb_core.h"
18 #include "ppapi/c/ppb_instance.h"
19 #include "ppapi/c/ppb_messaging.h"
20 #include "ppapi/c/ppb_var.h"
21 #include "ppapi/c/ppp.h"
22 #include "ppapi/c/ppp_instance.h"
23 #include "ppapi/c/ppp_messaging.h"
24
25 /* Global variables */
26 PPB_GetInterface get_browser_interface_func = NULL;
27 PP_Instance instance = 0;
28 PP_Module module = 0;
29
30 struct MessageInfo {
31 PP_Instance instance;
32 struct PP_Var message;
33 };
34
35 static struct PPB_Var* GetPPB_Var() {
36 return (struct PPB_Var*)(*get_browser_interface_func)(PPB_VAR_INTERFACE);
37 }
38
39 static void SendOnMessageEventCallback(void* data, int32_t result) {
40 struct MessageInfo* message_to_send = (struct MessageInfo*)data;
41 struct PPB_Messaging* ppb_messaging =
42 (struct PPB_Messaging*)(*get_browser_interface_func)(
43 PPB_MESSAGING_INTERFACE);
44
45 UNREFERENCED_PARAMETER(result);
46 CHECK(ppb_messaging);
47
48 ppb_messaging->PostMessage(message_to_send->instance,
49 message_to_send->message);
50
51 /* Since the message we're sending originally was sent from the browser,
52 * and subequently copied, if sending a string message we need to
53 * dereference it.
54 */
55 if (message_to_send->message.type == PP_VARTYPE_STRING) {
56 struct PPB_Var* ppb_var = GetPPB_Var();
57 ppb_var->Release(message_to_send->message);
58 }
59 free(message_to_send);
60 }
61
62 /* TODO(dspringer): We need to add a test that calls PostMessage directly from
63 * HandleMessage to ensure that this is all asynchronous.
64 */
65 void HandleMessage(PP_Instance instance, struct PP_Var message) {
66 struct PPB_Core* ppb_core =
67 (struct PPB_Core*)(*get_browser_interface_func)(PPB_CORE_INTERFACE);
68 struct MessageInfo* message_to_send = malloc(sizeof(struct MessageInfo));
69 message_to_send->instance = instance;
70 message_to_send->message = message;
71
72 if (message.type == PP_VARTYPE_STRING) {
73 struct PPB_Var* ppb_var = GetPPB_Var();
74 /* If the message is a string, add reference to go with the copy we did
75 * above.
76 */
77 ppb_var->AddRef(message);
78 }
79 /* Echo message back to browser */
80 ppb_core->CallOnMainThread(
81 0, /* I don't care about delay */
82 PP_MakeCompletionCallback(SendOnMessageEventCallback, message_to_send),
83 PP_OK); /* Dummy value for result */
84 }
85
86 PP_Bool DidCreate(PP_Instance instance,
87 uint32_t argc,
88 const char** argn,
89 const char** argv) {
90 UNREFERENCED_PARAMETER(instance);
91 UNREFERENCED_PARAMETER(argc);
92 UNREFERENCED_PARAMETER(argn);
93 UNREFERENCED_PARAMETER(argv);
94 return PP_TRUE;
95 }
96
97 void DidDestroy(PP_Instance instance) {
98 UNREFERENCED_PARAMETER(instance);
99 }
100
101 void DidChangeView(PP_Instance instance,
102 const struct PP_Rect* position,
103 const struct PP_Rect* clip) {
104 UNREFERENCED_PARAMETER(instance);
105 UNREFERENCED_PARAMETER(position);
106 UNREFERENCED_PARAMETER(clip);
107 }
108
109 void DidChangeFocus(PP_Instance instance,
110 PP_Bool has_focus) {
111 UNREFERENCED_PARAMETER(instance);
112 UNREFERENCED_PARAMETER(has_focus);
113 }
114
115 static PP_Bool HandleDocumentLoad(PP_Instance instance,
116 PP_Resource url_loader) {
117 UNREFERENCED_PARAMETER(instance);
118 UNREFERENCED_PARAMETER(url_loader);
119 return PP_TRUE;
120 }
121
122 /* Implementations of the PPP entry points expected by the browser. */
123 PP_EXPORT int32_t PPP_InitializeModule(PP_Module module_id,
124 PPB_GetInterface get_browser_interface) {
125 module = module_id;
126 get_browser_interface_func = get_browser_interface;
127 return PP_OK;
128 }
129
130 PP_EXPORT void PPP_ShutdownModule() {
131 }
132
133 PP_EXPORT const void* PPP_GetInterface(const char* interface_name) {
134 if (0 == strncmp(PPP_INSTANCE_INTERFACE, interface_name,
135 strlen(PPP_INSTANCE_INTERFACE))) {
136 static struct PPP_Instance instance_interface = {
137 DidCreate,
138 DidDestroy,
139 DidChangeView,
140 DidChangeFocus,
141 HandleDocumentLoad
142 };
143 return &instance_interface;
144 } else if (0 == strncmp(PPP_MESSAGING_INTERFACE, interface_name,
145 strlen(PPP_MESSAGING_INTERFACE))) {
146 static struct PPP_Messaging messaging_interface = {
147 HandleMessage
148 };
149 return &messaging_interface;
150 }
151 return NULL;
152 }
OLDNEW
« no previous file with comments | « ppapi/native_client/tests/ppapi_messaging/nacl.scons ('k') | ppapi/native_client/tests/ppapi_messaging/ppapi_messaging.html » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698