2 // Copyright (C) 2005, 2006, 2007, 2008, 2009, 2010,
3 // 2011 Free Software Foundation, Inc
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.
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.
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
24 #include "gnashconfig.h"
29 # define dummystr(x) # x
30 # define dummyestr(x) dummystr(x)
31 # define __FUNCTION__ __FILE__":"dummyestr(__LINE__)
33 # define __FUNCTION__ __func__
37 #ifndef HAVE_PRETTY_FUNCTION
38 # define __PRETTY_FUNCTION__ __FUNCTION__
43 //#include <X11/Intrinsic.h>
44 #include <X11/cursorfont.h>
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"
61 extern NPBool plugInitialized
;
63 class nsPluginInstance
: public nsPluginInstanceBase
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
; }
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
,
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!!!
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
;
114 std::string _swf_url
;
115 std::string _swf_file
;
117 unsigned int _height
;
118 std::map
<std::string
, std::string
> _options
;
124 /// Name of the plugin instance element in the dom
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 !
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
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 | \
181 bad_format_string_bit)); \
182 processLog_##data(f BOOST_PP_REPEAT_FROM_TO(1, \
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
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__
200 } // end of gnash namespace
204 // indent-tabs-mode: nil