Bug 1520422 - Entries API should not use callback inferfaces, r=Ms2ger
authorAndrea Marchesini <amarchesini@mozilla.com>
Tue, 22 Jan 2019 10:29:49 +0100
changeset 454797 914de25ef02776554dd747e3cdca24bcf7a805da
parent 454796 4e928a279f87eb139d5683e1b5aba7ffbff59de1
child 454798 faade3f1fa138c0abe93a88fd738307329b5d9a2
push idunknown
push userunknown
push dateunknown
reviewersMs2ger
bugs1520422
milestone66.0a1
Bug 1520422 - Entries API should not use callback inferfaces, r=Ms2ger
dom/filesystem/compat/CallbackRunnables.cpp
dom/filesystem/compat/FileSystemDirectoryReader.cpp
dom/filesystem/compat/FileSystemFileEntry.cpp
dom/filesystem/compat/FileSystemRootDirectoryReader.cpp
dom/webidl/DataTransferItem.webidl
dom/webidl/File.webidl
dom/webidl/FileSystem.webidl
dom/webidl/FileSystemDirectoryEntry.webidl
dom/webidl/FileSystemDirectoryReader.webidl
dom/webidl/FileSystemEntry.webidl
dom/webidl/FileSystemFileEntry.webidl
dom/webidl/HTMLInputElement.webidl
--- a/dom/filesystem/compat/CallbackRunnables.cpp
+++ b/dom/filesystem/compat/CallbackRunnables.cpp
@@ -28,17 +28,17 @@ EntryCallbackRunnable::EntryCallbackRunn
                                              FileSystemEntry* aEntry)
     : Runnable("EntryCallbackRunnable"), mCallback(aCallback), mEntry(aEntry) {
   MOZ_ASSERT(aCallback);
   MOZ_ASSERT(aEntry);
 }
 
 NS_IMETHODIMP
 EntryCallbackRunnable::Run() {
-  mCallback->HandleEvent(*mEntry);
+  mCallback->Call(*mEntry);
   return NS_OK;
 }
 
 ErrorCallbackRunnable::ErrorCallbackRunnable(nsIGlobalObject* aGlobalObject,
                                              ErrorCallback* aCallback,
                                              nsresult aError)
     : Runnable("ErrorCallbackRunnable"),
       mGlobal(aGlobalObject),
@@ -47,30 +47,30 @@ ErrorCallbackRunnable::ErrorCallbackRunn
   MOZ_ASSERT(aGlobalObject);
   MOZ_ASSERT(aCallback);
   MOZ_ASSERT(NS_FAILED(aError));
 }
 
 NS_IMETHODIMP
 ErrorCallbackRunnable::Run() {
   RefPtr<DOMException> exception = DOMException::Create(mError);
-  mCallback->HandleEvent(*exception);
+  mCallback->Call(*exception);
   return NS_OK;
 }
 
 EmptyEntriesCallbackRunnable::EmptyEntriesCallbackRunnable(
     FileSystemEntriesCallback* aCallback)
     : Runnable("EmptyEntriesCallbackRunnable"), mCallback(aCallback) {
   MOZ_ASSERT(aCallback);
 }
 
 NS_IMETHODIMP
 EmptyEntriesCallbackRunnable::Run() {
   Sequence<OwningNonNull<FileSystemEntry>> sequence;
-  mCallback->HandleEvent(sequence);
+  mCallback->Call(sequence);
   return NS_OK;
 }
 
 GetEntryHelper::GetEntryHelper(FileSystemDirectoryEntry* aParentEntry,
                                Directory* aDirectory,
                                nsTArray<nsString>& aParts,
                                FileSystem* aFileSystem,
                                FileSystemEntryCallback* aSuccessCallback,
@@ -183,31 +183,31 @@ void GetEntryHelper::CompleteOperation(J
     RefPtr<File> file;
     if (NS_FAILED(UNWRAP_OBJECT(File, aObj, file))) {
       Error(NS_ERROR_DOM_TYPE_MISMATCH_ERR);
       return;
     }
 
     RefPtr<FileSystemFileEntry> entry = new FileSystemFileEntry(
         mParentEntry->GetParentObject(), file, mParentEntry, mFileSystem);
-    mSuccessCallback->HandleEvent(*entry);
+    mSuccessCallback->Call(*entry);
     return;
   }
 
   MOZ_ASSERT(mType == FileSystemDirectoryEntry::eGetDirectory);
 
   RefPtr<Directory> directory;
   if (NS_FAILED(UNWRAP_OBJECT(Directory, aObj, directory))) {
     Error(NS_ERROR_DOM_TYPE_MISMATCH_ERR);
     return;
   }
 
   RefPtr<FileSystemDirectoryEntry> entry = new FileSystemDirectoryEntry(
       mParentEntry->GetParentObject(), directory, mParentEntry, mFileSystem);
-  mSuccessCallback->HandleEvent(*entry);
+  mSuccessCallback->Call(*entry);
 }
 
 void GetEntryHelper::ContinueRunning(JSObject* aObj) {
   MOZ_ASSERT(!mParts.IsEmpty());
 
   RefPtr<Directory> directory;
   if (NS_FAILED(UNWRAP_OBJECT(Directory, aObj, directory))) {
     Error(NS_ERROR_DOM_TYPE_MISMATCH_ERR);
--- a/dom/filesystem/compat/FileSystemDirectoryReader.cpp
+++ b/dom/filesystem/compat/FileSystemDirectoryReader.cpp
@@ -81,17 +81,17 @@ class PromiseHandler final : public Prom
       }
 
       RefPtr<FileSystemDirectoryEntry> entry =
           new FileSystemDirectoryEntry(mParentEntry->GetParentObject(),
                                        directory, mParentEntry, mFileSystem);
       sequence[i] = entry;
     }
 
