Bug 963064 - FileHandle cleanup. r=bent
authorJan Varga <jan.varga@gmail.com>
Mon, 24 Feb 2014 21:56:13 +0100
changeset 170577 90b514d09591dd1d5424bad8bf10d55a9853979f
parent 170576 a15a762f7eefdd7c09ce04574a968c69b2817c5d
child 170578 edf18d2929c328c10b62b8779d63431b84aca6c3
push id270
push userpvanderbeken@mozilla.com
push dateThu, 06 Mar 2014 09:24:21 +0000
reviewersbent
bugs963064
milestone30.0a1
Bug 963064 - FileHandle cleanup. r=bent
dom/base/nsDOMWindowUtils.cpp
dom/file/DOMFileHandle.cpp
dom/file/DOMFileHandle.h
dom/file/FileHandle.cpp
dom/file/FileHandle.h
dom/file/LockedFile.cpp
dom/file/moz.build
dom/file/nsIDOMFileHandle.idl
dom/file/nsIDOMLockedFile.idl
dom/indexedDB/IDBDatabase.cpp
dom/indexedDB/IDBFileHandle.cpp
dom/indexedDB/IDBFileHandle.h
dom/indexedDB/IDBObjectStore.cpp
--- a/dom/base/nsDOMWindowUtils.cpp
+++ b/dom/base/nsDOMWindowUtils.cpp
@@ -60,22 +60,23 @@
 #include <gdk/gdk.h>
 #include <gdk/gdkx.h>
 #endif
 
 #include "Layers.h"
 #include "mozilla/layers/ShadowLayers.h"
 
 #include "mozilla/dom/Element.h"
+#include "mozilla/dom/file/FileHandle.h"
+#include "mozilla/dom/FileHandleBinding.h"
 #include "mozilla/dom/IDBFactoryBinding.h"
 #include "mozilla/dom/indexedDB/IndexedDatabaseManager.h"
 #include "mozilla/dom/quota/PersistenceType.h"
 #include "mozilla/dom/quota/QuotaManager.h"
 #include "nsDOMBlobBuilder.h"
-#include "nsIDOMFileHandle.h"
 #include "nsPrintfCString.h"
 #include "nsViewportInfo.h"
 #include "nsIFormControl.h"
 #include "nsIScriptError.h"
 #include "nsIAppShell.h"
 #include "nsWidgetsCID.h"
 #include "FrameLayerBuilder.h"
 #include "nsDisplayList.h"
