FireBreath  1.4.0
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Pages
NpapiPluginX11.cpp
1 /**********************************************************\
2 Original Author: Richard Bateman (taxilian)
3 
4 Created: Dec 3, 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 #include <dlfcn.h>
16 
17 #include "NpapiTypes.h"
18 #include "PluginCore.h"
19 #include "X11/PluginWindowX11.h"
20 #include "FactoryBase.h"
21 
22 #include "X11/NpapiPluginX11.h"
23 #include "NpapiPluginFactory.h"
24 #include <boost/make_shared.hpp>
25 
26 FB::Npapi::NpapiPluginPtr FB::Npapi::createNpapiPlugin(const FB::Npapi::NpapiBrowserHostPtr& host, const std::string& mimetype)
27 {
28  return boost::make_shared<NpapiPluginX11>(host, mimetype);
29 }
30 
31 using namespace FB::Npapi;
32 
33 inline GdkNativeWindow getGdkWindow(void *in)
34 {
35  // This is one of the ugliest hacks known to man; it was neccesary to make 64 bit work.
36  // Don't change it without testing on 32 and 64, and don't ask -- you don't want to know
37  return (char*)in - (char*)0;
38 }
39 
40 namespace
41 {
42  std::string getPluginPath()
43  {
44  ::Dl_info dlinfo;
45  if (::dladdr((void*)::NP_Initialize, &dlinfo) != 0) {
46  return dlinfo.dli_fname;
47  } else {
48  return "";
49  }
50  }
51 }
52 
53 NpapiPluginX11::NpapiPluginX11(const FB::Npapi::NpapiBrowserHostPtr& host, const std::string& mimetype)
54  : NpapiPlugin(host, mimetype), pluginWin(NULL)
55 {
56  PluginCore::setPlatform("X11", "NPAPI");
57 
58  // Get the path to the shared lib
59 
60  static const std::string pluginPath = getPluginPath();
61  setFSPath(pluginPath);
62 }
63 
64 NpapiPluginX11::~NpapiPluginX11()
65 {
66  delete pluginWin;
67  pluginWin = NULL;
68 }
69 
70 NPError NpapiPluginX11::GetValue(NPPVariable variable, void *value)
71 {
72  switch (variable) {
73  /* Tell browser we use XEmbed, this is required for Chrome on Unix */
74  case NPPVpluginNeedsXEmbed:
75  *((bool *)value) = true;
76  return NPERR_NO_ERROR;
77  default:
78  return NpapiPlugin::GetValue(variable, value);
79  }
80 }
81 
82 NPError NpapiPluginX11::SetWindow(NPWindow* window)
83 {
84 #if FB_GUI_DISABLED != 1
85  if (window != NULL && window->window != NULL) {
86  /* Require XEmbed support from browser, see:
87  * https://developer.mozilla.org/en/XEmbed_Extension_for_Mozilla_Plugins
88  */
89  int xembedSupported = 0;
90 
91  m_npHost->GetValue(NPNVSupportsXEmbedBool, &xembedSupported);
92  if (!xembedSupported)
93  {
94  FBLOG_ERROR("FB.NpapiPluginX11", "XEmbed not supported! Cannot create pluginwindow!");
95  return NPERR_GENERIC_ERROR;
96  }
97 
98  if (pluginWin != NULL && pluginWin->getTopLevelWindow() != getGdkWindow(window->window)) {
99  pluginMain->ClearWindow();
100  delete pluginWin;
101  pluginWin = NULL;
102  }
103 
104  if (pluginWin == NULL) {
105  GdkNativeWindow browserWindow;
106  m_npHost->GetValue(NPNVnetscapeWindow, (void*)&browserWindow);
107 
108  pluginWin = getFactoryInstance()->createPluginWindowX11(WindowContextX11(getGdkWindow(window->window)));
109  pluginWin->setBrowserWindow(browserWindow);
110  pluginWin->setWindowPosition(window->x, window->y, window->width, window->height);
111  pluginWin->setWindowClipping(window->clipRect.top, window->clipRect.left,
112  window->clipRect.bottom, window->clipRect.right);
113  pluginMain->SetWindow(pluginWin);
114  } else {
115  pluginWin->setWindowPosition(window->x, window->y, window->width, window->height);
116  pluginWin->setWindowClipping(window->clipRect.top, window->clipRect.left,
117  window->clipRect.bottom, window->clipRect.right);
118  }
119 
120  } else if (pluginWin != NULL) {
121  // If the handle goes to NULL, our window is gone and we need to stop using it
122  pluginMain->ClearWindow();
123  delete pluginWin; pluginWin = NULL;
124  }
125 #endif
126  return NPERR_NO_ERROR;
127 }
128 
129 
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