Bug 664717 - Part 2: Pass requestingPrincipal to parent process with nsITransferable. r?smaug draft
authorHector Zhao <bzhao@mozilla.com>
Thu, 30 Jun 2016 15:12:56 +0800
changeset 383107 d4002835c36390de9cd486867fd825bc71badfd4
parent 383106 c4f15e1497aa6abab2caf5a868832df9844efba7
child 383108 ca2fa839de6cdaefa3c8d24d0b82db18c0442267
push id21936
push userbmo:bzhao@mozilla.com
push dateFri, 01 Jul 2016 08:06:55 +0000
reviewerssmaug
bugs664717
milestone50.0a1
Bug 664717 - Part 2: Pass requestingPrincipal to parent process with nsITransferable. r?smaug MozReview-Commit-ID: B0k10UplydR
dom/ipc/ContentParent.cpp
dom/ipc/ContentParent.h
dom/ipc/PContent.ipdl
widget/nsClipboardProxy.cpp
--- a/dom/ipc/ContentParent.cpp
+++ b/dom/ipc/ContentParent.cpp
@@ -2735,16 +2735,17 @@ ContentParent::RecvReadPermissions(Infal
 #endif
 
   return true;
 }
 
 bool
 ContentParent::RecvSetClipboard(const IPCDataTransfer& aDataTransfer,
                                 const bool& aIsPrivateData,
+                                const IPC::Principal& aRequestingPrincipal,
                                 const int32_t& aWhichClipboard)
 {
   nsresult rv;
   nsCOMPtr<nsIClipboard> clipboard(do_GetService(kCClipboardCID, &rv));
   NS_ENSURE_SUCCESS(rv, true);
 
   nsCOMPtr<nsITransferable> trans =
     do_CreateInstance("@mozilla.org/widget/transferable;1", &rv);
@@ -2800,16 +2801,17 @@ ContentParent::RecvSetClipboard(const IP
         NS_ENSURE_SUCCESS(rv, true);
       }
 
       Unused << DeallocShmem(item.data().get_Shmem());
     }
   }
 
   trans->SetIsPrivateData(aIsPrivateData);
+  trans->SetRequestingPrincipal(aRequestingPrincipal);
 
   clipboard->SetData(trans, nullptr, aWhichClipboard);
   return true;
 }
 
 bool
 ContentParent::RecvGetClipboard(nsTArray<nsCString>&& aTypes,
                                 const int32_t& aWhichClipboard,
--- a/dom/ipc/ContentParent.h
+++ b/dom/ipc/ContentParent.h
@@ -951,16 +951,17 @@ private:
 
   virtual bool RecvReadDataStorageArray(const nsString& aFilename,
                                         InfallibleTArray<DataStorageItem>* aValues) override;
 
   virtual bool RecvReadPermissions(InfallibleTArray<IPC::Permission>* aPermissions) override;
 
   virtual bool RecvSetClipboard(const IPCDataTransfer& aDataTransfer,
                                 const bool& aIsPrivateData,
+                                const IPC::Principal& aRequestingPrincipal,
                                 const int32_t& aWhichClipboard) override;
 
   virtual bool RecvGetClipboard(nsTArray<nsCString>&& aTypes,
                                 const int32_t& aWhichClipboard,
                                 IPCDataTransfer* aDataTransfer) override;
 
   virtual bool RecvEmptyClipboard(const int32_t& aWhichClipboard) override;
 
--- a/dom/ipc/PContent.ipdl
+++ b/dom/ipc/PContent.ipdl
@@ -882,16 +882,17 @@ parent:
                       nsCString category);
 
     // nsIPermissionManager messages
     sync ReadPermissions() returns (Permission[] permissions);
 
     // Places the items within dataTransfer on the clipboard.
     async SetClipboard(IPCDataTransfer aDataTransfer,
                        bool aIsPrivateData,
+                       Principal aRequestingPrincipal,
                        int32_t aWhichClipboard);
 
     // Given a list of supported types, returns the clipboard data for the
     // first type that matches.
     sync GetClipboard(nsCString[] aTypes, int32_t aWhichClipboard)
         returns (IPCDataTransfer dataTransfer);
 
     // Clears the clipboard.
--- a/widget/nsClipboardProxy.cpp
+++ b/widget/nsClipboardProxy.cpp
@@ -29,17 +29,20 @@ nsClipboardProxy::SetData(nsITransferabl
   ContentChild* child = ContentChild::GetSingleton();
 
   IPCDataTransfer ipcDataTransfer;
   nsContentUtils::TransferableToIPCTransferable(aTransferable, &ipcDataTransfer,
                                                 false, child, nullptr);
 
   bool isPrivateData = false;
   aTransferable->GetIsPrivateData(&isPrivateData);
-  child->SendSetClipboard(ipcDataTransfer, isPrivateData, aWhichClipboard);
+  nsCOMPtr<nsIPrincipal> requestingPrincipal;
+  aTransferable->GetRequestingPrincipal(getter_AddRefs(requestingPrincipal));
+  child->SendSetClipboard(ipcDataTransfer, isPrivateData,
+                          IPC::Principal(requestingPrincipal), aWhichClipboard);
 
   return NS_OK;
 }
 
 NS_IMETHODIMP
 nsClipboardProxy::GetData(nsITransferable *aTransferable, int32_t aWhichClipboard)
 {
    nsTArray<nsCString> types;