Line data Source code
1 : /* -*- Mode: C++; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
2 : /* vim: set ts=8 sts=2 et sw=2 tw=80: */
3 : /* This Source Code Form is subject to the terms of the Mozilla Public
4 : * License, v. 2.0. If a copy of the MPL was not distributed with this file,
5 : * You can obtain one at http://mozilla.org/MPL/2.0/. */
6 :
7 : #include "FileSystem.h"
8 : #include "FileSystemRootDirectoryEntry.h"
9 : #include "mozilla/dom/FileSystemBinding.h"
10 : #include "nsContentUtils.h"
11 :
12 : namespace mozilla {
13 : namespace dom {
14 :
15 0 : NS_IMPL_CYCLE_COLLECTION_WRAPPERCACHE(FileSystem, mParent, mRoot)
16 :
17 0 : NS_IMPL_CYCLE_COLLECTING_ADDREF(FileSystem)
18 0 : NS_IMPL_CYCLE_COLLECTING_RELEASE(FileSystem)
19 :
20 0 : NS_INTERFACE_MAP_BEGIN_CYCLE_COLLECTION(FileSystem)
21 0 : NS_WRAPPERCACHE_INTERFACE_MAP_ENTRY
22 0 : NS_INTERFACE_MAP_ENTRY(nsISupports)
23 0 : NS_INTERFACE_MAP_END
24 :
25 : /* static */ already_AddRefed<FileSystem>
26 0 : FileSystem::Create(nsIGlobalObject* aGlobalObject)
27 :
28 : {
29 0 : MOZ_ASSERT(aGlobalObject);
30 :
31 :
32 : nsID id;
33 0 : nsresult rv = nsContentUtils::GenerateUUIDInPlace(id);
34 0 : if (NS_WARN_IF(NS_FAILED(rv))) {
35 0 : return nullptr;
36 : }
37 :
38 : char chars[NSID_LENGTH];
39 0 : id.ToProvidedString(chars);
40 :
41 : // Any fileSystem has an unique ID. We use UUID, but our generator produces
42 : // UUID in this format '{' + UUID + '}'. We remove them with these +1 and -2.
43 0 : nsAutoCString name(Substring(chars + 1, chars + NSID_LENGTH - 2));
44 :
45 : RefPtr<FileSystem> fs =
46 0 : new FileSystem(aGlobalObject, NS_ConvertUTF8toUTF16(name));
47 :
48 0 : return fs.forget();
49 : }
50 :
51 0 : FileSystem::FileSystem(nsIGlobalObject* aGlobal, const nsAString& aName)
52 : : mParent(aGlobal)
53 0 : , mName(aName)
54 : {
55 0 : MOZ_ASSERT(aGlobal);
56 0 : }
57 :
58 0 : FileSystem::~FileSystem()
59 0 : {}
60 :
61 : JSObject*
62 0 : FileSystem::WrapObject(JSContext* aCx, JS::Handle<JSObject*> aGivenProto)
63 : {
64 0 : return FileSystemBinding::Wrap(aCx, this, aGivenProto);
65 : }
66 :
67 : void
68 0 : FileSystem::CreateRoot(const Sequence<RefPtr<FileSystemEntry>>& aEntries)
69 : {
70 0 : MOZ_ASSERT(!mRoot);
71 0 : mRoot = new FileSystemRootDirectoryEntry(mParent, aEntries, this);
72 0 : }
73 :
74 : } // dom namespace
75 : } // mozilla namespace
|