mirror of
https://gitlab.winehq.org/wine/wine-gecko.git
synced 2024-09-13 09:24:08 -07:00
Bug 1075450 - Disable some Awesomebar actions for private windows r=mak
This commit is contained in:
parent
34812ed027
commit
9c8381b9b9
@ -7305,9 +7305,13 @@ let gPrivateBrowsingUI = {
|
||||
|
||||
if (gURLBar &&
|
||||
!PrivateBrowsingUtils.permanentPrivateBrowsing) {
|
||||
// Disable switch to tab autocompletion for private windows
|
||||
// (not for "Always use private browsing" mode)
|
||||
gURLBar.setAttribute("autocompletesearchparam", "");
|
||||
// Disable switch to tab autocompletion for private windows.
|
||||
// We leave it enabled for permanent private browsing mode though.
|
||||
let value = gURLBar.getAttribute("autocompletesearchparam") || "";
|
||||
if (!value.contains("disable-private-actions")) {
|
||||
gURLBar.setAttribute("autocompletesearchparam",
|
||||
value + " disable-private-actions");
|
||||
}
|
||||
}
|
||||
}
|
||||
};
|
||||
|
@ -44,7 +44,7 @@ function test() {
|
||||
});
|
||||
});
|
||||
|
||||
function runTest(aSourceWindow, aDestWindow, aExpectSuccess, aCallback) {
|
||||
function runTest(aSourceWindow, aDestWindow, aExpectSwitch, aCallback) {
|
||||
// Open the base tab
|
||||
let baseTab = aSourceWindow.gBrowser.addTab(testURL);
|
||||
baseTab.linkedBrowser.addEventListener("load", function() {
|
||||
@ -71,52 +71,52 @@ function test() {
|
||||
ok(!testTab.hasAttribute("busy"),
|
||||
"The test tab doesn't have the busy attribute");
|
||||
|
||||
// Set the urlbar to include the moz-action
|
||||
aDestWindow.gURLBar.value = "moz-action:switchtab," + JSON.stringify({url: testURL});
|
||||
// Focus the urlbar so we can press enter
|
||||
aDestWindow.gURLBar.focus();
|
||||
let urlbar = aDestWindow.gURLBar;
|
||||
let controller = urlbar.controller;
|
||||
|
||||
// We want to see if the switchtab action works. If it does, the
|
||||
// current tab will get closed, and that's what we detect with the
|
||||
// TabClose handler. If pressing enter triggers a load in that tab,
|
||||
// then the load handler will get called. Neither of these are
|
||||
// the desired effect here. So if the test goes successfully, it is
|
||||
// the timeout handler which gets called.
|
||||
//
|
||||
// The reason that we can't avoid the timeout here is because we are
|
||||
// trying to test something which should not happen, so we just need
|
||||
// to wait for a while and then check whether any bad things have
|
||||
// happened.
|
||||
// Focus URL bar, enter value, and start searching.
|
||||
urlbar.focus();
|
||||
urlbar.value = testURL;
|
||||
controller.startSearch(testURL);
|
||||
|
||||
function onTabClose(aEvent) {
|
||||
aDestWindow.gBrowser.tabContainer.removeEventListener("TabClose", onTabClose, false);
|
||||
aDestWindow.gBrowser.removeEventListener("load", onLoad, false);
|
||||
clearTimeout(timeout);
|
||||
// Should only happen when we expect success
|
||||
ok(aExpectSuccess, "Tab closed as expected");
|
||||
aCallback();
|
||||
}
|
||||
function onLoad(aEvent) {
|
||||
aDestWindow.gBrowser.tabContainer.removeEventListener("TabClose", onTabClose, false);
|
||||
aDestWindow.gBrowser.removeEventListener("load", onLoad, false);
|
||||
clearTimeout(timeout);
|
||||
// Should only happen when we expect success
|
||||
ok(aExpectSuccess, "Tab loaded as expected");
|
||||
aCallback();
|
||||
}
|
||||
// Wait for the Awesomebar popup to appear.
|
||||
promisePopupShown(aDestWindow.gURLBar.popup).then(() => {
|
||||
function searchIsComplete() {
|
||||
return controller.searchStatus ==
|
||||
Ci.nsIAutoCompleteController.STATUS_COMPLETE_MATCH;
|
||||
}
|
||||
|
||||
aDestWindow.gBrowser.tabContainer.addEventListener("TabClose", onTabClose, false);
|
||||
aDestWindow.gBrowser.addEventListener("load", onLoad, false);
|
||||
let timeout = setTimeout(function() {
|
||||
aDestWindow.gBrowser.tabContainer.removeEventListener("TabClose", onTabClose, false);
|
||||
aDestWindow.gBrowser.removeEventListener("load", onLoad, false);
|
||||
aCallback();
|
||||
}, 500);
|
||||
// Wait until the search is complete.
|
||||
waitForCondition(searchIsComplete, function () {
|
||||
if (aExpectSwitch) {
|
||||
// If we expect a tab switch then the current tab
|
||||
// will be closed and we switch to the other tab.
|
||||
let tabContainer = aDestWindow.gBrowser.tabContainer;
|
||||
tabContainer.addEventListener("TabClose", function onClose(event) {
|
||||
if (event.target == testTab) {
|
||||
tabContainer.removeEventListener("TabClose", onClose);
|
||||
executeSoon(aCallback);
|
||||
}
|
||||
});
|
||||
} else {
|
||||
// If we don't expect a tab switch then wait for the tab to load.
|
||||
testTab.addEventListener("load", function onLoad() {
|
||||
testTab.removeEventListener("load", onLoad, true);
|
||||
executeSoon(aCallback);
|
||||
}, true);
|
||||
}
|
||||
|
||||
// Select the second match, if any.
|
||||
if (controller.matchCount > 1) {
|
||||
controller.handleKeyNavigation(KeyEvent.DOM_VK_DOWN);
|
||||
}
|
||||
|
||||
// Execute the selected action.
|
||||
controller.handleEnter(true);
|
||||
});
|
||||
});
|
||||
|
||||
// Press enter!
|
||||
EventUtils.synthesizeKey("VK_RETURN", {});
|
||||
}, aDestWindow);
|
||||
}, true);
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -384,7 +384,7 @@ let EventTargetParent = {
|
||||
// Check if |target| is somewhere on the patch from the
|
||||
// <tabbrowser> up to the root element.
|
||||
let window = target.ownerDocument.defaultView;
|
||||
if (target.contains(window.gBrowser)) {
|
||||
if (window && target.contains(window.gBrowser)) {
|
||||
return window;
|
||||
}
|
||||
}
|
||||
|
@ -568,7 +568,10 @@ function Search(searchString, searchParam, autocompleteListener,
|
||||
// Set the default behavior for this search.
|
||||
this._behavior = this._searchString ? Prefs.defaultBehavior
|
||||
: Prefs.emptySearchDefaultBehavior;
|
||||
this._enableActions = searchParam.split(" ").indexOf("enable-actions") != -1;
|
||||
|
||||
let params = new Set(searchParam.split(" "));
|
||||
this._enableActions = params.has("enable-actions");
|
||||
this._disablePrivateActions = params.has("disable-private-actions");
|
||||
|
||||
this._searchTokens =
|
||||
this.filterTokens(getUnfilteredSearchTokens(this._searchString));
|
||||
@ -630,8 +633,14 @@ Search.prototype = {
|
||||
* @return true if the behavior is set, false otherwise.
|
||||
*/
|
||||
hasBehavior: function (type) {
|
||||
return this._behavior &
|
||||
Ci.mozIPlacesAutoComplete["BEHAVIOR_" + type.toUpperCase()];
|
||||
let behavior = Ci.mozIPlacesAutoComplete["BEHAVIOR_" + type.toUpperCase()];
|
||||
|
||||
if (this._disablePrivateActions &&
|
||||
behavior == Ci.mozIPlacesAutoComplete.BEHAVIOR_OPENPAGE) {
|
||||
return false;
|
||||
}
|
||||
|
||||
return this._behavior & behavior;
|
||||
},
|
||||
|
||||
/**
|
||||
|
@ -498,8 +498,9 @@ nsPlacesAutoComplete.prototype = {
|
||||
this._currentSearchString =
|
||||
fixupSearchText(this._originalSearchString.toLowerCase());
|
||||
|
||||
let searchParamParts = aSearchParam.split(" ");
|
||||
this._enableActions = searchParamParts.indexOf("enable-actions") != -1;
|
||||
let params = new Set(aSearchParam.split(" "));
|
||||
this._enableActions = params.has("enable-actions");
|
||||
this._disablePrivateActions = params.has("disable-private-actions");
|
||||
|
||||
this._listener = aListener;
|
||||
let result = Cc["@mozilla.org/autocomplete/simple-result;1"].
|
||||
@ -1293,8 +1294,14 @@ nsPlacesAutoComplete.prototype = {
|
||||
*/
|
||||
_hasBehavior: function PAC_hasBehavior(aType)
|
||||
{
|
||||
return (this._behavior &
|
||||
Ci.mozIPlacesAutoComplete["BEHAVIOR_" + aType.toUpperCase()]);
|
||||
let behavior = Ci.mozIPlacesAutoComplete["BEHAVIOR_" + aType.toUpperCase()];
|
||||
|
||||
if (this._disablePrivateActions &&
|
||||
behavior == Ci.mozIPlacesAutoComplete.BEHAVIOR_OPENPAGE) {
|
||||
return false;
|
||||
}
|
||||
|
||||
return this._behavior & behavior;
|
||||
},
|
||||
|
||||
/**
|
||||
|
@ -60,6 +60,23 @@ add_task(function* test_tab_matches() {
|
||||
{ uri: makeActionURI("switchtab", {url: "http://xyz.net/"}), title: "xyz.net - we're better than ABC", style: [ "action", "switchtab" ] } ]
|
||||
});
|
||||
|
||||
do_log_info("three results, no tab matches (disable-private-actions)");
|
||||
yield check_autocomplete({
|
||||
search: "abc",
|
||||
searchParam: "enable-actions disable-private-actions",
|
||||
matches: [ { uri: makeActionURI("searchengine", {engineName: "MozSearch", input: "abc", searchQuery: "abc"}), title: "MozSearch", style: [ "action", "searchengine" ] },
|
||||
{ uri: uri1, title: "ABC rocks", style: [ "favicon" ] },
|
||||
{ uri: uri2, title: "xyz.net - we're better than ABC", style: [ "favicon" ] } ]
|
||||
});
|
||||
|
||||
do_log_info("two results (actions disabled)");
|
||||
yield check_autocomplete({
|
||||
search: "abc",
|
||||
searchParam: "",
|
||||
matches: [ { uri: uri1, title: "ABC rocks", style: [ "favicon" ] },
|
||||
{ uri: uri2, title: "xyz.net - we're better than ABC", style: [ "favicon" ] } ]
|
||||
});
|
||||
|
||||
do_log_info("three results, no tab matches");
|
||||
removeOpenPages(uri1, 1);
|
||||
removeOpenPages(uri2, 6);
|
||||
|
Loading…
Reference in New Issue
Block a user