Bug 1550930 part 3. Stop using [array] for nsIDroppedLinkHandler.dropLinks. r=NeilDeakin
authorBoris Zbarsky <bzbarsky@mit.edu>
Wed, 15 May 2019 20:58:08 +0000
changeset 532827 1274c074caef1fb327fad2d59bda256e5029e5e2
parent 532826 5945a8e0198b041454d61bfc92b2d3e79229d352
child 532828 6440419b9d330aa54135832c910187b63d1649e2
push id11272
push userapavel@mozilla.com
push dateThu, 16 May 2019 15:28:22 +0000
treeherdermozilla-beta@2265bfc5920d [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersNeilDeakin
bugs1550930
milestone68.0a1
first release with
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
last release without
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
Bug 1550930 part 3. Stop using [array] for nsIDroppedLinkHandler.dropLinks. r=NeilDeakin Differential Revision: https://phabricator.services.mozilla.com/D30770
docshell/base/nsDocShellTreeOwner.cpp
dom/base/ContentAreaDropListener.jsm
dom/base/nsIDroppedLinkHandler.idl
dom/interfaces/base/nsIBrowserChild.idl
dom/ipc/BrowserChild.cpp
--- a/docshell/base/nsDocShellTreeOwner.cpp
+++ b/docshell/base/nsDocShellTreeOwner.cpp
@@ -868,36 +868,30 @@ nsDocShellTreeOwner::HandleEvent(Event* 
     bool canDropLink = false;
     handler->CanDropLink(dragEvent, false, &canDropLink);
     if (canDropLink) {
       aEvent->PreventDefault();
     }
   } else if (eventType.EqualsLiteral("drop")) {
     nsIWebNavigation* webnav = static_cast<nsIWebNavigation*>(mWebBrowser);
 
-    uint32_t linksCount;
-    nsIDroppedLinkItem** links;
-    if (webnav && NS_SUCCEEDED(handler->DropLinks(dragEvent, true, &linksCount,
-                                                  &links))) {
-      if (linksCount >= 1) {
+    nsTArray<RefPtr<nsIDroppedLinkItem>> links;
+    if (webnav && NS_SUCCEEDED(handler->DropLinks(dragEvent, true, links))) {
+      if (links.Length() >= 1) {
         nsCOMPtr<nsIPrincipal> triggeringPrincipal;
         handler->GetTriggeringPrincipal(dragEvent,
                                         getter_AddRefs(triggeringPrincipal));
         if (triggeringPrincipal) {
           nsCOMPtr<nsIWebBrowserChrome> webBrowserChrome =
               GetWebBrowserChrome();
           if (webBrowserChrome) {
             nsCOMPtr<nsIBrowserChild> browserChild =
                 do_QueryInterface(webBrowserChrome);
             if (browserChild) {
-              nsresult rv = browserChild->RemoteDropLinks(linksCount, links);
-              for (uint32_t i = 0; i < linksCount; i++) {
-                NS_RELEASE(links[i]);
-              }
-              free(links);
+              nsresult rv = browserChild->RemoteDropLinks(links);
               return rv;
             }
           }
           nsAutoString url;
           if (NS_SUCCEEDED(links[0]->GetUrl(url))) {
             if (!url.IsEmpty()) {
 #ifndef ANDROID
               MOZ_ASSERT(triggeringPrincipal,
@@ -907,21 +901,16 @@ nsDocShellTreeOwner::HandleEvent(Event* 
               LoadURIOptions loadURIOptions;
               loadURIOptions.mTriggeringPrincipal = triggeringPrincipal;
               nsCOMPtr<nsIContentSecurityPolicy> csp;
               handler->GetCSP(dragEvent, getter_AddRefs(csp));
               loadURIOptions.mCsp = csp;
               webnav->LoadURI(url, loadURIOptions);
             }
           }
-
-          for (uint32_t i = 0; i < linksCount; i++) {
-            NS_RELEASE(links[i]);
-          }
-          free(links);
         }
       }
     } else {
       aEvent->StopPropagation();
       aEvent->PreventDefault();
     }
   }
 
--- a/dom/base/ContentAreaDropListener.jsm
+++ b/dom/base/ContentAreaDropListener.jsm
@@ -271,17 +271,17 @@ ContentAreaDropListener.prototype =
       let name = links[0].name;
       if (name)
         aName.value = name;
     }
 
     return url;
   },
 
-  dropLinks: function(aEvent, aDisallowInherit, aCount)
+  dropLinks: function(aEvent, aDisallowInherit)
   {
     if (aEvent && this._eventTargetIsDisabled(aEvent))
       return [];
 
     let dataTransfer = aEvent.dataTransfer;
     let links = this._getDropLinks(dataTransfer);
     let triggeringPrincipal = this._getTriggeringPrincipalFromDataTransfer(dataTransfer, false);
 
@@ -292,18 +292,16 @@ ContentAreaDropListener.prototype =
       } catch (ex) {
         // Prevent the drop entirely if any of the links are invalid even if
         // one of them is valid.
         aEvent.stopPropagation();
         aEvent.preventDefault();
         throw ex;
       }
     }
-    if (aCount)
-      aCount.value = links.length;
 
     return links;
   },
 
   validateURIsForDrop: function(aEvent, aURIs, aDisallowInherit)
   {
     let dataTransfer = aEvent.dataTransfer;
     let triggeringPrincipal = this._getTriggeringPrincipalFromDataTransfer(dataTransfer, false);
--- a/dom/base/nsIDroppedLinkHandler.idl
+++ b/dom/base/nsIDroppedLinkHandler.idl
@@ -60,31 +60,29 @@ interface nsIDroppedLinkHandler : nsISup
    * otherwise.
    */
   AString dropLink(in DragEvent aEvent, out AString aName,
                    [optional] in boolean aDisallowInherit);
 
   /**
    * Given a drop event aEvent, determines links being dragged and returns
    * them. If links are returned the caller can, for instance, load them. If
-   * the count of links is 0, there is no valid link to be dropped.
+   * the returned array is empty, there is no valid link to be dropped.
    *
    * A NS_ERROR_DOM_SECURITY_ERR error will be thrown and the event cancelled if
    * the receiving target should not load the uri for security reasons. This
    * will occur if any of the following conditions are true:
    *  - the source of the drag initiated a link for dragging that
    *    it itself cannot access. This prevents a source document from tricking
    *    the user into a dragging a chrome url, for example.
    *  - aDisallowInherit is true, and the URI being dropped would inherit the
    *    current document's security context (URI_INHERITS_SECURITY_CONTEXT).
    */
-  void dropLinks(in DragEvent aEvent,
-                 [optional] in boolean aDisallowInherit,
-                 [optional] out unsigned long aCount,
-                 [retval, array, size_is(aCount)] out nsIDroppedLinkItem aLinks);
+  Array<nsIDroppedLinkItem> dropLinks(in DragEvent aEvent,
+                                      [optional] in boolean aDisallowInherit);
 
   /**
    * Given a drop event aEvent, validate the extra URIs for the event,
    * this is used when the caller extracts yet another URIs from the dropped
    * text, like home button that splits the text with "|".
    */
   void validateURIsForDrop(in DragEvent aEvent,
                            in Array<AString> aURIs,
--- a/dom/interfaces/base/nsIBrowserChild.idl
+++ b/dom/interfaces/base/nsIBrowserChild.idl
@@ -24,18 +24,17 @@ interface nsIBrowserChild : nsISupports
 
   [noscript, notxpcom] void enableDisableCommands(in AString action,
                                                   in CommandsArrayRef enabledCommands,
                                                   in CommandsArrayRef disabledCommands);
 
   [noscript] void remoteSizeShellTo(in int32_t width, in int32_t height,
                                     in int32_t shellItemWidth, in int32_t shellItemHeight);
 
-  [noscript] void remoteDropLinks(in unsigned long linksCount,
-                                  [array, size_is(linksCount)] in nsIDroppedLinkItem links);
+  void remoteDropLinks(in Array<nsIDroppedLinkItem> links);
 
   readonly attribute uint64_t tabId;
 
   /*
    * Indicates whether or not there are other tabs in this tab's window.
    */
   attribute boolean hasSiblings;
 
--- a/dom/ipc/BrowserChild.cpp
+++ b/dom/ipc/BrowserChild.cpp
@@ -730,35 +730,35 @@ BrowserChild::RemoteSizeShellTo(int32_t 
 
   bool sent = SendSizeShellTo(flags, aWidth, aHeight, aShellItemWidth,
                               aShellItemHeight);
 
   return sent ? NS_OK : NS_ERROR_FAILURE;
 }
 
 NS_IMETHODIMP
-BrowserChild::RemoteDropLinks(uint32_t aLinksCount,
-                              nsIDroppedLinkItem** aLinks) {
+BrowserChild::RemoteDropLinks(
+    const nsTArray<RefPtr<nsIDroppedLinkItem>>& aLinks) {
   nsTArray<nsString> linksArray;
   nsresult rv = NS_OK;
-  for (uint32_t i = 0; i < aLinksCount; i++) {
+  for (nsIDroppedLinkItem* link : aLinks) {
     nsString tmp;
-    rv = aLinks[i]->GetUrl(tmp);
+    rv = link->GetUrl(tmp);
     if (NS_FAILED(rv)) {
       return rv;
     }
     linksArray.AppendElement(tmp);
 
-    rv = aLinks[i]->GetName(tmp);
+    rv = link->GetName(tmp);
     if (NS_FAILED(rv)) {
       return rv;
     }
     linksArray.AppendElement(tmp);
 
-    rv = aLinks[i]->GetType(tmp);
+    rv = link->GetType(tmp);
     if (NS_FAILED(rv)) {
       return rv;
     }
     linksArray.AppendElement(tmp);
   }
   bool sent = SendDropLinks(linksArray);
 
   return sent ? NS_OK : NS_ERROR_FAILURE;
@@ -1811,17 +1811,18 @@ mozilla::ipc::IPCResult BrowserChild::Re
     nsCOMPtr<Document> document = GetTopLevelDocument();
     if (gfxPrefs::TouchActionEnabled()) {
       APZCCallbackHelper::SendSetAllowedTouchBehaviorNotification(
           mPuppetWidget, document, localEvent, aInputBlockId,
           mSetAllowedTouchBehaviorCallback);
     }
     UniquePtr<DisplayportSetListener> postLayerization =
         APZCCallbackHelper::SendSetTargetAPZCNotification(
-            mPuppetWidget, document, localEvent, aGuid.mLayersId, aInputBlockId);
+            mPuppetWidget, document, localEvent, aGuid.mLayersId,
+            aInputBlockId);
     if (postLayerization && postLayerization->Register()) {
       Unused << postLayerization.release();
     }
   }
 
   // Dispatch event to content (potentially a long-running operation)
   nsEventStatus status = DispatchWidgetEventViaAPZ(localEvent);