Thu, 15 Jan 2015 15:59:08 +0100
Implement a real Private Browsing Mode condition by changing the API/ABI;
This solves Tor bug #9701, complying with disk avoidance documented in
https://www.torproject.org/projects/torbrowser/design/#disk-avoidance.
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 | 'use strict'; |
michael@0 | 5 | |
michael@0 | 6 | const { Cu } = require('chrome'); |
michael@0 | 7 | const { getMostRecentBrowserWindow } = require('sdk/window/utils'); |
michael@0 | 8 | const { fromIterator } = require('sdk/util/array'); |
michael@0 | 9 | |
michael@0 | 10 | const BUILTIN_SIDEBAR_MENUITEMS = exports.BUILTIN_SIDEBAR_MENUITEMS = [ |
michael@0 | 11 | 'menu_socialSidebar', |
michael@0 | 12 | 'menu_historySidebar', |
michael@0 | 13 | 'menu_bookmarksSidebar' |
michael@0 | 14 | ]; |
michael@0 | 15 | |
michael@0 | 16 | function isSidebarShowing(window) { |
michael@0 | 17 | window = window || getMostRecentBrowserWindow(); |
michael@0 | 18 | let sidebar = window.document.getElementById('sidebar-box'); |
michael@0 | 19 | return !sidebar.hidden; |
michael@0 | 20 | } |
michael@0 | 21 | exports.isSidebarShowing = isSidebarShowing; |
michael@0 | 22 | |
michael@0 | 23 | function getSidebarMenuitems(window) { |
michael@0 | 24 | window = window || getMostRecentBrowserWindow(); |
michael@0 | 25 | return fromIterator(window.document.querySelectorAll('#viewSidebarMenu menuitem')); |
michael@0 | 26 | } |
michael@0 | 27 | exports.getSidebarMenuitems = getSidebarMenuitems; |
michael@0 | 28 | |
michael@0 | 29 | function getExtraSidebarMenuitems() { |
michael@0 | 30 | let menuitems = getSidebarMenuitems(); |
michael@0 | 31 | return menuitems.filter(function(mi) { |
michael@0 | 32 | return BUILTIN_SIDEBAR_MENUITEMS.indexOf(mi.getAttribute('id')) < 0; |
michael@0 | 33 | }); |
michael@0 | 34 | } |
michael@0 | 35 | exports.getExtraSidebarMenuitems = getExtraSidebarMenuitems; |
michael@0 | 36 | |
michael@0 | 37 | function makeID(id) { |
michael@0 | 38 | return 'jetpack-sidebar-' + id; |
michael@0 | 39 | } |
michael@0 | 40 | exports.makeID = makeID; |
michael@0 | 41 | |
michael@0 | 42 | function simulateCommand(ele) { |
michael@0 | 43 | let window = ele.ownerDocument.defaultView; |
michael@0 | 44 | let { document } = window; |
michael@0 | 45 | var evt = document.createEvent('XULCommandEvent'); |
michael@0 | 46 | evt.initCommandEvent('command', true, true, window, |
michael@0 | 47 | 0, false, false, false, false, null); |
michael@0 | 48 | ele.dispatchEvent(evt); |
michael@0 | 49 | } |
michael@0 | 50 | exports.simulateCommand = simulateCommand; |
michael@0 | 51 | |
michael@0 | 52 | function simulateClick(ele) { |
michael@0 | 53 | let window = ele.ownerDocument.defaultView; |
michael@0 | 54 | let { document } = window; |
michael@0 | 55 | let evt = document.createEvent('MouseEvents'); |
michael@0 | 56 | evt.initMouseEvent('click', true, true, window, |
michael@0 | 57 | 0, 0, 0, 0, 0, false, false, false, false, 0, null); |
michael@0 | 58 | ele.dispatchEvent(evt); |
michael@0 | 59 | } |
michael@0 | 60 | exports.simulateClick = simulateClick; |
michael@0 | 61 | |
michael@0 | 62 | // OSX and Windows exhibit different behaviors when 'checked' is false, |
michael@0 | 63 | // so compare against the consistent 'true'. See bug 894809. |
michael@0 | 64 | function isChecked(node) { |
michael@0 | 65 | return node.getAttribute('checked') === 'true'; |
michael@0 | 66 | }; |
michael@0 | 67 | exports.isChecked = isChecked; |