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 a null-terminated request line
105 /// The single request.
106 /// Caller is responsible for memory management, but give us
107 /// permission to modify the string.
110 /// Lenght of buffer.
112 /// @return true if the request was processed, false otherwise (bogus request..)
114 bool processPlayerRequest(gchar
* buf
, gsize len
);
116 // EMBED or OBJECT attributes / parameters
117 // @@ this should likely replace the _options element below
118 std::map
<std::string
, std::string
> _params
;
122 std::string _swf_url
;
123 std::string _swf_file
;
125 unsigned int _height
;
126 std::map
<std::string
, std::string
> _options
;
134 /// Name of the plugin instance element in the dom
136 GnashPluginScriptObject
*_scriptObject
;
138 std::string
getCurrentPageURL() const;
141 // Define the following to make the plugin verbose
142 // WARNING: will write to .xsession_errors !
144 // 0: no messages at all
145 // 1: fatal errors (errors preventing the plugin from working as it should)
146 // 2: informational messages
147 #define GNASH_PLUGIN_DEBUG 1
149 // This following logging code is copied from libbase/log.h, but
150 // duplicated here because the plugin only needs a more trimmed down
151 // version that doesn't require any Gnash libraires to keep the
152 // memory footprint down.
153 DSOEXPORT
void processLog_error(const boost::format
& fmt
);
154 DSOEXPORT
void processLog_debug(const boost::format
& fmt
);
155 DSOEXPORT
void processLog_trace(const boost::format
& fmt
);
157 /// This heap of steaming preprocessor code magically converts
158 /// printf-style statements into boost::format messages using templates.
160 /// Macro to feed boost::format strings to the boost::format object,
161 /// producing code like this: "% t1 % t2 % t3 ..."
162 #define TOKENIZE_FORMAT(z, n, t) % t##n
164 /// Macro to add a number of arguments to the templated function
165 /// corresponding to the number of template arguments. Produces code
166 /// like this: "const T0& t0, const T1& t1, const T2& t2 ..."
167 #define TOKENIZE_ARGS(z, n, t) BOOST_PP_COMMA_IF(n) const T##n& t##n
169 /// This is a sequence of different log message types to be used in
170 /// the code. Append the name to log_ to call the function, e.g.
171 /// log_error, log_unimpl.
172 #define LOG_TYPES (error) (debug) (trace)
173 /// The preprocessor generates templates with 1..ARG_NUMBER
176 #define LOG_TEMPLATES(z, n, data)\
177 template<BOOST_PP_ENUM_PARAMS(BOOST_PP_INC(n), typename T)>\
178 inline void log_##data(BOOST_PP_REPEAT(BOOST_PP_INC(n), TOKENIZE_ARGS, t)) \
180 if (GNASH_PLUGIN_DEBUG < 1) return; \
181 boost::format f(t0); \
182 using namespace boost::io; \
183 f.exceptions(all_error_bits ^ (too_many_args_bit | \
185 bad_format_string_bit)); \
186 processLog_##data(f BOOST_PP_REPEAT_FROM_TO(1, \
188 TOKENIZE_FORMAT, t));\
191 /// Calls the macro LOG_TEMPLATES an ARG_NUMBER number
192 /// of times, each time adding an extra typename argument to the
194 #define GENERATE_LOG_TYPES(r, _, t) \
195 BOOST_PP_REPEAT(ARG_NUMBER, LOG_TEMPLATES, t)
197 /// Calls the template generator for each log type in the
198 /// sequence LOG_TYPES.
199 BOOST_PP_SEQ_FOR_EACH(GENERATE_LOG_TYPES
, _
, LOG_TYPES
)
201 // end of __PLUGIN_H__
204 } // end of gnash namespace
208 // indent-tabs-mode: nil