Bug 470455 - test_database_sync_embed_visits.js leaks, r=sdwilsh
[wine-gecko.git] / extensions / widgetutils / src / nsWidgetUtils.cpp
blobe711785471d0a0dfb626147a05ef1124de083a43
1 /* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
2 /* vim:set ts=2 sw=2 sts=2 tw=80 et cindent: */
3 /* ***** BEGIN LICENSE BLOCK *****
4 * Version: MPL 1.1/GPL 2.0/LGPL 2.1
6 * The contents of this file are subject to the Mozilla Public License Version
7 * 1.1 (the "License"); you may not use this file except in compliance with
8 * the License. You may obtain a copy of the License at
9 * http://www.mozilla.org/MPL/
11 * Software distributed under the License is distributed on an "AS IS" basis,
12 * WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
13 * for the specific language governing rights and limitations under the
14 * License.
16 * The Original Code is Mozilla's Element Optimizeing extension.
18 * The Initial Developer of the Original Code is the Mozilla Foundation.
19 * Portions created by the Initial Developer are Copyright (C) 2006
20 * the Initial Developer. All Rights Reserved.
22 * Contributor(s):
23 * Oleg Romashin <romaxa@gmail.com> (original author)
24 * Brad Lassey <blassey@mozilla.com>
26 * Alternatively, the contents of this file may be used under the terms of
27 * either the GNU General Public License Version 2 or later (the "GPL"), or
28 * the GNU Lesser General Public License Version 2.1 or later (the "LGPL"),
29 * in which case the provisions of the GPL or the LGPL are applicable instead
30 * of those above. If you wish to allow use of your version of this file only
31 * under the terms of either the GPL or the LGPL, and not to allow others to
32 * use your version of this file under the terms of the MPL, indicate your
33 * decision by deleting the provisions above and replace them with the notice
34 * and other provisions required by the GPL or the LGPL. If you do not delete
35 * the provisions above, a recipient may use your version of this file under
36 * the terms of any one of the MPL, the GPL or the LGPL.
38 * ***** END LICENSE BLOCK ***** */
40 #include "nsCURILoader.h"
41 #include "nsICategoryManager.h"
42 #include "nsIDOMAbstractView.h"
43 #include "nsIDOMDocument.h"
44 #include "nsIDOMDocumentView.h"
45 #include "nsIDOMHTMLElement.h"
46 #include "nsIDOMHTMLIFrameElement.h"
47 #include "nsIDOMNSDocument.h"
48 #include "nsIDOMNSElement.h"
49 #include "nsIDOMNSHTMLElement.h"
50 #include "nsIDOMNode.h"
51 #include "nsIDOMNodeList.h"
52 #include "nsIDOMWindow.h"
53 #include "nsIDOMWindowCollection.h"
54 #include "nsIDocument.h"
55 #include "nsIGenericFactory.h"
56 #include "nsIObserver.h"
57 #include "nsIPref.h"
58 #include "nsIPresShell.h"
59 #include "nsIStyleSheetService.h"
60 #include "nsIWebProgress.h"
61 #include "nsIWebProgressListener.h"
62 #include "nsIWindowWatcher.h"
63 #include "nsNetUtil.h"
64 #include "nsRect.h"
65 #include "nsStringGlue.h"
66 #include "nsWeakReference.h"
67 #include "nsIWebBrowser.h"
68 #include "nsIObserverService.h"
69 #include "nsIDOMEventTarget.h"
70 #include "nsPIDOMWindow.h"
71 #include "nsIDOMWindow.h"
72 //#include ".h"
73 #include "nsIDOM3EventTarget.h"
74 #include "nsIDOMKeyListener.h"
75 #include "nsIDOMCompositionListener.h"
76 #include "nsIDOMTextListener.h"
77 #include "nsIDOMMouseMotionListener.h"
78 #include "nsIDOMMouseListener.h"
79 #include "nsIDOMMouseEvent.h"
80 #include "nsIDOMNSEvent.h"
81 #include "nsIView.h"
82 #include "nsGUIEvent.h"
83 #include "nsIViewManager.h"
84 #include "nsIContentPolicy.h"
85 #include "nsIDocShellTreeItem.h"
86 #include "nsIContent.h"
87 #include "nsITimer.h"
89 const int MIN_INT =((int) (1 << (sizeof(int) * 8 - 1)));
91 static int g_lastX=MIN_INT;
92 static int g_lastY=MIN_INT;
93 static PRInt32 g_panning = 0;
94 static PRBool g_is_scrollable = PR_FALSE;
96 #define EM_MULT 16.
97 #define NS_FRAME_HAS_RELATIVE_SIZE 0x01000000
98 #define NS_FRAME_HAS_OPTIMIZEDVIEW 0x02000000
99 #define BEHAVIOR_ACCEPT nsIPermissionManager::ALLOW_ACTION
100 #define BEHAVIOR_REJECT nsIPermissionManager::DENY_ACTION
101 #define BEHAVIOR_NOFOREIGN 3
102 #define NUMBER_OF_TYPES 13
104 // TODO auto reload nsWidgetUtils in C.
105 class nsWidgetUtils : public nsIObserver,
106 public nsIDOMMouseMotionListener,
107 public nsIDOMMouseListener,
108 public nsIContentPolicy,
109 public nsSupportsWeakReference
111 public:
112 nsWidgetUtils();
113 virtual ~nsWidgetUtils();
115 // nsIDOMMouseMotionListener
116 NS_IMETHOD MouseMove(nsIDOMEvent* aDOMEvent);
117 NS_IMETHOD DragMove(nsIDOMEvent* aMouseEvent);
118 NS_IMETHOD HandleEvent(nsIDOMEvent* aDOMEvent);
120 // nsIDOMMouseListener
121 NS_IMETHOD MouseDown(nsIDOMEvent* aDOMEvent);
122 NS_IMETHOD MouseUp(nsIDOMEvent* aDOMEvent);
123 NS_IMETHOD MouseClick(nsIDOMEvent* aDOMEvent);
124 NS_IMETHOD MouseDblClick(nsIDOMEvent* aDOMEvent);
125 NS_IMETHOD MouseOver(nsIDOMEvent* aDOMEvent);
126 NS_IMETHOD MouseOut(nsIDOMEvent* aDOMEvent);
128 NS_DECL_ISUPPORTS
129 NS_DECL_NSIOBSERVER
130 NS_DECL_NSICONTENTPOLICY
132 private:
133 nsresult Init(void);
134 void RemoveWindowListeners(nsIDOMWindow *aDOMWin);
135 void GetChromeEventHandler(nsIDOMWindow *aDOMWin, nsIDOMEventTarget **aChromeTarget);
136 void AttachWindowListeners(nsIDOMWindow *aDOMWin);
137 PRBool IsXULNode(nsIDOMNode *aNode, PRUint32 *aType = 0);
138 nsresult GetDOMWindowByNode(nsIDOMNode *aNode, nsIDOMWindow * *aDOMWindow);
139 nsresult UpdateFromEvent(nsIDOMEvent *aDOMEvent, nsIWidget * *aWidget = nsnull, nsIViewManager * *aViewManager = nsnull);
141 static void StopPanningCallback(nsITimer *timer, void *closure);
143 nsCOMPtr<nsIWidget> mWidget;
144 nsCOMPtr<nsIViewManager> mViewManager;
145 nsCOMPtr<nsITimer> mTimer;
148 nsWidgetUtils::nsWidgetUtils()
150 Init();
153 NS_IMETHODIMP
154 nsWidgetUtils::Init()
156 nsresult rv;
157 nsCOMPtr<nsIObserverService> obsSvc =
158 do_GetService("@mozilla.org/observer-service;1");
159 NS_ENSURE_STATE(obsSvc);
161 rv = obsSvc->AddObserver(this, "domwindowopened", PR_FALSE);
162 NS_ENSURE_SUCCESS(rv, rv);
163 rv = obsSvc->AddObserver(this, "domwindowclosed", PR_FALSE);
164 NS_ENSURE_SUCCESS(rv, rv);
165 mTimer = do_CreateInstance(NS_TIMER_CONTRACTID);
168 nsresult
169 nsWidgetUtils::UpdateFromEvent(nsIDOMEvent *aDOMEvent, nsIWidget * *aWidget, nsIViewManager * *aViewManager)
171 nsCOMPtr <nsIDOMMouseEvent> mouseEvent;
172 mouseEvent = do_QueryInterface(aDOMEvent);
173 if (!mouseEvent)
174 return NS_OK;
176 ((nsIDOMMouseEvent*)mouseEvent)->GetScreenX(&g_lastX);
177 ((nsIDOMMouseEvent*)mouseEvent)->GetScreenY(&g_lastY);
179 nsCOMPtr<nsIDOMWindow> mWindow;
180 nsCOMPtr<nsIDOMNode> mNode;
181 nsCOMPtr<nsIDOMNode> mOrigNode;
183 PRUint32 type = 0;
184 PRBool isXul = PR_FALSE;
186 nsCOMPtr <nsIDOMNSEvent> aEvent = do_QueryInterface(aDOMEvent);
187 nsCOMPtr<nsIDOMEventTarget> eventOrigTarget;
188 if (aEvent)
189 aEvent->GetOriginalTarget(getter_AddRefs(eventOrigTarget));
190 if (eventOrigTarget)
191 mOrigNode = do_QueryInterface(eventOrigTarget);
192 isXul = IsXULNode(mOrigNode, &type);
195 if (isXul)
196 return NS_ERROR_FAILURE;
198 nsCOMPtr<nsIDOMEventTarget> eventTarget;
199 aDOMEvent->GetTarget(getter_AddRefs(eventTarget));
200 if (eventTarget)
201 mNode = do_QueryInterface(eventTarget);
203 if (!mNode)
204 return NS_OK;
206 GetDOMWindowByNode(mNode, getter_AddRefs(mWindow));
207 if (!mWindow)
208 return NS_OK;
209 nsCOMPtr<nsIDocument> doc;
210 nsCOMPtr<nsIDOMDocument> domDoc;
211 mWindow->GetDocument(getter_AddRefs(domDoc));
212 doc = do_QueryInterface(domDoc);
213 if (!doc) return NS_OK;
214 // the only case where there could be more shells in printpreview
215 nsIPresShell *shell = doc->GetPrimaryShell();
216 NS_ENSURE_TRUE(shell, NS_ERROR_FAILURE);
217 mViewManager = shell->GetViewManager();
218 NS_ENSURE_TRUE(mViewManager, NS_ERROR_FAILURE);
219 mViewManager->GetWidget(getter_AddRefs(mWidget));
220 NS_ENSURE_TRUE(mWidget, NS_ERROR_FAILURE);
221 if (aWidget)
222 NS_ADDREF(*aWidget = mWidget);
223 if (aViewManager)
224 NS_ADDREF(*aViewManager = mViewManager);
225 return NS_OK;
228 NS_IMETHODIMP
229 nsWidgetUtils::MouseDown(nsIDOMEvent* aDOMEvent)
231 g_is_scrollable = PR_FALSE;
232 // Return TRUE from your signal handler to mark the event as consumed.
233 if (NS_FAILED(UpdateFromEvent(aDOMEvent)))
234 return NS_OK;
235 g_is_scrollable = PR_TRUE;
236 if (g_is_scrollable) {
237 aDOMEvent->StopPropagation();
238 aDOMEvent->PreventDefault();
240 return NS_OK;
243 /* static */ void
244 nsWidgetUtils::StopPanningCallback(nsITimer *timer, void *closure)
246 g_panning = PR_FALSE;
249 NS_IMETHODIMP
250 nsWidgetUtils::MouseUp(nsIDOMEvent* aDOMEvent)
252 nsCOMPtr <nsIDOMMouseEvent> mouseEvent;
253 mouseEvent = do_QueryInterface(aDOMEvent);
254 if (!mouseEvent)
255 return NS_OK;
256 // Return TRUE from your signal handler to mark the event as consumed.
257 g_lastX = MIN_INT;
258 g_lastY = MIN_INT;
259 g_is_scrollable = PR_FALSE;
260 if (g_panning) {
261 aDOMEvent->StopPropagation();
262 aDOMEvent->PreventDefault();
263 nsresult rv;
264 if (mTimer) {
265 rv = mTimer->InitWithFuncCallback(nsWidgetUtils::StopPanningCallback,
266 nsnull, 500, nsITimer::TYPE_ONE_SHOT);
267 if (NS_SUCCEEDED(rv))
268 return NS_OK;
270 g_panning = PR_FALSE;
272 return NS_OK;
275 NS_IMETHODIMP
276 nsWidgetUtils::MouseMove(nsIDOMEvent* aDOMEvent)
278 if (!g_is_scrollable) return NS_OK;
280 nsCOMPtr<nsIDOMMouseEvent> mouseEvent = do_QueryInterface(aDOMEvent);
281 if (!mouseEvent)
282 return NS_OK;
283 int x, y;
284 ((nsIDOMMouseEvent*)mouseEvent)->GetScreenX(&x);
285 ((nsIDOMMouseEvent*)mouseEvent)->GetScreenY(&y);
287 int dx = g_lastX - x;
288 int dy = g_lastY - y;
289 if(g_lastX == MIN_INT || g_lastY == MIN_INT)
290 return NS_OK;
292 nsIView *aView = nsnull;
293 mViewManager->GetRootView(aView);
294 if (!aView)
295 if (NS_FAILED(UpdateFromEvent(aDOMEvent)))
296 return NS_OK;
298 nsEventStatus statusX;
299 nsMouseScrollEvent scrollEventX(PR_TRUE, NS_MOUSE_SCROLL, mWidget);
300 scrollEventX.delta = dx;
301 scrollEventX.scrollFlags = nsMouseScrollEvent::kIsHorizontal | nsMouseScrollEvent::kIsPixels;
302 mViewManager->DispatchEvent(&scrollEventX, &statusX);
303 if(statusX != nsEventStatus_eIgnore ){
304 if (dx > 5)
305 g_panning = PR_TRUE;
306 g_lastX = x;
309 nsEventStatus statusY;
310 nsMouseScrollEvent scrollEventY(PR_TRUE, NS_MOUSE_SCROLL, mWidget);
311 scrollEventY.delta = dy;
312 scrollEventY.scrollFlags = nsMouseScrollEvent::kIsVertical | nsMouseScrollEvent::kIsPixels;
313 mViewManager->DispatchEvent(&scrollEventY, &statusY);
314 if(statusY != nsEventStatus_eIgnore ){
315 if (dy > 5)
316 g_panning = PR_TRUE;
317 g_lastY = y;
319 if (g_panning) {
320 aDOMEvent->StopPropagation();
321 aDOMEvent->PreventDefault();
324 return NS_OK;
327 // nsIContentPolicy Implementation
328 NS_IMETHODIMP
329 nsWidgetUtils::ShouldLoad(PRUint32 aContentType,
330 nsIURI *aContentLocation,
331 nsIURI *aRequestingLocation,
332 nsISupports *aRequestingContext,
333 const nsACString &aMimeGuess,
334 nsISupports *aExtra,
335 PRInt16 *aDecision)
337 *aDecision = nsIContentPolicy::ACCEPT;
338 nsresult rv;
340 if (aContentType != nsIContentPolicy::TYPE_DOCUMENT)
341 return NS_OK;
343 // we can't do anything without this
344 if (!aContentLocation)
345 return NS_OK;
347 nsCAutoString scheme;
348 rv = aContentLocation->GetScheme(scheme);
349 nsCAutoString lscheme;
350 ToLowerCase(scheme, lscheme);
351 if (!lscheme.EqualsLiteral("ftp") &&
352 !lscheme.EqualsLiteral("http") &&
353 !lscheme.EqualsLiteral("https"))
354 return NS_OK;
355 if (g_panning > 0)
356 *aDecision = nsIContentPolicy::REJECT_REQUEST;
357 return NS_OK;
360 NS_IMETHODIMP
361 nsWidgetUtils::MouseClick(nsIDOMEvent* aDOMEvent)
363 return NS_OK;
366 NS_IMETHODIMP
367 nsWidgetUtils::MouseDblClick(nsIDOMEvent* aDOMEvent)
369 return NS_OK;
372 NS_IMETHODIMP
373 nsWidgetUtils::HandleEvent(nsIDOMEvent* aDOMEvent)
375 return NS_OK;
378 NS_IMETHODIMP
379 nsWidgetUtils::MouseOver(nsIDOMEvent* aDOMEvent)
381 return NS_OK;
384 NS_IMETHODIMP
385 nsWidgetUtils::MouseOut(nsIDOMEvent* aDOMEvent)
387 return NS_OK;
391 NS_IMETHODIMP
392 nsWidgetUtils::DragMove(nsIDOMEvent* aDOMEvent)
394 return NS_OK;
397 NS_IMETHODIMP
398 nsWidgetUtils::ShouldProcess(PRUint32 aContentType,
399 nsIURI *aContentLocation,
400 nsIURI *aRequestingLocation,
401 nsISupports *aRequestingContext,
402 const nsACString &aMimeGuess,
403 nsISupports *aExtra,
404 PRInt16 *aDecision)
406 *aDecision = nsIContentPolicy::ACCEPT;
407 return NS_OK;
410 PRBool
411 nsWidgetUtils::IsXULNode(nsIDOMNode *aNode, PRUint32 *aType)
413 PRBool retval = PR_FALSE;
414 if (!aNode) return retval;
416 nsString sorigNode;
417 aNode->GetNodeName(sorigNode);
418 if (sorigNode.EqualsLiteral("#document"))
419 return retval;
420 retval = StringBeginsWith(sorigNode, NS_LITERAL_STRING("xul:"));
422 if (!aType) return retval;
424 if (sorigNode.EqualsLiteral("xul:thumb")
425 || sorigNode.EqualsLiteral("xul:vbox")
426 || sorigNode.EqualsLiteral("xul:spacer"))
427 *aType = PR_FALSE; // Magic
428 else if (sorigNode.EqualsLiteral("xul:slider"))
429 *aType = 2; // Magic
430 else if (sorigNode.EqualsLiteral("xul:scrollbarbutton"))
431 *aType = 3; // Magic
433 return retval;
436 nsresult
437 nsWidgetUtils::GetDOMWindowByNode(nsIDOMNode *aNode, nsIDOMWindow * *aDOMWindow)
439 nsresult rv;
440 nsCOMPtr<nsIDOMDocument> nodeDoc;
441 rv = aNode->GetOwnerDocument(getter_AddRefs(nodeDoc));
442 NS_ENSURE_SUCCESS(rv, rv);
443 nsCOMPtr<nsIDOMDocumentView> docView = do_QueryInterface(nodeDoc, &rv);
444 NS_ENSURE_SUCCESS(rv, rv);
445 nsCOMPtr<nsIDOMAbstractView> absView;
446 NS_ENSURE_SUCCESS(rv, rv);
447 rv = docView->GetDefaultView(getter_AddRefs(absView));
448 NS_ENSURE_SUCCESS(rv, rv);
449 nsCOMPtr<nsIDOMWindow> window = do_QueryInterface(absView, &rv);
450 NS_ENSURE_SUCCESS(rv, rv);
451 *aDOMWindow = window;
452 NS_IF_ADDREF(*aDOMWindow);
453 return rv;
456 void
457 nsWidgetUtils::GetChromeEventHandler(nsIDOMWindow *aDOMWin,
458 nsIDOMEventTarget **aChromeTarget)
460 nsCOMPtr<nsPIDOMWindow> privateDOMWindow(do_QueryInterface(aDOMWin));
461 nsPIDOMEventTarget* chromeEventHandler = nsnull;
462 if (privateDOMWindow) {
463 chromeEventHandler = privateDOMWindow->GetChromeEventHandler();
466 nsCOMPtr<nsIDOMEventTarget> target(do_QueryInterface(chromeEventHandler));
468 *aChromeTarget = target;
469 NS_IF_ADDREF(*aChromeTarget);
472 void
473 nsWidgetUtils::RemoveWindowListeners(nsIDOMWindow *aDOMWin)
475 nsresult rv;
476 nsCOMPtr<nsIDOMEventTarget> chromeEventHandler;
477 GetChromeEventHandler(aDOMWin, getter_AddRefs(chromeEventHandler));
478 if (!chromeEventHandler) {
479 return;
482 // Use capturing, otherwise the normal find next will get activated when ours should
483 nsCOMPtr<nsPIDOMEventTarget> piTarget(do_QueryInterface(chromeEventHandler));
485 // Remove DOM Text listener for IME text events
486 rv = piTarget->RemoveEventListenerByIID(static_cast<nsIDOMMouseListener*>(this),
487 NS_GET_IID(nsIDOMMouseListener));
488 if (NS_FAILED(rv)) {
489 NS_WARNING("Failed to add Mouse Motion listener\n");
490 return;
492 rv = piTarget->RemoveEventListenerByIID(static_cast<nsIDOMMouseMotionListener*>(this),
493 NS_GET_IID(nsIDOMMouseMotionListener));
494 if (NS_FAILED(rv)) {
495 NS_WARNING("Failed to add Mouse Motion listener\n");
496 return;
500 void
501 nsWidgetUtils::AttachWindowListeners(nsIDOMWindow *aDOMWin)
503 nsresult rv;
504 nsCOMPtr<nsIDOMEventTarget> chromeEventHandler;
505 GetChromeEventHandler(aDOMWin, getter_AddRefs(chromeEventHandler));
506 if (!chromeEventHandler) {
507 return;
510 // Use capturing, otherwise the normal find next will get activated when ours should
511 nsCOMPtr<nsPIDOMEventTarget> piTarget(do_QueryInterface(chromeEventHandler));
513 // Attach menu listeners, this will help us ignore keystrokes meant for menus
514 rv = piTarget->AddEventListenerByIID(static_cast<nsIDOMMouseListener*>(this),
515 NS_GET_IID(nsIDOMMouseListener));
516 if (NS_FAILED(rv)) {
517 NS_WARNING("Failed to add Mouse Motion listener\n");
518 return;
520 rv = piTarget->AddEventListenerByIID(static_cast<nsIDOMMouseMotionListener*>(this),
521 NS_GET_IID(nsIDOMMouseMotionListener));
522 if (NS_FAILED(rv)) {
523 NS_WARNING("Failed to add Mouse Motion listener\n");
524 return;
528 nsWidgetUtils::~nsWidgetUtils()
532 NS_IMPL_ISUPPORTS5(nsWidgetUtils, nsIObserver, nsIDOMMouseMotionListener, nsIDOMMouseListener, nsIContentPolicy, nsISupportsWeakReference)
534 NS_IMETHODIMP
535 nsWidgetUtils::Observe(nsISupports *aSubject, const char *aTopic, const PRUnichar *aData)
537 nsresult rv;
538 if (!strcmp(aTopic,"domwindowopened"))
540 nsCOMPtr<nsIDOMWindow> chromeWindow = do_QueryInterface(aSubject);
541 if (chromeWindow)
542 AttachWindowListeners(chromeWindow);
543 return NS_OK;
546 if (!strcmp(aTopic,"domwindowclosed"))
548 nsCOMPtr<nsIDOMWindow> chromeWindow = do_QueryInterface(aSubject);
549 RemoveWindowListeners(chromeWindow);
550 return NS_OK;
553 return NS_OK;
556 //------------------------------------------------------------------------------
557 // XPCOM REGISTRATION BELOW
558 //------------------------------------------------------------------------------
560 #define WidgetUtils_CID \
561 { 0x0ced17b6, 0x96ed, 0x4030, \
562 {0xa1, 0x34, 0x77, 0xcb, 0x66, 0x10, 0xa8, 0xf6} }
564 #define WidgetUtils_ContractID "@mozilla.org/extensions/widgetutils;1"
566 static NS_METHOD WidgetUtilsRegistration(nsIComponentManager *aCompMgr,
567 nsIFile *aPath,
568 const char *registryLocation,
569 const char *componentType,
570 const nsModuleComponentInfo *info)
572 nsresult rv;
574 nsCOMPtr<nsIServiceManager> servman = do_QueryInterface((nsISupports*)aCompMgr, &rv);
575 if (NS_FAILED(rv))
576 return rv;
578 nsCOMPtr<nsICategoryManager> catman;
579 servman->GetServiceByContractID(NS_CATEGORYMANAGER_CONTRACTID,
580 NS_GET_IID(nsICategoryManager),
581 getter_AddRefs(catman));
583 if (NS_FAILED(rv))
584 return rv;
586 char* previous = nsnull;
587 rv = catman->AddCategoryEntry("app-startup",
588 "WidgetUtils",
589 WidgetUtils_ContractID,
590 PR_TRUE,
591 PR_TRUE,
592 &previous);
593 if (previous)
594 nsMemory::Free(previous);
595 rv = catman->AddCategoryEntry("content-policy",
596 "WidgetUtils",
597 WidgetUtils_ContractID,
598 PR_TRUE,
599 PR_TRUE,
600 &previous);
601 if (previous)
602 nsMemory::Free(previous);
604 return rv;
607 static NS_METHOD WidgetUtilsUnregistration(nsIComponentManager *aCompMgr,
608 nsIFile *aPath,
609 const char *registryLocation,
610 const nsModuleComponentInfo *info)
612 nsresult rv;
614 nsCOMPtr<nsIServiceManager> servman = do_QueryInterface((nsISupports*)aCompMgr, &rv);
615 if (NS_FAILED(rv))
616 return rv;
618 nsCOMPtr<nsICategoryManager> catman;
619 servman->GetServiceByContractID(NS_CATEGORYMANAGER_CONTRACTID,
620 NS_GET_IID(nsICategoryManager),
621 getter_AddRefs(catman));
623 if (NS_FAILED(rv))
624 return rv;
626 rv = catman->DeleteCategoryEntry("app-startup",
627 "WidgetUtils",
628 PR_TRUE);
629 rv = catman->DeleteCategoryEntry("content-policy",
630 "WidgetUtils",
631 PR_TRUE);
633 return rv;
636 NS_GENERIC_FACTORY_CONSTRUCTOR(nsWidgetUtils)
638 static const nsModuleComponentInfo components[] =
640 { "nsWidgetUtilsService",
641 WidgetUtils_CID,
642 WidgetUtils_ContractID,
643 nsWidgetUtilsConstructor,
644 WidgetUtilsRegistration,
645 WidgetUtilsUnregistration
649 NS_IMPL_NSGETMODULE(nsWidgetUtilsModule, components)