Bug 1020743: Fix bug in which we don't keep track of which clipboard we cached, general or find, which resulted in pasting from the wrong clipboard on OS X. r=bz, a=sylvestre
authorJosh Aas <joshmoz@gmail.com>
Wed, 25 Jun 2014 20:29:50 -0500
changeset 207405 577c1dd3fc024883fafe3e80ea5a4f8bf7ef847e
parent 207404 731a5e8831e6b7b9d325975fbeee35fd4497a5ca
child 207406 c67b5095f022bcdda87ed4d7013bb5c4694c70db
push id3741
push userasasaki@mozilla.com
push dateMon, 21 Jul 2014 20:25:18 +0000
treeherdermozilla-beta@4d6f46f5af68 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersbz, sylvestre
bugs1020743
milestone32.0a2
Bug 1020743: Fix bug in which we don't keep track of which clipboard we cached, general or find, which resulted in pasting from the wrong clipboard on OS X. r=bz, a=sylvestre
widget/cocoa/nsClipboard.h
widget/cocoa/nsClipboard.mm
--- a/widget/cocoa/nsClipboard.h
+++ b/widget/cocoa/nsClipboard.h
@@ -33,18 +33,13 @@ public:
 
 protected:
 
   // impelement the native clipboard behavior
   NS_IMETHOD SetNativeClipboardData(int32_t aWhichClipboard);
   NS_IMETHOD GetNativeClipboardData(nsITransferable * aTransferable, int32_t aWhichClipboard);
   
 private:
-  // This is always set to the native change count after any modification of the
-  // general clipboard.
-  int mChangeCountGeneral;
-  // This is always set to the native change count after any modification of the
-  // find clipboard.
-  int mChangeCountFind;
-
+  int32_t mCachedClipboard;
+  int32_t mChangeCount; // Set to the native change count after any modification of the clipboard.
 };
 
 #endif // nsClipboard_h_
--- a/widget/cocoa/nsClipboard.mm
+++ b/widget/cocoa/nsClipboard.mm
@@ -35,18 +35,18 @@ using mozilla::RefPtr;
 #ifdef PR_LOGGING
 extern PRLogModuleInfo* sCocoaLog;
 #endif
 
 extern void EnsureLogInitialized();
 
 nsClipboard::nsClipboard() : nsBaseClipboard()
 {
-  mChangeCountGeneral = 0;
-  mChangeCountFind = 0;
+  mCachedClipboard = -1;
+  mChangeCount = 0;
 
   EnsureLogInitialized();
 }
 
 nsClipboard::~nsClipboard()
 {
 }
 
@@ -108,21 +108,18 @@ nsClipboard::SetNativeClipboardData(int3
         [cocoaPasteboard setString:(nsClipboard::WrapHtmlForSystemPasteboard(currentValue))
                          forType:currentKey];
       } else {
         [cocoaPasteboard setData:currentValue forType:currentKey];
       }
     }
   }
 
-  if (aWhichClipboard == kFindClipboard) {
-    mChangeCountFind = [cocoaPasteboard changeCount];
-  } else {
-    mChangeCountGeneral = [cocoaPasteboard changeCount];
-  }
+  mCachedClipboard = aWhichClipboard;
+  mChangeCount = [cocoaPasteboard changeCount];
 
   mIgnoreEmptyNotification = false;
 
   return NS_OK;
 
   NS_OBJC_END_TRY_ABORT_BLOCK_NSRESULT;
 }
 
@@ -276,20 +273,20 @@ nsClipboard::GetNativeClipboardData(nsIT
   nsCOMPtr<nsISupportsArray> flavorList;
   nsresult rv = aTransferable->FlavorsTransferableCanImport(getter_AddRefs(flavorList));
   if (NS_FAILED(rv))
     return NS_ERROR_FAILURE;
 
   uint32_t flavorCount;
   flavorList->Count(&flavorCount);
 
-  int changeCount = (aWhichClipboard == kFindClipboard) ? mChangeCountFind : mChangeCountGeneral;
   // If we were the last ones to put something on the pasteboard, then just use the cached
   // transferable. Otherwise clear it because it isn't relevant any more.
-  if (changeCount == [cocoaPasteboard changeCount]) {
+  if (mCachedClipboard == aWhichClipboard &&
+      mChangeCount == [cocoaPasteboard changeCount]) {
     if (mTransferable) {
       for (uint32_t i = 0; i < flavorCount; i++) {
         nsCOMPtr<nsISupports> genericFlavor;
         flavorList->GetElementAt(i, getter_AddRefs(genericFlavor));
         nsCOMPtr<nsISupportsCString> currentFlavor(do_QueryInterface(genericFlavor));
         if (!currentFlavor)
           continue;