-    mSuccessCallback->HandleEvent(sequence);
+    mSuccessCallback->Call(sequence);
   }
 
   virtual void RejectedCallback(JSContext* aCx,
                                 JS::Handle<JS::Value> aValue) override {
     if (mErrorCallback) {
       RefPtr<ErrorCallbackRunnable> runnable = new ErrorCallbackRunnable(
           mParentEntry->GetParentObject(), mErrorCallback,
           NS_ERROR_DOM_INVALID_STATE_ERR);
--- a/dom/filesystem/compat/FileSystemFileEntry.cpp
+++ b/dom/filesystem/compat/FileSystemFileEntry.cpp
@@ -26,17 +26,17 @@ class FileCallbackRunnable final : publi
 
   NS_IMETHOD
   Run() override {
     // Here we clone the File object.
 
     RefPtr<File> file = File::Create(mFile->GetParentObject(), mFile->Impl());
     MOZ_ASSERT(file);
 
-    mCallback->HandleEvent(*file);
+    mCallback->Call(*file);
     return NS_OK;
   }
 
  private:
   RefPtr<FileCallback> mCallback;
   RefPtr<File> mFile;
 };
 
--- a/dom/filesystem/compat/FileSystemRootDirectoryReader.cpp
+++ b/dom/filesystem/compat/FileSystemRootDirectoryReader.cpp
@@ -28,17 +28,17 @@ class EntriesCallbackRunnable final : pu
   Run() override {
     Sequence<OwningNonNull<FileSystemEntry>> entries;
     for (uint32_t i = 0; i < mEntries.Length(); ++i) {
       if (!entries.AppendElement(mEntries[i].forget(), fallible)) {
         return NS_ERROR_OUT_OF_MEMORY;
       }
     }
 
-    mCallback->HandleEvent(entries);
+    mCallback->Call(entries);
     return NS_OK;
   }
 
  private:
   RefPtr<FileSystemEntriesCallback> mCallback;
   Sequence<RefPtr<FileSystemEntry>> mEntries;
 };
 
--- a/dom/webidl/DataTransferItem.webidl
+++ b/dom/webidl/DataTransferItem.webidl
@@ -1,25 +1,27 @@
 /* -*- Mode: IDL; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
 /* This Source Code Form is subject to the terms of the Mozilla Public
  * License, v. 2.0. If a copy of the MPL was not distributed with this file,
  * You can obtain one at http://mozilla.org/MPL/2.0/.
  *
  * The origin of this IDL file is:
  * https://html.spec.whatwg.org/multipage/interaction.html#the-datatransferitem-interface
+ * https://wicg.github.io/entries-api/#idl-index
  */
 
 interface DataTransferItem {
   readonly attribute DOMString kind;
   readonly attribute DOMString type;
   [Throws, NeedsSubjectPrincipal]
   void getAsString(FunctionStringCallback? _callback);
   [Throws, NeedsSubjectPrincipal]
   File? getAsFile();
 };
 
 callback FunctionStringCallback = void (DOMString data);
 
