Skip to content
This repository has been archived by the owner on Jan 17, 2023. It is now read-only.

Commit

Permalink
Fix #4531, Move history enabled and upload-disabled pref checks into …
Browse files Browse the repository at this point in the history
…webextension API (#4810)
  • Loading branch information
jaredhirsch committed Aug 30, 2018
1 parent c5163ba commit 2a375ca
Show file tree
Hide file tree
Showing 4 changed files with 25 additions and 20 deletions.
17 changes: 0 additions & 17 deletions addon/bootstrap.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,6 @@
const ADDON_ID = "screenshots@mozilla.org";
const PREF_BRANCH = "extensions.screenshots.";
const USER_DISABLE_PREF = "extensions.screenshots.disabled";
const UPLOAD_DISABLED_PREF = "extensions.screenshots.upload-disabled";
const HISTORY_ENABLED_PREF = "places.history.enabled";

ChromeUtils.import("resource://gre/modules/XPCOMUtils.jsm");
ChromeUtils.defineModuleGetter(this, "AddonManager",
Expand Down Expand Up @@ -150,7 +148,6 @@ function handleStartup() {

function start(webExtension) {
return webExtension.startup(startupReason, addonData).then((api) => {
api.browser.runtime.onMessage.addListener(handleMessage);
LibraryButton.init(webExtension);
}).catch((err) => {
// The startup() promise will be rejected if the webExtension was
Expand All @@ -169,17 +166,3 @@ function stop(webExtension, reason) {
}
return Promise.resolve(webExtension.shutdown(reason));
}

function handleMessage(msg, sender, sendReply) {
if (!msg) {
return;
}

if (msg.funcName === "isUploadDisabled") {
const uploadDisabled = getBoolPref(UPLOAD_DISABLED_PREF);
sendReply({type: "success", value: uploadDisabled});
} else if (msg.funcName === "isHistoryEnabled") {
const historyEnabled = getBoolPref(HISTORY_ENABLED_PREF);
sendReply({type: "success", value: historyEnabled});
}
}
4 changes: 2 additions & 2 deletions addon/webextension/background/selectorLoader.js
Original file line number Diff line number Diff line change
Expand Up @@ -92,8 +92,8 @@ this.selectorLoader = (function() {
// TODO: since bootstrap communication is now required, would this function
// make more sense inside background/main?
function downloadOnlyCheck(tabId) {
return communication.sendToBootstrap("isHistoryEnabled").then((historyEnabled) => {
return communication.sendToBootstrap("isUploadDisabled").then((uploadDisabled) => {
return browser.experiments.screenshots.isHistoryEnabled().then((historyEnabled) => {
return browser.experiments.screenshots.isUploadDisabled().then((uploadDisabled) => {
return browser.experiments.screenshots.getUpdateChannel().then((channel) => {
return browser.tabs.get(tabId).then(tab => {
const downloadOnly = !historyEnabled || uploadDisabled || channel === "esr" || tab.incognito;
Expand Down
10 changes: 9 additions & 1 deletion addon/webextension/experiments/screenshots/api.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@

ChromeUtils.defineModuleGetter(this, "AppConstants",
"resource://gre/modules/AppConstants.jsm");
ChromeUtils.defineModuleGetter(this, "Services",
"resource://gre/modules/Services.jsm");

this.screenshots = class extends ExtensionAPI {
getAPI() {
Expand All @@ -24,9 +26,15 @@ this.screenshots = class extends ExtensionAPI {
// 'aurora' - deprecated aurora channel (still observed in dxr)
// 'default' - local builds from source
// 'nightly-try' - nightly Try builds (QA may occasionally need to test with these)
async getUpdateChannel() {
getUpdateChannel() {
return AppConstants.MOZ_UPDATE_CHANNEL;
},
isHistoryEnabled() {
return Services.prefs.getBoolPref("places.history.enabled", true);
},
isUploadDisabled() {
return Services.prefs.getBoolPref("extensions.screenshots.upload-disabled", false);
},
},
},
};
Expand Down
14 changes: 14 additions & 0 deletions addon/webextension/experiments/screenshots/schema.json
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,20 @@
"description": "Returns the Firefox channel (AppConstants.MOZ_UPDATE_CHANNEL)",
"parameters": [],
"async": true
},
{
"name": "isHistoryEnabled",
"type": "function",
"description": "Returns the value of the 'places.history.enabled' preference",
"parameters": [],
"async": true
},
{
"name": "isUploadDisabled",
"type": "function",
"description": "Returns the value of the 'extensions.screenshots.upload-disabled' preference",
"parameters": [],
"async": true
}
]
}
Expand Down

0 comments on commit 2a375ca

Please sign in to comment.