Bug 1486984 - Fix find commands for PDF and special pages, and remove obsolete code. r=Gijs
Support for finding text in a page is now determined by a blacklist of locations, simplifying handling in multi-process mode and restoring the intended behavior. Differential Revision: https://phabricator.services.mozilla.com/D8005
This commit is contained in:
@@ -4674,19 +4674,24 @@ var XULBrowserWindow = {
|
||||
delete this.reloadCommand;
|
||||
return this.reloadCommand = document.getElementById("Browser:Reload");
|
||||
},
|
||||
get elementsForTextBasedTypes() {
|
||||
delete this.elementsForTextBasedTypes;
|
||||
return this.elementsForTextBasedTypes = [
|
||||
get _elementsForTextBasedTypes() {
|
||||
delete this._elementsForTextBasedTypes;
|
||||
return this._elementsForTextBasedTypes = [
|
||||
document.getElementById("pageStyleMenu"),
|
||||
document.getElementById("context-viewpartialsource-selection"),
|
||||
];
|
||||
},
|
||||
get _elementsForFind() {
|
||||
delete this._elementsForFind;
|
||||
return this._elementsForFind = [
|
||||
document.getElementById("cmd_find"),
|
||||
document.getElementById("cmd_findAgain"),
|
||||
document.getElementById("cmd_findPrevious"),
|
||||
];
|
||||
},
|
||||
get elementsForViewSource() {
|
||||
delete this.elementsForViewSource;
|
||||
return this.elementsForViewSource = [
|
||||
get _elementsForViewSource() {
|
||||
delete this._elementsForViewSource;
|
||||
return this._elementsForViewSource = [
|
||||
document.getElementById("context-viewsource"),
|
||||
document.getElementById("View:PageSource"),
|
||||
];
|
||||
@@ -4840,24 +4845,18 @@ var XULBrowserWindow = {
|
||||
this.status = "";
|
||||
this.setDefaultStatus(msg);
|
||||
|
||||
// Disable menu entries for images, enable otherwise
|
||||
// Disable View Source menu entries for images, enable otherwise
|
||||
let isText = browser.documentContentType &&
|
||||
BrowserUtils.mimeTypeIsTextBased(browser.documentContentType);
|
||||
for (let element of this.elementsForTextBasedTypes) {
|
||||
if (isText) {
|
||||
element.removeAttribute("disabled");
|
||||
} else {
|
||||
element.setAttribute("disabled", "true");
|
||||
}
|
||||
}
|
||||
|
||||
for (let element of this.elementsForViewSource) {
|
||||
for (let element of this._elementsForViewSource) {
|
||||
if (canViewSource && isText) {
|
||||
element.removeAttribute("disabled");
|
||||
} else {
|
||||
element.setAttribute("disabled", "true");
|
||||
}
|
||||
}
|
||||
|
||||
this._updateElementsForContentType();
|
||||
}
|
||||
|
||||
this.isBusy = false;
|
||||
@@ -4892,19 +4891,6 @@ var XULBrowserWindow = {
|
||||
}
|
||||
}
|
||||
|
||||
let browser = gBrowser.selectedBrowser;
|
||||
|
||||
// Disable menu entries for images, enable otherwise
|
||||
let isText = browser.documentContentType &&
|
||||
BrowserUtils.mimeTypeIsTextBased(browser.documentContentType);
|
||||
for (let element of this.elementsForTextBasedTypes) {
|
||||
if (isText) {
|
||||
element.removeAttribute("disabled");
|
||||
} else {
|
||||
element.setAttribute("disabled", "true");
|
||||
}
|
||||
}
|
||||
|
||||
this.hideOverLinkImmediately = true;
|
||||
this.setOverLink("", null);
|
||||
this.hideOverLinkImmediately = false;
|
||||
@@ -4939,46 +4925,7 @@ var XULBrowserWindow = {
|
||||
|
||||
gTabletModePageCounter.inc();
|
||||
|
||||
// Utility functions for disabling find
|
||||
var shouldDisableFind = function(aDocument) {
|
||||
let docElt = aDocument.documentElement;
|
||||
return docElt && docElt.getAttribute("disablefastfind") == "true";
|
||||
};
|
||||
|
||||
var disableFindCommands = function(aDisable) {
|
||||
let findCommands = [document.getElementById("cmd_find"),
|
||||
document.getElementById("cmd_findAgain"),
|
||||
document.getElementById("cmd_findPrevious")];
|
||||
for (let elt of findCommands) {
|
||||
if (aDisable)
|
||||
elt.setAttribute("disabled", "true");
|
||||
else
|
||||
elt.removeAttribute("disabled");
|
||||
}
|
||||
};
|
||||
|
||||
var onContentRSChange = function(e) {
|
||||
if (e.target.readyState != "interactive" && e.target.readyState != "complete")
|
||||
return;
|
||||
|
||||
e.target.removeEventListener("readystatechange", onContentRSChange);
|
||||
disableFindCommands(shouldDisableFind(e.target));
|
||||
};
|
||||
|
||||
// Disable find commands in documents that ask for them to be disabled.
|
||||
if (!gMultiProcessBrowser && aLocationURI &&
|
||||
(aLocationURI.schemeIs("about") || aLocationURI.schemeIs("chrome"))) {
|
||||
// Don't need to re-enable/disable find commands for same-document location changes
|
||||
// (e.g. the replaceStates in about:addons)
|
||||
if (!(aFlags & Ci.nsIWebProgressListener.LOCATION_CHANGE_SAME_DOCUMENT)) {
|
||||
if (window.content.document.readyState == "interactive" || window.content.document.readyState == "complete")
|
||||
disableFindCommands(shouldDisableFind(window.content.document));
|
||||
else {
|
||||
window.content.document.addEventListener("readystatechange", onContentRSChange);
|
||||
}
|
||||
}
|
||||
} else
|
||||
disableFindCommands(false);
|
||||
this._updateElementsForContentType();
|
||||
|
||||
// Try not to instantiate gCustomizeMode as much as possible,
|
||||
// so don't use CustomizeMode.jsm to check for URI or customizing.
|
||||
@@ -5025,6 +4972,32 @@ var XULBrowserWindow = {
|
||||
}
|
||||
},
|
||||
|
||||
_updateElementsForContentType() {
|
||||
let browser = gBrowser.selectedBrowser;
|
||||
|
||||
let isText = browser.documentContentType &&
|
||||
BrowserUtils.mimeTypeIsTextBased(browser.documentContentType);
|
||||
for (let element of this._elementsForTextBasedTypes) {
|
||||
if (isText) {
|
||||
element.removeAttribute("disabled");
|
||||
} else {
|
||||
element.setAttribute("disabled", "true");
|
||||
}
|
||||
}
|
||||
|
||||
// Always enable find commands in PDF documents, otherwise do it only for
|
||||
// text documents whose location is not in the blacklist.
|
||||
let enableFind = browser.documentContentType == "application/pdf" ||
|
||||
(isText && BrowserUtils.canFindInPage(gBrowser.currentURI.spec));
|
||||
for (let element of this._elementsForFind) {
|
||||
if (enableFind) {
|
||||
element.removeAttribute("disabled");
|
||||
} else {
|
||||
element.setAttribute("disabled", "true");
|
||||
}
|
||||
}
|
||||
},
|
||||
|
||||
asyncUpdateUI() {
|
||||
BrowserSearch.updateOpenSearchBadge();
|
||||
},
|
||||
|
||||
@@ -13,7 +13,7 @@ function wait_while_tab_is_busy() {
|
||||
}
|
||||
|
||||
// This function waits for the tab to stop being busy instead of waiting for it
|
||||
// to load, since the elementsForViewSource change happens at that time.
|
||||
// to load, since the _elementsForViewSource change happens at that time.
|
||||
var with_new_tab_opened = async function(options, taskFn) {
|
||||
let busyPromise = wait_while_tab_is_busy();
|
||||
let tab = await BrowserTestUtils.openNewForegroundTab(options.gBrowser, options.url, false);
|
||||
@@ -24,7 +24,7 @@ var with_new_tab_opened = async function(options, taskFn) {
|
||||
|
||||
add_task(async function test_regular_page() {
|
||||
function test_expect_view_source_enabled(browser) {
|
||||
for (let element of [...XULBrowserWindow.elementsForViewSource]) {
|
||||
for (let element of [...XULBrowserWindow._elementsForViewSource]) {
|
||||
ok(!element.hasAttribute("disabled"),
|
||||
"View Source should be enabled");
|
||||
}
|
||||
@@ -38,7 +38,7 @@ add_task(async function test_regular_page() {
|
||||
|
||||
add_task(async function test_view_source_page() {
|
||||
function test_expect_view_source_disabled(browser) {
|
||||
for (let element of [...XULBrowserWindow.elementsForViewSource]) {
|
||||
for (let element of [...XULBrowserWindow._elementsForViewSource]) {
|
||||
ok(element.hasAttribute("disabled"),
|
||||
"View Source should be disabled");
|
||||
}
|
||||
|
||||
@@ -33,7 +33,6 @@
|
||||
|
||||
<page xmlns="http://www.mozilla.org/keymaster/gatekeeper/there.is.only.xul"
|
||||
xmlns:html="http://www.w3.org/1999/xhtml"
|
||||
disablefastfind="true"
|
||||
data-l10n-id="pref-page"
|
||||
data-l10n-attrs="title">
|
||||
|
||||
|
||||
@@ -61,8 +61,15 @@ class FindBarChild extends ActorChild {
|
||||
return FindBarContent.start(event);
|
||||
}
|
||||
|
||||
// disable FAYT in about:blank to prevent FAYT opening unexpectedly.
|
||||
let location = this.content.location.href;
|
||||
if (location == "about:blank") {
|
||||
return null;
|
||||
}
|
||||
|
||||
if (event.ctrlKey || event.altKey || event.metaKey || event.defaultPrevented ||
|
||||
!BrowserUtils.canFastFind(this.content)) {
|
||||
!BrowserUtils.mimeTypeIsTextBased(this.content.document.contentType) ||
|
||||
!BrowserUtils.canFindInPage(location)) {
|
||||
return null;
|
||||
}
|
||||
|
||||
|
||||
@@ -16,7 +16,6 @@
|
||||
role="application"
|
||||
width="750"
|
||||
height="500"
|
||||
disablefastfind="true"
|
||||
onunload="onConfigUnload();"
|
||||
onload="onConfigLoad();">
|
||||
|
||||
|
||||
@@ -311,31 +311,16 @@ var BrowserUtils = {
|
||||
},
|
||||
|
||||
/**
|
||||
* Return true if we can FAYT for this window (could be CPOW):
|
||||
*
|
||||
* @param win
|
||||
* The top level window that is focused
|
||||
* Returns true if we can show a find bar, including FAYT, for the specified
|
||||
* document location. The location must not be in a blacklist of specific
|
||||
* "about:" pages for which find is disabled.
|
||||
*
|
||||
* This can be called from the parent process or from content processes.
|
||||
*/
|
||||
canFastFind(win) {
|
||||
if (!win)
|
||||
return false;
|
||||
|
||||
if (!this.mimeTypeIsTextBased(win.document.contentType))
|
||||
return false;
|
||||
|
||||
// disable FAYT in about:blank to prevent FAYT opening unexpectedly.
|
||||
let loc = win.location;
|
||||
if (loc.href == "about:blank")
|
||||
return false;
|
||||
|
||||
// disable FAYT in documents that ask for it to be disabled.
|
||||
if ((loc.protocol == "about:" || loc.protocol == "chrome:") &&
|
||||
(win.document.documentElement &&
|
||||
win.document.documentElement.getAttribute("disablefastfind") == "true"))
|
||||
return false;
|
||||
|
||||
return true;
|
||||
canFindInPage(location) {
|
||||
return !location.startsWith("about:addons") &&
|
||||
!location.startsWith("about:config") &&
|
||||
!location.startsWith("about:preferences");
|
||||
},
|
||||
|
||||
_visibleToolbarsMap: new WeakMap(),
|
||||
|
||||
@@ -17,8 +17,7 @@
|
||||
<page xmlns="http://www.mozilla.org/keymaster/gatekeeper/there.is.only.xul"
|
||||
xmlns:xhtml="http://www.w3.org/1999/xhtml"
|
||||
id="addons-page" data-l10n-id="addons-window"
|
||||
role="application" windowtype="Addons:Manager"
|
||||
disablefastfind="true">
|
||||
role="application" windowtype="Addons:Manager">
|
||||
|
||||
<xhtml:link rel="shortcut icon"
|
||||
href="chrome://mozapps/skin/extensions/extensionGeneric-16.svg"/>
|
||||
|
||||
Reference in New Issue
Block a user