Fri, 16 Jan 2015 04:50:19 +0100
Replace accessor implementation with direct member state manipulation, by
request https://trac.torproject.org/projects/tor/ticket/9701#comment:32
michael@0 | 1 | /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 2 -*- |
michael@0 | 2 | * |
michael@0 | 3 | * This Source Code Form is subject to the terms of the Mozilla Public |
michael@0 | 4 | * License, v. 2.0. If a copy of the MPL was not distributed with this |
michael@0 | 5 | * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ |
michael@0 | 6 | |
michael@0 | 7 | #include "nsFilePickerProxy.h" |
michael@0 | 8 | #include "nsComponentManagerUtils.h" |
michael@0 | 9 | #include "nsNetUtil.h" |
michael@0 | 10 | #include "nsIFile.h" |
michael@0 | 11 | #include "nsDOMFile.h" |
michael@0 | 12 | #include "mozilla/dom/TabChild.h" |
michael@0 | 13 | #include "mozilla/dom/ipc/Blob.h" |
michael@0 | 14 | |
michael@0 | 15 | using namespace mozilla::dom; |
michael@0 | 16 | |
michael@0 | 17 | NS_IMPL_ISUPPORTS(nsFilePickerProxy, nsIFilePicker) |
michael@0 | 18 | |
michael@0 | 19 | nsFilePickerProxy::nsFilePickerProxy() |
michael@0 | 20 | { |
michael@0 | 21 | } |
michael@0 | 22 | |
michael@0 | 23 | nsFilePickerProxy::~nsFilePickerProxy() |
michael@0 | 24 | { |
michael@0 | 25 | } |
michael@0 | 26 | |
michael@0 | 27 | NS_IMETHODIMP |
michael@0 | 28 | nsFilePickerProxy::Init(nsIDOMWindow* aParent, const nsAString& aTitle, |
michael@0 | 29 | int16_t aMode) |
michael@0 | 30 | { |
michael@0 | 31 | TabChild* tabChild = TabChild::GetFrom(aParent); |
michael@0 | 32 | if (!tabChild) { |
michael@0 | 33 | return NS_ERROR_FAILURE; |
michael@0 | 34 | } |
michael@0 | 35 | |
michael@0 | 36 | mMode = aMode; |
michael@0 | 37 | |
michael@0 | 38 | NS_ADDREF_THIS(); |
michael@0 | 39 | tabChild->SendPFilePickerConstructor(this, nsString(aTitle), aMode); |
michael@0 | 40 | return NS_OK; |
michael@0 | 41 | } |
michael@0 | 42 | |
michael@0 | 43 | void |
michael@0 | 44 | nsFilePickerProxy::InitNative(nsIWidget* aParent, const nsAString& aTitle) |
michael@0 | 45 | { |
michael@0 | 46 | } |
michael@0 | 47 | |
michael@0 | 48 | NS_IMETHODIMP |
michael@0 | 49 | nsFilePickerProxy::AppendFilter(const nsAString& aTitle, const nsAString& aFilter) |
michael@0 | 50 | { |
michael@0 | 51 | mFilterNames.AppendElement(aTitle); |
michael@0 | 52 | mFilters.AppendElement(aFilter); |
michael@0 | 53 | return NS_OK; |
michael@0 | 54 | } |
michael@0 | 55 | |
michael@0 | 56 | NS_IMETHODIMP |
michael@0 | 57 | nsFilePickerProxy::GetDefaultString(nsAString& aDefaultString) |
michael@0 | 58 | { |
michael@0 | 59 | aDefaultString = mDefault; |
michael@0 | 60 | return NS_OK; |
michael@0 | 61 | } |
michael@0 | 62 | |
michael@0 | 63 | NS_IMETHODIMP |
michael@0 | 64 | nsFilePickerProxy::SetDefaultString(const nsAString& aDefaultString) |
michael@0 | 65 | { |
michael@0 | 66 | mDefault = aDefaultString; |
michael@0 | 67 | return NS_OK; |
michael@0 | 68 | } |
michael@0 | 69 | |
michael@0 | 70 | NS_IMETHODIMP |
michael@0 | 71 | nsFilePickerProxy::GetDefaultExtension(nsAString& aDefaultExtension) |
michael@0 | 72 | { |
michael@0 | 73 | aDefaultExtension = mDefaultExtension; |
michael@0 | 74 | return NS_OK; |
michael@0 | 75 | } |
michael@0 | 76 | |
michael@0 | 77 | NS_IMETHODIMP |
michael@0 | 78 | nsFilePickerProxy::SetDefaultExtension(const nsAString& aDefaultExtension) |
michael@0 | 79 | { |
michael@0 | 80 | mDefaultExtension = aDefaultExtension; |
michael@0 | 81 | return NS_OK; |
michael@0 | 82 | } |
michael@0 | 83 | |
michael@0 | 84 | NS_IMETHODIMP |
michael@0 | 85 | nsFilePickerProxy::GetFilterIndex(int32_t* aFilterIndex) |
michael@0 | 86 | { |
michael@0 | 87 | *aFilterIndex = mSelectedType; |
michael@0 | 88 | return NS_OK; |
michael@0 | 89 | } |
michael@0 | 90 | |
michael@0 | 91 | NS_IMETHODIMP |
michael@0 | 92 | nsFilePickerProxy::SetFilterIndex(int32_t aFilterIndex) |
michael@0 | 93 | { |
michael@0 | 94 | mSelectedType = aFilterIndex; |
michael@0 | 95 | return NS_OK; |
michael@0 | 96 | } |
michael@0 | 97 | |
michael@0 | 98 | /* readonly attribute nsIFile file; */ |
michael@0 | 99 | NS_IMETHODIMP |
michael@0 | 100 | nsFilePickerProxy::GetFile(nsIFile** aFile) |
michael@0 | 101 | { |
michael@0 | 102 | MOZ_ASSERT(false, "GetFile is unimplemented; use GetDomfile"); |
michael@0 | 103 | return NS_ERROR_FAILURE; |
michael@0 | 104 | } |
michael@0 | 105 | |
michael@0 | 106 | /* readonly attribute nsIFileURL fileURL; */ |
michael@0 | 107 | NS_IMETHODIMP |
michael@0 | 108 | nsFilePickerProxy::GetFileURL(nsIURI** aFileURL) |
michael@0 | 109 | { |
michael@0 | 110 | MOZ_ASSERT(false, "GetFileURL is unimplemented; use GetDomfile"); |
michael@0 | 111 | return NS_ERROR_FAILURE; |
michael@0 | 112 | } |
michael@0 | 113 | |
michael@0 | 114 | /* readonly attribute nsISimpleEnumerator files; */ |
michael@0 | 115 | NS_IMETHODIMP |
michael@0 | 116 | nsFilePickerProxy::GetFiles(nsISimpleEnumerator** aFiles) |
michael@0 | 117 | { |
michael@0 | 118 | MOZ_ASSERT(false, "GetFiles is unimplemented; use GetDomfiles"); |
michael@0 | 119 | return NS_ERROR_FAILURE; |
michael@0 | 120 | } |
michael@0 | 121 | |
michael@0 | 122 | NS_IMETHODIMP |
michael@0 | 123 | nsFilePickerProxy::Show(int16_t* aReturn) |
michael@0 | 124 | { |
michael@0 | 125 | MOZ_ASSERT(false, "Show is unimplemented; use Open"); |
michael@0 | 126 | return NS_ERROR_NOT_IMPLEMENTED; |
michael@0 | 127 | } |
michael@0 | 128 | |
michael@0 | 129 | NS_IMETHODIMP |
michael@0 | 130 | nsFilePickerProxy::Open(nsIFilePickerShownCallback* aCallback) |
michael@0 | 131 | { |
michael@0 | 132 | mCallback = aCallback; |
michael@0 | 133 | |
michael@0 | 134 | SendOpen(mSelectedType, mAddToRecentDocs, mDefault, |
michael@0 | 135 | mDefaultExtension, mFilters, mFilterNames); |
michael@0 | 136 | |
michael@0 | 137 | return NS_OK; |
michael@0 | 138 | } |
michael@0 | 139 | |
michael@0 | 140 | bool |
michael@0 | 141 | nsFilePickerProxy::Recv__delete__(const MaybeInputFiles& aFiles, |
michael@0 | 142 | const int16_t& aResult) |
michael@0 | 143 | { |
michael@0 | 144 | if (aFiles.type() == MaybeInputFiles::TInputFiles) { |
michael@0 | 145 | const InfallibleTArray<PBlobChild*>& files = aFiles.get_InputFiles().filesChild(); |
michael@0 | 146 | for (uint32_t i = 0; i < files.Length(); ++i) { |
michael@0 | 147 | BlobChild* actor = static_cast<BlobChild*>(files[i]); |
michael@0 | 148 | nsCOMPtr<nsIDOMBlob> blob = actor->GetBlob(); |
michael@0 | 149 | nsCOMPtr<nsIDOMFile> file(do_QueryInterface(blob)); |
michael@0 | 150 | NS_ENSURE_TRUE(file, true); |
michael@0 | 151 | mDomfiles.AppendObject(file); |
michael@0 | 152 | } |
michael@0 | 153 | } |
michael@0 | 154 | |
michael@0 | 155 | if (mCallback) { |
michael@0 | 156 | mCallback->Done(aResult); |
michael@0 | 157 | mCallback = nullptr; |
michael@0 | 158 | } |
michael@0 | 159 | |
michael@0 | 160 | return true; |
michael@0 | 161 | } |
michael@0 | 162 | |
michael@0 | 163 | NS_IMETHODIMP |
michael@0 | 164 | nsFilePickerProxy::GetDomfile(nsIDOMFile** aDomfile) |
michael@0 | 165 | { |
michael@0 | 166 | *aDomfile = nullptr; |
michael@0 | 167 | if (mDomfiles.IsEmpty()) { |
michael@0 | 168 | return NS_OK; |
michael@0 | 169 | } |
michael@0 | 170 | |
michael@0 | 171 | MOZ_ASSERT(mDomfiles.Length() == 1); |
michael@0 | 172 | nsCOMPtr<nsIDOMFile> domfile = mDomfiles[0]; |
michael@0 | 173 | domfile.forget(aDomfile); |
michael@0 | 174 | return NS_OK; |
michael@0 | 175 | } |
michael@0 | 176 | |
michael@0 | 177 | NS_IMETHODIMP |
michael@0 | 178 | nsFilePickerProxy::GetDomfiles(nsISimpleEnumerator** aDomfiles) |
michael@0 | 179 | { |
michael@0 | 180 | return NS_NewArrayEnumerator(aDomfiles, mDomfiles); |
michael@0 | 181 | } |