2 * Copyright 2008, Google Inc.
5 * Redistribution and use in source and binary forms, with or without
6 * modification, are permitted provided that the following conditions are
9 * * Redistributions of source code must retain the above copyright
10 * notice, this list of conditions and the following disclaimer.
11 * * Redistributions in binary form must reproduce the above
12 * copyright notice, this list of conditions and the following disclaimer
13 * in the documentation and/or other materials provided with the
15 * * Neither the name of Google Inc. nor the names of its
16 * contributors may be used to endorse or promote products derived from
17 * this software without specific prior written permission.
19 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
20 * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
21 * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
22 * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
23 * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
24 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
25 * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
26 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
27 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
28 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
29 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
36 #include "native_client/tests/npapi_bridge/plugin.h"
38 // Please refer to the Gecko Plugin API Reference for the description of
40 // In the NaCl module, NPP_New is called from NaClNP_MainLoop().
41 NPError
NPP_New(NPMIMEType mime_type
, NPP instance
, uint16_t mode
,
42 int16_t argc
, char* argn
[], char* argv
[],
46 if (instance
== NULL
) {
47 return NPERR_INVALID_INSTANCE_ERROR
;
50 const char* canvas
= "tutorial";
51 for (uint16_t i
= 0; i
< argc
; ++i
) {
52 printf("%u: '%s' '%s'\n", i
, argn
[i
], argv
[i
]);
53 if (strcmp(argn
[i
], "canvas") == 0) {
58 Plugin
* plugin
= new(std::nothrow
) Plugin(instance
, canvas
);
60 return NPERR_OUT_OF_MEMORY_ERROR
;
63 instance
->pdata
= plugin
;
64 return NPERR_NO_ERROR
;
67 // Please refer to the Gecko Plugin API Reference for the description of
69 // In the NaCl module, NPP_Destroy is called from NaClNP_MainLoop().
70 NPError
NPP_Destroy(NPP instance
, NPSavedData
** save
) {
71 printf("NPP_Destroy\n");
73 if (instance
== NULL
) {
74 return NPERR_INVALID_INSTANCE_ERROR
;
77 Plugin
* plugin
= static_cast<Plugin
*>(instance
->pdata
);
81 return NPERR_NO_ERROR
;
84 // NPP_GetScriptableInstance retruns the NPObject pointer that corresponds to
85 // NPPVpluginScriptableNPObject queried by NPP_GetValue() from the browser.
86 NPObject
* NPP_GetScriptableInstance(NPP instance
) {
87 printf("NPP_GetScriptableInstance\n");
89 if (instance
== NULL
) {
93 NPObject
* object
= NULL
;
94 Plugin
* plugin
= static_cast<Plugin
*>(instance
->pdata
);
96 object
= plugin
->GetScriptableObject();
101 NPError
NPP_SetWindow(NPP instance
, NPWindow
* window
) {
102 printf("NPP_SetWindow\n");
103 if (instance
== NULL
) {
104 return NPERR_INVALID_INSTANCE_ERROR
;
106 if (window
== NULL
) {
107 return NPERR_GENERIC_ERROR
;
109 Plugin
* plugin
= static_cast<Plugin
*>(instance
->pdata
);
110 if (plugin
!= NULL
) {
111 return plugin
->SetWindow(window
);
113 return NPERR_GENERIC_ERROR
;