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_TOOLS_NPAPI_RUNTIME_NPNAVIGATOR_H_
36 #define NATIVE_CLIENT_TOOLS_NPAPI_RUNTIME_NPNAVIGATOR_H_
41 #include "native_client/tools/npapi_runtime/npbridge.h"
45 // Represents the NaCl module end of the connection to the browser plugin. The
46 // opposite end is the NPModule.
47 class NPNavigator
: public NPBridge
{
48 // Compares two strings in string_set_.
49 struct StringCompare
{
50 bool operator()(const NPUTF8
* left
, const NPUTF8
* right
) const {
51 return (strcmp(left
, right
) < 0) ? true : false;
55 // The number of argument passed from the plugin.
57 // The array of arguments passed from the plugin.
60 // The set of character strings for NPIdentifier names.
61 std::set
<const NPUTF8
*, StringCompare
> string_set_
;
63 // The following three member variables save the user parameters passed to
66 // The callback function to be called upon a successful OpenURL() invocation.
67 void (*notify_
)(const char* url
, void* notify_data
, HtpHandle handle
);
68 // The user supplied pointer to the user data.
73 // The NPWindow for this NaCl module.
75 // The shared memory object handle received from the plugin into which the
76 // window content is rendered.
77 HtpHandle bitmap_shm_
;
80 // Creates a new instance of NPNavigator. argc and argv should be unmodified
81 // variables from NaClNP_Init(). npp must be a pointer to an NPP_t structure
82 // to be used for the NaCl module.
83 NPNavigator(NPP npp
, int* argc
, char* argv
[]);
86 // Dispatches the received request message.
87 virtual int Dispatch(RpcHeader
* request
, int length
);
89 // Processes NPP_New() request from the plugin.
90 int New(RpcHeader
* request
, int length
);
91 // Processes NPP_Destroy() request from the plugin.
92 int Destroy(RpcHeader
* request
, int length
);
93 // Processes NPP_GetScriptableInstance() request from the plugin.
94 int GetPluginScriptableObject(RpcHeader
* request
, int length
);
95 // Processes NPP_URLNotify() request from the plugin.
96 int URLNotify(RpcHeader
* request
, int length
);
98 // Sends NPN_Status() request to the plugin.
99 void SetStatus(const char* message
);
100 // Sends NPN_GetValue() request to the plugin.
101 NPError
GetValue(nacl::RpcType
, void* value
);
102 // Sends NaClNPN_CreateArray() request to the plugin.
103 NPObject
* CreateArray();
104 // Sends NaClNPN_OpenURL() request to the plugin.
105 NPError
OpenURL(const char* url
, void* notify_data
,
106 void (*notify
)(const char* url
, void* notify_data
,
108 // Sends NPN_InvalidateRect() request to the plugin.
109 void InvalidateRect(NPRect
* invalid_rect
);
110 // Sends NPN_ForceRedraw() request to the plugin.
113 // Gets the character string from string_set_ that matches the specified name.
114 const NPUTF8
* GetStringIdentifier(const NPUTF8
* name
);
116 // Returns true if name is a string NPIdentifier.
117 // Note NPN_IdentifierIsString() inside the browser cannot be used to detect
118 // string identifiers being transferred from the NaCl module over the IMC
120 static bool IdentifierIsString(NPIdentifier name
) {
121 return (reinterpret_cast<intptr_t>(name
) & 1) ? false : true;
127 nacl::NPNavigator
* NaClNP_GetNavigator();
129 #endif // NATIVE_CLIENT_TOOLS_NPAPI_RUNTIME_NPNAVIGATOR_H_