gecko-dev/browser/extensions/onboarding/bootstrap.js
Fischer.json a228efff93 Bug 1357020 - Should hide the onboarding tour if user explicitly checked the hide-the-tour checkbox, r=gasolin,mossop,rexboy
This patch
- adds one hide-onboarding-tour checkbox
- after toggling the overlay, hides the onboarding tour if user checked hide-the-tour checkbox
- creates the message channel between the chrome process and the content process to set prefs.
- listens to the pref-updated event and then hide the onboarding tour across pages.
- Add one browser_onboarding_hide_tours.js test

MozReview-Commit-ID: 7ZjbrhfO9dB

--HG--
extra : rebase_source : 5c59527ff7cb16996539a4eec49b47a9decafb3a
2017-06-10 16:14:08 +08:00

55 lines
1.6 KiB
JavaScript

/* -*- indent-tabs-mode: nil; js-indent-level: 2 -*- */
/* 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/. */
"use strict";
const {classes: Cc, interfaces: Ci, utils: Cu} = Components;
Cu.import("resource://gre/modules/Services.jsm");
Cu.import("resource://gre/modules/Preferences.jsm");
const PREF_WHITELIST = [
"browser.onboarding.enabled",
"browser.onboarding.hidden",
"browser.onboarding.notification.finished"
];
/**
* Set pref. Why no `getPrefs` function is due to the priviledge level.
* We cannot set prefs inside a framescript but can read.
* For simplicity and effeciency, we still read prefs inside the framescript.
*
* @param {Array} prefs the array of prefs to set.
* The array element carrys info to set pref, should contain
* - {String} name the pref name, such as `browser.onboarding.hidden`
* - {*} value the value to set
**/
function setPrefs(prefs) {
prefs.forEach(pref => {
if (PREF_WHITELIST.includes(pref.name)) {
Preferences.set(pref.name, pref.value);
}
});
}
function initContentMessageListener() {
Services.mm.addMessageListener("Onboarding:OnContentMessage", msg => {
switch (msg.data.action) {
case "set-prefs":
setPrefs(msg.data.params);
break;
}
});
}
function install(aData, aReason) {}
function uninstall(aData, aReason) {}
function startup(aData, reason) {
Services.mm.loadFrameScript("resource://onboarding/onboarding.js", true);
initContentMessageListener();
}
function shutdown(aData, reason) {}