2014-02-17 16:30:06 -08:00
|
|
|
/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 2 -*-
|
2010-10-20 08:19:24 -07:00
|
|
|
*
|
2012-05-21 04:12:37 -07:00
|
|
|
* 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/. */
|
2010-10-20 08:19:24 -07:00
|
|
|
|
|
|
|
#include "nsFilePickerProxy.h"
|
2014-02-17 16:30:06 -08:00
|
|
|
#include "nsComponentManagerUtils.h"
|
2012-08-23 12:33:46 -07:00
|
|
|
#include "nsNetUtil.h"
|
2014-02-17 16:30:06 -08:00
|
|
|
#include "nsIFile.h"
|
2014-10-07 10:16:11 -07:00
|
|
|
#include "nsDOMFile.h"
|
2014-02-17 16:30:06 -08:00
|
|
|
#include "mozilla/dom/TabChild.h"
|
2014-09-26 16:21:57 -07:00
|
|
|
#include "mozilla/dom/ipc/BlobChild.h"
|
2010-10-20 08:19:24 -07:00
|
|
|
|
2014-02-17 16:30:06 -08:00
|
|
|
using namespace mozilla::dom;
|
2010-10-20 08:19:24 -07:00
|
|
|
|
2014-04-27 00:06:00 -07:00
|
|
|
NS_IMPL_ISUPPORTS(nsFilePickerProxy, nsIFilePicker)
|
2010-10-20 08:19:24 -07:00
|
|
|
|
|
|
|
nsFilePickerProxy::nsFilePickerProxy()
|
2014-02-17 16:30:06 -08:00
|
|
|
{
|
2010-10-20 08:19:24 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
nsFilePickerProxy::~nsFilePickerProxy()
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
2014-02-17 16:30:06 -08:00
|
|
|
nsFilePickerProxy::Init(nsIDOMWindow* aParent, const nsAString& aTitle,
|
2012-08-22 08:56:38 -07:00
|
|
|
int16_t aMode)
|
2010-10-20 08:19:24 -07:00
|
|
|
{
|
2014-02-17 16:30:06 -08:00
|
|
|
TabChild* tabChild = TabChild::GetFrom(aParent);
|
|
|
|
if (!tabChild) {
|
|
|
|
return NS_ERROR_FAILURE;
|
|
|
|
}
|
|
|
|
|
|
|
|
mMode = aMode;
|
2010-10-20 08:19:24 -07:00
|
|
|
|
2014-02-17 16:30:06 -08:00
|
|
|
NS_ADDREF_THIS();
|
|
|
|
tabChild->SendPFilePickerConstructor(this, nsString(aTitle), aMode);
|
|
|
|
return NS_OK;
|
2010-10-20 08:19:24 -07:00
|
|
|
}
|
|
|
|
|
2014-02-17 16:30:06 -08:00
|
|
|
void
|
|
|
|
nsFilePickerProxy::InitNative(nsIWidget* aParent, const nsAString& aTitle)
|
2010-10-20 08:19:24 -07:00
|
|
|
{
|
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
|
|
|
nsFilePickerProxy::AppendFilter(const nsAString& aTitle, const nsAString& aFilter)
|
|
|
|
{
|
2014-02-17 16:30:06 -08:00
|
|
|
mFilterNames.AppendElement(aTitle);
|
|
|
|
mFilters.AppendElement(aFilter);
|
|
|
|
return NS_OK;
|
2010-10-20 08:19:24 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
|
|
|
nsFilePickerProxy::GetDefaultString(nsAString& aDefaultString)
|
|
|
|
{
|
2014-02-17 16:30:06 -08:00
|
|
|
aDefaultString = mDefault;
|
|
|
|
return NS_OK;
|
2010-10-20 08:19:24 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
|
|
|
nsFilePickerProxy::SetDefaultString(const nsAString& aDefaultString)
|
|
|
|
{
|
2014-02-17 16:30:06 -08:00
|
|
|
mDefault = aDefaultString;
|
|
|
|
return NS_OK;
|
2010-10-20 08:19:24 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
|
|
|
nsFilePickerProxy::GetDefaultExtension(nsAString& aDefaultExtension)
|
|
|
|
{
|
2014-02-17 16:30:06 -08:00
|
|
|
aDefaultExtension = mDefaultExtension;
|
|
|
|
return NS_OK;
|
2010-10-20 08:19:24 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
|
|
|
nsFilePickerProxy::SetDefaultExtension(const nsAString& aDefaultExtension)
|
|
|
|
{
|
2014-02-17 16:30:06 -08:00
|
|
|
mDefaultExtension = aDefaultExtension;
|
|
|
|
return NS_OK;
|
2010-10-20 08:19:24 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
2012-08-22 08:56:38 -07:00
|
|
|
nsFilePickerProxy::GetFilterIndex(int32_t* aFilterIndex)
|
2010-10-20 08:19:24 -07:00
|
|
|
{
|
2014-02-17 16:30:06 -08:00
|
|
|
*aFilterIndex = mSelectedType;
|
|
|
|
return NS_OK;
|
2010-10-20 08:19:24 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
2012-08-22 08:56:38 -07:00
|
|
|
nsFilePickerProxy::SetFilterIndex(int32_t aFilterIndex)
|
2010-10-20 08:19:24 -07:00
|
|
|
{
|
2014-02-17 16:30:06 -08:00
|
|
|
mSelectedType = aFilterIndex;
|
|
|
|
return NS_OK;
|
2010-10-20 08:19:24 -07:00
|
|
|
}
|
|
|
|
|
2012-06-05 19:08:30 -07:00
|
|
|
/* readonly attribute nsIFile file; */
|
2010-10-20 08:19:24 -07:00
|
|
|
NS_IMETHODIMP
|
2012-06-05 19:08:30 -07:00
|
|
|
nsFilePickerProxy::GetFile(nsIFile** aFile)
|
2010-10-20 08:19:24 -07:00
|
|
|
{
|
2014-02-24 13:09:03 -08:00
|
|
|
MOZ_ASSERT(false, "GetFile is unimplemented; use GetDomfile");
|
|
|
|
return NS_ERROR_FAILURE;
|
2010-10-20 08:19:24 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
/* readonly attribute nsIFileURL fileURL; */
|
|
|
|
NS_IMETHODIMP
|
|
|
|
nsFilePickerProxy::GetFileURL(nsIURI** aFileURL)
|
|
|
|
{
|
2014-02-24 13:09:03 -08:00
|
|
|
MOZ_ASSERT(false, "GetFileURL is unimplemented; use GetDomfile");
|
|
|
|
return NS_ERROR_FAILURE;
|
2010-10-20 08:19:24 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
/* readonly attribute nsISimpleEnumerator files; */
|
|
|
|
NS_IMETHODIMP
|
|
|
|
nsFilePickerProxy::GetFiles(nsISimpleEnumerator** aFiles)
|
|
|
|
{
|
2014-02-24 13:09:03 -08:00
|
|
|
MOZ_ASSERT(false, "GetFiles is unimplemented; use GetDomfiles");
|
2014-02-17 16:30:06 -08:00
|
|
|
return NS_ERROR_FAILURE;
|
2010-10-20 08:19:24 -07:00
|
|
|
}
|
|
|
|
|
2014-02-17 16:30:06 -08:00
|
|
|
NS_IMETHODIMP
|
|
|
|
nsFilePickerProxy::Show(int16_t* aReturn)
|
|
|
|
{
|
2014-02-24 13:09:03 -08:00
|
|
|
MOZ_ASSERT(false, "Show is unimplemented; use Open");
|
2014-02-17 16:30:06 -08:00
|
|
|
return NS_ERROR_NOT_IMPLEMENTED;
|
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
|
|
|
nsFilePickerProxy::Open(nsIFilePickerShownCallback* aCallback)
|
|
|
|
{
|
|
|
|
mCallback = aCallback;
|
|
|
|
|
|
|
|
SendOpen(mSelectedType, mAddToRecentDocs, mDefault,
|
|
|
|
mDefaultExtension, mFilters, mFilterNames);
|
|
|
|
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
bool
|
|
|
|
nsFilePickerProxy::Recv__delete__(const MaybeInputFiles& aFiles,
|
|
|
|
const int16_t& aResult)
|
|
|
|
{
|
|
|
|
if (aFiles.type() == MaybeInputFiles::TInputFiles) {
|
2014-02-24 13:09:03 -08:00
|
|
|
const InfallibleTArray<PBlobChild*>& files = aFiles.get_InputFiles().filesChild();
|
2014-02-17 16:30:06 -08:00
|
|
|
for (uint32_t i = 0; i < files.Length(); ++i) {
|
2014-02-24 13:09:03 -08:00
|
|
|
BlobChild* actor = static_cast<BlobChild*>(files[i]);
|
2014-10-07 10:16:11 -07:00
|
|
|
nsCOMPtr<nsIDOMBlob> blob = actor->GetBlob();
|
2014-02-24 13:09:03 -08:00
|
|
|
nsCOMPtr<nsIDOMFile> file(do_QueryInterface(blob));
|
2014-02-17 16:30:06 -08:00
|
|
|
NS_ENSURE_TRUE(file, true);
|
2014-02-24 13:09:03 -08:00
|
|
|
mDomfiles.AppendObject(file);
|
2010-10-20 08:19:24 -07:00
|
|
|
}
|
2014-02-17 16:30:06 -08:00
|
|
|
}
|
2010-10-20 08:19:24 -07:00
|
|
|
|
2014-02-17 16:30:06 -08:00
|
|
|
if (mCallback) {
|
|
|
|
mCallback->Done(aResult);
|
|
|
|
mCallback = nullptr;
|
|
|
|
}
|
2010-10-20 08:19:24 -07:00
|
|
|
|
2014-02-17 16:30:06 -08:00
|
|
|
return true;
|
2010-10-20 08:19:24 -07:00
|
|
|
}
|
2014-02-24 13:09:03 -08:00
|
|
|
|
|
|
|
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);
|
|
|
|
}
|