Bug 975696 - Split ArchiveReader and FileHandle implementation into separate dirs. r=bent f=baku
authorJan Varga <jan.varga@gmail.com>
Wed, 07 May 2014 16:32:12 +0200
changeset 201268 03fdda1af1f4fc0bdf7bd71c765b89216a5a2737
parent 201267 e8b73142e2e86680ab5adcb0a8b858617ac6f1b3
child 201269 ef60f8aa9a017213edff0e6413b43c4eed15e66b
push id3741
push userasasaki@mozilla.com
push dateMon, 21 Jul 2014 20:25:18 +0000
treeherdermozilla-beta@4d6f46f5af68 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersbent
bugs975696
milestone32.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 975696 - Split ArchiveReader and FileHandle implementation into separate dirs. r=bent f=baku
dom/archivereader/ArchiveEvent.cpp
dom/archivereader/ArchiveEvent.h
dom/archivereader/ArchiveReader.cpp
dom/archivereader/ArchiveReader.h
dom/archivereader/ArchiveReaderCommon.h
dom/archivereader/ArchiveRequest.cpp
dom/archivereader/ArchiveRequest.h
dom/archivereader/ArchiveZipEvent.cpp
dom/archivereader/ArchiveZipEvent.h
dom/archivereader/ArchiveZipFile.cpp
dom/archivereader/ArchiveZipFile.h
dom/archivereader/moz.build
dom/archivereader/test/helpers.js
dom/archivereader/test/mochitest.ini
dom/archivereader/test/moz.build
dom/archivereader/test/test_basic.html
dom/archivereader/test/test_nonUnicode.html
dom/archivereader/test/test_zip_in_zip.html
dom/base/nsDOMWindowUtils.cpp
dom/base/test/mochitest.ini
dom/base/test/test_bug793311.html
dom/bindings/Bindings.conf
dom/file/ArchiveEvent.cpp
dom/file/ArchiveEvent.h
dom/file/ArchiveReader.cpp
dom/file/ArchiveReader.h
dom/file/ArchiveRequest.cpp
dom/file/ArchiveRequest.h
dom/file/ArchiveZipEvent.cpp
dom/file/ArchiveZipEvent.h
dom/file/ArchiveZipFile.cpp
dom/file/ArchiveZipFile.h
dom/file/AsyncHelper.cpp
dom/file/AsyncHelper.h
dom/file/File.cpp
dom/file/File.h
dom/file/FileCommon.h
dom/file/FileHandle.cpp
dom/file/FileHandle.h
dom/file/FileHelper.cpp
dom/file/FileHelper.h
dom/file/FileRequest.cpp
dom/file/FileRequest.h
dom/file/FileService.cpp
dom/file/FileService.h
dom/file/FileStreamWrappers.cpp
dom/file/FileStreamWrappers.h
dom/file/LockedFile.cpp
dom/file/LockedFile.h
dom/file/MemoryStreams.cpp
dom/file/MemoryStreams.h
dom/file/MetadataHelper.cpp
dom/file/MetadataHelper.h
dom/file/moz.build
dom/file/nsIFileStorage.h
dom/file/test/dummy_worker.js
dom/file/test/helpers.js
dom/file/test/mochitest.ini
dom/file/test/moz.build
dom/file/test/test_append_read_data.html
dom/file/test/test_archivereader.html
dom/file/test/test_archivereader_nonUnicode.html
dom/file/test/test_archivereader_zip_in_zip.html
dom/file/test/test_bug_793311.html
dom/file/test/test_getFile.html
dom/file/test/test_getFileId.html
dom/file/test/test_location.html
dom/file/test/test_lockedfile_lifetimes.html
dom/file/test/test_lockedfile_lifetimes_nested.html
dom/file/test/test_lockedfile_ordering.html
dom/file/test/test_overlapping_lockedfiles.html
dom/file/test/test_progress_events.html
dom/file/test/test_readonly_lockedfiles.html
dom/file/test/test_request_readyState.html
dom/file/test/test_stream_tracking.html
dom/file/test/test_success_events_after_abort.html
dom/file/test/test_truncate.html
dom/file/test/test_workers.html
dom/file/test/test_write_read_data.html
dom/filehandle/AsyncHelper.cpp
dom/filehandle/AsyncHelper.h
dom/filehandle/File.cpp
dom/filehandle/File.h
dom/filehandle/FileHandle.cpp
dom/filehandle/FileHandle.h
dom/filehandle/FileHelper.cpp
dom/filehandle/FileHelper.h
dom/filehandle/FileRequest.cpp
dom/filehandle/FileRequest.h
dom/filehandle/FileService.cpp
dom/filehandle/FileService.h
dom/filehandle/FileStreamWrappers.cpp
dom/filehandle/FileStreamWrappers.h
dom/filehandle/LockedFile.cpp
dom/filehandle/LockedFile.h
dom/filehandle/MemoryStreams.cpp
dom/filehandle/MemoryStreams.h
dom/filehandle/MetadataHelper.cpp
dom/filehandle/MetadataHelper.h
dom/filehandle/moz.build
dom/filehandle/nsIFileStorage.h
dom/filehandle/test/dummy_worker.js
dom/filehandle/test/helpers.js
dom/filehandle/test/mochitest.ini
dom/filehandle/test/moz.build
dom/filehandle/test/test_append_read_data.html
dom/filehandle/test/test_getFile.html
dom/filehandle/test/test_getFileId.html
dom/filehandle/test/test_location.html
dom/filehandle/test/test_lockedfile_lifetimes.html
dom/filehandle/test/test_lockedfile_lifetimes_nested.html
dom/filehandle/test/test_lockedfile_ordering.html
dom/filehandle/test/test_overlapping_lockedfiles.html
dom/filehandle/test/test_progress_events.html
dom/filehandle/test/test_readonly_lockedfiles.html
dom/filehandle/test/test_request_readyState.html
dom/filehandle/test/test_stream_tracking.html
dom/filehandle/test/test_success_events_after_abort.html
dom/filehandle/test/test_truncate.html
dom/filehandle/test/test_workers.html
dom/filehandle/test/test_write_read_data.html
dom/indexedDB/IDBFileHandle.cpp
dom/indexedDB/IDBFileHandle.h
dom/indexedDB/IDBObjectStore.cpp
dom/moz.build
dom/quota/QuotaManager.cpp
rename from dom/file/ArchiveEvent.cpp
rename to dom/archivereader/ArchiveEvent.cpp
--- a/dom/file/ArchiveEvent.cpp
+++ b/dom/archivereader/ArchiveEvent.cpp
@@ -4,17 +4,17 @@
  * 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 "ArchiveEvent.h"
 
 #include "nsCExternalHandlerService.h"
 #include "nsProxyRelease.h"
 
-USING_FILE_NAMESPACE
+USING_ARCHIVEREADER_NAMESPACE
 
 NS_IMPL_ISUPPORTS0(ArchiveItem)
 
 ArchiveItem::ArchiveItem()
 {
   MOZ_COUNT_CTOR(ArchiveItem);
 }
 
rename from dom/file/ArchiveEvent.h
rename to dom/archivereader/ArchiveEvent.h
--- a/dom/file/ArchiveEvent.h
+++ b/dom/archivereader/ArchiveEvent.h
@@ -1,26 +1,26 @@
 /* -*- 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_domarchiveevent_h__
-#define mozilla_dom_file_domarchiveevent_h__
+#ifndef mozilla_dom_archivereader_domarchiveevent_h__
+#define mozilla_dom_archivereader_domarchiveevent_h__
 
 #include "ArchiveReader.h"
 
 #include "nsISeekableStream.h"
 #include "nsIMIMEService.h"
 #include "nsDOMFile.h"
 
-#include "FileCommon.h"
+#include "ArchiveReaderCommon.h"
 
-BEGIN_FILE_NAMESPACE
+BEGIN_ARCHIVEREADER_NAMESPACE
 
 /**
  * This class contains all the info needed for a single item
  * It must contain the implementation of the File() method.
  */
 class ArchiveItem : public nsISupports
 {
 public:
@@ -71,12 +71,11 @@ protected: // data
   ArchiveReader* mArchiveReader;
 
   nsCOMPtr<nsIMIMEService> mMimeService;
 
   nsTArray<nsRefPtr<ArchiveItem> > mFileList; // this must be populated
   nsresult mStatus;
 };
 
-END_FILE_NAMESPACE
+END_ARCHIVEREADER_NAMESPACE
 
-#endif // mozilla_dom_file_domarchiveevent_h__
-
+#endif // mozilla_dom_archivereader_domarchiveevent_h__
rename from dom/file/ArchiveReader.cpp
rename to dom/archivereader/ArchiveReader.cpp
--- a/dom/file/ArchiveReader.cpp
+++ b/dom/archivereader/ArchiveReader.cpp
@@ -14,17 +14,17 @@
 
 #include "mozilla/dom/ArchiveReaderBinding.h"
 #include "mozilla/dom/BindingDeclarations.h"
 #include "mozilla/Preferences.h"
 #include "mozilla/dom/EncodingUtils.h"
 
 using namespace mozilla;
 using namespace mozilla::dom;
-USING_FILE_NAMESPACE
+USING_ARCHIVEREADER_NAMESPACE
 
 /* static */ already_AddRefed<ArchiveReader>
 ArchiveReader::Constructor(const GlobalObject& aGlobal,
                            nsIDOMBlob* aBlob,
                            const ArchiveReaderOptions& aOptions,
                            ErrorResult& aError)
 {
   MOZ_ASSERT(aBlob);
rename from dom/file/ArchiveReader.h
rename to dom/archivereader/ArchiveReader.h
--- a/dom/file/ArchiveReader.h
+++ b/dom/archivereader/ArchiveReader.h
@@ -1,34 +1,34 @@
 /* -*- 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_domarchivereader_h__
-#define mozilla_dom_file_domarchivereader_h__
+#ifndef mozilla_dom_archivereader_domarchivereader_h__
+#define mozilla_dom_archivereader_domarchivereader_h__
 
 #include "nsWrapperCache.h"
 
-#include "FileCommon.h"
+#include "ArchiveReaderCommon.h"
 
 #include "nsCOMArray.h"
 #include "nsIChannel.h"
 #include "nsIDOMFile.h"
 #include "mozilla/Attributes.h"
 
 namespace mozilla {
 namespace dom {
 class ArchiveReaderOptions;
 class GlobalObject;
 } // namespace dom
 } // namespace mozilla
 
-BEGIN_FILE_NAMESPACE
+BEGIN_ARCHIVEREADER_NAMESPACE
 
 class ArchiveRequest;
 
 /**
  * This is the ArchiveReader object
  */
 class ArchiveReader MOZ_FINAL : public nsISupports,
                                 public nsWrapperCache
@@ -102,11 +102,11 @@ protected:
   struct {
     nsTArray<nsCOMPtr<nsIDOMFile> > fileList;
     nsresult status;
   } mData;
 
   nsCString mEncoding;
 };
 
