FireBreath  1.4.0
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Pages
PluginCore.h
1 /**********************************************************\
2 Original Author: Richard Bateman (taxilian)
3 
4 Created: Oct 19, 2009
5 License: Dual license model; choose one of two:
6  New BSD License
7  http://www.opensource.org/licenses/bsd-license.php
8  - or -
9  GNU Lesser General Public License, version 2.1
10  http://www.gnu.org/licenses/lgpl-2.1.html
11 
12 Copyright 2009 PacketPass, Inc and the Firebreath development team
13 \**********************************************************/
14 
15 #pragma once
16 #ifndef H_FB_PLUGINCORE
17 #define H_FB_PLUGINCORE
18 
19 #include "PluginEventSink.h"
20 #include "BrowserStream.h"
21 #include "BrowserPlugin.h"
22 #include "APITypes.h"
23 #include <string>
24 #include <set>
25 #include <boost/assign.hpp>
26 #include <boost/logic/tribool.hpp>
27 
28 using boost::assign::list_of;
29 
30 namespace FB {
31 
32  class PluginWindow;
33  class PluginEvent;
34  class BrowserStreamRequest;
35  FB_FORWARD_PTR(PluginCore);
36  FB_FORWARD_PTR(JSAPI);
37  FB_FORWARD_PTR(BrowserHost);
38 
54  class PluginCore : public PluginEventSink
55  {
56  public:
57  static int getActivePluginCount() { return ActivePluginCount; }
58  static std::string& getOS() { return OS; }
59  static std::string& getBrowser() { return Browser; }
60  private:
61  static volatile int ActivePluginCount;
62 
63  static std::string OS;
64  static std::string Browser;
65 
66  public:
77  static void setPlatform(const std::string& os, const std::string& browser);
78 
79  public:
80 
114  PluginCore();
115 
121  virtual ~PluginCore();
122 
131  virtual void SetHost(const FB::BrowserHostPtr& host)
132  {
133  m_host = host;
134  }
135 
143  virtual PluginWindow* GetWindow() const
144  {
145  return m_Window;
146  }
147 
157  virtual void setScriptingOnly(const bool so = true)
158  {
159  m_scriptingOnly = so;
160  }
161 
170  virtual bool isScriptingOnly() const { return m_scriptingOnly; }
171 
180  virtual void SetWindow(PluginWindow *win);
181 
188  virtual void ClearWindow();
189 
197  virtual bool setReady();
198 
210  virtual void onPluginReady() {};
222  virtual void shutdown() {};
223 
224  protected:
225 
237  virtual JSAPIPtr createJSAPI() = 0;
238 
239  public:
253  void releaseRootJSAPI() { m_api.reset(); }
264  {
265  if (!m_api) {
266  m_api = createJSAPI();
267  }
268 
269  return m_api;
270  }
271 
283  virtual bool isWindowless();
284 
293  virtual std::string negotiateDrawingModel();
294 
305  virtual void setFSPath(const std::string& path) { m_filesystemPath = path; }
306 
317  static std::string getFSPath() { return BrowserPlugin::getFSPath(); }
318 
331 
332  virtual void setParams(const FB::VariantMap& inParams);
333 
334  virtual boost::optional<std::string> getParam(const std::string& key);
335  virtual FB::variant getParamVariant(const std::string& key);
336 
349 
350  public:
351  virtual BrowserHostPtr getHost() { return m_host; }
352  protected:
356  std::string m_filesystemPath;
358  bool m_paramsSet;
362  private:
364  PluginWindow *m_Window;
366  JSAPIPtr m_api;
367  boost::tribool m_windowLessParam;
368  bool m_scriptingOnly;
369  };
370 };
371 
372 #endif
373 
virtual JSAPIPtr getRootJSAPI()
Gets the root JSAPI object. It is not recommended to call this from the constructor or before setHost...
Definition: PluginCore.h:263
bool m_paramsSet
Boolean value indicates if the browser has called setParams() yet or not.
Definition: PluginCore.h:358
virtual ~PluginCore()
Finaliser.
Definition: PluginCore.cpp:56
virtual bool isScriptingOnly() const
Returns true if there is no DOM element associated with the plugin.
Definition: PluginCore.h:170
virtual std::string negotiateDrawingModel()
Called at plugin creation to query the plugin's preferred drawing model.
Definition: PluginCore.cpp:169
virtual void shutdown()
This is called when the plugin needs to shut down to give it a chance to stop all threads; the destru...
Definition: PluginCore.h:222
Accepts any datatype, used in all interactions with javascript. Provides tools for getting back out t...
Definition: variant.h:198
FB::VariantMap m_params
Definition: PluginCore.h:361
BrowserHostPtr m_host
The BrowserHost object for the current session; deprecated, use getHost()
Definition: PluginCore.h:354
virtual PluginWindow * GetWindow() const
Gets the PluginWindow instance currently provided by the browser, or NULL if none.
Definition: PluginCore.h:143
virtual void handleUnsolicitedStream(BrowserStreamRequest &req)
Called by the browser to handle an unsolicited BrowserStream.
Definition: PluginCore.h:348
Information about an HTTP request to be made.
virtual void setScriptingOnly(const bool so=true)
Called by the browser to indicate that there is no DOM element associated with this object...
Definition: PluginCore.h:157
boost::shared_ptr< FB::JSAPI > JSAPIPtr
Defines an alias for a JSAPI shared_ptr (you should never use a JSAPI* directly)
Definition: APITypes.h:94
static std::string getFSPath()
Returns the path and filename of the current plugin module.
Definition: PluginCore.h:317
virtual void onPluginReady()
This is called when the plugin is ready.
Definition: PluginCore.h:210
virtual JSAPIPtr createJSAPI()=0
Called the first time something calls getRootJSAPI() to get the Root JSAPI instance.
Definition: PluginCore.h:222
virtual void SetHost(const FB::BrowserHostPtr &host)
Called by the browser during startup to provide a Browser Host object.
Definition: PluginCore.h:131
virtual bool setReady()
Called by the browser to indicate that the basic initialization is complete and the plugin is now rea...
Definition: PluginCore.cpp:111
Base class for all FireBreath Plugins.
Definition: PluginCore.h:54
virtual bool isWindowless()
Called by the browser to query if this plugin should be windowless.
Definition: PluginCore.cpp:133
PluginCore()
Default Constructor.
Definition: PluginCore.cpp:47
boost::shared_ptr< FB::BrowserHost > BrowserHostPtr
Defines an alias representing a BrowserHost shared_ptr (you should never use a BrowserHost* directly)...
Definition: APITypes.h:117
virtual void SetWindow(PluginWindow *win)
Called by the browser to set the window. The default implementation fires the WindowAttached event in...
Definition: PluginCore.cpp:150
PluginWindow is the base class for all PluginWindow objects.
Definition: PluginWindow.h:33
static void setPlatform(const std::string &os, const std::string &browser)
Called by the browser when the Operating System and Browser are known.
Definition: PluginCore.cpp:36
Plugin event sink; all objects that can receive PluginEvent s should inherit from this class...
virtual void ClearWindow()
Called by the browser to indicate that the window is no longer valid. The default implementation fire...
Definition: PluginCore.cpp:160
void releaseRootJSAPI()
Releases the root JSAPI object.
Definition: PluginCore.h:253
std::map< std::string, variant > VariantMap
Defines an alias representing a string -> variant map.
Definition: APITypes.h:72
virtual void setParams(const FB::VariantMap &inParams)
Called by the browser to store the values provided in param tags in m_params.
Definition: PluginCore.cpp:68
virtual void setFSPath(const std::string &path)
Called by the browser to set the file system path of the plugin module.
Definition: PluginCore.h:305
std::string m_filesystemPath
Stores the value passed into setFSPath(); deprecated, use getFSPath()
Definition: PluginCore.h:356