addon-sdk/source/examples/reading-data/lib/main.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 var self = require("sdk/self");
     7 var { Panel } = require("sdk/panel");
     8 var { ToggleButton } = require("sdk/ui");
    10 function replaceMom(html) {
    11   return html.replace("World", "Mom");
    12 }
    13 exports.replaceMom = replaceMom;
    15 exports.main = function(options, callbacks) {
    16   console.log("My ID is " + self.id);
    18   // Load the sample HTML into a string.
    19   var helloHTML = self.data.load("sample.html");
    21   // Let's now modify it...
    22   helloHTML = replaceMom(helloHTML);
    24   // ... and then create a panel that displays it.
    25   var myPanel = Panel({
    26     contentURL: "data:text/html," + helloHTML,
    27     onHide: handleHide
    28   });
    30   // Create a widget that displays the image.  We'll attach the panel to it.
    31   // When you click the widget, the panel will pop up.
    32   var button = ToggleButton({
    33     id: "test-widget",
    34     label: "Mom",
    35     icon: './mom.png',
    36     onChange: handleChange
    37   });
    39   // If you run cfx with --static-args='{"quitWhenDone":true}' this program
    40   // will automatically quit Firefox when it's done.
    41   if (options.staticArgs.quitWhenDone)
    42     callbacks.quit();
    43 }
    45 function handleChange(state) {
    46   if (state.checked) {
    47     myPanel.show({ position: button });
    48   }
    49 }
    51 function handleHide() {
    52   button.state('window', { checked: false });
    53 }

mercurial