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

Commit

Permalink
Partial fix for #3574, create download only mode for private browsing
Browse files Browse the repository at this point in the history
  • Loading branch information
jaredhirsch committed Oct 18, 2017
1 parent 8276b79 commit faa5e57
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 10 deletions.
15 changes: 12 additions & 3 deletions addon/webextension/background/selectorLoader.js
Original file line number Diff line number Diff line change
Expand Up @@ -65,12 +65,12 @@ this.selectorLoader = (function() {
let loadingTabs = new Set();

exports.loadModules = function(tabId, hasSeenOnboarding) {
let promise;
loadingTabs.add(tabId);
let promise = setIncognito(tabId); // TODO this is a terrible function name. think of something better
if (hasSeenOnboarding) {
promise = executeModules(tabId, standardScripts.concat(selectorScripts));
promise = promise.then(executeModules(tabId, standardScripts.concat(selectorScripts)));
} else {
promise = executeModules(tabId, standardScripts.concat(onboardingScripts).concat(selectorScripts));
promise = promise.then(executeModules(tabId, standardScripts.concat(onboardingScripts).concat(selectorScripts)));
}
return promise.then((result) => {
loadingTabs.delete(tabId);
Expand All @@ -81,6 +81,15 @@ this.selectorLoader = (function() {
});
};

function setIncognito(tabId) {
return browser.tabs.get(tabId).then(tab => {
return browser.tabs.executeScript(tabId, {
code: `window.incognito = ${tab.incognito};`,
runAt: "document_start"
});
});
}

function executeModules(tabId, scripts) {
let lastPromise = Promise.resolve(null);
scripts.forEach((file) => {
Expand Down
22 changes: 15 additions & 7 deletions addon/webextension/selector/ui.js
Original file line number Diff line number Diff line change
Expand Up @@ -264,8 +264,10 @@ this.ui = (function() { // eslint-disable-line no-unused-vars
</div>
<div class="preview-instructions" data-l10n-id="screenshotInstructions"></div>
<div class="myshots-all-buttons-container">
<button class="myshots-button myshots-link" tabindex="1" data-l10n-id="myShotsLink"></button>
<div class="spacer"></div>
${window.incognito ? '' : `
<button class="myshots-button myshots-link" tabindex="1" data-l10n-id="myShotsLink"></button>
<div class="spacer"></div>
`}
<button class="myshots-button visible" tabindex="2" data-l10n-id="saveScreenshotVisibleArea"></button>
<button class="myshots-button full-page" tabindex="3" data-l10n-id="saveScreenshotFullPage"></button>
</div>
Expand All @@ -280,8 +282,10 @@ this.ui = (function() { // eslint-disable-line no-unused-vars
this.document.documentElement.lang = browser.i18n.getMessage("@@ui_locale");
const overlay = this.document.querySelector(".preview-overlay");
localizeText(this.document);
overlay.querySelector(".myshots-button").addEventListener(
"click", watchFunction(assertIsTrusted(standardOverlayCallbacks.onOpenMyShots)));
if (!window.incognito) {
overlay.querySelector(".myshots-button").addEventListener(
"click", watchFunction(assertIsTrusted(standardOverlayCallbacks.onOpenMyShots)));
}
overlay.querySelector(".visible").addEventListener(
"click", watchFunction(assertIsTrusted(standardOverlayCallbacks.onClickVisible)));
overlay.querySelector(".full-page").addEventListener(
Expand Down Expand Up @@ -363,7 +367,9 @@ this.ui = (function() { // eslint-disable-line no-unused-vars
<div class="preview-buttons">
<button class="highlight-button-cancel"></button>
<button class="highlight-button-download"></button>
<button class="preview-button-save" data-l10n-id="saveScreenshotSelectedArea"></button>
${window.incognito ? '' : `
<button class="preview-button-save" data-l10n-id="saveScreenshotSelectedArea"></button>
`}
</div>
</div>
</div>
Expand All @@ -375,8 +381,10 @@ this.ui = (function() { // eslint-disable-line no-unused-vars
const overlay = this.document.querySelector(".preview-overlay");
overlay.querySelector(".highlight-button-download").addEventListener(
"click", watchFunction(assertIsTrusted(standardOverlayCallbacks.onDownloadPreview)));
overlay.querySelector(".preview-button-save").addEventListener(
"click", watchFunction(assertIsTrusted(standardOverlayCallbacks.onSavePreview)));
if (!window.incognito) {
overlay.querySelector(".preview-button-save").addEventListener(
"click", watchFunction(assertIsTrusted(standardOverlayCallbacks.onSavePreview)));
}
overlay.querySelector(".highlight-button-cancel").addEventListener(
"click", watchFunction(assertIsTrusted(standardOverlayCallbacks.cancel)));
resolve();
Expand Down

0 comments on commit faa5e57

Please # to comment.