forked from Floorp-Projects/Floorp
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathnsFilePickerProxy.cpp
195 lines (162 loc) · 4.47 KB
/
nsFilePickerProxy.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
/* -*- Mode: C++; tab-width: 4; 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/. */
#include "nsFilePickerProxy.h"
#include "nsComponentManagerUtils.h"
#include "nsNetUtil.h"
#include "nsIFile.h"
#include "mozilla/dom/File.h"
#include "mozilla/dom/TabChild.h"
#include "mozilla/dom/ipc/BlobChild.h"
using namespace mozilla::dom;
NS_IMPL_ISUPPORTS(nsFilePickerProxy, nsIFilePicker)
nsFilePickerProxy::nsFilePickerProxy()
{
}
nsFilePickerProxy::~nsFilePickerProxy()
{
}
NS_IMETHODIMP
nsFilePickerProxy::Init(nsIDOMWindow* aParent, const nsAString& aTitle,
int16_t aMode)
{
TabChild* tabChild = TabChild::GetFrom(aParent);
if (!tabChild) {
return NS_ERROR_FAILURE;
}
mParent = do_QueryInterface(aParent);
if (!mParent->IsInnerWindow()) {
mParent = mParent->GetCurrentInnerWindow();
}
mMode = aMode;
NS_ADDREF_THIS();
tabChild->SendPFilePickerConstructor(this, nsString(aTitle), aMode);
return NS_OK;
}
void
nsFilePickerProxy::InitNative(nsIWidget* aParent, const nsAString& aTitle)
{
}
NS_IMETHODIMP
nsFilePickerProxy::AppendFilter(const nsAString& aTitle, const nsAString& aFilter)
{
mFilterNames.AppendElement(aTitle);
mFilters.AppendElement(aFilter);
return NS_OK;
}
NS_IMETHODIMP
nsFilePickerProxy::GetDefaultString(nsAString& aDefaultString)
{
aDefaultString = mDefault;
return NS_OK;
}
NS_IMETHODIMP
nsFilePickerProxy::SetDefaultString(const nsAString& aDefaultString)
{
mDefault = aDefaultString;
return NS_OK;
}
NS_IMETHODIMP
nsFilePickerProxy::GetDefaultExtension(nsAString& aDefaultExtension)
{
aDefaultExtension = mDefaultExtension;
return NS_OK;
}
NS_IMETHODIMP
nsFilePickerProxy::SetDefaultExtension(const nsAString& aDefaultExtension)
{
mDefaultExtension = aDefaultExtension;
return NS_OK;
}
NS_IMETHODIMP
nsFilePickerProxy::GetFilterIndex(int32_t* aFilterIndex)
{
*aFilterIndex = mSelectedType;
return NS_OK;
}
NS_IMETHODIMP
nsFilePickerProxy::SetFilterIndex(int32_t aFilterIndex)
{
mSelectedType = aFilterIndex;
return NS_OK;
}
/* readonly attribute nsIFile file; */
NS_IMETHODIMP
nsFilePickerProxy::GetFile(nsIFile** aFile)
{
MOZ_ASSERT(false, "GetFile is unimplemented; use GetDomfile");
return NS_ERROR_FAILURE;
}
/* readonly attribute nsIFileURL fileURL; */
NS_IMETHODIMP
nsFilePickerProxy::GetFileURL(nsIURI** aFileURL)
{
MOZ_ASSERT(false, "GetFileURL is unimplemented; use GetDomfile");
return NS_ERROR_FAILURE;
}
/* readonly attribute nsISimpleEnumerator files; */
NS_IMETHODIMP
nsFilePickerProxy::GetFiles(nsISimpleEnumerator** aFiles)
{
MOZ_ASSERT(false, "GetFiles is unimplemented; use GetDomfiles");
return NS_ERROR_FAILURE;
}
NS_IMETHODIMP
nsFilePickerProxy::Show(int16_t* aReturn)
{
MOZ_ASSERT(false, "Show is unimplemented; use Open");
return NS_ERROR_NOT_IMPLEMENTED;
}
NS_IMETHODIMP
nsFilePickerProxy::Open(nsIFilePickerShownCallback* aCallback)
{
mCallback = aCallback;
nsString displayDirectory;
if (mDisplayDirectory) {
mDisplayDirectory->GetPath(displayDirectory);
}
SendOpen(mSelectedType, mAddToRecentDocs, mDefault, mDefaultExtension,
mFilters, mFilterNames, displayDirectory);
return NS_OK;
}
bool
nsFilePickerProxy::Recv__delete__(const MaybeInputFiles& aFiles,
const int16_t& aResult)
{
if (aFiles.type() == MaybeInputFiles::TInputFiles) {
const InfallibleTArray<PBlobChild*>& files = aFiles.get_InputFiles().filesChild();
for (uint32_t i = 0; i < files.Length(); ++i) {
BlobChild* actor = static_cast<BlobChild*>(files[i]);
nsRefPtr<FileImpl> blobImpl = actor->GetBlobImpl();
NS_ENSURE_TRUE(blobImpl, true);
nsCOMPtr<nsIDOMBlob> blob = new File(mParent, blobImpl);
nsCOMPtr<nsIDOMFile> file(do_QueryInterface(blob));
NS_ENSURE_TRUE(file, true);
mDomfiles.AppendObject(file);
}
}
if (mCallback) {
mCallback->Done(aResult);
mCallback = nullptr;
}
return true;
}
NS_IMETHODIMP
nsFilePickerProxy::GetDomfile(nsIDOMFile** aDomfile)
{
*aDomfile = nullptr;
if (mDomfiles.IsEmpty()) {
return NS_OK;
}
MOZ_ASSERT(mDomfiles.Length() == 1);
nsCOMPtr<nsIDOMFile> domfile = mDomfiles[0];
domfile.forget(aDomfile);
return NS_OK;
}
NS_IMETHODIMP
nsFilePickerProxy::GetDomfiles(nsISimpleEnumerator** aDomfiles)
{
return NS_NewArrayEnumerator(aDomfiles, mDomfiles);
}