Load 57 into trunk.
[nativeclient.git] / npapi_plugin / srpc / plugin.h
blob894ad907b2ee124f48b7dfa1ffcb2b17de3fe362
1 /*
2 * Copyright 2008, Google Inc.
3 * All rights reserved.
4 *
5 * Redistribution and use in source and binary forms, with or without
6 * modification, are permitted provided that the following conditions are
7 * met:
8 *
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
14 * distribution.
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 #ifndef NATIVE_CLIENT_NPAPI_PLUGIN_SRPC_PLUGIN_H_
34 #define NATIVE_CLIENT_NPAPI_PLUGIN_SRPC_PLUGIN_H_
36 #include <stdio.h>
37 #include <string>
38 #include "native_client/tools/npapi_runtime/nacl_npapi.h"
39 #include "native_client/npapi_plugin/srpc/utility.h"
40 #include "native_client/service_runtime/nrd_xfer_lib/nrd_all_modules.h"
41 #include "native_client/service_runtime/nrd_xfer_lib/nrd_xfer.h"
42 #include "native_client/service_runtime/nrd_xfer_lib/nrd_xfer_effector.h"
44 // An incomplete class for method declarations.
45 namespace nacl {
46 class SRPC_Plugin;
49 // An incomplete class for the client runtime.
50 namespace nacl_srpc {
52 // Incomplete classes for method declarations.
53 class ConnectedSocket;
54 class ServiceRuntimeInterface;
55 class SharedMemory;
56 class UnknownHandle;
58 // The main plugin class.
59 class Plugin : public NPObject {
60 public:
61 static Plugin* New(NPP instance, nacl::SRPC_Plugin* srpc_plugin);
62 NPP npp() { return npp_; }
63 const char* local_url() { return local_url_; }
64 nacl::SRPC_Plugin* srpc_plugin() { return srpc_plugin_; }
65 void set_local_url(const char*);
67 // Load from the local URL saved in local_url_.
68 bool Load();
70 // Get/SetProperty is public
71 static bool GetProperty(NPObject* obj, NPIdentifier name,
72 NPVariant* variant);
73 static bool SetProperty(NPObject* obj, NPIdentifier name,
74 const NPVariant* variant);
76 // Origin of page with the embed tag that created this plugin instance.
77 std::string origin() { return origin_; }
79 // Initialize some plugin data.
80 bool Start();
82 // Constructor and destructor (for derived class)
83 explicit Plugin(NPP);
84 ~Plugin();
86 private:
87 // Method invocation.
88 static bool HasMethod(NPObject* obj, NPIdentifier name);
89 static bool Invoke(NPObject* obj, NPIdentifier name, const NPVariant* args,
90 uint32_t arg_count, NPVariant *result);
91 static bool InvokeDefault(NPObject* obj, const NPVariant* args,
92 uint32_t arg_count, NPVariant* result);
94 // Property accessor/mutators.
95 static bool HasProperty(NPObject* obj, NPIdentifier name);
97 // Allocation and deallocation.
98 static NPObject* Allocate(NPP npp, NPClass* theClass);
99 static void Deallocate(NPObject* obj);
100 static void Invalidate(NPObject* obj);
102 // Catch bad accesses during loading.
103 static void SignalHandler(int value);
105 public:
106 // Not really constants. Do not modify. Use only after at least
107 // one Plugin instance has been constructed.
108 static NPIdentifier kConnectIdent;
109 static NPIdentifier kHeightIdent;
110 static NPIdentifier kLengthIdent;
111 static NPIdentifier kMapIdent;
112 static NPIdentifier kOnfailIdent;
113 static NPIdentifier kOnloadIdent;
114 static NPIdentifier kModuleReadyIdent;
115 static NPIdentifier kNullNpapiMethodIdent;
116 static NPIdentifier kReadIdent;
117 static NPIdentifier kShmFactoryIdent;
118 static NPIdentifier kSignaturesIdent;
119 static NPIdentifier kSrcIdent;
120 static NPIdentifier kToStringIdent;
121 static NPIdentifier kUrlAsNaClDescIdent;
122 static NPIdentifier kValueOfIdent;
123 static NPIdentifier kVideoUpdateModeIdent;
124 static NPIdentifier kWidthIdent;
125 static NPIdentifier kWriteIdent;
127 static NPIdentifier kLocationIdent;
128 static NPIdentifier kHrefIdent;
130 private:
131 NPP npp_;
133 nacl::SRPC_Plugin* srpc_plugin_;
134 ConnectedSocket* socket_;
135 ServiceRuntimeInterface* service_runtime_interface_;
136 char* local_url_;
137 int32_t height_;
138 int32_t video_update_mode_;
139 int32_t width_;
141 std::string origin_;
142 bool origin_valid_;
144 public:
145 struct NaClDescEffector* effp_;
146 struct NaClNrdXferEffector eff_;
148 static PLUGIN_JMPBUF loader_env;
150 static bool identifiers_initialized;
153 } // namespace nacl_srpc
155 #endif // NATIVE_CLIENT_NPAPI_PLUGIN_SRPC_PLUGIN_H_