dom/devicestorage/DeviceStorageRequestChild.cpp

Sat, 03 Jan 2015 20:18:00 +0100

author
Michael Schloh von Bennewitz <michael@schloh.com>
date
Sat, 03 Jan 2015 20:18:00 +0100
branch
TOR_BUG_3246
changeset 7
129ffea94266
permissions
-rw-r--r--

Conditionally enable double key logic according to:
private browsing mode or privacy.thirdparty.isolate preference and
implement in GetCookieStringCommon and FindCookie where it counts...
With some reservations of how to convince FindCookie users to test
condition and pass a nullptr when disabling double key logic.

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

mercurial