-END_FILE_NAMESPACE
+END_ARCHIVEREADER_NAMESPACE
 
-#endif // mozilla_dom_file_domarchivereader_h__
+#endif // mozilla_dom_archivereader_domarchivereader_h__
new file mode 100644
--- /dev/null
+++ b/dom/archivereader/ArchiveReaderCommon.h
@@ -0,0 +1,25 @@
+/* -*- 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_archivereader_archivereader_h
+#define mozilla_dom_archivereader_archivereader_h
+
+#include "mozilla/DOMEventTargetHelper.h"
+#include "nsAutoPtr.h"
+#include "nsCOMPtr.h"
+#include "nsCycleCollectionParticipant.h"
+#include "nsDebug.h"
+#include "nsString.h"
+#include "nsTArray.h"
+
+#define BEGIN_ARCHIVEREADER_NAMESPACE \
+  namespace mozilla { namespace dom { namespace archivereader {
+#define END_ARCHIVEREADER_NAMESPACE \
+  } /* namespace archivereader */ } /* namespace dom */ } /* namespace mozilla */
+#define USING_ARCHIVEREADER_NAMESPACE \
+  using namespace mozilla::dom::archivereader;
+
+#endif // mozilla_dom_archivereader_archivereadercommon_h
rename from dom/file/ArchiveRequest.cpp
rename to dom/archivereader/ArchiveRequest.cpp
--- a/dom/file/ArchiveRequest.cpp
+++ b/dom/archivereader/ArchiveRequest.cpp
@@ -8,17 +8,17 @@
 
 #include "mozilla/EventDispatcher.h"
 #include "mozilla/dom/ArchiveRequestBinding.h"
 #include "nsContentUtils.h"
 #include "nsCxPusher.h"
 
 using namespace mozilla;
 
-USING_FILE_NAMESPACE
+USING_ARCHIVEREADER_NAMESPACE
 
 /**
  * Class used to make asynchronous the ArchiveRequest.
  */
 class ArchiveRequestEvent : public nsRunnable
 {
 public:
   NS_DECL_NSIRUNNABLE
rename from dom/file/ArchiveRequest.h
rename to dom/archivereader/ArchiveRequest.h
--- a/dom/file/ArchiveRequest.h
+++ b/dom/archivereader/ArchiveRequest.h
@@ -1,28 +1,28 @@
 /* -*- 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_domarchiverequest_h__
-#define mozilla_dom_file_domarchiverequest_h__
+#ifndef mozilla_dom_archivereader_domarchiverequest_h__
+#define mozilla_dom_archivereader_domarchiverequest_h__
 
 #include "mozilla/Attributes.h"
 #include "ArchiveReader.h"
 #include "DOMRequest.h"
 
-#include "FileCommon.h"
+#include "ArchiveReaderCommon.h"
 
 namespace mozilla {
 class EventChainPreVisitor;
 } // namespace mozilla
 
-BEGIN_FILE_NAMESPACE
+BEGIN_ARCHIVEREADER_NAMESPACE
 
 /**
  * This is the ArchiveRequest that handles any operation
  * related to ArchiveReader
  */
 class ArchiveRequest : public mozilla::dom::DOMRequest
 {
 public:
@@ -79,11 +79,11 @@ protected:
     GetFile,
     GetFiles
   } mOperation;
 
   // The filename (needed by GetFile):
   nsString mFilename;
 };
 
-END_FILE_NAMESPACE
+END_ARCHIVEREADER_NAMESPACE
 
-#endif // mozilla_dom_file_domarchiverequest_h__
+#endif // mozilla_dom_archivereader_domarchiverequest_h__
rename from dom/file/ArchiveZipEvent.cpp
rename to dom/archivereader/ArchiveZipEvent.cpp
--- a/dom/file/ArchiveZipEvent.cpp
+++ b/dom/archivereader/ArchiveZipEvent.cpp
@@ -7,17 +7,17 @@
 #include "ArchiveZipEvent.h"
 #include "ArchiveZipFile.h"
 
 #include "nsContentUtils.h"
 #include "nsCExternalHandlerService.h"
 
 using namespace mozilla::dom;
 
-USING_FILE_NAMESPACE
+USING_ARCHIVEREADER_NAMESPACE
 
 #ifndef PATH_MAX
 #  define PATH_MAX 65536 // The filename length is stored in 2 bytes
 #endif
 
 ArchiveZipItem::ArchiveZipItem(const char* aFilename,
                                const ZipCentral& aCentralStruct,
                                const nsACString& aEncoding)
rename from dom/file/ArchiveZipEvent.h
rename to dom/archivereader/ArchiveZipEvent.h
--- a/dom/file/ArchiveZipEvent.h
+++ b/dom/archivereader/ArchiveZipEvent.h
@@ -1,24 +1,24 @@
 /* -*- 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_domarchivezipevent_h__
-#define mozilla_dom_file_domarchivezipevent_h__
+#ifndef mozilla_dom_archivereader_domarchivezipevent_h__
+#define mozilla_dom_archivereader_domarchivezipevent_h__
 
 #include "mozilla/Attributes.h"
 #include "ArchiveEvent.h"
 
-#include "FileCommon.h"
+#include "ArchiveReaderCommon.h"
 #include "zipstruct.h"
 
-BEGIN_FILE_NAMESPACE
+BEGIN_ARCHIVEREADER_NAMESPACE
 
 /**
  * ArchiveZipItem - ArchiveItem for ArchiveReaderZipEvent
  */
 class ArchiveZipItem : public ArchiveItem
 {
 public:
   ArchiveZipItem(const char* aFilename,
@@ -57,12 +57,11 @@ public:
                         const nsACString& aEncoding);
 
   nsresult Exec() MOZ_OVERRIDE;
 
 private:
   nsCString mEncoding;
 };
 
-END_FILE_NAMESPACE
+END_ARCHIVEREADER_NAMESPACE
 
-#endif // mozilla_dom_file_domarchivezipevent_h__
-
+#endif // mozilla_dom_archivereader_domarchivezipevent_h__
rename from dom/file/ArchiveZipFile.cpp
rename to dom/archivereader/ArchiveZipFile.cpp
--- a/dom/file/ArchiveZipFile.cpp
+++ b/dom/archivereader/ArchiveZipFile.cpp
@@ -6,17 +6,17 @@
 
 #include "ArchiveZipFile.h"
 #include "ArchiveZipEvent.h"
 
 #include "nsIInputStream.h"
 #include "zlib.h"
 #include "mozilla/Attributes.h"
 
-USING_FILE_NAMESPACE
+USING_ARCHIVEREADER_NAMESPACE
 
 #define ZIP_CHUNK 16384
 
 /**
  * Input stream object for zip files
  */
 class ArchiveInputStream MOZ_FINAL : public nsIInputStream,
                                      public nsISeekableStream
