widget/xpwidgets/nsFilePickerProxy.cpp

Thu, 22 Jan 2015 13:21:57 +0100

author
Michael Schloh von Bennewitz <michael@schloh.com>
date
Thu, 22 Jan 2015 13:21:57 +0100
branch
TOR_BUG_9701
changeset 15
b8a032363ba2
permissions
-rw-r--r--

Incorporate requested changes from Mozilla in review:
https://bugzilla.mozilla.org/show_bug.cgi?id=1123480#c6

     1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 2 -*-
     2  *
     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/. */
     7 #include "nsFilePickerProxy.h"
     8 #include "nsComponentManagerUtils.h"
     9 #include "nsNetUtil.h"
    10 #include "nsIFile.h"
    11 #include "nsDOMFile.h"
    12 #include "mozilla/dom/TabChild.h"
    13 #include "mozilla/dom/ipc/Blob.h"
    15 using namespace mozilla::dom;
    17 NS_IMPL_ISUPPORTS(nsFilePickerProxy, nsIFilePicker)
    19 nsFilePickerProxy::nsFilePickerProxy()
    20 {
    21 }
    23 nsFilePickerProxy::~nsFilePickerProxy()
    24 {
    25 }
    27 NS_IMETHODIMP
    28 nsFilePickerProxy::Init(nsIDOMWindow* aParent, const nsAString& aTitle,
    29                         int16_t aMode)
    30 {
    31   TabChild* tabChild = TabChild::GetFrom(aParent);
    32   if (!tabChild) {
    33     return NS_ERROR_FAILURE;
    34   }
    36   mMode = aMode;
    38   NS_ADDREF_THIS();
    39   tabChild->SendPFilePickerConstructor(this, nsString(aTitle), aMode);
    40   return NS_OK;
    41 }
    43 void
    44 nsFilePickerProxy::InitNative(nsIWidget* aParent, const nsAString& aTitle)
    45 {
    46 }
    48 NS_IMETHODIMP
    49 nsFilePickerProxy::AppendFilter(const nsAString& aTitle, const nsAString& aFilter)
    50 {
    51   mFilterNames.AppendElement(aTitle);
    52   mFilters.AppendElement(aFilter);
    53   return NS_OK;
    54 }
    56 NS_IMETHODIMP
    57 nsFilePickerProxy::GetDefaultString(nsAString& aDefaultString)
    58 {
    59   aDefaultString = mDefault;
    60   return NS_OK;
    61 }
    63 NS_IMETHODIMP
    64 nsFilePickerProxy::SetDefaultString(const nsAString& aDefaultString)
    65 {
    66   mDefault = aDefaultString;
    67   return NS_OK;
    68 }
    70 NS_IMETHODIMP
    71 nsFilePickerProxy::GetDefaultExtension(nsAString& aDefaultExtension)
    72 {
    73   aDefaultExtension = mDefaultExtension;
    74   return NS_OK;
    75 }
    77 NS_IMETHODIMP
    78 nsFilePickerProxy::SetDefaultExtension(const nsAString& aDefaultExtension)
    79 {
    80   mDefaultExtension = aDefaultExtension;
    81   return NS_OK;
    82 }
    84 NS_IMETHODIMP
    85 nsFilePickerProxy::GetFilterIndex(int32_t* aFilterIndex)
    86 {
    87   *aFilterIndex = mSelectedType;
    88   return NS_OK;
    89 }
    91 NS_IMETHODIMP
    92 nsFilePickerProxy::SetFilterIndex(int32_t aFilterIndex)
    93 {
    94   mSelectedType = aFilterIndex;
    95   return NS_OK;
    96 }
    98 /* readonly attribute nsIFile file; */
    99 NS_IMETHODIMP
   100 nsFilePickerProxy::GetFile(nsIFile** aFile)
   101 {
   102   MOZ_ASSERT(false, "GetFile is unimplemented; use GetDomfile");
   103   return NS_ERROR_FAILURE;
   104 }
   106 /* readonly attribute nsIFileURL fileURL; */
   107 NS_IMETHODIMP
   108 nsFilePickerProxy::GetFileURL(nsIURI** aFileURL)
   109 {
   110   MOZ_ASSERT(false, "GetFileURL is unimplemented; use GetDomfile");
   111   return NS_ERROR_FAILURE;
   112 }
   114 /* readonly attribute nsISimpleEnumerator files; */
   115 NS_IMETHODIMP
   116 nsFilePickerProxy::GetFiles(nsISimpleEnumerator** aFiles)
   117 {
   118   MOZ_ASSERT(false, "GetFiles is unimplemented; use GetDomfiles");
   119   return NS_ERROR_FAILURE;
   120 }
   122 NS_IMETHODIMP
   123 nsFilePickerProxy::Show(int16_t* aReturn)
   124 {
   125   MOZ_ASSERT(false, "Show is unimplemented; use Open");
   126   return NS_ERROR_NOT_IMPLEMENTED;
   127 }
   129 NS_IMETHODIMP
   130 nsFilePickerProxy::Open(nsIFilePickerShownCallback* aCallback)
   131 {
   132   mCallback = aCallback;
   134   SendOpen(mSelectedType, mAddToRecentDocs, mDefault,
   135            mDefaultExtension, mFilters, mFilterNames);
   137   return NS_OK;
   138 }
   140 bool
   141 nsFilePickerProxy::Recv__delete__(const MaybeInputFiles& aFiles,
   142                                   const int16_t& aResult)
   143 {
   144   if (aFiles.type() == MaybeInputFiles::TInputFiles) {
   145     const InfallibleTArray<PBlobChild*>& files = aFiles.get_InputFiles().filesChild();
   146     for (uint32_t i = 0; i < files.Length(); ++i) {
   147       BlobChild* actor = static_cast<BlobChild*>(files[i]);
   148       nsCOMPtr<nsIDOMBlob> blob = actor->GetBlob();
   149       nsCOMPtr<nsIDOMFile> file(do_QueryInterface(blob));
   150       NS_ENSURE_TRUE(file, true);
   151       mDomfiles.AppendObject(file);
   152     }
   153   }
   155   if (mCallback) {
   156     mCallback->Done(aResult);
   157     mCallback = nullptr;
   158   }
   160   return true;
   161 }
   163 NS_IMETHODIMP
   164 nsFilePickerProxy::GetDomfile(nsIDOMFile** aDomfile)
   165 {
   166   *aDomfile = nullptr;
   167   if (mDomfiles.IsEmpty()) {
   168     return NS_OK;
   169   }
   171   MOZ_ASSERT(mDomfiles.Length() == 1);
   172   nsCOMPtr<nsIDOMFile> domfile = mDomfiles[0];
   173   domfile.forget(aDomfile);
   174   return NS_OK;
   175 }
   177 NS_IMETHODIMP
   178 nsFilePickerProxy::GetDomfiles(nsISimpleEnumerator** aDomfiles)
   179 {
   180   return NS_NewArrayEnumerator(aDomfiles, mDomfiles);
   181 }

mercurial