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

Side by Side Diff: examples/srpc/duality/npp_gate.cc

Issue 2856050: Adding srpc example to naclports. (Closed) Base URL: http://naclports.googlecode.com/svn/trunk/src/
Patch Set: '' Created 10 years, 5 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
« no previous file with comments | « examples/srpc/duality/nacl_build.mk ('k') | examples/srpc/duality/scriptable.h » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
(Empty)
1 // Copyright 2008 The Native Client SDK Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can
3 // be found in the LICENSE file.
4
5
6 #include <stdbool.h>
7 #include <stdio.h>
8 #include <stdlib.h>
9 #include <string.h>
10
11 #include <nacl/nacl_npapi.h>
12 #include <nacl/npupp.h>
13
14 #include <examples/srpc/duality/duality.h>
15 #include <examples/srpc/duality/scripting_bridge.h>
16
17 struct NaClContext {
18 NPP npp;
19 NPObject *npobject;
20 };
21
22 // This file implements functions that the plugin is expected to implement so
23 // that the browser can call them.
24
25
26 // Called after NP_Initialize with a Plugin Instance Pointer and context
27 // information for the plugin instance that is being allocated.
28 // Declaration: npapi.h
29 // Documentation URL: https://developer.mozilla.org/en/NPP_New
30 NPError NPP_New(NPMIMEType mime_type,
31 NPP instance,
32 uint16_t mode,
33 int16_t argc,
34 char* argn[],
35 char* argv[],
36 NPSavedData* saved) {
37 printf("Duality: NPP_New was called!\n");
38 fflush(stdout);
39 if (instance == NULL)
40 return NPERR_INVALID_INSTANCE_ERROR;
41
42 struct NaClContext *nacl_context = NULL;
43 nacl_context = new NaClContext;
44 nacl_context->npp = instance;
45 nacl_context->npobject = NULL;
46
47 instance->pdata = nacl_context;
48 return NPERR_NO_ERROR;
49 }
50
51
52 // Called when a Plugin |instance| is being deleted by the browser. This
53 // function should clean up any information allocated by NPP_New but not
54 // NP_Initialize. Use |save| to store any information that should persist but
55 // note that browser may choose to throw it away.
56 // In the NaCl module, NPP_Destroy is called from NaClNP_MainLoop().
57 // Declaration: npapi.h
58 // Documentation URL: https://developer.mozilla.org/en/NPP_Destroy
59 NPError NPP_Destroy(NPP instance, NPSavedData** save) {
60 printf("Duality: NPP_Destroy was called!\n");
61 fflush(stdout);
62 if (NULL == instance)
63 return NPERR_INVALID_INSTANCE_ERROR;
64
65 // Free plugin.
66 if (NULL != instance->pdata) {
67 NaClContext* nacl_context = static_cast<NaClContext*>(instance->pdata);
68 if (NULL != nacl_context->npobject) {
69 NPN_ReleaseObject(nacl_context->npobject);
70 nacl_context->npobject = NULL;
71 }
72 delete nacl_context;
73 instance->pdata = NULL;
74 }
75 return NPERR_NO_ERROR;
76 }
77
78 // NPP_GetScriptableInstance returns the NPObject pointer that corresponds to
79 // NPPVpluginScriptableNPObject queried by NPP_GetValue() from the browser.
80 // |instance| is this plugin's representation in the browser. Returns the new
81 // NPObject or NULL.
82 // Declaration: local
83 // Documentation URL: N/A (not actually an NPAPI function)
84 NPObject *NPP_GetScriptableInstance(NPP instance) {
85 printf("Duality: NPP_GetScriptableInstance was called!\n");
86 fflush(stdout);
87 struct NaClContext* nacl_context;
88
89 if (NULL == instance) {
90 return NULL;
91 }
92 nacl_context = static_cast<NaClContext*>(instance->pdata);
93 if (NULL == nacl_context->npobject) {
94 nacl_context->npobject =
95 NPN_CreateObject(instance,
96 ScriptingBridge::GetNPSimpleClass<Duality>());
97 }
98 if (NULL != nacl_context->npobject) {
99 NPN_RetainObject(nacl_context->npobject);
100 }
101 return nacl_context->npobject;
102 }
103
104 // Implemented so the browser can get a scriptable instance from this plugin.
105 // Declaration: npapi.h
106 // Documentation URL: https://developer.mozilla.org/en/NPP_GetValue
107 NPError NPP_GetValue(NPP instance, NPPVariable variable, void* ret_value) {
108 printf("Duality: NPP_GetValue was called!\n");
109 fflush(stdout);
110 if (NPPVpluginScriptableNPObject == variable) {
111 void** v = reinterpret_cast<void**>(ret_value);
112 *v = NPP_GetScriptableInstance(instance);
113 return NPERR_NO_ERROR;
114 } else {
115 return NPERR_GENERIC_ERROR;
116 }
117 }
118
119 // |event| just took place in this plugin's window in the browser. This
120 // function should return true if the event was handled, false if it was
121 // ignored.
122 // Declaration: npapi.h
123 // Documentation URL: https://developer.mozilla.org/en/NPP_HandleEvent
124 int16_t NPP_HandleEvent(NPP instance, void* event) {
125 printf("Duality: NPP_HandleEvent was called!\n");
126 fflush(stdout);
127 return 0;
128 }
129
130
131 // |window| contains the current state of the window in the browser. If this
132 // is called, that state has probably changed recently.
133 // Declaration: npapi.h
134 // Documentation URL: https://developer.mozilla.org/en/NPP_SetWindow
135 NPError NPP_SetWindow(NPP instance, NPWindow* window) {
136 printf("Duality: NPP_SetWindow was called!\n");
137 fflush(stdout);
138 return NPERR_NO_ERROR;
139 }
140
141 extern "C" {
142 // When the browser calls NP_Initialize the plugin needs to return a list
143 // of functions that have been implemented so that the browser can
144 // communicate with the plugin. This function populates that list,
145 // |plugin_funcs|, with pointers to the functions.
146 NPError InitializePluginFunctions(NPPluginFuncs* plugin_funcs) {
147 printf("Duality: InitializePluginFunctions was called!\n");
148 fflush(stdout);
149 memset(plugin_funcs, 0, sizeof(*plugin_funcs));
150 plugin_funcs->version = NPVERS_HAS_PLUGIN_THREAD_ASYNC_CALL;
151 plugin_funcs->size = sizeof(*plugin_funcs);
152 plugin_funcs->newp = NPP_New;
153 plugin_funcs->destroy = NPP_Destroy;
154 plugin_funcs->setwindow = NPP_SetWindow;
155 plugin_funcs->event = NPP_HandleEvent;
156 plugin_funcs->getvalue = NPP_GetValue;
157 return NPERR_GENERIC_ERROR;
158 // return NPERR_NO_ERROR;
159 }
160 } // extern "C"
OLDNEW
« no previous file with comments | « examples/srpc/duality/nacl_build.mk ('k') | examples/srpc/duality/scriptable.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698