rename from dom/file/ArchiveZipFile.h
rename to dom/archivereader/ArchiveZipFile.h
--- a/dom/file/ArchiveZipFile.h
+++ b/dom/archivereader/ArchiveZipFile.h
@@ -1,26 +1,26 @@
 /* -*- 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_domarchivefile_h__
-#define mozilla_dom_file_domarchivefile_h__
+#ifndef mozilla_dom_archivereader_domarchivefile_h__
+#define mozilla_dom_archivereader_domarchivefile_h__
 
 #include "mozilla/Attributes.h"
 #include "nsDOMFile.h"
 
 #include "ArchiveReader.h"
 
-#include "FileCommon.h"
+#include "ArchiveReaderCommon.h"
 #include "zipstruct.h"
 
-BEGIN_FILE_NAMESPACE
+BEGIN_ARCHIVEREADER_NAMESPACE
 
 /**
  * ZipFile to DOMFileCC
  */
 class ArchiveZipFile : public nsDOMFileCC
 {
 public:
   ArchiveZipFile(const nsAString& aName,
@@ -70,11 +70,11 @@ protected:
 
 private: // Data
   ZipCentral mCentral;
   nsRefPtr<ArchiveReader> mArchiveReader;
 
   nsString mFilename;
 };
 
-END_FILE_NAMESPACE
+END_ARCHIVEREADER_NAMESPACE
 
-#endif // mozilla_dom_file_domarchivefile_h__
+#endif // mozilla_dom_archivereader_domarchivefile_h__
new file mode 100644
--- /dev/null
+++ b/dom/archivereader/moz.build
@@ -0,0 +1,32 @@
+# -*- Mode: python; c-basic-offset: 4; indent-tabs-mode: nil; tab-width: 40 -*-
+# 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']
+
+EXPORTS.mozilla.dom.archivereader += [
+    'ArchiveEvent.h',
+    'ArchiveReader.h',
+    'ArchiveReaderCommon.h',
+    'ArchiveRequest.h',
+    'ArchiveZipEvent.h',
+    'ArchiveZipFile.h',
+]
+
+UNIFIED_SOURCES += [
+    'ArchiveEvent.cpp',
+    'ArchiveReader.cpp',
+    'ArchiveRequest.cpp',
+    'ArchiveZipEvent.cpp',
+    'ArchiveZipFile.cpp',
+]
+
+FAIL_ON_WARNINGS = True
+
+LOCAL_INCLUDES += [
+    '../base',
+]
+
+FINAL_LIBRARY = 'gklayout'
new file mode 100644
--- /dev/null
+++ b/dom/archivereader/test/helpers.js
@@ -0,0 +1,37 @@
+/**
+ * Any copyright is dedicated to the Public Domain.
+ * http://creativecommons.org/publicdomain/zero/1.0/
+ */
+
+var archiveReaderEnabled = false;
+
+var testGenerator = testSteps();
+
+function runTest()
+{
+  enableArchiveReader();
+
+  SimpleTest.waitForExplicitFinish();
+  testGenerator.next();
+}
+
+function finishTest()
+{
+  resetArchiveReader();
+
+  SimpleTest.executeSoon(function() {
+    testGenerator.close();
+    SimpleTest.finish();
+  });
+}
+
+function enableArchiveReader()
+{
+  archiveReaderEnabled = SpecialPowers.getBoolPref("dom.archivereader.enabled");
+  SpecialPowers.setBoolPref("dom.archivereader.enabled", true);
+}
+
+function resetArchiveReader()
+{
+  SpecialPowers.setBoolPref("dom.archivereader.enabled", archiveReaderEnabled);
+}
new file mode 100644
--- /dev/null
+++ b/dom/archivereader/test/mochitest.ini
@@ -0,0 +1,11 @@
+[DEFAULT]
+skip-if = e10s
+support-files =
+  helpers.js
+
+[test_basic.html]
+skip-if = (buildapp == 'b2g' && toolkit == 'gonk')
+[test_nonUnicode.html]
+skip-if = (buildapp == 'b2g' && toolkit == 'gonk')
+[test_zip_in_zip.html]
+skip-if = (buildapp == 'b2g' && toolkit == 'gonk')
new file mode 100644
--- /dev/null
+++ b/dom/archivereader/test/moz.build
@@ -0,0 +1,8 @@
+# -*- Mode: python; c-basic-offset: 4; indent-tabs-mode: nil; tab-width: 40 -*-
+# 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/.
+
+MOCHITEST_MANIFESTS += ['mochitest.ini']
+
rename from dom/file/test/test_archivereader.html
rename to dom/archivereader/test/test_basic.html
rename from dom/file/test/test_archivereader_nonUnicode.html
rename to dom/archivereader/test/test_nonUnicode.html
rename from dom/file/test/test_archivereader_zip_in_zip.html
rename to dom/archivereader/test/test_zip_in_zip.html
--- a/dom/base/nsDOMWindowUtils.cpp
+++ b/dom/base/nsDOMWindowUtils.cpp
@@ -59,17 +59,17 @@
 #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/FileHandle.h"
 #include "mozilla/dom/FileHandleBinding.h"
 #include "mozilla/dom/TabChild.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 "nsPrintfCString.h"
@@ -3238,17 +3238,17 @@ nsDOMWindowUtils::GetFileId(JS::Handle<J
 {
   if (!nsContentUtils::IsCallerChrome()) {
     return NS_ERROR_DOM_SECURITY_ERR;
   }
 
   if (!aFile.isPrimitive()) {
     JSObject* obj = aFile.toObjectOrNull();
 
-    file::FileHandle* fileHandle;
+    FileHandle* fileHandle;
     if (NS_SUCCEEDED(UNWRAP_OBJECT(FileHandle, obj, fileHandle))) {
       *aResult = fileHandle->GetFileId();
       return NS_OK;
     }
 
     nsISupports* nativeObj =
       nsContentUtils::XPConnect()->GetNativeOfWrapper(aCx, obj);
 
--- a/dom/base/test/mochitest.ini
+++ b/dom/base/test/mochitest.ini
@@ -6,16 +6,17 @@ support-files =
   iframe_messageChannel_post.html
   file_empty.html
   iframe_postMessage_solidus.html
 
 [test_Image_constructor.html]
 [test_appname_override.html]
 [test_audioWindowUtils.html]
 [test_audioNotification.html]
+[test_bug793311.html]
 [test_bug913761.html]
 [test_bug978522.html]
 [test_bug979109.html]
 [test_bug989665.html]
 [test_clearTimeoutIntervalNoArg.html]
 [test_consoleEmptyStack.html]
 [test_constructor-assignment.html]
 [test_constructor.html]
rename from dom/file/test/test_bug_793311.html
rename to dom/base/test/test_bug793311.html
--- a/dom/file/test/test_bug_793311.html
+++ b/dom/base/test/test_bug793311.html
@@ -1,28 +1,35 @@
+<!DOCTYPE HTML>
+<html>
 <!--
-  Any copyright is dedicated to the Public Domain.
-  http://creativecommons.org/publicdomain/zero/1.0/
+https://bugzilla.mozilla.org/show_bug.cgi?id=793311
 -->
-<html>
 <head>
-  <title>Bug 793311 Test</title>
+  <meta charset="utf-8">
+  <title>Test for Bug 793311</title>
+  <script type="application/javascript" src="/tests/SimpleTest/SimpleTest.js"></script>
+  <link rel="stylesheet" type="text/css" href="/tests/SimpleTest/test.css"/>
+  <script type="application/javascript">
 
-  <script type="text/javascript" src="/tests/SimpleTest/SimpleTest.js"></script>
-  <link rel="stylesheet" type="text/css" href="/tests/SimpleTest/test.css"/>
-
-</head>
-
-<body>
-  <script type="text/javascript;version=1.7">
+  /** Test for Bug {793311} **/
   SimpleTest.waitForExplicitFinish();
 
   try {
     SpecialPowers.DOMWindowUtils.wrapDOMFile(null);
     ok(false, "wrapDOMFile(null) throws an exception");
   } catch(e) {
     ok(true, "wrapDOMFile(null) throws an exception");
   }
   SimpleTest.finish();
+
   </script>
+</head>
+<body>
+<a target="_blank" href="https://bugzilla.mozilla.org/show_bug.cgi?id=793311">Mozilla Bug 793311</a>
+<p id="display"></p>
+<div id="content" style="display: none">
+
+</div>
+<pre id="test">
+</pre>
 </body>
-
 </html>
--- a/dom/bindings/Bindings.conf
+++ b/dom/bindings/Bindings.conf
@@ -93,21 +93,21 @@ DOMInterfaces = {
     'nativeType': 'mozilla::dom::Activity',
 },
 
 'AbstractWorker': {
     'concrete': False
 },
 
 'ArchiveReader': {
-    'nativeType': 'mozilla::dom::file::ArchiveReader',
+    'nativeType': 'mozilla::dom::archivereader::ArchiveReader',
 },
 
 'ArchiveRequest': {
-    'nativeType': 'mozilla::dom::file::ArchiveRequest',
+    'nativeType': 'mozilla::dom::archivereader::ArchiveRequest',
 },
 
 'AudioChannelManager': {
     'nativeType': 'mozilla::dom::system::AudioChannelManager',
     'headerFile': 'AudioChannelManager.h'
 },
 
 'AudioContext': {
@@ -432,17 +432,17 @@ DOMInterfaces = {
 'Exception': {
     'headerFile': 'mozilla/dom/DOMException.h',
     'binaryNames': {
         'message': 'messageMoz',
     },
 },
 
 'FileHandle': {
-    'nativeType': 'mozilla::dom::file::FileHandle'
+    'nativeType': 'mozilla::dom::FileHandle'
 },
 
 'FileList': {
     'nativeType': 'nsDOMFileList',
     'headerFile': 'nsDOMFile.h',
     'resultNotAddRefed': [ 'item' ]
 },
 
@@ -452,17 +452,17 @@ DOMInterfaces = {
 },
 
 'FileReaderSync': {
     'workers': True,
     'wrapperCache': False,
 },
 
 'FileRequest': {
-    'nativeType': 'mozilla::dom::file::FileRequest',
+    'nativeType': 'mozilla::dom::FileRequest',
 },
 
 'FormData': [
 {
     'nativeType': 'nsFormData'
 },
 {
     'workers': True,
@@ -720,17 +720,17 @@ DOMInterfaces = {
     # NOTE: Before you turn on codegen for Location, make sure all the
     # Unforgeable stuff is dealt with.
     'nativeType': 'nsIDOMLocation',
     'skipGen': True,
     'register': False
 },
 
 'LockedFile': {
-    'nativeType': 'mozilla::dom::file::LockedFile',
+    'nativeType': 'mozilla::dom::LockedFile',
 },
 
 'MediaList': {
     'nativeType': 'nsMediaList',
     'headerFile': 'nsIMediaList.h',
 },
 
 'MediaSource': [{
deleted file mode 100644
--- a/dom/file/FileCommon.h
+++ /dev/null
@@ -1,25 +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_filecommon_h__
-#define mozilla_dom_file_filecommon_h__
-
-#include "mozilla/DOMEventTargetHelper.h"
-#include "nsAutoPtr.h"
-#include "nsCOMPtr.h"
-#include "nsCycleCollectionParticipant.h"
-#include "nsDebug.h"
-#include "nsString.h"
-#include "nsTArray.h"
-
-#define BEGIN_FILE_NAMESPACE \
-  namespace mozilla { namespace dom { namespace file {
-#define END_FILE_NAMESPACE \
-  } /* namespace file */ } /* namespace dom */ } /* namespace mozilla */
-#define USING_FILE_NAMESPACE \
-  using namespace mozilla::dom::file;
-
-#endif // mozilla_dom_file_filecommon_h__
rename from dom/file/AsyncHelper.cpp
rename to dom/filehandle/AsyncHelper.cpp
--- a/dom/file/AsyncHelper.cpp
+++ b/dom/filehandle/AsyncHelper.cpp
@@ -1,23 +1,25 @@
 /* -*- 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 "AsyncHelper.h"
 
+#include "FileService.h"
+#include "MainThreadUtils.h"
+#include "nsDebug.h"
+#include "nsIEventTarget.h"
 #include "nsIRequestObserver.h"
-
 #include "nsNetUtil.h"
 
-#include "FileService.h"
-
-USING_FILE_NAMESPACE
+namespace mozilla {
+namespace dom {
 
 NS_IMPL_ISUPPORTS(AsyncHelper, nsIRunnable, nsIRequest)
 
 nsresult
 AsyncHelper::AsyncWork(nsIRequestObserver* aObserver, nsISupports* aCtxt)
 {
   nsresult rv;
 
@@ -119,8 +121,11 @@ AsyncHelper::GetLoadFlags(nsLoadFlags* a
 }
 
 NS_IMETHODIMP
 AsyncHelper::SetLoadFlags(nsLoadFlags aLoadFlags)
 {
   NS_WARNING("Shouldn't be called!");
   return NS_ERROR_NOT_IMPLEMENTED;
 }
+
+} // namespace dom
+} // namespace mozilla
rename from dom/file/AsyncHelper.h
rename to dom/filehandle/AsyncHelper.h
--- a/dom/file/AsyncHelper.h
+++ b/dom/filehandle/AsyncHelper.h
@@ -1,25 +1,25 @@
 /* -*- 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_asynchelper_h__
-#define mozilla_dom_file_asynchelper_h__
+#ifndef mozilla_dom_AsyncHelper_h
+#define mozilla_dom_AsyncHelper_h
 
-#include "FileCommon.h"
-
+#include "nsCOMPtr.h"
 #include "nsIRequest.h"
 #include "nsIRunnable.h"
 
 class nsIRequestObserver;
 
-BEGIN_FILE_NAMESPACE
+namespace mozilla {
+namespace dom {
 
 /**
  * Must be subclassed. The subclass must implement DoStreamWork.
  * Async operations that are not supported in necko (truncate, flush, etc.)
  * should use this helper. Call AsyncWork to invoke the operation.
  */
 class AsyncHelper : public nsIRunnable,
                     public nsIRequest
@@ -46,11 +46,12 @@ protected:
 
 private:
   nsCOMPtr<nsISupports> mStream;
   nsCOMPtr<nsIRequestObserver> mObserver;
 
   nsresult mStatus;
 };
 
-END_FILE_NAMESPACE
+} // namespace dom
+} // namespace mozilla
 
-#endif // mozilla_dom_file_asynchelper_h__
+#endif // mozilla_dom_AsyncHelper_h
rename from dom/file/File.cpp
rename to dom/filehandle/File.cpp
--- a/dom/file/File.cpp
+++ b/dom/filehandle/File.cpp
@@ -2,19 +2,47 @@
 /* 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 "File.h"
 
 #include "LockedFile.h"
+#include "mozilla/Assertions.h"
+#include "nsDebug.h"
 
-USING_FILE_NAMESPACE
-using mozilla::dom::indexedDB::IndexedDatabaseManager;
+namespace mozilla {
+namespace dom {
+
+using indexedDB::IndexedDatabaseManager;
+
+  // Create as a file
+File::File(const nsAString& aName, const nsAString& aContentType,
+           uint64_t aLength, nsIFile* aFile, LockedFile* aLockedFile)
+: nsDOMFileCC(aName, aContentType, aLength),
+  mFile(aFile), mLockedFile(aLockedFile),
+  mWholeFile(true), mStoredFile(false)
+{
+  MOZ_ASSERT(mFile, "Null file!");
+  MOZ_ASSERT(mLockedFile, "Null locked file!");
+}
+
+// Create as a stored file
+File::File(const nsAString& aName, const nsAString& aContentType,
+           uint64_t aLength, nsIFile* aFile, LockedFile* aLockedFile,
+           FileInfo* aFileInfo)
+: nsDOMFileCC(aName, aContentType, aLength),
+  mFile(aFile), mLockedFile(aLockedFile),
+  mWholeFile(true), mStoredFile(true)
+{
+  MOZ_ASSERT(mFile, "Null file!");
+  MOZ_ASSERT(mLockedFile, "Null locked file!");
+  mFileInfos.AppendElement(aFileInfo);
+}
 
 // Create slice
 File::File(const File* aOther, uint64_t aStart, uint64_t aLength,
            const nsAString& aContentType)
 : nsDOMFileCC(aContentType, aOther->mStart + aStart, aLength),
   mFile(aOther->mFile), mLockedFile(aOther->mLockedFile),
   mWholeFile(false), mStoredFile(aOther->mStoredFile)
 {
@@ -31,16 +59,20 @@ File::File(const File* aOther, uint64_t 
       MutexAutoLock lock(IndexedDatabaseManager::FileMutex());
       fileInfo = aOther->GetFileInfo();
     }
 
     mFileInfos.AppendElement(fileInfo);
   }
 }
 
+File::~File()
+{
+}
+
 NS_IMPL_CYCLE_COLLECTION_INHERITED(File, nsDOMFileCC,
                                    mLockedFile)
 
 NS_INTERFACE_MAP_BEGIN_CYCLE_COLLECTION_INHERITED(File)
 NS_INTERFACE_MAP_END_INHERITING(nsDOMFileCC)
 
 NS_IMPL_ADDREF_INHERITED(File, nsDOMFileCC)
 NS_IMPL_RELEASE_INHERITED(File, nsDOMFileCC)
@@ -71,8 +103,11 @@ File::CreateSlice(uint64_t aStart, uint6
 NS_IMETHODIMP
 File::GetMozFullPathInternal(nsAString &aFilename)
 {
   NS_ASSERTION(NS_IsMainThread(), "Wrong thread!");
   NS_ASSERTION(mIsFile, "Should only be called on files");
 
   return mFile->GetPath(aFilename);
 }
+
+} // namespace dom
+} // namespace mozilla
rename from dom/file/File.h
rename to dom/filehandle/File.h
--- a/dom/file/File.h
+++ b/dom/filehandle/File.h
@@ -1,71 +1,57 @@
 /* -*- 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_file_h__
-#define mozilla_dom_file_file_h__
+#ifndef mozilla_dom_File_h
+#define mozilla_dom_File_h
 
 #include "mozilla/Attributes.h"
-#include "FileCommon.h"
-
+#include "nsAutoPtr.h"
+#include "nsCOMPtr.h"
+#include "nsCycleCollectionParticipant.h"
 #include "nsDOMFile.h"
 
-#include "LockedFile.h"
+namespace mozilla {
+namespace dom {
 
-BEGIN_FILE_NAMESPACE
+class LockedFile;
 
 class File : public nsDOMFileCC
 {
 public:
   NS_DECL_ISUPPORTS_INHERITED
 
   NS_DECL_CYCLE_COLLECTION_CLASS_INHERITED(File, nsDOMFileCC)
 
   // Create as a file
   File(const nsAString& aName, const nsAString& aContentType,
-       uint64_t aLength, nsIFile* aFile, LockedFile* aLockedFile)
-  : nsDOMFileCC(aName, aContentType, aLength),
-    mFile(aFile), mLockedFile(aLockedFile),
-    mWholeFile(true), mStoredFile(false)
-  {
-    NS_ASSERTION(mFile, "Null file!");
-    NS_ASSERTION(mLockedFile, "Null locked file!");
-  }
+       uint64_t aLength, nsIFile* aFile, LockedFile* aLockedFile);
 
   // Create as a stored file
   File(const nsAString& aName, const nsAString& aContentType,
        uint64_t aLength, nsIFile* aFile, LockedFile* aLockedFile,
-       FileInfo* aFileInfo)
-  : nsDOMFileCC(aName, aContentType, aLength),
-    mFile(aFile), mLockedFile(aLockedFile),
-    mWholeFile(true), mStoredFile(true)
-  {
-    NS_ASSERTION(mFile, "Null file!");
-    NS_ASSERTION(mLockedFile, "Null locked file!");
-    mFileInfos.AppendElement(aFileInfo);
-  }
+       FileInfo* aFileInfo);
 
   // Overrides
   NS_IMETHOD
   GetMozFullPathInternal(nsAString& aFullPath) MOZ_OVERRIDE;
 
   NS_IMETHOD
   GetInternalStream(nsIInputStream** aStream) MOZ_OVERRIDE;
 
 protected:
   // Create slice
   File(const File* aOther, uint64_t aStart, uint64_t aLength,
        const nsAString& aContentType);
 
-  virtual ~File()
-  { }
+  virtual ~File();
 
   virtual already_AddRefed<nsIDOMBlob>
   CreateSlice(uint64_t aStart, uint64_t aLength,
               const nsAString& aContentType) MOZ_OVERRIDE;
 
   virtual bool
   IsStoredFile() const MOZ_OVERRIDE
   {
@@ -87,11 +73,12 @@ protected:
 private:
   nsCOMPtr<nsIFile> mFile;
   nsRefPtr<LockedFile> mLockedFile;
 
   bool mWholeFile;
   bool mStoredFile;
 };
 
-END_FILE_NAMESPACE
+} // namespace dom
+} // namespace mozilla
 
-#endif // mozilla_dom_file_file_h__
+#endif // mozilla_dom_File_h
rename from dom/file/FileHandle.cpp
rename to dom/filehandle/FileHandle.cpp
--- a/dom/file/FileHandle.cpp
+++ b/dom/filehandle/FileHandle.cpp
@@ -1,33 +1,35 @@
 /* -*- 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 "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/Assertions.h"
 #include "mozilla/dom/FileHandleBinding.h"
+#include "mozilla/ErrorResult.h"
+#include "nsAutoPtr.h"
+#include "nsContentUtils.h"
+#include "nsDebug.h"
+#include "nsError.h"
+#include "nsIDOMFile.h"
+#include "nsIFile.h"
+#include "nsIFileStorage.h"
+#include "nsNetUtil.h"
 
-using namespace mozilla;
-using namespace mozilla::dom;
-USING_FILE_NAMESPACE
+namespace mozilla {
+namespace dom {
 
 namespace {
 
 class GetFileHelper : public MetadataHelper
 {
 public:
   GetFileHelper(LockedFile* aLockedFile,
                 FileRequest* aFileRequest,
@@ -50,16 +52,30 @@ public:
   }
 
 private:
   nsRefPtr<FileHandle> mFileHandle;
 };
 
 } // anonymous namespace
 
+FileHandle::FileHandle(nsPIDOMWindow* aWindow)
+  : DOMEventTargetHelper(aWindow)
+{
+}
+
+FileHandle::FileHandle(DOMEventTargetHelper* aOwner)
+  : DOMEventTargetHelper(aOwner)
+{
+}
+
+FileHandle::~FileHandle()
+{
+}
+
 NS_IMPL_CYCLE_COLLECTION_INHERITED(FileHandle, DOMEventTargetHelper,
                                    mFileStorage)
 
 NS_INTERFACE_MAP_BEGIN_CYCLE_COLLECTION_INHERITED(FileHandle)
 NS_INTERFACE_MAP_END_INHERITING(DOMEventTargetHelper)
 
 NS_IMPL_ADDREF_INHERITED(FileHandle, DOMEventTargetHelper)
 NS_IMPL_RELEASE_INHERITED(FileHandle, DOMEventTargetHelper)
@@ -188,8 +204,11 @@ GetFileHelper::GetSuccessResult(JSContex
   nsCOMPtr<nsIDOMFile> domFile =
     mFileHandle->CreateFileObject(mLockedFile, mParams->Size());
 
   nsresult rv =
     nsContentUtils::WrapNative(aCx, domFile, &NS_GET_IID(nsIDOMFile), aVal);
   NS_ENSURE_SUCCESS(rv, NS_ERROR_DOM_FILEHANDLE_UNKNOWN_ERR);
   return NS_OK;
 }
+
+} // namespace dom
+} // namespace mozilla
rename from dom/file/FileHandle.h
rename to dom/filehandle/FileHandle.h
--- a/dom/file/FileHandle.h
+++ b/dom/filehandle/FileHandle.h
@@ -1,61 +1,62 @@
 /* -*- 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_filehandle_h__
-#define mozilla_dom_file_filehandle_h__
-
-#include "FileCommon.h"
+#ifndef mozilla_dom_FileHandle_h
+#define mozilla_dom_FileHandle_h
 
-#include "nsIFile.h"
-#include "nsIFileStorage.h"
-
+#include "js/TypeDecls.h"
 #include "mozilla/Attributes.h"
+#include "mozilla/dom/FileModeBinding.h"
 #include "mozilla/DOMEventTargetHelper.h"
-#include "mozilla/dom/FileModeBinding.h"
+#include "nsCOMPtr.h"
+#include "nsCycleCollectionParticipant.h"
+#include "nsString.h"
 
 class nsIDOMFile;
+class nsIFile;
 class nsIFileStorage;
 class nsPIDOMWindow;
 
 namespace mozilla {
+
+class ErrorResult;
+
 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;
 
+namespace indexedDB {
+class FileInfo;
+} // namespace indexedDB
+
 /**
  * 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 DOMEventTargetHelper
 {
   friend class FileService;
   friend class LockedFile;
   friend class FinishHelper;
   friend class FileHelper;
 
 public:
   NS_DECL_ISUPPORTS_INHERITED
+
   NS_DECL_CYCLE_COLLECTION_CLASS_INHERITED(FileHandle, DOMEventTargetHelper)
 
   static already_AddRefed<FileHandle>
   Create(nsPIDOMWindow* aWindow,
          nsIFileStorage* aFileStorage,
          nsIFile* aFile);
 
   const nsAString&
@@ -116,34 +117,27 @@ public:
 
   already_AddRefed<DOMRequest>
   GetFile(ErrorResult& aError);
 
   IMPL_EVENT_HANDLER(abort)
   IMPL_EVENT_HANDLER(error)
 
 protected:
-  FileHandle(nsPIDOMWindow* aWindow)
-    : DOMEventTargetHelper(aWindow)
-  {
-  }
+  FileHandle(nsPIDOMWindow* aWindow);
 
-  FileHandle(DOMEventTargetHelper* aOwner)
-    : DOMEventTargetHelper(aOwner)
-  {
-  }
+  FileHandle(DOMEventTargetHelper* aOwner);
 
-  ~FileHandle()
-  {
-  }
+  virtual ~FileHandle();
 
   nsCOMPtr<nsIFileStorage> mFileStorage;
 
   nsString mName;
   nsString mType;
 
   nsCOMPtr<nsIFile> mFile;
   nsString mFileName;
 };
 
-END_FILE_NAMESPACE
+} // namespace dom
+} // namespace mozilla
 
-#endif // mozilla_dom_file_filehandle_h__
+#endif // mozilla_dom_FileHandle_h
rename from dom/file/FileHelper.cpp
rename to dom/filehandle/FileHelper.cpp
--- a/dom/file/FileHelper.cpp
+++ b/dom/filehandle/FileHelper.cpp
@@ -1,28 +1,29 @@
 /* -*- 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 "FileHelper.h"
 
-#include "nsIFileStorage.h"
-
-#include "nsError.h"
-#include "nsProxyRelease.h"
-
 #include "FileHandle.h"
 #include "FileRequest.h"
 #include "FileService.h"
+#include "js/Value.h"
+#include "LockedFile.h"
+#include "MainThreadUtils.h"
+#include "nsDebug.h"
+#include "nsError.h"
+#include "nsIFileStorage.h"
 #include "nsIRequest.h"
-#include "nsThreadUtils.h"
 
-USING_FILE_NAMESPACE
+namespace mozilla {
+namespace dom {
 
 namespace {
 
 LockedFile* gCurrentLockedFile = nullptr;
 
 } // anonymous namespace
 
 FileHelper::FileHelper(LockedFile* aLockedFile,
@@ -224,8 +225,11 @@ FileHelper::OnStreamClose()
 }
 
 void
 FileHelper::OnStreamDestroy()
 {
   NS_ASSERTION(NS_IsMainThread(), "Wrong thread!");
   Finish();
 }
+
+} // namespace dom
+} // namespace mozilla
rename from dom/file/FileHelper.h
rename to dom/filehandle/FileHelper.h
--- a/dom/file/FileHelper.h
+++ b/dom/filehandle/FileHelper.h
@@ -1,24 +1,26 @@
 /* -*- 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_filehelper_h__
-#define mozilla_dom_file_filehelper_h__
+#ifndef mozilla_dom_FileHelper_h
+#define mozilla_dom_FileHelper_h
 
-#include "FileCommon.h"
-
+#include "js/TypeDecls.h"
+#include "nsAutoPtr.h"
+#include "nsCOMPtr.h"
 #include "nsIRequestObserver.h"
 
 class nsIFileStorage;
 
-BEGIN_FILE_NAMESPACE
+namespace mozilla {
+namespace dom {
 
 class FileHelper;
 class FileRequest;
 class FileOutputStreamWrapper;
 class LockedFile;
 
 class FileHelperListener
 {
@@ -89,11 +91,12 @@ protected:
   nsRefPtr<FileHelperListener> mListener;
   nsCOMPtr<nsIRequest> mRequest;
 
 private:
   nsresult mResultCode;
   bool mFinished;
 };
 
-END_FILE_NAMESPACE
+} // namespace dom
+} // namespace mozilla
 
-#endif // mozilla_dom_file_filehelper_h__
+#endif // mozilla_dom_FileHelper_h
rename from dom/file/FileRequest.cpp
rename to dom/filehandle/FileRequest.cpp
--- a/dom/file/FileRequest.cpp
+++ b/dom/filehandle/FileRequest.cpp
@@ -1,28 +1,34 @@
 /* -*- 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 "mozilla/EventDispatcher.h"
+#include "FileHelper.h"
+#include "js/RootingAPI.h"
+#include "jsapi.h"
+#include "LockedFile.h"
+#include "MainThreadUtils.h"
 #include "mozilla/dom/FileRequestBinding.h"
+#include "mozilla/EventDispatcher.h"
+#include "nsCOMPtr.h"
 #include "nsCxPusher.h"
+#include "nsDebug.h"
 #include "nsError.h"
+#include "nsIDOMEvent.h"
 #include "nsIDOMProgressEvent.h"
-#include "nsDOMClassInfoID.h"
-#include "FileHelper.h"
-#include "LockedFile.h"
+#include "nsIScriptContext.h"
+#include "nsLiteralString.h"
 
-using namespace mozilla;
-
-USING_FILE_NAMESPACE
+namespace mozilla {
+namespace dom {
 
 FileRequest::FileRequest(nsPIDOMWindow* aWindow)
   : DOMRequest(aWindow), mWrapAsDOMRequest(false)
 {
   NS_ASSERTION(NS_IsMainThread(), "Wrong thread!");
 }
 
 FileRequest::~FileRequest()
@@ -141,8 +147,11 @@ FileRequest::FireProgressEvent(uint64_t 
   rv = progress->InitProgressEvent(NS_LITERAL_STRING("progress"), false, false,
                                    false, aLoaded, aTotal);
   if (NS_FAILED(rv)) {
     return;
   }
 
   DispatchTrustedEvent(event);
 }
+
+} // namespace dom
+} // namespace mozilla
rename from dom/file/FileRequest.h
rename to dom/filehandle/FileRequest.h
--- a/dom/file/FileRequest.h
+++ b/dom/filehandle/FileRequest.h
@@ -1,35 +1,39 @@
 /* -*- 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_filerequest_h__
-#define mozilla_dom_file_filerequest_h__
-
-#include "mozilla/Attributes.h"
-#include "FileCommon.h"
+#ifndef mozilla_dom_FileRequest_h
+#define mozilla_dom_FileRequest_h
 
 #include "DOMRequest.h"
+#include "js/TypeDecls.h"
+#include "mozilla/Attributes.h"
+#include "nsAutoPtr.h"
+#include "nsCycleCollectionParticipant.h"
+
+class nsPIDOMWindow;
 
 namespace mozilla {
+
 class EventChainPreVisitor;
-} // namespace mozilla
 
-BEGIN_FILE_NAMESPACE
+namespace dom {
 
 class FileHelper;
 class LockedFile;
 
-class FileRequest : public mozilla::dom::DOMRequest
+class FileRequest : public DOMRequest
 {
 public:
   NS_DECL_ISUPPORTS_INHERITED
+
   NS_DECL_CYCLE_COLLECTION_CLASS_INHERITED(FileRequest, DOMRequest)
 
   static already_AddRefed<FileRequest>
   Create(nsPIDOMWindow* aOwner, LockedFile* aLockedFile,
          bool aWrapAsDOMRequest);
 
   // nsIDOMEventTarget
   virtual nsresult
@@ -61,11 +65,12 @@ protected:
   void
   FireProgressEvent(uint64_t aLoaded, uint64_t aTotal);
 
   nsRefPtr<LockedFile> mLockedFile;
 
   bool mWrapAsDOMRequest;
 };
 
-END_FILE_NAMESPACE
+} // namespace dom
+} // namespace mozilla
 
-#endif // mozilla_dom_file_filerequest_h__
+#endif // mozilla_dom_FileRequest_h
rename from dom/file/FileService.cpp
rename to dom/filehandle/FileService.cpp
--- a/dom/file/FileService.cpp
+++ b/dom/filehandle/FileService.cpp
@@ -1,27 +1,29 @@
 /* -*- 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 "FileService.h"
 
-#include "nsIFile.h"
+#include "FileHandle.h"
+#include "LockedFile.h"
+#include "MainThreadUtils.h"
+#include "nsError.h"
+#include "nsIEventTarget.h"
 #include "nsIFileStorage.h"
 #include "nsIObserverService.h"
-#include "nsIStreamTransportService.h"
-
 #include "nsNetCID.h"
+#include "nsServiceManagerUtils.h"
+#include "nsThreadUtils.h"
 
-#include "FileHandle.h"
-#include "FileRequest.h"
-
-USING_FILE_NAMESPACE
+namespace mozilla {
+namespace dom {
 
 namespace {
 
 FileService* gInstance = nullptr;
 bool gShutdown = false;
 
 } // anonymous namespace
 
@@ -390,16 +392,24 @@ FileService::LockedFileQueue::ProcessQue
   mQueue.RemoveElementAt(0);
 
   nsresult rv = mCurrentHelper->AsyncRun(this);
   NS_ENSURE_SUCCESS(rv, rv);
 
   return NS_OK;
 }
 
+FileService::DelayedEnqueueInfo::DelayedEnqueueInfo()
+{
+}
+
+FileService::DelayedEnqueueInfo::~DelayedEnqueueInfo()
+{
+}
+
 FileService::LockedFileQueue*
 FileService::FileStorageInfo::CreateLockedFileQueue(LockedFile* aLockedFile)
 {
   nsRefPtr<LockedFileQueue>* lockedFileQueue =
     mLockedFileQueues.AppendElement();
   *lockedFileQueue = new LockedFileQueue(aLockedFile);
   return lockedFileQueue->get();
 }
@@ -515,8 +525,11 @@ FileService::FileStorageInfo::CollectRun
 
   for (uint32_t index = 0; index < mDelayedEnqueueInfos.Length(); index++) {
     LockedFile* lockedFile = mDelayedEnqueueInfos[index].mLockedFile;
     if (lockedFile->mFileHandle->mFileStorage == aFileStorage) {
       aLockedFiles.AppendElement(lockedFile);
     }
   }
 }
+
+} // namespace dom
+} // namespace mozilla
rename from dom/file/FileService.h
rename to dom/filehandle/FileService.h
--- a/dom/file/FileService.h
+++ b/dom/filehandle/FileService.h
@@ -1,28 +1,37 @@
 /* -*- 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_fileservice_h__
-#define mozilla_dom_file_fileservice_h__
-
-#include "FileCommon.h"
-
-#include "nsIObserver.h"
+#ifndef mozilla_dom_FileService_h
+#define mozilla_dom_FileService_h
 
+#include "mozilla/Attributes.h"
+#include "mozilla/dom/FileHelper.h"
 #include "nsClassHashtable.h"
-#include "mozilla/Attributes.h"
+#include "nsIObserver.h"
+#include "nsAutoPtr.h"
+#include "nsCOMPtr.h"
+#include "nsDebug.h"
+#include "nsHashKeys.h"
+#include "nsTArray.h"
+#include "nsTHashtable.h"
 
-#include "mozilla/dom/file/FileHelper.h"
-#include "mozilla/dom/file/LockedFile.h"
+class nsAString;
+class nsIEventTarget;
+class nsIFileStorage;
+class nsIRunnable;
 
-BEGIN_FILE_NAMESPACE
+namespace mozilla {
+namespace dom {
+
+class LockedFile;
 
 class FileService MOZ_FINAL : public nsIObserver
 {
 public:
   NS_DECL_ISUPPORTS
   NS_DECL_NSIOBSERVER
 
   // Returns a non-owning reference!
@@ -92,16 +101,19 @@ private:
     NS_DECL_OWNINGTHREAD
     nsRefPtr<LockedFile> mLockedFile;
     nsTArray<nsRefPtr<FileHelper> > mQueue;
     nsRefPtr<FileHelper> mCurrentHelper;
   };
 
   struct DelayedEnqueueInfo
   {
+    DelayedEnqueueInfo();
+    ~DelayedEnqueueInfo();
+
     nsRefPtr<LockedFile> mLockedFile;
     nsRefPtr<FileHelper> mFileHelper;
   };
 
   class FileStorageInfo
   {
     friend class FileService;
 
@@ -185,11 +197,12 @@ private:
   bool
   MaybeFireCallback(StoragesCompleteCallback& aCallback);
 
   nsCOMPtr<nsIEventTarget> mStreamTransportTarget;
   nsClassHashtable<nsCStringHashKey, FileStorageInfo> mFileStorageInfos;
   nsTArray<StoragesCompleteCallback> mCompleteCallbacks;
 };
 
-END_FILE_NAMESPACE
+} // namespace dom
+} // namespace mozilla
 
-#endif /* mozilla_dom_file_fileservice_h__ */
+#endif // mozilla_dom_FileService_h
rename from dom/file/FileStreamWrappers.cpp
rename to dom/filehandle/FileStreamWrappers.cpp
--- a/dom/file/FileStreamWrappers.cpp
+++ b/dom/filehandle/FileStreamWrappers.cpp
@@ -1,23 +1,28 @@
 /* -*- 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 "FileStreamWrappers.h"
 
+#include "FileHelper.h"
+#include "MainThreadUtils.h"
+#include "mozilla/Attributes.h"
+#include "nsDebug.h"
+#include "nsError.h"
 #include "nsIFileStorage.h"
+#include "nsIRunnable.h"
 #include "nsISeekableStream.h"
-#include "mozilla/Attributes.h"
+#include "nsThreadUtils.h"
 
-#include "FileHelper.h"
-
-USING_FILE_NAMESPACE
+namespace mozilla {
+namespace dom {
 
 namespace {
 
 class ProgressRunnable MOZ_FINAL : public nsIRunnable
 {
 public:
   NS_DECL_THREADSAFE_ISUPPORTS
   NS_DECL_NSIRUNNABLE
@@ -380,8 +385,11 @@ DestroyRunnable::Run()
 {
   NS_ASSERTION(NS_IsMainThread(), "Wrong thread!");
 
   mFileHelper->OnStreamDestroy();
   mFileHelper = nullptr;
 
   return NS_OK;
 }
+
+} // namespace dom
+} // namespace mozilla
rename from dom/file/FileStreamWrappers.h
rename to dom/filehandle/FileStreamWrappers.h
--- a/dom/file/FileStreamWrappers.h
+++ b/dom/filehandle/FileStreamWrappers.h
@@ -1,23 +1,24 @@
 /* -*- 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_filestreamwrappers_h__
-#define mozilla_dom_file_filestreamwrappers_h__
+#ifndef mozilla_dom_FileStreamWrappers_h
+#define mozilla_dom_FileStreamWrappers_h
 
-#include "FileCommon.h"
-
+#include "nsAutoPtr.h"
+#include "nsCOMPtr.h"
 #include "nsIInputStream.h"
 #include "nsIOutputStream.h"
 
-BEGIN_FILE_NAMESPACE
+namespace mozilla {
+namespace dom {
 
 class FileHelper;
 
 class FileStreamWrapper : public nsISupports
 {
 public:
   NS_DECL_THREADSAFE_ISUPPORTS
 
@@ -68,27 +69,28 @@ private:
 class FileOutputStreamWrapper : public FileStreamWrapper,
                                 public nsIOutputStream
 {
 public:
   NS_DECL_ISUPPORTS_INHERITED
   NS_DECL_NSIOUTPUTSTREAM
 
   FileOutputStreamWrapper(nsISupports* aFileStream,
-                         FileHelper* aFileHelper,
-                         uint64_t aOffset,
-                         uint64_t aLimit,
-                         uint32_t aFlags);
+                          FileHelper* aFileHelper,
+                          uint64_t aOffset,
+                          uint64_t aLimit,
+                          uint32_t aFlags);
 
 protected:
   virtual ~FileOutputStreamWrapper()
   { }
 
 private:
   nsCOMPtr<nsIOutputStream> mOutputStream;
 #ifdef DEBUG
   void* mWriteThread;
 #endif
 };
 
-END_FILE_NAMESPACE
+} // namespace dom
+} // namespace mozilla
 
-#endif // mozilla_dom_file_filestreamwrappers_h__
+#endif // mozilla_dom_FileStreamWrappers_h
rename from dom/file/LockedFile.cpp
rename to dom/filehandle/LockedFile.cpp
--- a/dom/file/LockedFile.cpp
+++ b/dom/filehandle/LockedFile.cpp
@@ -9,36 +9,39 @@
 #include "AsyncHelper.h"
 #include "FileHandle.h"
 #include "FileHelper.h"
 #include "FileRequest.h"
 #include "FileService.h"
 #include "FileStreamWrappers.h"
 #include "MemoryStreams.h"
 #include "MetadataHelper.h"
-#include "mozilla/dom/DOMRequest.h"
 #include "mozilla/dom/EncodingUtils.h"
 #include "mozilla/dom/LockedFileBinding.h"
-#include "mozilla/dom/TypedArray.h"
-#include "mozilla/dom/UnionTypes.h"
 #include "mozilla/EventDispatcher.h"
 #include "nsContentUtils.h"
+#include "nsDebug.h"
 #include "nsError.h"
 #include "nsIAppShell.h"
 #include "nsIDOMEvent.h"
 #include "nsIDOMFile.h"
+#include "nsIEventTarget.h"
 #include "nsIFileStorage.h"
 #include "nsISeekableStream.h"
 #include "nsNetUtil.h"
+#include "nsServiceManagerUtils.h"
+#include "nsString.h"
 #include "nsStringStream.h"
+#include "nsThreadUtils.h"
 #include "nsWidgetsCID.h"
 
 #define STREAM_COPY_BLOCK_SIZE 32768
 
-BEGIN_FILE_NAMESPACE
+namespace mozilla {
+namespace dom {
 
 namespace {
 
 NS_DEFINE_CID(kAppShellCID, NS_APPSHELL_CID);
 
 class ReadHelper : public FileHelper
 {
 public:
@@ -142,17 +145,17 @@ private:
 
   uint64_t mOffset;
 };
 
 class FlushHelper : public FileHelper
 {
 public:
   FlushHelper(LockedFile* aLockedFile,
-               FileRequest* aFileRequest)
+              FileRequest* aFileRequest)
   : FileHelper(aLockedFile, aFileRequest)
   { }
 
   nsresult
   DoAsyncRun(nsISupports* aStream);
 
 private:
   class AsyncFlusher : public AsyncHelper
@@ -191,17 +194,17 @@ private:
   bool mWholeFile;
   uint64_t mStart;
   uint64_t mLength;
 
   nsCOMPtr<nsIInputStream> mStream;
 };
 
 already_AddRefed<nsIDOMEvent>
-CreateGenericEvent(mozilla::dom::EventTarget* aEventOwner,
+CreateGenericEvent(EventTarget* aEventOwner,
                    const nsAString& aType, bool aBubbles, bool aCancelable)
 {
   nsCOMPtr<nsIDOMEvent> event;
   NS_NewDOMEvent(getter_AddRefs(event), aEventOwner, nullptr, nullptr);
   nsresult rv = event->InitEvent(aType, aBubbles, aCancelable);
   NS_ENSURE_SUCCESS(rv, nullptr);
 
   event->SetTrusted(true);
@@ -1053,9 +1056,10 @@ OpenStreamHelper::DoAsyncRun(nsISupports
 
   mStream = mWholeFile ?
     new FileInputStreamWrapper(aStream, this, 0, mLength, flags) :
     new FileInputStreamWrapper(aStream, this, mStart, mLength, flags);
 
   return NS_OK;
 }
 
-END_FILE_NAMESPACE
+} // namespace dom
+} // namespace mozilla
rename from dom/file/LockedFile.h
rename to dom/filehandle/LockedFile.h
--- a/dom/file/LockedFile.h
+++ b/dom/filehandle/LockedFile.h
@@ -1,48 +1,58 @@
 /* -*- 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_lockedfile_h__
-#define mozilla_dom_file_lockedfile_h__
+#ifndef mozilla_dom_LockedFile_h
+#define mozilla_dom_LockedFile_h
 
-#include "FileCommon.h"
+#include "js/TypeDecls.h"
+#include "MainThreadUtils.h"
+#include "mozilla/Assertions.h"
 #include "mozilla/Attributes.h"
+#include "mozilla/dom/BindingDeclarations.h"
+#include "mozilla/dom/FileModeBinding.h"
+#include "mozilla/dom/Nullable.h"
+#include "mozilla/dom/TypedArray.h"
 #include "mozilla/DOMEventTargetHelper.h"
-#include "mozilla/dom/FileModeBinding.h"
-#include "mozilla/dom/TypedArray.h"
+#include "mozilla/ErrorResult.h"
+#include "nsAutoPtr.h"
+#include "nsCOMPtr.h"
+#include "nsCycleCollectionParticipant.h"
 #include "nsIInputStream.h"
 #include "nsIRunnable.h"
+#include "nsTArray.h"
+
+class nsAString;
+class nsIDOMBlob;
+class nsPIDOMWindow;
 
 namespace mozilla {
+
+class EventChainPreVisitor;
+
 namespace dom {
-class DOMFileMetadataParameters;
-class DOMRequest;
-} // namespace dom
-} // namespace mozilla
 
-namespace mozilla {
-class EventChainPreVisitor;
-} // namespace mozilla
-
-BEGIN_FILE_NAMESPACE
-
+class DOMFileMetadataParameters;
 class FileHandle;
+class FileHelper;
 class FileRequest;
+class FileService;
+class FinishHelper;
 class MetadataHelper;
 
 class LockedFile : public DOMEventTargetHelper,
                    public nsIRunnable
 {
-  friend class FinishHelper;
+  friend class FileHelper;
   friend class FileService;
-  friend class FileHelper;
+  friend class FinishHelper;
   friend class MetadataHelper;
 
 public:
   NS_DECL_ISUPPORTS_INHERITED
   NS_DECL_NSIRUNNABLE
 
   NS_DECL_CYCLE_COLLECTION_CLASS_INHERITED(LockedFile, DOMEventTargetHelper)
 
@@ -298,11 +308,12 @@ private:
 
   nsRefPtr<LockedFile> mLockedFile;
   nsTArray<nsCOMPtr<nsISupports> > mParallelStreams;
   nsCOMPtr<nsISupports> mStream;
 
   bool mAborted;
 };
 
-END_FILE_NAMESPACE
+} // namespace dom
+} // namespace mozilla
 
-#endif // mozilla_dom_file_lockedfile_h__
+#endif // mozilla_dom_LockedFile_h
rename from dom/file/MemoryStreams.cpp
rename to dom/filehandle/MemoryStreams.cpp
--- a/dom/file/MemoryStreams.cpp
+++ b/dom/filehandle/MemoryStreams.cpp
@@ -1,19 +1,24 @@
 /* -*- 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 "MemoryStreams.h"
 
+#include "nsAutoPtr.h"
+#include "nsCOMPtr.h"
+#include "nsDebug.h"
+#include "nsError.h"
 #include "nsStreamUtils.h"
 
-USING_FILE_NAMESPACE
+namespace mozilla {
+namespace dom {
 
 // static
 already_AddRefed<MemoryOutputStream>
 MemoryOutputStream::Create(uint64_t aSize)
 {
   NS_ASSERTION(aSize, "Passed zero size!");
 
   NS_ENSURE_TRUE(aSize <= UINT32_MAX, nullptr);
@@ -83,8 +88,11 @@ MemoryOutputStream::WriteSegments(nsRead
 }
 
 NS_IMETHODIMP
 MemoryOutputStream::IsNonBlocking(bool* _retval)
 {
   *_retval = false;
   return NS_OK;
 }
+
+} // namespace dom
+} // namespace mozilla
rename from dom/file/MemoryStreams.h
rename to dom/filehandle/MemoryStreams.h
--- a/dom/file/MemoryStreams.h
+++ b/dom/filehandle/MemoryStreams.h
@@ -1,33 +1,34 @@
 /* -*- 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_memorystreams_h__
-#define mozilla_dom_file_memorystreams_h__
-
-#include "FileCommon.h"
+#ifndef mozilla_dom_MemoryStreams_h
+#define mozilla_dom_MemoryStreams_h
 
 #include "nsIOutputStream.h"
+#include "nsString.h"
 
-BEGIN_FILE_NAMESPACE
+template <class> class already_AddRefed;
+
+namespace mozilla {
+namespace dom {
 
 class MemoryOutputStream : public nsIOutputStream
 {
 public:
   NS_DECL_THREADSAFE_ISUPPORTS
   NS_DECL_NSIOUTPUTSTREAM
 
   static already_AddRefed<MemoryOutputStream>
   Create(uint64_t aSize);
 
-
   const nsCString&
   Data() const
   {
     return mData;
   }
 
 private:
   MemoryOutputStream()
@@ -36,11 +37,12 @@ private:
 
   virtual ~MemoryOutputStream()
   { }
 
   nsCString mData;
   uint64_t mOffset;
 };
 
-END_FILE_NAMESPACE
+} // namespace dom
+} // namespace mozilla
 
-#endif // mozilla_dom_file_memorystreams_h__
+#endif // mozilla_dom_MemoryStreams_h
rename from dom/file/MetadataHelper.cpp
rename to dom/filehandle/MetadataHelper.cpp
--- a/dom/file/MetadataHelper.cpp
+++ b/dom/filehandle/MetadataHelper.cpp
@@ -1,19 +1,27 @@
 /* -*- 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 "MetadataHelper.h"
 
+#include "js/Value.h"
+#include "js/RootingAPI.h"
+#include "jsapi.h"
 #include "LockedFile.h"
+#include "mozilla/dom/FileModeBinding.h"
+#include "nsDebug.h"
+#include "nsIFileStreams.h"
+#include "nsIOutputStream.h"
 
-USING_FILE_NAMESPACE
+namespace mozilla {
+namespace dom {
 
 nsresult
 MetadataHelper::DoAsyncRun(nsISupports* aStream)
 {
   bool readWrite = mLockedFile->mMode == FileMode::Readwrite;
 
   nsRefPtr<AsyncMetadataGetter> getter =
     new AsyncMetadataGetter(aStream, mParams, readWrite);
@@ -89,8 +97,11 @@ MetadataHelper::AsyncMetadataGetter::DoS
     rv = metadata->GetLastModified(&lastModified);
     NS_ENSURE_SUCCESS(rv, rv);
 
     mParams->mLastModified = lastModified;
   }
 
   return NS_OK;
 }
+
+} // namespace dom
+} // namespace mozilla
rename from dom/file/MetadataHelper.h
rename to dom/filehandle/MetadataHelper.h
--- a/dom/file/MetadataHelper.h
+++ b/dom/filehandle/MetadataHelper.h
@@ -1,28 +1,25 @@
 /* -*- 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_metadatahelper_h__
-#define mozilla_dom_file_metadatahelper_h__
-
-#include "mozilla/Attributes.h"
-#include "FileCommon.h"
-
-#include "nsIFileStreams.h"
+#ifndef mozilla_dom_MetadataHelper_h
+#define mozilla_dom_MetadataHelper_h
 
 #include "AsyncHelper.h"
 #include "FileHelper.h"
+#include "js/TypeDecls.h"
+#include "mozilla/Attributes.h"
+#include "nsAutoPtr.h"
 
-class nsIFileStream;
-
-BEGIN_FILE_NAMESPACE
+namespace mozilla {
+namespace dom {
 
 class MetadataHelper;
 
 class MetadataParameters MOZ_FINAL
 {
   friend class MetadataHelper;
 
 public:
@@ -110,11 +107,12 @@ protected:
   private:
     nsRefPtr<MetadataParameters> mParams;
     bool mReadWrite;
   };
 
   nsRefPtr<MetadataParameters> mParams;
 };
 
-END_FILE_NAMESPACE
+} // namespace dom
+} // namespace mozilla
 
-#endif // mozilla_dom_file_metadatahelper_h__
+#endif // mozilla_dom_MetadataHelper_h
rename from dom/file/moz.build
rename to dom/filehandle/moz.build
--- a/dom/file/moz.build
+++ b/dom/filehandle/moz.build
@@ -5,37 +5,26 @@
 # file, You can obtain one at http://mozilla.org/MPL/2.0/.
 
 TEST_DIRS += ['test']
 
 EXPORTS += [
     'nsIFileStorage.h',
 ]
 
-EXPORTS.mozilla.dom.file += [
-    'ArchiveEvent.h',
-    'ArchiveReader.h',
-    'ArchiveRequest.h',
-    'ArchiveZipEvent.h',
-    'ArchiveZipFile.h',
+EXPORTS.mozilla.dom += [
     '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',
     'File.cpp',
     'FileHandle.cpp',
     'FileHelper.cpp',
     'FileRequest.cpp',
     'FileService.cpp',
     'FileStreamWrappers.cpp',
     'LockedFile.cpp',
rename from dom/file/nsIFileStorage.h
rename to dom/filehandle/nsIFileStorage.h
--- a/dom/file/nsIFileStorage.h
+++ b/dom/filehandle/nsIFileStorage.h
@@ -8,16 +8,18 @@
 #define nsIFileStorage_h__
 
 #include "nsISupports.h"
 
 #define NS_FILESTORAGE_IID \
   {0x6278f453, 0xd557, 0x4a55, \
   { 0x99, 0x3e, 0xf4, 0x69, 0xe2, 0xa5, 0xe1, 0xd0 } }
 
+class nsACString;
+
 class nsIFileStorage : public nsISupports
 {
 public:
   NS_DECLARE_STATIC_IID_ACCESSOR(NS_FILESTORAGE_IID)
 
   NS_IMETHOD_(const nsACString&)
   Id() = 0;
 
rename from dom/file/test/dummy_worker.js
rename to dom/filehandle/test/dummy_worker.js
rename from dom/file/test/helpers.js
rename to dom/filehandle/test/helpers.js
--- a/dom/file/test/helpers.js
+++ b/dom/filehandle/test/helpers.js
@@ -8,33 +8,29 @@ const DeviceStorageKey = "DS";
 
 var fileStorages = [
   { key: IndexedDatabaseKey }
 //  { key: DeviceStorageKey }
 ];
 
 var utils = SpecialPowers.getDOMWindowUtils(window);
 
-var archiveReaderEnabled = false;
-
 var testGenerator = testSteps();
 
 function runTest()
 {
   allowUnlimitedQuota();
-  enableArchiveReader();
 
   SimpleTest.waitForExplicitFinish();
   testGenerator.next();
 }
 
 function finishTest()
 {
   resetUnlimitedQuota();
-  resetArchiveReader();
 
   SimpleTest.executeSoon(function() {
     testGenerator.close();
     SimpleTest.finish();
   });
 }
 
 function grabEventAndContinueHandler(event)
@@ -97,27 +93,16 @@ function allowUnlimitedQuota(url)
   addPermission("indexedDB-unlimited", true, url);
 }
 
 function resetUnlimitedQuota(url)
 {
   removePermission("indexedDB-unlimited", url);
 }
 
-function enableArchiveReader()
-{
-  archiveReaderEnabled = SpecialPowers.getBoolPref("dom.archivereader.enabled");
-  SpecialPowers.setBoolPref("dom.archivereader.enabled", true);
-}
-
-function resetArchiveReader()
-{
-  SpecialPowers.setBoolPref("dom.archivereader.enabled", archiveReaderEnabled);
-}
-
 function getFileHandle(fileStorageKey, name)
 {
   var requestService = SpecialPowers.getDOMRequestService();
   var request = requestService.createRequest(window);
 
   switch (fileStorageKey) {
     case IndexedDatabaseKey:
       var dbname = window.location.pathname;
rename from dom/file/test/mochitest.ini
rename to dom/filehandle/test/mochitest.ini
--- a/dom/file/test/mochitest.ini
+++ b/dom/filehandle/test/mochitest.ini
@@ -1,38 +1,31 @@
 [DEFAULT]
 skip-if = e10s
 support-files =
   dummy_worker.js
   helpers.js
 
 [test_append_read_data.html]
 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]
 skip-if = buildapp == 'b2g'
 [test_overlapping_lockedfiles.html]
 skip-if = buildapp == 'b2g'
 [test_progress_events.html]
-skip-if = buildapp == 'b2g' # b2g(All of these fail fairly regularly with: UnknownError: The operation failed for reasons unrelated to the database itself and not covered by any other error code. at http://mochi.test:8888/tests/dom/file/test/helpers.js:126) b2g-debug(All of these fail fairly regularly with: UnknownError: The operation failed for reasons unrelated to the database itself and not covered by any other error code. at http://mochi.test:8888/tests/dom/file/test/helpers.js:126) b2g-desktop(All of these fail fairly regularly with: UnknownError: The operation failed for reasons unrelated to the database itself and not covered by any other error code. at http://mochi.test:8888/tests/dom/file/test/helpers.js:126)
+skip-if = buildapp == 'b2g' # b2g(All of these fail fairly regularly with: UnknownError: The operation failed for reasons unrelated to the database itself and not covered by any other error code. at http://mochi.test:8888/tests/dom/file/test/helpers.js:109) b2g-debug(All of these fail fairly regularly with: UnknownError: The operation failed for reasons unrelated to the database itself and not covered by any other error code. at http://mochi.test:8888/tests/dom/file/test/helpers.js:109) b2g-desktop(All of these fail fairly regularly with: UnknownError: The operation failed for reasons unrelated to the database itself and not covered by any other error code. at http://mochi.test:8888/tests/dom/file/test/helpers.js:109)
 [test_readonly_lockedfiles.html]
 skip-if = buildapp == 'b2g'
 [test_request_readyState.html]
 skip-if = buildapp == 'b2g'
 [test_stream_tracking.html]
 skip-if = buildapp == 'b2g'
 [test_success_events_after_abort.html]
 skip-if = buildapp == 'b2g'
rename from dom/file/test/moz.build
rename to dom/filehandle/test/moz.build
rename from dom/file/test/test_append_read_data.html
rename to dom/filehandle/test/test_append_read_data.html
rename from dom/file/test/test_getFile.html
rename to dom/filehandle/test/test_getFile.html
rename from dom/file/test/test_getFileId.html
rename to dom/filehandle/test/test_getFileId.html
rename from dom/file/test/test_location.html
rename to dom/filehandle/test/test_location.html
rename from dom/file/test/test_lockedfile_lifetimes.html
rename to dom/filehandle/test/test_lockedfile_lifetimes.html
rename from dom/file/test/test_lockedfile_lifetimes_nested.html
rename to dom/filehandle/test/test_lockedfile_lifetimes_nested.html
rename from dom/file/test/test_lockedfile_ordering.html
rename to dom/filehandle/test/test_lockedfile_ordering.html
rename from dom/file/test/test_overlapping_lockedfiles.html
rename to dom/filehandle/test/test_overlapping_lockedfiles.html
rename from dom/file/test/test_progress_events.html
rename to dom/filehandle/test/test_progress_events.html
rename from dom/file/test/test_readonly_lockedfiles.html
rename to dom/filehandle/test/test_readonly_lockedfiles.html
rename from dom/file/test/test_request_readyState.html
rename to dom/filehandle/test/test_request_readyState.html
rename from dom/file/test/test_stream_tracking.html
rename to dom/filehandle/test/test_stream_tracking.html
rename from dom/file/test/test_success_events_after_abort.html
rename to dom/filehandle/test/test_success_events_after_abort.html
rename from dom/file/test/test_truncate.html
rename to dom/filehandle/test/test_truncate.html
rename from dom/file/test/test_workers.html
rename to dom/filehandle/test/test_workers.html
rename from dom/file/test/test_write_read_data.html
rename to dom/filehandle/test/test_write_read_data.html
--- a/dom/indexedDB/IDBFileHandle.cpp
+++ b/dom/indexedDB/IDBFileHandle.cpp
@@ -1,17 +1,17 @@
 /* -*- 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 "IDBFileHandle.h"
 
-#include "mozilla/dom/file/File.h"
+#include "mozilla/dom/File.h"
 #include "mozilla/dom/IDBFileHandleBinding.h"
 #include "mozilla/dom/quota/FileStreams.h"
 
 #include "IDBDatabase.h"
 
 USING_INDEXEDDB_NAMESPACE
 USING_QUOTA_NAMESPACE
 
@@ -92,21 +92,21 @@ IDBFileHandle::CreateStream(nsIFile* aFi
     result = NS_ISUPPORTS_CAST(nsIFileStream*, stream);
   }
   NS_ENSURE_TRUE(result, nullptr);
 
   return result.forget();
 }
 
 already_AddRefed<nsIDOMFile>
-IDBFileHandle::CreateFileObject(mozilla::dom::file::LockedFile* aLockedFile,
+IDBFileHandle::CreateFileObject(mozilla::dom::LockedFile* aLockedFile,
                                 uint32_t aFileSize)
 {
-  nsCOMPtr<nsIDOMFile> file = new mozilla::dom::file::File(
-    mName, mType, aFileSize, mFile, aLockedFile, mFileInfo);
+  nsCOMPtr<nsIDOMFile> file =
+    new File(mName, mType, aFileSize, mFile, aLockedFile, mFileInfo);
 
   return file.forget();
 }
 
 // virtual
 JSObject*
 IDBFileHandle::WrapObject(JSContext* aCx)
 {
--- a/dom/indexedDB/IDBFileHandle.h
+++ b/dom/indexedDB/IDBFileHandle.h
@@ -4,26 +4,26 @@
  * 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_indexeddb_idbfilehandle_h__
 #define mozilla_dom_indexeddb_idbfilehandle_h__
 
 #include "IndexedDatabase.h"
 
-#include "mozilla/dom/file/FileHandle.h"
+#include "mozilla/dom/FileHandle.h"
 #include "mozilla/dom/indexedDB/FileInfo.h"
 
 BEGIN_INDEXEDDB_NAMESPACE
 
 class IDBDatabase;
 
-class IDBFileHandle : public file::FileHandle
+class IDBFileHandle : public FileHandle
 {
-  typedef mozilla::dom::file::LockedFile LockedFile;
+  typedef mozilla::dom::LockedFile LockedFile;
 
 public:
   static already_AddRefed<IDBFileHandle>
   Create(IDBDatabase* aDatabase, const nsAString& aName,
          const nsAString& aType, already_AddRefed<FileInfo> aFileInfo);
 
 
   virtual int64_t
--- a/dom/indexedDB/IDBObjectStore.cpp
+++ b/dom/indexedDB/IDBObjectStore.cpp
@@ -1555,17 +1555,17 @@ IDBObjectStore::StructuredCloneWriteCall
     uint64_t value = 0;
     // Omit endian swap
     return JS_WriteBytes(aWriter, &value, sizeof(value));
   }
 
   IDBTransaction* transaction = cloneWriteInfo->mTransaction;
   FileManager* fileManager = transaction->Database()->Manager();
 
-  file::FileHandle* fileHandle = nullptr;
+  FileHandle* fileHandle = nullptr;
   if (NS_SUCCEEDED(UNWRAP_OBJECT(FileHandle, aObj, fileHandle))) {
     nsRefPtr<FileInfo> fileInfo = fileHandle->GetFileInfo();
 
     // Throw when trying to store non IDB file handles or IDB file handles
     // across databases.
     if (!fileInfo || fileInfo->Manager() != fileManager) {
       return false;
     }
--- a/dom/moz.build
+++ b/dom/moz.build
@@ -33,28 +33,29 @@ interfaces = [
 ]
 
 PARALLEL_DIRS += ['interfaces/' + i for i in interfaces]
 
 PARALLEL_DIRS += [
     'apps',
     'base',
     'activities',
+    'archivereader',
     'bindings',
     'battery',
     'bluetooth',
     'browser-element',
     'contacts',
     'phonenumberutils',
     'alarm',
     'datastore',
     'devicestorage',
     'encoding',
     'events',
-    'file',
+    'filehandle',
     'filesystem',
     'fmradio',
     'asmjscache',
     'media',
     'messages',
     'power',
     'push',
     'quota',
--- a/dom/quota/QuotaManager.cpp
+++ b/dom/quota/QuotaManager.cpp
@@ -16,23 +16,24 @@
 #include "nsIQuotaRequest.h"
 #include "nsIRunnable.h"
 #include "nsISimpleEnumerator.h"
 #include "nsIScriptObjectPrincipal.h"
 #include "nsIScriptSecurityManager.h"
 #include "nsITimer.h"
 #include "nsIURI.h"
 #include "nsIUsageCallback.h"
+#include "nsPIDOMWindow.h"
 
 #include <algorithm>
 #include "GeckoProfiler.h"
 #include "mozilla/Atomics.h"
 #include "mozilla/CondVar.h"
 #include "mozilla/dom/asmjscache/AsmJSCache.h"
-#include "mozilla/dom/file/FileService.h"
+#include "mozilla/dom/FileService.h"
 #include "mozilla/dom/indexedDB/Client.h"
 #include "mozilla/Mutex.h"
 #include "mozilla/LazyIdleThread.h"
 #include "mozilla/Preferences.h"
 #include "mozilla/Services.h"
 #include "nsAppDirectoryServiceDefs.h"
 #include "nsComponentManagerUtils.h"
 #include "nsContentUtils.h"
@@ -84,17 +85,17 @@
 // The name of the file that we use to load/save the last access time of an
 // origin.
 #define METADATA_FILE_NAME ".metadata"
 
 #define PERMISSION_DEFAUT_PERSISTENT_STORAGE "default-persistent-storage"
 
 USING_QUOTA_NAMESPACE
 using namespace mozilla::dom;
-using mozilla::dom::file::FileService;
+using mozilla::dom::FileService;
 
 static_assert(
   static_cast<uint32_t>(StorageType::Persistent) ==
   static_cast<uint32_t>(PERSISTENCE_TYPE_PERSISTENT),
   "Enum values should match.");
 
 static_assert(
   static_cast<uint32_t>(StorageType::Temporary) ==