1 /* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
2 /* vim:set ts=2 sw=2 sts=2 et cindent: */
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
5 * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
6 #include "FileSystemPermissionRequest.h"
8 #include "mozilla/dom/FileSystemBase.h"
9 #include "mozilla/dom/FileSystemTaskBase.h"
10 #include "mozilla/dom/FileSystemUtils.h"
11 #include "nsIDocument.h"
12 #include "nsPIDOMWindow.h"
13 #include "nsContentPermissionHelper.h"
18 NS_IMPL_ISUPPORTS(FileSystemPermissionRequest
, nsIRunnable
, nsIContentPermissionRequest
)
22 FileSystemPermissionRequest::RequestForTask(FileSystemTaskBase
* aTask
)
24 MOZ_ASSERT(aTask
, "aTask should not be null!");
25 MOZ_ASSERT(NS_IsMainThread());
26 nsRefPtr
<FileSystemPermissionRequest
> request
=
27 new FileSystemPermissionRequest(aTask
);
28 NS_DispatchToCurrentThread(request
);
31 FileSystemPermissionRequest::FileSystemPermissionRequest(
32 FileSystemTaskBase
* aTask
)
35 MOZ_ASSERT(mTask
, "aTask should not be null!");
36 MOZ_ASSERT(NS_IsMainThread());
38 mTask
->GetPermissionAccessType(mPermissionAccess
);
40 nsRefPtr
<FileSystemBase
> filesystem
= mTask
->GetFileSystem();
45 mPermissionType
= filesystem
->GetPermission();
47 mWindow
= filesystem
->GetWindow();
52 nsCOMPtr
<nsIDocument
> doc
= mWindow
->GetDoc();
57 mPrincipal
= doc
->NodePrincipal();
60 FileSystemPermissionRequest::~FileSystemPermissionRequest()
65 FileSystemPermissionRequest::GetTypes(nsIArray
** aTypes
)
67 nsTArray
<nsString
> emptyOptions
;
68 return nsContentPermissionUtils::CreatePermissionArray(mPermissionType
,
75 FileSystemPermissionRequest::GetPrincipal(nsIPrincipal
** aRequestingPrincipal
)
77 NS_IF_ADDREF(*aRequestingPrincipal
= mPrincipal
);
82 FileSystemPermissionRequest::GetWindow(nsIDOMWindow
** aRequestingWindow
)
84 NS_IF_ADDREF(*aRequestingWindow
= mWindow
);
89 FileSystemPermissionRequest::GetElement(nsIDOMElement
** aRequestingElement
)
91 *aRequestingElement
= nullptr;
96 FileSystemPermissionRequest::Cancel()
98 MOZ_ASSERT(NS_IsMainThread());
99 mTask
->SetError(NS_ERROR_DOM_SECURITY_ERR
);
105 FileSystemPermissionRequest::Allow(JS::HandleValue aChoices
)
107 MOZ_ASSERT(NS_IsMainThread());
108 MOZ_ASSERT(aChoices
.isUndefined());
114 FileSystemPermissionRequest::Run()
116 MOZ_ASSERT(NS_IsMainThread());
118 nsRefPtr
<FileSystemBase
> filesystem
= mTask
->GetFileSystem();
124 if (filesystem
->IsTesting()) {
125 Allow(JS::UndefinedHandleValue
);
134 nsContentPermissionUtils::AskPermission(this, mWindow
);
138 } /* namespace dom */
139 } /* namespace mozilla */