Merge branch 'master' into release_0_8_9
[gnash.git] / plugin / npapi / plugin.h
blob60e305a1c823ac99e3eb0f6b259eb6091b1c6bdb
1 //
2 // Copyright (C) 2005, 2006, 2007, 2008, 2009, 2010,
3 // 2011 Free Software Foundation, Inc
4 //
5 // This program is free software; you can redistribute it and/or modify
6 // it under the terms of the GNU General Public License as published by
7 // the Free Software Foundation; either version 3 of the License, or
8 // (at your option) any later version.
9 //
10 // This program is distributed in the hope that it will be useful,
11 // but WITHOUT ANY WARRANTY; without even the implied warranty of
12 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 // GNU General Public License for more details.
14 //
15 // You should have received a copy of the GNU General Public License
16 // along with this program; if not, write to the Free Software
17 // Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
20 #ifndef GNASH_PLUGIN_H
21 #define GNASH_PLUGIN_H
23 #ifdef HAVE_CONFIG_H
24 #include "gnashconfig.h"
25 #endif
27 #ifndef HAVE_FUNCTION
28 # ifndef HAVE_func
29 # define dummystr(x) # x
30 # define dummyestr(x) dummystr(x)
31 # define __FUNCTION__ __FILE__":"dummyestr(__LINE__)
32 # else
33 # define __FUNCTION__ __func__
34 # endif
35 #endif
37 #ifndef HAVE_PRETTY_FUNCTION
38 # define __PRETTY_FUNCTION__ __FUNCTION__
39 #endif
41 /* Xlib/Xt stuff */
42 #include <X11/Xlib.h>
43 //#include <X11/Intrinsic.h>
44 #include <X11/cursorfont.h>
45 #include <glib.h>
46 #include <string>
47 #include <map>
48 #include <vector>
49 #include <boost/format.hpp>
50 #include <boost/preprocessor/arithmetic/inc.hpp>
51 #include <boost/preprocessor/repetition/enum_params.hpp>
52 #include <boost/preprocessor/repetition/repeat.hpp>
53 #include <boost/preprocessor/repetition/repeat_from_to.hpp>
54 #include <boost/preprocessor/seq/for_each.hpp>
56 #include "pluginbase.h"
57 #include "pluginScriptObject.h"
59 namespace gnash {
61 extern NPBool plugInitialized;
63 class nsPluginInstance : public nsPluginInstanceBase
65 public:
66 nsPluginInstance(nsPluginCreateData* );
67 virtual ~nsPluginInstance();
69 // We are required to implement these three methods.
70 NPBool init(NPWindow *aWindow);
71 NPBool isInitialized() { return plugInitialized; }
72 void shut();
74 NPError GetValue(NPPVariable variable, void *value);
75 NPError SetWindow(NPWindow *aWindow);
77 /// Open a new stream. THis is called every time there is swf content.
78 NPError NewStream(NPMIMEType type, NPStream *stream, NPBool seekable,
79 uint16_t *stype);
80 /// Destroy the stream
81 NPError DestroyStream(NPStream * stream, NPError reason);
83 /// Can the stream be written to yet ?
84 int32_t WriteReady(NPStream *stream);
85 int32_t Write(NPStream *stream, int32_t offset, int32_t len, void *buffer);
86 NPObject *getScriptableObject();
87 const char *getEmbedURL() const;
89 GnashPluginScriptObject *getScriptObject() { return _scriptObject; }; // FIXME: debug only!!!
91 private:
92 void startProc();
93 std::vector<std::string> getCmdLine(int hostfd, int controlfd);
95 void setupCookies(const std::string& pageURL);
96 void setupProxy(const std::string& pageURL);
98 static bool handlePlayerRequestsWrapper(GIOChannel* iochan, GIOCondition cond, nsPluginInstance* plugin);
100 bool handlePlayerRequests(GIOChannel* iochan, GIOCondition cond);
102 /// Process requests from the player.
104 /// @return true if the requests were processed, false otherwise (bogus request..)
106 bool processPlayerRequest();
108 // EMBED or OBJECT attributes / parameters
109 // @@ this should likely replace the _options element below
110 std::map<std::string, std::string> _params;
112 NPP _instance;
113 Window _window;
114 std::string _swf_url;
115 std::string _swf_file;
116 unsigned int _width;
117 unsigned int _height;
118 std::map<std::string, std::string> _options;
119 int _streamfd;
120 int _ichanWatchId;
121 pid_t _childpid;
122 int _filefd;
124 /// Name of the plugin instance element in the dom
125 std::string _name;
126 GnashPluginScriptObject *_scriptObject;
128 /// Buffer containing incoming requests from the player process received
129 /// over a socket. Since partial requests are likely in a network situation
130 /// this buffer preserves them until they can be finished.
131 // FIXME: should we perhaps use a deque instead?
132 std::string _requestbuf;
134 std::string getCurrentPageURL() const;
137 // Define the following to make the plugin verbose
138 // WARNING: will write to .xsession_errors !
139 // Values:
140 // 0: no messages at all
141 // 1: fatal errors (errors preventing the plugin from working as it should)
142 // 2: informational messages
143 #define GNASH_PLUGIN_DEBUG 1
145 // This following logging code is copied from libbase/log.h, but
146 // duplicated here because the plugin only needs a more trimmed down
147 // version that doesn't require any Gnash libraires to keep the
148 // memory footprint down.
149 DSOEXPORT void processLog_error(const boost::format& fmt);
150 DSOEXPORT void processLog_debug(const boost::format& fmt);
151 DSOEXPORT void processLog_trace(const boost::format& fmt);
153 /// This heap of steaming preprocessor code magically converts
154 /// printf-style statements into boost::format messages using templates.
156 /// Macro to feed boost::format strings to the boost::format object,
157 /// producing code like this: "% t1 % t2 % t3 ..."
158 #define TOKENIZE_FORMAT(z, n, t) % t##n
160 /// Macro to add a number of arguments to the templated function
161 /// corresponding to the number of template arguments. Produces code
162 /// like this: "const T0& t0, const T1& t1, const T2& t2 ..."
163 #define TOKENIZE_ARGS(z, n, t) BOOST_PP_COMMA_IF(n) const T##n& t##n
165 /// This is a sequence of different log message types to be used in
166 /// the code. Append the name to log_ to call the function, e.g.
167 /// log_error, log_unimpl.
168 #define LOG_TYPES (error) (debug) (trace)
169 /// The preprocessor generates templates with 1..ARG_NUMBER
170 /// arguments.
171 #define ARG_NUMBER 4
172 #define LOG_TEMPLATES(z, n, data)\
173 template<BOOST_PP_ENUM_PARAMS(BOOST_PP_INC(n), typename T)>\
174 inline void log_##data(BOOST_PP_REPEAT(BOOST_PP_INC(n), TOKENIZE_ARGS, t)) \
176 if (GNASH_PLUGIN_DEBUG < 1) return; \
177 boost::format f(t0); \
178 using namespace boost::io; \
179 f.exceptions(all_error_bits ^ (too_many_args_bit | \
180 too_few_args_bit | \
181 bad_format_string_bit)); \
182 processLog_##data(f BOOST_PP_REPEAT_FROM_TO(1, \
183 BOOST_PP_INC(n), \
184 TOKENIZE_FORMAT, t));\
187 /// Calls the macro LOG_TEMPLATES an ARG_NUMBER number
188 /// of times, each time adding an extra typename argument to the
189 /// template.
190 #define GENERATE_LOG_TYPES(r, _, t) \
191 BOOST_PP_REPEAT(ARG_NUMBER, LOG_TEMPLATES, t)
193 /// Calls the template generator for each log type in the
194 /// sequence LOG_TYPES.
195 BOOST_PP_SEQ_FOR_EACH(GENERATE_LOG_TYPES, _, LOG_TYPES)
197 // end of __PLUGIN_H__
198 #endif
200 } // end of gnash namespace
202 // local Variables:
203 // mode: C++
204 // indent-tabs-mode: nil
205 // End: