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 | /** |
michael@0 | 6 | * PageThumbsProtocol.js |
michael@0 | 7 | * |
michael@0 | 8 | * This file implements the moz-page-thumb:// protocol and the corresponding |
michael@0 | 9 | * channel delivering cached thumbnails. |
michael@0 | 10 | * |
michael@0 | 11 | * URL structure: |
michael@0 | 12 | * |
michael@0 | 13 | * moz-page-thumb://thumbnail?url=http%3A%2F%2Fwww.mozilla.org%2F |
michael@0 | 14 | * |
michael@0 | 15 | * This URL requests an image for 'http://www.mozilla.org/'. |
michael@0 | 16 | */ |
michael@0 | 17 | |
michael@0 | 18 | "use strict"; |
michael@0 | 19 | |
michael@0 | 20 | const Cu = Components.utils; |
michael@0 | 21 | const Cc = Components.classes; |
michael@0 | 22 | const Cr = Components.results; |
michael@0 | 23 | const Ci = Components.interfaces; |
michael@0 | 24 | |
michael@0 | 25 | Cu.import("resource://gre/modules/PageThumbs.jsm"); |
michael@0 | 26 | Cu.import("resource://gre/modules/XPCOMUtils.jsm"); |
michael@0 | 27 | |
michael@0 | 28 | XPCOMUtils.defineLazyModuleGetter(this, "Services", |
michael@0 | 29 | "resource://gre/modules/Services.jsm"); |
michael@0 | 30 | XPCOMUtils.defineLazyModuleGetter(this, "FileUtils", |
michael@0 | 31 | "resource://gre/modules/FileUtils.jsm"); |
michael@0 | 32 | |
michael@0 | 33 | /** |
michael@0 | 34 | * Implements the thumbnail protocol handler responsible for moz-page-thumb: URIs. |
michael@0 | 35 | */ |
michael@0 | 36 | function Protocol() { |
michael@0 | 37 | } |
michael@0 | 38 | |
michael@0 | 39 | Protocol.prototype = { |
michael@0 | 40 | /** |
michael@0 | 41 | * The scheme used by this protocol. |
michael@0 | 42 | */ |
michael@0 | 43 | get scheme() PageThumbs.scheme, |
michael@0 | 44 | |
michael@0 | 45 | /** |
michael@0 | 46 | * The default port for this protocol (we don't support ports). |
michael@0 | 47 | */ |
michael@0 | 48 | get defaultPort() -1, |
michael@0 | 49 | |
michael@0 | 50 | /** |
michael@0 | 51 | * The flags specific to this protocol implementation. |
michael@0 | 52 | */ |
michael@0 | 53 | get protocolFlags() { |
michael@0 | 54 | return Ci.nsIProtocolHandler.URI_DANGEROUS_TO_LOAD | |
michael@0 | 55 | Ci.nsIProtocolHandler.URI_NORELATIVE | |
michael@0 | 56 | Ci.nsIProtocolHandler.URI_NOAUTH; |
michael@0 | 57 | }, |
michael@0 | 58 | |
michael@0 | 59 | /** |
michael@0 | 60 | * Creates a new URI object that is suitable for loading by this protocol. |
michael@0 | 61 | * @param aSpec The URI string in UTF8 encoding. |
michael@0 | 62 | * @param aOriginCharset The charset of the document from which the URI originated. |
michael@0 | 63 | * @return The newly created URI. |
michael@0 | 64 | */ |
michael@0 | 65 | newURI: function Proto_newURI(aSpec, aOriginCharset) { |
michael@0 | 66 | let uri = Cc["@mozilla.org/network/simple-uri;1"].createInstance(Ci.nsIURI); |
michael@0 | 67 | uri.spec = aSpec; |
michael@0 | 68 | return uri; |
michael@0 | 69 | }, |
michael@0 | 70 | |
michael@0 | 71 | /** |
michael@0 | 72 | * Constructs a new channel from the given URI for this protocol handler. |
michael@0 | 73 | * @param aURI The URI for which to construct a channel. |
michael@0 | 74 | * @return The newly created channel. |
michael@0 | 75 | */ |
michael@0 | 76 | newChannel: function Proto_newChannel(aURI) { |
michael@0 | 77 | let {url} = parseURI(aURI); |
michael@0 | 78 | let file = PageThumbsStorage.getFilePathForURL(url); |
michael@0 | 79 | let fileuri = Services.io.newFileURI(new FileUtils.File(file)); |
michael@0 | 80 | return Services.io.newChannelFromURI(fileuri); |
michael@0 | 81 | }, |
michael@0 | 82 | |
michael@0 | 83 | /** |
michael@0 | 84 | * Decides whether to allow a blacklisted port. |
michael@0 | 85 | * @return Always false, we'll never allow ports. |
michael@0 | 86 | */ |
michael@0 | 87 | allowPort: function () false, |
michael@0 | 88 | |
michael@0 | 89 | classID: Components.ID("{5a4ae9b5-f475-48ae-9dce-0b4c1d347884}"), |
michael@0 | 90 | QueryInterface: XPCOMUtils.generateQI([Ci.nsIProtocolHandler]) |
michael@0 | 91 | }; |
michael@0 | 92 | |
michael@0 | 93 | this.NSGetFactory = XPCOMUtils.generateNSGetFactory([Protocol]); |
michael@0 | 94 | |
michael@0 | 95 | /** |
michael@0 | 96 | * Parses a given URI and extracts all parameters relevant to this protocol. |
michael@0 | 97 | * @param aURI The URI to parse. |
michael@0 | 98 | * @return The parsed parameters. |
michael@0 | 99 | */ |
michael@0 | 100 | function parseURI(aURI) { |
michael@0 | 101 | let {scheme, staticHost} = PageThumbs; |
michael@0 | 102 | let re = new RegExp("^" + scheme + "://" + staticHost + ".*?\\?"); |
michael@0 | 103 | let query = aURI.spec.replace(re, ""); |
michael@0 | 104 | let params = {}; |
michael@0 | 105 | |
michael@0 | 106 | query.split("&").forEach(function (aParam) { |
michael@0 | 107 | let [key, value] = aParam.split("=").map(decodeURIComponent); |
michael@0 | 108 | params[key.toLowerCase()] = value; |
michael@0 | 109 | }); |
michael@0 | 110 | |
michael@0 | 111 | return params; |
michael@0 | 112 | } |