Bug 910412 - WebIDL and DOM binding for filesystem API. r=baku, r=smaug, f=dhylands, f=jonas

This commit is contained in:
Yuan Xulei 2014-03-05 11:26:39 +08:00
Родитель c291a0c95a
Коммит 4681ab0aeb
10 изменённых файлов: 229 добавлений и 0 удалений

Просмотреть файл

@ -31,6 +31,7 @@ namespace dom {
class DeviceStorageEnumerationParameters;
class DOMCursor;
class DOMRequest;
class Promise;
} // namespace dom
namespace ipc {
class FileDescriptor;
@ -157,6 +158,7 @@ class nsDOMDeviceStorage MOZ_FINAL
EnumerationParameters;
typedef mozilla::dom::DOMCursor DOMCursor;
typedef mozilla::dom::DOMRequest DOMRequest;
typedef mozilla::dom::Promise Promise;
public:
typedef nsTArray<nsString> VolumeNameArray;
@ -255,6 +257,9 @@ public:
// Uses XPCOM GetStorageName
already_AddRefed<Promise>
GetRoot();
static void
CreateDeviceStorageFor(nsPIDOMWindow* aWin,
const nsAString& aType,

Просмотреть файл

@ -12,10 +12,12 @@
#include "mozilla/dom/ContentChild.h"
#include "mozilla/dom/DeviceStorageBinding.h"
#include "mozilla/dom/devicestorage/PDeviceStorageRequestChild.h"
#include "mozilla/dom/Directory.h"
#include "mozilla/dom/ipc/Blob.h"
#include "mozilla/dom/PBrowserChild.h"
#include "mozilla/dom/PContentPermissionRequestChild.h"
#include "mozilla/dom/PermissionMessageUtils.h"
#include "mozilla/dom/Promise.h"
#include "mozilla/LazyIdleThread.h"
#include "mozilla/Preferences.h"
#include "mozilla/Scoped.h"
@ -3917,6 +3919,13 @@ nsDOMDeviceStorage::Default()
return mStorageName.Equals(defaultStorageName);
}
already_AddRefed<Promise>
nsDOMDeviceStorage::GetRoot()
{
// TODO
return nullptr;
}
NS_IMETHODIMP
nsDOMDeviceStorage::GetDefault(bool* aDefault)
{

Просмотреть файл

@ -0,0 +1,74 @@
/* -*- 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 "mozilla/dom/Directory.h"
#include "nsString.h"
#include "mozilla/dom/DirectoryBinding.h"
// Resolve the name collision of Microsoft's API name with macros defined in
// Windows header files. Undefine the macro of CreateDirectory to avoid
// Directory#CreateDirectory being replaced by Directory#CreateDirectoryW.
#ifdef CreateDirectory
#undef CreateDirectory
#endif
namespace mozilla {
namespace dom {
NS_IMPL_CYCLE_COLLECTION_WRAPPERCACHE_0(Directory)
NS_IMPL_CYCLE_COLLECTING_ADDREF(Directory)
NS_IMPL_CYCLE_COLLECTING_RELEASE(Directory)
NS_INTERFACE_MAP_BEGIN_CYCLE_COLLECTION(Directory)
NS_WRAPPERCACHE_INTERFACE_MAP_ENTRY
NS_INTERFACE_MAP_ENTRY(nsISupports)
NS_INTERFACE_MAP_END
Directory::Directory()
{
SetIsDOMBinding();
}
Directory::~Directory()
{
}
nsPIDOMWindow*
Directory::GetParentObject() const
{
// TODO
return nullptr;
}
JSObject*
Directory::WrapObject(JSContext* aCx, JS::Handle<JSObject*> aScope)
{
return DirectoryBinding::Wrap(aCx, aScope, this);
}
void
Directory::GetName(nsString& aRetval) const
{
aRetval.Truncate();
// TODO
}
already_AddRefed<Promise>
Directory::CreateDirectory(const nsAString& aPath)
{
// TODO
return nullptr;
}
already_AddRefed<Promise>
Directory::Get(const nsAString& aPath)
{
// TODO
return nullptr;
}
} // namespace dom
} // namespace mozilla

Просмотреть файл

@ -0,0 +1,64 @@
/* -*- 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_Directory_h
#define mozilla_dom_Directory_h
#include "mozilla/Attributes.h"
#include "mozilla/dom/BindingDeclarations.h"
#include "nsAutoPtr.h"
#include "nsCycleCollectionParticipant.h"
#include "nsPIDOMWindow.h"
#include "nsWrapperCache.h"
// Resolve the name collision of Microsoft's API name with macros defined in
// Windows header files. Undefine the macro of CreateDirectory to avoid
// Directory#CreateDirectory being replaced by Directory#CreateDirectoryW.
#ifdef CreateDirectory
#undef CreateDirectory
#endif
namespace mozilla {
namespace dom {
class Promise;
class Directory MOZ_FINAL
: public nsISupports
, public nsWrapperCache
{
public:
NS_DECL_CYCLE_COLLECTING_ISUPPORTS
NS_DECL_CYCLE_COLLECTION_SCRIPT_HOLDER_CLASS(Directory)
public:
Directory();
~Directory();
// ========= Begin WebIDL bindings. ===========
nsPIDOMWindow*
GetParentObject() const;
virtual JSObject*
WrapObject(JSContext* aCx, JS::Handle<JSObject*> aScope) MOZ_OVERRIDE;
void
GetName(nsString& aRetval) const;
already_AddRefed<Promise>
CreateDirectory(const nsAString& aPath);
already_AddRefed<Promise>
Get(const nsAString& aPath);
// =========== End WebIDL bindings.============
};
} // namespace dom
} // namespace mozilla
#endif // mozilla_dom_Directory_h

22
dom/filesystem/moz.build Normal file
Просмотреть файл

@ -0,0 +1,22 @@
# -*- 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/.
EXPORTS.mozilla.dom += [
'Directory.h',
]
SOURCES += [
'Directory.cpp',
]
FINAL_LIBRARY = 'gklayout'
include('/ipc/chromium/chromium-config.mozbuild')
LOCAL_INCLUDES += [
'/dom/base',
]

Просмотреть файл

@ -50,6 +50,7 @@ PARALLEL_DIRS += [
'encoding',
'events',
'file',
'filesystem',
'fmradio',
'asmjscache',
'media',

Просмотреть файл

@ -55,4 +55,7 @@ interface DeviceStorage : EventTarget {
// Determines if this storage area is the one which will be used by default
// for storing new files.
readonly attribute boolean default;
[NewObject]
Promise getRoot();
};

Просмотреть файл

@ -0,0 +1,49 @@
/* -*- Mode: IDL; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
/* This Source Code Form is subject to the terms of the Mozilla Public
* License, v. 2.0. If a copy of the MPL was not distributed with this file,
* You can obtain one at http://mozilla.org/MPL/2.0/.
*/
interface File;
/*
* All functions on Directory that accept DOMString arguments for file or
* directory names only allow relative path to current directory itself. The
* path should be a descendent path like "path/to/file.txt" and not contain a
* segment of ".." or ".". So the paths aren't allowed to walk up the directory
* tree. For example, paths like "../foo", "..", "/foo/bar" or "foo/../bar" are
* not allowed.
*/
[NoInterfaceObject]
interface Directory {
/*
* The leaf name of the directory.
*/
readonly attribute DOMString name;
/*
* Creates a descendent directory. This method will create any intermediate
* directories specified by the path segments.
*
* @param path The relative path of the new directory to current directory.
* If path exists, createDirectory must fail.
* @return If succeeds, the promise is resolved with the new created
* Directory object. Otherwise, rejected with a DOM error.
*/
[NewObject]
// Promise<Directory>
Promise createDirectory(DOMString path);
/*
* Gets a descendent file or directory with the given path.
*
* @param path The descendent entry's relative path to current directory.
* @return If the path exists and no error occurs, the promise is resolved
* with a File or Directory object, depending on the entry's type. Otherwise,
* rejected with a DOM error.
*/
[NewObject]
// Promise<(File or Directory)>
Promise get(DOMString path);
};

Просмотреть файл

@ -73,6 +73,7 @@ WEBIDL_FILES = [
'DesktopNotification.webidl',
'DeviceMotionEvent.webidl',
'DeviceStorage.webidl',
'Directory.webidl',
'Document.webidl',
'DocumentFragment.webidl',
'DocumentType.webidl',

Просмотреть файл

@ -53,6 +53,7 @@ LOCAL_INCLUDES += [
'/dom/camera',
'/dom/events',
'/dom/file',
'/dom/filesystem',
'/dom/media',
'/dom/speakermanager',
'/dom/src/geolocation',