Bug 773760: Save privacy status of transferable during cross-process clipboard transfer. r=ehsan
authorEric Wong <ewong3@gmail.com>
Tue, 14 Aug 2012 20:37:44 -0700
changeset 102417 3bc014ea9703529dd858f4445f706d01067a44ad
parent 102416 0b26e7597f318860cdeaa6384e48319fcf5b67df
child 102418 4ec6f3cb235863f8f838846c21a0242103de7a85
push id1
push userroot
push dateMon, 20 Oct 2014 17:29:22 +0000
reviewersehsan
bugs773760
milestone17.0a1
Bug 773760: Save privacy status of transferable during cross-process clipboard transfer. r=ehsan
dom/ipc/ContentParent.cpp
dom/ipc/ContentParent.h
dom/ipc/PContent.ipdl
widget/android/nsClipboard.cpp
widget/nsITransferable.idl
widget/xpwidgets/nsTransferable.cpp
--- a/dom/ipc/ContentParent.cpp
+++ b/dom/ipc/ContentParent.cpp
@@ -681,17 +681,19 @@ ContentParent::RecvReadPermissions(Infal
     // Ask for future changes
     mSendPermissionUpdates = true;
 #endif
 
     return true;
 }
 
 bool
-ContentParent::RecvSetClipboardText(const nsString& text, const PRInt32& whichClipboard)
+ContentParent::RecvSetClipboardText(const nsString& text,
+                                       const bool& isPrivateData,
+                                       const PRInt32& whichClipboard)
 {
     nsresult rv;
     nsCOMPtr<nsIClipboard> clipboard(do_GetService(kCClipboardCID, &rv));
     NS_ENSURE_SUCCESS(rv, true);
 
     nsCOMPtr<nsISupportsString> dataWrapper =
         do_CreateInstance(NS_SUPPORTS_STRING_CONTRACTID, &rv);
     NS_ENSURE_SUCCESS(rv, true);
@@ -700,16 +702,17 @@ ContentParent::RecvSetClipboardText(cons
     NS_ENSURE_SUCCESS(rv, true);
     
     nsCOMPtr<nsITransferable> trans = do_CreateInstance("@mozilla.org/widget/transferable;1", &rv);
     NS_ENSURE_SUCCESS(rv, true);
     trans->Init(nullptr);
     
     // If our data flavor has already been added, this will fail. But we don't care
     trans->AddDataFlavor(kUnicodeMime);
+    trans->SetIsPrivateData(isPrivateData);
     
     nsCOMPtr<nsISupports> nsisupportsDataWrapper =
         do_QueryInterface(dataWrapper);
     
     rv = trans->SetTransferData(kUnicodeMime, nsisupportsDataWrapper,
                                 text.Length() * sizeof(PRUnichar));
     NS_ENSURE_SUCCESS(rv, true);
     
--- a/dom/ipc/ContentParent.h
+++ b/dom/ipc/ContentParent.h
@@ -196,17 +196,17 @@ private:
     virtual PStorageParent* AllocPStorage(const StorageConstructData& aData);
     virtual bool DeallocPStorage(PStorageParent* aActor);
 
     virtual bool RecvReadPrefsArray(InfallibleTArray<PrefTuple> *retValue);
     virtual bool RecvReadFontList(InfallibleTArray<FontListEntry>* retValue);
 
     virtual bool RecvReadPermissions(InfallibleTArray<IPC::Permission>* 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);
 
     virtual bool RecvGetSystemColors(const PRUint32& colorsCount, InfallibleTArray<PRUint32>* colors);
     virtual bool RecvGetIconForExtension(const nsCString& aFileExt, const PRUint32& aIconSize, InfallibleTArray<PRUint8>* bits);
     virtual bool RecvGetShowPasswordSetting(bool* showPassword);
 
--- a/dom/ipc/PContent.ipdl
+++ b/dom/ipc/PContent.ipdl
@@ -274,17 +274,17 @@ parent:
                 PRUint32 lineNumber, PRUint32 colNumber, PRUint32 flags,
                 nsCString category); 
 
     // nsIPermissionManager messages
     sync ReadPermissions() returns (Permission[] permissions);
 
     // 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();
     sync ClipboardHasText()
         returns (bool hasText);
 
     sync GetSystemColors(PRUint32 colorsCount)
         returns (PRUint32[] colors);
--- a/widget/android/nsClipboard.cpp
+++ b/widget/android/nsClipboard.cpp
@@ -45,17 +45,20 @@ nsClipboard::SetData(nsITransferable *aT
 
   if (XRE_GetProcessType() == GeckoProcessType_Default) {
     if (AndroidBridge::Bridge())
       AndroidBridge::Bridge()->SetClipboardText(buffer);
     else
       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;
 }
 
 NS_IMETHODIMP
 nsClipboard::GetData(nsITransferable *aTransferable, PRInt32 aWhichClipboard)
 {
--- a/widget/nsITransferable.idl
+++ b/widget/nsITransferable.idl
@@ -76,17 +76,17 @@ interface nsIFlavorDataProvider : nsISup
     * @param  aFlavor (in parameter) the flavor of data to retrieve
     * @param  aData the data. Some variant of class in nsISupportsPrimitives.idl
     * @param  aDataLen the length of the data
     */
   void getFlavorData(in nsITransferable aTransferable, in string aFlavor, out nsISupports aData, out unsigned long aDataLen);
 };
 
 
-[scriptable, uuid(983cb266-535b-4ca5-8ef2-2cee08d061e6)]
+[scriptable, uuid(5a611a60-e5b5-11e1-aff1-0800200c9a66)]
 interface nsITransferable : nsISupports
 {
   const long kFlavorHasDataProvider = 0;
 
   /**
    * Initializes a transferable object.  This should be called on all
    * transferable objects.  Failure to do so will result in fatal assertions in
    * debug builds.
@@ -167,12 +167,17 @@ interface nsITransferable : nsISupports
     * that goes along with it.
     *
     * @param  aDataFlavor a data flavor to remove
     */
   void removeDataFlavor ( in string aDataFlavor ) ;
 
   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;
 
 };
 
--- a/widget/xpwidgets/nsTransferable.cpp
+++ b/widget/xpwidgets/nsTransferable.cpp
@@ -616,8 +616,19 @@ nsTransferable::GetIsPrivateData(bool *a
   MOZ_ASSERT(mInitialized);
 
   NS_ENSURE_ARG_POINTER(aIsPrivateData);
 
   *aIsPrivateData = mPrivateData;
 
   return NS_OK;
 }
+
+NS_IMETHODIMP
+nsTransferable::SetIsPrivateData(bool aIsPrivateData)
+{
+  MOZ_ASSERT(mInitialized);
+
+  mPrivateData = aIsPrivateData;
+
+  return NS_OK;
+}
+