/* This Source Code Form is subject to the terms of the Mozilla Public * License, v. 2.0. If a copy of the MPL was not distributed with this * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ /* jshint moz: true */ /* Dialog / Popup ===================================== */ // dialog names (used as dialog identifiers) const dialogNames = { "promptToShare": "promptToShareData", "resetData": "resetData", "blockSites": "blockSites", "hideSites": "hideSites", "startUploadData": "startUploadData", "stopUploadData": "stopUploadData", "privateBrowsing": "privateBrowsing", "saveOldData": "saveOldData" }; const allDialogs = { 'Reset Data Confirmation': confirmResetDataDialog, 'Block Sites Confirmation': confirmBlockSitesDialog, 'Hide Sites Confirmation': confirmHideSitesDialog, 'Upload Data Confirmation': askForDataSharingConfirmationDialog, 'Stop Uploading Data Confirmation': stopSharingDialog, 'Private Browsing Notification': informUserOfUnsafeWindowsDialog, }; // options: name, title, message, type, dnsPrompt(Do Not Show), imageUrl function dialog(options, callback) { createDialog(options, callback); } function createDialog(options, callback) { var modal = picoModal({ content: createDialogContent(options), closeButton: false, overlayClose: false, overlayStyles: { backgroundColor: "#000", opacity: 0.75 } }); addDialogEventHandlers(modal, options, function (userResponse) { callback(userResponse); }); } function createDialogContent(options) { return dialogTitleBar(options) + dialogMessage(options) + dialogControls(options); } function dialogTitleBar(options) { return "
" + (options.title || " ") + "
"; } function dialogMessage(options) { return "
" + (options.imageUrl ? "
" : "") + "
" + (options.message || " ") + "
" + "
"; } function dialogControls(options) { var doNotShowAgainPrompt = "
Do not show this again.
"; // control buttons var controlButtons = "
"; var okButton = "OK"; var cancelButton = "Cancel"; // check dialog type // alert dialog only needs a single button - "OK" // else we show both "OK" and "Cancel" buttons if (options.type == "alert") { controlButtons += "OK"; } else { if (navigator.appVersion.indexOf("Win") > -1) { // runs on Windows controlButtons += okButton + cancelButton; } else { // runs on OS other than Windows controlButtons += cancelButton + okButton; } } controlButtons += "
"; return "
" + (options.dnsPrompt ? doNotShowAgainPrompt : "") + controlButtons + "
"; } function addDialogEventHandlers(modal, options, callback) { var dialogContainer = modal.modalElem; // OK button click event handler var okButton = dialogContainer.querySelector(".pico-close.dialog-ok"); okButton.addEventListener("click", function () { if (dialogContainer.querySelector(".dialog-dns input") && dialogContainer.querySelector(".dialog-dns input").checked) { // Do Not Show } modal.close(); callback(true); }); // Cancel button click event handler var cancelButton = dialogContainer.querySelector(".pico-close.dialog-cancel"); if (cancelButton) { cancelButton.addEventListener("click", function () { if (options.name == dialogNames.promptToShare) { if (dialogContainer.querySelector(".dialog-dns input").checked) {} } modal.close(); callback(false); }); } var keyDownHandler = function (event) { // disable Tab if (event.keyCode == "9") { event.preventDefault(); } // press Esc to close the dialog (functions the same as clicking Cancel) if (event.keyCode == "27") { // Esc key pressed modal.close(); callback(false); } }; document.addEventListener("keydown", keyDownHandler); modal.onClose(function () { document.removeEventListener("keydown", keyDownHandler); }); // for Upload Data dialog if (dialogContainer.querySelector(".toggle-pp")) { dialogContainer.querySelector(".toggle-pp").addEventListener("click", function (event) { dialogContainer.querySelector(".pico-content .privacy-policy").classList.toggle("collapsed"); }); } restrictTabWithinDialog(modal); } function restrictTabWithinDialog(modal) { var dialogContainer = modal.modalElem; assignTabIndices(modal); dialogContainer.addEventListener("keypress", function (event) { event.stopPropagation(); var focusedElm = document.activeElement; // Tab key is pressed if (event.keyCode == "9") { var currentTabIndex = parseInt(focusedElm.getAttribute("tabIndex")); var nextElem = dialogContainer.querySelector("[tabIndex='" + (currentTabIndex + 1) + "']"); if (nextElem) { nextElem.focus(); } else { dialogContainer.querySelector("[tabIndex='0']").focus(); } } // when the focused element is the OK or Cancel button and Enter key is pressed // mimic mouse clicking on button if (event.keyCode == "13" && focusedElm.mozMatchesSelector(".pico-content .dialog-btns a")) { focusedElm.click(); } }); } function assignTabIndices(modal) { var dialogContainer = modal.modalElem; var allElemsInDialog = dialogContainer.querySelectorAll("*"); var tabIndex = 0; toArray(allElemsInDialog).forEach(function (elem, i) { if (elem.nodeName.toLowerCase() == "a" || elem.nodeName.toLowerCase() == "input") { elem.setAttribute("tabIndex", tabIndex); tabIndex++; } }); dialogContainer.querySelector("[tabIndex='0']").focus(); } function askForDataSharingConfirmationDialog(callback) { dialog({ "name": dialogNames.startUploadData, "title": "Upload Data", "message": '

