toolkit/components/osfile/modules/osfile_native.jsm

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 /* This Source Code Form is subject to the terms of the Mozilla Public
     2  * License, v. 2.0. If a copy of the MPL was not distributed with this file,
     3  * You can obtain one at http://mozilla.org/MPL/2.0/. */
     5 /**
     6  * Native (xpcom) implementation of key OS.File functions
     7  */
     9 "use strict";
    11 this.EXPORTED_SYMBOLS = ["read"];
    13 let {results: Cr, utils: Cu, interfaces: Ci} = Components;
    15 let SharedAll = Cu.import("resource://gre/modules/osfile/osfile_shared_allthreads.jsm", {});
    17 let SysAll = {};
    18 if (SharedAll.Constants.Win) {
    19   Cu.import("resource://gre/modules/osfile/osfile_win_allthreads.jsm", SysAll);
    20 } else if (SharedAll.Constants.libc) {
    21   Cu.import("resource://gre/modules/osfile/osfile_unix_allthreads.jsm", SysAll);
    22 } else {
    23   throw new Error("I am neither under Windows nor under a Posix system");
    24 }
    25 let {Promise} = Cu.import("resource://gre/modules/Promise.jsm", {});
    26 let {XPCOMUtils} = Cu.import("resource://gre/modules/XPCOMUtils.jsm", {});
    28 /**
    29  * The native service holding the implementation of the functions.
    30  */
    31 XPCOMUtils.defineLazyServiceGetter(this,
    32   "Internals",
    33   "@mozilla.org/toolkit/osfile/native-internals;1",
    34   "nsINativeOSFileInternalsService");
    36 /**
    37  * Native implementation of OS.File.read
    38  *
    39  * This implementation does not handle option |compression|.
    40  */
    41 this.read = function(path, options = {}) {
    42   // Sanity check on types of options
    43   if ("encoding" in options && typeof options.encoding != "string") {
    44     return Promise.reject(new TypeError("Invalid type for option encoding"));
    45   }
    46   if ("compression" in options && typeof options.compression != "string") {
    47     return Promise.reject(new TypeError("Invalid type for option compression"));
    48   }
    49   if ("bytes" in options && typeof options.bytes != "number") {
    50     return Promise.reject(new TypeError("Invalid type for option bytes"));
    51   }
    53   let deferred = Promise.defer();
    54   Internals.read(path,
    55     options,
    56     function onSuccess(success) {
    57       success.QueryInterface(Ci.nsINativeOSFileResult);
    58       if ("outExecutionDuration" in options) {
    59         options.outExecutionDuration =
    60           success.executionDurationMS +
    61           (options.outExecutionDuration || 0);
    62       }
    63       deferred.resolve(success.result);
    64     },
    65     function onError(operation, oserror) {
    66       deferred.reject(new SysAll.Error(operation, oserror, path));
    67     }
    68   );
    69   return deferred.promise;
    70 };

mercurial