Bug 1297539 - Send message PasteTransferable if the focused element is on the content process, otherwise pass the transferable to the controller directly. r=mrbkap
authorJimmy Wang <jimmyw22@gmail.com>
Tue, 23 Aug 2016 20:00:27 -0400
changeset 312459 4e15e5606976b626dba9a577d86098d1ed568492
parent 312458 3bb42e64430405cb93bcaee9e31affdf2314db8b
child 312460 6f406d30eddb8ccbe7a15392b7cc583722145765
push id20447
push userkwierso@gmail.com
push dateFri, 02 Sep 2016 20:36:44 +0000
treeherderfx-team@969397f22187 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersmrbkap
bugs1297539
milestone51.0a1
Bug 1297539 - Send message PasteTransferable if the focused element is on the content process, otherwise pass the transferable to the controller directly. r=mrbkap MozReview-Commit-ID: Bj3mY23YUDT
dom/events/EventStateManager.cpp
--- a/dom/events/EventStateManager.cpp
+++ b/dom/events/EventStateManager.cpp
@@ -5204,26 +5204,48 @@ EventStateManager::DoContentCommandEvent
   } else {
     bool canDoIt;
     rv = controller->IsCommandEnabled(cmd, &canDoIt);
     NS_ENSURE_SUCCESS(rv, rv);
     aEvent->mIsEnabled = canDoIt;
     if (canDoIt && !aEvent->mOnlyEnabledCheck) {
       switch (aEvent->mMessage) {
         case eContentCommandPasteTransferable: {
-          nsCOMPtr<nsICommandController> commandController = do_QueryInterface(controller);
-          NS_ENSURE_STATE(commandController);
-
-          nsCOMPtr<nsICommandParams> params = do_CreateInstance("@mozilla.org/embedcomp/command-params;1", &rv);
-          NS_ENSURE_SUCCESS(rv, rv);
-
-          rv = params->SetISupportsValue("transferable", aEvent->mTransferable);
-          NS_ENSURE_SUCCESS(rv, rv);
-
-          rv = commandController->DoCommandWithParams(cmd, params);
+          nsFocusManager* fm = nsFocusManager::GetFocusManager();
+          nsIContent* focusedContent = fm ? fm->GetFocusedContent() : nullptr;
+          RefPtr<TabParent> remote = TabParent::GetFrom(focusedContent);
+          if (remote) {
+            NS_ENSURE_TRUE(remote->Manager()->IsContentParent(), NS_ERROR_FAILURE);
+
+            nsCOMPtr<nsITransferable> transferable = aEvent->mTransferable;
+            IPCDataTransfer ipcDataTransfer;
+            ContentParent* cp = remote->Manager()->AsContentParent();
+            nsContentUtils::TransferableToIPCTransferable(transferable,
+                                                          &ipcDataTransfer,
+                                                          false, nullptr,
+                                                          cp);
+            bool isPrivateData = false;
+            transferable->GetIsPrivateData(&isPrivateData);
+            nsCOMPtr<nsIPrincipal> requestingPrincipal;
+            transferable->GetRequestingPrincipal(getter_AddRefs(requestingPrincipal));
+            remote->SendPasteTransferable(ipcDataTransfer, isPrivateData,
+                                          IPC::Principal(requestingPrincipal));
+            rv = NS_OK;
+          } else {
+            nsCOMPtr<nsICommandController> commandController = do_QueryInterface(controller);
+            NS_ENSURE_STATE(commandController);
+
+            nsCOMPtr<nsICommandParams> params = do_CreateInstance("@mozilla.org/embedcomp/command-params;1", &rv);
+            NS_ENSURE_SUCCESS(rv, rv);
+
+            rv = params->SetISupportsValue("transferable", aEvent->mTransferable);
+            NS_ENSURE_SUCCESS(rv, rv);
+
+            rv = commandController->DoCommandWithParams(cmd, params);
+          }
           break;
         }
 
         case eContentCommandLookUpDictionary: {
           nsCOMPtr<nsICommandController> commandController =
             do_QueryInterface(controller);
           if (NS_WARN_IF(!commandController)) {
             return NS_ERROR_FAILURE;