Wed, 31 Dec 2014 06:09:35 +0100
Cloned upstream origin tor-browser at tor-browser-31.3.0esr-4.5-1-build1
revision ID fc1c9ff7c1b2defdbc039f12214767608f46423f for hacking purpose.
michael@0 | 1 | /* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */ |
michael@0 | 2 | /* This Source Code Form is subject to the terms of the Mozilla Public |
michael@0 | 3 | * License, v. 2.0. If a copy of the MPL was not distributed with this file, |
michael@0 | 4 | * You can obtain one at http://mozilla.org/MPL/2.0/. */ |
michael@0 | 5 | |
michael@0 | 6 | |
michael@0 | 7 | #include "DeviceStorageRequestChild.h" |
michael@0 | 8 | #include "DeviceStorageFileDescriptor.h" |
michael@0 | 9 | #include "nsDeviceStorage.h" |
michael@0 | 10 | #include "nsDOMFile.h" |
michael@0 | 11 | #include "mozilla/dom/ipc/Blob.h" |
michael@0 | 12 | |
michael@0 | 13 | namespace mozilla { |
michael@0 | 14 | namespace dom { |
michael@0 | 15 | namespace devicestorage { |
michael@0 | 16 | |
michael@0 | 17 | DeviceStorageRequestChild::DeviceStorageRequestChild() |
michael@0 | 18 | : mCallback(nullptr) |
michael@0 | 19 | { |
michael@0 | 20 | MOZ_COUNT_CTOR(DeviceStorageRequestChild); |
michael@0 | 21 | } |
michael@0 | 22 | |
michael@0 | 23 | DeviceStorageRequestChild::DeviceStorageRequestChild(DOMRequest* aRequest, |
michael@0 | 24 | DeviceStorageFile* aDSFile) |
michael@0 | 25 | : mRequest(aRequest) |
michael@0 | 26 | , mDSFile(aDSFile) |
michael@0 | 27 | , mCallback(nullptr) |
michael@0 | 28 | { |
michael@0 | 29 | MOZ_ASSERT(aRequest); |
michael@0 | 30 | MOZ_ASSERT(aDSFile); |
michael@0 | 31 | MOZ_COUNT_CTOR(DeviceStorageRequestChild); |
michael@0 | 32 | } |
michael@0 | 33 | |
michael@0 | 34 | DeviceStorageRequestChild::DeviceStorageRequestChild(DOMRequest* aRequest, |
michael@0 | 35 | DeviceStorageFile* aDSFile, |
michael@0 | 36 | DeviceStorageFileDescriptor* aDSFileDescriptor) |
michael@0 | 37 | : mRequest(aRequest) |
michael@0 | 38 | , mDSFile(aDSFile) |
michael@0 | 39 | , mDSFileDescriptor(aDSFileDescriptor) |
michael@0 | 40 | , mCallback(nullptr) |
michael@0 | 41 | { |
michael@0 | 42 | MOZ_ASSERT(aRequest); |
michael@0 | 43 | MOZ_ASSERT(aDSFile); |
michael@0 | 44 | MOZ_ASSERT(aDSFileDescriptor); |
michael@0 | 45 | MOZ_COUNT_CTOR(DeviceStorageRequestChild); |
michael@0 | 46 | } |
michael@0 | 47 | |
michael@0 | 48 | DeviceStorageRequestChild::~DeviceStorageRequestChild() { |
michael@0 | 49 | MOZ_COUNT_DTOR(DeviceStorageRequestChild); |
michael@0 | 50 | } |
michael@0 | 51 | |
michael@0 | 52 | bool |
michael@0 | 53 | DeviceStorageRequestChild:: |
michael@0 | 54 | Recv__delete__(const DeviceStorageResponseValue& aValue) |
michael@0 | 55 | { |
michael@0 | 56 | if (mCallback) { |
michael@0 | 57 | mCallback->RequestComplete(); |
michael@0 | 58 | mCallback = nullptr; |
michael@0 | 59 | } |
michael@0 | 60 | |
michael@0 | 61 | nsCOMPtr<nsPIDOMWindow> window = mRequest->GetOwner(); |
michael@0 | 62 | if (!window) { |
michael@0 | 63 | return true; |
michael@0 | 64 | } |
michael@0 | 65 | |
michael@0 | 66 | switch (aValue.type()) { |
michael@0 | 67 | |
michael@0 | 68 | case DeviceStorageResponseValue::TErrorResponse: |
michael@0 | 69 | { |
michael@0 | 70 | ErrorResponse r = aValue; |
michael@0 | 71 | mRequest->FireError(r.error()); |
michael@0 | 72 | break; |
michael@0 | 73 | } |
michael@0 | 74 | |
michael@0 | 75 | case DeviceStorageResponseValue::TSuccessResponse: |
michael@0 | 76 | { |
michael@0 | 77 | nsString fullPath; |
michael@0 | 78 | mDSFile->GetFullPath(fullPath); |
michael@0 | 79 | AutoJSContext cx; |
michael@0 | 80 | JS::Rooted<JS::Value> result(cx, |
michael@0 | 81 | StringToJsval(window, fullPath)); |
michael@0 | 82 | mRequest->FireSuccess(result); |
michael@0 | 83 | break; |
michael@0 | 84 | } |
michael@0 | 85 | |
michael@0 | 86 | case DeviceStorageResponseValue::TFileDescriptorResponse: |
michael@0 | 87 | { |
michael@0 | 88 | FileDescriptorResponse r = aValue; |
michael@0 | 89 | |
michael@0 | 90 | nsString fullPath; |
michael@0 | 91 | mDSFile->GetFullPath(fullPath); |
michael@0 | 92 | AutoJSContext cx; |
michael@0 | 93 | JS::Rooted<JS::Value> result(cx, |
michael@0 | 94 | StringToJsval(window, fullPath)); |
michael@0 | 95 | |
michael@0 | 96 | mDSFileDescriptor->mDSFile = mDSFile; |
michael@0 | 97 | mDSFileDescriptor->mFileDescriptor = r.fileDescriptor(); |
michael@0 | 98 | mRequest->FireSuccess(result); |
michael@0 | 99 | break; |
michael@0 | 100 | } |
michael@0 | 101 | |
michael@0 | 102 | case DeviceStorageResponseValue::TBlobResponse: |
michael@0 | 103 | { |
michael@0 | 104 | BlobResponse r = aValue; |
michael@0 | 105 | BlobChild* actor = static_cast<BlobChild*>(r.blobChild()); |
michael@0 | 106 | nsCOMPtr<nsIDOMBlob> blob = actor->GetBlob(); |
michael@0 | 107 | |
michael@0 | 108 | nsCOMPtr<nsIDOMFile> file = do_QueryInterface(blob); |
michael@0 | 109 | AutoJSContext cx; |
michael@0 | 110 | JS::Rooted<JS::Value> result(cx, |
michael@0 | 111 | InterfaceToJsval(window, file, &NS_GET_IID(nsIDOMFile))); |
michael@0 | 112 | mRequest->FireSuccess(result); |
michael@0 | 113 | break; |
michael@0 | 114 | } |
michael@0 | 115 | |
michael@0 | 116 | case DeviceStorageResponseValue::TFreeSpaceStorageResponse: |
michael@0 | 117 | { |
michael@0 | 118 | FreeSpaceStorageResponse r = aValue; |
michael@0 | 119 | AutoJSContext cx; |
michael@0 | 120 | JS::Rooted<JS::Value> result(cx, JS_NumberValue(double(r.freeBytes()))); |
michael@0 | 121 | mRequest->FireSuccess(result); |
michael@0 | 122 | break; |
michael@0 | 123 | } |
michael@0 | 124 | |
michael@0 | 125 | case DeviceStorageResponseValue::TUsedSpaceStorageResponse: |
michael@0 | 126 | { |
michael@0 | 127 | UsedSpaceStorageResponse r = aValue; |
michael@0 | 128 | AutoJSContext cx; |
michael@0 | 129 | JS::Rooted<JS::Value> result(cx, JS_NumberValue(double(r.usedBytes()))); |
michael@0 | 130 | mRequest->FireSuccess(result); |
michael@0 | 131 | break; |
michael@0 | 132 | } |
michael@0 | 133 | |
michael@0 | 134 | case DeviceStorageResponseValue::TAvailableStorageResponse: |
michael@0 | 135 | { |
michael@0 | 136 | AvailableStorageResponse r = aValue; |
michael@0 | 137 | AutoJSContext cx; |
michael@0 | 138 | JS::Rooted<JS::Value> result( |
michael@0 | 139 | cx, StringToJsval(window, r.mountState())); |
michael@0 | 140 | mRequest->FireSuccess(result); |
michael@0 | 141 | break; |
michael@0 | 142 | } |
michael@0 | 143 | |
michael@0 | 144 | case DeviceStorageResponseValue::TStorageStatusResponse: |
michael@0 | 145 | { |
michael@0 | 146 | StorageStatusResponse r = aValue; |
michael@0 | 147 | AutoJSContext cx; |
michael@0 | 148 | JS::Rooted<JS::Value> result( |
michael@0 | 149 | cx, StringToJsval(window, r.storageStatus())); |
michael@0 | 150 | mRequest->FireSuccess(result); |
michael@0 | 151 | break; |
michael@0 | 152 | } |
michael@0 | 153 | |
michael@0 | 154 | case DeviceStorageResponseValue::TFormatStorageResponse: |
michael@0 | 155 | { |
michael@0 | 156 | FormatStorageResponse r = aValue; |
michael@0 | 157 | AutoJSContext cx; |
michael@0 | 158 | JS::Rooted<JS::Value> result( |
michael@0 | 159 | cx, StringToJsval(window, r.mountState())); |
michael@0 | 160 | mRequest->FireSuccess(result); |
michael@0 | 161 | break; |
michael@0 | 162 | } |
michael@0 | 163 | |
michael@0 | 164 | case DeviceStorageResponseValue::TMountStorageResponse: |
michael@0 | 165 | { |
michael@0 | 166 | MountStorageResponse r = aValue; |
michael@0 | 167 | AutoJSContext cx; |
michael@0 | 168 | JS::Rooted<JS::Value> result( |
michael@0 | 169 | cx, StringToJsval(window, r.storageStatus())); |
michael@0 | 170 | mRequest->FireSuccess(result); |
michael@0 | 171 | break; |
michael@0 | 172 | } |
michael@0 | 173 | |
michael@0 | 174 | case DeviceStorageResponseValue::TUnmountStorageResponse: |
michael@0 | 175 | { |
michael@0 | 176 | UnmountStorageResponse r = aValue; |
michael@0 | 177 | AutoJSContext cx; |
michael@0 | 178 | JS::Rooted<JS::Value> result( |
michael@0 | 179 | cx, StringToJsval(window, r.storageStatus())); |
michael@0 | 180 | mRequest->FireSuccess(result); |
michael@0 | 181 | break; |
michael@0 | 182 | } |
michael@0 | 183 | |
michael@0 | 184 | case DeviceStorageResponseValue::TEnumerationResponse: |
michael@0 | 185 | { |
michael@0 | 186 | EnumerationResponse r = aValue; |
michael@0 | 187 | nsDOMDeviceStorageCursor* cursor |
michael@0 | 188 | = static_cast<nsDOMDeviceStorageCursor*>(mRequest.get()); |
michael@0 | 189 | |
michael@0 | 190 | uint32_t count = r.paths().Length(); |
michael@0 | 191 | for (uint32_t i = 0; i < count; i++) { |
michael@0 | 192 | nsRefPtr<DeviceStorageFile> dsf |
michael@0 | 193 | = new DeviceStorageFile(r.type(), r.paths()[i].storageName(), |
michael@0 | 194 | r.rootdir(), r.paths()[i].name()); |
michael@0 | 195 | cursor->mFiles.AppendElement(dsf); |
michael@0 | 196 | } |
michael@0 | 197 | |
michael@0 | 198 | nsRefPtr<ContinueCursorEvent> event = new ContinueCursorEvent(cursor); |
michael@0 | 199 | event->Continue(); |
michael@0 | 200 | break; |
michael@0 | 201 | } |
michael@0 | 202 | |
michael@0 | 203 | default: |
michael@0 | 204 | { |
michael@0 | 205 | NS_RUNTIMEABORT("not reached"); |
michael@0 | 206 | break; |
michael@0 | 207 | } |
michael@0 | 208 | } |
michael@0 | 209 | return true; |
michael@0 | 210 | } |
michael@0 | 211 | |
michael@0 | 212 | void |
michael@0 | 213 | DeviceStorageRequestChild:: |
michael@0 | 214 | SetCallback(DeviceStorageRequestChildCallback *aCallback) |
michael@0 | 215 | { |
michael@0 | 216 | mCallback = aCallback; |
michael@0 | 217 | } |
michael@0 | 218 | |
michael@0 | 219 | } // namespace devicestorage |
michael@0 | 220 | } // namespace dom |
michael@0 | 221 | } // namespace mozilla |