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

Side by Side Diff: tests/translation_service/npp_gate.cc

Issue 3356014: HTTP service that converts *.bc to *.nexe.... (Closed) Base URL: svn://svn.chromium.org/native_client/trunk/src/native_client/
Patch Set: '' Created 10 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
« no previous file with comments | « tests/translation_service/hello_world_nexe.html ('k') | tests/translation_service/server.py » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Property Changes:
Added: svn:eol-style
+ LF
OLDNEW
(Empty)
1 // Copyright 2008 The Native Client 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 #include <stdbool.h>
6 #include <stdio.h>
7 #include <stdlib.h>
8 #include <string.h>
9
10 #include <nacl/nacl_npapi.h>
11 #include <nacl/npupp.h>
12
13 struct HelloWorld {
14 NPP npp;
15 NPObject *npobject;
16 };
17
18 // This file implements functions that the plugin is expected to implement so
19 // that the browser can all them. All of them are required to be implemented
20 // regardless of whether this is a trusted or untrusted build of the module.
21
22
23 // Called after NP_Initialize with a Plugin Instance Pointer and context
24 // information for the plugin instance that is being allocated.
25 // Declaration: npapi.h
26 // Documentation URL: https://developer.mozilla.org/en/NPP_New
27 NPError NPP_New(NPMIMEType mime_type,
28 NPP instance,
29 uint16_t mode,
30 int16_t argc,
31 char* argn[],
32 char* argv[],
33 NPSavedData* saved) {
34 if (instance == NULL)
35 return NPERR_INVALID_INSTANCE_ERROR;
36
37 struct HelloWorld *hello_world = NULL;
38 hello_world = new HelloWorld;
39 hello_world->npp = instance;
40 hello_world->npobject = NULL;
41
42 instance->pdata = hello_world;
43 return NPERR_NO_ERROR;
44 }
45
46 // Called when a Plugin |instance| is being deleted by the browser. This
47 // function should clean up any information allocated by NPP_New but not
48 // NP_Initialize. Use |save| to store any information that should persist but
49 // note that browser may choose to throw it away.
50 // In the NaCl module, NPP_Destroy is called from NaClNP_MainLoop().
51 // Declaration: npapi.h
52 // Documentation URL: https://developer.mozilla.org/en/NPP_Destroy
53 NPError NPP_Destroy(NPP instance, NPSavedData** save) {
54 if (NULL == instance)
55 return NPERR_INVALID_INSTANCE_ERROR;
56
57 // free plugin
58 if (NULL != instance->pdata) {
59 HelloWorld* hello_world = static_cast<HelloWorld*>(instance->pdata);
60 delete hello_world;
61 instance->pdata = NULL;
62 }
63 return NPERR_NO_ERROR;
64 }
65
66 // NPP_GetScriptableInstance returns the NPObject pointer that corresponds to
67 // NPPVpluginScriptableNPObject queried by NPP_GetValue() from the browser.
68 // Helper function for NPP_GetValue to create this plugin's NPObject.
69 // |instance| is this plugin's representation in the browser. Returns the new
70 // NPObject or NULL.
71 // Declaration: local
72 // Documentation URL: N/A (not actually an NPAPI function)
73 NPObject *NPP_GetScriptableInstance(NPP instance) {
74 struct HelloWorld* hello_world;
75
76 NPClass *GetNPSimpleClass();
77
78 if (NULL == instance) {
79 return NULL;
80 }
81 hello_world = static_cast<HelloWorld*>(instance->pdata);
82 if (NULL == hello_world->npobject) {
83 hello_world->npobject = NPN_CreateObject(instance, GetNPSimpleClass());
84 }
85 if (NULL != hello_world->npobject) {
86 NPN_RetainObject(hello_world->npobject);
87 }
88 return hello_world->npobject;
89 }
90
91 // Implemented so the browser can get a scriptable instance from this plugin.
92 // Declaration: npapi.h
93 // Documentation URL: https://developer.mozilla.org/en/NPP_GetValue
94 NPError NPP_GetValue(NPP instance, NPPVariable variable, void* ret_value) {
95 if (NPPVpluginScriptableNPObject == variable) {
96 void** v = reinterpret_cast<void**>(ret_value);
97 *v = NPP_GetScriptableInstance(instance);
98 return NPERR_NO_ERROR;
99 } else {
100 return NPERR_GENERIC_ERROR;
101 }
102 }
103
104 // |window| contains the current state of the window in the browser. If this
105 // is called, that state has probably changed recently.
106 // Declaration: npapi.h
107 // Documentation URL: https://developer.mozilla.org/en/NPP_SetWindow
108 NPError NPP_SetWindow(NPP instance, NPWindow* window) {
109 return NPERR_NO_ERROR;
110 }
111
112 extern "C" {
113 // When the browser calls NP_Initialize the plugin needs to return a list
114 // of functions that have been implemented so that the browser can
115 // communicate with the plugin. This function populates that list,
116 // |plugin_funcs|, with pointers to the functions.
117 NPError InitializePluginFunctions(NPPluginFuncs* plugin_funcs) {
118 memset(plugin_funcs, 0, sizeof(*plugin_funcs));
119 plugin_funcs->version = NPVERS_HAS_PLUGIN_THREAD_ASYNC_CALL;
120 plugin_funcs->size = sizeof(*plugin_funcs);
121 plugin_funcs->newp = NPP_New;
122 plugin_funcs->destroy = NPP_Destroy;
123 plugin_funcs->setwindow = NPP_SetWindow;
124 plugin_funcs->getvalue = NPP_GetValue;
125 return NPERR_NO_ERROR;
126 }
127 } // extern "C"
OLDNEW
« no previous file with comments | « tests/translation_service/hello_world_nexe.html ('k') | tests/translation_service/server.py » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698