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.
33 // NaCl-NPAPI Interface
35 #ifndef NATIVE_CLIENT_NPAPI_PLUGIN_NPAPI_BRIDGE_NPMODULE_H_
36 #define NATIVE_CLIENT_NPAPI_PLUGIN_NPAPI_BRIDGE_NPMODULE_H_
44 #if NACL_LINUX && defined(MOZ_X11)
46 #include <X11/Intrinsic.h>
47 #endif // NACL_LINUX && defined(MOZ_X11)
51 #include "native_client/intermodule_comm/nacl_imc.h"
52 #include "native_client/nonnacl_util/sel_ldr_launcher.h"
53 #include "native_client/npapi_plugin/npinstance.h"
54 #include "native_client/tools/npapi_runtime/nacl_npapi.h"
55 #include "native_client/tools/npapi_runtime/npbridge.h"
56 #include "native_client/tools/npapi_runtime/nprpc.h"
60 // Represents the plugin end of the connection to the NaCl module. The opposite
61 // end is the NPNavigator.
62 class NPModule
: public NPBridge
, public NPInstance
{
63 // The child process that executes the NaCl module program.
64 SelLdrLauncher
* subprocess_
;
65 // The child process handle.
68 // The proxy NPObject that represents the plugin's scriptable object.
69 NPObjectProxy
* proxy_
;
71 // The URL origin of the HTML page that started this module.
74 // The name of the file currently being loaded by NPN_GetURLNotify().
76 // The URL currently being loaded by NPN_GetURLNotify().
78 // The file handle of the file currently being loaded by NPN_GetURLNotify().
81 // The number of arguments to pass to the child process.
83 // The array of arguments to pass to the child process.
84 char const* argv_
[kMaxArg
];
86 // The thread that monitors the NPAPI runtime behavior.
88 HANDLE monitor_thread_
;
90 pthread_t monitor_thread_
;
91 bool monitor_thread_started_
;
92 // TODO: investigate a cleaner solution than this.
95 // The NPWindow of this plugin instance.
97 // The shared memory object handle that keeps the window content rendered by
99 HtpHandle bitmap_shm_
;
100 // The start address of bitmap_shm_ mapped in the browser's address space.
102 // The size of bitmap_shm_.
107 // The original window procedure for the NPWindow.
108 WNDPROC original_window_procedure_
;
109 // The window procedure that intercepts messages sent to the NPWindow.
110 static LRESULT CALLBACK
WindowProcedure(HWND
, UINT
, WPARAM
, LPARAM
);
112 #if NACL_LINUX && defined(MOZ_X11)
113 // The event handler that processes events sent to the NPWindow.
114 static void EventHandler(Widget widget
, NPModule
* module
,
115 XEvent
* xevent
, Boolean
* b
);
118 // Redraws the NPWindow with bitmap_data_.
122 // Creates a new instance of NPModule. All parameters should be unmodified
123 // variables from NPP_New().
124 explicit NPModule(NPP npp
, int argc
, char* argn
[], char* argv
[]);
127 const char* GetApplicationName() const {
131 return subprocess_
->GetApplicationName();
134 Handle
child() const {
138 const char* filename() const {
141 void set_filename(const char* filename
) {
142 if (filename_
!= NULL
) {
148 filename_
= _strdup(filename
);
150 filename_
= strdup(filename
);
151 #endif // NACL_WINDOWS
155 const char* url() const {
158 void set_url(const char* url
) {
168 #endif // NACL_WINDOWS
173 bool monitor_thread_started() {
174 return monitor_thread_started_
;
176 void set_monitor_thread_started(bool mon_thread_started
) {
177 monitor_thread_started_
= mon_thread_started
;
179 #endif // !NACL_WINDOWS
181 // Spawns a child process that executes the binary specified by
182 // application_name. Start returns the child process handle.
183 Handle
Start(const char* application_name
);
185 // Dispatches the received request message.
186 virtual int Dispatch(RpcHeader
* request
, int length
);
188 // Processes NPN_GetValue() request from the child process.
189 int GetValue(RpcHeader
* request
, int length
, NPNVariable variable
);
190 // Processes NPN_Status() request from the child process.
191 int SetStatus(RpcHeader
* request
, int length
);
192 // Processes NPN_InvalidateRect() request from the child process.
193 int InvalidateRect(RpcHeader
* request
, int length
);
194 // Processes NPN_ForceRedraw() request from the child process.
195 int ForceRedraw(RpcHeader
* request
, int length
);
196 // Processes NaClNPN_CreateArray() request from the child process.
197 int CreateArray(RpcHeader
* request
, int length
);
198 // Processes NaClNPN_OpenURL() request from the child process.
199 int OpenURL(RpcHeader
* request
, int length
);
201 // Invokes NPP_New() in the child process.
205 // NPInstance methods
208 // Processes NPP_Destroy() invocation from the browser.
209 NPError
Destroy(NPSavedData
** save
);
210 // Processes NPP_SetWindow() invocation from the browser.
211 NPError
SetWindow(NPWindow
* window
);
212 // Processes NPP_GetValue() invocation from the browser.
213 NPError
GetValue(NPPVariable variable
, void *value
);
214 // Processes NPP_HandleEvent() invocation from the browser.
215 int16_t HandleEvent(void* event
);
216 // Processes NPP_GetScriptableInstance() invocation from the browser.
217 NPObject
* GetScriptableInstance();
218 // Processes NPP_NewStream() invocation from the browser.
219 NPError
NewStream(NPMIMEType type
,
220 NPStream
* stream
, NPBool seekable
,
222 // Processes NPP_StreamAsFile() invocation from the browser.
223 void StreamAsFile(NPStream
* stream
, const char* filename
);
224 // Processes NPP_DestroyStream() invocation from the browser.
225 NPError
DestroyStream(NPStream
*stream
, NPError reason
);
226 // Processes NPP_URLNotify() invocation from the browser.
227 void URLNotify(const char* url
, NPReason reason
, void* notify_data
);
229 // The timeout value in seconds to pop up a message box to terminate the
230 // non-responding child process.
231 static const int kTimeout
= 5;
232 // sel_ldr instances initially communicate with the browser over channel 5.
233 // After the requisite connects/accepts have been done, this channel is
235 static const int kStartupChannel
= 5;
240 #endif // NATIVE_CLIENT_NPAPI_PLUGIN_NPAPI_BRIDGE_NPMODULE_H_