widget/xpwidgets/nsFilePickerProxy.cpp

changeset 0
6474c204b198
     1.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     1.2 +++ b/widget/xpwidgets/nsFilePickerProxy.cpp	Wed Dec 31 06:09:35 2014 +0100
     1.3 @@ -0,0 +1,181 @@
     1.4 +/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 2 -*-
     1.5 + *
     1.6 + * This Source Code Form is subject to the terms of the Mozilla Public
     1.7 + * License, v. 2.0. If a copy of the MPL was not distributed with this
     1.8 + * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
     1.9 +
    1.10 +#include "nsFilePickerProxy.h"
    1.11 +#include "nsComponentManagerUtils.h"
    1.12 +#include "nsNetUtil.h"
    1.13 +#include "nsIFile.h"
    1.14 +#include "nsDOMFile.h"
    1.15 +#include "mozilla/dom/TabChild.h"
    1.16 +#include "mozilla/dom/ipc/Blob.h"
    1.17 +
    1.18 +using namespace mozilla::dom;
    1.19 +
    1.20 +NS_IMPL_ISUPPORTS(nsFilePickerProxy, nsIFilePicker)
    1.21 +
    1.22 +nsFilePickerProxy::nsFilePickerProxy()
    1.23 +{
    1.24 +}
    1.25 +
    1.26 +nsFilePickerProxy::~nsFilePickerProxy()
    1.27 +{
    1.28 +}
    1.29 +
    1.30 +NS_IMETHODIMP
    1.31 +nsFilePickerProxy::Init(nsIDOMWindow* aParent, const nsAString& aTitle,
    1.32 +                        int16_t aMode)
    1.33 +{
    1.34 +  TabChild* tabChild = TabChild::GetFrom(aParent);
    1.35 +  if (!tabChild) {
    1.36 +    return NS_ERROR_FAILURE;
    1.37 +  }
    1.38 +
    1.39 +  mMode = aMode;
    1.40 +
    1.41 +  NS_ADDREF_THIS();
    1.42 +  tabChild->SendPFilePickerConstructor(this, nsString(aTitle), aMode);
    1.43 +  return NS_OK;
    1.44 +}
    1.45 +
    1.46 +void
    1.47 +nsFilePickerProxy::InitNative(nsIWidget* aParent, const nsAString& aTitle)
    1.48 +{
    1.49 +}
    1.50 +
    1.51 +NS_IMETHODIMP
    1.52 +nsFilePickerProxy::AppendFilter(const nsAString& aTitle, const nsAString& aFilter)
    1.53 +{
    1.54 +  mFilterNames.AppendElement(aTitle);
    1.55 +  mFilters.AppendElement(aFilter);
    1.56 +  return NS_OK;
    1.57 +}
    1.58 +
    1.59 +NS_IMETHODIMP
    1.60 +nsFilePickerProxy::GetDefaultString(nsAString& aDefaultString)
    1.61 +{
    1.62 +  aDefaultString = mDefault;
    1.63 +  return NS_OK;
    1.64 +}
    1.65 +
    1.66 +NS_IMETHODIMP
    1.67 +nsFilePickerProxy::SetDefaultString(const nsAString& aDefaultString)
    1.68 +{
    1.69 +  mDefault = aDefaultString;
    1.70 +  return NS_OK;
    1.71 +}
    1.72 +
    1.73 +NS_IMETHODIMP
    1.74 +nsFilePickerProxy::GetDefaultExtension(nsAString& aDefaultExtension)
    1.75 +{
    1.76 +  aDefaultExtension = mDefaultExtension;
    1.77 +  return NS_OK;
    1.78 +}
    1.79 +
    1.80 +NS_IMETHODIMP
    1.81 +nsFilePickerProxy::SetDefaultExtension(const nsAString& aDefaultExtension)
    1.82 +{
    1.83 +  mDefaultExtension = aDefaultExtension;
    1.84 +  return NS_OK;
    1.85 +}
    1.86 +
    1.87 +NS_IMETHODIMP
    1.88 +nsFilePickerProxy::GetFilterIndex(int32_t* aFilterIndex)
    1.89 +{
    1.90 +  *aFilterIndex = mSelectedType;
    1.91 +  return NS_OK;
    1.92 +}
    1.93 +
    1.94 +NS_IMETHODIMP
    1.95 +nsFilePickerProxy::SetFilterIndex(int32_t aFilterIndex)
    1.96 +{
    1.97 +  mSelectedType = aFilterIndex;
    1.98 +  return NS_OK;
    1.99 +}
   1.100 +
   1.101 +/* readonly attribute nsIFile file; */
   1.102 +NS_IMETHODIMP
   1.103 +nsFilePickerProxy::GetFile(nsIFile** aFile)
   1.104 +{
   1.105 +  MOZ_ASSERT(false, "GetFile is unimplemented; use GetDomfile");
   1.106 +  return NS_ERROR_FAILURE;
   1.107 +}
   1.108 +
   1.109 +/* readonly attribute nsIFileURL fileURL; */
   1.110 +NS_IMETHODIMP
   1.111 +nsFilePickerProxy::GetFileURL(nsIURI** aFileURL)
   1.112 +{
   1.113 +  MOZ_ASSERT(false, "GetFileURL is unimplemented; use GetDomfile");
   1.114 +  return NS_ERROR_FAILURE;
   1.115 +}
   1.116 +
   1.117 +/* readonly attribute nsISimpleEnumerator files; */
   1.118 +NS_IMETHODIMP
   1.119 +nsFilePickerProxy::GetFiles(nsISimpleEnumerator** aFiles)
   1.120 +{
   1.121 +  MOZ_ASSERT(false, "GetFiles is unimplemented; use GetDomfiles");
   1.122 +  return NS_ERROR_FAILURE;
   1.123 +}
   1.124 +
   1.125 +NS_IMETHODIMP
   1.126 +nsFilePickerProxy::Show(int16_t* aReturn)
   1.127 +{
   1.128 +  MOZ_ASSERT(false, "Show is unimplemented; use Open");
   1.129 +  return NS_ERROR_NOT_IMPLEMENTED;
   1.130 +}
   1.131 +
   1.132 +NS_IMETHODIMP
   1.133 +nsFilePickerProxy::Open(nsIFilePickerShownCallback* aCallback)
   1.134 +{
   1.135 +  mCallback = aCallback;
   1.136 +
   1.137 +  SendOpen(mSelectedType, mAddToRecentDocs, mDefault,
   1.138 +           mDefaultExtension, mFilters, mFilterNames);
   1.139 +
   1.140 +  return NS_OK;
   1.141 +}
   1.142 +
   1.143 +bool
   1.144 +nsFilePickerProxy::Recv__delete__(const MaybeInputFiles& aFiles,
   1.145 +                                  const int16_t& aResult)
   1.146 +{
   1.147 +  if (aFiles.type() == MaybeInputFiles::TInputFiles) {
   1.148 +    const InfallibleTArray<PBlobChild*>& files = aFiles.get_InputFiles().filesChild();
   1.149 +    for (uint32_t i = 0; i < files.Length(); ++i) {
   1.150 +      BlobChild* actor = static_cast<BlobChild*>(files[i]);
   1.151 +      nsCOMPtr<nsIDOMBlob> blob = actor->GetBlob();
   1.152 +      nsCOMPtr<nsIDOMFile> file(do_QueryInterface(blob));
   1.153 +      NS_ENSURE_TRUE(file, true);
   1.154 +      mDomfiles.AppendObject(file);
   1.155 +    }
   1.156 +  }
   1.157 +
   1.158 +  if (mCallback) {
   1.159 +    mCallback->Done(aResult);
   1.160 +    mCallback = nullptr;
   1.161 +  }
   1.162 +
   1.163 +  return true;
   1.164 +}
   1.165 +
   1.166 +NS_IMETHODIMP
   1.167 +nsFilePickerProxy::GetDomfile(nsIDOMFile** aDomfile)
   1.168 +{
   1.169 +  *aDomfile = nullptr;
   1.170 +  if (mDomfiles.IsEmpty()) {
   1.171 +    return NS_OK;
   1.172 +  }
   1.173 +
   1.174 +  MOZ_ASSERT(mDomfiles.Length() == 1);
   1.175 +  nsCOMPtr<nsIDOMFile> domfile = mDomfiles[0];
   1.176 +  domfile.forget(aDomfile);
   1.177 +  return NS_OK;
   1.178 +}
   1.179 +
   1.180 +NS_IMETHODIMP
   1.181 +nsFilePickerProxy::GetDomfiles(nsISimpleEnumerator** aDomfiles)
   1.182 +{
   1.183 +  return NS_NewArrayEnumerator(aDomfiles, mDomfiles);
   1.184 +}

mercurial