/src/mozilla-central/dom/filesystem/compat/FileSystem.cpp
Line | Count | Source (jump to first uncovered line) |
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 | | NS_IMPL_CYCLE_COLLECTION_WRAPPERCACHE(FileSystem, mParent, mRoot) |
16 | | |
17 | | NS_IMPL_CYCLE_COLLECTING_ADDREF(FileSystem) |
18 | | 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 | | FileSystem::Create(nsIGlobalObject* aGlobalObject) |
27 | | |
28 | 0 | { |
29 | 0 | MOZ_ASSERT(aGlobalObject); |
30 | 0 |
|
31 | 0 |
|
32 | 0 | nsID id; |
33 | 0 | nsresult rv = nsContentUtils::GenerateUUIDInPlace(id); |
34 | 0 | if (NS_WARN_IF(NS_FAILED(rv))) { |
35 | 0 | return nullptr; |
36 | 0 | } |
37 | 0 | |
38 | 0 | char chars[NSID_LENGTH]; |
39 | 0 | id.ToProvidedString(chars); |
40 | 0 |
|
41 | 0 | // Any fileSystem has an unique ID. We use UUID, but our generator produces |
42 | 0 | // 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 | 0 |
|
45 | 0 | RefPtr<FileSystem> fs = |
46 | 0 | new FileSystem(aGlobalObject, NS_ConvertUTF8toUTF16(name)); |
47 | 0 |
|
48 | 0 | return fs.forget(); |
49 | 0 | } |
50 | | |
51 | | FileSystem::FileSystem(nsIGlobalObject* aGlobal, const nsAString& aName) |
52 | | : mParent(aGlobal) |
53 | | , mName(aName) |
54 | 0 | { |
55 | 0 | MOZ_ASSERT(aGlobal); |
56 | 0 | } |
57 | | |
58 | | FileSystem::~FileSystem() |
59 | 0 | {} |
60 | | |
61 | | JSObject* |
62 | | FileSystem::WrapObject(JSContext* aCx, JS::Handle<JSObject*> aGivenProto) |
63 | 0 | { |
64 | 0 | return FileSystem_Binding::Wrap(aCx, this, aGivenProto); |
65 | 0 | } |
66 | | |
67 | | void |
68 | | FileSystem::CreateRoot(const Sequence<RefPtr<FileSystemEntry>>& aEntries) |
69 | 0 | { |
70 | 0 | MOZ_ASSERT(!mRoot); |
71 | 0 | mRoot = new FileSystemRootDirectoryEntry(mParent, aEntries, this); |
72 | 0 | } |
73 | | |
74 | | } // dom namespace |
75 | | } // mozilla namespace |