@@ -3018,30 +3019,30 @@ nsDOMWindowUtils::GetFileId(JS::Handle<J
 {
   if (!nsContentUtils::IsCallerChrome()) {
     return NS_ERROR_DOM_SECURITY_ERR;
   }
 
   if (!JSVAL_IS_PRIMITIVE(aFile)) {
     JSObject* obj = JSVAL_TO_OBJECT(aFile);
 
+    file::FileHandle* fileHandle;
+    if (NS_SUCCEEDED(UNWRAP_OBJECT(FileHandle, obj, fileHandle))) {
+      *aResult = fileHandle->GetFileId();
+      return NS_OK;
+    }
+
     nsISupports* nativeObj =
       nsContentUtils::XPConnect()->GetNativeOfWrapper(aCx, obj);
 
     nsCOMPtr<nsIDOMBlob> blob = do_QueryInterface(nativeObj);
     if (blob) {
       *aResult = blob->GetFileId();
       return NS_OK;
     }
-
-    nsCOMPtr<nsIDOMFileHandle> fileHandle = do_QueryInterface(nativeObj);
-    if (fileHandle) {
-      *aResult = fileHandle->GetFileId();
-      return NS_OK;
-    }
   }
 
   *aResult = -1;
   return NS_OK;
 }
 
 NS_IMETHODIMP
 nsDOMWindowUtils::GetFileReferences(const nsAString& aDatabaseName, int64_t aId,
deleted file mode 100644
--- a/dom/file/DOMFileHandle.cpp
+++ /dev/null
@@ -1,66 +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 "DOMFileHandle.h"
-
-#include "nsIFileStreams.h"
-
-#include "nsDOMClassInfoID.h"
-#include "nsNetUtil.h"
-
-#include "File.h"
-#include "LockedFile.h"
-
-USING_FILE_NAMESPACE
-
-// static
-already_AddRefed<DOMFileHandle>
-DOMFileHandle::Create(nsPIDOMWindow* aWindow,
-                      nsIFileStorage* aFileStorage,
-                      nsIFile* aFile)
-{
-  NS_ASSERTION(NS_IsMainThread(), "Wrong thread!");
-
-  nsRefPtr<DOMFileHandle> newFile(new DOMFileHandle(aWindow));
-
-  newFile->mFileStorage = aFileStorage;
-  nsresult rv = aFile->GetLeafName(newFile->mName);
-  NS_ENSURE_SUCCESS(rv, nullptr);
-
-  newFile->mFile = aFile;
-  newFile->mFileName = newFile->mName;
-
-  return newFile.forget();
-}
-
-already_AddRefed<nsISupports>
-DOMFileHandle::CreateStream(nsIFile* aFile, bool aReadOnly)
-{
-  nsresult rv;
-
-  if (aReadOnly) {
-    nsCOMPtr<nsIInputStream> stream;
-    rv = NS_NewLocalFileInputStream(getter_AddRefs(stream), aFile, -1, -1,
-                                    nsIFileInputStream::DEFER_OPEN);
-    NS_ENSURE_SUCCESS(rv, nullptr);
-    return stream.forget();
-  }
-
-  nsCOMPtr<nsIFileStream> stream;
-  rv = NS_NewLocalFileStream(getter_AddRefs(stream), aFile, -1, -1,
-                             nsIFileStream::DEFER_OPEN);
-  NS_ENSURE_SUCCESS(rv, nullptr);
-  return stream.forget();
-}
-
-already_AddRefed<nsIDOMFile>
-DOMFileHandle::CreateFileObject(LockedFile* aLockedFile, uint32_t aFileSize)
-{
-  nsCOMPtr<nsIDOMFile> file = 
-    new File(mName, mType, aFileSize, mFile, aLockedFile);
-
-  return file.forget();
-}
deleted file mode 100644
--- a/dom/file/DOMFileHandle.h
+++ /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/. */
-
-#ifndef mozilla_dom_file_domfilehandle_h__
-#define mozilla_dom_file_domfilehandle_h__
-
-#include "mozilla/Attributes.h"
-#include "FileCommon.h"
-
-#include "FileHandle.h"
-
-BEGIN_FILE_NAMESPACE
-
-class DOMFileHandle : public FileHandle
-{
-public:
-  static already_AddRefed<DOMFileHandle>
-  Create(nsPIDOMWindow* aWindow,
-         nsIFileStorage* aFileStorage,
-         nsIFile* aFile);
-
-  virtual already_AddRefed<nsISupports>
-  CreateStream(nsIFile* aFile, bool aReadOnly) MOZ_OVERRIDE;
-
-  virtual already_AddRefed<nsIDOMFile>
-  CreateFileObject(LockedFile* aLockedFile, uint32_t aFileSize) MOZ_OVERRIDE;
-
-protected:
-  DOMFileHandle(nsPIDOMWindow* aWindow)
-    : FileHandle(aWindow)
-  { }
-
-  ~DOMFileHandle()
-  { }
-};
-
-END_FILE_NAMESPACE
-
-#endif // mozilla_dom_file_domfilehandle_h__
--- a/dom/file/FileHandle.cpp
+++ b/dom/file/FileHandle.cpp
@@ -3,20 +3,22 @@
 /* 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 "FileHandle.h"
 
 #include "nsContentUtils.h"
 #include "nsDOMClassInfoID.h"
+#include "nsNetUtil.h"
 
 #include "nsIDOMFile.h"
 #include "nsIFileStorage.h"
 
+#include "File.h"
 #include "FileRequest.h"
 #include "FileService.h"
 #include "LockedFile.h"
 #include "MetadataHelper.h"
 #include "mozilla/dom/FileHandleBinding.h"
 
 using namespace mozilla;
 using namespace mozilla::dom;
@@ -30,83 +32,105 @@ public:
   GetFileHelper(LockedFile* aLockedFile,
                 FileRequest* aFileRequest,
                 MetadataParameters* aParams,
                 FileHandle* aFileHandle)
   : MetadataHelper(aLockedFile, aFileRequest, aParams),
     mFileHandle(aFileHandle)
   { }
 
-  nsresult
+  virtual nsresult
   GetSuccessResult(JSContext* aCx,
                    JS::MutableHandle<JS::Value> aVal) MOZ_OVERRIDE;
 
-  void
-  ReleaseObjects()
+  virtual void
+  ReleaseObjects() MOZ_OVERRIDE
   {
     mFileHandle = nullptr;
 
     MetadataHelper::ReleaseObjects();
   }
 
 private:
   nsRefPtr<FileHandle> mFileHandle;
 };
 
 } // anonymous namespace
 
 NS_IMPL_CYCLE_COLLECTION_INHERITED_1(FileHandle, nsDOMEventTargetHelper,
                                      mFileStorage)
 
 NS_INTERFACE_MAP_BEGIN_CYCLE_COLLECTION_INHERITED(FileHandle)
-  NS_INTERFACE_MAP_ENTRY(nsIDOMFileHandle)
 NS_INTERFACE_MAP_END_INHERITING(nsDOMEventTargetHelper)
 
 NS_IMPL_ADDREF_INHERITED(FileHandle, nsDOMEventTargetHelper)
 NS_IMPL_RELEASE_INHERITED(FileHandle, nsDOMEventTargetHelper)
 
-NS_IMPL_EVENT_HANDLER(FileHandle, abort)
-NS_IMPL_EVENT_HANDLER(FileHandle, error)
-
-NS_IMETHODIMP
-FileHandle::GetDOMName(nsAString& aName)
+// static
+already_AddRefed<FileHandle>
+FileHandle::Create(nsPIDOMWindow* aWindow,
+                   nsIFileStorage* aFileStorage,
+                   nsIFile* aFile)
 {
-  aName = mName;
-  return NS_OK;
-}
+  MOZ_ASSERT(NS_IsMainThread(), "Wrong thread!");
+
+  nsRefPtr<FileHandle> newFileHandle = new FileHandle(aWindow);
 
-NS_IMETHODIMP
-FileHandle::GetDOMType(nsAString& aType)
-{
-  aType = mType;
-  return NS_OK;
+  newFileHandle->mFileStorage = aFileStorage;
+  nsresult rv = aFile->GetLeafName(newFileHandle->mName);
+  if (NS_WARN_IF(NS_FAILED(rv))) {
+    return nullptr;
+  }
+
+  newFileHandle->mFile = aFile;
+  newFileHandle->mFileName = newFileHandle->mName;
+
+  return newFileHandle.forget();
 }
 
-NS_IMETHODIMP
-FileHandle::Open(const nsAString& aMode,
-                 uint8_t aOptionalArgCount,
-                 nsIDOMLockedFile** _retval)
+// virtual
+already_AddRefed<nsISupports>
+FileHandle::CreateStream(nsIFile* aFile, bool aReadOnly)
 {
-  FileMode mode;
-  if (aOptionalArgCount) {
-    if (aMode.EqualsLiteral("readwrite")) {
-      mode = FileMode::Readwrite;
-    } else if (aMode.EqualsLiteral("readonly")) {
-      mode = FileMode::Readonly;
-    } else {
-      return NS_ERROR_TYPE_ERR;
+  nsresult rv;
+
+  if (aReadOnly) {
+    nsCOMPtr<nsIInputStream> stream;
+    rv = NS_NewLocalFileInputStream(getter_AddRefs(stream), aFile, -1, -1,
+                                    nsIFileInputStream::DEFER_OPEN);
+    if (NS_WARN_IF(NS_FAILED(rv))) {
+      return nullptr;
     }
-  } else {
-    mode = FileMode::Readonly;
+    return stream.forget();
   }
 
-  ErrorResult rv;
-  nsCOMPtr<nsIDOMLockedFile> lockedFile = Open(mode, rv);
-  lockedFile.forget(_retval);
-  return rv.ErrorCode();
+  nsCOMPtr<nsIFileStream> stream;
+  rv = NS_NewLocalFileStream(getter_AddRefs(stream), aFile, -1, -1,
+                             nsIFileStream::DEFER_OPEN);
+  if (NS_WARN_IF(NS_FAILED(rv))) {
+    return nullptr;
+  }
+  return stream.forget();
+}
+
+// virtual
+already_AddRefed<nsIDOMFile>
+FileHandle::CreateFileObject(LockedFile* aLockedFile, uint32_t aFileSize)
+{
+  nsCOMPtr<nsIDOMFile> file =
+    new File(mName, mType, aFileSize, mFile, aLockedFile);
+
+  return file.forget();
+}
+
+// virtual
+JSObject*
+FileHandle::WrapObject(JSContext* aCx, JS::Handle<JSObject*> aScope)
+{
+  return FileHandleBinding::Wrap(aCx, aScope, this);
 }
 
 already_AddRefed<nsIDOMLockedFile>
 FileHandle::Open(FileMode aMode, ErrorResult& aError)
 {
   MOZ_ASSERT(NS_IsMainThread());
 
   if (FileService::IsShuttingDown() || mFileStorage->IsShuttingDown()) {
@@ -118,25 +142,16 @@ FileHandle::Open(FileMode aMode, ErrorRe
   if (!lockedFile) {
     aError.Throw(NS_ERROR_DOM_FILEHANDLE_UNKNOWN_ERR);
     return nullptr;
   }
 
   return lockedFile.forget();
 }
 
-NS_IMETHODIMP
-FileHandle::GetFile(nsIDOMDOMRequest** _retval)
-{
-  ErrorResult rv;
-  nsRefPtr<DOMRequest> request = GetFile(rv);
-  request.forget(_retval);
-  return rv.ErrorCode();
-}
-
 already_AddRefed<DOMRequest>
 FileHandle::GetFile(ErrorResult& aError)
 {
   MOZ_ASSERT(NS_IsMainThread());
 
   // Do nothing if the window is closed
   if (!GetOwner()) {
     return nullptr;
@@ -160,41 +175,22 @@ FileHandle::GetFile(ErrorResult& aError)
   if (NS_FAILED(rv)) {
     aError.Throw(NS_ERROR_DOM_FILEHANDLE_UNKNOWN_ERR);
     return nullptr;
   }
 
   return request.forget();
 }
 
-NS_IMETHODIMP_(int64_t)
-FileHandle::GetFileId()
-{
-  return -1;
-}
-
-NS_IMETHODIMP_(mozilla::dom::indexedDB::FileInfo*)
-FileHandle::GetFileInfo()
-{
-  return nullptr;
-}
-
 nsresult
 GetFileHelper::GetSuccessResult(JSContext* aCx,
                                 JS::MutableHandle<JS::Value> aVal)
 {
   nsCOMPtr<nsIDOMFile> domFile =
     mFileHandle->CreateFileObject(mLockedFile, mParams->Size());
 
   JS::Rooted<JSObject*> global(aCx, JS::CurrentGlobalOrNull(aCx));
   nsresult rv =
     nsContentUtils::WrapNative(aCx, global, domFile,
                                &NS_GET_IID(nsIDOMFile), aVal);
   NS_ENSURE_SUCCESS(rv, NS_ERROR_DOM_FILEHANDLE_UNKNOWN_ERR);
   return NS_OK;
 }
-
-/* virtual */
-JSObject*
-FileHandle::WrapObject(JSContext* aCx, JS::Handle<JSObject*> aScope)
-{
-  return FileHandleBinding::Wrap(aCx, aScope, this);
-}
--- a/dom/file/FileHandle.h
+++ b/dom/file/FileHandle.h
@@ -4,113 +4,143 @@
  * 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_filehandle_h__
 #define mozilla_dom_file_filehandle_h__
 
 #include "FileCommon.h"
 
-#include "nsIDOMFileHandle.h"
 #include "nsIFile.h"
 #include "nsIFileStorage.h"
 
 #include "nsDOMEventTargetHelper.h"
 
 #include "mozilla/Attributes.h"
 #include "mozilla/dom/FileModeBinding.h"
 
 class nsIDOMFile;
+class nsIDOMLockedFile;
 class nsIFileStorage;
 class nsPIDOMWindow;
 
 namespace mozilla {
 namespace dom {
 class DOMRequest;
+namespace indexedDB {
+class FileInfo;
+} // namespace indexedDB
 } // namespace dom
 } // namespace mozilla
 
 BEGIN_FILE_NAMESPACE
 
 class FileService;
 class LockedFile;
 class FinishHelper;
 class FileHelper;
 
 /**
- * Must be subclassed. The subclass must implement CreateStream and
- * CreateFileObject. Basically, every file storage implementation provides its
- * own FileHandle implementation (for example IDBFileHandle provides IndexedDB
- * specific implementation).
+ * This class provides a default FileHandle implementation, but it can be also
+ * subclassed. The subclass can override implementation of GetFileId,
+ * GetFileInfo, CreateStream and CreateFileObject.
+ * (for example IDBFileHandle provides IndexedDB specific implementation).
  */
-class FileHandle : public nsDOMEventTargetHelper,
-                   public nsIDOMFileHandle
+class FileHandle : public nsDOMEventTargetHelper
 {
   friend class FileService;
   friend class LockedFile;
   friend class FinishHelper;
   friend class FileHelper;
 
 public:
   NS_DECL_ISUPPORTS_INHERITED
-  NS_DECL_NSIDOMFILEHANDLE
-
-  nsPIDOMWindow* GetParentObject() const
-  {
-    return GetOwner();
-  }
-  virtual JSObject* WrapObject(JSContext* aCx,
-                               JS::Handle<JSObject*> aScope) MOZ_OVERRIDE;
+  NS_DECL_CYCLE_COLLECTION_CLASS_INHERITED(FileHandle, nsDOMEventTargetHelper)
 
-  void GetName(nsString& aName) const
-  {
-    aName = mName;
-  }
-  void GetType(nsString& aType) const
-  {
-    aType = mType;
-  }
-  already_AddRefed<nsIDOMLockedFile> Open(FileMode aMode, ErrorResult& aError);
-  already_AddRefed<DOMRequest> GetFile(ErrorResult& aError);
-  IMPL_EVENT_HANDLER(abort)
-  IMPL_EVENT_HANDLER(error)
-
-  NS_DECL_CYCLE_COLLECTION_CLASS_INHERITED(FileHandle, nsDOMEventTargetHelper)
+  static already_AddRefed<FileHandle>
+  Create(nsPIDOMWindow* aWindow,
+         nsIFileStorage* aFileStorage,
+         nsIFile* aFile);
 
   const nsAString&
   Name() const
   {
     return mName;
   }
 
   const nsAString&
   Type() const
   {
     return mType;
   }
 
+  virtual int64_t
+  GetFileId()
+  {
+    return -1;
+  }
+
+  virtual mozilla::dom::indexedDB::FileInfo*
+  GetFileInfo()
+  {
+    return nullptr;
+  }
+
   virtual already_AddRefed<nsISupports>
-  CreateStream(nsIFile* aFile, bool aReadOnly) = 0;
+  CreateStream(nsIFile* aFile, bool aReadOnly);
 
   virtual already_AddRefed<nsIDOMFile>
-  CreateFileObject(LockedFile* aLockedFile, uint32_t aFileSize) = 0;
+  CreateFileObject(LockedFile* aLockedFile, uint32_t aFileSize);
+
+  // nsWrapperCache
+  virtual JSObject*
+  WrapObject(JSContext* aCx, JS::Handle<JSObject*> aScope) MOZ_OVERRIDE;
+
+  // WebIDL
+  nsPIDOMWindow*
+  GetParentObject() const
+  {
+    return GetOwner();
+  }
+
+  void
+  GetName(nsString& aName) const
+  {
+    aName = mName;
+  }
+
+  void
+  GetType(nsString& aType) const
+  {
+    aType = mType;
+  }
+
+  already_AddRefed<nsIDOMLockedFile>
+  Open(FileMode aMode, ErrorResult& aError);
+
+  already_AddRefed<DOMRequest>
+  GetFile(ErrorResult& aError);
+
+  IMPL_EVENT_HANDLER(abort)
+  IMPL_EVENT_HANDLER(error)
 
 protected:
   FileHandle(nsPIDOMWindow* aWindow)
     : nsDOMEventTargetHelper(aWindow)
   {
   }
 
   FileHandle(nsDOMEventTargetHelper* aOwner)
     : nsDOMEventTargetHelper(aOwner)
   {
   }
 
   ~FileHandle()
-  { }
+  {
+  }
 
   nsCOMPtr<nsIFileStorage> mFileStorage;
 
   nsString mName;
   nsString mType;
 
   nsCOMPtr<nsIFile> mFile;
   nsString mFileName;
--- a/dom/file/LockedFile.cpp
+++ b/dom/file/LockedFile.cpp
@@ -453,19 +453,19 @@ LockedFile::IsOpen() const
       return true;
     }
   }
 
   return false;
 }
 
 NS_IMETHODIMP
