Bug 1261299 - Only update nsClipboard::sSelectionCache in nsSelection.cpp when the selection listener is on the same process as the focused window where the selection occured or became active. draft
authorJimmy Wang <jimmyw22@gmail.com>
Wed, 03 Aug 2016 19:08:33 -0400
changeset 398678 5f8566938930f0d967aab5cf9b09eff5dccdf9e6
parent 398677 083e8da402b6a5b106d68dc8dfdea277c9acda5d
child 398679 8ebacbcaebad190e7ecdbebfd82922a67b2eeb7e
push id25595
push userjimmyw22@gmail.com
push dateTue, 09 Aug 2016 15:57:35 +0000
bugs1261299
milestone51.0a1
Bug 1261299 - Only update nsClipboard::sSelectionCache in nsSelection.cpp when the selection listener is on the same process as the focused window where the selection occured or became active. MozReview-Commit-ID: KARKdc8G0nI
layout/generic/nsSelection.cpp
--- a/layout/generic/nsSelection.cpp
+++ b/layout/generic/nsSelection.cpp
@@ -79,16 +79,17 @@ static NS_DEFINE_CID(kFrameTraversalCID,
 #include "mozilla/dom/SelectionBinding.h"
 #include "mozilla/AsyncEventDispatcher.h"
 #include "mozilla/Telemetry.h"
 #include "mozilla/layers/ScrollInputMethods.h"
 #include "nsViewManager.h"
 
 #include "nsIEditor.h"
 #include "nsIHTMLEditor.h"
+#include "nsFocusManager.h"
 
 using namespace mozilla;
 using namespace mozilla::dom;
 using mozilla::layers::ScrollInputMethod;
 
 //#define DEBUG_TABLE 1
 
 static bool IsValidSelectionPoint(nsFrameSelection *aFrameSel, nsINode *aNode);
@@ -1970,17 +1971,20 @@ nsFrameSelection::RepaintSelection(Selec
   if (index < 0)
     return NS_ERROR_INVALID_ARG;
   if (!mDomSelections[index])
     return NS_ERROR_NULL_POINTER;
   NS_ENSURE_STATE(mShell);
 
 // On macOS, update the cached selection to the active selection
 #ifdef XP_MACOSX
-  if (aSelectionType == SelectionType::eNormal) {
+  nsFocusManager* fm = nsFocusManager::GetFocusManager();
+  // Check that nsFrameSelection is on the same process as the focused window
+  // where the current active selection is on and that it's a normal selection.
+  if (fm->GetActiveWindow() && aSelectionType == SelectionType::eNormal) {
     UpdateSelectionCacheOnRepaintSelection(mDomSelections[index]);
   }
 #endif
   return mDomSelections[index]->Repaint(mShell->GetPresContext());
 }
  
 nsIFrame*
 nsFrameSelection::GetFrameForNodeOffset(nsIContent*        aNode,
@@ -6481,16 +6485,25 @@ NS_IMPL_ISUPPORTS(nsAutoCopyListener, ns
  * - maybe we should just never clear the X clipboard?  That would make this 
  *   problem just go away, which is very tempting.
  */
 
 NS_IMETHODIMP
 nsAutoCopyListener::NotifySelectionChanged(nsIDOMDocument *aDoc,
                                            nsISelection *aSel, int16_t aReason)
 {
+  if (mCachedClipboard == nsIClipboard::kSelectionCache) {
+    nsFocusManager* fm = nsFocusManager::GetFocusManager();
+    // If the nsAutoCopyListener is not on the same process as the focused
+    // window where the selection occured then don't update the selection cache.
+    if (!fm->GetActiveWindow()) {
+      return NS_OK;
+    }
+  }
+
   if (!(aReason & nsISelectionListener::MOUSEUP_REASON   || 
         aReason & nsISelectionListener::SELECTALL_REASON ||
         aReason & nsISelectionListener::KEYPRESS_REASON))
     return NS_OK; //dont care if we are still dragging
 
   bool collapsed;
   if (!aDoc || !aSel ||
       NS_FAILED(aSel->GetIsCollapsed(&collapsed)) || collapsed) {