Page tree
Skip to end of metadata
Go to start of metadata

FireBreathWin.cpp
1 /**********************************************************\
2 Original Author: Richard Bateman (taxilian)
3 
4 Created: Sept 17, 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 Richard Bateman, Firebreath development team
13 \**********************************************************/
14 
15 // FireBreathWin.cpp : Implementation of DLL Exports.
16 
17 #include "win_common.h"
18 #include "global/resource.h"
19 #include "global/config.h"
20 #include "FireBreathWin_i.h"
21 #include "axmain.h"
22 #include "FBControl.h"
23 #include "axutil.h"
24 #include "PluginCore.h"
25 #include <boost/algorithm/string.hpp>
26 #include "precompiled_headers.h" // On windows, everything above this line in PCH
27 
28 #include <Psapi.h>
29 
30 using FB::ActiveX::isStaticInitialized;
31 using FB::ActiveX::flagStaticInitialized;
32 using FB::ActiveX::FbPerUserRegistration;
33 
34 // Used to determine whether the DLL can be unloaded by OLE
35 STDAPI DllCanUnloadNow(void)
36 {
37  HRESULT hr = _AtlModule.DllCanUnloadNow();
38  if ((hr == S_OK || !FB::PluginCore::getActivePluginCount()) && isStaticInitialized()) {
39  // We had to change this so that if this function gets called (a sure sign that the browser
40  // would like to unload the DLL) and there are no active plugins it will call Deinitialize
41  // because some systems it never returned S_OK :-( Would love to know why and fix it correctly...
42  getFactoryInstance()->globalPluginDeinitialize();
43  FB::Log::stopLogging();
44  flagStaticInitialized(false);
45  }
46  return hr;
47 }
48 
49 
50 // Returns a class factory to create an object of the requested type
51 STDAPI DllGetClassObject(REFCLSID rclsid, REFIID riid, LPVOID* ppv)
52 {
53  HRESULT hr = _AtlModule.DllGetClassObject(rclsid, riid, ppv);
54  if (SUCCEEDED(hr) && !isStaticInitialized()) {
55  FB::Log::initLogging();
56  FB::PluginCore::setPlatform("Windows", "IE");
57  getFactoryInstance()->globalPluginInitialize();
58  flagStaticInitialized(true);
59  }
60  return hr;
61 }
62 
63 std::string getProcessName()
64 {
65  TCHAR szModName[MAX_PATH];
66  DWORD count;
67  HMODULE hm[1];
68  HANDLE proc = ::GetCurrentProcess();
69  BOOL success = ::EnumProcessModules(proc, hm, sizeof(HMODULE), &count);
70  if (::GetModuleFileNameW(hm[0], szModName, sizeof(szModName) / sizeof(TCHAR))) {
71  std::wstring fname(szModName);
72  return FB::wstring_to_utf8(fname);
73  } else {
74  return "";
75  }
76 }
77 
78 extern HINSTANCE gInstance;
79 // DllRegisterServer - Adds entries to the system registry
80 STDAPI DllRegisterServer(void)
81 {
82  //Sleep(10000);
83  boost::scoped_ptr<FbPerUserRegistration> regHolder;
84 #ifndef FB_ATLREG_MACHINEWIDE
85  if (!boost::algorithm::ends_with(getProcessName(), "heat.exe")) {
86  regHolder.swap(boost::scoped_ptr<FbPerUserRegistration>(new FbPerUserRegistration(true)));
87  }
88 #endif
89  HRESULT hr = _AtlModule.DllRegisterServer();
90 
91  if (!SUCCEEDED(hr))
92  hr = getFactoryInstance()->UpdateWindowsRegistry(true);
93  return hr;
94 }
95 
96 
97 // DllUnregisterServer - Removes entries from the system registry
98 STDAPI DllUnregisterServer(void)
99 {
100  boost::scoped_ptr<FbPerUserRegistration> regHolder;
101 #ifndef FB_ATLREG_MACHINEWIDE
102  if (!boost::algorithm::ends_with(getProcessName(), "heat.exe")) {
103  regHolder.swap(boost::scoped_ptr<FbPerUserRegistration>(new FbPerUserRegistration(true)));
104  }
105 #endif
106  HRESULT hr = _AtlModule.DllUnregisterServer();
107  if (!SUCCEEDED(hr))
108  hr = getFactoryInstance()->UpdateWindowsRegistry(false);
109  return hr;
110 }
111 
112 // DllInstall - Adds/Removes entries to the system registry per user
113 // per machine.
114 STDAPI DllInstall(BOOL bInstall, LPCWSTR pszCmdLine)
115 {
116  HRESULT hr = E_FAIL;
117  static const wchar_t szUserSwitch[] = _T("user");
118  bool doPerUserRegistration = false;
119 
120  if (pszCmdLine != NULL)
121  {
122  if (_wcsnicmp(pszCmdLine, szUserSwitch, _countof(szUserSwitch)) == 0)
123  {
124  doPerUserRegistration = true;
125  }
126  }
127 
128  FbPerUserRegistration perUser(doPerUserRegistration);
129 
130  if (bInstall)
131  {
132  hr = DllRegisterServer();
133  if (FAILED(hr))
134  {
135  DllUnregisterServer();
136  }
137  }
138  else
139  {
140  hr = DllUnregisterServer();
141  }
142 
143  return hr;
144 }
145 
std::string wstring_to_utf8(const std::wstring &src)
Accepts a std::wstring and returns a UTF8-encoded std::string.
Definition: utf8_tools.cpp:37
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
  • No labels