jat@google.com | 134be54 | 2009-08-03 15:30:11 +0000 | [diff] [blame] | 1 | /* |
| 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.com | 268f998 | 2009-11-06 21:34:25 +0000 | [diff] [blame] | 25 | #include "nsIXULRuntime.h" |
jat@google.com | 134be54 | 2009-08-03 15:30:11 +0000 | [diff] [blame] | 26 | #include "nsServiceManagerUtils.h" |
| 27 | #include "nsXPCOMCID.h" |
| 28 | |
jat@google.com | d9f13ab | 2010-06-17 18:57:35 +0000 | [diff] [blame] | 29 | #ifdef GECKO_19 |
jat@google.com | 134be54 | 2009-08-03 15:30:11 +0000 | [diff] [blame] | 30 | #include "nsIClassInfoImpl.h" // 1.9 only |
| 31 | #endif |
| 32 | |
jat@google.com | 268f998 | 2009-11-06 21:34:25 +0000 | [diff] [blame] | 33 | // 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.com | 134be54 | 2009-08-03 15:30:11 +0000 | [diff] [blame] | 37 | #ifdef _WINDOWS |
| 38 | #include <windows.h> |
| 39 | |
| 40 | BOOL 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 | |
| 52 | NS_GENERIC_FACTORY_CONSTRUCTOR(ExternalWrapper) |
| 53 | NS_DECL_CLASSINFO(ExternalWrapper) |
| 54 | |
| 55 | static NS_IMETHODIMP registerSelf(nsIComponentManager *aCompMgr, nsIFile *aPath, |
| 56 | const char *aLoaderStr, const char *aType, |
| 57 | const nsModuleComponentInfo *aInfo) { |
| 58 | |
jat@google.com | 2318196 | 2009-09-03 22:22:56 +0000 | [diff] [blame] | 59 | Debug::log(Debug::Info) |
jat@google.com | a9e207a | 2009-11-09 14:14:18 +0000 | [diff] [blame] | 60 | << " successfully registered GWT Developer Plugin" |
jat@google.com | 134be54 | 2009-08-03 15:30:11 +0000 | [diff] [blame] | 61 | << 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 | |
| 78 | static NS_IMETHODIMP factoryDestructor(void) { |
| 79 | Debug::log(Debug::Debugging) << "ModuleOOPHM factoryDestructor()" |
| 80 | << Debug::flush; |
| 81 | return NS_OK; |
| 82 | } |
| 83 | |
| 84 | static NS_IMETHODIMP unregisterSelf(nsIComponentManager *aCompMgr, |
| 85 | nsIFile *aPath, const char *aLoaderStr, |
| 86 | const nsModuleComponentInfo *aInfo) { |
jat@google.com | a9e207a | 2009-11-09 14:14:18 +0000 | [diff] [blame] | 87 | Debug::log(Debug::Info) << "Unregistered GWT Developer Plugin" |
jat@google.com | 134be54 | 2009-08-03 15:30:11 +0000 | [diff] [blame] | 88 | << Debug::flush; |
| 89 | return NS_OK; |
| 90 | } |
| 91 | |
| 92 | static 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 |
| 109 | static nsModuleInfo const kModuleInfo = { |
| 110 | NS_MODULEINFO_VERSION, |
| 111 | ("ExternalWrapperModule"), |
| 112 | (components), |
| 113 | (sizeof(components) / sizeof(components[0])), |
| 114 | (nsnull), |
| 115 | (nsnull) |
| 116 | }; |
| 117 | |
| 118 | NSGETMODULE_ENTRY_POINT(ExternalWrapperModule) (nsIComponentManager *servMgr, |
| 119 | nsIFile* location, nsIModule** result) { |
jat@google.com | 134be54 | 2009-08-03 15:30:11 +0000 | [diff] [blame] | 120 | nsresult nr; |
jat@google.com | 268f998 | 2009-11-06 21:34:25 +0000 | [diff] [blame] | 121 | nsCOMPtr<nsIXULAppInfo> app_info |
| 122 | = do_GetService("@mozilla.org/xre/app-info;1", &nr); |
jat@google.com | 134be54 | 2009-08-03 15:30:11 +0000 | [diff] [blame] | 123 | if (NS_FAILED(nr) || !app_info) { |
| 124 | return NS_ERROR_FAILURE; |
| 125 | } |
jat@google.com | 134be54 | 2009-08-03 15:30:11 +0000 | [diff] [blame] | 126 | nsCString gecko_version; |
| 127 | app_info->GetPlatformVersion(gecko_version); |
jat@google.com | 268f998 | 2009-11-06 21:34:25 +0000 | [diff] [blame] | 128 | 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.com | 134be54 | 2009-08-03 15:30:11 +0000 | [diff] [blame] | 133 | return NS_ERROR_FAILURE; |
| 134 | } |
jat@google.com | 268f998 | 2009-11-06 21:34:25 +0000 | [diff] [blame] | 135 | nsCString os; |
| 136 | xulRuntime->GetOS(os); |
| 137 | nsCString abi; |
| 138 | xulRuntime->GetXPCOMABI(abi); |
jat@google.com | a9e207a | 2009-11-09 14:14:18 +0000 | [diff] [blame] | 139 | Debug::log(Debug::Info) << "Initializing GWT Developer Plugin" |
jat@google.com | 268f998 | 2009-11-06 21:34:25 +0000 | [diff] [blame] | 140 | << 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.com | 134be54 | 2009-08-03 15:30:11 +0000 | [diff] [blame] | 145 | return NS_NewGenericModule2(&kModuleInfo, result); |
| 146 | } |