Wed, 31 Dec 2014 06:09:35 +0100
Cloned upstream origin tor-browser at tor-browser-31.3.0esr-4.5-1-build1
revision ID fc1c9ff7c1b2defdbc039f12214767608f46423f for hacking purpose.
michael@0 | 1 | /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */ |
michael@0 | 2 | /* vim:expandtab:shiftwidth=4:tabstop=4: |
michael@0 | 3 | */ |
michael@0 | 4 | /* This Source Code Form is subject to the terms of the Mozilla Public |
michael@0 | 5 | * License, v. 2.0. If a copy of the MPL was not distributed with this |
michael@0 | 6 | * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ |
michael@0 | 7 | |
michael@0 | 8 | #include "mozilla/ModuleUtils.h" |
michael@0 | 9 | #include "NativeKeyBindings.h" |
michael@0 | 10 | #include "nsWidgetsCID.h" |
michael@0 | 11 | #include "nsAppShell.h" |
michael@0 | 12 | #include "nsAppShellSingleton.h" |
michael@0 | 13 | #include "nsBaseWidget.h" |
michael@0 | 14 | #include "nsLookAndFeel.h" |
michael@0 | 15 | #include "nsWindow.h" |
michael@0 | 16 | #include "nsTransferable.h" |
michael@0 | 17 | #include "nsHTMLFormatConverter.h" |
michael@0 | 18 | #ifdef MOZ_X11 |
michael@0 | 19 | #include "nsClipboardHelper.h" |
michael@0 | 20 | #include "nsClipboard.h" |
michael@0 | 21 | #include "nsDragService.h" |
michael@0 | 22 | #endif |
michael@0 | 23 | #include "nsColorPicker.h" |
michael@0 | 24 | #include "nsFilePicker.h" |
michael@0 | 25 | #include "nsSound.h" |
michael@0 | 26 | #include "nsBidiKeyboard.h" |
michael@0 | 27 | #include "nsScreenManagerGtk.h" |
michael@0 | 28 | #include "nsGTKToolkit.h" |
michael@0 | 29 | |
michael@0 | 30 | #ifdef NS_PRINTING |
michael@0 | 31 | #include "nsPrintOptionsGTK.h" |
michael@0 | 32 | #include "nsPrintSession.h" |
michael@0 | 33 | #include "nsDeviceContextSpecG.h" |
michael@0 | 34 | #endif |
michael@0 | 35 | |
michael@0 | 36 | #include "mozilla/Preferences.h" |
michael@0 | 37 | |
michael@0 | 38 | #include "nsImageToPixbuf.h" |
michael@0 | 39 | #include "nsPrintDialogGTK.h" |
michael@0 | 40 | |
michael@0 | 41 | #if defined(MOZ_X11) |
michael@0 | 42 | #include "nsIdleServiceGTK.h" |
michael@0 | 43 | #include "GfxInfoX11.h" |
michael@0 | 44 | #endif |
michael@0 | 45 | |
michael@0 | 46 | #include "nsNativeThemeGTK.h" |
michael@0 | 47 | |
michael@0 | 48 | #include "nsIComponentRegistrar.h" |
michael@0 | 49 | #include "nsComponentManagerUtils.h" |
michael@0 | 50 | #include "nsAutoPtr.h" |
michael@0 | 51 | #include "mozilla/gfx/2D.h" |
michael@0 | 52 | #include <gtk/gtk.h> |
michael@0 | 53 | |
michael@0 | 54 | using namespace mozilla; |
michael@0 | 55 | using namespace mozilla::widget; |
michael@0 | 56 | |
michael@0 | 57 | /* from nsFilePicker.js */ |
michael@0 | 58 | #define XULFILEPICKER_CID \ |
michael@0 | 59 | { 0x54ae32f8, 0x1dd2, 0x11b2, \ |
michael@0 | 60 | { 0xa2, 0x09, 0xdf, 0x7c, 0x50, 0x53, 0x70, 0xf8} } |
michael@0 | 61 | static NS_DEFINE_CID(kXULFilePickerCID, XULFILEPICKER_CID); |
michael@0 | 62 | |
michael@0 | 63 | NS_GENERIC_FACTORY_CONSTRUCTOR(nsWindow) |
michael@0 | 64 | NS_GENERIC_FACTORY_CONSTRUCTOR(nsChildWindow) |
michael@0 | 65 | NS_GENERIC_FACTORY_CONSTRUCTOR(nsTransferable) |
michael@0 | 66 | NS_GENERIC_FACTORY_CONSTRUCTOR(nsBidiKeyboard) |
michael@0 | 67 | NS_GENERIC_FACTORY_CONSTRUCTOR(nsHTMLFormatConverter) |
michael@0 | 68 | #ifdef MOZ_X11 |
michael@0 | 69 | NS_GENERIC_FACTORY_SINGLETON_CONSTRUCTOR(nsIdleServiceGTK, nsIdleServiceGTK::GetInstance) |
michael@0 | 70 | NS_GENERIC_FACTORY_CONSTRUCTOR(nsClipboardHelper) |
michael@0 | 71 | NS_GENERIC_FACTORY_CONSTRUCTOR_INIT(nsClipboard, Init) |
michael@0 | 72 | NS_GENERIC_FACTORY_CONSTRUCTOR(nsDragService) |
michael@0 | 73 | #endif |
michael@0 | 74 | NS_GENERIC_FACTORY_CONSTRUCTOR(nsSound) |
michael@0 | 75 | NS_GENERIC_FACTORY_CONSTRUCTOR(nsScreenManagerGtk) |
michael@0 | 76 | NS_GENERIC_FACTORY_CONSTRUCTOR(nsImageToPixbuf) |
michael@0 | 77 | |
michael@0 | 78 | |
michael@0 | 79 | // from nsWindow.cpp |
michael@0 | 80 | extern bool gDisableNativeTheme; |
michael@0 | 81 | |
michael@0 | 82 | static nsresult |
michael@0 | 83 | nsNativeThemeGTKConstructor(nsISupports *aOuter, REFNSIID aIID, |
michael@0 | 84 | void **aResult) |
michael@0 | 85 | { |
michael@0 | 86 | nsresult rv; |
michael@0 | 87 | nsNativeThemeGTK * inst; |
michael@0 | 88 | |
michael@0 | 89 | if (gDisableNativeTheme) |
michael@0 | 90 | return NS_ERROR_NO_INTERFACE; |
michael@0 | 91 | |
michael@0 | 92 | *aResult = nullptr; |
michael@0 | 93 | if (nullptr != aOuter) { |
michael@0 | 94 | rv = NS_ERROR_NO_AGGREGATION; |
michael@0 | 95 | return rv; |
michael@0 | 96 | } |
michael@0 | 97 | |
michael@0 | 98 | inst = new nsNativeThemeGTK(); |
michael@0 | 99 | if (nullptr == inst) { |
michael@0 | 100 | rv = NS_ERROR_OUT_OF_MEMORY; |
michael@0 | 101 | return rv; |
michael@0 | 102 | } |
michael@0 | 103 | NS_ADDREF(inst); |
michael@0 | 104 | rv = inst->QueryInterface(aIID, aResult); |
michael@0 | 105 | NS_RELEASE(inst); |
michael@0 | 106 | |
michael@0 | 107 | return rv; |
michael@0 | 108 | } |
michael@0 | 109 | |
michael@0 | 110 | #if defined(MOZ_X11) |
michael@0 | 111 | namespace mozilla { |
michael@0 | 112 | namespace widget { |
michael@0 | 113 | // This constructor should really be shared with all platforms. |
michael@0 | 114 | NS_GENERIC_FACTORY_CONSTRUCTOR_INIT(GfxInfo, Init) |
michael@0 | 115 | } |
michael@0 | 116 | } |
michael@0 | 117 | #endif |
michael@0 | 118 | |
michael@0 | 119 | #ifdef NS_PRINTING |
michael@0 | 120 | NS_GENERIC_FACTORY_CONSTRUCTOR(nsDeviceContextSpecGTK) |
michael@0 | 121 | NS_GENERIC_FACTORY_CONSTRUCTOR_INIT(nsPrintOptionsGTK, Init) |
michael@0 | 122 | NS_GENERIC_FACTORY_CONSTRUCTOR(nsPrinterEnumeratorGTK) |
michael@0 | 123 | NS_GENERIC_FACTORY_CONSTRUCTOR_INIT(nsPrintSession, Init) |
michael@0 | 124 | NS_GENERIC_FACTORY_CONSTRUCTOR_INIT(nsPrintDialogServiceGTK, Init) |
michael@0 | 125 | #endif |
michael@0 | 126 | |
michael@0 | 127 | static nsresult |
michael@0 | 128 | nsFilePickerConstructor(nsISupports *aOuter, REFNSIID aIID, |
michael@0 | 129 | void **aResult) |
michael@0 | 130 | { |
michael@0 | 131 | *aResult = nullptr; |
michael@0 | 132 | if (aOuter != nullptr) { |
michael@0 | 133 | return NS_ERROR_NO_AGGREGATION; |
michael@0 | 134 | } |
michael@0 | 135 | |
michael@0 | 136 | bool allowPlatformPicker = |
michael@0 | 137 | Preferences::GetBool("ui.allow_platform_file_picker", true); |
michael@0 | 138 | |
michael@0 | 139 | nsCOMPtr<nsIFilePicker> picker; |
michael@0 | 140 | if (allowPlatformPicker) { |
michael@0 | 141 | picker = new nsFilePicker; |
michael@0 | 142 | } else { |
michael@0 | 143 | picker = do_CreateInstance(kXULFilePickerCID); |
michael@0 | 144 | } |
michael@0 | 145 | |
michael@0 | 146 | if (!picker) { |
michael@0 | 147 | return NS_ERROR_OUT_OF_MEMORY; |
michael@0 | 148 | } |
michael@0 | 149 | |
michael@0 | 150 | return picker->QueryInterface(aIID, aResult); |
michael@0 | 151 | } |
michael@0 | 152 | |
michael@0 | 153 | static nsresult |
michael@0 | 154 | nsColorPickerConstructor(nsISupports *aOuter, REFNSIID aIID, |
michael@0 | 155 | void **aResult) |
michael@0 | 156 | { |
michael@0 | 157 | *aResult = nullptr; |
michael@0 | 158 | if (aOuter != nullptr) { |
michael@0 | 159 | return NS_ERROR_NO_AGGREGATION; |
michael@0 | 160 | } |
michael@0 | 161 | |
michael@0 | 162 | nsCOMPtr<nsIColorPicker> picker = new nsColorPicker; |
michael@0 | 163 | |
michael@0 | 164 | if (!picker) { |
michael@0 | 165 | return NS_ERROR_OUT_OF_MEMORY; |
michael@0 | 166 | } |
michael@0 | 167 | |
michael@0 | 168 | return picker->QueryInterface(aIID, aResult); |
michael@0 | 169 | } |
michael@0 | 170 | |
michael@0 | 171 | NS_DEFINE_NAMED_CID(NS_WINDOW_CID); |
michael@0 | 172 | NS_DEFINE_NAMED_CID(NS_CHILD_CID); |
michael@0 | 173 | NS_DEFINE_NAMED_CID(NS_APPSHELL_CID); |
michael@0 | 174 | NS_DEFINE_NAMED_CID(NS_COLORPICKER_CID); |
michael@0 | 175 | NS_DEFINE_NAMED_CID(NS_FILEPICKER_CID); |
michael@0 | 176 | NS_DEFINE_NAMED_CID(NS_SOUND_CID); |
michael@0 | 177 | NS_DEFINE_NAMED_CID(NS_TRANSFERABLE_CID); |
michael@0 | 178 | #ifdef MOZ_X11 |
michael@0 | 179 | NS_DEFINE_NAMED_CID(NS_CLIPBOARD_CID); |
michael@0 | 180 | NS_DEFINE_NAMED_CID(NS_CLIPBOARDHELPER_CID); |
michael@0 | 181 | NS_DEFINE_NAMED_CID(NS_DRAGSERVICE_CID); |
michael@0 | 182 | #endif |
michael@0 | 183 | NS_DEFINE_NAMED_CID(NS_HTMLFORMATCONVERTER_CID); |
michael@0 | 184 | NS_DEFINE_NAMED_CID(NS_BIDIKEYBOARD_CID); |
michael@0 | 185 | NS_DEFINE_NAMED_CID(NS_SCREENMANAGER_CID); |
michael@0 | 186 | NS_DEFINE_NAMED_CID(NS_THEMERENDERER_CID); |
michael@0 | 187 | #ifdef NS_PRINTING |
michael@0 | 188 | NS_DEFINE_NAMED_CID(NS_PRINTSETTINGSSERVICE_CID); |
michael@0 | 189 | NS_DEFINE_NAMED_CID(NS_PRINTER_ENUMERATOR_CID); |
michael@0 | 190 | NS_DEFINE_NAMED_CID(NS_PRINTSESSION_CID); |
michael@0 | 191 | NS_DEFINE_NAMED_CID(NS_DEVICE_CONTEXT_SPEC_CID); |
michael@0 | 192 | NS_DEFINE_NAMED_CID(NS_PRINTDIALOGSERVICE_CID); |
michael@0 | 193 | #endif |
michael@0 | 194 | NS_DEFINE_NAMED_CID(NS_IMAGE_TO_PIXBUF_CID); |
michael@0 | 195 | #if defined(MOZ_X11) |
michael@0 | 196 | NS_DEFINE_NAMED_CID(NS_IDLE_SERVICE_CID); |
michael@0 | 197 | NS_DEFINE_NAMED_CID(NS_GFXINFO_CID); |
michael@0 | 198 | #endif |
michael@0 | 199 | |
michael@0 | 200 | |
michael@0 | 201 | static const mozilla::Module::CIDEntry kWidgetCIDs[] = { |
michael@0 | 202 | { &kNS_WINDOW_CID, false, nullptr, nsWindowConstructor }, |
michael@0 | 203 | { &kNS_CHILD_CID, false, nullptr, nsChildWindowConstructor }, |
michael@0 | 204 | { &kNS_APPSHELL_CID, false, nullptr, nsAppShellConstructor }, |
michael@0 | 205 | { &kNS_COLORPICKER_CID, false, nullptr, nsColorPickerConstructor, Module::MAIN_PROCESS_ONLY }, |
michael@0 | 206 | { &kNS_FILEPICKER_CID, false, nullptr, nsFilePickerConstructor, Module::MAIN_PROCESS_ONLY }, |
michael@0 | 207 | { &kNS_SOUND_CID, false, nullptr, nsSoundConstructor, Module::MAIN_PROCESS_ONLY }, |
michael@0 | 208 | { &kNS_TRANSFERABLE_CID, false, nullptr, nsTransferableConstructor }, |
michael@0 | 209 | #ifdef MOZ_X11 |
michael@0 | 210 | { &kNS_CLIPBOARD_CID, false, nullptr, nsClipboardConstructor, Module::MAIN_PROCESS_ONLY }, |
michael@0 | 211 | { &kNS_CLIPBOARDHELPER_CID, false, nullptr, nsClipboardHelperConstructor }, |
michael@0 | 212 | { &kNS_DRAGSERVICE_CID, false, nullptr, nsDragServiceConstructor, Module::MAIN_PROCESS_ONLY }, |
michael@0 | 213 | #endif |
michael@0 | 214 | { &kNS_HTMLFORMATCONVERTER_CID, false, nullptr, nsHTMLFormatConverterConstructor }, |
michael@0 | 215 | { &kNS_BIDIKEYBOARD_CID, false, nullptr, nsBidiKeyboardConstructor }, |
michael@0 | 216 | { &kNS_SCREENMANAGER_CID, false, nullptr, nsScreenManagerGtkConstructor }, |
michael@0 | 217 | { &kNS_THEMERENDERER_CID, false, nullptr, nsNativeThemeGTKConstructor }, |
michael@0 | 218 | #ifdef NS_PRINTING |
michael@0 | 219 | { &kNS_PRINTSETTINGSSERVICE_CID, false, nullptr, nsPrintOptionsGTKConstructor }, |
michael@0 | 220 | { &kNS_PRINTER_ENUMERATOR_CID, false, nullptr, nsPrinterEnumeratorGTKConstructor, |
michael@0 | 221 | Module::MAIN_PROCESS_ONLY }, |
michael@0 | 222 | { &kNS_PRINTSESSION_CID, false, nullptr, nsPrintSessionConstructor, |
michael@0 | 223 | Module::MAIN_PROCESS_ONLY }, |
michael@0 | 224 | { &kNS_DEVICE_CONTEXT_SPEC_CID, false, nullptr, nsDeviceContextSpecGTKConstructor, |
michael@0 | 225 | Module::MAIN_PROCESS_ONLY }, |
michael@0 | 226 | { &kNS_PRINTDIALOGSERVICE_CID, false, nullptr, nsPrintDialogServiceGTKConstructor, |
michael@0 | 227 | Module::MAIN_PROCESS_ONLY }, |
michael@0 | 228 | #endif |
michael@0 | 229 | { &kNS_IMAGE_TO_PIXBUF_CID, false, nullptr, nsImageToPixbufConstructor }, |
michael@0 | 230 | #if defined(MOZ_X11) |
michael@0 | 231 | { &kNS_IDLE_SERVICE_CID, false, nullptr, nsIdleServiceGTKConstructor }, |
michael@0 | 232 | { &kNS_GFXINFO_CID, false, nullptr, mozilla::widget::GfxInfoConstructor }, |
michael@0 | 233 | #endif |
michael@0 | 234 | { nullptr } |
michael@0 | 235 | }; |
michael@0 | 236 | |
michael@0 | 237 | static const mozilla::Module::ContractIDEntry kWidgetContracts[] = { |
michael@0 | 238 | { "@mozilla.org/widget/window/gtk;1", &kNS_WINDOW_CID }, |
michael@0 | 239 | { "@mozilla.org/widgets/child_window/gtk;1", &kNS_CHILD_CID }, |
michael@0 | 240 | { "@mozilla.org/widget/appshell/gtk;1", &kNS_APPSHELL_CID }, |
michael@0 | 241 | { "@mozilla.org/colorpicker;1", &kNS_COLORPICKER_CID, Module::MAIN_PROCESS_ONLY }, |
michael@0 | 242 | { "@mozilla.org/filepicker;1", &kNS_FILEPICKER_CID, Module::MAIN_PROCESS_ONLY }, |
michael@0 | 243 | { "@mozilla.org/sound;1", &kNS_SOUND_CID, Module::MAIN_PROCESS_ONLY }, |
michael@0 | 244 | { "@mozilla.org/widget/transferable;1", &kNS_TRANSFERABLE_CID }, |
michael@0 | 245 | #ifdef MOZ_X11 |
michael@0 | 246 | { "@mozilla.org/widget/clipboard;1", &kNS_CLIPBOARD_CID, Module::MAIN_PROCESS_ONLY }, |
michael@0 | 247 | { "@mozilla.org/widget/clipboardhelper;1", &kNS_CLIPBOARDHELPER_CID }, |
michael@0 | 248 | { "@mozilla.org/widget/dragservice;1", &kNS_DRAGSERVICE_CID, Module::MAIN_PROCESS_ONLY }, |
michael@0 | 249 | #endif |
michael@0 | 250 | { "@mozilla.org/widget/htmlformatconverter;1", &kNS_HTMLFORMATCONVERTER_CID }, |
michael@0 | 251 | { "@mozilla.org/widget/bidikeyboard;1", &kNS_BIDIKEYBOARD_CID }, |
michael@0 | 252 | { "@mozilla.org/gfx/screenmanager;1", &kNS_SCREENMANAGER_CID }, |
michael@0 | 253 | { "@mozilla.org/chrome/chrome-native-theme;1", &kNS_THEMERENDERER_CID }, |
michael@0 | 254 | #ifdef NS_PRINTING |
michael@0 | 255 | { "@mozilla.org/gfx/printsettings-service;1", &kNS_PRINTSETTINGSSERVICE_CID }, |
michael@0 | 256 | { "@mozilla.org/gfx/printerenumerator;1", &kNS_PRINTER_ENUMERATOR_CID, |
michael@0 | 257 | Module::MAIN_PROCESS_ONLY }, |
michael@0 | 258 | { "@mozilla.org/gfx/printsession;1", &kNS_PRINTSESSION_CID, |
michael@0 | 259 | Module::MAIN_PROCESS_ONLY }, |
michael@0 | 260 | { "@mozilla.org/gfx/devicecontextspec;1", &kNS_DEVICE_CONTEXT_SPEC_CID, |
michael@0 | 261 | Module::MAIN_PROCESS_ONLY }, |
michael@0 | 262 | { NS_PRINTDIALOGSERVICE_CONTRACTID, &kNS_PRINTDIALOGSERVICE_CID, |
michael@0 | 263 | Module::MAIN_PROCESS_ONLY }, |
michael@0 | 264 | #endif |
michael@0 | 265 | { "@mozilla.org/widget/image-to-gdk-pixbuf;1", &kNS_IMAGE_TO_PIXBUF_CID }, |
michael@0 | 266 | #if defined(MOZ_X11) |
michael@0 | 267 | { "@mozilla.org/widget/idleservice;1", &kNS_IDLE_SERVICE_CID }, |
michael@0 | 268 | { "@mozilla.org/gfx/info;1", &kNS_GFXINFO_CID }, |
michael@0 | 269 | #endif |
michael@0 | 270 | { nullptr } |
michael@0 | 271 | }; |
michael@0 | 272 | |
michael@0 | 273 | static void |
michael@0 | 274 | nsWidgetGtk2ModuleDtor() |
michael@0 | 275 | { |
michael@0 | 276 | NativeKeyBindings::Shutdown(); |
michael@0 | 277 | nsLookAndFeel::Shutdown(); |
michael@0 | 278 | nsFilePicker::Shutdown(); |
michael@0 | 279 | nsSound::Shutdown(); |
michael@0 | 280 | nsWindow::ReleaseGlobals(); |
michael@0 | 281 | nsGTKToolkit::Shutdown(); |
michael@0 | 282 | nsAppShellShutdown(); |
michael@0 | 283 | } |
michael@0 | 284 | |
michael@0 | 285 | static const mozilla::Module kWidgetModule = { |
michael@0 | 286 | mozilla::Module::kVersion, |
michael@0 | 287 | kWidgetCIDs, |
michael@0 | 288 | kWidgetContracts, |
michael@0 | 289 | nullptr, |
michael@0 | 290 | nullptr, |
michael@0 | 291 | nsAppShellInit, |
michael@0 | 292 | nsWidgetGtk2ModuleDtor |
michael@0 | 293 | }; |
michael@0 | 294 | |
michael@0 | 295 | NSMODULE_DEFN(nsWidgetGtk2Module) = &kWidgetModule; |