зеркало из https://github.com/mozilla/gecko-dev.git
Bug 1506653 support disabling page action for private windows, r=Gijs
Differential Revision: https://phabricator.services.mozilla.com/D11805 --HG-- extra : moz-landing-system : lando
This commit is contained in:
Родитель
4997b75c09
Коммит
b8b0e4b612
|
@ -106,3 +106,32 @@ add_task(async function testIncognitoPopup() {
|
||||||
await extension.awaitFinish("incognito");
|
await extension.awaitFinish("incognito");
|
||||||
await extension.unload();
|
await extension.unload();
|
||||||
});
|
});
|
||||||
|
|
||||||
|
add_task(async function test_pageAction_incognito_not_allowed() {
|
||||||
|
const URL = "http://example.com/";
|
||||||
|
let extension = ExtensionTestUtils.loadExtension({
|
||||||
|
manifest: {
|
||||||
|
"permissions": ["*://example.com/*"],
|
||||||
|
"page_action": {
|
||||||
|
"show_matches": ["<all_urls>"],
|
||||||
|
"pinned": true,
|
||||||
|
},
|
||||||
|
},
|
||||||
|
incognitoOverride: "not_allowed",
|
||||||
|
});
|
||||||
|
|
||||||
|
await extension.startup();
|
||||||
|
let tab = await BrowserTestUtils.openNewForegroundTab(gBrowser, URL, true, true);
|
||||||
|
let privateWindow = await BrowserTestUtils.openNewBrowserWindow({private: true});
|
||||||
|
await BrowserTestUtils.openNewForegroundTab(privateWindow.gBrowser, URL, true, true);
|
||||||
|
|
||||||
|
let elem = await getPageActionButton(extension, window);
|
||||||
|
ok(elem, "pageAction button state correct in non-PB");
|
||||||
|
|
||||||
|
elem = await getPageActionButton(extension, privateWindow);
|
||||||
|
ok(!elem, "pageAction button state correct in private window");
|
||||||
|
|
||||||
|
BrowserTestUtils.removeTab(tab);
|
||||||
|
await BrowserTestUtils.closeWindow(privateWindow);
|
||||||
|
await extension.unload();
|
||||||
|
});
|
||||||
|
|
|
@ -21,7 +21,8 @@ ChromeUtils.defineModuleGetter(this, "AsyncShutdown",
|
||||||
"resource://gre/modules/AsyncShutdown.jsm");
|
"resource://gre/modules/AsyncShutdown.jsm");
|
||||||
ChromeUtils.defineModuleGetter(this, "BinarySearch",
|
ChromeUtils.defineModuleGetter(this, "BinarySearch",
|
||||||
"resource://gre/modules/BinarySearch.jsm");
|
"resource://gre/modules/BinarySearch.jsm");
|
||||||
|
ChromeUtils.defineModuleGetter(this, "PrivateBrowsingUtils",
|
||||||
|
"resource://gre/modules/PrivateBrowsingUtils.jsm");
|
||||||
|
|
||||||
const ACTION_ID_BOOKMARK = "bookmark";
|
const ACTION_ID_BOOKMARK = "bookmark";
|
||||||
const ACTION_ID_BOOKMARK_SEPARATOR = "bookmarkSeparator";
|
const ACTION_ID_BOOKMARK_SEPARATOR = "bookmarkSeparator";
|
||||||
|
@ -523,6 +524,8 @@ var PageActions = {
|
||||||
* clicked.
|
* clicked.
|
||||||
* @param wantsSubview (bool, optional)
|
* @param wantsSubview (bool, optional)
|
||||||
* Pass true to make an action that shows a panel subview when clicked.
|
* Pass true to make an action that shows a panel subview when clicked.
|
||||||
|
* @param disablePrivateBrowsing (bool, optional)
|
||||||
|
* Pass true to prevent the action from showing in a private browsing window.
|
||||||
*/
|
*/
|
||||||
function Action(options) {
|
function Action(options) {
|
||||||
setProperties(this, options, {
|
setProperties(this, options, {
|
||||||
|
@ -550,6 +553,7 @@ function Action(options) {
|
||||||
urlbarIDOverride: false,
|
urlbarIDOverride: false,
|
||||||
wantsIframe: false,
|
wantsIframe: false,
|
||||||
wantsSubview: false,
|
wantsSubview: false,
|
||||||
|
disablePrivateBrowsing: false,
|
||||||
|
|
||||||
// private
|
// private
|
||||||
|
|
||||||
|
@ -618,6 +622,25 @@ Action.prototype = {
|
||||||
return this._id;
|
return this._id;
|
||||||
},
|
},
|
||||||
|
|
||||||
|
get disablePrivateBrowsing() {
|
||||||
|
return !!this._disablePrivateBrowsing;
|
||||||
|
},
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Verifies that the action can be shown in a private window. For
|
||||||
|
* extensions, verifies the extension has access to the window.
|
||||||
|
*/
|
||||||
|
canShowInWindow(browserWindow) {
|
||||||
|
if (this._extensionID) {
|
||||||
|
let policy = WebExtensionPolicy.getByID(this._extensionID);
|
||||||
|
if (!policy.canAccessWindow(browserWindow)) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return !(this.disablePrivateBrowsing &&
|
||||||
|
PrivateBrowsingUtils.isWindowPrivate(browserWindow));
|
||||||
|
},
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* True if the action is pinned to the urlbar. The action is shown in the
|
* True if the action is pinned to the urlbar. The action is shown in the
|
||||||
* urlbar if it's pinned and not disabled. (bool)
|
* urlbar if it's pinned and not disabled. (bool)
|
||||||
|
@ -1021,7 +1044,8 @@ Action.prototype = {
|
||||||
* disabled.
|
* disabled.
|
||||||
*/
|
*/
|
||||||
shouldShowInPanel(browserWindow) {
|
shouldShowInPanel(browserWindow) {
|
||||||
return !this.__transient || !this.getDisabled(browserWindow);
|
return (!this.__transient || !this.getDisabled(browserWindow)) &&
|
||||||
|
this.canShowInWindow(browserWindow);
|
||||||
},
|
},
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -1033,7 +1057,8 @@ Action.prototype = {
|
||||||
* should be shown if it's both pinned and not disabled.
|
* should be shown if it's both pinned and not disabled.
|
||||||
*/
|
*/
|
||||||
shouldShowInUrlbar(browserWindow) {
|
shouldShowInUrlbar(browserWindow) {
|
||||||
return this.pinnedToUrlbar && !this.getDisabled(browserWindow);
|
return (this.pinnedToUrlbar && !this.getDisabled(browserWindow)) &&
|
||||||
|
this.canShowInWindow(browserWindow);
|
||||||
},
|
},
|
||||||
|
|
||||||
get _isBuiltIn() {
|
get _isBuiltIn() {
|
||||||
|
|
|
@ -1657,6 +1657,31 @@ add_task(async function transient() {
|
||||||
otherAction.remove();
|
otherAction.remove();
|
||||||
});
|
});
|
||||||
|
|
||||||
|
add_task(async function action_disablePrivateBrowsing() {
|
||||||
|
let id = "testWidget";
|
||||||
|
let action = PageActions.addAction(new PageActions.Action({
|
||||||
|
id,
|
||||||
|
disablePrivateBrowsing: true,
|
||||||
|
title: "title",
|
||||||
|
disabled: false,
|
||||||
|
pinnedToUrlbar: true,
|
||||||
|
}));
|
||||||
|
// Open an actionable page so that the main page action button appears.
|
||||||
|
let url = "http://example.com/";
|
||||||
|
let privateWindow = await BrowserTestUtils.openNewBrowserWindow({private: true});
|
||||||
|
await BrowserTestUtils.openNewForegroundTab(privateWindow.gBrowser, url, true, true);
|
||||||
|
|
||||||
|
Assert.ok(action.canShowInWindow(window), "should show in default window");
|
||||||
|
Assert.ok(!action.canShowInWindow(privateWindow), "should not show in private browser");
|
||||||
|
Assert.ok(action.shouldShowInUrlbar(window), "should show in default urlbar");
|
||||||
|
Assert.ok(!action.shouldShowInUrlbar(privateWindow), "should not show in default urlbar");
|
||||||
|
Assert.ok(action.shouldShowInPanel(window), "should show in default urlbar");
|
||||||
|
Assert.ok(!action.shouldShowInPanel(privateWindow), "should not show in default urlbar");
|
||||||
|
|
||||||
|
action.remove();
|
||||||
|
|
||||||
|
privateWindow.close();
|
||||||
|
});
|
||||||
|
|
||||||
function assertActivatedPageActionPanelHidden() {
|
function assertActivatedPageActionPanelHidden() {
|
||||||
Assert.ok(!document.getElementById(BrowserPageActions._activatedActionPanelID));
|
Assert.ok(!document.getElementById(BrowserPageActions._activatedActionPanelID));
|
||||||
|
|
Загрузка…
Ссылка в новой задаче