blob: 89aabe6962c118f67db6a256565a32ffe2941513 [file] [log] [blame]
jat@google.com134be542009-08-03 15:30:11 +00001/*
2 * Copyright 2008 Google Inc.
3 *
4 * Licensed under the Apache License, Version 2.0 (the "License"); you may not
5 * use this file except in compliance with the License. You may obtain a copy of
6 * the License at
7 *
8 * http://www.apache.org/licenses/LICENSE-2.0
9 *
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
12 * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
13 * License for the specific language governing permissions and limitations under
14 * the License.
15 */
16
17#include "Debug.h"
18#include "ExternalWrapper.h"
19
20#include "nsCOMPtr.h"
21#include "nsIGenericFactory.h"
22#include "nsICategoryManager.h"
23#include "nsISupports.h"
24#include "nsIXULAppInfo.h"
jat@google.com268f9982009-11-06 21:34:25 +000025#include "nsIXULRuntime.h"
jat@google.com134be542009-08-03 15:30:11 +000026#include "nsServiceManagerUtils.h"
27#include "nsXPCOMCID.h"
28
jat@google.comd9f13ab2010-06-17 18:57:35 +000029#ifdef GECKO_19
jat@google.com134be542009-08-03 15:30:11 +000030#include "nsIClassInfoImpl.h" // 1.9 only
31#endif
32
jat@google.com268f9982009-11-06 21:34:25 +000033// Allow a macro to be treated as a C string, ie -Dfoo=bar; QUOTE(foo) = "bar"
34#define QUOTE_HELPER(x) #x
35#define QUOTE(x) QUOTE_HELPER(x)
36
jat@google.com134be542009-08-03 15:30:11 +000037#ifdef _WINDOWS
38#include <windows.h>
39
40BOOL APIENTRY DllMain(HMODULE hModule, DWORD ulReasonForCall, LPVOID lpReserved) {
41 switch (ulReasonForCall) {
42 case DLL_PROCESS_ATTACH:
43 case DLL_THREAD_ATTACH:
44 case DLL_THREAD_DETACH:
45 case DLL_PROCESS_DETACH:
46 break;
47 }
48 return TRUE;
49}
50#endif
51
52NS_GENERIC_FACTORY_CONSTRUCTOR(ExternalWrapper)
53NS_DECL_CLASSINFO(ExternalWrapper)
54
55static NS_IMETHODIMP registerSelf(nsIComponentManager *aCompMgr, nsIFile *aPath,
56 const char *aLoaderStr, const char *aType,
57 const nsModuleComponentInfo *aInfo) {
58
jat@google.com23181962009-09-03 22:22:56 +000059 Debug::log(Debug::Info)
jat@google.coma9e207a2009-11-09 14:14:18 +000060 << " successfully registered GWT Developer Plugin"
jat@google.com134be542009-08-03 15:30:11 +000061 << Debug::flush;
62 nsresult rv;
63 nsCOMPtr<nsICategoryManager> categoryManager =
64 do_GetService(NS_CATEGORYMANAGER_CONTRACTID, &rv);
65
66 NS_ENSURE_SUCCESS(rv, rv);
67
68 rv = categoryManager->AddCategoryEntry("JavaScript global property",
69 "__gwt_HostedModePlugin", OOPHM_CONTRACTID, true, true, nsnull);
70
71 if (rv != NS_OK) {
72 Debug::log(Debug::Error) << "ModuleOOPHM registerSelf returned " << rv
73 << Debug::flush;
74 }
75 return rv;
76}
77
78static NS_IMETHODIMP factoryDestructor(void) {
79 Debug::log(Debug::Debugging) << "ModuleOOPHM factoryDestructor()"
80 << Debug::flush;
81 return NS_OK;
82}
83
84static NS_IMETHODIMP unregisterSelf(nsIComponentManager *aCompMgr,
85 nsIFile *aPath, const char *aLoaderStr,
86 const nsModuleComponentInfo *aInfo) {
jat@google.coma9e207a2009-11-09 14:14:18 +000087 Debug::log(Debug::Info) << "Unregistered GWT Developer Plugin"
jat@google.com134be542009-08-03 15:30:11 +000088 << Debug::flush;
89 return NS_OK;
90}
91
92static nsModuleComponentInfo components[] = {
93 {
94 OOPHM_CLASSNAME,
95 OOPHM_CID,
96 OOPHM_CONTRACTID,
97 ExternalWrapperConstructor,
98 registerSelf,
99 unregisterSelf, /* unregister self */
100 factoryDestructor, /* factory destructor */
101 NS_CI_INTERFACE_GETTER_NAME(ExternalWrapper), /* get interfaces */
102 nsnull, /* language helper */
103 &NS_CLASSINFO_NAME(ExternalWrapper), /* global class-info pointer */
104 0 /* class flags */
105 }
106};
107
108// From Gears base/firefox/module.cc
109static nsModuleInfo const kModuleInfo = {
110 NS_MODULEINFO_VERSION,
111 ("ExternalWrapperModule"),
112 (components),
113 (sizeof(components) / sizeof(components[0])),
114 (nsnull),
115 (nsnull)
116};
117
118NSGETMODULE_ENTRY_POINT(ExternalWrapperModule) (nsIComponentManager *servMgr,
119 nsIFile* location, nsIModule** result) {
jat@google.com134be542009-08-03 15:30:11 +0000120 nsresult nr;
jat@google.com268f9982009-11-06 21:34:25 +0000121 nsCOMPtr<nsIXULAppInfo> app_info
122 = do_GetService("@mozilla.org/xre/app-info;1", &nr);
jat@google.com134be542009-08-03 15:30:11 +0000123 if (NS_FAILED(nr) || !app_info) {
124 return NS_ERROR_FAILURE;
125 }
jat@google.com134be542009-08-03 15:30:11 +0000126 nsCString gecko_version;
127 app_info->GetPlatformVersion(gecko_version);
jat@google.com268f9982009-11-06 21:34:25 +0000128 nsCString browser_version;
129 app_info->GetVersion(browser_version);
130 nsCOMPtr<nsIXULRuntime> xulRuntime
131 = do_GetService("@mozilla.org/xre/app-info;1", &nr);
132 if (NS_FAILED(nr) || !app_info) {
jat@google.com134be542009-08-03 15:30:11 +0000133 return NS_ERROR_FAILURE;
134 }
jat@google.com268f9982009-11-06 21:34:25 +0000135 nsCString os;
136 xulRuntime->GetOS(os);
137 nsCString abi;
138 xulRuntime->GetXPCOMABI(abi);
jat@google.coma9e207a2009-11-09 14:14:18 +0000139 Debug::log(Debug::Info) << "Initializing GWT Developer Plugin"
jat@google.com268f9982009-11-06 21:34:25 +0000140 << Debug::flush;
141 Debug::log(Debug::Info) << " gecko=" << gecko_version.BeginReading()
142 << ", firefox=" << browser_version.BeginReading() << ", abi="
143 << os.BeginReading() << "_" << abi.BeginReading() << ", built for "
144 QUOTE(BROWSER) << Debug::flush;
jat@google.com134be542009-08-03 15:30:11 +0000145 return NS_NewGenericModule2(&kModuleInfo, result);
146}