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 Cu = Components.utils; |
michael@0 | 6 | const Cc = Components.classes; |
michael@0 | 7 | const Ci = Components.interfaces; |
michael@0 | 8 | |
michael@0 | 9 | Cu.import("resource://gre/modules/XPCOMUtils.jsm"); |
michael@0 | 10 | |
michael@0 | 11 | const MAX_CACHE_SIZE = 250; |
michael@0 | 12 | const PREF_UPDATE = "general.useragent.updates."; |
michael@0 | 13 | const PREF_OVERRIDE = "general.useragent.override."; |
michael@0 | 14 | const XPCOM_SHUTDOWN = "xpcom-shutdown"; |
michael@0 | 15 | const HTTP_PROTO_HANDLER = Cc["@mozilla.org/network/protocol;1?name=http"] |
michael@0 | 16 | .getService(Ci.nsIHttpProtocolHandler); |
michael@0 | 17 | |
michael@0 | 18 | XPCOMUtils.defineLazyServiceGetter(this, "cpmm", |
michael@0 | 19 | "@mozilla.org/childprocessmessagemanager;1", |
michael@0 | 20 | "nsISyncMessageSender"); |
michael@0 | 21 | |
michael@0 | 22 | function SiteSpecificUserAgent() { |
michael@0 | 23 | this.inParent = Cc["@mozilla.org/xre/app-info;1"].getService(Ci.nsIXULRuntime) |
michael@0 | 24 | .processType == Ci.nsIXULRuntime.PROCESS_TYPE_DEFAULT; |
michael@0 | 25 | |
michael@0 | 26 | if (this.inParent) { |
michael@0 | 27 | Cu.import("resource://gre/modules/UserAgentOverrides.jsm"); |
michael@0 | 28 | } else { |
michael@0 | 29 | Cu.import("resource://gre/modules/Services.jsm"); |
michael@0 | 30 | Services.prefs.addObserver(PREF_OVERRIDE, this, false); |
michael@0 | 31 | Services.prefs.addObserver(PREF_UPDATE, this, false); |
michael@0 | 32 | Services.obs.addObserver(this, XPCOM_SHUTDOWN, false); |
michael@0 | 33 | this.userAgentCache = new Map; |
michael@0 | 34 | } |
michael@0 | 35 | } |
michael@0 | 36 | |
michael@0 | 37 | SiteSpecificUserAgent.prototype = { |
michael@0 | 38 | getUserAgentForURIAndWindow: function ssua_getUserAgentForURIAndWindow(aURI, aWindow) { |
michael@0 | 39 | if (this.inParent) { |
michael@0 | 40 | return UserAgentOverrides.getOverrideForURI(aURI) || HTTP_PROTO_HANDLER.userAgent; |
michael@0 | 41 | } |
michael@0 | 42 | |
michael@0 | 43 | let host = aURI.asciiHost; |
michael@0 | 44 | let cachedResult = this.userAgentCache.get(host); |
michael@0 | 45 | if (cachedResult) { |
michael@0 | 46 | return cachedResult; |
michael@0 | 47 | } |
michael@0 | 48 | |
michael@0 | 49 | let data = { uri: aURI }; |
michael@0 | 50 | let result = cpmm.sendSyncMessage("Useragent:GetOverride", data)[0] || HTTP_PROTO_HANDLER.userAgent; |
michael@0 | 51 | |
michael@0 | 52 | if (this.userAgentCache.size >= MAX_CACHE_SIZE) { |
michael@0 | 53 | this.userAgentCache.clear(); |
michael@0 | 54 | } |
michael@0 | 55 | |
michael@0 | 56 | this.userAgentCache.set(host, result); |
michael@0 | 57 | return result; |
michael@0 | 58 | }, |
michael@0 | 59 | |
michael@0 | 60 | invalidateCache: function() { |
michael@0 | 61 | this.userAgentCache.clear(); |
michael@0 | 62 | }, |
michael@0 | 63 | |
michael@0 | 64 | clean: function() { |
michael@0 | 65 | this.userAgentCache.clear(); |
michael@0 | 66 | if (!this.inParent) { |
michael@0 | 67 | Services.obs.removeObserver(this, XPCOM_SHUTDOWN); |
michael@0 | 68 | Services.prefs.removeObserver(PREF_OVERRIDE, this); |
michael@0 | 69 | Services.prefs.removeObserver(PREF_UPDATE, this); |
michael@0 | 70 | } |
michael@0 | 71 | }, |
michael@0 | 72 | |
michael@0 | 73 | observe: function(subject, topic, data) { |
michael@0 | 74 | switch (topic) { |
michael@0 | 75 | case "nsPref:changed": |
michael@0 | 76 | this.invalidateCache(); |
michael@0 | 77 | break; |
michael@0 | 78 | case XPCOM_SHUTDOWN: |
michael@0 | 79 | this.clean(); |
michael@0 | 80 | break; |
michael@0 | 81 | } |
michael@0 | 82 | }, |
michael@0 | 83 | |
michael@0 | 84 | classID: Components.ID("{506c680f-3d1c-4954-b351-2c80afbc37d3}"), |
michael@0 | 85 | QueryInterface: XPCOMUtils.generateQI([Ci.nsISiteSpecificUserAgent]) |
michael@0 | 86 | }; |
michael@0 | 87 | |
michael@0 | 88 | this.NSGetFactory = XPCOMUtils.generateNSGetFactory([SiteSpecificUserAgent]); |