From c200656eac34f3a10fffae75929231e30c15d779 Mon Sep 17 00:00:00 2001 From: Eric Wong Date: Tue, 14 Aug 2012 20:37:44 -0700 Subject: [PATCH] Bug 773760: Save privacy status of transferable during cross-process clipboard transfer. r=ehsan --- dom/ipc/ContentParent.cpp | 5 ++++- dom/ipc/ContentParent.h | 2 +- dom/ipc/PContent.ipdl | 2 +- widget/android/nsClipboard.cpp | 5 ++++- widget/nsITransferable.idl | 9 +++++++-- widget/xpwidgets/nsTransferable.cpp | 11 +++++++++++ 6 files changed, 28 insertions(+), 6 deletions(-) diff --git a/dom/ipc/ContentParent.cpp b/dom/ipc/ContentParent.cpp index 925755e9f210..ea179dc59fbb 100644 --- a/dom/ipc/ContentParent.cpp +++ b/dom/ipc/ContentParent.cpp @@ -686,7 +686,9 @@ ContentParent::RecvReadPermissions(InfallibleTArray* aPermissio } bool -ContentParent::RecvSetClipboardText(const nsString& text, const PRInt32& whichClipboard) +ContentParent::RecvSetClipboardText(const nsString& text, + const bool& isPrivateData, + const PRInt32& whichClipboard) { nsresult rv; nsCOMPtr clipboard(do_GetService(kCClipboardCID, &rv)); @@ -705,6 +707,7 @@ ContentParent::RecvSetClipboardText(const nsString& text, const PRInt32& whichCl // If our data flavor has already been added, this will fail. But we don't care trans->AddDataFlavor(kUnicodeMime); + trans->SetIsPrivateData(isPrivateData); nsCOMPtr nsisupportsDataWrapper = do_QueryInterface(dataWrapper); diff --git a/dom/ipc/ContentParent.h b/dom/ipc/ContentParent.h index e78eac15d407..7579586db333 100644 --- a/dom/ipc/ContentParent.h +++ b/dom/ipc/ContentParent.h @@ -201,7 +201,7 @@ private: virtual bool RecvReadPermissions(InfallibleTArray* aPermissions); - virtual bool RecvSetClipboardText(const nsString& text, const PRInt32& whichClipboard); + virtual bool RecvSetClipboardText(const nsString& text, const bool& isPrivateData, const PRInt32& whichClipboard); virtual bool RecvGetClipboardText(const PRInt32& whichClipboard, nsString* text); virtual bool RecvEmptyClipboard(); virtual bool RecvClipboardHasText(bool* hasText); diff --git a/dom/ipc/PContent.ipdl b/dom/ipc/PContent.ipdl index 4cf2cd6847e9..94bcc303587b 100644 --- a/dom/ipc/PContent.ipdl +++ b/dom/ipc/PContent.ipdl @@ -279,7 +279,7 @@ parent: // These clipboard methods are only really used on Android since // the clipboard is not available in the content process. - SetClipboardText(nsString text, PRInt32 whichClipboard); + SetClipboardText(nsString text, bool isPrivateData, PRInt32 whichClipboard); sync GetClipboardText(PRInt32 whichClipboard) returns (nsString text); EmptyClipboard(); diff --git a/widget/android/nsClipboard.cpp b/widget/android/nsClipboard.cpp index 0c9a03800a3f..a981aaf896a9 100644 --- a/widget/android/nsClipboard.cpp +++ b/widget/android/nsClipboard.cpp @@ -50,7 +50,10 @@ nsClipboard::SetData(nsITransferable *aTransferable, return NS_ERROR_NOT_IMPLEMENTED; } else { - ContentChild::GetSingleton()->SendSetClipboardText(buffer, aWhichClipboard); + bool isPrivateData = false; + aTransferable->GetIsPrivateData(&isPrivateData); + ContentChild::GetSingleton()->SendSetClipboardText(buffer, isPrivateData, + aWhichClipboard); } return NS_OK; diff --git a/widget/nsITransferable.idl b/widget/nsITransferable.idl index 82e833d8a6a7..66fb8422ab39 100644 --- a/widget/nsITransferable.idl +++ b/widget/nsITransferable.idl @@ -81,7 +81,7 @@ interface nsIFlavorDataProvider : nsISupports }; -[scriptable, uuid(983cb266-535b-4ca5-8ef2-2cee08d061e6)] +[scriptable, uuid(5a611a60-e5b5-11e1-aff1-0800200c9a66)] interface nsITransferable : nsISupports { const long kFlavorHasDataProvider = 0; @@ -172,7 +172,12 @@ interface nsITransferable : nsISupports attribute nsIFormatConverter converter; - [noscript] readonly attribute boolean isPrivateData; + /** + * Use of the SetIsPrivateData() method generated by isPrivateData attribute should + * be avoided as much as possible because the value set may not reflect the status + * of the context in which the transferable was created. + */ + [noscript] attribute boolean isPrivateData; }; diff --git a/widget/xpwidgets/nsTransferable.cpp b/widget/xpwidgets/nsTransferable.cpp index 281f4c75f637..9fb334dd8c65 100644 --- a/widget/xpwidgets/nsTransferable.cpp +++ b/widget/xpwidgets/nsTransferable.cpp @@ -621,3 +621,14 @@ nsTransferable::GetIsPrivateData(bool *aIsPrivateData) return NS_OK; } + +NS_IMETHODIMP +nsTransferable::SetIsPrivateData(bool aIsPrivateData) +{ + MOZ_ASSERT(mInitialized); + + mPrivateData = aIsPrivateData; + + return NS_OK; +} +