Sat, 03 Jan 2015 20:18:00 +0100
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.
michael@0 | 1 | /* This Source Code Form is subject to the terms of the Mozilla Public |
michael@0 | 2 | * License, v. 2.0. If a copy of the MPL was not distributed with this |
michael@0 | 3 | * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ |
michael@0 | 4 | |
michael@0 | 5 | 'use strict'; |
michael@0 | 6 | |
michael@0 | 7 | module.metadata = { |
michael@0 | 8 | "stability": "unstable" |
michael@0 | 9 | }; |
michael@0 | 10 | |
michael@0 | 11 | const { Cc, Ci, CC } = require('chrome'); |
michael@0 | 12 | const options = require('@loader/options'); |
michael@0 | 13 | const file = require('./io/file'); |
michael@0 | 14 | const runtime = require("./system/runtime"); |
michael@0 | 15 | |
michael@0 | 16 | const appStartup = Cc['@mozilla.org/toolkit/app-startup;1']. |
michael@0 | 17 | getService(Ci.nsIAppStartup); |
michael@0 | 18 | const appInfo = Cc["@mozilla.org/xre/app-info;1"]. |
michael@0 | 19 | getService(Ci.nsIXULAppInfo); |
michael@0 | 20 | const directoryService = Cc['@mozilla.org/file/directory_service;1']. |
michael@0 | 21 | getService(Ci.nsIProperties); |
michael@0 | 22 | |
michael@0 | 23 | const PR_WRONLY = parseInt("0x02"); |
michael@0 | 24 | const PR_CREATE_FILE = parseInt("0x08"); |
michael@0 | 25 | const PR_APPEND = parseInt("0x10"); |
michael@0 | 26 | const PR_TRUNCATE = parseInt("0x20"); |
michael@0 | 27 | |
michael@0 | 28 | function openFile(path, mode) { |
michael@0 | 29 | let file = Cc["@mozilla.org/file/local;1"]. |
michael@0 | 30 | createInstance(Ci.nsILocalFile); |
michael@0 | 31 | file.initWithPath(path); |
michael@0 | 32 | let stream = Cc["@mozilla.org/network/file-output-stream;1"]. |
michael@0 | 33 | createInstance(Ci.nsIFileOutputStream); |
michael@0 | 34 | stream.init(file, mode, -1, 0); |
michael@0 | 35 | return stream |
michael@0 | 36 | } |
michael@0 | 37 | |
michael@0 | 38 | const { eAttemptQuit: E_ATTEMPT, eForceQuit: E_FORCE } = appStartup; |
michael@0 | 39 | |
michael@0 | 40 | /** |
michael@0 | 41 | * Parsed JSON object that was passed via `cfx --static-args "{ foo: 'bar' }"` |
michael@0 | 42 | */ |
michael@0 | 43 | exports.staticArgs = options.staticArgs; |
michael@0 | 44 | |
michael@0 | 45 | /** |
michael@0 | 46 | * Environment variables. Environment variables are non-enumerable properties |
michael@0 | 47 | * of this object (key is name and value is value). |
michael@0 | 48 | */ |
michael@0 | 49 | exports.env = require('./system/environment').env; |
michael@0 | 50 | |
michael@0 | 51 | /** |
michael@0 | 52 | * Ends the process with the specified `code`. If omitted, exit uses the |
michael@0 | 53 | * 'success' code 0. To exit with failure use `1`. |
michael@0 | 54 | * TODO: Improve platform to actually quit with an exit code. |
michael@0 | 55 | */ |
michael@0 | 56 | let forcedExit = false; |
michael@0 | 57 | exports.exit = function exit(code) { |
michael@0 | 58 | if (forcedExit) { |
michael@0 | 59 | // a forced exit was already tried |
michael@0 | 60 | // NOTE: exit(0) is called twice sometimes (ex when using cfx testaddons) |
michael@0 | 61 | return; |
michael@0 | 62 | } |
michael@0 | 63 | |
michael@0 | 64 | // This is used by 'cfx' to find out exit code. |
michael@0 | 65 | if ('resultFile' in options && options.resultFile) { |
michael@0 | 66 | let mode = PR_WRONLY | PR_CREATE_FILE | PR_TRUNCATE; |
michael@0 | 67 | let stream = openFile(options.resultFile, mode); |
michael@0 | 68 | let status = code ? 'FAIL' : 'OK'; |
michael@0 | 69 | stream.write(status, status.length); |
michael@0 | 70 | stream.flush(); |
michael@0 | 71 | stream.close(); |
michael@0 | 72 | } |
michael@0 | 73 | |
michael@0 | 74 | if (code == 0) { |
michael@0 | 75 | forcedExit = true; |
michael@0 | 76 | } |
michael@0 | 77 | appStartup.quit(code ? E_ATTEMPT : E_FORCE); |
michael@0 | 78 | }; |
michael@0 | 79 | |
michael@0 | 80 | // Adapter for nodejs's stdout & stderr: |
michael@0 | 81 | // http://nodejs.org/api/process.html#process_process_stdout |
michael@0 | 82 | let stdout = Object.freeze({ write: dump, end: dump }); |
michael@0 | 83 | exports.stdout = stdout; |
michael@0 | 84 | exports.stderr = stdout; |
michael@0 | 85 | |
michael@0 | 86 | /** |
michael@0 | 87 | * Returns a path of the system's or application's special directory / file |
michael@0 | 88 | * associated with a given `id`. For list of possible `id`s please see: |
michael@0 | 89 | * https://developer.mozilla.org/en-US/docs/Code_snippets/File_I_O#Getting_files_in_special_directories |
michael@0 | 90 | * http://mxr.mozilla.org/mozilla-central/source/xpcom/io/nsAppDirectoryServiceDefs.h |
michael@0 | 91 | * @example |
michael@0 | 92 | * |
michael@0 | 93 | * // get firefox profile path |
michael@0 | 94 | * let profilePath = require('system').pathFor('ProfD'); |
michael@0 | 95 | * // get OS temp files directory (/tmp) |
michael@0 | 96 | * let temps = require('system').pathFor('TmpD'); |
michael@0 | 97 | * // get OS desktop path for an active user (~/Desktop on linux |
michael@0 | 98 | * // or C:\Documents and Settings\username\Desktop on windows). |
michael@0 | 99 | * let desktopPath = require('system').pathFor('Desk'); |
michael@0 | 100 | */ |
michael@0 | 101 | exports.pathFor = function pathFor(id) { |
michael@0 | 102 | return directoryService.get(id, Ci.nsIFile).path; |
michael@0 | 103 | }; |
michael@0 | 104 | |
michael@0 | 105 | /** |
michael@0 | 106 | * What platform you're running on (all lower case string). |
michael@0 | 107 | * For possible values see: |
michael@0 | 108 | * https://developer.mozilla.org/en/OS_TARGET |
michael@0 | 109 | */ |
michael@0 | 110 | exports.platform = runtime.OS.toLowerCase(); |
michael@0 | 111 | |
michael@0 | 112 | const [, architecture, compiler] = runtime.XPCOMABI ? |
michael@0 | 113 | runtime.XPCOMABI.match(/^([^-]*)-(.*)$/) : |
michael@0 | 114 | [, null, null]; |
michael@0 | 115 | |
michael@0 | 116 | /** |
michael@0 | 117 | * What processor architecture you're running on: |
michael@0 | 118 | * `'arm', 'ia32', or 'x64'`. |
michael@0 | 119 | */ |
michael@0 | 120 | exports.architecture = architecture; |
michael@0 | 121 | |
michael@0 | 122 | /** |
michael@0 | 123 | * What compiler used for build: |
michael@0 | 124 | * `'msvc', 'n32', 'gcc2', 'gcc3', 'sunc', 'ibmc'...` |
michael@0 | 125 | */ |
michael@0 | 126 | exports.compiler = compiler; |
michael@0 | 127 | |
michael@0 | 128 | /** |
michael@0 | 129 | * The application's build ID/date, for example "2004051604". |
michael@0 | 130 | */ |
michael@0 | 131 | exports.build = appInfo.appBuildID; |
michael@0 | 132 | |
michael@0 | 133 | /** |
michael@0 | 134 | * The XUL application's UUID. |
michael@0 | 135 | * This has traditionally been in the form |
michael@0 | 136 | * `{AAAAAAAA-BBBB-CCCC-DDDD-EEEEEEEEEEEE}` but for some applications it may |
michael@0 | 137 | * be: "appname@vendor.tld". |
michael@0 | 138 | */ |
michael@0 | 139 | exports.id = appInfo.ID; |
michael@0 | 140 | |
michael@0 | 141 | /** |
michael@0 | 142 | * The name of the application. |
michael@0 | 143 | */ |
michael@0 | 144 | exports.name = appInfo.name; |
michael@0 | 145 | |
michael@0 | 146 | /** |
michael@0 | 147 | * The XUL application's version, for example "0.8.0+" or "3.7a1pre". |
michael@0 | 148 | */ |
michael@0 | 149 | exports.version = appInfo.version; |
michael@0 | 150 | |
michael@0 | 151 | /** |
michael@0 | 152 | * XULRunner version. |
michael@0 | 153 | */ |
michael@0 | 154 | exports.platformVersion = appInfo.platformVersion; |
michael@0 | 155 | |
michael@0 | 156 | |
michael@0 | 157 | /** |
michael@0 | 158 | * The name of the application vendor, for example "Mozilla". |
michael@0 | 159 | */ |
michael@0 | 160 | exports.vendor = appInfo.vendor; |