-LockedFile::GetFileHandle(nsIDOMFileHandle** aFileHandle)
+LockedFile::GetFileHandle(nsISupports** aFileHandle)
 {
-  nsCOMPtr<nsIDOMFileHandle> result(mFileHandle);
+  nsCOMPtr<nsISupports> result(mFileHandle);
   result.forget(aFileHandle);
   return NS_OK;
 }
 
 NS_IMETHODIMP
 LockedFile::GetMode(nsAString& aMode)
 {
   NS_ASSERTION(NS_IsMainThread(), "Wrong thread!");
--- a/dom/file/moz.build
+++ b/dom/file/moz.build
@@ -2,50 +2,47 @@
 # vim: set filetype=python:
 # 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/.
 
 TEST_DIRS += ['test']
 
 XPIDL_SOURCES += [
-    'nsIDOMFileHandle.idl',
     'nsIDOMLockedFile.idl',
 ]
 
 XPIDL_MODULE = 'dom_file'
 
 EXPORTS += [
     'nsIFileStorage.h',
 ]
 
 EXPORTS.mozilla.dom.file += [
     'ArchiveEvent.h',
     'ArchiveReader.h',
     'ArchiveRequest.h',
     'ArchiveZipEvent.h',
     'ArchiveZipFile.h',
-    'DOMFileHandle.h',
     'DOMFileRequest.h',
     'File.h',
     'FileCommon.h',
     'FileHandle.h',
     'FileHelper.h',
     'FileService.h',
     'LockedFile.h',
 ]
 
 UNIFIED_SOURCES += [
     'ArchiveEvent.cpp',
     'ArchiveReader.cpp',
     'ArchiveRequest.cpp',
     'ArchiveZipEvent.cpp',
     'ArchiveZipFile.cpp',
     'AsyncHelper.cpp',
-    'DOMFileHandle.cpp',
     'DOMFileRequest.cpp',
     'File.cpp',
     'FileHandle.cpp',
     'FileHelper.cpp',
     'FileRequest.cpp',
     'FileService.cpp',
     'FileStreamWrappers.cpp',
     'LockedFile.cpp',
deleted file mode 100644
--- a/dom/file/nsIDOMFileHandle.idl
+++ /dev/null
@@ -1,53 +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 "nsISupports.idl"
-
-%{C++
-namespace mozilla {
-namespace dom {
-namespace indexedDB {
-class FileInfo;
-}
-}
-}
-%}
-
-[ptr] native FileInfo(mozilla::dom::indexedDB::FileInfo);
-
-interface nsIDOMDOMRequest;
-interface nsIDOMEventListener;
-interface nsIDOMLockedFile;
-
-[scriptable, builtinclass, uuid(47438729-7f3f-4a66-b6d4-d1297c593d46)]
-interface nsIDOMFileHandle : nsISupports
-{
-  [binaryname(DOMName)]
-  readonly attribute DOMString name;
-
-  [binaryname(DOMType)]
-  readonly attribute DOMString type;
-
-  // mode can be either "readonly" or "readwrite"
-  [optional_argc]
-  nsIDOMLockedFile
-  open([optional /* "readonly" */] in DOMString mode);
-
-  nsIDOMDOMRequest
-  getFile();
-
-  [notxpcom]
-  long long
-  getFileId();
-
-  [notxpcom]
-  FileInfo
-  getFileInfo();
-
-  [implicit_jscontext] attribute jsval onabort;
-
-  [implicit_jscontext] attribute jsval onerror;
-};
--- a/dom/file/nsIDOMLockedFile.idl
+++ b/dom/file/nsIDOMLockedFile.idl
@@ -2,22 +2,21 @@
 /* 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 "nsISupports.idl"
 
 interface nsIDOMEventListener;
-interface nsIDOMFileHandle;
 
 [scriptable, builtinclass, uuid(a09cdc35-6b1e-42ce-95bb-f8f10a354202)]
 interface nsIDOMLockedFile : nsISupports
 {
-  readonly attribute nsIDOMFileHandle fileHandle;
+  readonly attribute nsISupports /* FileHandle */ fileHandle;
 
   // "readonly" or "readwrite"
   readonly attribute DOMString mode;
 
   readonly attribute boolean active;
 
   [implicit_jscontext]
   attribute jsval location;
--- a/dom/indexedDB/IDBDatabase.cpp
+++ b/dom/indexedDB/IDBDatabase.cpp
@@ -948,11 +948,10 @@ CreateFileHelper::DoDatabaseWork(mozISto
 nsresult
 CreateFileHelper::GetSuccessResult(JSContext* aCx,
                                    JS::MutableHandle<JS::Value> aVal)
 {
   nsRefPtr<IDBFileHandle> fileHandle =
     IDBFileHandle::Create(mDatabase, mName, mType, mFileInfo.forget());
   IDB_ENSURE_TRUE(fileHandle, NS_ERROR_DOM_INDEXEDDB_UNKNOWN_ERR);
 
-  return WrapNative(aCx, NS_ISUPPORTS_CAST(nsIDOMFileHandle*, fileHandle),
-                    aVal);
+  return WrapNative(aCx, NS_ISUPPORTS_CAST(EventTarget*, fileHandle), aVal);
 }
--- a/dom/indexedDB/IDBFileHandle.cpp
+++ b/dom/indexedDB/IDBFileHandle.cpp
@@ -35,23 +35,16 @@ GetFileFor(FileInfo* aFileInfo)
 
 } // anonymous namespace
 
 IDBFileHandle::IDBFileHandle(IDBDatabase* aOwner)
   : FileHandle(aOwner)
 {
 }
 
-// virtual
-JSObject*
-IDBFileHandle::WrapObject(JSContext* aCx, JS::Handle<JSObject*> aScope)
-{
-  return IDBFileHandleBinding::Wrap(aCx, aScope, this);
-}
-
 // static
 already_AddRefed<IDBFileHandle>
 IDBFileHandle::Create(IDBDatabase* aDatabase,
                       const nsAString& aName,
                       const nsAString& aType,
                       already_AddRefed<FileInfo> aFileInfo)
 {
   NS_ASSERTION(NS_IsMainThread(), "Wrong thread!");
@@ -108,16 +101,23 @@ IDBFileHandle::CreateFileObject(mozilla:
                                 uint32_t aFileSize)
 {
   nsCOMPtr<nsIDOMFile> file = new mozilla::dom::file::File(
     mName, mType, aFileSize, mFile, aLockedFile, mFileInfo);
 
   return file.forget();
 }
 
+// virtual
+JSObject*
+IDBFileHandle::WrapObject(JSContext* aCx, JS::Handle<JSObject*> aScope)
+{
+  return IDBFileHandleBinding::Wrap(aCx, aScope, this);
+}
+
 IDBDatabase*
 IDBFileHandle::Database()
 {
   NS_ASSERTION(NS_IsMainThread(), "Wrong thread!");
 
   IDBDatabase* database = static_cast<IDBDatabase*>(mFileStorage.get());
   MOZ_ASSERT(database);
 
--- a/dom/indexedDB/IDBFileHandle.h
+++ b/dom/indexedDB/IDBFileHandle.h
@@ -13,49 +13,55 @@
 #include "mozilla/dom/indexedDB/FileInfo.h"
 
 BEGIN_INDEXEDDB_NAMESPACE
 
 class IDBDatabase;
 
 class IDBFileHandle : public file::FileHandle
 {
+  typedef mozilla::dom::file::LockedFile LockedFile;
+
 public:
-  virtual JSObject*
-  WrapObject(JSContext* aCx, JS::Handle<JSObject*> aScope) MOZ_OVERRIDE;
+  static already_AddRefed<IDBFileHandle>
+  Create(IDBDatabase* aDatabase, const nsAString& aName,
+         const nsAString& aType, already_AddRefed<FileInfo> aFileInfo);
 
-  NS_IMETHOD_(int64_t)
-  GetFileId()
+
+  virtual int64_t
+  GetFileId() MOZ_OVERRIDE
   {
     return mFileInfo->Id();
   }
 
-  NS_IMETHOD_(FileInfo*)
-  GetFileInfo()
+  virtual FileInfo*
+  GetFileInfo() MOZ_OVERRIDE
   {
     return mFileInfo;
   }
 
-  static already_AddRefed<IDBFileHandle>
-  Create(IDBDatabase* aDatabase, const nsAString& aName,
-         const nsAString& aType, already_AddRefed<FileInfo> aFileInfo);
-
   virtual already_AddRefed<nsISupports>
-  CreateStream(nsIFile* aFile, bool aReadOnly);
+  CreateStream(nsIFile* aFile, bool aReadOnly) MOZ_OVERRIDE;
 
   virtual already_AddRefed<nsIDOMFile>
-  CreateFileObject(file::LockedFile* aLockedFile, uint32_t aFileSize);
+  CreateFileObject(LockedFile* aLockedFile, uint32_t aFileSize) MOZ_OVERRIDE;
 
+  // nsWrapperCache
+  virtual JSObject*
+  WrapObject(JSContext* aCx, JS::Handle<JSObject*> aScope) MOZ_OVERRIDE;
+
+  // WebIDL
   IDBDatabase*
   Database();
 
 private:
   IDBFileHandle(IDBDatabase* aOwner);
 
   ~IDBFileHandle()
-  { }
+  {
+  }
 
   nsRefPtr<FileInfo> mFileInfo;
 };
 
 END_INDEXEDDB_NAMESPACE
 
 #endif // mozilla_dom_indexeddb_idbfilehandle_h__
--- a/dom/indexedDB/IDBObjectStore.cpp
+++ b/dom/indexedDB/IDBObjectStore.cpp
@@ -775,29 +775,21 @@ public:
   {
     MOZ_ASSERT(NS_IsMainThread());
 
     nsRefPtr<FileInfo>& fileInfo = aFile.mFileInfo;
 
     nsRefPtr<IDBFileHandle> fileHandle = IDBFileHandle::Create(aDatabase,
       aData.name, aData.type, fileInfo.forget());
 
-    JS::Rooted<JS::Value> wrappedFileHandle(aCx);
     JS::Rooted<JSObject*> global(aCx, JS::CurrentGlobalOrNull(aCx));
-    nsresult rv =
-      nsContentUtils::WrapNative(aCx, global,
-                                 static_cast<nsIDOMFileHandle*>(fileHandle),
-                                 &NS_GET_IID(nsIDOMFileHandle),
-                                 &wrappedFileHandle);
-    if (NS_FAILED(rv)) {
-      NS_WARNING("Failed to wrap native!");
+    if (!global) {
       return nullptr;
     }
-
-    return JSVAL_TO_OBJECT(wrappedFileHandle);
+    return fileHandle->WrapObject(aCx, global);
   }
 
   static JSObject* CreateAndWrapBlobOrFile(JSContext* aCx,
                                            IDBDatabase* aDatabase,
                                            StructuredCloneFile& aFile,
                                            const BlobOrFileData& aData)
   {
     MOZ_ASSERT(NS_IsMainThread());