Bug 980275 - Merge DOMFileRequest and FileRequest. r=bent
authorJan Varga <jan.varga@gmail.com>
Sun, 16 Mar 2014 17:53:44 +0100
changeset 173839 db46457d0731
parent 173838 d14ffbbfac7b
child 173840 a83ecf923dec
push id26425
push userphilringnalda@gmail.com
push date2014-03-17 04:06 +0000
treeherdermozilla-central@5870a4beef4d [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersbent
bugs980275
milestone30.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 980275 - Merge DOMFileRequest and FileRequest. r=bent
dom/bindings/Bindings.conf
dom/file/DOMFileRequest.cpp
dom/file/DOMFileRequest.h
dom/file/FileHandle.cpp
dom/file/FileRequest.cpp
dom/file/FileRequest.h
dom/file/LockedFile.cpp
dom/file/LockedFile.h
dom/file/moz.build
dom/file/test/mochitest.ini
dom/file/test/test_getFile.html
--- a/dom/bindings/Bindings.conf
+++ b/dom/bindings/Bindings.conf
@@ -405,17 +405,17 @@ DOMInterfaces = {
 },
 
 'FileReaderSync': {
     'workers': True,
     'wrapperCache': False,
 },
 
 'FileRequest': {
-    'nativeType': 'mozilla::dom::file::DOMFileRequest',
+    'nativeType': 'mozilla::dom::file::FileRequest',
 },
 
 'FormData': [
 {
     'nativeType': 'nsFormData'
 },
 {
     'workers': True,
deleted file mode 100644
--- a/dom/file/DOMFileRequest.cpp
+++ /dev/null
@@ -1,42 +0,0 @@
-/* -*- Mode: C++; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
-/* vim: set ts=2 et sw=2 tw=80: */
-/* 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/. */
-
-#include "DOMFileRequest.h"
-
-#include "mozilla/dom/FileRequestBinding.h"
-#include "LockedFile.h"
-
-USING_FILE_NAMESPACE
-
-DOMFileRequest::DOMFileRequest(nsPIDOMWindow* aWindow)
-  : FileRequest(aWindow)
-{
-}
-
-// static
-already_AddRefed<DOMFileRequest>
-DOMFileRequest::Create(nsPIDOMWindow* aOwner, LockedFile* aLockedFile)
-{
-  MOZ_ASSERT(NS_IsMainThread(), "Wrong thread!");
-
-  nsRefPtr<DOMFileRequest> request = new DOMFileRequest(aOwner);
-  request->mLockedFile = aLockedFile;
-
-  return request.forget();
-}
-
-/* virtual */ JSObject*
-DOMFileRequest::WrapObject(JSContext* aCx, JS::Handle<JSObject*> aScope)
-{
-  return FileRequestBinding::Wrap(aCx, aScope, this);
-}
-
-nsIDOMLockedFile*
-DOMFileRequest::GetLockedFile() const
-{
-  NS_ASSERTION(NS_IsMainThread(), "Wrong thread!");
-  return mLockedFile;
-}
deleted file mode 100644
--- a/dom/file/DOMFileRequest.h
+++ /dev/null
@@ -1,34 +0,0 @@
-/* -*- Mode: C++; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
-/* vim: set ts=2 et sw=2 tw=80: */
-/* 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/. */
-
-#ifndef mozilla_dom_file_DOMFileRequest_h
-#define mozilla_dom_file_DOMFileRequest_h
-
-#include "FileRequest.h"
-
-class nsIDOMLockedFile;
-
-BEGIN_FILE_NAMESPACE
-
-class DOMFileRequest : public FileRequest
-{
-public:
-  static already_AddRefed<DOMFileRequest>
-  Create(nsPIDOMWindow* aOwner, LockedFile* aLockedFile);
-
-  virtual JSObject* WrapObject(JSContext* aCx,
-                               JS::Handle<JSObject*> aScope) MOZ_OVERRIDE;
-
-  nsIDOMLockedFile* GetLockedFile() const;
-  IMPL_EVENT_HANDLER(progress)
-
-protected:
-  DOMFileRequest(nsPIDOMWindow* aWindow);
-};
-
-END_FILE_NAMESPACE
-
-#endif // mozilla_dom_file_DOMFileRequest_h
--- a/dom/file/FileHandle.cpp
+++ b/dom/file/FileHandle.cpp
@@ -159,17 +159,18 @@ FileHandle::GetFile(ErrorResult& aError)
 
   nsRefPtr<LockedFile> lockedFile =
     LockedFile::Create(this, FileMode::Readonly, LockedFile::PARALLEL);
   if (!lockedFile) {
     aError.Throw(NS_ERROR_DOM_FILEHANDLE_UNKNOWN_ERR);
     return nullptr;
   }
 
-  nsRefPtr<FileRequest> request = FileRequest::Create(GetOwner(), lockedFile);
+  nsRefPtr<FileRequest> request =
+    FileRequest::Create(GetOwner(), lockedFile, /* aWrapAsDOMRequest */ true);
 
   nsRefPtr<MetadataParameters> params = new MetadataParameters(true, false);
 
   nsRefPtr<GetFileHelper> helper =
     new GetFileHelper(lockedFile, request, params, this);
 
   nsresult rv = helper->Enqueue();
   if (NS_FAILED(rv)) {
--- a/dom/file/FileRequest.cpp
+++ b/dom/file/FileRequest.cpp
@@ -1,46 +1,48 @@
 /* -*- Mode: C++; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
 /* vim: set ts=2 et sw=2 tw=80: */
 /* 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/. */
 
 #include "FileRequest.h"
 
-#include "DOMFileRequest.h"
+#include "mozilla/dom/FileRequestBinding.h"
 #include "nsCxPusher.h"
 #include "nsEventDispatcher.h"
 #include "nsError.h"
 #include "nsIDOMProgressEvent.h"
 #include "nsDOMClassInfoID.h"
 #include "FileHelper.h"
 #include "LockedFile.h"
 
 USING_FILE_NAMESPACE
 
 FileRequest::FileRequest(nsPIDOMWindow* aWindow)
-  : DOMRequest(aWindow)
+  : DOMRequest(aWindow), mWrapAsDOMRequest(false)
 {
   NS_ASSERTION(NS_IsMainThread(), "Wrong thread!");
 }
 
 FileRequest::~FileRequest()
 {
   NS_ASSERTION(NS_IsMainThread(), "Wrong thread!");
 }
 
 // static
 already_AddRefed<FileRequest>
-FileRequest::Create(nsPIDOMWindow* aOwner, LockedFile* aLockedFile)
+FileRequest::Create(nsPIDOMWindow* aOwner, LockedFile* aLockedFile,
+                    bool aWrapAsDOMRequest)
 {
   NS_ASSERTION(NS_IsMainThread(), "Wrong thread!");
 
   nsRefPtr<FileRequest> request = new FileRequest(aOwner);
   request->mLockedFile = aLockedFile;
+  request->mWrapAsDOMRequest = aWrapAsDOMRequest;
 
   return request.forget();
 }
 
 nsresult
 FileRequest::PreHandleEvent(nsEventChainPreVisitor& aVisitor)
 {
   NS_ASSERTION(NS_IsMainThread(), "Wrong thread!");
@@ -96,16 +98,33 @@ NS_IMPL_CYCLE_COLLECTION_INHERITED_1(Fil
                                      mLockedFile)
 
 NS_INTERFACE_MAP_BEGIN_CYCLE_COLLECTION_INHERITED(FileRequest)
 NS_INTERFACE_MAP_END_INHERITING(DOMRequest)
 
 NS_IMPL_ADDREF_INHERITED(FileRequest, DOMRequest)
 NS_IMPL_RELEASE_INHERITED(FileRequest, DOMRequest)
 
+// virtual
+JSObject*
+FileRequest::WrapObject(JSContext* aCx, JS::Handle<JSObject*> aScope)
+{
+  if (mWrapAsDOMRequest) {
+    return DOMRequest::WrapObject(aCx, aScope);
+  }
+  return FileRequestBinding::Wrap(aCx, aScope, this);
+}
+
+nsIDOMLockedFile*
+FileRequest::GetLockedFile() const
+{
+  MOZ_ASSERT(NS_IsMainThread(), "Wrong thread!");
+  return mLockedFile;
+}
+
 void
 FileRequest::FireProgressEvent(uint64_t aLoaded, uint64_t aTotal)
 {
   if (NS_FAILED(CheckInnerWindowCorrectness())) {
     return;
   }
 
   nsCOMPtr<nsIDOMEvent> event;
--- a/dom/file/FileRequest.h
+++ b/dom/file/FileRequest.h
@@ -19,36 +19,49 @@ class LockedFile;
 
 class FileRequest : public mozilla::dom::DOMRequest
 {
 public:
   NS_DECL_ISUPPORTS_INHERITED
   NS_DECL_CYCLE_COLLECTION_CLASS_INHERITED(FileRequest, DOMRequest)
 
   static already_AddRefed<FileRequest>
-  Create(nsPIDOMWindow* aOwner, LockedFile* aLockedFile);
+  Create(nsPIDOMWindow* aOwner, LockedFile* aLockedFile,
+         bool aWrapAsDOMRequest);
 
   // nsIDOMEventTarget
   virtual nsresult
   PreHandleEvent(nsEventChainPreVisitor& aVisitor) MOZ_OVERRIDE;
 
   void
   OnProgress(uint64_t aProgress, uint64_t aProgressMax)
   {
     FireProgressEvent(aProgress, aProgressMax);
   }
 
   nsresult
   NotifyHelperCompleted(FileHelper* aFileHelper);
 
+  // nsWrapperCache
+  virtual JSObject*
+  WrapObject(JSContext* aCx, JS::Handle<JSObject*> aScope) MOZ_OVERRIDE;
+
+  // WebIDL
+  nsIDOMLockedFile*
+  GetLockedFile() const;
+
+  IMPL_EVENT_HANDLER(progress)
+
 protected:
   FileRequest(nsPIDOMWindow* aWindow);
   ~FileRequest();
 
   void
   FireProgressEvent(uint64_t aLoaded, uint64_t aTotal);
 
   nsRefPtr<LockedFile> mLockedFile;
+
+  bool mWrapAsDOMRequest;
 };
 
 END_FILE_NAMESPACE
 
 #endif // mozilla_dom_file_filerequest_h__
--- a/dom/file/LockedFile.cpp
+++ b/dom/file/LockedFile.cpp
@@ -17,19 +17,19 @@
 #include "nsNetUtil.h"
 #include "nsDOMClassInfoID.h"
 #include "nsJSUtils.h"
 #include "nsStringStream.h"
 #include "nsWidgetsCID.h"
 #include "xpcpublic.h"
 
 #include "AsyncHelper.h"
-#include "DOMFileRequest.h"
 #include "FileHandle.h"
 #include "FileHelper.h"
+#include "FileRequest.h"
 #include "FileService.h"
 #include "FileStreamWrappers.h"
 #include "MemoryStreams.h"
 #include "MetadataHelper.h"
 #include "nsError.h"
 #include "nsContentUtils.h"
 
 #include "mozilla/dom/EncodingUtils.h"
@@ -415,21 +415,21 @@ LockedFile::GetOrCreateStream(nsISupport
   }
 
   nsCOMPtr<nsISupports> stream(mStream);
   stream.forget(aStream);
 
   return NS_OK;
 }
 
-already_AddRefed<DOMFileRequest>
+already_AddRefed<FileRequest>
 LockedFile::GenerateFileRequest()
 {
   NS_ASSERTION(NS_IsMainThread(), "Wrong thread!");
-  return DOMFileRequest::Create(GetOwner(), this);
+  return FileRequest::Create(GetOwner(), this, /* aWrapAsDOMRequest */ false);
 }
 
 bool
 LockedFile::IsOpen() const
 {
   NS_ASSERTION(NS_IsMainThread(), "Wrong thread!");
 
   // If we haven't started anything then we're open.
@@ -551,17 +551,17 @@ LockedFile::GetMetadata(JS::Handle<JS::V
   NS_ENSURE_TRUE(result, NS_ERROR_DOM_FILEHANDLE_UNKNOWN_ERR);
 
   nsRefPtr<MetadataParameters> params =
     new MetadataParameters(config.mSize, config.mLastModified);
   if (!params->IsConfigured()) {
     return NS_ERROR_TYPE_ERR;
   }
 
-  nsRefPtr<DOMFileRequest> fileRequest = GenerateFileRequest();
+  nsRefPtr<FileRequest> fileRequest = GenerateFileRequest();
 
   nsRefPtr<MetadataHelper> helper =
     new MetadataHelper(this, fileRequest, params);
 
   nsresult rv = helper->Enqueue();
   NS_ENSURE_SUCCESS(rv, NS_ERROR_DOM_FILEHANDLE_UNKNOWN_ERR);
 
   nsRefPtr<nsIDOMDOMRequest> request = fileRequest.forget();
@@ -588,17 +588,17 @@ LockedFile::ReadAsArrayBuffer(uint64_t a
     return NS_ERROR_TYPE_ERR;
   }
 
   // Do nothing if the window is closed
   if (!GetOwner()) {
     return NS_OK;
   }
 
-  nsRefPtr<DOMFileRequest> fileRequest = GenerateFileRequest();
+  nsRefPtr<FileRequest> fileRequest = GenerateFileRequest();
 
   nsRefPtr<ReadHelper> helper =
     new ReadHelper(this, fileRequest, mLocation, aSize);
 
   nsresult rv = helper->Init();
   NS_ENSURE_SUCCESS(rv, NS_ERROR_DOM_FILEHANDLE_UNKNOWN_ERR);
 
   rv = helper->Enqueue();
@@ -630,17 +630,17 @@ LockedFile::ReadAsText(uint64_t aSize,
     return NS_ERROR_TYPE_ERR;
   }
 
   // Do nothing if the window is closed
   if (!GetOwner()) {
     return NS_OK;
   }
 
-  nsRefPtr<DOMFileRequest> fileRequest = GenerateFileRequest();
+  nsRefPtr<FileRequest> fileRequest = GenerateFileRequest();
 
   nsRefPtr<ReadTextHelper> helper =
     new ReadTextHelper(this, fileRequest, mLocation, aSize, aEncoding);
 
   nsresult rv = helper->Init();
   NS_ENSURE_SUCCESS(rv, NS_ERROR_DOM_FILEHANDLE_UNKNOWN_ERR);
 
   rv = helper->Enqueue();
@@ -701,17 +701,17 @@ LockedFile::Truncate(uint64_t aSize,
     location = mLocation;
   }
 
   // Do nothing if the window is closed
   if (!GetOwner()) {
     return NS_OK;
   }
 
-  nsRefPtr<DOMFileRequest> fileRequest = GenerateFileRequest();
+  nsRefPtr<FileRequest> fileRequest = GenerateFileRequest();
 
   nsRefPtr<TruncateHelper> helper =
     new TruncateHelper(this, fileRequest, location);
 
   nsresult rv = helper->Enqueue();
   NS_ENSURE_SUCCESS(rv, NS_ERROR_DOM_FILEHANDLE_UNKNOWN_ERR);
 
   if (aOptionalArgCount) {
@@ -736,17 +736,17 @@ LockedFile::Flush(nsISupports** _retval)
     return NS_ERROR_DOM_FILEHANDLE_READ_ONLY_ERR;
   }
 
   // Do nothing if the window is closed
   if (!GetOwner()) {
     return NS_OK;
   }
 
-  nsRefPtr<DOMFileRequest> fileRequest = GenerateFileRequest();
+  nsRefPtr<FileRequest> fileRequest = GenerateFileRequest();
 
   nsRefPtr<FlushHelper> helper = new FlushHelper(this, fileRequest);
 
   nsresult rv = helper->Enqueue();
   NS_ENSURE_SUCCESS(rv, NS_ERROR_DOM_FILEHANDLE_UNKNOWN_ERR);
 
   nsRefPtr<nsIDOMDOMRequest> request = fileRequest.forget();
   request.forget(_retval);
@@ -858,17 +858,17 @@ LockedFile::WriteOrAppend(JS::Handle<JS:
     GetInputStreamForJSVal(aValue, aCx, getter_AddRefs(inputStream),
                            &inputLength);
   NS_ENSURE_SUCCESS(rv, rv);
 
   if (!inputLength) {
     return NS_OK;
   }
 
-  nsRefPtr<DOMFileRequest> fileRequest = GenerateFileRequest();
+  nsRefPtr<FileRequest> fileRequest = GenerateFileRequest();
 
   uint64_t location = aAppend ? UINT64_MAX : mLocation;
 
   nsRefPtr<WriteHelper> helper =
     new WriteHelper(this, fileRequest, location, inputStream, inputLength);
 
   rv = helper->Enqueue();
   NS_ENSURE_SUCCESS(rv, NS_ERROR_DOM_FILEHANDLE_UNKNOWN_ERR);
--- a/dom/file/LockedFile.h
+++ b/dom/file/LockedFile.h
@@ -14,17 +14,16 @@
 #include "nsIRunnable.h"
 
 #include "nsDOMEventTargetHelper.h"
 
 class nsIInputStream;
 
 BEGIN_FILE_NAMESPACE
 
-class DOMFileRequest;
 class FileHandle;
 class FileRequest;
 class MetadataHelper;
 
 class LockedFile : public nsDOMEventTargetHelper,
                    public nsIDOMLockedFile,
                    public nsIRunnable
 {
@@ -93,17 +92,17 @@ private:
   ~LockedFile();
 
   void
   OnNewRequest();
 
   void
   OnRequestFinished();
 
-  inline already_AddRefed<DOMFileRequest>
+  already_AddRefed<FileRequest>
   GenerateFileRequest();
 
   nsresult
   WriteOrAppend(JS::Handle<JS::Value> aValue, JSContext* aCx,
                 nsISupports** _retval, bool aAppend);
 
   nsresult
   Finish();
--- a/dom/file/moz.build
+++ b/dom/file/moz.build
@@ -17,33 +17,32 @@ EXPORTS += [
 ]
 
 EXPORTS.mozilla.dom.file += [
     'ArchiveEvent.h',
     'ArchiveReader.h',
     'ArchiveRequest.h',
     'ArchiveZipEvent.h',
     'ArchiveZipFile.h',
-    'DOMFileRequest.h',
     'File.h',
     'FileCommon.h',
     'FileHandle.h',
     'FileHelper.h',
+    'FileRequest.h',
     'FileService.h',
     'LockedFile.h',
 ]
 
 UNIFIED_SOURCES += [
     'ArchiveEvent.cpp',
     'ArchiveReader.cpp',
     'ArchiveRequest.cpp',
     'ArchiveZipEvent.cpp',
     'ArchiveZipFile.cpp',
     'AsyncHelper.cpp',
-    'DOMFileRequest.cpp',
     'File.cpp',
     'FileHandle.cpp',
     'FileHelper.cpp',
     'FileRequest.cpp',
     'FileService.cpp',
     'FileStreamWrappers.cpp',
     'LockedFile.cpp',
     'MemoryStreams.cpp',
--- a/dom/file/test/mochitest.ini
+++ b/dom/file/test/mochitest.ini
@@ -8,16 +8,18 @@ support-files =
 skip-if = buildapp == 'b2g'
 [test_archivereader.html]
 skip-if = buildapp == 'b2g'
 [test_archivereader_nonUnicode.html]
 skip-if = buildapp == 'b2g'
 [test_archivereader_zip_in_zip.html]
 skip-if = buildapp == 'b2g'
 [test_bug_793311.html]
+[test_getFile.html]
+skip-if = buildapp == 'b2g'
 [test_getFileId.html]
 [test_location.html]
 skip-if = buildapp == 'b2g'
 [test_lockedfile_lifetimes.html]
 skip-if = buildapp == 'b2g'
 [test_lockedfile_lifetimes_nested.html]
 skip-if = buildapp == 'b2g'
 [test_lockedfile_ordering.html]
new file mode 100644
--- /dev/null
+++ b/dom/file/test/test_getFile.html
@@ -0,0 +1,43 @@
+<!--
+  Any copyright is dedicated to the Public Domain.
+  http://creativecommons.org/publicdomain/zero/1.0/
+-->
+<html>
+<head>
+  <title>File Handle Test</title>
+
+  <script type="text/javascript" src="/tests/SimpleTest/SimpleTest.js"></script>
+  <link rel="stylesheet" type="text/css" href="/tests/SimpleTest/test.css" />
+
+  <script type="text/javascript;version=1.7">
+  function testSteps()
+  {
+    for each (let fileStorage in fileStorages) {
+      let request = getFileHandle(fileStorage.key, "test.txt");
+      request.onerror = errorHandler;
+      request.onsuccess = grabEventAndContinueHandler;
+      let event = yield undefined;
+
+      let fileHandle = event.target.result;
+      fileHandle.onerror = errorHandler;
+
+      request = fileHandle.getFile();
+      ok(request instanceof DOMRequest, "Correct interface");
+      ok(!(request instanceof FileRequest), "Correct interface");
+      ok(!('lockedFile' in request), "Property should not exist");
+      ok(request.lockedFile === undefined, "Property should not exist");
+      ok(!('onprogress' in request), "Property should not exist");
+      ok(request.onprogress === undefined, "Property should not exist");
+    }
+
+    finishTest();
+    yield undefined;
+  }
+  </script>
+  <script type="text/javascript;version=1.7" src="helpers.js"></script>
+
+</head>
+
+<body onload="runTest();"></body>
+
+</html>