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 | (function () { // bug 673569 workaround :( |
michael@0 | 6 | |
michael@0 | 7 | const { classes: Cc, interfaces: Ci, utils: Cu } = Components; |
michael@0 | 8 | |
michael@0 | 9 | Cu.import("resource://gre/modules/PageThumbs.jsm"); |
michael@0 | 10 | Cu.import("resource://gre/modules/XPCOMUtils.jsm"); |
michael@0 | 11 | Cu.import("resource://gre/modules/Services.jsm"); |
michael@0 | 12 | |
michael@0 | 13 | const STATE_LOADING = 1; |
michael@0 | 14 | const STATE_CAPTURING = 2; |
michael@0 | 15 | const STATE_CANCELED = 3; |
michael@0 | 16 | |
michael@0 | 17 | const backgroundPageThumbsContent = { |
michael@0 | 18 | |
michael@0 | 19 | init: function () { |
michael@0 | 20 | Services.obs.addObserver(this, "document-element-inserted", true); |
michael@0 | 21 | |
michael@0 | 22 | // We want a low network priority for this service - lower than b/g tabs |
michael@0 | 23 | // etc - so set it to the lowest priority available. |
michael@0 | 24 | this._webNav.QueryInterface(Ci.nsIDocumentLoader). |
michael@0 | 25 | loadGroup.QueryInterface(Ci.nsISupportsPriority). |
michael@0 | 26 | priority = Ci.nsISupportsPriority.PRIORITY_LOWEST; |
michael@0 | 27 | |
michael@0 | 28 | docShell.allowMedia = false; |
michael@0 | 29 | docShell.allowPlugins = false; |
michael@0 | 30 | docShell.allowContentRetargeting = false; |
michael@0 | 31 | let defaultFlags = Ci.nsIRequest.LOAD_ANONYMOUS | |
michael@0 | 32 | Ci.nsIRequest.LOAD_BYPASS_CACHE | |
michael@0 | 33 | Ci.nsIRequest.INHIBIT_CACHING | |
michael@0 | 34 | Ci.nsIWebNavigation.LOAD_FLAGS_BYPASS_HISTORY; |
michael@0 | 35 | docShell.defaultLoadFlags = defaultFlags; |
michael@0 | 36 | |
michael@0 | 37 | addMessageListener("BackgroundPageThumbs:capture", |
michael@0 | 38 | this._onCapture.bind(this)); |
michael@0 | 39 | docShell. |
michael@0 | 40 | QueryInterface(Ci.nsIInterfaceRequestor). |
michael@0 | 41 | getInterface(Ci.nsIWebProgress). |
michael@0 | 42 | addProgressListener(this, Ci.nsIWebProgress.NOTIFY_STATE_WINDOW); |
michael@0 | 43 | }, |
michael@0 | 44 | |
michael@0 | 45 | observe: function (subj, topic, data) { |
michael@0 | 46 | // Arrange to prevent (most) popup dialogs for this window - popups done |
michael@0 | 47 | // in the parent (eg, auth) aren't prevented, but alert() etc are. |
michael@0 | 48 | // disableDialogs only works on the current inner window, so it has |
michael@0 | 49 | // to be called every page load, but before scripts run. |
michael@0 | 50 | if (subj == content.document) { |
michael@0 | 51 | content. |
michael@0 | 52 | QueryInterface(Ci.nsIInterfaceRequestor). |
michael@0 | 53 | getInterface(Ci.nsIDOMWindowUtils). |
michael@0 | 54 | disableDialogs(); |
michael@0 | 55 | } |
michael@0 | 56 | }, |
michael@0 | 57 | |
michael@0 | 58 | get _webNav() { |
michael@0 | 59 | return docShell.QueryInterface(Ci.nsIWebNavigation); |
michael@0 | 60 | }, |
michael@0 | 61 | |
michael@0 | 62 | _onCapture: function (msg) { |
michael@0 | 63 | this._nextCapture = { |
michael@0 | 64 | id: msg.data.id, |
michael@0 | 65 | url: msg.data.url, |
michael@0 | 66 | }; |
michael@0 | 67 | if (this._currentCapture) { |
michael@0 | 68 | if (this._state == STATE_LOADING) { |
michael@0 | 69 | // Cancel the current capture. |
michael@0 | 70 | this._state = STATE_CANCELED; |
michael@0 | 71 | this._loadAboutBlank(); |
michael@0 | 72 | } |
michael@0 | 73 | // Let the current capture finish capturing, or if it was just canceled, |
michael@0 | 74 | // wait for onStateChange due to the about:blank load. |
michael@0 | 75 | return; |
michael@0 | 76 | } |
michael@0 | 77 | this._startNextCapture(); |
michael@0 | 78 | }, |
michael@0 | 79 | |
michael@0 | 80 | _startNextCapture: function () { |
michael@0 | 81 | if (!this._nextCapture) |
michael@0 | 82 | return; |
michael@0 | 83 | this._currentCapture = this._nextCapture; |
michael@0 | 84 | delete this._nextCapture; |
michael@0 | 85 | this._state = STATE_LOADING; |
michael@0 | 86 | this._currentCapture.pageLoadStartDate = new Date(); |
michael@0 | 87 | this._webNav.loadURI(this._currentCapture.url, |
michael@0 | 88 | Ci.nsIWebNavigation.LOAD_FLAGS_STOP_CONTENT, |
michael@0 | 89 | null, null, null); |
michael@0 | 90 | }, |
michael@0 | 91 | |
michael@0 | 92 | onStateChange: function (webProgress, req, flags, status) { |
michael@0 | 93 | if (webProgress.isTopLevel && |
michael@0 | 94 | (flags & Ci.nsIWebProgressListener.STATE_STOP) && |
michael@0 | 95 | this._currentCapture) { |
michael@0 | 96 | if (req.name == "about:blank") { |
michael@0 | 97 | if (this._state == STATE_CAPTURING) { |
michael@0 | 98 | // about:blank has loaded, ending the current capture. |
michael@0 | 99 | this._finishCurrentCapture(); |
michael@0 | 100 | delete this._currentCapture; |
michael@0 | 101 | this._startNextCapture(); |
michael@0 | 102 | } |
michael@0 | 103 | else if (this._state == STATE_CANCELED) { |
michael@0 | 104 | // A capture request was received while the current capture's page |
michael@0 | 105 | // was still loading. |
michael@0 | 106 | delete this._currentCapture; |
michael@0 | 107 | this._startNextCapture(); |
michael@0 | 108 | } |
michael@0 | 109 | } |
michael@0 | 110 | else if (this._state == STATE_LOADING) { |
michael@0 | 111 | // The requested page has loaded. Capture it. |
michael@0 | 112 | this._state = STATE_CAPTURING; |
michael@0 | 113 | this._captureCurrentPage(); |
michael@0 | 114 | } |
michael@0 | 115 | } |
michael@0 | 116 | }, |
michael@0 | 117 | |
michael@0 | 118 | _captureCurrentPage: function () { |
michael@0 | 119 | let capture = this._currentCapture; |
michael@0 | 120 | capture.finalURL = this._webNav.currentURI.spec; |
michael@0 | 121 | capture.pageLoadTime = new Date() - capture.pageLoadStartDate; |
michael@0 | 122 | |
michael@0 | 123 | let canvas = PageThumbs._createCanvas(content); |
michael@0 | 124 | let canvasDrawDate = new Date(); |
michael@0 | 125 | PageThumbs._captureToCanvas(content, canvas); |
michael@0 | 126 | capture.canvasDrawTime = new Date() - canvasDrawDate; |
michael@0 | 127 | |
michael@0 | 128 | canvas.toBlob(blob => { |
michael@0 | 129 | capture.imageBlob = blob; |
michael@0 | 130 | // Load about:blank to finish the capture and wait for onStateChange. |
michael@0 | 131 | this._loadAboutBlank(); |
michael@0 | 132 | }); |
michael@0 | 133 | }, |
michael@0 | 134 | |
michael@0 | 135 | _finishCurrentCapture: function () { |
michael@0 | 136 | let capture = this._currentCapture; |
michael@0 | 137 | let fileReader = Cc["@mozilla.org/files/filereader;1"]. |
michael@0 | 138 | createInstance(Ci.nsIDOMFileReader); |
michael@0 | 139 | fileReader.onloadend = () => { |
michael@0 | 140 | sendAsyncMessage("BackgroundPageThumbs:didCapture", { |
michael@0 | 141 | id: capture.id, |
michael@0 | 142 | imageData: fileReader.result, |
michael@0 | 143 | finalURL: capture.finalURL, |
michael@0 | 144 | telemetry: { |
michael@0 | 145 | CAPTURE_PAGE_LOAD_TIME_MS: capture.pageLoadTime, |
michael@0 | 146 | CAPTURE_CANVAS_DRAW_TIME_MS: capture.canvasDrawTime, |
michael@0 | 147 | }, |
michael@0 | 148 | }); |
michael@0 | 149 | }; |
michael@0 | 150 | fileReader.readAsArrayBuffer(capture.imageBlob); |
michael@0 | 151 | }, |
michael@0 | 152 | |
michael@0 | 153 | // We load about:blank to finish all captures, even canceled captures. Two |
michael@0 | 154 | // reasons: GC the captured page, and ensure it can't possibly load any more |
michael@0 | 155 | // resources. |
michael@0 | 156 | _loadAboutBlank: function _loadAboutBlank() { |
michael@0 | 157 | this._webNav.loadURI("about:blank", |
michael@0 | 158 | Ci.nsIWebNavigation.LOAD_FLAGS_STOP_CONTENT, |
michael@0 | 159 | null, null, null); |
michael@0 | 160 | }, |
michael@0 | 161 | |
michael@0 | 162 | QueryInterface: XPCOMUtils.generateQI([ |
michael@0 | 163 | Ci.nsIWebProgressListener, |
michael@0 | 164 | Ci.nsISupportsWeakReference, |
michael@0 | 165 | Ci.nsIObserver, |
michael@0 | 166 | ]), |
michael@0 | 167 | }; |
michael@0 | 168 | |
michael@0 | 169 | backgroundPageThumbsContent.init(); |
michael@0 | 170 | |
michael@0 | 171 | })(); |