+// https://wicg.github.io/entries-api/#idl-index
 partial interface DataTransferItem {
   [Pref="dom.webkitBlink.filesystem.enabled", BinaryName="getAsEntry", Throws,
    NeedsSubjectPrincipal]
   FileSystemEntry? webkitGetAsEntry();
 };
--- a/dom/webidl/File.webidl
+++ b/dom/webidl/File.webidl
@@ -1,15 +1,16 @@
 /* -*- Mode: IDL; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
 /* This Source Code Form is subject to the terms of the Mozilla Public
  * License, v. 2.0. If a copy of the MPL was not distributed with this file,
  * You can obtain one at http://mozilla.org/MPL/2.0/.
  *
  * The origin of this IDL file is
  * https://w3c.github.io/FileAPI/#file
+ * https://wicg.github.io/entries-api
  */
 
 interface nsIFile;
 
 [Constructor(sequence<BlobPart> fileBits,
              USVString fileName, optional FilePropertyBag options),
  Exposed=(Window,Worker)]
 interface File : Blob {
@@ -23,21 +24,24 @@ dictionary FilePropertyBag : BlobPropert
   long long lastModified;
 };
 
 dictionary ChromeFilePropertyBag : FilePropertyBag {
   DOMString name = "";
   boolean existenceCheck = true;
 };
 
-// Mozilla extensions
+// https://wicg.github.io/entries-api
 partial interface File {
   [BinaryName="relativePath", Func="mozilla::dom::DOMPrefs::dom_webkitBlink_dirPicker_enabled"]
   readonly attribute USVString webkitRelativePath;
+};
 
+// Mozilla extensions
+partial interface File {
   [GetterThrows, ChromeOnly, NeedsCallerType]
   readonly attribute DOMString mozFullPath;
 };
 
 // Mozilla extensions
 // These 2 methods can be used only in these conditions:
 // - the main-thread
 // - parent process OR file process OR, only for testing, with pref
--- a/dom/webidl/FileSystem.webidl
+++ b/dom/webidl/FileSystem.webidl
@@ -1,28 +1,21 @@
 /* -*- Mode: IDL; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
 /* This Source Code Form is subject to the terms of the Mozilla Public
  * License, v. 2.0. If a copy of the MPL was not distributed with this file,
  * You can obtain one at http://mozilla.org/MPL/2.0/.
+ *
+ * https://wicg.github.io/entries-api/#idl-index
  */
 
-
 dictionary FileSystemFlags {
     boolean create = false;
     boolean exclusive = false;
 };
 
-callback interface FileSystemEntryCallback {
-    void handleEvent(FileSystemEntry entry);
-};
+callback FileSystemEntryCallback = void (FileSystemEntry entry);
 
-callback interface VoidCallback {
-    void handleEvent();
-};
-
-callback interface ErrorCallback {
-    void handleEvent(DOMException err);
-};
+callback ErrorCallback = void (DOMException err);
 
 interface FileSystem {
     readonly    attribute USVString name;
     readonly    attribute FileSystemDirectoryEntry root;
 };
