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 file, |
michael@0 | 3 | * You can obtain one at http://mozilla.org/MPL/2.0/. */ |
michael@0 | 4 | |
michael@0 | 5 | /* PermissionPromptHelper checks the permissionDB for a given permission |
michael@0 | 6 | * name and performs prompting if needed. |
michael@0 | 7 | * Usage: send PermissionPromptHelper:AskPermission via the FrameMessageManager with: |
michael@0 | 8 | * |origin|, |appID|, |browserFlag| -> used for getting the principal and |
michael@0 | 9 | * |type| and |access| to call testExactPermissionFromPrincipal. |
michael@0 | 10 | * Note that |access| isn't currently used. |
michael@0 | 11 | * Other arugments are: |
michael@0 | 12 | * requestID: ID that gets returned with the result message. |
michael@0 | 13 | * |
michael@0 | 14 | * Once the permission is checked, it returns with the message |
michael@0 | 15 | * "PermissionPromptHelper:AskPermission:OK" |
michael@0 | 16 | * The result contains the |result| e.g.Ci.nsIPermissionManager.ALLOW_ACTION |
michael@0 | 17 | * and a requestID that |
michael@0 | 18 | */ |
michael@0 | 19 | |
michael@0 | 20 | "use strict"; |
michael@0 | 21 | |
michael@0 | 22 | let DEBUG = 0; |
michael@0 | 23 | let debug; |
michael@0 | 24 | if (DEBUG) |
michael@0 | 25 | debug = function (s) { dump("-*- Permission Prompt Helper component: " + s + "\n"); } |
michael@0 | 26 | else |
michael@0 | 27 | debug = function (s) {} |
michael@0 | 28 | |
michael@0 | 29 | const Cu = Components.utils; |
michael@0 | 30 | const Cc = Components.classes; |
michael@0 | 31 | const Ci = Components.interfaces; |
michael@0 | 32 | |
michael@0 | 33 | this.EXPORTED_SYMBOLS = ["PermissionPromptHelper"]; |
michael@0 | 34 | |
michael@0 | 35 | Cu.import("resource://gre/modules/XPCOMUtils.jsm"); |
michael@0 | 36 | Cu.import("resource://gre/modules/Services.jsm"); |
michael@0 | 37 | |
michael@0 | 38 | XPCOMUtils.defineLazyServiceGetter(this, "ppmm", |
michael@0 | 39 | "@mozilla.org/parentprocessmessagemanager;1", |
michael@0 | 40 | "nsIMessageListenerManager"); |
michael@0 | 41 | |
michael@0 | 42 | XPCOMUtils.defineLazyServiceGetter(this, "permissionPromptService", |
michael@0 | 43 | "@mozilla.org/permission-prompt-service;1", |
michael@0 | 44 | "nsIPermissionPromptService"); |
michael@0 | 45 | |
michael@0 | 46 | let appsService = Cc["@mozilla.org/AppsService;1"].getService(Ci.nsIAppsService); |
michael@0 | 47 | |
michael@0 | 48 | this.PermissionPromptHelper = { |
michael@0 | 49 | init: function init() { |
michael@0 | 50 | debug("Init"); |
michael@0 | 51 | ppmm.addMessageListener("PermissionPromptHelper:AskPermission", this); |
michael@0 | 52 | Services.obs.addObserver(this, "profile-before-change", false); |
michael@0 | 53 | }, |
michael@0 | 54 | |
michael@0 | 55 | askPermission: function askPermission(aMessage, aCallbacks) { |
michael@0 | 56 | let msg = aMessage.json; |
michael@0 | 57 | |
michael@0 | 58 | let access = msg.type; |
michael@0 | 59 | if (msg.access) { |
michael@0 | 60 | access = access + "-" + msg.access; |
michael@0 | 61 | } |
michael@0 | 62 | |
michael@0 | 63 | let uri = Services.io.newURI(msg.origin, null, null); |
michael@0 | 64 | let principal = |
michael@0 | 65 | Services.scriptSecurityManager.getAppCodebasePrincipal(uri, msg.appID, msg.browserFlag); |
michael@0 | 66 | |
michael@0 | 67 | let permValue = |
michael@0 | 68 | Services.perms.testExactPermissionFromPrincipal(principal, access); |
michael@0 | 69 | |
michael@0 | 70 | if (permValue == Ci.nsIPermissionManager.DENY_ACTION || |
michael@0 | 71 | permValue == Ci.nsIPermissionManager.UNKNOWN_ACTION) { |
michael@0 | 72 | aCallbacks.cancel(); |
michael@0 | 73 | return; |
michael@0 | 74 | } |
michael@0 | 75 | |
michael@0 | 76 | if (permValue == Ci.nsIPermissionManager.PROMPT_ACTION) { |
michael@0 | 77 | |
michael@0 | 78 | // create the options from permission request. |
michael@0 | 79 | let options = Cc["@mozilla.org/array;1"].createInstance(Ci.nsIMutableArray); |
michael@0 | 80 | if (msg.options) { |
michael@0 | 81 | for (let option of options) { |
michael@0 | 82 | options.appendElement(option); |
michael@0 | 83 | } |
michael@0 | 84 | } |
michael@0 | 85 | |
michael@0 | 86 | // create an array with a nsIContentPermissionType element |
michael@0 | 87 | let type = { |
michael@0 | 88 | type: msg.type, |
michael@0 | 89 | access: msg.access ? msg.access : "unused", |
michael@0 | 90 | options: options, |
michael@0 | 91 | QueryInterface: XPCOMUtils.generateQI([Ci.nsIContentPermissionType]) |
michael@0 | 92 | }; |
michael@0 | 93 | let typeArray = Cc["@mozilla.org/array;1"].createInstance(Ci.nsIMutableArray); |
michael@0 | 94 | typeArray.appendElement(type, false); |
michael@0 | 95 | |
michael@0 | 96 | // create a nsIContentPermissionRequest |
michael@0 | 97 | let request = { |
michael@0 | 98 | types: typeArray, |
michael@0 | 99 | principal: principal, |
michael@0 | 100 | QueryInterface: XPCOMUtils.generateQI([Ci.nsIContentPermissionRequest]), |
michael@0 | 101 | allow: aCallbacks.allow, |
michael@0 | 102 | cancel: aCallbacks.cancel, |
michael@0 | 103 | window: Services.wm.getOuterWindowWithId(msg.windowID) |
michael@0 | 104 | }; |
michael@0 | 105 | |
michael@0 | 106 | permissionPromptService.getPermission(request); |
michael@0 | 107 | return; |
michael@0 | 108 | } |
michael@0 | 109 | |
michael@0 | 110 | if (permValue == Ci.nsIPermissionManager.ALLOW_ACTION) { |
michael@0 | 111 | aCallbacks.allow(); |
michael@0 | 112 | return; |
michael@0 | 113 | } |
michael@0 | 114 | }, |
michael@0 | 115 | |
michael@0 | 116 | observe: function observe(aSubject, aTopic, aData) { |
michael@0 | 117 | ppmm.removeMessageListener("PermissionPromptHelper:AskPermission", this); |
michael@0 | 118 | Services.obs.removeObserver(this, "profile-before-change"); |
michael@0 | 119 | ppmm = null; |
michael@0 | 120 | }, |
michael@0 | 121 | |
michael@0 | 122 | receiveMessage: function receiveMessage(aMessage) { |
michael@0 | 123 | debug("PermissionPromptHelper::receiveMessage " + aMessage.name); |
michael@0 | 124 | let mm = aMessage.target; |
michael@0 | 125 | let msg = aMessage.data; |
michael@0 | 126 | |
michael@0 | 127 | let result; |
michael@0 | 128 | if (aMessage.name == "PermissionPromptHelper:AskPermission") { |
michael@0 | 129 | this.askPermission(aMessage, { |
michael@0 | 130 | cancel: function() { |
michael@0 | 131 | mm.sendAsyncMessage("PermissionPromptHelper:AskPermission:OK", |
michael@0 | 132 | { result: Ci.nsIPermissionManager.DENY_ACTION, |
michael@0 | 133 | requestID: msg.requestID }); |
michael@0 | 134 | }, |
michael@0 | 135 | allow: function(aChoice) { |
michael@0 | 136 | mm.sendAsyncMessage("PermissionPromptHelper:AskPermission:OK", |
michael@0 | 137 | { result: Ci.nsIPermissionManager.ALLOW_ACTION, |
michael@0 | 138 | choice: aChoice, |
michael@0 | 139 | requestID: msg.requestID }); |
michael@0 | 140 | } |
michael@0 | 141 | }); |
michael@0 | 142 | } |
michael@0 | 143 | } |
michael@0 | 144 | } |
michael@0 | 145 | |
michael@0 | 146 | PermissionPromptHelper.init(); |