Bug 1241302 - Slightly modernize this code. r=jst
authorBlake Kaplan <mrbkap@gmail.com>
Wed, 20 Jan 2016 14:45:00 +0100
changeset 316085 c0be07690562d76bd836a24c817c015b1086f3a2
parent 316084 9f34b95fa1d029c7eae575190efed6e2536547ad
child 316086 0ff0ab3c254a2bb8d040005a9606e43d26cb158f
push id5703
push userraliiev@mozilla.com
push dateMon, 07 Mar 2016 14:18:41 +0000
treeherdermozilla-beta@31e373ad5b5f [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersjst
bugs1241302
milestone46.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 1241302 - Slightly modernize this code. r=jst
widget/nsBaseClipboard.cpp
widget/nsBaseClipboard.h
--- a/widget/nsBaseClipboard.cpp
+++ b/widget/nsBaseClipboard.cpp
@@ -6,21 +6,19 @@
 #include "nsBaseClipboard.h"
 
 #include "nsIClipboardOwner.h"
 #include "nsCOMPtr.h"
 #include "nsXPCOM.h"
 #include "nsISupportsPrimitives.h"
 
 nsBaseClipboard::nsBaseClipboard()
+  : mEmptyingForSetData(false)
+  , mIgnoreEmptyNotification(false)
 {
-  mClipboardOwner          = nullptr;
-  mTransferable            = nullptr;
-  mIgnoreEmptyNotification = false;
-  mEmptyingForSetData      = false;
 }
 
 nsBaseClipboard::~nsBaseClipboard()
 {
   EmptyClipboard(kSelectionClipboard);
   EmptyClipboard(kGlobalClipboard);
   EmptyClipboard(kFindClipboard);
 }
@@ -45,28 +43,23 @@ NS_IMETHODIMP nsBaseClipboard::SetData(n
   if ( !selectClipPresent && !findClipPresent && aWhichClipboard != kGlobalClipboard )
     return NS_ERROR_FAILURE;
 
   mEmptyingForSetData = true;
   EmptyClipboard(aWhichClipboard);
   mEmptyingForSetData = false;
 
   mClipboardOwner = anOwner;
-  if ( anOwner )
-    NS_ADDREF(mClipboardOwner);
+  mTransferable = aTransferable;
 
-  mTransferable = aTransferable;
-  
   nsresult rv = NS_ERROR_FAILURE;
-
-  if ( mTransferable ) {
-    NS_ADDREF(mTransferable);
+  if (mTransferable) {
     rv = SetNativeClipboardData(aWhichClipboard);
   }
-  
+
   return rv;
 }
 
 /**
   * Gets the transferable object
   *
   */
 NS_IMETHODIMP nsBaseClipboard::GetData(nsITransferable * aTransferable, int32_t aWhichClipboard)
@@ -87,29 +80,28 @@ NS_IMETHODIMP nsBaseClipboard::GetData(n
 }
 
 NS_IMETHODIMP nsBaseClipboard::EmptyClipboard(int32_t aWhichClipboard)
 {
   bool selectClipPresent;
   SupportsSelectionClipboard(&selectClipPresent);
   bool findClipPresent;
   SupportsFindClipboard(&findClipPresent);
-  if ( !selectClipPresent && !findClipPresent && aWhichClipboard != kGlobalClipboard )
+  if (!selectClipPresent && !findClipPresent && aWhichClipboard != kGlobalClipboard)
     return NS_ERROR_FAILURE;
 
   if (mIgnoreEmptyNotification)
     return NS_OK;
 
-  if ( mClipboardOwner ) {
+  if (mClipboardOwner) {
     mClipboardOwner->LosingOwnership(mTransferable);
-    NS_RELEASE(mClipboardOwner);
+    mClipboardOwner = nullptr;
   }
 
-  NS_IF_RELEASE(mTransferable);
-
+  mTransferable = nullptr;
   return NS_OK;
 }
 
 NS_IMETHODIMP
 nsBaseClipboard::HasDataMatchingFlavors(const char** aFlavorList,
                                         uint32_t aLength,
                                         int32_t aWhichClipboard,
                                         bool* outResult) 
--- a/widget/nsBaseClipboard.h
+++ b/widget/nsBaseClipboard.h
@@ -32,15 +32,15 @@ public:
 protected:
   virtual ~nsBaseClipboard();
 
   NS_IMETHOD SetNativeClipboardData ( int32_t aWhichClipboard ) = 0;
   NS_IMETHOD GetNativeClipboardData ( nsITransferable * aTransferable, int32_t aWhichClipboard ) = 0;
 
   bool                mEmptyingForSetData;
   bool                mIgnoreEmptyNotification;
-  nsIClipboardOwner * mClipboardOwner;
-  nsITransferable   * mTransferable;
+  nsCOMPtr<nsIClipboardOwner> mClipboardOwner;
+  nsCOMPtr<nsITransferable>   mTransferable;
 
 };
 
 #endif // nsBaseClipboard_h__