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 | // -*- Mode: Java; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- |
michael@0 | 2 | |
michael@0 | 3 | /* This Source Code Form is subject to the terms of the Mozilla Public |
michael@0 | 4 | * License, v. 2.0. If a copy of the MPL was not distributed with this |
michael@0 | 5 | * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ |
michael@0 | 6 | |
michael@0 | 7 | /** Document Zoom Management Code |
michael@0 | 8 | * |
michael@0 | 9 | * To use this, you'll need to have a getBrowser() function or use the methods |
michael@0 | 10 | * that accept a browser to be modified. |
michael@0 | 11 | **/ |
michael@0 | 12 | |
michael@0 | 13 | var ZoomManager = { |
michael@0 | 14 | get _prefBranch() { |
michael@0 | 15 | delete this._prefBranch; |
michael@0 | 16 | return this._prefBranch = Components.classes["@mozilla.org/preferences-service;1"] |
michael@0 | 17 | .getService(Components.interfaces.nsIPrefBranch); |
michael@0 | 18 | }, |
michael@0 | 19 | |
michael@0 | 20 | get MIN() { |
michael@0 | 21 | delete this.MIN; |
michael@0 | 22 | return this.MIN = this._prefBranch.getIntPref("zoom.minPercent") / 100; |
michael@0 | 23 | }, |
michael@0 | 24 | |
michael@0 | 25 | get MAX() { |
michael@0 | 26 | delete this.MAX; |
michael@0 | 27 | return this.MAX = this._prefBranch.getIntPref("zoom.maxPercent") / 100; |
michael@0 | 28 | }, |
michael@0 | 29 | |
michael@0 | 30 | get useFullZoom() { |
michael@0 | 31 | return this._prefBranch.getBoolPref("browser.zoom.full"); |
michael@0 | 32 | }, |
michael@0 | 33 | |
michael@0 | 34 | set useFullZoom(aVal) { |
michael@0 | 35 | this._prefBranch.setBoolPref("browser.zoom.full", aVal); |
michael@0 | 36 | return aVal; |
michael@0 | 37 | }, |
michael@0 | 38 | |
michael@0 | 39 | get zoom() { |
michael@0 | 40 | return this.getZoomForBrowser(getBrowser()); |
michael@0 | 41 | }, |
michael@0 | 42 | |
michael@0 | 43 | getZoomForBrowser: function ZoomManager_getZoomForBrowser(aBrowser) { |
michael@0 | 44 | return (this.useFullZoom || aBrowser.isSyntheticDocument) |
michael@0 | 45 | ? aBrowser.fullZoom : aBrowser.textZoom; |
michael@0 | 46 | }, |
michael@0 | 47 | |
michael@0 | 48 | set zoom(aVal) { |
michael@0 | 49 | this.setZoomForBrowser(getBrowser(), aVal); |
michael@0 | 50 | return aVal; |
michael@0 | 51 | }, |
michael@0 | 52 | |
michael@0 | 53 | setZoomForBrowser: function ZoomManager_setZoomForBrowser(aBrowser, aVal) { |
michael@0 | 54 | if (aVal < this.MIN || aVal > this.MAX) |
michael@0 | 55 | throw Components.results.NS_ERROR_INVALID_ARG; |
michael@0 | 56 | |
michael@0 | 57 | if (this.useFullZoom || aBrowser.isSyntheticDocument) { |
michael@0 | 58 | aBrowser.textZoom = 1; |
michael@0 | 59 | aBrowser.fullZoom = aVal; |
michael@0 | 60 | } else { |
michael@0 | 61 | aBrowser.textZoom = aVal; |
michael@0 | 62 | aBrowser.fullZoom = 1; |
michael@0 | 63 | } |
michael@0 | 64 | }, |
michael@0 | 65 | |
michael@0 | 66 | get zoomValues() { |
michael@0 | 67 | var zoomValues = this._prefBranch.getCharPref("toolkit.zoomManager.zoomValues") |
michael@0 | 68 | .split(",").map(parseFloat); |
michael@0 | 69 | zoomValues.sort(function (a, b) a - b); |
michael@0 | 70 | |
michael@0 | 71 | while (zoomValues[0] < this.MIN) |
michael@0 | 72 | zoomValues.shift(); |
michael@0 | 73 | |
michael@0 | 74 | while (zoomValues[zoomValues.length - 1] > this.MAX) |
michael@0 | 75 | zoomValues.pop(); |
michael@0 | 76 | |
michael@0 | 77 | delete this.zoomValues; |
michael@0 | 78 | return this.zoomValues = zoomValues; |
michael@0 | 79 | }, |
michael@0 | 80 | |
michael@0 | 81 | enlarge: function ZoomManager_enlarge() { |
michael@0 | 82 | var i = this.zoomValues.indexOf(this.snap(this.zoom)) + 1; |
michael@0 | 83 | if (i < this.zoomValues.length) |
michael@0 | 84 | this.zoom = this.zoomValues[i]; |
michael@0 | 85 | }, |
michael@0 | 86 | |
michael@0 | 87 | reduce: function ZoomManager_reduce() { |
michael@0 | 88 | var i = this.zoomValues.indexOf(this.snap(this.zoom)) - 1; |
michael@0 | 89 | if (i >= 0) |
michael@0 | 90 | this.zoom = this.zoomValues[i]; |
michael@0 | 91 | }, |
michael@0 | 92 | |
michael@0 | 93 | reset: function ZoomManager_reset() { |
michael@0 | 94 | this.zoom = 1; |
michael@0 | 95 | }, |
michael@0 | 96 | |
michael@0 | 97 | toggleZoom: function ZoomManager_toggleZoom() { |
michael@0 | 98 | var zoomLevel = this.zoom; |
michael@0 | 99 | |
michael@0 | 100 | this.useFullZoom = !this.useFullZoom; |
michael@0 | 101 | this.zoom = zoomLevel; |
michael@0 | 102 | }, |
michael@0 | 103 | |
michael@0 | 104 | snap: function ZoomManager_snap(aVal) { |
michael@0 | 105 | var values = this.zoomValues; |
michael@0 | 106 | for (var i = 0; i < values.length; i++) { |
michael@0 | 107 | if (values[i] >= aVal) { |
michael@0 | 108 | if (i > 0 && aVal - values[i - 1] < values[i] - aVal) |
michael@0 | 109 | i--; |
michael@0 | 110 | return values[i]; |
michael@0 | 111 | } |
michael@0 | 112 | } |
michael@0 | 113 | return values[i - 1]; |
michael@0 | 114 | } |
michael@0 | 115 | }; |