addon-sdk/source/test/addons/private-browsing-supported/sidebar/utils.js

Thu, 15 Jan 2015 15:59:08 +0100

author
Michael Schloh von Bennewitz <michael@schloh.com>
date
Thu, 15 Jan 2015 15:59:08 +0100
branch
TOR_BUG_9701
changeset 10
ac0c01689b40
permissions
-rw-r--r--

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.

     1 /* This Source Code Form is subject to the terms of the Mozilla Public
     2  * License, v. 2.0. If a copy of the MPL was not distributed with this
     3  * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
     4 'use strict';
     6 const { Cu } = require('chrome');
     7 const { getMostRecentBrowserWindow } = require('sdk/window/utils');
     8 const { fromIterator } = require('sdk/util/array');
    10 const BUILTIN_SIDEBAR_MENUITEMS = exports.BUILTIN_SIDEBAR_MENUITEMS = [
    11   'menu_socialSidebar',
    12   'menu_historySidebar',
    13   'menu_bookmarksSidebar'
    14 ];
    16 function isSidebarShowing(window) {
    17   window = window || getMostRecentBrowserWindow();
    18   let sidebar = window.document.getElementById('sidebar-box');
    19   return !sidebar.hidden;
    20 }
    21 exports.isSidebarShowing = isSidebarShowing;
    23 function getSidebarMenuitems(window) {
    24   window = window || getMostRecentBrowserWindow();
    25   return fromIterator(window.document.querySelectorAll('#viewSidebarMenu menuitem'));
    26 }
    27 exports.getSidebarMenuitems = getSidebarMenuitems;
    29 function getExtraSidebarMenuitems() {
    30   let menuitems = getSidebarMenuitems();
    31   return menuitems.filter(function(mi) {
    32     return BUILTIN_SIDEBAR_MENUITEMS.indexOf(mi.getAttribute('id')) < 0;
    33   });
    34 }
    35 exports.getExtraSidebarMenuitems = getExtraSidebarMenuitems;
    37 function makeID(id) {
    38   return 'jetpack-sidebar-' + id;
    39 }
    40 exports.makeID = makeID;
    42 function simulateCommand(ele) {
    43   let window = ele.ownerDocument.defaultView;
    44   let { document } = window;
    45   var evt = document.createEvent('XULCommandEvent');
    46   evt.initCommandEvent('command', true, true, window,
    47     0, false, false, false, false, null);
    48   ele.dispatchEvent(evt);
    49 }
    50 exports.simulateCommand = simulateCommand;
    52 function simulateClick(ele) {
    53   let window = ele.ownerDocument.defaultView;
    54   let { document } = window;
    55   let evt = document.createEvent('MouseEvents');
    56   evt.initMouseEvent('click', true, true, window,
    57     0, 0, 0, 0, 0, false, false, false, false, 0, null);
    58   ele.dispatchEvent(evt);
    59 }
    60 exports.simulateClick = simulateClick;
    62 // OSX and Windows exhibit different behaviors when 'checked' is false,
    63 // so compare against the consistent 'true'. See bug 894809.
    64 function isChecked(node) {
    65   return node.getAttribute('checked') === 'true';
    66 };
    67 exports.isChecked = isChecked;

mercurial