Bug 1261299 - Add a method nsCopySupport::SetSelectionCache instead of relying on the method used to set the os clipboard.
MozReview-Commit-ID: KvmdD2XqKBh
--- a/dom/base/nsCopySupport.cpp
+++ b/dom/base/nsCopySupport.cpp
@@ -303,16 +303,28 @@ nsCopySupport::HTMLCopy(nsISelection* aS
uint32_t flags = nsIDocumentEncoder::SkipInvisibleContent;
if (aWithRubyAnnotation) {
flags |= nsIDocumentEncoder::OutputRubyAnnotation;
}
return SelectionCopyHelper(aSel, aDoc, true, aClipboardID, flags, nullptr);
}
nsresult
+nsCopySupport::SetSelectionCache(nsISelection* aSel, nsIDocument* aDoc)
+{
+ nsresult rv;
+ nsCOMPtr<nsITransferable> transferable;
+ rv = nsCopySupport::GetTransferableForSelection(aSel, aDoc,
+ getter_AddRefs(transferable));
+ nsCOMPtr<nsIClipboard> clipboard = do_GetService(kCClipboardCID, &rv);
+ clipboard->SetData(transferable, nullptr, nsIClipboard::kSelectionCache);
+ return rv;
+}
+
+nsresult
nsCopySupport::ClearSelectionCache()
{
nsresult rv;
nsCOMPtr<nsIClipboard> clipboard = do_GetService(kCClipboardCID, &rv);
clipboard->EmptyClipboard(nsIClipboard::kSelectionCache);
return rv;
}
--- a/dom/base/nsCopySupport.h
+++ b/dom/base/nsCopySupport.h
@@ -21,16 +21,17 @@ class nsAString;
class nsIPresShell;
class nsILoadContext;
class nsCopySupport
{
// class of static helper functions for copy support
public:
static nsresult ClearSelectionCache();
+ static nsresult SetSelectionCache(nsISelection* aSel, nsIDocument* aDoc);
static nsresult HTMLCopy(nsISelection *aSel, nsIDocument *aDoc,
int16_t aClipboardID, bool aWithRubyAnnotation);
static nsresult DoHooks(nsIDocument *aDoc, nsITransferable *aTrans,
bool *aDoPutOnClipboard);
// Get the selection, or entire document, in the format specified by the mime type
// (text/html or text/plain). If aSel is non-null, use it, otherwise get the entire
// doc.
--- a/layout/generic/nsSelection.cpp
+++ b/layout/generic/nsSelection.cpp
@@ -6517,16 +6517,20 @@ nsAutoCopyListener::NotifySelectionChang
}
/* clear X clipboard? */
return NS_OK;
}
nsCOMPtr<nsIDocument> doc = do_QueryInterface(aDoc);
NS_ENSURE_TRUE(doc, NS_ERROR_FAILURE);
+ if (mCachedClipboard == nsIClipboard::kSelectionCache) {
+ return nsCopySupport::SetSelectionCache(aSel, doc);
+ }
+
// call the copy code
return nsCopySupport::HTMLCopy(aSel, doc,
mCachedClipboard, false);
}
/**
* See Bug 1288453.
*