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