You are about to start uploading data to the Lightbeam server. Your data will continue to be uploaded periodically until you turn off sharing. For more information about the data we upload, how we take steps to minimize risk of re-identification, and what Mozilla\'s privacy policies are, please read the the Lightbeam Privacy Policy.

' + // Lightbeam Privacy Policy. '
Lightbeam Privacy Notice

We care about your privacy. Lightbeam is a browser add-on that collects and helps you visualize third party requests on any site you visit. If you choose to send Lightbeam data to Mozilla (that’s us), our privacy policy describes how we handle that data.

Things you should know
Mozilla Privacy Policy – Learn More

Your privacy is an important factor that Mozilla (that\'s us) considers in the development of each of our products and services. We are committed to being transparent and open and want you to know how we receive information about you, and what we do with that information once we have it.

What do we mean by "personal information?"

For us, "personal information" means information which identifies you, like your name or email address.

Any information that falls outside of this is "non-personal information."

If we store your personal information with information that is non-personal, we will consider the combination as personal information. If we remove all personal information from a set of data then the remaining is non-personal information.

How do we learn information about you?

We learn information about you when:


What do we do with your information once we have it?

When you give us personal information, we will use it in the ways for which you\'ve given us permission. Generally, we use your information to help us provide and improve our products and services for you.

When do we share your information with others?
How do we store and protect your personal information?

We are committed to protecting your personal information once we have it. We implement physical, business and technical security measures. Despite our efforts, if we learn of a security breach, we\'ll notify you so that you can take appropriate protective steps.

We also don\'t want your personal information for any longer than we need it, so we only keep it long enough to do what we collected it for. Once we don\'t need it, we take steps to destroy it unless we are required by law to keep it longer.

What else do we want you know?

We\'re a global organization and our computers are in several different places around the world. We also use service providers whose computers may also be in various countries. This means that your information might end up on one of those computers in another country, and that country may have a different level of data protection regulation than yours. By giving us information, you consent to this kind of transfer of your information. No matter what country your information is in, we comply with applicable law and will also abide by the commitments we make in this privacy policy.

If you are under 13, we don\'t want your personal information, and you must not provide it to us. If you are a parent and believe that your child who is under 13 has provided us with personal information, please contact us at lightbeam-privacy@mozilla.org to have your child\'s information removed.

What if we change this policy?

We may need to change this policy and when we do, we\'ll notify you.

' + // Lightbeam Privacy Policy ends '
' + '

By clicking OK, you are agreeing to the data practices in our privacy notice.

', "imageUrl": "image/lightbeam_popup_warningsharing.png" }, callback); } function stopSharingDialog(callback) { dialog({ "name": dialogNames.stopUploadData, "title": "Stop Uploading Data", "message": '

You are about to stop sharing data with the Lightbeam server.

' + '

By clicking OK you will no longer be uploading data.

', "imageUrl": "image/lightbeam_popup_stopsharing2.png" }, function (confirmed) { callback(confirmed); } ); } function informUserOfUnsafeWindowsDialog() { dialog({ "type": "alert", "name": dialogNames.privateBrowsing, "dnsPrompt": true, "title": "Private Browsing", "message": "

You have one or more private browsing windows open.

" + "

Connections made in private browsing windows will be visualized in Lightbeam but that data is neither stored locally nor will it ever be shared, even if sharing is enabled.

" + "

Information gathered in private browsing mode will be deleted whenever Lightbeam is restarted, and is not collected at all when Lightbeam is not open..

", "imageUrl": "image/lightbeam_popup_privacy.png" }, function (confirmed) {} ); } function confirmBlockSitesDialog(callback) { dialog({ "name": dialogNames.blockSites, "title": "Block Sites", "message": "

Warning:

" + "

Blocking sites will prevent any and all content from being loaded from selected domains, for example: [example.com, example.net] and all of their subdomains [mail.example.com, news.example.net etc.].

" + "

This can prevent some sites from working and degrade your internet experience. Please use this feature carefully.

", "imageUrl": "image/lightbeam_popup_blocked.png" }, callback ); } function confirmHideSitesDialog(callback) { dialog({ "name": dialogNames.hideSites, "dnsPrompt": true, "title": "Hide Sites", "message": "

These sites will not be shown in Lightbeam visualizations, including List View, unless you specifically toggle them back on with the Show Hidden Sites button.

" + "

You can use this to ignore trusted sites from the data.

", "imageUrl": "image/lightbeam_popup_hidden.png" }, callback ); } function confirmResetDataDialog(callback) { dialog({ "name": dialogNames.resetData, "title": "Reset Data", "message": "

Pressing OK will delete all Lightbeam information including connection history, user preferences, block sites list etc.

" + "

Your browser will be returned to the state of a fresh install of Lightbeam.

", "imageUrl": "image/lightbeam_popup_warningreset.png" }, callback); }