--- a/dom/webidl/FileSystemDirectoryEntry.webidl
+++ b/dom/webidl/FileSystemDirectoryEntry.webidl
@@ -1,12 +1,14 @@
 /* -*- Mode: IDL; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
 /* This Source Code Form is subject to the terms of the Mozilla Public
  * License, v. 2.0. If a copy of the MPL was not distributed with this file,
  * You can obtain one at http://mozilla.org/MPL/2.0/.
+ *
+ * https://wicg.github.io/entries-api/#idl-index
  */
 
 interface FileSystemDirectoryEntry : FileSystemEntry {
     FileSystemDirectoryReader createReader();
 
     void getFile(optional USVString? path,
                  optional FileSystemFlags options,
                  optional FileSystemEntryCallback successCallback,
--- a/dom/webidl/FileSystemDirectoryReader.webidl
+++ b/dom/webidl/FileSystemDirectoryReader.webidl
@@ -1,17 +1,17 @@
 /* -*- Mode: IDL; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
 /* This Source Code Form is subject to the terms of the Mozilla Public
  * License, v. 2.0. If a copy of the MPL was not distributed with this file,
  * You can obtain one at http://mozilla.org/MPL/2.0/.
+ *
+ * https://wicg.github.io/entries-api/#idl-index
  */
 
-callback interface FileSystemEntriesCallback {
-    void handleEvent(sequence<FileSystemEntry> entries);
-};
+callback FileSystemEntriesCallback = void (sequence<FileSystemEntry> entries);
 
 interface FileSystemDirectoryReader {
 
     // readEntries can be called just once. The second time it returns no data.
 
     [Throws]
     void readEntries(FileSystemEntriesCallback successCallback,
                      optional ErrorCallback errorCallback);
--- a/dom/webidl/FileSystemEntry.webidl
+++ b/dom/webidl/FileSystemEntry.webidl
@@ -1,12 +1,14 @@
 /* -*- Mode: IDL; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
 /* This Source Code Form is subject to the terms of the Mozilla Public
  * License, v. 2.0. If a copy of the MPL was not distributed with this file,
  * You can obtain one at http://mozilla.org/MPL/2.0/.
+ *
+ * https://wicg.github.io/entries-api/#idl-index
  */
 
 interface FileSystemEntry {
     readonly attribute boolean isFile;
     readonly attribute boolean isDirectory;
 
     [GetterThrows]
     readonly attribute USVString name;
--- a/dom/webidl/FileSystemFileEntry.webidl
+++ b/dom/webidl/FileSystemFileEntry.webidl
@@ -1,15 +1,15 @@
 /* -*- Mode: IDL; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
 /* This Source Code Form is subject to the terms of the Mozilla Public
  * License, v. 2.0. If a copy of the MPL was not distributed with this file,
  * You can obtain one at http://mozilla.org/MPL/2.0/.
+ *
+ * https://wicg.github.io/entries-api/#idl-index
  */
 
-callback interface FileCallback {
-    void handleEvent(File file);
-};
+callback FileCallback = void (File file);
 
 interface FileSystemFileEntry : FileSystemEntry {
     [BinaryName="GetFile"]
     void file (FileCallback successCallback,
                optional ErrorCallback errorCallback);
 };
--- a/dom/webidl/HTMLInputElement.webidl
+++ b/dom/webidl/HTMLInputElement.webidl
@@ -1,16 +1,17 @@
 /* -*- Mode: IDL; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
 /* This Source Code Form is subject to the terms of the Mozilla Public
  * License, v. 2.0. If a copy of the MPL was not distributed with this file,
  * You can obtain one at http://mozilla.org/MPL/2.0/.
  *
  * The origin of this IDL file is
  * http://www.whatwg.org/specs/web-apps/current-work/#the-input-element
  * http://www.whatwg.org/specs/web-apps/current-work/#other-elements,-attributes-and-apis
+ * https://wicg.github.io/entries-api/#idl-index
  *
  * © Copyright 2004-2011 Apple Computer, Inc., Mozilla Foundation, and
  * Opera Software ASA. You are granted a license to use, reproduce
  * and create derivative works of this document.
  */
 
 enum SelectionMode {
   "select",
@@ -227,17 +228,17 @@ partial interface HTMLInputElement {
   Promise<sequence<File>> getFiles(optional boolean recursiveFlag = false);
 
   [Throws, Pref="dom.input.dirpicker"]
   void chooseDirectory();
 };
 
 HTMLInputElement implements MozImageLoadingContent;
 
-// Webkit/Blink
+// https://wicg.github.io/entries-api/#idl-index
 partial interface HTMLInputElement {
   [Pref="dom.webkitBlink.filesystem.enabled", Frozen, Cached, Pure]
   readonly attribute sequence<FileSystemEntry> webkitEntries;
 
   [Pref="dom.webkitBlink.dirPicker.enabled", BinaryName="WebkitDirectoryAttr", SetterThrows]
           attribute boolean webkitdirectory;
 };