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 | const {Cc, Ci, Cu, CC} = require("chrome"); |
michael@0 | 6 | const Services = require("Services"); |
michael@0 | 7 | const protocol = require("devtools/server/protocol"); |
michael@0 | 8 | const {method, RetVal} = protocol; |
michael@0 | 9 | const {Promise: promise} = Cu.import("resource://gre/modules/Promise.jsm", {}); |
michael@0 | 10 | const {LongStringActor} = require("devtools/server/actors/string"); |
michael@0 | 11 | const {DebuggerServer} = require("devtools/server/main"); |
michael@0 | 12 | |
michael@0 | 13 | Cu.import("resource://gre/modules/PermissionsTable.jsm") |
michael@0 | 14 | |
michael@0 | 15 | const APP_MAP = { |
michael@0 | 16 | '{ec8030f7-c20a-464f-9b0e-13a3a9e97384}': 'firefox', |
michael@0 | 17 | '{3550f703-e582-4d05-9a08-453d09bdfdc6}': 'thunderbird', |
michael@0 | 18 | '{92650c4d-4b8e-4d2a-b7eb-24ecf4f6b63a}': 'seamonkey', |
michael@0 | 19 | '{718e30fb-e89b-41dd-9da7-e25a45638b28}': 'sunbird', |
michael@0 | 20 | '{3c2e2abc-06d4-11e1-ac3b-374f68613e61}': 'b2g', |
michael@0 | 21 | '{aa3c5121-dab2-40e2-81ca-7ea25febc110}': 'mobile/android', |
michael@0 | 22 | '{a23983c0-fd0e-11dc-95ff-0800200c9a66}': 'mobile/xul' |
michael@0 | 23 | } |
michael@0 | 24 | |
michael@0 | 25 | exports.register = function(handle) { |
michael@0 | 26 | handle.addGlobalActor(DeviceActor, "deviceActor"); |
michael@0 | 27 | }; |
michael@0 | 28 | |
michael@0 | 29 | exports.unregister = function(handle) { |
michael@0 | 30 | }; |
michael@0 | 31 | |
michael@0 | 32 | let DeviceActor = protocol.ActorClass({ |
michael@0 | 33 | typeName: "device", |
michael@0 | 34 | |
michael@0 | 35 | _desc: null, |
michael@0 | 36 | |
michael@0 | 37 | _getAppIniString : function(section, key) { |
michael@0 | 38 | let inifile = Services.dirsvc.get("GreD", Ci.nsIFile); |
michael@0 | 39 | inifile.append("application.ini"); |
michael@0 | 40 | |
michael@0 | 41 | if (!inifile.exists()) { |
michael@0 | 42 | inifile = Services.dirsvc.get("CurProcD", Ci.nsIFile); |
michael@0 | 43 | inifile.append("application.ini"); |
michael@0 | 44 | } |
michael@0 | 45 | |
michael@0 | 46 | if (!inifile.exists()) { |
michael@0 | 47 | return undefined; |
michael@0 | 48 | } |
michael@0 | 49 | |
michael@0 | 50 | let iniParser = Cc["@mozilla.org/xpcom/ini-parser-factory;1"].getService(Ci.nsIINIParserFactory).createINIParser(inifile); |
michael@0 | 51 | try { |
michael@0 | 52 | return iniParser.getString(section, key); |
michael@0 | 53 | } catch (e) { |
michael@0 | 54 | return undefined; |
michael@0 | 55 | } |
michael@0 | 56 | }, |
michael@0 | 57 | |
michael@0 | 58 | _getSetting: function(name) { |
michael@0 | 59 | let deferred = promise.defer(); |
michael@0 | 60 | |
michael@0 | 61 | if ("@mozilla.org/settingsService;1" in Cc) { |
michael@0 | 62 | let settingsService = Cc["@mozilla.org/settingsService;1"].getService(Ci.nsISettingsService); |
michael@0 | 63 | let req = settingsService.createLock().get(name, { |
michael@0 | 64 | handle: (name, value) => deferred.resolve(value), |
michael@0 | 65 | handleError: (error) => deferred.reject(error), |
michael@0 | 66 | }); |
michael@0 | 67 | } else { |
michael@0 | 68 | deferred.reject(new Error("No settings service")); |
michael@0 | 69 | } |
michael@0 | 70 | return deferred.promise; |
michael@0 | 71 | }, |
michael@0 | 72 | |
michael@0 | 73 | getDescription: method(function() { |
michael@0 | 74 | // Most of this code is inspired from Nightly Tester Tools: |
michael@0 | 75 | // https://wiki.mozilla.org/Auto-tools/Projects/NightlyTesterTools |
michael@0 | 76 | |
michael@0 | 77 | let appInfo = Services.appinfo; |
michael@0 | 78 | let win = Services.wm.getMostRecentWindow(DebuggerServer.chromeWindowType); |
michael@0 | 79 | let utils = win.QueryInterface(Ci.nsIInterfaceRequestor).getInterface(Ci.nsIDOMWindowUtils); |
michael@0 | 80 | |
michael@0 | 81 | desc = { |
michael@0 | 82 | appid: appInfo.ID, |
michael@0 | 83 | apptype: APP_MAP[appInfo.ID], |
michael@0 | 84 | vendor: appInfo.vendor, |
michael@0 | 85 | name: appInfo.name, |
michael@0 | 86 | version: appInfo.version, |
michael@0 | 87 | appbuildid: appInfo.appBuildID, |
michael@0 | 88 | platformbuildid: appInfo.platformBuildID, |
michael@0 | 89 | platformversion: appInfo.platformVersion, |
michael@0 | 90 | geckobuildid: appInfo.platformBuildID, |
michael@0 | 91 | geckoversion: appInfo.platformVersion, |
michael@0 | 92 | changeset: this._getAppIniString("App", "SourceStamp"), |
michael@0 | 93 | useragent: win.navigator.userAgent, |
michael@0 | 94 | locale: Cc["@mozilla.org/chrome/chrome-registry;1"].getService(Ci.nsIXULChromeRegistry).getSelectedLocale("global"), |
michael@0 | 95 | os: null, |
michael@0 | 96 | hardware: "unknown", |
michael@0 | 97 | processor: appInfo.XPCOMABI.split("-")[0], |
michael@0 | 98 | compiler: appInfo.XPCOMABI.split("-")[1], |
michael@0 | 99 | dpi: utils.displayDPI, |
michael@0 | 100 | brandName: null, |
michael@0 | 101 | channel: null, |
michael@0 | 102 | profile: null, |
michael@0 | 103 | width: win.screen.width, |
michael@0 | 104 | height: win.screen.height |
michael@0 | 105 | }; |
michael@0 | 106 | |
michael@0 | 107 | // Profile |
michael@0 | 108 | let profd = Services.dirsvc.get("ProfD", Ci.nsILocalFile); |
michael@0 | 109 | let profservice = Cc["@mozilla.org/toolkit/profile-service;1"].getService(Ci.nsIToolkitProfileService); |
michael@0 | 110 | var profiles = profservice.profiles; |
michael@0 | 111 | while (profiles.hasMoreElements()) { |
michael@0 | 112 | let profile = profiles.getNext().QueryInterface(Ci.nsIToolkitProfile); |
michael@0 | 113 | if (profile.rootDir.path == profd.path) { |
michael@0 | 114 | desc.profile = profile.name; |
michael@0 | 115 | break; |
michael@0 | 116 | } |
michael@0 | 117 | } |
michael@0 | 118 | |
michael@0 | 119 | if (!desc.profile) { |
michael@0 | 120 | desc.profile = profd.leafName; |
michael@0 | 121 | } |
michael@0 | 122 | |
michael@0 | 123 | // Channel |
michael@0 | 124 | try { |
michael@0 | 125 | desc.channel = Services.prefs.getCharPref('app.update.channel'); |
michael@0 | 126 | } catch(e) {} |
michael@0 | 127 | |
michael@0 | 128 | if (desc.apptype == "b2g") { |
michael@0 | 129 | // B2G specific |
michael@0 | 130 | desc.os = "B2G"; |
michael@0 | 131 | |
michael@0 | 132 | return this._getSetting('deviceinfo.hardware') |
michael@0 | 133 | .then(value => desc.hardware = value) |
michael@0 | 134 | .then(() => this._getSetting('deviceinfo.os')) |
michael@0 | 135 | .then(value => desc.version = value) |
michael@0 | 136 | .then(() => desc); |
michael@0 | 137 | } |
michael@0 | 138 | |
michael@0 | 139 | // Not B2G |
michael@0 | 140 | desc.os = appInfo.OS; |
michael@0 | 141 | let bundle = Services.strings.createBundle("chrome://branding/locale/brand.properties"); |
michael@0 | 142 | if (bundle) { |
michael@0 | 143 | desc.brandName = bundle.GetStringFromName("brandFullName"); |
michael@0 | 144 | } |
michael@0 | 145 | |
michael@0 | 146 | return desc; |
michael@0 | 147 | |
michael@0 | 148 | }, {request: {},response: { value: RetVal("json")}}), |
michael@0 | 149 | |
michael@0 | 150 | getWallpaper: method(function() { |
michael@0 | 151 | let deferred = promise.defer(); |
michael@0 | 152 | this._getSetting("wallpaper.image").then((blob) => { |
michael@0 | 153 | let FileReader = CC("@mozilla.org/files/filereader;1"); |
michael@0 | 154 | let reader = new FileReader(); |
michael@0 | 155 | let conn = this.conn; |
michael@0 | 156 | reader.addEventListener("load", function() { |
michael@0 | 157 | let str = new LongStringActor(conn, reader.result); |
michael@0 | 158 | deferred.resolve(str); |
michael@0 | 159 | }); |
michael@0 | 160 | reader.addEventListener("error", function() { |
michael@0 | 161 | deferred.reject(reader.error); |
michael@0 | 162 | }); |
michael@0 | 163 | reader.readAsDataURL(blob); |
michael@0 | 164 | }); |
michael@0 | 165 | return deferred.promise; |
michael@0 | 166 | }, {request: {},response: { value: RetVal("longstring")}}), |
michael@0 | 167 | |
michael@0 | 168 | screenshotToDataURL: method(function() { |
michael@0 | 169 | let window = Services.wm.getMostRecentWindow(DebuggerServer.chromeWindowType); |
michael@0 | 170 | let canvas = window.document.createElementNS("http://www.w3.org/1999/xhtml", "canvas"); |
michael@0 | 171 | let width = window.innerWidth; |
michael@0 | 172 | let height = window.innerHeight; |
michael@0 | 173 | canvas.setAttribute('width', width); |
michael@0 | 174 | canvas.setAttribute('height', height); |
michael@0 | 175 | let context = canvas.getContext('2d'); |
michael@0 | 176 | let flags = |
michael@0 | 177 | context.DRAWWINDOW_DRAW_CARET | |
michael@0 | 178 | context.DRAWWINDOW_DRAW_VIEW | |
michael@0 | 179 | context.DRAWWINDOW_USE_WIDGET_LAYERS; |
michael@0 | 180 | context.drawWindow(window, 0, 0, width, height, 'rgb(255,255,255)', flags); |
michael@0 | 181 | let dataURL = canvas.toDataURL('image/png') |
michael@0 | 182 | return new LongStringActor(this.conn, dataURL); |
michael@0 | 183 | }, {request: {},response: { value: RetVal("longstring")}}), |
michael@0 | 184 | |
michael@0 | 185 | getRawPermissionsTable: method(function() { |
michael@0 | 186 | return { |
michael@0 | 187 | rawPermissionsTable: PermissionsTable, |
michael@0 | 188 | UNKNOWN_ACTION: Ci.nsIPermissionManager.UNKNOWN_ACTION, |
michael@0 | 189 | ALLOW_ACTION: Ci.nsIPermissionManager.ALLOW_ACTION, |
michael@0 | 190 | DENY_ACTION: Ci.nsIPermissionManager.DENY_ACTION, |
michael@0 | 191 | PROMPT_ACTION: Ci.nsIPermissionManager.PROMPT_ACTION |
michael@0 | 192 | }; |
michael@0 | 193 | }, {request: {},response: { value: RetVal("json")}}) |
michael@0 | 194 | }); |
michael@0 | 195 | |
michael@0 | 196 | let DeviceFront = protocol.FrontClass(DeviceActor, { |
michael@0 | 197 | initialize: function(client, form) { |
michael@0 | 198 | protocol.Front.prototype.initialize.call(this, client); |
michael@0 | 199 | this.actorID = form.deviceActor; |
michael@0 | 200 | client.addActorPool(this); |
michael@0 | 201 | this.manage(this); |
michael@0 | 202 | }, |
michael@0 | 203 | |
michael@0 | 204 | screenshotToBlob: function() { |
michael@0 | 205 | return this.screenshotToDataURL().then(longstr => { |
michael@0 | 206 | return longstr.string().then(dataURL => { |
michael@0 | 207 | let deferred = promise.defer(); |
michael@0 | 208 | longstr.release().then(null, Cu.reportError); |
michael@0 | 209 | let req = Cc["@mozilla.org/xmlextras/xmlhttprequest;1"].createInstance(Ci.nsIXMLHttpRequest); |
michael@0 | 210 | req.open("GET", dataURL, true); |
michael@0 | 211 | req.responseType = "blob"; |
michael@0 | 212 | req.onload = () => { |
michael@0 | 213 | deferred.resolve(req.response); |
michael@0 | 214 | }; |
michael@0 | 215 | req.onerror = () => { |
michael@0 | 216 | deferred.reject(req.status); |
michael@0 | 217 | } |
michael@0 | 218 | req.send(); |
michael@0 | 219 | return deferred.promise; |
michael@0 | 220 | }); |
michael@0 | 221 | }); |
michael@0 | 222 | }, |
michael@0 | 223 | }); |
michael@0 | 224 | |
michael@0 | 225 | const _knownDeviceFronts = new WeakMap(); |
michael@0 | 226 | |
michael@0 | 227 | exports.getDeviceFront = function(client, form) { |
michael@0 | 228 | if (_knownDeviceFronts.has(client)) |
michael@0 | 229 | return _knownDeviceFronts.get(client); |
michael@0 | 230 | |
michael@0 | 231 | let front = new DeviceFront(client, form); |
michael@0 | 232 | _knownDeviceFronts.set(client, front); |
michael@0 | 233 | return front; |
michael@0 | 234 | } |