Gnash  0.8.11dev
npapi/plugin.h
Go to the documentation of this file.
1 //
2 // Copyright (C) 2005, 2006, 2007, 2008, 2009, 2010, 2011, 2012
3 // 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
18 
19 
20 #ifndef GNASH_PLUGIN_H
21 #define GNASH_PLUGIN_H
22 
23 #ifdef HAVE_CONFIG_H
24 #include "gnashconfig.h"
25 #endif
26 
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
36 
37 #ifndef HAVE_PRETTY_FUNCTION
38 # define __PRETTY_FUNCTION__ __FUNCTION__
39 #endif
40 
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>
55 
56 #include "pluginbase.h"
57 #include "pluginScriptObject.h"
58 
59 namespace gnash {
60 
61 extern NPBool plugInitialized;
62 
63 class nsPluginInstance : public nsPluginInstanceBase
64 {
65 public:
66  nsPluginInstance(nsPluginCreateData* );
67  virtual ~nsPluginInstance();
68 
69  // We are required to implement these three methods.
70  NPBool init(NPWindow *aWindow);
71  NPBool isInitialized() { return plugInitialized; }
72  void shut();
73 
74  NPError GetValue(NPPVariable variable, void *value);
75  NPError SetWindow(NPWindow *aWindow);
76 
78  NPError NewStream(NPMIMEType type, NPStream *stream, NPBool seekable,
79  uint16_t *stype);
81  NPError DestroyStream(NPStream * stream, NPError reason);
82 
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;
88 
89  GnashPluginScriptObject *getScriptObject() { return _scriptObject; }; // FIXME: debug only!!!
90 
91 private:
92  NPError startProc();
93  std::vector<std::string> getCmdLine(int hostfd, int controlfd);
94 
95  void setupCookies(const std::string& pageURL);
96  void setupProxy(const std::string& pageURL);
97 
99  std::string getDocumentProp(const std::string& propname) const;
100 
101  static bool handlePlayerRequestsWrapper(GIOChannel* iochan, GIOCondition cond, nsPluginInstance* plugin);
102 
103  bool handlePlayerRequests(GIOChannel* iochan, GIOCondition cond);
104 
110  void setupIOChannel(int fd, GIOFunc handler, GIOCondition signals);
111 
112 
114  //
117  bool processPlayerRequest();
118 
119  // EMBED or OBJECT attributes / parameters
120  // @@ this should likely replace the _options element below
121  std::map<std::string, std::string> _params;
122 
123  NPP _instance;
124  Window _window;
125  std::string _swf_url;
126  std::string _swf_file;
127  unsigned int _width;
128  unsigned int _height;
129  std::map<std::string, std::string> _options;
134  int _streamfd;
135  pid_t _childpid;
136  int _filefd;
137 
139  std::string _name;
140  GnashPluginScriptObject *_scriptObject;
141 
145  // FIXME: should we perhaps use a deque instead?
146  std::string _requestbuf;
147 
148  std::string getCurrentPageURL() const;
149 };
150 
151 // Define the following to make the plugin verbose
152 // WARNING: will write to .xsession_errors !
153 // Values:
154 // 0: no messages at all
155 // 1: fatal errors (errors preventing the plugin from working as it should)
156 // 2: informational messages
157 #define GNASH_PLUGIN_DEBUG 1
158 
159 // This following logging code is copied from libbase/log.h, but
160 // duplicated here because the plugin only needs a more trimmed down
161 // version that doesn't require any Gnash libraires to keep the
162 // memory footprint down.
163 DSOEXPORT void processLog_error(const boost::format& fmt);
164 DSOEXPORT void processLog_debug(const boost::format& fmt);
165 DSOEXPORT void processLog_trace(const boost::format& fmt);
166 
169 //
172 #define TOKENIZE_FORMAT(z, n, t) % t##n
173 
177 #define TOKENIZE_ARGS(z, n, t) BOOST_PP_COMMA_IF(n) const T##n& t##n
178 
182 #define LOG_TYPES (error) (debug) (trace)
183 #define ARG_NUMBER 4
186 #define LOG_TEMPLATES(z, n, data)\
187 template<BOOST_PP_ENUM_PARAMS(BOOST_PP_INC(n), typename T)>\
188 inline void log_##data(BOOST_PP_REPEAT(BOOST_PP_INC(n), TOKENIZE_ARGS, t)) \
189 {\
190  if (GNASH_PLUGIN_DEBUG < 1) return; \
191  boost::format f(t0); \
192  using namespace boost::io; \
193  f.exceptions(all_error_bits ^ (too_many_args_bit | \
194  too_few_args_bit | \
195  bad_format_string_bit)); \
196  processLog_##data(f BOOST_PP_REPEAT_FROM_TO(1, \
197  BOOST_PP_INC(n), \
198  TOKENIZE_FORMAT, t));\
199 }
200 
204 #define GENERATE_LOG_TYPES(r, _, t) \
205  BOOST_PP_REPEAT(ARG_NUMBER, LOG_TEMPLATES, t)
206 
209 BOOST_PP_SEQ_FOR_EACH(GENERATE_LOG_TYPES, _, LOG_TYPES)
210 
211 // end of __PLUGIN_H__
212 #endif
213 
214 } // end of gnash namespace
215 
216 // local Variables:
217 // mode: C++
218 // indent-tabs-mode: nil
219 // End:
void shut()
Shutdown an instantiated object.
Definition: npapi/plugin.cpp:575
const char * getEmbedURL() const
#define LOG_TYPES
Definition: npapi/plugin.h:182
NPBool plugInitialized
Definition: npapi/plugin.cpp:126
int32_t Write(NPStream *stream, int32_t offset, int32_t len, void *buffer)
Read the data stream from Mozilla/Firefox.
Definition: npapi/plugin.cpp:709
NPBool isInitialized()
Definition: npapi/plugin.h:71
Anonymous namespace for callbacks, local functions, event handlers etc.
Definition: dbus_ext.cpp:40
type
Definition: GnashKey.h:329
Definition: npapi/plugin.h:63
Definition: pluginScriptObject.h:57
#define GENERATE_LOG_TYPES(r, _, t)
Definition: npapi/plugin.h:204
GnashPluginScriptObject * getScriptObject()
Definition: npapi/plugin.h:89
void processLog_trace(const boost::format &fmt)
Definition: log.cpp:119
#define _(String)
Definition: log.h:44
NPObject * getScriptableObject()
NPError SetWindow(NPWindow *aWindow)
Set the window to be used to render in.
Definition: npapi/plugin.cpp:596
void processLog_error(const boost::format &fmt)
Definition: log.cpp:176
#define DSOEXPORT
Definition: dsodefs.h:55
int32_t WriteReady(NPStream *stream)
Can the stream be written to yet ?
Definition: npapi/plugin.cpp:696
NPError GetValue(NPPVariable variable, void *value)
Definition: npapi/plugin.cpp:630
virtual ~nsPluginInstance()
Destructor.
Definition: npapi/plugin.cpp:495
void processLog_debug(const boost::format &fmt)
Definition: log.cpp:130
NPError NewStream(NPMIMEType type, NPStream *stream, NPBool seekable, uint16_t *stype)
Open a new stream. THis is called every time there is swf content.
Definition: npapi/plugin.cpp:658
NPBool init(NPWindow *aWindow)
Initialize an instance of the plugin object.
Definition: npapi/plugin.cpp:550
NPError DestroyStream(NPStream *stream, NPError reason)
Destroy the stream.
Definition: npapi/plugin.cpp:681
nsPluginInstance(nsPluginCreateData *)
Constructor.
Definition: npapi/plugin.cpp:430