Bug 503879, remove nsIToolkit, make nsToolkit a singleton, remove it from some widget platforms, and don't pass it around when creating widgets, original patch by robarnold, r=roc
authorNeil Deakin <neil@mozilla.com>
Tue, 25 Oct 2011 11:05:32 -0400
changeset 79196 3131f4933dd48026d607276cfb72e9148481d149
parent 79195 dd18ab29d0e834dd771ed085581b2213a48cea1b
child 79197 3f7638d38b32b2e5fa221c7816e16f612a9e67b7
push id21377
push userbmo@edmorley.co.uk
push dateWed, 26 Oct 2011 00:52:20 +0000
treeherdermozilla-central@cc66accc8181 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersroc
bugs503879
milestone10.0a1
first release with
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
last release without
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
Bug 503879, remove nsIToolkit, make nsToolkit a singleton, remove it from some widget platforms, and don't pass it around when creating widgets, original patch by robarnold, r=roc
embedding/browser/webBrowser/nsWebBrowser.cpp
layout/generic/nsObjectFrame.cpp
toolkit/components/remote/nsGTKRemoteService.cpp
toolkit/xre/nsAppRunner.cpp
view/src/nsView.cpp
widget/public/Makefile.in
widget/public/nsIToolkit.idl
widget/public/nsIWidget.h
widget/src/android/Makefile.in
widget/src/android/nsToolkit.cpp
widget/src/android/nsToolkit.h
widget/src/android/nsWidgetFactory.cpp
widget/src/android/nsWindow.cpp
widget/src/android/nsWindow.h
widget/src/build/nsWinWidgetFactory.cpp
widget/src/cocoa/nsChildView.h
widget/src/cocoa/nsChildView.mm
widget/src/cocoa/nsCocoaWindow.h
widget/src/cocoa/nsCocoaWindow.mm
widget/src/cocoa/nsToolkit.h
widget/src/cocoa/nsToolkit.mm
widget/src/cocoa/nsWidgetFactory.mm
widget/src/gtk2/nsGTKToolkit.h
widget/src/gtk2/nsToolkit.cpp
widget/src/gtk2/nsWidgetFactory.cpp
widget/src/gtk2/nsWindow.cpp
widget/src/gtk2/nsWindow.h
widget/src/os2/Makefile.in
widget/src/os2/nsToolkit.cpp
widget/src/os2/nsToolkit.h
widget/src/os2/nsWidgetFactory.cpp
widget/src/os2/nsWindow.cpp
widget/src/os2/nsWindow.h
widget/src/qt/Makefile.in
widget/src/qt/nsToolkit.cpp
widget/src/qt/nsToolkit.h
widget/src/qt/nsWidgetFactory.cpp
widget/src/qt/nsWindow.cpp
widget/src/qt/nsWindow.h
widget/src/windows/nsToolkit.cpp
widget/src/windows/nsToolkit.h
widget/src/windows/nsWindow.cpp
widget/src/windows/nsWindow.h
widget/src/xpwidgets/Makefile.in
widget/src/xpwidgets/PuppetWidget.cpp
widget/src/xpwidgets/PuppetWidget.h
widget/src/xpwidgets/nsBaseWidget.cpp
widget/src/xpwidgets/nsBaseWidget.h
xpfe/appshell/src/nsWebShellWindow.cpp
--- a/embedding/browser/webBrowser/nsWebBrowser.cpp
+++ b/embedding/browser/webBrowser/nsWebBrowser.cpp
@@ -1151,17 +1151,17 @@ NS_IMETHODIMP nsWebBrowser::Create()
 
       widgetInit.clipChildren = true;
 
       widgetInit.mWindowType = eWindowType_child;
       nsIntRect bounds(mInitInfo->x, mInitInfo->y, mInitInfo->cx, mInitInfo->cy);
       
       mInternalWidget->SetClientData(static_cast<nsWebBrowser *>(this));
       mInternalWidget->Create(nsnull, mParentNativeWindow, bounds, nsWebBrowser::HandleEvent,
-                              nsnull, nsnull, &widgetInit);  
+                              nsnull, &widgetInit);  
       }
 
     nsCOMPtr<nsIDocShell> docShell(do_CreateInstance("@mozilla.org/docshell;1", &rv));
     NS_ENSURE_SUCCESS(rv, rv);
     rv = SetDocShell(docShell);
     NS_ENSURE_SUCCESS(rv, rv);
 
     // get the system default window background colour
--- a/layout/generic/nsObjectFrame.cpp
+++ b/layout/generic/nsObjectFrame.cpp
@@ -463,17 +463,17 @@ nsObjectFrame::CreateWidget(nscoord aWid
     initData.clipChildren = true;
     initData.clipSiblings = true;
     // We want mWidget to be able to deliver events to us, especially on
     // Mac where events to the plugin are routed through Gecko. So we
     // allow the view to attach its event handler to mWidget even though
     // mWidget isn't the view's designated widget.
     EVENT_CALLBACK eventHandler = mInnerView->AttachWidgetEventHandler(mWidget);
     rv = mWidget->Create(parentWidget, nsnull, nsIntRect(0,0,0,0),
-                         eventHandler, dx, nsnull, &initData);
+                         eventHandler, dx, &initData);
     if (NS_FAILED(rv)) {
       mWidget->Destroy();
       mWidget = nsnull;
       return rv;
     }
 
     mWidget->EnableDragDrop(true);
 
--- a/toolkit/components/remote/nsGTKRemoteService.cpp
+++ b/toolkit/components/remote/nsGTKRemoteService.cpp
@@ -108,34 +108,16 @@ static nsIWidget* GetMainWidget(nsIDOMWi
     (do_QueryInterface(window->GetDocShell()));
   NS_ENSURE_TRUE(baseWindow, nsnull);
 
   nsCOMPtr<nsIWidget> mainWidget;
   baseWindow->GetMainWidget(getter_AddRefs(mainWidget));
   return mainWidget;
 }
 
-static nsGTKToolkit* GetGTKToolkit()
-{
-  nsCOMPtr<nsIAppShellService> svc = do_GetService(NS_APPSHELLSERVICE_CONTRACTID);
-  if (!svc)
-    return nsnull;
-  nsCOMPtr<nsIDOMWindow> window;
-  svc->GetHiddenDOMWindow(getter_AddRefs(window));
-  if (!window)
-    return nsnull;
-  nsIWidget* widget = GetMainWidget(window);
-  if (!widget)
-    return nsnull;
-  nsIToolkit* toolkit = widget->GetToolkit();
-  if (!toolkit)
-    return nsnull;
-  return static_cast<nsGTKToolkit*>(toolkit);
-}
-
 NS_IMETHODIMP
 nsGTKRemoteService::RegisterWindow(nsIDOMWindow* aWindow)
 {
   nsIWidget* mainWidget = GetMainWidget(aWindow);
   NS_ENSURE_TRUE(mainWidget, NS_ERROR_FAILURE);
 
   // walk up the widget tree and find the toplevel window in the
   // hierarchy
@@ -182,17 +164,17 @@ nsGTKRemoteService::Shutdown()
 // Set desktop startup ID to the passed ID, if there is one, so that any created
 // windows get created with the right window manager metadata, and any windows
 // that get new tabs and are activated also get the right WM metadata.
 // If there is no desktop startup ID, then use the X event's timestamp
 // for _NET_ACTIVE_WINDOW when the window gets focused or shown.
 void
 nsGTKRemoteService::SetDesktopStartupIDOrTimestamp(const nsACString& aDesktopStartupID,
                                                    PRUint32 aTimestamp) {
-  nsGTKToolkit* toolkit = GetGTKToolkit();
+  nsGTKToolkit* toolkit = nsGTKToolkit::GetToolkit();
   if (!toolkit)
     return;
   if (!aDesktopStartupID.IsEmpty()) {
     toolkit->SetDesktopStartupID(aDesktopStartupID);
   } else {
     toolkit->SetFocusTimestamp(aTimestamp);
   }
 }
--- a/toolkit/xre/nsAppRunner.cpp
+++ b/toolkit/xre/nsAppRunner.cpp
@@ -2434,49 +2434,16 @@ static PRFuncPtr FindFunction(const char
   PRFuncPtr result = PR_FindFunctionSymbolAndLibrary(aName, &lib);
   // Since the library was already loaded, we can safely unload it here.
   if (lib) {
     PR_UnloadLibrary(lib);
   }
   return result;
 }
 
-static nsIWidget* GetMainWidget(nsIDOMWindow* aWindow)
-{
-  // get the native window for this instance
-  nsCOMPtr<nsPIDOMWindow> window(do_QueryInterface(aWindow));
-  NS_ENSURE_TRUE(window, nsnull);
-
-  nsCOMPtr<nsIBaseWindow> baseWindow
-    (do_QueryInterface(window->GetDocShell()));
-  NS_ENSURE_TRUE(baseWindow, nsnull);
-
-  nsCOMPtr<nsIWidget> mainWidget;
-  baseWindow->GetMainWidget(getter_AddRefs(mainWidget));
-  return mainWidget;
-}
-
-static nsGTKToolkit* GetGTKToolkit()
-{
-  nsCOMPtr<nsIAppShellService> svc = do_GetService(NS_APPSHELLSERVICE_CONTRACTID);
-  if (!svc)
-    return nsnull;
-  nsCOMPtr<nsIDOMWindow> window;
-  svc->GetHiddenDOMWindow(getter_AddRefs(window));
-  if (!window)
-    return nsnull;
-  nsIWidget* widget = GetMainWidget(window);
-  if (!widget)
-    return nsnull;
-  nsIToolkit* toolkit = widget->GetToolkit();
-  if (!toolkit)
-    return nsnull;
-  return static_cast<nsGTKToolkit*>(toolkit);
-}
-
 static void MOZ_gdk_display_close(GdkDisplay *display)
 {
   // XXX wallpaper for bug 417163: don't close the Display if we're using the
   // Qt theme because we crash (in Qt code) when using jemalloc.
   bool theme_is_qt = false;
   GtkSettings* settings =
     gtk_settings_get_for_screen(gdk_display_get_default_screen(display));
   gchar *theme_name;
@@ -3496,17 +3463,17 @@ XRE_main(int argc, char* argv[], const n
 
         if (!shuttingDown) {
           NS_TIME_FUNCTION_MARK("Next: CreateHiddenWindow");
 
           rv = appStartup->CreateHiddenWindow();
           NS_ENSURE_SUCCESS(rv, 1);
 
 #if defined(HAVE_DESKTOP_STARTUP_ID) && defined(MOZ_WIDGET_GTK2)
-          nsRefPtr<nsGTKToolkit> toolkit = GetGTKToolkit();
+          nsGTKToolkit* toolkit = nsGTKToolkit::GetToolkit();
           if (toolkit && !desktopStartupID.IsEmpty()) {
             toolkit->SetDesktopStartupID(desktopStartupID);
           }
           // Clear the environment variable so it won't be inherited by
           // child processes and confuse things.
           g_unsetenv ("DESKTOP_STARTUP_ID");
 #endif
 
--- a/view/src/nsView.cpp
+++ b/view/src/nsView.cpp
@@ -732,17 +732,17 @@ nsresult nsView::CreateWidget(nsWidgetIn
   if (!parentWidget) {
     NS_ERROR("nsView::CreateWidget without suitable parent widget??");
     return NS_ERROR_FAILURE;
   }
 
   // XXX: using aForceUseIWidgetParent=true to preserve previous
   // semantics.  It's not clear that it's actually needed.
   mWindow = parentWidget->CreateChild(trect, ::HandleEvent,
-                                      dx, nsnull, aWidgetInitData,
+                                      dx, aWidgetInitData,
                                       true).get();
   if (!mWindow) {
     return NS_ERROR_FAILURE;
   }
  
   InitializeWindow(aEnableDragDrop, aResetVisibility);
 
   return NS_OK;
@@ -764,17 +764,17 @@ nsresult nsView::CreateWidgetForParent(n
 
   nsIntRect trect = CalcWidgetBounds(aWidgetInitData->mWindowType);
 
   nsRefPtr<nsDeviceContext> dx;
   mViewManager->GetDeviceContext(*getter_AddRefs(dx));
 
   mWindow =
     aParentWidget->CreateChild(trect, ::HandleEvent,
-                               dx, nsnull, aWidgetInitData).get();
+                               dx, aWidgetInitData).get();
   if (!mWindow) {
     return NS_ERROR_FAILURE;
   }
 
   InitializeWindow(aEnableDragDrop, aResetVisibility);
 
   return NS_OK;
 }
@@ -797,31 +797,31 @@ nsresult nsView::CreateWidgetForPopup(ns
   // XXX/cjones: having these two separate creation cases seems ... um
   // ... unnecessary, but it's the way the old code did it.  Please
   // unify them by first finding a suitable parent nsIWidget, then
   // getting rid of aForceUseIWidgetParent.
   if (aParentWidget) {
     // XXX: using aForceUseIWidgetParent=true to preserve previous
     // semantics.  It's not clear that it's actually needed.
     mWindow = aParentWidget->CreateChild(trect, ::HandleEvent,
-                                         dx, nsnull, aWidgetInitData,
+                                         dx, aWidgetInitData,
                                          true).get();
   }
   else {
     nsIWidget* nearestParent = GetParent() ? GetParent()->GetNearestWidget(nsnull)
                                            : nsnull;
     if (!nearestParent) {
       // Without a parent, we can't make a popup.  This can happen
       // when printing
       return NS_ERROR_FAILURE;
     }
 
     mWindow =
       nearestParent->CreateChild(trect, ::HandleEvent,
-                                 dx, nsnull, aWidgetInitData).get();
+                                 dx, aWidgetInitData).get();
   }
   if (!mWindow) {
     return NS_ERROR_FAILURE;
   }
 
   InitializeWindow(aEnableDragDrop, aResetVisibility);
 
   return NS_OK;
--- a/widget/public/Makefile.in
+++ b/widget/public/Makefile.in
@@ -100,17 +100,16 @@ EXPORTS		+= \
 		nsIDragSessionGTK.h \
 		nsIPrintDialogService.h \
 		$(NULL)
 endif
 
 XPIDLSRCS	= \
 		nsIAppShell.idl \
 		nsIFilePicker.idl \
-		nsIToolkit.idl \
 		nsISound.idl \
 		nsITransferable.idl \
 		nsIClipboardDragDropHooks.idl \
 		nsIClipboardDragDropHookList.idl \
 		nsIDragSession.idl \
 		nsIDragService.idl \
 		nsIFormatConverter.idl \
 		nsIClipboard.idl \
deleted file mode 100644
--- a/widget/public/nsIToolkit.idl
+++ /dev/null
@@ -1,66 +0,0 @@
-/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*-
- *
- * ***** BEGIN LICENSE BLOCK *****
- * Version: MPL 1.1/GPL 2.0/LGPL 2.1
- *
- * The contents of this file are subject to the Mozilla Public License Version
- * 1.1 (the "License"); you may not use this file except in compliance with
- * the License. You may obtain a copy of the License at
- * http://www.mozilla.org/MPL/
- *
- * Software distributed under the License is distributed on an "AS IS" basis,
- * WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
- * for the specific language governing rights and limitations under the
- * License.
- *
- * The Original Code is the Mozilla browser.
- *
- * The Initial Developer of the Original Code is
- * Netscape Communications Corporation.
- * Portions created by the Initial Developer are Copyright (C) 1999
- * the Initial Developer. All Rights Reserved.
- *
- * Contributor(s):
- *   Stuart Parmenter <pavlov@netscape.com>
- *
- * Alternatively, the contents of this file may be used under the terms of
- * either the GNU General Public License Version 2 or later (the "GPL"), or
- * the GNU Lesser General Public License Version 2.1 or later (the "LGPL"),
- * in which case the provisions of the GPL or the LGPL are applicable instead
- * of those above. If you wish to allow use of your version of this file only
- * under the terms of either the GPL or the LGPL, and not to allow others to
- * use your version of this file under the terms of the MPL, indicate your
- * decision by deleting the provisions above and replace them with the notice
- * and other provisions required by the GPL or the LGPL. If you do not delete
- * the provisions above, a recipient may use your version of this file under
- * the terms of any one of the MPL, the GPL or the LGPL.
- *
- * ***** END LICENSE BLOCK ***** */
-
-#include "nsISupports.idl"
-
-%{ C++
-#include "prthread.h"
-%}
-
-[ptr] native PRThread(PRThread);
-
-
-[uuid(18032BD0-B265-11d1-AA2A-000000000000)]
-interface nsIToolkit : nsISupports
-{
-  /**
-   * Initialize this toolkit with aThread. 
-   * @param aThread The thread passed in runs the message pump.
-   *  NULL can be passed in, in which case a new thread gets created
-   *  and a message pump will run in that thread
-   *
-   */
-  void Init(in PRThread aThread);
-
-};
-
-
-%{ C++
-extern NS_METHOD NS_GetCurrentToolkit(nsIToolkit* *aResult);
-%}
--- a/widget/public/nsIWidget.h
+++ b/widget/public/nsIWidget.h
@@ -52,17 +52,16 @@
 #include "nsCOMPtr.h"
 #include "nsITheme.h"
 #include "nsNativeWidget.h"
 #include "nsWidgetInitData.h"
 #include "nsTArray.h"
 #include "nsXULAppAPI.h"
 
 // forward declarations
-class   nsIToolkit;
 class   nsFontMetrics;
 class   nsRenderingContext;
 class   nsDeviceContext;
 struct  nsFont;
 class   nsIRollupListener;
 class   nsIMenuRollup;
 class   nsGUIEvent;
 class   imgIContainer;
@@ -115,18 +114,18 @@ typedef nsEventStatus (* EVENT_CALLBACK)
 #endif
 #ifdef XP_WIN
 #define NS_NATIVE_TSF_THREAD_MGR       100
 #define NS_NATIVE_TSF_CATEGORY_MGR     101
 #define NS_NATIVE_TSF_DISPLAY_ATTR_MGR 102
 #endif
 
 #define NS_IWIDGET_IID \
-  { 0x64e1ee3d, 0xe0f2, 0x4ace, \
-    { 0x91, 0xb7, 0xdc, 0xd1, 0xbe, 0x69, 0xb6, 0xe6 } }
+  { 0x712b07a4, 0x4344, 0x4404, \
+    { 0xaf, 0x85, 0x63, 0x3d, 0x68, 0x0b, 0x21, 0xb0 } }
 
 /*
  * Window shadow styles
  * Also used for the -moz-window-shadow CSS property
  */
 
 #define NS_STYLE_WINDOW_SHADOW_NONE             0
 #define NS_STYLE_WINDOW_SHADOW_DEFAULT          1
@@ -320,26 +319,24 @@ class nsIWidget : public nsISupports {
      * both are null the widget isn't parented (e.g. context menus or
      * independent top level windows).
      *
      * @param     aParent       parent nsIWidget
      * @param     aNativeParent native parent widget
      * @param     aRect         the widget dimension
      * @param     aHandleEventFunction the event handler callback function
      * @param     aContext
-     * @param     aToolkit
      * @param     aInitData     data that is used for widget initialization
      *
      */
     NS_IMETHOD Create(nsIWidget        *aParent,
                       nsNativeWidget   aNativeParent,
                       const nsIntRect  &aRect,
                       EVENT_CALLBACK   aHandleEventFunction,
                       nsDeviceContext *aContext,
-                      nsIToolkit       *aToolkit = nsnull,
                       nsWidgetInitData *aInitData = nsnull) = 0;
 
     /**
      * Allocate, initialize, and return a widget that is a child of
      * |this|.  The returned widget (if nonnull) has gone through the
      * equivalent of CreateInstance(widgetCID) + Create(...).
      *
      * |CreateChild()| lets widget backends decide whether to parent
@@ -351,18 +348,17 @@ class nsIWidget : public nsISupports {
      * |aForceUseIWidgetParent| forces |CreateChild()| to only use the
      * |nsIWidget*| this, not its native widget (if it exists), when
      * calling |Create()|.  This is a timid hack around poorly
      * understood code, and shouldn't be used in new code.
      */
     virtual already_AddRefed<nsIWidget>
     CreateChild(const nsIntRect  &aRect,
                 EVENT_CALLBACK   aHandleEventFunction,
-                nsDeviceContext *aContext,
-                nsIToolkit       *aToolkit = nsnull,
+                nsDeviceContext  *aContext,
                 nsWidgetInitData *aInitData = nsnull,
                 bool             aForceUseIWidgetParent = false) = 0;
 
     /**
      * Attach to a top level widget. 
      *
      * In cases where a top level chrome widget is being used as a content
      * container, attach a secondary event callback and update the device
@@ -880,26 +876,16 @@ class nsIWidget : public nsISupports {
     /**
      * Force a synchronous repaint of the window if there are dirty rects.
      *
      * @see Invalidate()
      */
 
      NS_IMETHOD Update() = 0;
 
-    /**
-     * Return the widget's toolkit
-     *
-     * An AddRef has NOT been done for the caller.
-     *
-     * @return the toolkit this widget was created in. See nsToolkit.
-     */
-
-    virtual nsIToolkit* GetToolkit() = 0;    
-
     enum LayerManagerPersistence
     {
       LAYER_MANAGER_CURRENT = 0,
       LAYER_MANAGER_PERSISTENT
     };
 
     /**
      * Return the widget's LayerManager. The layer tree for that
--- a/widget/src/android/Makefile.in
+++ b/widget/src/android/Makefile.in
@@ -50,17 +50,16 @@ MODULE_NAME     = nsWidgetAndroidModule
 GRE_MODULE      = 1
 LIBXUL_LIBRARY  = 1
 
 
 CPPSRCS	= \
 	GfxInfo.cpp \
 	nsWidgetFactory.cpp \
 	nsAppShell.cpp \
-	nsToolkit.cpp \
 	AndroidJavaWrappers.cpp \
 	AndroidBridge.cpp \
 	AndroidJNI.cpp \
 	nsWindow.cpp \
 	nsLookAndFeel.cpp \
 	nsScreenManagerAndroid.cpp \
 	nsIdleServiceAndroid.cpp \
 	nsClipboard.cpp \
deleted file mode 100644
--- a/widget/src/android/nsToolkit.cpp
+++ /dev/null
@@ -1,97 +0,0 @@
-/* -*- Mode: C++; tab-width: 40; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
-/* ***** BEGIN LICENSE BLOCK *****
- * Version: MPL 1.1/GPL 2.0/LGPL 2.1
- *
- * The contents of this file are subject to the Mozilla Public License Version
- * 1.1 (the "License"); you may not use this file except in compliance with
- * the License. You may obtain a copy of the License at
- * http://www.mozilla.org/MPL/
- *
- * Software distributed under the License is distributed on an "AS IS" basis,
- * WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
- * for the specific language governing rights and limitations under the
- * License.
- *
- * The Original Code is mozilla.org code.
- *
- * The Initial Developer of the Original Code is
- *   Mozilla Foundation
- * Portions created by the Initial Developer are Copyright (C) 2009-2010
- * the Initial Developer. All Rights Reserved.
- *
- * Contributor(s):
- *   Vladimir Vukicevic <vladimir@pobox.com>
- *
- * Alternatively, the contents of this file may be used under the terms of
- * either the GNU General Public License Version 2 or later (the "GPL"), or
- * the GNU Lesser General Public License Version 2.1 or later (the "LGPL"),
- * in which case the provisions of the GPL or the LGPL are applicable instead
- * of those above. If you wish to allow use of your version of this file only
- * under the terms of either the GPL or the LGPL, and not to allow others to
- * use your version of this file under the terms of the MPL, indicate your
- * decision by deleting the provisions above and replace them with the notice
- * and other provisions required by the GPL or the LGPL. If you do not delete
- * the provisions above, a recipient may use your version of this file under
- * the terms of any one of the MPL, the GPL or the LGPL.
- *
- * ***** END LICENSE BLOCK ***** */
-
-#include "nsToolkit.h"
-#include "nsGUIEvent.h"
-#include "nsGkAtoms.h"
-
-NS_IMPL_ISUPPORTS1(nsToolkit, nsIToolkit)
-
-// why do we have this?
-static PRUintn gToolkitTLSIndex = 0;
-
-nsToolkit::nsToolkit()
-{
-    MOZ_COUNT_CTOR(nsToolkit);
-}
-
-nsToolkit::~nsToolkit()
-{
-    MOZ_COUNT_DTOR(nsToolkit);
-    PR_SetThreadPrivate(gToolkitTLSIndex, nsnull);
-}
-
-NS_IMETHODIMP
-nsToolkit::Init(PRThread *aThread)
-{
-    return NS_OK;
-}
-
-NS_METHOD
-NS_GetCurrentToolkit(nsIToolkit* *aResult)
-{
-    nsCOMPtr<nsIToolkit> toolkit = nsnull;
-    nsresult rv = NS_OK;
-    PRStatus status;
-
-    if (gToolkitTLSIndex == 0) {
-        status = PR_NewThreadPrivateIndex(&gToolkitTLSIndex, NULL);
-        if (PR_FAILURE == status)
-            rv = NS_ERROR_FAILURE;
-    }
-
-    if (NS_FAILED(rv))
-        return rv;
-
-    toolkit = (nsIToolkit*) PR_GetThreadPrivate(gToolkitTLSIndex);
-    if (!toolkit) {
-        toolkit = new nsToolkit();
-
-        if (toolkit) {
-            toolkit->Init(PR_GetCurrentThread());
-
-            PR_SetThreadPrivate(gToolkitTLSIndex, (void*)toolkit.get());
-        } else {
-            rv = NS_ERROR_OUT_OF_MEMORY;
-        }
-    }
-
-    NS_IF_ADDREF(*aResult = toolkit);
-
-    return rv;
-}
deleted file mode 100644
--- a/widget/src/android/nsToolkit.h
+++ /dev/null
@@ -1,57 +0,0 @@
-/* -*- Mode: c++; tab-width: 40; indent-tabs-mode: nil; c-basic-offset: 4; -*- */
-/* ***** BEGIN LICENSE BLOCK *****
- * Version: MPL 1.1/GPL 2.0/LGPL 2.1
- *
- * The contents of this file are subject to the Mozilla Public License Version
- * 1.1 (the "License"); you may not use this file except in compliance with
- * the License. You may obtain a copy of the License at
- * http://www.mozilla.org/MPL/
- *
- * Software distributed under the License is distributed on an "AS IS" basis,
- * WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
- * for the specific language governing rights and limitations under the
- * License.
- *
- * The Original Code is mozilla.org code.
- *
- * The Initial Developer of the Original Code is
- *   Mozilla Foundation
- * Portions created by the Initial Developer are Copyright (C) 2009-2010
- * the Initial Developer. All Rights Reserved.
- *
- * Contributor(s):
- *   Vladimir Vukicevic <vladimir@pobox.com>
- *
- * Alternatively, the contents of this file may be used under the terms of
- * either the GNU General Public License Version 2 or later (the "GPL"), or
- * the GNU Lesser General Public License Version 2.1 or later (the "LGPL"),
- * in which case the provisions of the GPL or the LGPL are applicable instead
- * of those above. If you wish to allow use of your version of this file only
- * under the terms of either the GPL or the LGPL, and not to allow others to
- * use your version of this file under the terms of the MPL, indicate your
- * decision by deleting the provisions above and replace them with the notice
- * and other provisions required by the GPL or the LGPL. If you do not delete
- * the provisions above, a recipient may use your version of this file under
- * the terms of any one of the MPL, the GPL or the LGPL.
- *
- * ***** END LICENSE BLOCK ***** */
-
-#ifndef nsToolkit_h__
-#define nsToolkit_h__
-
-#include <nsIToolkit.h>
-
-class nsToolkit :
-    public nsIToolkit
-{
-public:
-    NS_DECL_ISUPPORTS
-
-    // nsIToolkit
-    NS_IMETHOD Init(PRThread *aThread);
-
-    nsToolkit();
-    virtual ~nsToolkit();
-};
-
-#endif /* nsToolkit_h__ */
--- a/widget/src/android/nsWidgetFactory.cpp
+++ b/widget/src/android/nsWidgetFactory.cpp
@@ -36,17 +36,16 @@
  *
  * ***** END LICENSE BLOCK ***** */
 
 #include "mozilla/ModuleUtils.h"
 
 #include "nsCOMPtr.h"
 #include "nsWidgetsCID.h"
 #include "nsAppShell.h"
-#include "nsToolkit.h"
 
 #include "nsWindow.h"
 #include "nsLookAndFeel.h"
 #include "nsAppShellSingleton.h"
 #include "nsScreenManagerAndroid.h"
 
 #include "nsIdleServiceAndroid.h"
 #include "nsClipboard.h"
@@ -56,17 +55,16 @@
 #include "nsPrintSession.h"
 #include "nsDeviceContextAndroid.h"
 #include "nsFilePicker.h"
 #include "nsHTMLFormatConverter.h"
 #include "nsIMEPicker.h"
 #include "nsFilePickerProxy.h"
 #include "nsXULAppAPI.h"
 
-NS_GENERIC_FACTORY_CONSTRUCTOR(nsToolkit)
 NS_GENERIC_FACTORY_CONSTRUCTOR(nsWindow)
 NS_GENERIC_FACTORY_CONSTRUCTOR(nsScreenManagerAndroid)
 NS_GENERIC_FACTORY_CONSTRUCTOR(nsIdleServiceAndroid)
 NS_GENERIC_FACTORY_CONSTRUCTOR(nsTransferable)
 NS_GENERIC_FACTORY_CONSTRUCTOR(nsClipboard)
 NS_GENERIC_FACTORY_CONSTRUCTOR(nsClipboardHelper)
 NS_GENERIC_FACTORY_CONSTRUCTOR_INIT(nsPrintOptionsAndroid, Init)
 NS_GENERIC_FACTORY_CONSTRUCTOR_INIT(nsPrintSession, Init)
@@ -95,17 +93,16 @@ nsFilePickerConstructor(nsISupports *aOu
   if (XRE_GetProcessType() == GeckoProcessType_Content)
     picker = new nsFilePickerProxy();
   else
     picker = new nsFilePicker;
 
   return picker->QueryInterface(aIID, aResult);
 }
 
-NS_DEFINE_NAMED_CID(NS_TOOLKIT_CID);
 NS_DEFINE_NAMED_CID(NS_APPSHELL_CID);
 NS_DEFINE_NAMED_CID(NS_WINDOW_CID);
 NS_DEFINE_NAMED_CID(NS_CHILD_CID);
 NS_DEFINE_NAMED_CID(NS_SCREENMANAGER_CID);
 NS_DEFINE_NAMED_CID(NS_IDLE_SERVICE_CID);
 NS_DEFINE_NAMED_CID(NS_TRANSFERABLE_CID);
 NS_DEFINE_NAMED_CID(NS_CLIPBOARD_CID);
 NS_DEFINE_NAMED_CID(NS_CLIPBOARDHELPER_CID);
@@ -116,17 +113,16 @@ NS_DEFINE_NAMED_CID(NS_FILEPICKER_CID);
 NS_DEFINE_NAMED_CID(NS_HTMLFORMATCONVERTER_CID);
 NS_DEFINE_NAMED_CID(NS_IMEPICKER_CID);
 NS_DEFINE_NAMED_CID(NS_GFXINFO_CID);
 
 static const mozilla::Module::CIDEntry kWidgetCIDs[] = {
   { &kNS_WINDOW_CID, false, NULL, nsWindowConstructor },
   { &kNS_CHILD_CID, false, NULL, nsWindowConstructor },
   { &kNS_APPSHELL_CID, false, NULL, nsAppShellConstructor },
-  { &kNS_TOOLKIT_CID, false, NULL, nsToolkitConstructor },
   { &kNS_SCREENMANAGER_CID, false, NULL, nsScreenManagerAndroidConstructor },
   { &kNS_IDLE_SERVICE_CID, false, NULL, nsIdleServiceAndroidConstructor },
   { &kNS_TRANSFERABLE_CID, false, NULL, nsTransferableConstructor },
   { &kNS_CLIPBOARD_CID, false, NULL, nsClipboardConstructor },
   { &kNS_CLIPBOARDHELPER_CID, false, NULL, nsClipboardHelperConstructor },
   { &kNS_PRINTSETTINGSSERVICE_CID, false, NULL, nsPrintOptionsAndroidConstructor },
   { &kNS_PRINTSESSION_CID, false, NULL, nsPrintSessionConstructor },
   { &kNS_DEVICE_CONTEXT_SPEC_CID, false, NULL, nsDeviceContextSpecAndroidConstructor },
@@ -136,17 +132,16 @@ static const mozilla::Module::CIDEntry k
   { &kNS_GFXINFO_CID, false, NULL, mozilla::widget::GfxInfoConstructor },
   { NULL }
 };
 
 static const mozilla::Module::ContractIDEntry kWidgetContracts[] = {
   { "@mozilla.org/widgets/window/android;1", &kNS_WINDOW_CID },
   { "@mozilla.org/widgets/child_window/android;1", &kNS_CHILD_CID },
   { "@mozilla.org/widget/appshell/android;1", &kNS_APPSHELL_CID },
-  { "@mozilla.org/widget/toolkit/android;1", &kNS_TOOLKIT_CID },
   { "@mozilla.org/gfx/screenmanager;1", &kNS_SCREENMANAGER_CID },
   { "@mozilla.org/widget/idleservice;1", &kNS_IDLE_SERVICE_CID },
   { "@mozilla.org/widget/transferable;1", &kNS_TRANSFERABLE_CID },
   { "@mozilla.org/widget/clipboard;1", &kNS_CLIPBOARD_CID },
   { "@mozilla.org/widget/clipboardhelper;1", &kNS_CLIPBOARDHELPER_CID },
   { "@mozilla.org/gfx/printsettings-service;1", &kNS_PRINTSETTINGSSERVICE_CID },
   { "@mozilla.org/gfx/printsession;1", &kNS_PRINTSESSION_CID },
   { "@mozilla.org/gfx/devicecontextspec;1", &kNS_DEVICE_CONTEXT_SPEC_CID },
--- a/widget/src/android/nsWindow.cpp
+++ b/widget/src/android/nsWindow.cpp
@@ -197,17 +197,16 @@ nsWindow::IsTopLevel()
 }
 
 NS_IMETHODIMP
 nsWindow::Create(nsIWidget *aParent,
                  nsNativeWidget aNativeParent,
                  const nsIntRect &aRect,
                  EVENT_CALLBACK aHandleEventFunction,
                  nsDeviceContext *aContext,
-                 nsIToolkit *aToolkit,
                  nsWidgetInitData *aInitData)
 {
     ALOG("nsWindow[%p]::Create %p [%d %d %d %d]", (void*)this, (void*)aParent, aRect.x, aRect.y, aRect.width, aRect.height);
     nsWindow *parent = (nsWindow*) aParent;
 
     if (!AndroidBridge::Bridge()) {
         aNativeParent = nsnull;
     }
@@ -225,18 +224,17 @@ nsWindow::Create(nsIWidget *aParent,
     // for toplevel windows, bounds are fixed to full screen size
     if (!parent) {
         mBounds.x = 0;
         mBounds.y = 0;
         mBounds.width = gAndroidBounds.width;
         mBounds.height = gAndroidBounds.height;
     }
 
-    BaseCreate(nsnull, mBounds, aHandleEventFunction, aContext,
-               aToolkit, aInitData);
+    BaseCreate(nsnull, mBounds, aHandleEventFunction, aContext, aInitData);
 
     NS_ASSERTION(IsTopLevel() || parent, "non top level windowdoesn't have a parent!");
 
     if (IsTopLevel()) {
         gTopLevelWindows.AppendElement(this);
     }
 
     if (parent) {
--- a/widget/src/android/nsWindow.h
+++ b/widget/src/android/nsWindow.h
@@ -82,17 +82,16 @@ public:
     // nsIWidget
     //
 
     NS_IMETHOD Create(nsIWidget *aParent,
                       nsNativeWidget aNativeParent,
                       const nsIntRect &aRect,
                       EVENT_CALLBACK aHandleEventFunction,
                       nsDeviceContext *aContext,
-                      nsIToolkit *aToolkit,
                       nsWidgetInitData *aInitData);
     NS_IMETHOD Destroy(void);
     NS_IMETHOD ConfigureChildren(const nsTArray<nsIWidget::Configuration>&);
     NS_IMETHOD SetParent(nsIWidget* aNewParent);
     virtual nsIWidget *GetParent(void);
     virtual float GetDPI();
     NS_IMETHOD Show(bool aState);
     NS_IMETHOD SetModal(bool aModal);
--- a/widget/src/build/nsWinWidgetFactory.cpp
+++ b/widget/src/build/nsWinWidgetFactory.cpp
@@ -47,22 +47,22 @@
 #include "nsFilePicker.h"
 #include "mozilla/ModuleUtils.h"
 #include "nsIServiceManager.h"
 #include "nsIdleServiceWin.h"
 #include "nsLookAndFeel.h"
 #include "nsNativeThemeWin.h"
 #include "nsScreenManagerWin.h"
 #include "nsSound.h"
-#include "nsToolkit.h"
 #include "nsWindow.h"
 #include "WinTaskbar.h"
 #include "JumpListBuilder.h"
 #include "JumpListItem.h"
 #include "GfxInfo.h"
+#include "nsToolkit.h"
 
 // Drag & Drop, Clipboard
 
 #include "nsClipboardHelper.h"
 
 #include "nsClipboard.h"
 #include "nsBidiKeyboard.h"
 #include "nsDragService.h"
@@ -75,17 +75,16 @@
 #include "nsPrintSession.h"
 #endif
 
 using namespace mozilla::widget;
 
 NS_GENERIC_FACTORY_CONSTRUCTOR(nsWindow)
 NS_GENERIC_FACTORY_CONSTRUCTOR(ChildWindow)
 NS_GENERIC_FACTORY_CONSTRUCTOR(nsFilePicker)
-NS_GENERIC_FACTORY_CONSTRUCTOR(nsToolkit)
 NS_GENERIC_FACTORY_CONSTRUCTOR(nsScreenManagerWin)
 NS_GENERIC_FACTORY_CONSTRUCTOR(nsIdleServiceWin)
 NS_GENERIC_FACTORY_CONSTRUCTOR(nsClipboard)
 NS_GENERIC_FACTORY_CONSTRUCTOR(nsClipboardHelper)
 NS_GENERIC_FACTORY_CONSTRUCTOR(nsSound)
 
 #if MOZ_WINSDK_TARGETVER >= MOZ_NTDDI_WIN7
 NS_GENERIC_FACTORY_CONSTRUCTOR(WinTaskbar)
@@ -114,17 +113,16 @@ NS_GENERIC_FACTORY_CONSTRUCTOR(nsPrinter
 NS_GENERIC_FACTORY_CONSTRUCTOR_INIT(nsPrintSession, Init)
 NS_GENERIC_FACTORY_CONSTRUCTOR(nsDeviceContextSpecWin)
 #endif
 
 NS_DEFINE_NAMED_CID(NS_WINDOW_CID);
 NS_DEFINE_NAMED_CID(NS_CHILD_CID);
 NS_DEFINE_NAMED_CID(NS_FILEPICKER_CID);
 NS_DEFINE_NAMED_CID(NS_APPSHELL_CID);
-NS_DEFINE_NAMED_CID(NS_TOOLKIT_CID);
 NS_DEFINE_NAMED_CID(NS_SCREENMANAGER_CID);
 NS_DEFINE_NAMED_CID(NS_GFXINFO_CID);
 NS_DEFINE_NAMED_CID(NS_THEMERENDERER_CID);
 NS_DEFINE_NAMED_CID(NS_IDLE_SERVICE_CID);
 NS_DEFINE_NAMED_CID(NS_CLIPBOARD_CID);
 NS_DEFINE_NAMED_CID(NS_CLIPBOARDHELPER_CID);
 NS_DEFINE_NAMED_CID(NS_SOUND_CID);
 NS_DEFINE_NAMED_CID(NS_TRANSFERABLE_CID);
@@ -150,17 +148,16 @@ NS_DEFINE_NAMED_CID(NS_DEVICE_CONTEXT_SP
 #endif
 
 
 static const mozilla::Module::CIDEntry kWidgetCIDs[] = {
   { &kNS_WINDOW_CID, false, NULL, nsWindowConstructor },
   { &kNS_CHILD_CID, false, NULL, ChildWindowConstructor },
   { &kNS_FILEPICKER_CID, false, NULL, nsFilePickerConstructor },
   { &kNS_APPSHELL_CID, false, NULL, nsAppShellConstructor },
-  { &kNS_TOOLKIT_CID, false, NULL, nsToolkitConstructor },
   { &kNS_SCREENMANAGER_CID, false, NULL, nsScreenManagerWinConstructor },
   { &kNS_GFXINFO_CID, false, NULL, GfxInfoConstructor },
   { &kNS_THEMERENDERER_CID, false, NULL, NS_NewNativeTheme },
   { &kNS_IDLE_SERVICE_CID, false, NULL, nsIdleServiceWinConstructor },
   { &kNS_CLIPBOARD_CID, false, NULL, nsClipboardConstructor },
   { &kNS_CLIPBOARDHELPER_CID, false, NULL, nsClipboardHelperConstructor },
   { &kNS_SOUND_CID, false, NULL, nsSoundConstructor },
   { &kNS_TRANSFERABLE_CID, false, NULL, nsTransferableConstructor },
@@ -184,17 +181,16 @@ static const mozilla::Module::CIDEntry k
   { NULL }
 };
 
 static const mozilla::Module::ContractIDEntry kWidgetContracts[] = {
   { "@mozilla.org/widgets/window/win;1", &kNS_WINDOW_CID },
   { "@mozilla.org/widgets/child_window/win;1", &kNS_CHILD_CID },
   { "@mozilla.org/filepicker;1", &kNS_FILEPICKER_CID },
   { "@mozilla.org/widget/appshell/win;1", &kNS_APPSHELL_CID },
-  { "@mozilla.org/widget/toolkit/win;1", &kNS_TOOLKIT_CID },
   { "@mozilla.org/gfx/screenmanager;1", &kNS_SCREENMANAGER_CID },
   { "@mozilla.org/gfx/info;1", &kNS_GFXINFO_CID },
   { "@mozilla.org/chrome/chrome-native-theme;1", &kNS_THEMERENDERER_CID },
   { "@mozilla.org/widget/idleservice;1", &kNS_IDLE_SERVICE_CID },
   { "@mozilla.org/widget/clipboard;1", &kNS_CLIPBOARD_CID },
   { "@mozilla.org/widget/clipboardhelper;1", &kNS_CLIPBOARDHELPER_CID },
   { "@mozilla.org/sound;1", &kNS_SOUND_CID },
   { "@mozilla.org/widget/transferable;1", &kNS_TRANSFERABLE_CID },
@@ -217,16 +213,17 @@ static const mozilla::Module::ContractID
 #endif
   { NULL }
 };
 
 static void
 nsWidgetWindowsModuleDtor()
 {
   nsLookAndFeel::Shutdown();
+  nsToolkit::Shutdown();
   nsAppShellShutdown();
 }
 
 static const mozilla::Module kWidgetModule = {
   mozilla::Module::kVersion,
   kWidgetCIDs,
   kWidgetContracts,
   NULL,
--- a/widget/src/cocoa/nsChildView.h
+++ b/widget/src/cocoa/nsChildView.h
@@ -391,17 +391,16 @@ public:
   NS_DECL_ISUPPORTS_INHERITED
 
   // nsIWidget interface
   NS_IMETHOD              Create(nsIWidget *aParent,
                                  nsNativeWidget aNativeParent,
                                  const nsIntRect &aRect,
                                  EVENT_CALLBACK aHandleEventFunction,
                                  nsDeviceContext *aContext,
-                                 nsIToolkit *aToolkit = nsnull,
                                  nsWidgetInitData *aInitData = nsnull);
 
   NS_IMETHOD              Destroy();
 
   NS_IMETHOD              Show(bool aState);
   NS_IMETHOD              IsVisible(bool& outState);
 
   NS_IMETHOD              SetParent(nsIWidget* aNewParent);
--- a/widget/src/cocoa/nsChildView.mm
+++ b/widget/src/cocoa/nsChildView.mm
@@ -289,17 +289,16 @@ nsChildView::~nsChildView()
 
 NS_IMPL_ISUPPORTS_INHERITED1(nsChildView, nsBaseWidget, nsIPluginWidget)
 
 nsresult nsChildView::Create(nsIWidget *aParent,
                              nsNativeWidget aNativeParent,
                              const nsIntRect &aRect,
                              EVENT_CALLBACK aHandleEventFunction,
                              nsDeviceContext *aContext,
-                             nsIToolkit *aToolkit,
                              nsWidgetInitData *aInitData)
 {
   NS_OBJC_BEGIN_TRY_ABORT_BLOCK_NSRESULT;
 
   // Because the hidden window is created outside of an event loop,
   // we need to provide an autorelease pool to avoid leaking cocoa objects
   // (see bug 559075).
   nsAutoreleasePool localPool;
@@ -320,18 +319,20 @@ nsresult nsChildView::Create(nsIWidget *
 #ifndef NP_NO_CARBON
     TextInputHandler::SwizzleMethods();
 #endif
     gChildViewMethodsSwizzled = true;
   }
 
   mBounds = aRect;
 
-  BaseCreate(aParent, aRect, aHandleEventFunction, 
-             aContext, aToolkit, aInitData);
+  // Ensure that the toolkit is created.
+  nsToolkit::GetToolkit();
+
+  BaseCreate(aParent, aRect, aHandleEventFunction, aContext, aInitData);
 
   // inherit things from the parent view and create our parallel 
   // NSView in the Cocoa display system
   mParentView = nil;
   if (aParent) {
     // This is the case when we're the popup content view of a popup window.
     SetBackgroundColor(aParent->GetBackgroundColor());
     SetForegroundColor(aParent->GetForegroundColor());
--- a/widget/src/cocoa/nsCocoaWindow.h
+++ b/widget/src/cocoa/nsCocoaWindow.h
@@ -211,17 +211,16 @@ public:
     NS_DECL_ISUPPORTS_INHERITED
     NS_DECL_NSPIWIDGETCOCOA
       
     NS_IMETHOD              Create(nsIWidget* aParent,
                                    nsNativeWidget aNativeParent,
                                    const nsIntRect &aRect,
                                    EVENT_CALLBACK aHandleEventFunction,
                                    nsDeviceContext *aContext,
-                                   nsIToolkit *aToolkit = nsnull,
                                    nsWidgetInitData *aInitData = nsnull);
 
     NS_IMETHOD              Destroy();
 
     NS_IMETHOD              Show(bool aState);
     virtual nsIWidget*      GetSheetWindowParent(void);
     NS_IMETHOD              Enable(bool aState);
     NS_IMETHOD              IsEnabled(bool *aState);
@@ -302,18 +301,17 @@ public:
     NS_IMETHOD         ReparentNativeWidget(nsIWidget* aNewParent);
 protected:
 
   nsresult             CreateNativeWindow(const NSRect &aRect,
                                           nsBorderStyle aBorderStyle,
                                           bool aRectIsFrameRect);
   nsresult             CreatePopupContentView(const nsIntRect &aRect,
                                               EVENT_CALLBACK aHandleEventFunction,
-                                              nsDeviceContext *aContext,
-                                              nsIToolkit *aToolkit);
+                                              nsDeviceContext *aContext);
   void                 DestroyNativeWindow();
   void                 AdjustWindowShadow();
   void                 SetUpWindowFilter();
   void                 CleanUpWindowFilter();
   void                 UpdateBounds();
 
   virtual already_AddRefed<nsIWidget>
   AllocateChildPopupWidget()
--- a/widget/src/cocoa/nsCocoaWindow.mm
+++ b/widget/src/cocoa/nsCocoaWindow.mm
@@ -241,17 +241,16 @@ static bool UseNativePopupWindows()
 #endif /* MOZ_USE_NATIVE_POPUP_WINDOWS */
 }
 
 nsresult nsCocoaWindow::Create(nsIWidget *aParent,
                                nsNativeWidget aNativeParent,
                                const nsIntRect &aRect,
                                EVENT_CALLBACK aHandleEventFunction,
                                nsDeviceContext *aContext,
-                               nsIToolkit *aToolkit,
                                nsWidgetInitData *aInitData)
 {
   NS_OBJC_BEGIN_TRY_ABORT_BLOCK_NSRESULT;
 
   // Because the hidden window is created outside of an event loop,
   // we have to provide an autorelease pool (see bug 559075).
   nsAutoreleasePool localPool;
 
@@ -278,34 +277,37 @@ nsresult nsCocoaWindow::Create(nsIWidget
   }
   nsIntRect newBounds = aRect;
   FitRectToVisibleAreaForScreen(newBounds, targetScreen);
 
   // Set defaults which can be overriden from aInitData in BaseCreate
   mWindowType = eWindowType_toplevel;
   mBorderStyle = eBorderStyle_default;
 
+  // Ensure that the toolkit is created.
+  nsToolkit::GetToolkit();
+
   Inherited::BaseCreate(aParent, newBounds, aHandleEventFunction, aContext,
-                        aToolkit, aInitData);
+                        aInitData);
 
   mParent = aParent;
 
   // Applications that use native popups don't want us to create popup windows.
   if ((mWindowType == eWindowType_popup) && UseNativePopupWindows())
     return NS_OK;
 
   nsresult rv = CreateNativeWindow(nsCocoaUtils::GeckoRectToCocoaRect(newBounds),
                                    mBorderStyle, false);
   NS_ENSURE_SUCCESS(rv, rv);
 
   if (mWindowType == eWindowType_popup) {
     if (aInitData->mIsDragPopup) {
       [mWindow setIgnoresMouseEvents:YES];
     }
-    return CreatePopupContentView(newBounds, aHandleEventFunction, aContext, aToolkit);
+    return CreatePopupContentView(newBounds, aHandleEventFunction, aContext);
   }
 
   return NS_OK;
 
   NS_OBJC_END_TRY_ABORT_BLOCK_NSRESULT;
 }
 
 static unsigned int WindowMaskForBorderStyle(nsBorderStyle aBorderStyle)
@@ -472,31 +474,30 @@ nsresult nsCocoaWindow::CreateNativeWind
 
   return NS_OK;
 
   NS_OBJC_END_TRY_ABORT_BLOCK_NSRESULT;
 }
 
 NS_IMETHODIMP nsCocoaWindow::CreatePopupContentView(const nsIntRect &aRect,
                              EVENT_CALLBACK aHandleEventFunction,
-                             nsDeviceContext *aContext,
-                             nsIToolkit *aToolkit)
+                             nsDeviceContext *aContext)
 {
   NS_OBJC_BEGIN_TRY_ABORT_BLOCK_NSRESULT;
 
   // We need to make our content view a ChildView.
   mPopupContentView = new nsChildView();
   if (!mPopupContentView)
     return NS_ERROR_FAILURE;
 
   NS_ADDREF(mPopupContentView);
 
   nsIWidget* thisAsWidget = static_cast<nsIWidget*>(this);
   mPopupContentView->Create(thisAsWidget, nsnull, aRect, aHandleEventFunction,
-                            aContext, aToolkit, nsnull);
+                            aContext, nsnull);
 
   ChildView* newContentView = (ChildView*)mPopupContentView->GetNativeData(NS_NATIVE_WIDGET);
   [mWindow setContentView:newContentView];
 
   return NS_OK;
 
   NS_OBJC_END_TRY_ABORT_BLOCK_NSRESULT;
 }
--- a/widget/src/cocoa/nsToolkit.h
+++ b/widget/src/cocoa/nsToolkit.h
@@ -34,35 +34,39 @@
  * the provisions above, a recipient may use your version of this file under
  * the terms of any one of the MPL, the GPL or the LGPL.
  *
  * ***** END LICENSE BLOCK ***** */
 
 #ifndef nsToolkit_h_
 #define nsToolkit_h_
 
-#include "nsIToolkit.h"
+#include "nscore.h"
 
 #import <Carbon/Carbon.h>
 #import <Cocoa/Cocoa.h>
 #import <objc/Object.h>
 #import <IOKit/IOKitLib.h>
 
 #define MAC_OS_X_VERSION_10_5_HEX 0x00001050
 #define MAC_OS_X_VERSION_10_6_HEX 0x00001060
 #define MAC_OS_X_VERSION_10_7_HEX 0x00001070
 
-class nsToolkit : public nsIToolkit
+class nsToolkit
 {
 public:
                      nsToolkit();
   virtual            ~nsToolkit();
 
-  NS_DECL_ISUPPORTS
-  NS_DECL_NSITOOLKIT
+  static nsToolkit* GetToolkit();
+
+  static void Shutdown() {
+    delete gToolkit;
+    gToolkit = nsnull;
+  }
 
   static PRInt32     OSXVersion();
   static bool        OnSnowLeopardOrLater();
   static bool        OnLionOrLater();
 
   static void        PostSleepWakeNotification(const char* aNotification);
 
   static nsresult    SwizzleMethods(Class aClass, SEL orgMethod, SEL posedMethod,
@@ -73,20 +77,18 @@ protected:
   nsresult           RegisterForSleepWakeNotifcations();
   void               RemoveSleepWakeNotifcations();
 
   void               RegisterForAllProcessMouseEvents();
   void               UnregisterAllProcessMouseEventHandlers();
 
 protected:
 
-  bool               mInited;
+  static nsToolkit* gToolkit;
 
   CFRunLoopSourceRef mSleepWakeNotificationRLS;
   io_object_t        mPowerNotifier;
 
   CFMachPortRef      mEventTapPort;
   CFRunLoopSourceRef mEventTapRLS;
 };
 
-extern nsToolkit* NS_CreateToolkitInstance();
-
 #endif // nsToolkit_h_
--- a/widget/src/cocoa/nsToolkit.mm
+++ b/widget/src/cocoa/nsToolkit.mm
@@ -75,54 +75,32 @@ extern "C" {
 using namespace mozilla;
 
 // defined in nsChildView.mm
 extern nsIRollupListener * gRollupListener;
 extern nsIWidget         * gRollupWidget;
 
 static io_connect_t gRootPort = MACH_PORT_NULL;
 
-// Static thread local storage index of the Toolkit 
-// object associated with a given thread...
-static PRUintn gToolkitTLSIndex = 0;
+nsToolkit* nsToolkit::gToolkit = nsnull;
 
 nsToolkit::nsToolkit()
-: mInited(false)
-, mSleepWakeNotificationRLS(nsnull)
+: mSleepWakeNotificationRLS(nsnull)
 , mEventTapPort(nsnull)
 , mEventTapRLS(nsnull)
 {
-  MOZ_COUNT_CTOR(nsToolkit);
+  RegisterForSleepWakeNotifcations();
+  RegisterForAllProcessMouseEvents();
 }
 
 nsToolkit::~nsToolkit()
 {
   MOZ_COUNT_DTOR(nsToolkit);
   RemoveSleepWakeNotifcations();
   UnregisterAllProcessMouseEventHandlers();
-  // Remove the TLS reference to the toolkit...
-  PR_SetThreadPrivate(gToolkitTLSIndex, nsnull);
-}
-
-NS_IMPL_THREADSAFE_ISUPPORTS1(nsToolkit, nsIToolkit);
-
-NS_IMETHODIMP
-nsToolkit::Init(PRThread * aThread)
-{
-  mInited = true;
-  
-  RegisterForSleepWakeNotifcations();
-  RegisterForAllProcessMouseEvents();
-
-  return NS_OK;
-}
-
-nsToolkit* NS_CreateToolkitInstance()
-{
-  return new nsToolkit();
 }
 
 void
 nsToolkit::PostSleepWakeNotification(const char* aNotification)
 {
   nsCOMPtr<nsIObserverService> observerService = do_GetService("@mozilla.org/observer-service;1");
   if (observerService)
     observerService->NotifyObservers(nsnull, aNotification, nsnull);
@@ -314,54 +292,30 @@ nsToolkit::UnregisterAllProcessMouseEven
     CFMachPortInvalidate(mEventTapPort);
     CFRelease(mEventTapPort);
     mEventTapPort = nsnull;
   }
 
   NS_OBJC_END_TRY_ABORT_BLOCK;
 }
 
-// Return the nsIToolkit for the current thread.  If a toolkit does not
-// yet exist, then one will be created...
-NS_IMETHODIMP NS_GetCurrentToolkit(nsIToolkit* *aResult)
+// Return the nsToolkit instance.  If a toolkit does not yet exist, then one
+// will be created.
+// static
+nsToolkit* nsToolkit::GetToolkit()
 {
-  NS_OBJC_BEGIN_TRY_ABORT_BLOCK_NSRESULT;
+  NS_OBJC_BEGIN_TRY_ABORT_BLOCK_RETURN;
 
-  NS_ENSURE_ARG_POINTER(aResult);
-  *aResult = nsnull;
-  
-  // Create the TLS index the first time through...
-  if (gToolkitTLSIndex == 0) {
-    PRStatus status = PR_NewThreadPrivateIndex(&gToolkitTLSIndex, NULL);
-    if (PR_FAILURE == status)
-      return NS_ERROR_FAILURE;
+  if (!gToolkit) {
+    gToolkit = new nsToolkit();
   }
-  
-  // Create a new toolkit for this thread...
-  nsToolkit* toolkit = (nsToolkit*)PR_GetThreadPrivate(gToolkitTLSIndex);
-  if (!toolkit) {
-    toolkit = NS_CreateToolkitInstance();
-    if (!toolkit)
-      return NS_ERROR_OUT_OF_MEMORY;
-    
-    NS_ADDREF(toolkit);
-    toolkit->Init(PR_GetCurrentThread());
-    //
-    // The reference stored in the TLS is weak.  It is removed in the
-    // nsToolkit destructor...
-    //
-    PR_SetThreadPrivate(gToolkitTLSIndex, (void*)toolkit);
-  }
-  else {
-    NS_ADDREF(toolkit);
-  }
-  *aResult = toolkit;
-  return NS_OK;
 
-  NS_OBJC_END_TRY_ABORT_BLOCK_NSRESULT;
+  return gToolkit;
+
+  NS_OBJC_END_TRY_ABORT_BLOCK_RETURN(nsnull);
 }
 
 PRInt32 nsToolkit::OSXVersion()
 {
   NS_OBJC_BEGIN_TRY_ABORT_BLOCK_RETURN;
 
   static PRInt32 gOSXVersion = 0x0;
   if (gOSXVersion == 0x0) {
--- a/widget/src/cocoa/nsWidgetFactory.mm
+++ b/widget/src/cocoa/nsWidgetFactory.mm
@@ -37,44 +37,43 @@
 
 #include "nsIFactory.h"
 #include "nsISupports.h"
 #include "nsIComponentManager.h"
 #include "mozilla/ModuleUtils.h"
 
 #include "nsWidgetsCID.h"
 
-#include "nsToolkit.h"
 #include "nsChildView.h"
 #include "nsCocoaWindow.h"
 #include "nsAppShell.h"
 #include "nsAppShellSingleton.h"
 #include "nsFilePicker.h"
 
 #include "nsClipboard.h"
 #include "nsClipboardHelper.h"
 #include "nsTransferable.h"
 #include "nsHTMLFormatConverter.h"
 #include "nsDragService.h"
+#include "nsToolkit.h"
 
 #include "nsLookAndFeel.h"
 
 #include "nsSound.h"
 #include "nsIdleServiceX.h"
 
 #include "nsScreenManagerCocoa.h"
 #include "nsDeviceContextSpecX.h"
 #include "nsPrintOptionsX.h"
 #include "nsPrintDialogX.h"
 #include "nsPrintSession.h"
 
 NS_GENERIC_FACTORY_CONSTRUCTOR(nsCocoaWindow)
 NS_GENERIC_FACTORY_CONSTRUCTOR(nsChildView)
 NS_GENERIC_FACTORY_CONSTRUCTOR(nsFilePicker)
-NS_GENERIC_FACTORY_CONSTRUCTOR(nsToolkit)
 NS_GENERIC_FACTORY_CONSTRUCTOR(nsSound)
 NS_GENERIC_FACTORY_CONSTRUCTOR(nsTransferable)
 NS_GENERIC_FACTORY_CONSTRUCTOR(nsHTMLFormatConverter)
 NS_GENERIC_FACTORY_CONSTRUCTOR(nsClipboard)
 NS_GENERIC_FACTORY_CONSTRUCTOR(nsClipboardHelper)
 NS_GENERIC_FACTORY_CONSTRUCTOR(nsDragService)
 NS_GENERIC_FACTORY_CONSTRUCTOR(nsScreenManagerCocoa)
 NS_GENERIC_FACTORY_CONSTRUCTOR(nsDeviceContextSpecX)
@@ -107,17 +106,16 @@ NS_GENERIC_FACTORY_CONSTRUCTOR_INIT(GfxI
 }
 
 
 NS_DEFINE_NAMED_CID(NS_WINDOW_CID);
 NS_DEFINE_NAMED_CID(NS_POPUP_CID);
 NS_DEFINE_NAMED_CID(NS_CHILD_CID);
 NS_DEFINE_NAMED_CID(NS_FILEPICKER_CID);
 NS_DEFINE_NAMED_CID(NS_APPSHELL_CID);
-NS_DEFINE_NAMED_CID(NS_TOOLKIT_CID);
 NS_DEFINE_NAMED_CID(NS_SOUND_CID);
 NS_DEFINE_NAMED_CID(NS_TRANSFERABLE_CID);
 NS_DEFINE_NAMED_CID(NS_HTMLFORMATCONVERTER_CID);
 NS_DEFINE_NAMED_CID(NS_CLIPBOARD_CID);
 NS_DEFINE_NAMED_CID(NS_CLIPBOARDHELPER_CID);
 NS_DEFINE_NAMED_CID(NS_DRAGSERVICE_CID);
 NS_DEFINE_NAMED_CID(NS_BIDIKEYBOARD_CID);
 NS_DEFINE_NAMED_CID(NS_THEMERENDERER_CID);
@@ -134,17 +132,16 @@ NS_DEFINE_NAMED_CID(NS_GFXINFO_CID);
 
 
 static const mozilla::Module::CIDEntry kWidgetCIDs[] = {
   { &kNS_WINDOW_CID, false, NULL, nsCocoaWindowConstructor },
   { &kNS_POPUP_CID, false, NULL, nsCocoaWindowConstructor },
   { &kNS_CHILD_CID, false, NULL, nsChildViewConstructor },
   { &kNS_FILEPICKER_CID, false, NULL, nsFilePickerConstructor },
   { &kNS_APPSHELL_CID, false, NULL, nsAppShellConstructor },
-  { &kNS_TOOLKIT_CID, false, NULL, nsToolkitConstructor },
   { &kNS_SOUND_CID, false, NULL, nsSoundConstructor },
   { &kNS_TRANSFERABLE_CID, false, NULL, nsTransferableConstructor },
   { &kNS_HTMLFORMATCONVERTER_CID, false, NULL, nsHTMLFormatConverterConstructor },
   { &kNS_CLIPBOARD_CID, false, NULL, nsClipboardConstructor },
   { &kNS_CLIPBOARDHELPER_CID, false, NULL, nsClipboardHelperConstructor },
   { &kNS_DRAGSERVICE_CID, false, NULL, nsDragServiceConstructor },
   { &kNS_BIDIKEYBOARD_CID, false, NULL, nsBidiKeyboardConstructor },
   { &kNS_THEMERENDERER_CID, false, NULL, nsNativeThemeCocoaConstructor },
@@ -162,17 +159,16 @@ static const mozilla::Module::CIDEntry k
 };
 
 static const mozilla::Module::ContractIDEntry kWidgetContracts[] = {
   { "@mozilla.org/widgets/window/mac;1", &kNS_WINDOW_CID },
   { "@mozilla.org/widgets/popup/mac;1", &kNS_POPUP_CID },
   { "@mozilla.org/widgets/childwindow/mac;1", &kNS_CHILD_CID },
   { "@mozilla.org/filepicker;1", &kNS_FILEPICKER_CID },
   { "@mozilla.org/widget/appshell/mac;1", &kNS_APPSHELL_CID },
-  { "@mozilla.org/widget/toolkit/mac;1", &kNS_TOOLKIT_CID },
   { "@mozilla.org/sound;1", &kNS_SOUND_CID },
   { "@mozilla.org/widget/transferable;1", &kNS_TRANSFERABLE_CID },
   { "@mozilla.org/widget/htmlformatconverter;1", &kNS_HTMLFORMATCONVERTER_CID },
   { "@mozilla.org/widget/clipboard;1", &kNS_CLIPBOARD_CID },
   { "@mozilla.org/widget/clipboardhelper;1", &kNS_CLIPBOARDHELPER_CID },
   { "@mozilla.org/widget/dragservice;1", &kNS_DRAGSERVICE_CID },
   { "@mozilla.org/widget/bidikeyboard;1", &kNS_BIDIKEYBOARD_CID },
   { "@mozilla.org/chrome/chrome-native-theme;1", &kNS_THEMERENDERER_CID },
@@ -188,16 +184,17 @@ static const mozilla::Module::ContractID
   { "@mozilla.org/gfx/info;1", &kNS_GFXINFO_CID },
   { NULL }
 };
 
 static void
 nsWidgetCocoaModuleDtor()
 {
   nsLookAndFeel::Shutdown();
+  nsToolkit::Shutdown();
   nsAppShellShutdown();
 }
 
 static const mozilla::Module kWidgetModule = {
   mozilla::Module::kVersion,
   kWidgetCIDs,
   kWidgetContracts,
   NULL,
--- a/widget/src/gtk2/nsGTKToolkit.h
+++ b/widget/src/gtk2/nsGTKToolkit.h
@@ -35,35 +35,37 @@
  * the provisions above, a recipient may use your version of this file under
  * the terms of any one of the MPL, the GPL or the LGPL.
  *
  * ***** END LICENSE BLOCK ***** */
 
 #ifndef GTKTOOLKIT_H      
 #define GTKTOOLKIT_H
 
-#include "nsIToolkit.h"
 #include "nsString.h"
 #include <gtk/gtk.h>
 
 /**
  * Wrapper around the thread running the message pump.
  * The toolkit abstraction is necessary because the message pump must
  * execute within the same thread that created the widget under Win32.
  */ 
 
-class nsGTKToolkit : public nsIToolkit
+class nsGTKToolkit
 {
 public:
     nsGTKToolkit();
     virtual ~nsGTKToolkit();
 
-    NS_DECL_ISUPPORTS
+    static nsGTKToolkit* GetToolkit();
 
-    NS_IMETHOD    Init(PRThread *aThread);
+    static void Shutdown() {
+      delete gToolkit;
+      gToolkit = nsnull;
+    }
 
     void          CreateSharedGC(void);
     GdkGC         *GetSharedGC(void);
     
     /**
      * Get/set our value of DESKTOP_STARTUP_ID. When non-empty, this is applied
      * to the next toplevel window to be shown or focused (and then immediately
      * cleared).
@@ -74,14 +76,16 @@ public:
     /**
      * Get/set the timestamp value to be used, if non-zero, to focus the
      * next top-level window to be shown or focused (upon which it is cleared).
      */
     void SetFocusTimestamp(PRUint32 aTimestamp) { mFocusTimestamp = aTimestamp; }
     PRUint32 GetFocusTimestamp() { return mFocusTimestamp; }
 
 private:
+    static nsGTKToolkit* gToolkit;
+
     GdkGC         *mSharedGC;
     nsCString      mDesktopStartupID;
     PRUint32       mFocusTimestamp;
 };
 
 #endif  // GTKTOOLKIT_H
--- a/widget/src/gtk2/nsToolkit.cpp
+++ b/widget/src/gtk2/nsToolkit.cpp
@@ -35,56 +35,41 @@
  * the provisions above, a recipient may use your version of this file under
  * the terms of any one of the MPL, the GPL or the LGPL.
  *
  * ***** END LICENSE BLOCK ***** */
 
 #include "nscore.h"  // needed for 'nsnull'
 #include "nsGTKToolkit.h"
 
-//
-// Static thread local storage index of the Toolkit 
-// object associated with a given thread...
-//
-static PRUintn gToolkitTLSIndex = 0;
+nsGTKToolkit* nsGTKToolkit::gToolkit = nsnull;
 
 //-------------------------------------------------------------------------
 //
 // constructor
 //
 //-------------------------------------------------------------------------
 nsGTKToolkit::nsGTKToolkit()
+  : mSharedGC(nsnull), mFocusTimestamp(0)
 {
-    mSharedGC = nsnull;
-    mFocusTimestamp = 0;
+    CreateSharedGC();
 }
 
 //-------------------------------------------------------------------------
 //
 // destructor
 //
 //-------------------------------------------------------------------------
 nsGTKToolkit::~nsGTKToolkit()
 {
     if (mSharedGC) {
         g_object_unref(mSharedGC);
     }
-
-    // Remove the TLS reference to the toolkit...
-    PR_SetThreadPrivate(gToolkitTLSIndex, nsnull);
 }
 
-//-------------------------------------------------------------------------
-//
-// nsISupports implementation macro
-//
-//-------------------------------------------------------------------------
-
-NS_IMPL_ISUPPORTS1(nsGTKToolkit, nsIToolkit)
-
 void nsGTKToolkit::CreateSharedGC(void)
 {
     GdkPixmap *pixmap;
 
     if (mSharedGC)
         return;
 
     pixmap = gdk_pixmap_new(NULL, 1, 1, gdk_rgb_get_visual()->depth);
@@ -92,69 +77,20 @@ void nsGTKToolkit::CreateSharedGC(void)
     g_object_unref(pixmap);
 }
 
 GdkGC *nsGTKToolkit::GetSharedGC(void)
 {
     return (GdkGC *)g_object_ref(mSharedGC);
 }
 
-//-------------------------------------------------------------------------
-//
-//
-//-------------------------------------------------------------------------
-NS_IMETHODIMP nsGTKToolkit::Init(PRThread *aThread)
+//-------------------------------------------------------------------------------
+// Return the toolkit. If a toolkit does not yet exist, then one will be created.
+//-------------------------------------------------------------------------------
+// static
+nsGTKToolkit* nsGTKToolkit::GetToolkit()
 {
-    CreateSharedGC();
-    return NS_OK;
-}
-
-
-//-------------------------------------------------------------------------
-//
-// Return the nsIToolkit for the current thread.  If a toolkit does not
-// yet exist, then one will be created...
-//
-//-------------------------------------------------------------------------
-NS_METHOD NS_GetCurrentToolkit(nsIToolkit* *aResult)
-{
-    nsIToolkit* toolkit = nsnull;
-    nsresult rv = NS_OK;
-    PRStatus status;
-
-    // Create the TLS index the first time through...
-    if (0 == gToolkitTLSIndex) {
-        status = PR_NewThreadPrivateIndex(&gToolkitTLSIndex, NULL);
-        if (PR_FAILURE == status) {
-            rv = NS_ERROR_FAILURE;
-        }
+    if (!gToolkit) {
+        gToolkit = new nsGTKToolkit();
     }
-
-    if (NS_SUCCEEDED(rv)) {
-        toolkit = (nsIToolkit*)PR_GetThreadPrivate(gToolkitTLSIndex);
-
-        //
-        // Create a new toolkit for this thread...
-        //
-        if (!toolkit) {
-            toolkit = new nsGTKToolkit();
-
-            if (!toolkit) {
-                rv = NS_ERROR_OUT_OF_MEMORY;
-            } else {
-                NS_ADDREF(toolkit);
-                toolkit->Init(PR_GetCurrentThread());
-                //
-                // The reference stored in the TLS is weak.  It is
-                // removed in the nsToolkit destructor...
-                //
-                PR_SetThreadPrivate(gToolkitTLSIndex, (void*)toolkit);
-            }
-        } else {
-            NS_ADDREF(toolkit);
-        }
-        *aResult = toolkit;
-    }
-
-    return rv;
+ 
+    return gToolkit;
 }
-
-
--- a/widget/src/gtk2/nsWidgetFactory.cpp
+++ b/widget/src/gtk2/nsWidgetFactory.cpp
@@ -50,16 +50,17 @@
 #include "nsClipboard.h"
 #include "nsDragService.h"
 #endif
 #include "nsFilePicker.h"
 #include "nsSound.h"
 #include "nsBidiKeyboard.h"
 #include "nsNativeKeyBindings.h"
 #include "nsScreenManagerGtk.h"
+#include "nsGTKToolkit.h"
 
 #ifdef NS_PRINTING
 #include "nsPrintOptionsGTK.h"
 #include "nsPrintSession.h"
 #include "nsDeviceContextSpecG.h"
 #endif
 
 #include "mozilla/Preferences.h"
@@ -334,16 +335,17 @@ static const mozilla::Module::ContractID
 
 static void
 nsWidgetGtk2ModuleDtor()
 {
   nsLookAndFeel::Shutdown();
   nsFilePicker::Shutdown();
   nsSound::Shutdown();
   nsWindow::ReleaseGlobals();
+  nsGTKToolkit::Shutdown();
   nsAppShellShutdown();
 }
 
 static const mozilla::Module kWidgetModule = {
     mozilla::Module::kVersion,
     kWidgetCIDs,
     kWidgetContracts,
     NULL,
--- a/widget/src/gtk2/nsWindow.cpp
+++ b/widget/src/gtk2/nsWindow.cpp
@@ -1402,23 +1402,20 @@ nsWindow::SetSizeMode(PRInt32 aMode)
 
 typedef void (* SetUserTimeFunc)(GdkWindow* aWindow, guint32 aTimestamp);
 
 // This will become obsolete when new GTK APIs are widely supported,
 // as described here: http://bugzilla.gnome.org/show_bug.cgi?id=347375
 static void
 SetUserTimeAndStartupIDForActivatedWindow(GtkWidget* aWindow)
 {
-    nsCOMPtr<nsIToolkit> toolkit;
-    NS_GetCurrentToolkit(getter_AddRefs(toolkit));
-    if (!toolkit)
+    nsGTKToolkit* GTKToolkit = nsGTKToolkit::GetToolkit();
+    if (!GTKToolkit)
         return;
 
-    nsGTKToolkit* GTKToolkit = static_cast<nsGTKToolkit*>
-                                          (static_cast<nsIToolkit*>(toolkit));
     nsCAutoString desktopStartupID;
     GTKToolkit->GetDesktopStartupID(&desktopStartupID);
     if (desktopStartupID.IsEmpty()) {
         // We don't have the data we need. Fall back to an
         // approximation ... using the timestamp of the remote command
         // being received as a guess for the timestamp of the user event
         // that triggered it.
         PRUint32 timestamp = GTKToolkit->GetFocusTimestamp();
@@ -1739,18 +1736,19 @@ nsWindow::GetNativeData(PRUint32 aDataTy
         return GDK_DISPLAY_XDISPLAY(gdk_display_get_default());
 #else
         return nsnull;
 #endif /* MOZ_X11 */
         break;
 
     case NS_NATIVE_GRAPHIC: {
 #if defined(MOZ_WIDGET_GTK2)
-        NS_ASSERTION(nsnull != mToolkit, "NULL toolkit, unable to get a GC");    
-        return (void *)static_cast<nsGTKToolkit *>(mToolkit)->GetSharedGC();
+        nsGTKToolkit* toolkit = nsGTKToolkit::GetToolkit();
+        NS_ASSERTION(nsnull != toolkit, "NULL toolkit, unable to get a GC");    
+        return toolkit->GetSharedGC();
 #else
         return nsnull;
 #endif
         break;
     }
 
     case NS_NATIVE_SHELLWIDGET:
         return (void *) mShell;
@@ -3875,32 +3873,33 @@ CreateGdkWindow(GdkWindow *parent, GtkWi
 }
 
 nsresult
 nsWindow::Create(nsIWidget        *aParent,
                  nsNativeWidget    aNativeParent,
                  const nsIntRect  &aRect,
                  EVENT_CALLBACK    aHandleEventFunction,
                  nsDeviceContext *aContext,
-                 nsIToolkit       *aToolkit,
                  nsWidgetInitData *aInitData)
 {
     // only set the base parent if we're going to be a dialog or a
     // toplevel
     nsIWidget *baseParent = aInitData &&
         (aInitData->mWindowType == eWindowType_dialog ||
          aInitData->mWindowType == eWindowType_toplevel ||
          aInitData->mWindowType == eWindowType_invisible) ?
         nsnull : aParent;
 
     NS_ASSERTION(!mWindowGroup, "already have window group (leaking it)");
 
+    // Ensure that the toolkit is created.
+    nsGTKToolkit::GetToolkit();
+
     // initialize all the common bits of this class
-    BaseCreate(baseParent, aRect, aHandleEventFunction, aContext,
-               aToolkit, aInitData);
+    BaseCreate(baseParent, aRect, aHandleEventFunction, aContext, aInitData);
 
     // Do we need to listen for resizes?
     bool listenForResizes = false;;
     if (aNativeParent || (aInitData && aInitData->mListenForResizes))
         listenForResizes = true;
 
     // and do our common creation
     CommonCreate(aParent, listenForResizes);
--- a/widget/src/gtk2/nsWindow.h
+++ b/widget/src/gtk2/nsWindow.h
@@ -133,17 +133,16 @@ public:
     bool AreBoundsSane(void);
 
     // nsIWidget
     NS_IMETHOD         Create(nsIWidget        *aParent,
                               nsNativeWidget   aNativeParent,
                               const nsIntRect  &aRect,
                               EVENT_CALLBACK   aHandleEventFunction,
                               nsDeviceContext *aContext,
-                              nsIToolkit       *aToolkit,
                               nsWidgetInitData *aInitData);
     NS_IMETHOD         Destroy(void);
     virtual nsIWidget *GetParent();
     virtual float      GetDPI();
     virtual nsresult   SetParent(nsIWidget* aNewParent);
     NS_IMETHOD         SetModal(bool aModal);
     NS_IMETHOD         IsVisible(bool & aState);
     NS_IMETHOD         ConstrainPosition(bool aAllowSlop,
--- a/widget/src/os2/Makefile.in
+++ b/widget/src/os2/Makefile.in
@@ -57,17 +57,16 @@ CPPSRCS		= \
 		nsBidiKeyboard.cpp \
 		nsClipboard.cpp \
 		nsFilePicker.cpp \
 		os2FrameWindow.cpp \
 		nsLookAndFeel.cpp \
 		nsOS2Uni.cpp \
 		nsPrintOS2.cpp \
 		nsSound.cpp \
-		nsToolkit.cpp \
 		nsWidgetFactory.cpp \
 		nsWindow.cpp \
 		nsDragService.cpp \
 		nsScreenOS2.cpp	\
 		nsScreenManagerOS2.cpp \
 		nsDeviceContextSpecOS2.cpp \
 		nsPrintOptionsOS2.cpp \
 		nsRwsService.cpp \
deleted file mode 100644
--- a/widget/src/os2/nsToolkit.cpp
+++ /dev/null
@@ -1,130 +0,0 @@
-/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
-/* ***** BEGIN LICENSE BLOCK *****
- * Version: MPL 1.1/GPL 2.0/LGPL 2.1
- *
- * The contents of this file are subject to the Mozilla Public License Version
- * 1.1 (the "License"); you may not use this file except in compliance with
- * the License. You may obtain a copy of the License at
- * http://www.mozilla.org/MPL/
- *
- * Software distributed under the License is distributed on an "AS IS" basis,
- * WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
- * for the specific language governing rights and limitations under the
- * License.
- *
- * The Original Code is mozilla.org code.
- *
- * The Initial Developer of the Original Code is
- * Netscape Communications Corporation.
- * Portions created by the Initial Developer are Copyright (C) 1998
- * the Initial Developer. All Rights Reserved.
- *
- * Contributor(s):
- *   John Fairhurst <john_fairhurst@iname.com>
- *   Pierre Phaneuf <pp@ludusdesign.com>
- *
- * Alternatively, the contents of this file may be used under the terms of
- * either the GNU General Public License Version 2 or later (the "GPL"), or
- * the GNU Lesser General Public License Version 2.1 or later (the "LGPL"),
- * in which case the provisions of the GPL or the LGPL are applicable instead
- * of those above. If you wish to allow use of your version of this file only
- * under the terms of either the GPL or the LGPL, and not to allow others to
- * use your version of this file under the terms of the MPL, indicate your
- * decision by deleting the provisions above and replace them with the notice
- * and other provisions required by the GPL or the LGPL. If you do not delete
- * the provisions above, a recipient may use your version of this file under
- * the terms of any one of the MPL, the GPL or the LGPL.
- *
- * ***** END LICENSE BLOCK ***** */
-
-#include "nsToolkit.h"
-
-NS_IMPL_ISUPPORTS1(nsToolkit, nsIToolkit)
-
-//
-// Static thread local storage index of the Toolkit 
-// object associated with a given thread...
-//
-static PRUintn gToolkitTLSIndex = 0;
-
-//-------------------------------------------------------------------------
-//
-// constructor
-//
-//-------------------------------------------------------------------------
-nsToolkit::nsToolkit()  
-{
-    MOZ_COUNT_CTOR(nsToolkit);
-}
-
-
-//-------------------------------------------------------------------------
-//
-// destructor
-//
-//-------------------------------------------------------------------------
-nsToolkit::~nsToolkit()
-{
-    MOZ_COUNT_DTOR(nsToolkit);
-    // Remove the TLS reference to the toolkit...
-    PR_SetThreadPrivate(gToolkitTLSIndex, nsnull);
-}
-
-//-------------------------------------------------------------------------
-//
-//
-//-------------------------------------------------------------------------
-NS_METHOD nsToolkit::Init(PRThread *aThread)
-{
-    NS_ASSERTION(aThread, "Can only initialize toolkit on the current thread");
-    return NS_OK;
-}
-
-//-------------------------------------------------------------------------
-//
-// Return the nsIToolkit for the current thread.  If a toolkit does not
-// yet exist, then one will be created...
-//
-//-------------------------------------------------------------------------
-NS_METHOD NS_GetCurrentToolkit(nsIToolkit* *aResult)
-{
-  nsIToolkit* toolkit = nsnull;
-  nsresult rv = NS_OK;
-  PRStatus status;
-
-  // Create the TLS index the first time through...
-  if (0 == gToolkitTLSIndex) {
-    status = PR_NewThreadPrivateIndex(&gToolkitTLSIndex, NULL);
-    if (PR_FAILURE == status) {
-      rv = NS_ERROR_FAILURE;
-    }
-  }
-
-  if (NS_SUCCEEDED(rv)) {
-    toolkit = (nsIToolkit*)PR_GetThreadPrivate(gToolkitTLSIndex);
-
-    //
-    // Create a new toolkit for this thread...
-    //
-    if (!toolkit) {
-      toolkit = new nsToolkit();
-
-      if (!toolkit) {
-        rv = NS_ERROR_OUT_OF_MEMORY;
-      } else {
-        NS_ADDREF(toolkit);
-        toolkit->Init(PR_GetCurrentThread());
-        //
-        // The reference stored in the TLS is weak.  It is removed in the
-        // nsToolkit destructor...
-        //
-        PR_SetThreadPrivate(gToolkitTLSIndex, (void*)toolkit);
-      }
-    } else {
-      NS_ADDREF(toolkit);
-    }
-    *aResult = toolkit;
-  }
-
-  return rv;
-}
deleted file mode 100644
--- a/widget/src/os2/nsToolkit.h
+++ /dev/null
@@ -1,64 +0,0 @@
-/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
-/* ***** BEGIN LICENSE BLOCK *****
- * Version: MPL 1.1/GPL 2.0/LGPL 2.1
- *
- * The contents of this file are subject to the Mozilla Public License Version
- * 1.1 (the "License"); you may not use this file except in compliance with
- * the License. You may obtain a copy of the License at
- * http://www.mozilla.org/MPL/
- *
- * Software distributed under the License is distributed on an "AS IS" basis,
- * WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
- * for the specific language governing rights and limitations under the
- * License.
- *
- * The Original Code is mozilla.org code.
- *
- * The Initial Developer of the Original Code is
- * Netscape Communications Corporation.
- * Portions created by the Initial Developer are Copyright (C) 1998
- * the Initial Developer. All Rights Reserved.
- *
- * Contributor(s):
- *   John Fairhurst <john_fairhurst@iname.com>
- *
- * Alternatively, the contents of this file may be used under the terms of
- * either the GNU General Public License Version 2 or later (the "GPL"), or
- * the GNU Lesser General Public License Version 2.1 or later (the "LGPL"),
- * in which case the provisions of the GPL or the LGPL are applicable instead
- * of those above. If you wish to allow use of your version of this file only
- * under the terms of either the GPL or the LGPL, and not to allow others to
- * use your version of this file under the terms of the MPL, indicate your
- * decision by deleting the provisions above and replace them with the notice
- * and other provisions required by the GPL or the LGPL. If you do not delete
- * the provisions above, a recipient may use your version of this file under
- * the terms of any one of the MPL, the GPL or the LGPL.
- *
- * ***** END LICENSE BLOCK ***** */
-
-#ifndef TOOLKIT_H      
-#define TOOLKIT_H
-
-#include "nsIToolkit.h"
-
-/**
- * Wrapper around the thread running the message pump.
- * The toolkit abstraction is necessary because the message pump must
- * execute within the same thread that created the widget under Win32.
- */ 
-
-class nsToolkit : public nsIToolkit
-{
-
-  public:
-
-            NS_DECL_ISUPPORTS
-
-                            nsToolkit();
-            NS_IMETHOD      Init(PRThread *aThread);
-
-private:
-                            ~nsToolkit();
-};
-
-#endif  // TOOLKIT_H
--- a/widget/src/os2/nsWidgetFactory.cpp
+++ b/widget/src/os2/nsWidgetFactory.cpp
@@ -64,17 +64,16 @@
 #include "nsAppShellSingleton.h"
 #include "nsBidiKeyboard.h"
 #include "nsWindow.h"
 #include "nsDragService.h"
 #include "nsILocalFile.h"
 #include "nsFilePicker.h"
 #include "nsLookAndFeel.h"
 #include "nsSound.h"
-#include "nsToolkit.h"
 
 // Drag & Drop, Clipboard
 #include "nsClipboard.h"
 #include "nsClipboardHelper.h"
 #include "nsTransferable.h"
 #include "nsHTMLFormatConverter.h"
 
 #include "nsScreenManagerOS2.h"
@@ -89,17 +88,16 @@
 // objects that just require generic constructors
 NS_GENERIC_FACTORY_CONSTRUCTOR(nsBidiKeyboard)
 NS_GENERIC_FACTORY_CONSTRUCTOR(nsWindow)
 NS_GENERIC_FACTORY_CONSTRUCTOR(nsClipboard)
 NS_GENERIC_FACTORY_CONSTRUCTOR(nsClipboardHelper)
 NS_GENERIC_FACTORY_CONSTRUCTOR(nsFilePicker)
 NS_GENERIC_FACTORY_CONSTRUCTOR(nsChildWindow)
 NS_GENERIC_FACTORY_CONSTRUCTOR(nsSound)
-NS_GENERIC_FACTORY_CONSTRUCTOR(nsToolkit)
 NS_GENERIC_FACTORY_CONSTRUCTOR(nsTransferable)
 NS_GENERIC_FACTORY_CONSTRUCTOR(nsHTMLFormatConverter)
 NS_GENERIC_FACTORY_CONSTRUCTOR(nsDragService)
 
 NS_GENERIC_FACTORY_CONSTRUCTOR(nsDeviceContextSpecOS2)
 NS_GENERIC_FACTORY_CONSTRUCTOR_INIT(nsPrintOptionsOS2, Init)
 NS_GENERIC_FACTORY_CONSTRUCTOR(nsPrinterEnumeratorOS2)
 NS_GENERIC_FACTORY_CONSTRUCTOR_INIT(nsPrintSession, Init)
@@ -110,17 +108,16 @@ NS_GENERIC_FACTORY_CONSTRUCTOR(nsIdleSer
 NS_DEFINE_NAMED_CID(NS_APPSHELL_CID);
 NS_DEFINE_NAMED_CID(NS_BIDIKEYBOARD_CID);
 NS_DEFINE_NAMED_CID(NS_CHILD_CID);
 NS_DEFINE_NAMED_CID(NS_CLIPBOARD_CID);
 NS_DEFINE_NAMED_CID(NS_CLIPBOARDHELPER_CID);
 NS_DEFINE_NAMED_CID(NS_DRAGSERVICE_CID);
 NS_DEFINE_NAMED_CID(NS_FILEPICKER_CID);
 NS_DEFINE_NAMED_CID(NS_SOUND_CID);
-NS_DEFINE_NAMED_CID(NS_TOOLKIT_CID);
 NS_DEFINE_NAMED_CID(NS_WINDOW_CID);
 NS_DEFINE_NAMED_CID(NS_TRANSFERABLE_CID);
 NS_DEFINE_NAMED_CID(NS_HTMLFORMATCONVERTER_CID);
 NS_DEFINE_NAMED_CID(NS_SCREENMANAGER_CID);
 NS_DEFINE_NAMED_CID(NS_DEVICE_CONTEXT_SPEC_CID);
 NS_DEFINE_NAMED_CID(NS_PRINTSETTINGSSERVICE_CID);
 NS_DEFINE_NAMED_CID(NS_PRINTSESSION_CID);
 NS_DEFINE_NAMED_CID(NS_PRINTER_ENUMERATOR_CID);
@@ -132,17 +129,16 @@ static const mozilla::Module::CIDEntry k
     { &kNS_APPSHELL_CID, false, NULL, nsAppShellConstructor },
     { &kNS_BIDIKEYBOARD_CID, false, NULL, nsBidiKeyboardConstructor },
     { &kNS_CHILD_CID, false, NULL, nsChildWindowConstructor },
     { &kNS_CLIPBOARD_CID, false, NULL, nsClipboardConstructor },
     { &kNS_CLIPBOARDHELPER_CID, false, NULL, nsClipboardHelperConstructor },
     { &kNS_DRAGSERVICE_CID, false, NULL, nsDragServiceConstructor },
     { &kNS_FILEPICKER_CID, false, NULL, nsFilePickerConstructor },
     { &kNS_SOUND_CID, false, NULL, nsSoundConstructor },
-    { &kNS_TOOLKIT_CID, false, NULL, nsToolkitConstructor },
     { &kNS_WINDOW_CID, false, NULL, nsWindowConstructor },
     { &kNS_TRANSFERABLE_CID, false, NULL, nsTransferableConstructor },
     { &kNS_HTMLFORMATCONVERTER_CID, false, NULL, nsHTMLFormatConverterConstructor },
     { &kNS_SCREENMANAGER_CID, false, NULL, nsScreenManagerOS2Constructor },
     { &kNS_DEVICE_CONTEXT_SPEC_CID, false, NULL, nsDeviceContextSpecOS2Constructor },
     { &kNS_PRINTSETTINGSSERVICE_CID, false, NULL, nsPrintOptionsOS2Constructor },
     { &kNS_PRINTSESSION_CID, false, NULL, nsPrintSessionConstructor },
     { &kNS_PRINTER_ENUMERATOR_CID, false, NULL, nsPrinterEnumeratorOS2Constructor },
@@ -155,17 +151,16 @@ static const mozilla::Module::ContractID
   { "@mozilla.org/widget/appshell/os2;1", &kNS_APPSHELL_CID },
   { "@mozilla.org/widget/bidikeyboard;1", &kNS_BIDIKEYBOARD_CID },
   { "@mozilla.org/widget/child_window/os2;1", &kNS_CHILD_CID },
   { "@mozilla.org/widget/clipboard;1", &kNS_CLIPBOARD_CID },
   { "@mozilla.org/widget/clipboardhelper;1", &kNS_CLIPBOARDHELPER_CID },
   { "@mozilla.org/widget/dragservice;1", &kNS_DRAGSERVICE_CID },
   { "@mozilla.org/filepicker;1", &kNS_FILEPICKER_CID },
   { "@mozilla.org/sound;1", &kNS_SOUND_CID },
-  { "@mozilla.org/widget/toolkit/os2;1", &kNS_TOOLKIT_CID },
   { "@mozilla.org/widget/window/os2;1", &kNS_WINDOW_CID },
   { "@mozilla.org/widget/transferable;1", &kNS_TRANSFERABLE_CID },
   { "@mozilla.org/widget/htmlformatconverter;1", &kNS_HTMLFORMATCONVERTER_CID },
   { "@mozilla.org/gfx/screenmanager;1", &kNS_SCREENMANAGER_CID },
   { "@mozilla.org/gfx/devicecontextspec;1", &kNS_DEVICE_CONTEXT_SPEC_CID },
   { "@mozilla.org/gfx/printsettings-service;1", &kNS_PRINTSETTINGSSERVICE_CID },
   { "@mozilla.org/gfx/printsession;1", &kNS_PRINTSESSION_CID },
   { "@mozilla.org/gfx/printerenumerator;1", &kNS_PRINTER_ENUMERATOR_CID },
--- a/widget/src/os2/nsWindow.cpp
+++ b/widget/src/os2/nsWindow.cpp
@@ -74,17 +74,16 @@
 #include "nsDragService.h"
 #include "nsGfxCIID.h"
 #include "nsHashKeys.h"
 #include "nsIMenuRollup.h"
 #include "nsIRollupListener.h"
 #include "nsIScreenManager.h"
 #include "nsOS2Uni.h"
 #include "nsTHashtable.h"
-#include "nsToolkit.h"
 #include "nsGkAtoms.h"
 #include "wdgtos2rc.h"
 
 #include "mozilla/Preferences.h"
 
 using namespace mozilla;
 
 //=============================================================================
@@ -331,17 +330,16 @@ void nsWindow::ReleaseGlobals()
 //-----------------------------------------------------------------------------
 // Init an nsWindow & create the appropriate native window.
 
 NS_METHOD nsWindow::Create(nsIWidget* aParent,
                            nsNativeWidget aNativeParent,
                            const nsIntRect& aRect,
                            EVENT_CALLBACK aHandleEventFunction,
                            nsDeviceContext* aContext,
-                           nsIToolkit* aToolkit,
                            nsWidgetInitData* aInitData)
 {
   mWindowState = nsWindowState_eInCreate;
 
   // Identify the parent's nsWindow & native window.  Only one of these
   // should be supplied.  Note:  only nsWindow saves pParent as mParent;
   // os2FrameWindow discards it since toplevel widgets have no parent.
   HWND      hParent;
@@ -354,19 +352,17 @@ NS_METHOD nsWindow::Create(nsIWidget* aP
       hParent = (HWND)aNativeParent;
       pParent = GetNSWindowPtr(hParent);
     } else {
       hParent = HWND_DESKTOP;
       pParent = 0;
     }
   }
 
-  BaseCreate(aParent, aRect, aHandleEventFunction,
-             aContext, aToolkit, aInitData);
-
+  BaseCreate(aParent, aRect, aHandleEventFunction, aContext, aInitData);
 
 #ifdef DEBUG_FOCUS
   mWindowIdentifier = currentWindowIdentifier;
   currentWindowIdentifier++;
 #endif
 
   // Some basic initialization.
   if (aInitData) {
@@ -1916,17 +1912,17 @@ MRESULT nsWindow::ProcessMessage(ULONG m
 
 void nsWindow::OnDestroy()
 {
   mOnDestroyCalled = true;
 
   SetNSWindowPtr(mWnd, 0);
   mWnd = 0;
 
-  // release references to context, toolkit, appshell, children
+  // release references to context and children
   nsBaseWidget::OnDestroy();
 
   // dispatching of the event may cause the reference count to drop to 0
   // and result in this object being deleted. To avoid that, add a
   // reference and then release it after dispatching the event.
   //
   // It's important *not* to do this if we're being called from the
   // destructor -- this would result in our destructor being called *again*
--- a/widget/src/os2/nsWindow.h
+++ b/widget/src/os2/nsWindow.h
@@ -161,17 +161,16 @@ public:
   virtual ~nsWindow();
 
   // from nsIWidget
   NS_IMETHOD            Create(nsIWidget* aParent,
                                nsNativeWidget aNativeParent,
                                const nsIntRect& aRect,
                                EVENT_CALLBACK aHandleEventFunction,
                                nsDeviceContext* aContext,
-                               nsIToolkit* aToolkit = nsnull,
                                nsWidgetInitData* aInitData = nsnull);
   NS_IMETHOD            Destroy();
   virtual nsIWidget*    GetParent();
   virtual float         GetDPI();
   NS_IMETHOD            Enable(bool aState);
   NS_IMETHOD            IsEnabled(bool* aState);
   NS_IMETHOD            Show(bool aState);
   NS_IMETHOD            IsVisible(bool& aState);
--- a/widget/src/qt/Makefile.in
+++ b/widget/src/qt/Makefile.in
@@ -66,17 +66,16 @@ CPPSRCS	+= nsMFilePicker.cpp \
 endif
 
 CPPSRCS	+= \
 		$(MOCSRCS) \
 		nsAppShell.cpp \
 		nsWidgetFactory.cpp \
 		nsWindow.cpp \
 		nsLookAndFeel.cpp \
-		nsToolkit.cpp \
 		nsScreenQt.cpp \
 		nsScreenManagerQt.cpp \
 		nsQtKeyUtils.cpp \
 		nsClipboard.cpp \
 		nsBidiKeyboard.cpp \
 		nsIdleServiceQt.cpp \
 		nsDragService.cpp \
 		nsNativeThemeQt.cpp \
deleted file mode 100644
--- a/widget/src/qt/nsToolkit.cpp
+++ /dev/null
@@ -1,141 +0,0 @@
-/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
-/* ***** BEGIN LICENSE BLOCK *****
- * Version: MPL 1.1/GPL 2.0/LGPL 2.1
- *
- * The contents of this file are subject to the Mozilla Public License Version
- * 1.1 (the "License"); you may not use this file except in compliance with
- * the License. You may obtain a copy of the License at
- * http://www.mozilla.org/MPL/
- *
- * Software distributed under the License is distributed on an "AS IS" basis,
- * WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
- * for the specific language governing rights and limitations under the
- * License.
- *
- * The Original Code is mozilla.org code.
- *
- * The Initial Developer of the Original Code is
- * Netscape Communications Corporation.
- * Portions created by the Initial Developer are Copyright (C) 1998
- * the Initial Developer. All Rights Reserved.
- *
- * Contributor(s):
- *   Lars Knoll <knoll@kde.org>
- *   Zack Rusin <zack@kde.org>
- *   John C. Griggs <johng@corel.com>
- *
- * Alternatively, the contents of this file may be used under the terms of
- * either the GNU General Public License Version 2 or later (the "GPL"), or
- * the GNU Lesser General Public License Version 2.1 or later (the "LGPL"),
- * in which case the provisions of the GPL or the LGPL are applicable instead
- * of those above. If you wish to allow use of your version of this file only
- * under the terms of either the GPL or the LGPL, and not to allow others to
- * use your version of this file under the terms of the MPL, indicate your
- * decision by deleting the provisions above and replace them with the notice
- * and other provisions required by the GPL or the LGPL. If you do not delete
- * the provisions above, a recipient may use your version of this file under
- * the terms of any one of the MPL, the GPL or the LGPL.
- *
- * ***** END LICENSE BLOCK ***** */
-
-#include "nsToolkit.h"
-
-#include "nscore.h"  // needed for 'nsnull'
-
-#include "nsGUIEvent.h"
-
-// Static thread local storage index of the Toolkit
-// object associated with a given thread...
-static PRUintn gToolkitTLSIndex = 0;
-
-//-------------------------------------------------------------------------
-// constructor
-//-------------------------------------------------------------------------
-nsToolkit::nsToolkit()
-{
-  MOZ_COUNT_CTOR(nsToolkit);
-}
-
-//-------------------------------------------------------------------------
-// destructor
-//-------------------------------------------------------------------------
-nsToolkit::~nsToolkit()
-{
-  MOZ_COUNT_DTOR(nsToolkit);
-  // Remove the TLS reference to the toolkit...
-  PR_SetThreadPrivate(gToolkitTLSIndex, nsnull);
-}
-
-//-------------------------------------------------------------------------
-// nsISupports implementation macro
-//-------------------------------------------------------------------------
-NS_IMPL_ISUPPORTS1(nsToolkit, nsIToolkit)
-
-//-------------------------------------------------------------------------
-NS_IMETHODIMP nsToolkit::Init(PRThread *aThread)
-{
-  return NS_OK;
-}
-
-//-------------------------------------------------------------------------
-// Return the nsIToolkit for the current thread.  If a toolkit does not
-// yet exist, then one will be created...
-//-------------------------------------------------------------------------
-NS_METHOD NS_GetCurrentToolkit(nsIToolkit* *aResult)
-{
-  nsIToolkit* toolkit = nsnull;
-  nsresult rv = NS_OK;
-  PRStatus status;
-
-  // Create the TLS index the first time through...
-  if (0 == gToolkitTLSIndex) {
-    status = PR_NewThreadPrivateIndex(&gToolkitTLSIndex, NULL);
-    if (PR_FAILURE == status) {
-      rv = NS_ERROR_FAILURE;
-    }
-  }
-  if (NS_SUCCEEDED(rv)) {
-    toolkit = (nsIToolkit*)PR_GetThreadPrivate(gToolkitTLSIndex);
-
-    // Create a new toolkit for this thread...
-    if (!toolkit) {
-      toolkit = new nsToolkit();
-
-      if (!toolkit) {
-        rv = NS_ERROR_OUT_OF_MEMORY;
-      }
-      else {
-        NS_ADDREF(toolkit);
-        toolkit->Init(PR_GetCurrentThread());
-
-        // The reference stored in the TLS is weak.  It is removed in the
-        // nsToolkit destructor...
-        PR_SetThreadPrivate(gToolkitTLSIndex, (void*)toolkit);
-       }
-    }
-    else {
-      NS_ADDREF(toolkit);
-    }
-    *aResult = toolkit;
-  }
-  return rv;
-}
-
-void nsToolkit::CreateSharedGC(void)
-{
-    if (mSharedGC)
-        return;
-
-    mSharedGC = new QPixmap();
-}
-
-Qt::HANDLE
-nsToolkit::GetSharedGC(void)
-{
-    // FIXME Not sure
-#ifdef MOZ_X11
-    return mSharedGC->handle();
-#else
-    return 0;
-#endif
-}
deleted file mode 100644
--- a/widget/src/qt/nsToolkit.h
+++ /dev/null
@@ -1,84 +0,0 @@
-/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
-/* ***** BEGIN LICENSE BLOCK *****
- * Version: MPL 1.1/GPL 2.0/LGPL 2.1
- *
- * The contents of this file are subject to the Mozilla Public License Version
- * 1.1 (the "License"); you may not use this file except in compliance with
- * the License. You may obtain a copy of the License at
- * http://www.mozilla.org/MPL/
- *
- * Software distributed under the License is distributed on an "AS IS" basis,
- * WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
- * for the specific language governing rights and limitations under the
- * License.
- *
- * The Original Code is mozilla.org code.
- *
- * The Initial Developer of the Original Code is
- * Netscape Communications Corporation.
- * Portions created by the Initial Developer are Copyright (C) 1998
- * the Initial Developer. All Rights Reserved.
- *
- * Contributor(s):
- *   John C. Griggs <johng@corel.com>
- *
- * Alternatively, the contents of this file may be used under the terms of
- * either the GNU General Public License Version 2 or later (the "GPL"), or
- * the GNU Lesser General Public License Version 2.1 or later (the "LGPL"),
- * in which case the provisions of the GPL or the LGPL are applicable instead
- * of those above. If you wish to allow use of your version of this file only
- * under the terms of either the GPL or the LGPL, and not to allow others to
- * use your version of this file under the terms of the MPL, indicate your
- * decision by deleting the provisions above and replace them with the notice
- * and other provisions required by the GPL or the LGPL. If you do not delete
- * the provisions above, a recipient may use your version of this file under
- * the terms of any one of the MPL, the GPL or the LGPL.
- *
- * ***** END LICENSE BLOCK ***** */
-#ifndef nsToolkit_h__      
-#define nsToolkit_h__
-
-#include <QPixmap>
-
-#include "nsIToolkit.h"
-#include "nsString.h"
-
-/**
- * Wrapper around the thread running the message pump.
- * The toolkit abstraction is necessary because the message pump must
- * execute within the same thread that created the widget under Win32.
- */ 
-class nsToolkit : public nsIToolkit
-{
-public:
-    nsToolkit();
-    virtual ~nsToolkit();
-
-    void          CreateSharedGC(void);
-    Qt::HANDLE    GetSharedGC(void);
-
-    /**
-     * Get/set our value of DESKTOP_STARTUP_ID. When non-empty, this is applied
-     * to the next toplevel window to be shown or focused (and then immediately
-     * cleared).
-     */ 
-    void SetDesktopStartupID(const nsACString& aID) { mDesktopStartupID = aID; }
-    void GetDesktopStartupID(nsACString* aID) { *aID = mDesktopStartupID; }
-
-    /**
-     * Get/set the timestamp value to be used, if non-zero, to focus the
-     * next top-level window to be shown or focused (upon which it is cleared).
-     */
-    void SetFocusTimestamp(PRUint32 aTimestamp) { mFocusTimestamp = aTimestamp; }
-    PRUint32 GetFocusTimestamp() { return mFocusTimestamp; }
-
-    NS_DECL_ISUPPORTS
-    NS_IMETHOD Init(PRThread *aThread);
-
-private:
-    nsCString      mDesktopStartupID;
-    PRUint32       mFocusTimestamp;
-    QPixmap        *mSharedGC;
-};
-
-#endif  // nsToolkit_h__
--- a/widget/src/qt/nsWidgetFactory.cpp
+++ b/widget/src/qt/nsWidgetFactory.cpp
@@ -42,17 +42,16 @@
 #include "nsWindow.h"
 #include "nsAppShell.h"
 
 #include "mozilla/ModuleUtils.h"
 #include "nsIModule.h"
 
 #include "nsCOMPtr.h"
 #include "nsWidgetsCID.h"
-#include "nsToolkit.h"
 #include "nsHTMLFormatConverter.h"
 #include "nsTransferable.h"
 #include "nsLookAndFeel.h"
 #include "nsAppShellSingleton.h"
 #include "nsScreenManagerQt.h"
 #include "nsFilePicker.h"
 #include "nsClipboard.h"
 #include "nsClipboardHelper.h"
@@ -75,17 +74,16 @@
 #endif
 
 // from nsWindow.cpp
 extern bool gDisableNativeTheme;
 
 NS_GENERIC_FACTORY_CONSTRUCTOR(nsWindow)
 NS_GENERIC_FACTORY_CONSTRUCTOR(nsChildWindow)
 NS_GENERIC_FACTORY_CONSTRUCTOR(nsPopupWindow)
-NS_GENERIC_FACTORY_CONSTRUCTOR(nsToolkit)
 NS_GENERIC_FACTORY_CONSTRUCTOR(nsHTMLFormatConverter)
 NS_GENERIC_FACTORY_CONSTRUCTOR(nsTransferable)
 NS_GENERIC_FACTORY_CONSTRUCTOR(nsScreenManagerQt)
 NS_GENERIC_FACTORY_CONSTRUCTOR(nsClipboard)
 NS_GENERIC_FACTORY_CONSTRUCTOR(nsClipboardHelper)
 NS_GENERIC_FACTORY_CONSTRUCTOR(nsDragService)
 NS_GENERIC_FACTORY_CONSTRUCTOR(nsBidiKeyboard)
 NS_GENERIC_FACTORY_CONSTRUCTOR(nsIdleServiceQt)
@@ -163,17 +161,16 @@ NS_DEFINE_NAMED_CID(NS_CLIPBOARD_CID);
 NS_DEFINE_NAMED_CID(NS_CLIPBOARDHELPER_CID);
 NS_DEFINE_NAMED_CID(NS_DRAGSERVICE_CID);
 NS_DEFINE_NAMED_CID(NS_HTMLFORMATCONVERTER_CID);
 NS_DEFINE_NAMED_CID(NS_BIDIKEYBOARD_CID);
 NS_DEFINE_NAMED_CID(NS_SCREENMANAGER_CID);
 NS_DEFINE_NAMED_CID(NS_THEMERENDERER_CID);
 NS_DEFINE_NAMED_CID(NS_IDLE_SERVICE_CID);
 NS_DEFINE_NAMED_CID(NS_POPUP_CID);
-NS_DEFINE_NAMED_CID(NS_TOOLKIT_CID);
 #ifdef NS_PRINTING
 NS_DEFINE_NAMED_CID(NS_PRINTSETTINGSSERVICE_CID);
 NS_DEFINE_NAMED_CID(NS_PRINTER_ENUMERATOR_CID);
 NS_DEFINE_NAMED_CID(NS_PRINTSESSION_CID);
 NS_DEFINE_NAMED_CID(NS_DEVICE_CONTEXT_SPEC_CID);
 NS_DEFINE_NAMED_CID(NS_PRINTDIALOGSERVICE_CID);
 #endif
 
@@ -192,17 +189,16 @@ static const mozilla::Module::CIDEntry k
     { &kNS_CLIPBOARDHELPER_CID, false, NULL, nsClipboardHelperConstructor },
     { &kNS_DRAGSERVICE_CID, false, NULL, nsDragServiceConstructor },
     { &kNS_HTMLFORMATCONVERTER_CID, false, NULL, nsHTMLFormatConverterConstructor },
     { &kNS_BIDIKEYBOARD_CID, false, NULL, nsBidiKeyboardConstructor },
     { &kNS_SCREENMANAGER_CID, false, NULL, nsScreenManagerQtConstructor },
     { &kNS_THEMERENDERER_CID, false, NULL, nsNativeThemeQtConstructor },
     { &kNS_IDLE_SERVICE_CID, false, NULL, nsIdleServiceQtConstructor },
     { &kNS_POPUP_CID, false, NULL, nsPopupWindowConstructor },
-    { &kNS_TOOLKIT_CID, false, NULL, nsToolkitConstructor },
 #ifdef NS_PRINTING
     { &kNS_PRINTSETTINGSSERVICE_CID, false, NULL, nsPrintOptionsQtConstructor },
     { &kNS_PRINTER_ENUMERATOR_CID, false, NULL, nsPrinterEnumeratorQtConstructor },
     { &kNS_PRINTSESSION_CID, false, NULL, nsPrintSessionConstructor },
     { &kNS_DEVICE_CONTEXT_SPEC_CID, false, NULL, nsDeviceContextSpecQtConstructor },
     { &kNS_PRINTDIALOGSERVICE_CID, false, NULL, nsPrintDialogServiceQtConstructor },
 #endif
 #if defined(MOZ_X11)
@@ -222,17 +218,16 @@ static const mozilla::Module::ContractID
     { "@mozilla.org/widget/clipboardhelper;1", &kNS_CLIPBOARDHELPER_CID },
     { "@mozilla.org/widget/dragservice;1", &kNS_DRAGSERVICE_CID },
     { "@mozilla.org/widget/htmlformatconverter;1", &kNS_HTMLFORMATCONVERTER_CID },
     { "@mozilla.org/widget/bidikeyboard;1", &kNS_BIDIKEYBOARD_CID },
     { "@mozilla.org/gfx/screenmanager;1", &kNS_SCREENMANAGER_CID },
     { "@mozilla.org/chrome/chrome-native-theme;1", &kNS_THEMERENDERER_CID },
     { "@mozilla.org/widget/idleservice;1", &kNS_IDLE_SERVICE_CID },
     { "@mozilla.org/widgets/popup_window/qt;1", &kNS_POPUP_CID },
-    { "@mozilla.org/widget/toolkit/qt;1", &kNS_TOOLKIT_CID },
 #ifdef NS_PRINTING
     { "@mozilla.org/gfx/printsettings-service;1", &kNS_PRINTSETTINGSSERVICE_CID },
     { "@mozilla.org/gfx/printerenumerator;1", &kNS_PRINTER_ENUMERATOR_CID },
     { "@mozilla.org/gfx/printsession;1", &kNS_PRINTSESSION_CID },
     { "@mozilla.org/gfx/devicecontextspec;1", &kNS_DEVICE_CONTEXT_SPEC_CID },
     { NS_PRINTDIALOGSERVICE_CONTRACTID, &kNS_PRINTDIALOGSERVICE_CID },
 #endif
 #if defined(MOZ_X11)
--- a/widget/src/qt/nsWindow.cpp
+++ b/widget/src/qt/nsWindow.cpp
@@ -90,17 +90,16 @@ using namespace QtMobility;
 
 #include "nsWindow.h"
 #include "mozqwidget.h"
 
 #ifdef MOZ_ENABLE_QTMOBILITY
 #include "mozqorientationsensorfilter.h"
 #endif
 
-#include "nsToolkit.h"
 #include "nsIdleService.h"
 #include "nsRenderingContext.h"
 #include "nsIRollupListener.h"
 #include "nsIMenuRollup.h"
 #include "nsWidgetsCID.h"
 #include "nsQtKeyUtils.h"
 #include "mozilla/Services.h"
 #include "mozilla/Preferences.h"
@@ -819,18 +818,17 @@ nsWindow::GetNativeData(PRUint32 aDataTy
             return widget ? widget->x11Info().display() : nsnull;
 #else
             return nsnull;
 #endif
         }
         break;
 
     case NS_NATIVE_GRAPHIC: {
-        NS_ASSERTION(nsnull != mToolkit, "NULL toolkit, unable to get a GC");
-        return (void *)static_cast<nsToolkit *>(mToolkit)->GetSharedGC();
+        return nsnull;
         break;
     }
 
     case NS_NATIVE_SHELLWIDGET: {
         QWidget* widget = nsnull;
         if (mWidget && mWidget->scene())
             widget = mWidget->scene()->views()[0]->viewport();
         return (void *) widget;
@@ -2250,17 +2248,16 @@ GetBrandName(nsXPIDLString& brandName)
 
 
 nsresult
 nsWindow::Create(nsIWidget        *aParent,
                  nsNativeWidget    aNativeParent,
                  const nsIntRect  &aRect,
                  EVENT_CALLBACK    aHandleEventFunction,
                  nsDeviceContext *aContext,
-                 nsIToolkit       *aToolkit,
                  nsWidgetInitData *aInitData)
 {
     // only set the base parent if we're not going to be a dialog or a
     // toplevel
     nsIWidget *baseParent = aParent;
 
     if (aInitData &&
         (aInitData->mWindowType == eWindowType_dialog ||
@@ -2268,18 +2265,17 @@ nsWindow::Create(nsIWidget        *aPare
          aInitData->mWindowType == eWindowType_invisible)) {
 
         baseParent = nsnull;
         // also drop native parent for toplevel windows
         aNativeParent = nsnull;
     }
 
     // initialize all the common bits of this class
-    BaseCreate(baseParent, aRect, aHandleEventFunction, aContext,
-               aToolkit, aInitData);
+    BaseCreate(baseParent, aRect, aHandleEventFunction, aContext, aInitData);
 
     // and do our common creation
     mParent = aParent;
 
     // save our bounds
     mBounds = aRect;
 
     // find native parent
@@ -2305,25 +2301,23 @@ nsWindow::Create(nsIWidget        *aPare
 
     return NS_OK;
 }
 
 already_AddRefed<nsIWidget>
 nsWindow::CreateChild(const nsIntRect&  aRect,
                       EVENT_CALLBACK    aHandleEventFunction,
                       nsDeviceContext* aContext,
-                      nsIToolkit*       aToolkit,
                       nsWidgetInitData* aInitData,
                       bool              /*aForceUseIWidgetParent*/)
 {
     //We need to force parent widget, otherwise GetTopLevelWindow doesn't work
     return nsBaseWidget::CreateChild(aRect,
                                      aHandleEventFunction,
                                      aContext,
-                                     aToolkit,
                                      aInitData,
                                      true); // Force parent
 }
 
 
 NS_IMETHODIMP
 nsWindow::SetWindowClass(const nsAString &xulWinType)
 {
@@ -3119,17 +3113,17 @@ nsWindow::IsEnabled(bool *aState)
 void
 nsWindow::OnDestroy(void)
 {
     if (mOnDestroyCalled)
         return;
 
     mOnDestroyCalled = true;
 
-    // release references to children, device context, toolkit + app shell
+    // release references to children and device context
     nsBaseWidget::OnDestroy();
 
     // let go of our parent
     mParent = nsnull;
 
     nsCOMPtr<nsIWidget> kungFuDeathGrip = this;
 
     nsGUIEvent event(true, NS_DESTROY, this);
--- a/widget/src/qt/nsWindow.h
+++ b/widget/src/qt/nsWindow.h
@@ -123,24 +123,22 @@ public:
 
     NS_IMETHOD         ConfigureChildren(const nsTArray<nsIWidget::Configuration>&);
 
     NS_IMETHOD         Create(nsIWidget        *aParent,
                               nsNativeWidget   aNativeParent,
                               const nsIntRect  &aRect,
                               EVENT_CALLBACK   aHandleEventFunction,
                               nsDeviceContext *aContext,
-                              nsIToolkit       *aToolkit,
                               nsWidgetInitData *aInitData);
 
     virtual already_AddRefed<nsIWidget>
     CreateChild(const nsIntRect&  aRect,
                 EVENT_CALLBACK    aHandleEventFunction,
                 nsDeviceContext* aContext,
-                nsIToolkit*       aToolkit = nsnull,
                 nsWidgetInitData* aInitData = nsnull,
                 bool              aForceUseIWidgetParent = true);
 
     NS_IMETHOD         Destroy(void);
     NS_IMETHOD         SetParent(nsIWidget* aNewParent);
     virtual nsIWidget *GetParent(void);
     virtual float      GetDPI();
     NS_IMETHOD         Show(bool aState);
--- a/widget/src/windows/nsToolkit.cpp
+++ b/widget/src/windows/nsToolkit.cpp
@@ -48,24 +48,17 @@
 #include <objbase.h>
 #include <initguid.h>
 
 #include "nsUXThemeData.h"
 
 // unknwn.h is needed to build with WIN32_LEAN_AND_MEAN
 #include <unknwn.h>
 
-NS_IMPL_ISUPPORTS1(nsToolkit, nsIToolkit)
-
-//
-// Static thread local storage index of the Toolkit 
-// object associated with a given thread...
-//
-static PRUintn gToolkitTLSIndex = 0;
-
+nsToolkit* nsToolkit::gToolkit = nsnull;
 
 HINSTANCE nsToolkit::mDllInstance = 0;
 bool      nsToolkit::mIsWinXP     = false;
 static bool dummy = nsToolkit::InitVersionInfo();
 
 static const unsigned long kD3DUsageDelay = 5000;
 
 static void
@@ -120,16 +113,32 @@ nsToolkit::nsToolkit()
     mGuiThread  = NULL;
     mDispatchWnd = 0;
 
 #if defined(MOZ_STATIC_COMPONENT_LIBS)
     nsToolkit::Startup(GetModuleHandle(NULL));
 #endif
 
     gMouseTrailer = new MouseTrailer();
+
+    // Store the thread ID of the thread containing the message pump.  
+    // If no thread is provided create one
+    PRThread* thread = PR_GetCurrentThread();
+    if (NULL != thread) {
+      CreateInternalWindow(thread);
+    } else {
+      // create a thread where the message pump will run
+      CreateUIThread();
+    }
+
+    mD3D9Timer = do_CreateInstance("@mozilla.org/timer;1");
+    mD3D9Timer->InitWithFuncCallback(::StartAllowingD3D9,
+                                     NULL,
+                                     kD3DUsageDelay,
+                                     nsITimer::TYPE_ONE_SHOT);
 }
 
 
 //-------------------------------------------------------------------------
 //
 // destructor
 //
 //-------------------------------------------------------------------------
@@ -137,28 +146,21 @@ nsToolkit::~nsToolkit()
 {
     MOZ_COUNT_DTOR(nsToolkit);
     NS_PRECONDITION(::IsWindow(mDispatchWnd), "Invalid window handle");
 
     // Destroy the Dispatch Window
     ::DestroyWindow(mDispatchWnd);
     mDispatchWnd = NULL;
 
-    // Remove the TLS reference to the toolkit...
-    PR_SetThreadPrivate(gToolkitTLSIndex, nsnull);
-
     if (gMouseTrailer) {
       gMouseTrailer->DestroyTimer();
       delete gMouseTrailer;
       gMouseTrailer = nsnull;
     }
-
-#if defined (MOZ_STATIC_COMPONENT_LIBS)
-    nsToolkit::Shutdown();
-#endif
 }
 
 void
 nsToolkit::Startup(HMODULE hModule)
 {
     nsToolkit::mDllInstance = hModule;
 
     //
@@ -180,28 +182,31 @@ nsToolkit::Startup(HMODULE hModule)
 
     nsUXThemeData::Initialize();
 }
 
 
 void
 nsToolkit::Shutdown()
 {
+#if defined (MOZ_STATIC_COMPONENT_LIBS)
     // Crashes on certain XP machines/profiles - see bug 448104 for details
     //nsUXThemeData::Teardown();
     //VERIFY(::UnregisterClass("nsToolkitClass", nsToolkit::mDllInstance));
     ::UnregisterClassW(L"nsToolkitClass", nsToolkit::mDllInstance);
+#endif
+
+    delete gToolkit;
+    gToolkit = nsnull;
 }
 
 void
 nsToolkit::StartAllowingD3D9()
 {
-  nsRefPtr<nsIToolkit> toolkit;
-  NS_GetCurrentToolkit(getter_AddRefs(toolkit));
-  static_cast<nsToolkit*>(toolkit.get())->mD3D9Timer->Cancel();
+  nsToolkit::GetToolkit()->mD3D9Timer->Cancel();
   nsWindow::StartAllowingD3D9(false);
 }
 
 //-------------------------------------------------------------------------
 //
 // Register the window class for the internal window and create the window
 //
 //-------------------------------------------------------------------------
@@ -261,40 +266,16 @@ void nsToolkit::CreateUIThread()
     // at this point the thread is running
     ::PR_ExitMonitor(monitor);
     ::PR_DestroyMonitor(monitor);
 }
 
 
 //-------------------------------------------------------------------------
 //
-//
-//-------------------------------------------------------------------------
-NS_METHOD nsToolkit::Init(PRThread *aThread)
-{
-    // Store the thread ID of the thread containing the message pump.  
-    // If no thread is provided create one
-    if (NULL != aThread) {
-        CreateInternalWindow(aThread);
-    } else {
-        // create a thread where the message pump will run
-        CreateUIThread();
-    }
-
-    mD3D9Timer = do_CreateInstance("@mozilla.org/timer;1");
-    mD3D9Timer->InitWithFuncCallback(::StartAllowingD3D9,
-                                     NULL,
-                                     kD3DUsageDelay,
-                                     nsITimer::TYPE_ONE_SHOT);
-
-    return NS_OK;
-}
-
-//-------------------------------------------------------------------------
-//
 // nsToolkit WindowProc. Used to call methods on the "main GUI thread"...
 //
 //-------------------------------------------------------------------------
 LRESULT CALLBACK nsToolkit::WindowProc(HWND hWnd, UINT msg, WPARAM wParam, 
                                        LPARAM lParam)
 {
     switch (msg) {
         case WM_SYSCOLORCHANGE:
@@ -314,61 +295,28 @@ LRESULT CALLBACK nsToolkit::WindowProc(H
 
     return ::DefWindowProcW(hWnd, msg, wParam, lParam);
 }
 
 
 
 //-------------------------------------------------------------------------
 //
-// Return the nsIToolkit for the current thread.  If a toolkit does not
+// Return the nsToolkit for the current thread.  If a toolkit does not
 // yet exist, then one will be created...
 //
 //-------------------------------------------------------------------------
-NS_METHOD NS_GetCurrentToolkit(nsIToolkit* *aResult)
+// static
+nsToolkit* nsToolkit::GetToolkit()
 {
-  nsIToolkit* toolkit = nsnull;
-  nsresult rv = NS_OK;
-  PRStatus status;
-
-  // Create the TLS index the first time through...
-  if (0 == gToolkitTLSIndex) {
-    status = PR_NewThreadPrivateIndex(&gToolkitTLSIndex, NULL);
-    if (PR_FAILURE == status) {
-      rv = NS_ERROR_FAILURE;
-    }
+  if (!gToolkit) {
+    gToolkit = new nsToolkit();
   }
 
-  if (NS_SUCCEEDED(rv)) {
-    toolkit = (nsIToolkit*)PR_GetThreadPrivate(gToolkitTLSIndex);
-
-    //
-    // Create a new toolkit for this thread...
-    //
-    if (!toolkit) {
-      toolkit = new nsToolkit();
-
-      if (!toolkit) {
-        rv = NS_ERROR_OUT_OF_MEMORY;
-      } else {
-        NS_ADDREF(toolkit);
-        toolkit->Init(PR_GetCurrentThread());
-        //
-        // The reference stored in the TLS is weak.  It is removed in the
-        // nsToolkit destructor...
-        //
-        PR_SetThreadPrivate(gToolkitTLSIndex, (void*)toolkit);
-      }
-    } else {
-      NS_ADDREF(toolkit);
-    }
-    *aResult = toolkit;
-  }
-
-  return rv;
+  return gToolkit;
 }
 
 
 bool nsToolkit::InitVersionInfo()
 {
   static bool isInitialized = false;
 
   if (!isInitialized)
--- a/widget/src/windows/nsToolkit.h
+++ b/widget/src/windows/nsToolkit.h
@@ -35,17 +35,16 @@
  * the terms of any one of the MPL, the GPL or the LGPL.
  *
  * ***** END LICENSE BLOCK ***** */
 
 #ifndef TOOLKIT_H      
 #define TOOLKIT_H
 
 #include "nsdefs.h"
-#include "nsIToolkit.h"
 
 #include "nsITimer.h"
 #include "nsCOMPtr.h"
 
 #include <imm.h>
 
 // Avoid including windowsx.h to prevent macro pollution
 #ifndef GET_X_LPARAM
@@ -68,39 +67,40 @@ class MouseTrailer;
 
 
 /**
  * Wrapper around the thread running the message pump.
  * The toolkit abstraction is necessary because the message pump must
  * execute within the same thread that created the widget under Win32.
  */ 
 
-class nsToolkit : public nsIToolkit
+class nsToolkit
 {
 
   public:
-
-            NS_DECL_ISUPPORTS
-
                             nsToolkit();
-            NS_IMETHOD      Init(PRThread *aThread);
             void            CreateInternalWindow(PRThread *aThread);
 
 private:
                             ~nsToolkit();
             void            CreateUIThread(void);
 
 public:
+
+    static nsToolkit* GetToolkit();
+
     // Window procedure for the internal window
     static LRESULT CALLBACK WindowProc(HWND hWnd, 
                                         UINT Msg, 
                                         WPARAM WParam, 
                                         LPARAM lParam);
 
 protected:
+    static nsToolkit* gToolkit;
+
     // Handle of the window used to receive dispatch messages.
     HWND        mDispatchWnd;
     // Thread Id of the "main" Gui thread.
     PRThread    *mGuiThread;
     nsCOMPtr<nsITimer> mD3D9Timer;
 
 public:
     static HINSTANCE mDllInstance;
@@ -110,18 +110,16 @@ public:
     static bool InitVersionInfo();
     static void Startup(HINSTANCE hModule);
     static void Shutdown();
     static void StartAllowingD3D9();
 
     static MouseTrailer *gMouseTrailer;
 };
 
-class  nsWindow;
-
 /**
  * Makes sure exit/enter mouse messages are always dispatched.
  * In the case where the mouse has exited the outer most window the
  * only way to tell if it has exited is to set a timer and look at the
  * mouse pointer to see if it is within the outer most window.
  */ 
 
 class MouseTrailer 
--- a/widget/src/windows/nsWindow.cpp
+++ b/widget/src/windows/nsWindow.cpp
@@ -500,34 +500,36 @@ PRInt32 nsWindow::GetHeight(PRInt32 aPro
 
 // Create the proper widget
 nsresult
 nsWindow::Create(nsIWidget *aParent,
                  nsNativeWidget aNativeParent,
                  const nsIntRect &aRect,
                  EVENT_CALLBACK aHandleEventFunction,
                  nsDeviceContext *aContext,
-                 nsIToolkit *aToolkit,
                  nsWidgetInitData *aInitData)
 {
   nsWidgetInitData defaultInitData;
   if (!aInitData)
     aInitData = &defaultInitData;
 
   mUnicodeWidget = aInitData->mUnicode;
 
   nsIWidget *baseParent = aInitData->mWindowType == eWindowType_dialog ||
                           aInitData->mWindowType == eWindowType_toplevel ||
                           aInitData->mWindowType == eWindowType_invisible ?
                           nsnull : aParent;
 
   mIsTopWidgetWindow = (nsnull == baseParent);
   mBounds = aRect;
 
-  BaseCreate(baseParent, aRect, aHandleEventFunction, aContext, aToolkit, aInitData);
+  // Ensure that the toolkit is created.
+  nsToolkit::GetToolkit();
+
+  BaseCreate(baseParent, aRect, aHandleEventFunction, aContext, aInitData);
 
   HWND parent;
   if (aParent) { // has a nsIWidget parent
     parent = aParent ? (HWND)aParent->GetNativeData(NS_NATIVE_WINDOW) : NULL;
     mParent = aParent;
   } else { // has a nsNative parent
     parent = (HWND)aNativeParent;
     mParent = aNativeParent ? GetNSWindowPtr((HWND)aNativeParent) : nsnull;
--- a/widget/src/windows/nsWindow.h
+++ b/widget/src/windows/nsWindow.h
@@ -109,17 +109,16 @@ public:
   /**
    * nsIWidget interface
    */
   NS_IMETHOD              Create(nsIWidget *aParent,
                                  nsNativeWidget aNativeParent,
                                  const nsIntRect &aRect,
                                  EVENT_CALLBACK aHandleEventFunction,
                                  nsDeviceContext *aContext,
-                                 nsIToolkit *aToolkit = nsnull,
                                  nsWidgetInitData *aInitData = nsnull);
   NS_IMETHOD              Destroy();
   NS_IMETHOD              SetParent(nsIWidget *aNewParent);
   virtual nsIWidget*      GetParent(void);
   virtual float           GetDPI();
   NS_IMETHOD              Show(bool bState);
   NS_IMETHOD              IsVisible(bool & aState);
   NS_IMETHOD              ConstrainPosition(bool aAllowSlop, PRInt32 *aX, PRInt32 *aY);
--- a/widget/src/xpwidgets/Makefile.in
+++ b/widget/src/xpwidgets/Makefile.in
@@ -44,17 +44,16 @@ include $(DEPTH)/config/autoconf.mk
 
 MODULE		= widget
 LIBRARY_NAME	= xpwidgets_s
 LIBXUL_LIBRARY  = 1
 
 
 DEFINES += \
   -D_IMPL_NS_WIDGET \
-  -DUSE_TLS_FOR_TOOLKIT \
   -DNO_NSPR_10_SUPPORT=1 \
   $(NULL)
 
 CPPSRCS		= \
 		nsBaseAppShell.cpp \
 		nsBaseWidget.cpp \
 		nsTransferable.cpp \
 		nsHTMLFormatConverter.cpp \
--- a/widget/src/xpwidgets/PuppetWidget.cpp
+++ b/widget/src/xpwidgets/PuppetWidget.cpp
@@ -107,23 +107,21 @@ PuppetWidget::~PuppetWidget()
 }
 
 NS_IMETHODIMP
 PuppetWidget::Create(nsIWidget        *aParent,
                      nsNativeWidget   aNativeParent,
                      const nsIntRect  &aRect,
                      EVENT_CALLBACK   aHandleEventFunction,
                      nsDeviceContext *aContext,
-                     nsIToolkit       *aToolkit,
                      nsWidgetInitData *aInitData)
 {
   NS_ABORT_IF_FALSE(!aNativeParent, "got a non-Puppet native parent");
 
-  BaseCreate(nsnull, aRect, aHandleEventFunction, aContext,
-             aToolkit, aInitData);
+  BaseCreate(nsnull, aRect, aHandleEventFunction, aContext, aInitData);
 
   mBounds = aRect;
   mEnabled = true;
   mVisible = true;
 
   mSurface = gfxPlatform::GetPlatform()
              ->CreateOffscreenSurface(gfxIntSize(1, 1),
                                       gfxASurface::ContentFromFormat(gfxASurface::ImageFormatARGB32));
@@ -146,27 +144,25 @@ PuppetWidget::Create(nsIWidget        *a
 
   return NS_OK;
 }
 
 already_AddRefed<nsIWidget>
 PuppetWidget::CreateChild(const nsIntRect  &aRect,
                           EVENT_CALLBACK   aHandleEventFunction,
                           nsDeviceContext *aContext,
-                          nsIToolkit       *aToolkit,
                           nsWidgetInitData *aInitData,
                           bool             aForceUseIWidgetParent)
 {
   bool isPopup = IsPopup(aInitData);
   nsCOMPtr<nsIWidget> widget = nsIWidget::CreatePuppetWidget(mTabChild);
   return ((widget &&
            NS_SUCCEEDED(widget->Create(isPopup ? nsnull: this, nsnull, aRect,
                                        aHandleEventFunction,
-                                       aContext, aToolkit,
-                                       aInitData))) ?
+                                       aContext, aInitData))) ?
           widget.forget() : nsnull);
 }
 
 NS_IMETHODIMP
 PuppetWidget::Destroy()
 {
   Base::OnDestroy();
   Base::Destroy();
--- a/widget/src/xpwidgets/PuppetWidget.h
+++ b/widget/src/xpwidgets/PuppetWidget.h
@@ -69,25 +69,23 @@ public:
   virtual ~PuppetWidget();
 
   NS_DECL_ISUPPORTS_INHERITED
 
   NS_IMETHOD Create(nsIWidget*        aParent,
                     nsNativeWidget    aNativeParent,
                     const nsIntRect&  aRect,
                     EVENT_CALLBACK    aHandleEventFunction,
-                    nsDeviceContext* aContext,
-                    nsIToolkit*       aToolkit = nsnull,
+                    nsDeviceContext*  aContext,
                     nsWidgetInitData* aInitData = nsnull);
 
   virtual already_AddRefed<nsIWidget>
   CreateChild(const nsIntRect  &aRect,
               EVENT_CALLBACK   aHandleEventFunction,
-              nsDeviceContext *aContext,
-              nsIToolkit       *aToolkit = nsnull,
+              nsDeviceContext  *aContext,
               nsWidgetInitData *aInitData = nsnull,
               bool             aForceUseIWidgetParent = false);
 
   NS_IMETHOD Destroy();
 
   NS_IMETHOD Show(bool aState);
   NS_IMETHOD IsVisible(bool& aState)
   { aState = mVisible; return NS_OK; }
--- a/widget/src/xpwidgets/nsBaseWidget.cpp
+++ b/widget/src/xpwidgets/nsBaseWidget.cpp
@@ -99,17 +99,16 @@ nsAutoRollup::~nsAutoRollup()
 //-------------------------------------------------------------------------
 
 nsBaseWidget::nsBaseWidget()
 : mClientData(nsnull)
 , mViewWrapperPtr(nsnull)
 , mEventCallback(nsnull)
 , mViewCallback(nsnull)
 , mContext(nsnull)
-, mToolkit(nsnull)
 , mCursor(eCursor_standard)
 , mWindowType(eWindowType_child)
 , mBorderStyle(eBorderStyle_none)
 , mOnDestroyCalled(false)
 , mUseAcceleratedRendering(false)
 , mTemporarilyUseBasicLayerManager(false)
 , mBounds(0,0,0,0)
 , mOriginalBounds(nsnull)
@@ -145,67 +144,32 @@ nsBaseWidget::~nsBaseWidget()
     mLayerManager->Destroy();
   }
 
 #ifdef NOISY_WIDGET_LEAKS
   gNumWidgets--;
   printf("WIDGETS- = %d\n", gNumWidgets);
 #endif
 
-  NS_IF_RELEASE(mToolkit);
   NS_IF_RELEASE(mContext);
   delete mOriginalBounds;
 }
 
 
 //-------------------------------------------------------------------------
 //
 // Basic create.
 //
 //-------------------------------------------------------------------------
 void nsBaseWidget::BaseCreate(nsIWidget *aParent,
                               const nsIntRect &aRect,
                               EVENT_CALLBACK aHandleEventFunction,
                               nsDeviceContext *aContext,
-                              nsIToolkit *aToolkit,
                               nsWidgetInitData *aInitData)
 {
-  if (nsnull == mToolkit) {
-    if (nsnull != aToolkit) {
-      mToolkit = (nsIToolkit*)aToolkit;
-      NS_ADDREF(mToolkit);
-    }
-    else {
-      if (nsnull != aParent) {
-        mToolkit = aParent->GetToolkit();
-        NS_IF_ADDREF(mToolkit);
-      }
-      // it's some top level window with no toolkit passed in.
-      // Create a default toolkit with the current thread
-#if !defined(USE_TLS_FOR_TOOLKIT)
-      else {
-        static NS_DEFINE_CID(kToolkitCID, NS_TOOLKIT_CID);
-        
-        nsresult res;
-        res = CallCreateInstance(kToolkitCID, &mToolkit);
-        NS_ASSERTION(NS_SUCCEEDED(res), "Can not create a toolkit in nsBaseWidget::Create");
-        if (mToolkit)
-          mToolkit->Init(PR_GetCurrentThread());
-      }
-#else /* USE_TLS_FOR_TOOLKIT */
-      else {
-        nsresult rv;
-
-        rv = NS_GetCurrentToolkit(&mToolkit);
-      }
-#endif /* USE_TLS_FOR_TOOLKIT */
-    }
-    
-  }
-  
   // save the event callback function
   mEventCallback = aHandleEventFunction;
   
   // keep a reference to the device context
   if (aContext) {
     mContext = aContext;
     NS_ADDREF(mContext);
   }
@@ -248,17 +212,16 @@ NS_IMETHODIMP nsBaseWidget::SetClientDat
   mClientData = aClientData;
   return NS_OK;
 }
 
 already_AddRefed<nsIWidget>
 nsBaseWidget::CreateChild(const nsIntRect  &aRect,
                           EVENT_CALLBACK   aHandleEventFunction,
                           nsDeviceContext *aContext,
-                          nsIToolkit       *aToolkit,
                           nsWidgetInitData *aInitData,
                           bool             aForceUseIWidgetParent)
 {
   nsIWidget* parent = this;
   nsNativeWidget nativeParent = nsnull;
 
   if (!aForceUseIWidgetParent) {
     // Use only either parent or nativeParent, not both, to match
@@ -275,18 +238,17 @@ nsBaseWidget::CreateChild(const nsIntRec
   } else {
     static NS_DEFINE_IID(kCChildCID, NS_CHILD_CID);
     widget = do_CreateInstance(kCChildCID);
   }
 
   if (widget &&
       NS_SUCCEEDED(widget->Create(parent, nativeParent, aRect,
                                   aHandleEventFunction,
-                                  aContext, aToolkit,
-                                  aInitData))) {
+                                  aContext, aInitData))) {
     return widget.forget();
   }
 
   return nsnull;
 }
 
 // Attach a view to our widget which we'll send events to. 
 NS_IMETHODIMP
@@ -900,27 +862,16 @@ LayerManager* nsBaseWidget::GetLayerMana
 
 BasicLayerManager* nsBaseWidget::CreateBasicLayerManager()
 {
       return new BasicShadowLayerManager(this);
 }
 
 //-------------------------------------------------------------------------
 //
-// Return the toolkit this widget was created on
-//
-//-------------------------------------------------------------------------
-nsIToolkit* nsBaseWidget::GetToolkit()
-{
-  return mToolkit;
-}
-
-
-//-------------------------------------------------------------------------
-//
 // Return the used device context
 //
 //-------------------------------------------------------------------------
 nsDeviceContext* nsBaseWidget::GetDeviceContext() 
 {
   return mContext; 
 }
 
@@ -939,19 +890,18 @@ gfxASurface *nsBaseWidget::GetThebesSurf
 
 //-------------------------------------------------------------------------
 //
 // Destroy the window
 //
 //-------------------------------------------------------------------------
 void nsBaseWidget::OnDestroy()
 {
-  // release references to device context, toolkit, and app shell
+  // release references to device context and app shell
   NS_IF_RELEASE(mContext);
-  NS_IF_RELEASE(mToolkit);
 }
 
 NS_METHOD nsBaseWidget::SetWindowClass(const nsAString& xulWinType)
 {
   return NS_ERROR_NOT_IMPLEMENTED;
 }
 
 //-------------------------------------------------------------------------
--- a/widget/src/xpwidgets/nsBaseWidget.h
+++ b/widget/src/xpwidgets/nsBaseWidget.h
@@ -35,17 +35,16 @@
  *
  * ***** END LICENSE BLOCK ***** */
 #ifndef nsBaseWidget_h__
 #define nsBaseWidget_h__
 
 #include "nsRect.h"
 #include "nsIWidget.h"
 #include "nsWidgetsCID.h"
-#include "nsIToolkit.h"
 #include "nsILocalFile.h"
 #include "nsString.h"
 #include "nsCOMPtr.h"
 #include "nsGUIEvent.h"
 #include "nsAutoPtr.h"
 #include "BasicLayers.h"
 
 class nsIContent;
@@ -108,17 +107,16 @@ public:
   virtual void            SetTransparencyMode(nsTransparencyMode aMode);
   virtual nsTransparencyMode GetTransparencyMode();
   virtual void            GetWindowClipRegion(nsTArray<nsIntRect>* aRects);
   NS_IMETHOD              SetWindowShadowStyle(PRInt32 aStyle);
   virtual void            SetShowsToolbarButton(bool aShow) {}
   NS_IMETHOD              HideWindowChrome(bool aShouldHide);
   NS_IMETHOD              MakeFullScreen(bool aFullScreen);
   virtual nsDeviceContext* GetDeviceContext();
-  virtual nsIToolkit*     GetToolkit();
   virtual LayerManager*   GetLayerManager(PLayersChild* aShadowManager = nsnull,
                                           LayersBackend aBackendHint = LayerManager::LAYERS_NONE,
                                           LayerManagerPersistence aPersistence = LAYER_MANAGER_CURRENT,
                                           bool* aAllowRetaining = nsnull);
 
   virtual void            DrawOver(LayerManager* aManager, nsIntRect aRect) {}
   virtual void            UpdateThemeGeometries(const nsTArray<ThemeGeometry>& aThemeGeometries) {}
   virtual gfxASurface*    GetThebesSurface();
@@ -160,17 +158,16 @@ public:
   NS_IMETHOD              OnIMESelectionChange(void) { return NS_ERROR_NOT_IMPLEMENTED; }
   virtual nsIMEUpdatePreference GetIMEUpdatePreference() { return nsIMEUpdatePreference(false, false); }
   NS_IMETHOD              OnDefaultButtonLoaded(const nsIntRect &aButtonRect) { return NS_ERROR_NOT_IMPLEMENTED; }
   NS_IMETHOD              OverrideSystemMouseScrollSpeed(PRInt32 aOriginalDelta, bool aIsHorizontal, PRInt32 &aOverriddenDelta);
   virtual already_AddRefed<nsIWidget>
   CreateChild(const nsIntRect  &aRect,
               EVENT_CALLBACK   aHandleEventFunction,
               nsDeviceContext *aContext,
-              nsIToolkit       *aToolkit = nsnull,
               nsWidgetInitData *aInitData = nsnull,
               bool             aForceUseIWidgetParent = false);
   NS_IMETHOD              AttachViewToTopLevel(EVENT_CALLBACK aViewEventFunction, nsDeviceContext *aContext);
   virtual ViewWrapper*    GetAttachedViewPtr();
   NS_IMETHOD              SetAttachedViewPtr(ViewWrapper* aViewWrapper);
   NS_IMETHOD              ResizeClient(PRInt32 aX, PRInt32 aY, PRInt32 aWidth, PRInt32 aHeight, bool aRepaint);
   NS_IMETHOD              GetNonClientMargins(nsIntMargin &margins);
   NS_IMETHOD              SetNonClientMargins(nsIntMargin &margins);
@@ -229,17 +226,16 @@ protected:
   virtual void            ResolveIconName(const nsAString &aIconName,
                                           const nsAString &aIconSuffix,
                                           nsILocalFile **aResult);
   virtual void            OnDestroy();
   virtual void            BaseCreate(nsIWidget *aParent,
                                      const nsIntRect &aRect,
                                      EVENT_CALLBACK aHandleEventFunction,
                                      nsDeviceContext *aContext,
-                                     nsIToolkit *aToolkit,
                                      nsWidgetInitData *aInitData);
 
   virtual nsIContent* GetLastRollup()
   {
     return mLastRollup;
   }
 
   virtual nsresult SynthesizeNativeKeyEvent(PRInt32 aNativeKeyboardLayout,
@@ -269,17 +265,16 @@ protected:
   BasicLayerManager* CreateBasicLayerManager();
 
 protected:
   void*             mClientData;
   ViewWrapper*      mViewWrapperPtr;
   EVENT_CALLBACK    mEventCallback;
   EVENT_CALLBACK    mViewCallback;
   nsDeviceContext* mContext;
-  nsIToolkit*       mToolkit;
   nsRefPtr<LayerManager> mLayerManager;
   nsRefPtr<LayerManager> mBasicLayerManager;
   nscolor           mBackground;
   nscolor           mForeground;
   nsCursor          mCursor;
   nsWindowType      mWindowType;
   nsBorderStyle     mBorderStyle;
   bool              mOnDestroyCalled;
--- a/xpfe/appshell/src/nsWebShellWindow.cpp
+++ b/xpfe/appshell/src/nsWebShellWindow.cpp
@@ -200,17 +200,16 @@ nsresult nsWebShellWindow::Initialize(ns
   }
 
   mWindow->SetClientData(this);
   mWindow->Create((nsIWidget *)parentWidget,          // Parent nsIWidget
                   nsnull,                             // Native parent widget
                   r,                                  // Widget dimensions
                   nsWebShellWindow::HandleEvent,      // Event handler function
                   nsnull,                             // Device context
-                  nsnull,                             // nsIToolkit
                   &widgetInitData);                   // Widget initialization data
   mWindow->GetClientBounds(r);
   // Match the default background color of content. Important on windows
   // since we no longer use content child widgets.
   mWindow->SetBackgroundColor(NS_RGB(255,255,255));
 
   // Create web shell
   mDocShell = do_CreateInstance("@mozilla.org/docshell;1");