Bug 977959 part.5 Make NativeKeyBindings classes non-refcountable r=neil
authorMasayuki Nakano <masayuki@d-toybox.com>
Fri, 14 Mar 2014 22:13:32 +0900
changeset 173587 8e7dd50fde879b9633a1db115e76d62f0d43c322
parent 173586 b9daeea8712a87fd52634caf11d6596286c26689
child 173588 cd1bb57c45f930ee6d0eb14f78bae84da2ca1a53
push id41037
push usermasayuki@d-toybox.com
push dateFri, 14 Mar 2014 13:13:39 +0000
treeherdermozilla-inbound@8e7dd50fde87 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersneil
bugs977959
milestone30.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 977959 part.5 Make NativeKeyBindings classes non-refcountable r=neil
widget/cocoa/NativeKeyBindings.h
widget/cocoa/NativeKeyBindings.mm
widget/cocoa/nsChildView.mm
widget/cocoa/nsCocoaWindow.mm
widget/gtk/NativeKeyBindings.cpp
widget/gtk/NativeKeyBindings.h
widget/gtk/nsWindow.cpp
--- a/widget/cocoa/NativeKeyBindings.h
+++ b/widget/cocoa/NativeKeyBindings.h
@@ -18,21 +18,18 @@ namespace widget {
 typedef nsDataHashtable<nsPtrHashKey<struct objc_selector>, CommandInt>
   SelectorCommandHashtable;
 
 class NativeKeyBindings MOZ_FINAL
 {
   typedef nsIWidget::NativeKeyBindingsType NativeKeyBindingsType;
   typedef nsIWidget::DoCommandCallback DoCommandCallback;
 
-  NS_INLINE_DECL_REFCOUNTING(NativeKeyBindings)
-
 public:
-  static already_AddRefed<NativeKeyBindings>
-    GetInstance(NativeKeyBindingsType aType);
+  static NativeKeyBindings* GetInstance(NativeKeyBindingsType aType);
   static void Shutdown();
 
   void Init(NativeKeyBindingsType aType);
 
   bool Execute(const WidgetKeyboardEvent& aEvent,
                DoCommandCallback aCallback,
                void* aCallbackData);
 
--- a/widget/cocoa/NativeKeyBindings.mm
+++ b/widget/cocoa/NativeKeyBindings.mm
@@ -16,47 +16,47 @@ namespace widget {
 #ifdef PR_LOGGING
 PRLogModuleInfo* gNativeKeyBindingsLog = nullptr;
 #endif
 
 NativeKeyBindings* NativeKeyBindings::sInstanceForSingleLineEditor = nullptr;
 NativeKeyBindings* NativeKeyBindings::sInstanceForMultiLineEditor = nullptr;
 
 // static
-already_AddRefed<NativeKeyBindings>
+NativeKeyBindings*
 NativeKeyBindings::GetInstance(NativeKeyBindingsType aType)
 {
   switch (aType) {
     case nsIWidget::NativeKeyBindingsForSingleLineEditor:
       if (!sInstanceForSingleLineEditor) {
-        NS_ADDREF(sInstanceForSingleLineEditor = new NativeKeyBindings());
+        sInstanceForSingleLineEditor = new NativeKeyBindings();
         sInstanceForSingleLineEditor->Init(aType);
       }
-      NS_ADDREF(sInstanceForSingleLineEditor);
       return sInstanceForSingleLineEditor;
     case nsIWidget::NativeKeyBindingsForMultiLineEditor:
     case nsIWidget::NativeKeyBindingsForRichTextEditor:
       if (!sInstanceForMultiLineEditor) {
-        NS_ADDREF(sInstanceForMultiLineEditor = new NativeKeyBindings());
+        sInstanceForMultiLineEditor = new NativeKeyBindings();
         sInstanceForMultiLineEditor->Init(aType);
       }
-      NS_ADDREF(sInstanceForMultiLineEditor);
       return sInstanceForMultiLineEditor;
     default:
       MOZ_CRASH("Not implemented");
       return nullptr;
   }
 }
 
 // static
 void
 NativeKeyBindings::Shutdown()
 {
-  NS_IF_RELEASE(sInstanceForSingleLineEditor);
-  NS_IF_RELEASE(sInstanceForMultiLineEditor);
+  delete sInstanceForSingleLineEditor;
+  sInstanceForSingleLineEditor = nullptr;
+  delete sInstanceForMultiLineEditor;
+  sInstanceForMultiLineEditor = nullptr;
 }
 
 NativeKeyBindings::NativeKeyBindings()
 {
 }
 
 #define SEL_TO_COMMAND(aSel, aCommand) \
   mSelectorToCommand.Put( \
--- a/widget/cocoa/nsChildView.mm
+++ b/widget/cocoa/nsChildView.mm
@@ -1964,18 +1964,17 @@ nsChildView::GetInputContext()
 }
 
 NS_IMETHODIMP_(bool)
 nsChildView::ExecuteNativeKeyBinding(NativeKeyBindingsType aType,
                                      const WidgetKeyboardEvent& aEvent,
                                      DoCommandCallback aCallback,
                                      void* aCallbackData)
 {
-  nsRefPtr<NativeKeyBindings> keyBindings =
-    NativeKeyBindings::GetInstance(aType);
+  NativeKeyBindings* keyBindings = NativeKeyBindings::GetInstance(aType);
   return keyBindings->Execute(aEvent, aCallback, aCallbackData);
 }
 
 nsIMEUpdatePreference
 nsChildView::GetIMEUpdatePreference()
 {
   return nsIMEUpdatePreference(nsIMEUpdatePreference::NOTIFY_SELECTION_CHANGE);
 }
--- a/widget/cocoa/nsCocoaWindow.mm
+++ b/widget/cocoa/nsCocoaWindow.mm
@@ -2165,18 +2165,17 @@ nsCocoaWindow::SetInputContext(const Inp
 }
 
 NS_IMETHODIMP_(bool)
 nsCocoaWindow::ExecuteNativeKeyBinding(NativeKeyBindingsType aType,
                                        const WidgetKeyboardEvent& aEvent,
                                        DoCommandCallback aCallback,
                                        void* aCallbackData)
 {
-  nsRefPtr<NativeKeyBindings> keyBindings =
-    NativeKeyBindings::GetInstance(aType);
+  NativeKeyBindings* keyBindings = NativeKeyBindings::GetInstance(aType);
   return keyBindings->Execute(aEvent, aCallback, aCallbackData);
 }
 
 
 @implementation WindowDelegate
 
 // We try to find a gecko menu bar to paint. If one does not exist, just paint
 // the application menu by itself so that a window doesn't have some other
--- a/widget/gtk/NativeKeyBindings.cpp
+++ b/widget/gtk/NativeKeyBindings.cpp
@@ -192,48 +192,48 @@ select_all_cb(GtkWidget *w, gboolean sel
   g_signal_stop_emission_by_name(w, "select_all");
   gHandled = true;
 }
 
 NativeKeyBindings* NativeKeyBindings::sInstanceForSingleLineEditor = nullptr;
 NativeKeyBindings* NativeKeyBindings::sInstanceForMultiLineEditor = nullptr;
 
 // static
-already_AddRefed<NativeKeyBindings>
+NativeKeyBindings*
 NativeKeyBindings::GetInstance(NativeKeyBindingsType aType)
 {
   switch (aType) {
     case nsIWidget::NativeKeyBindingsForSingleLineEditor:
       if (!sInstanceForSingleLineEditor) {
-        NS_ADDREF(sInstanceForSingleLineEditor = new NativeKeyBindings());
+        sInstanceForSingleLineEditor = new NativeKeyBindings();
         sInstanceForSingleLineEditor->Init(aType);
       }
-      NS_ADDREF(sInstanceForSingleLineEditor);
       return sInstanceForSingleLineEditor;
 
     default:
       // fallback to multiline editor case in release build
       MOZ_ASSERT(false, "aType is invalid or not yet implemented");
     case nsIWidget::NativeKeyBindingsForMultiLineEditor:
     case nsIWidget::NativeKeyBindingsForRichTextEditor:
       if (!sInstanceForMultiLineEditor) {
-        NS_ADDREF(sInstanceForMultiLineEditor = new NativeKeyBindings());
+        sInstanceForMultiLineEditor = new NativeKeyBindings();
         sInstanceForMultiLineEditor->Init(aType);
       }
-      NS_ADDREF(sInstanceForMultiLineEditor);
       return sInstanceForMultiLineEditor;
   }
 }
 
 // static
 void
 NativeKeyBindings::Shutdown()
 {
-  NS_IF_RELEASE(sInstanceForSingleLineEditor);
-  NS_IF_RELEASE(sInstanceForMultiLineEditor);
+  delete sInstanceForSingleLineEditor;
+  sInstanceForSingleLineEditor = nullptr;
+  delete sInstanceForMultiLineEditor;
+  sInstanceForMultiLineEditor = nullptr;
 }
 
 void
 NativeKeyBindings::Init(NativeKeyBindingsType  aType)
 {
   switch (aType) {
   case nsIWidget::NativeKeyBindingsForSingleLineEditor:
     mNativeTarget = gtk_entry_new();
--- a/widget/gtk/NativeKeyBindings.h
+++ b/widget/gtk/NativeKeyBindings.h
@@ -14,21 +14,18 @@
 namespace mozilla {
 namespace widget {
 
 class NativeKeyBindings MOZ_FINAL
 {
   typedef nsIWidget::NativeKeyBindingsType NativeKeyBindingsType;
   typedef nsIWidget::DoCommandCallback DoCommandCallback;
 
-  NS_INLINE_DECL_REFCOUNTING(NativeKeyBindings)
-
 public:
-  static already_AddRefed<NativeKeyBindings>
-    GetInstance(NativeKeyBindingsType aType);
+  static NativeKeyBindings* GetInstance(NativeKeyBindingsType aType);
   static void Shutdown();
 
   void Init(NativeKeyBindingsType aType);
 
   bool Execute(const WidgetKeyboardEvent& aEvent,
                DoCommandCallback aCallback,
                void* aCallbackData);
 
--- a/widget/gtk/nsWindow.cpp
+++ b/widget/gtk/nsWindow.cpp
@@ -5975,18 +5975,17 @@ nsWindow::GetInputContext()
 }
 
 NS_IMETHODIMP_(bool)
 nsWindow::ExecuteNativeKeyBinding(NativeKeyBindingsType aType,
                                   const WidgetKeyboardEvent& aEvent,
                                   DoCommandCallback aCallback,
                                   void* aCallbackData)
 {
-    nsRefPtr<NativeKeyBindings> keyBindings =
-        NativeKeyBindings::GetInstance(aType);
+    NativeKeyBindings* keyBindings = NativeKeyBindings::GetInstance(aType);
     return keyBindings->Execute(aEvent, aCallback, aCallbackData);
 }
 
 NS_IMETHODIMP
 nsWindow::GetToggledKeyState(uint32_t aKeyCode, bool* aLEDState)
 {
     NS_ENSURE_ARG_POINTER(aLEDState);