Gnash
0.8.10
|
00001 // 00002 // Copyright (C) 2005, 2006, 2007, 2008, 2009, 2010, 2011, 2012 00003 // Free Software Foundation, Inc 00004 // 00005 // This program is free software; you can redistribute it and/or modify 00006 // it under the terms of the GNU General Public License as published by 00007 // the Free Software Foundation; either version 3 of the License, or 00008 // (at your option) any later version. 00009 // 00010 // This program is distributed in the hope that it will be useful, 00011 // but WITHOUT ANY WARRANTY; without even the implied warranty of 00012 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 00013 // GNU General Public License for more details. 00014 // 00015 // You should have received a copy of the GNU General Public License 00016 // along with this program; if not, write to the Free Software 00017 // Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA 00018 00019 00020 #ifndef GNASH_PLUGIN_H 00021 #define GNASH_PLUGIN_H 00022 00023 #ifdef HAVE_CONFIG_H 00024 #include "gnashconfig.h" 00025 #endif 00026 00027 #ifndef HAVE_FUNCTION 00028 # ifndef HAVE_func 00029 # define dummystr(x) # x 00030 # define dummyestr(x) dummystr(x) 00031 # define __FUNCTION__ __FILE__":"dummyestr(__LINE__) 00032 # else 00033 # define __FUNCTION__ __func__ 00034 # endif 00035 #endif 00036 00037 #ifndef HAVE_PRETTY_FUNCTION 00038 # define __PRETTY_FUNCTION__ __FUNCTION__ 00039 #endif 00040 00041 /* Xlib/Xt stuff */ 00042 #include <X11/Xlib.h> 00043 //#include <X11/Intrinsic.h> 00044 #include <X11/cursorfont.h> 00045 #include <glib.h> 00046 #include <string> 00047 #include <map> 00048 #include <vector> 00049 #include <boost/format.hpp> 00050 #include <boost/preprocessor/arithmetic/inc.hpp> 00051 #include <boost/preprocessor/repetition/enum_params.hpp> 00052 #include <boost/preprocessor/repetition/repeat.hpp> 00053 #include <boost/preprocessor/repetition/repeat_from_to.hpp> 00054 #include <boost/preprocessor/seq/for_each.hpp> 00055 00056 #include "pluginbase.h" 00057 #include "pluginScriptObject.h" 00058 00059 namespace gnash { 00060 00061 extern NPBool plugInitialized; 00062 00063 class nsPluginInstance : public nsPluginInstanceBase 00064 { 00065 public: 00066 nsPluginInstance(nsPluginCreateData* ); 00067 virtual ~nsPluginInstance(); 00068 00069 // We are required to implement these three methods. 00070 NPBool init(NPWindow *aWindow); 00071 NPBool isInitialized() { return plugInitialized; } 00072 void shut(); 00073 00074 NPError GetValue(NPPVariable variable, void *value); 00075 NPError SetWindow(NPWindow *aWindow); 00076 00078 NPError NewStream(NPMIMEType type, NPStream *stream, NPBool seekable, 00079 uint16_t *stype); 00081 NPError DestroyStream(NPStream * stream, NPError reason); 00082 00084 int32_t WriteReady(NPStream *stream); 00085 int32_t Write(NPStream *stream, int32_t offset, int32_t len, void *buffer); 00086 NPObject *getScriptableObject(); 00087 const char *getEmbedURL() const; 00088 00089 GnashPluginScriptObject *getScriptObject() { return _scriptObject; }; // FIXME: debug only!!! 00090 00091 private: 00092 NPError startProc(); 00093 std::vector<std::string> getCmdLine(int hostfd, int controlfd); 00094 00095 void setupCookies(const std::string& pageURL); 00096 void setupProxy(const std::string& pageURL); 00097 00099 std::string getDocumentProp(const std::string& propname) const; 00100 00101 static bool handlePlayerRequestsWrapper(GIOChannel* iochan, GIOCondition cond, nsPluginInstance* plugin); 00102 00103 bool handlePlayerRequests(GIOChannel* iochan, GIOCondition cond); 00104 00110 void setupIOChannel(int fd, GIOFunc handler, GIOCondition signals) const; 00111 00112 00114 // 00117 bool processPlayerRequest(); 00118 00119 // EMBED or OBJECT attributes / parameters 00120 // @@ this should likely replace the _options element below 00121 std::map<std::string, std::string> _params; 00122 00123 NPP _instance; 00124 Window _window; 00125 std::string _swf_url; 00126 std::string _swf_file; 00127 unsigned int _width; 00128 unsigned int _height; 00129 std::map<std::string, std::string> _options; 00134 int _streamfd; 00135 pid_t _childpid; 00136 int _filefd; 00137 00139 std::string _name; 00140 GnashPluginScriptObject *_scriptObject; 00141 00145 // FIXME: should we perhaps use a deque instead? 00146 std::string _requestbuf; 00147 00148 std::string getCurrentPageURL() const; 00149 }; 00150 00151 // Define the following to make the plugin verbose 00152 // WARNING: will write to .xsession_errors ! 00153 // Values: 00154 // 0: no messages at all 00155 // 1: fatal errors (errors preventing the plugin from working as it should) 00156 // 2: informational messages 00157 #define GNASH_PLUGIN_DEBUG 1 00158 00159 // This following logging code is copied from libbase/log.h, but 00160 // duplicated here because the plugin only needs a more trimmed down 00161 // version that doesn't require any Gnash libraires to keep the 00162 // memory footprint down. 00163 DSOEXPORT void processLog_error(const boost::format& fmt); 00164 DSOEXPORT void processLog_debug(const boost::format& fmt); 00165 DSOEXPORT void processLog_trace(const boost::format& fmt); 00166 00169 // 00172 #define TOKENIZE_FORMAT(z, n, t) % t##n 00173 00177 #define TOKENIZE_ARGS(z, n, t) BOOST_PP_COMMA_IF(n) const T##n& t##n 00178 00182 #define LOG_TYPES (error) (debug) (trace) 00183 00184 00185 #define ARG_NUMBER 4 00186 #define LOG_TEMPLATES(z, n, data)\ 00187 template<BOOST_PP_ENUM_PARAMS(BOOST_PP_INC(n), typename T)>\ 00188 inline void log_##data(BOOST_PP_REPEAT(BOOST_PP_INC(n), TOKENIZE_ARGS, t)) \ 00189 {\ 00190 if (GNASH_PLUGIN_DEBUG < 1) return; \ 00191 boost::format f(t0); \ 00192 using namespace boost::io; \ 00193 f.exceptions(all_error_bits ^ (too_many_args_bit | \ 00194 too_few_args_bit | \ 00195 bad_format_string_bit)); \ 00196 processLog_##data(f BOOST_PP_REPEAT_FROM_TO(1, \ 00197 BOOST_PP_INC(n), \ 00198 TOKENIZE_FORMAT, t));\ 00199 } 00200 00204 #define GENERATE_LOG_TYPES(r, _, t) \ 00205 BOOST_PP_REPEAT(ARG_NUMBER, LOG_TEMPLATES, t) 00206 00209 BOOST_PP_SEQ_FOR_EACH(GENERATE_LOG_TYPES, _, LOG_TYPES) 00210 00211 // end of __PLUGIN_H__ 00212 #endif 00213 00214 } // end of gnash namespace 00215 00216 // local Variables: 00217 // mode: C++ 00218 // indent-tabs-mode: nil 00219 // End: