mirror of
https://repo.dactyloidae.xyz/Dactyloidae/UXP.git
synced 2026-10-24 08:07:30 +09:00
Fix bug where search bar in about:home does nothing
This commit is contained in:
parent
bd5b144112
commit
6dfeba05d1
7 changed files with 104 additions and 9 deletions
|
|
@ -120,6 +120,7 @@ a {
|
||||||
transition-property: background-color, border-color, box-shadow;
|
transition-property: background-color, border-color, box-shadow;
|
||||||
transition-duration: 150ms;
|
transition-duration: 150ms;
|
||||||
width: 50px;
|
width: 50px;
|
||||||
|
display: none;
|
||||||
}
|
}
|
||||||
|
|
||||||
#searchSubmit:dir(rtl) {
|
#searchSubmit:dir(rtl) {
|
||||||
|
|
|
||||||
|
|
@ -27,7 +27,10 @@ window.addEventListener("pageshow", function () {
|
||||||
// Delay search engine setup, cause browser.js::BrowserOnAboutPageLoad runs
|
// Delay search engine setup, cause browser.js::BrowserOnAboutPageLoad runs
|
||||||
// later and may use asynchronous getters.
|
// later and may use asynchronous getters.
|
||||||
window.gObserver.observe(document.documentElement, { attributes: true });
|
window.gObserver.observe(document.documentElement, { attributes: true });
|
||||||
window.gObserver.observe(document.getElementById("launcher"), { attributes: true });
|
let launcher = document.getElementById("launcher");
|
||||||
|
if (launcher) {
|
||||||
|
window.gObserver.observe(launcher, { attributes: true });
|
||||||
|
}
|
||||||
fitToWidth();
|
fitToWidth();
|
||||||
setupSearch();
|
setupSearch();
|
||||||
window.addEventListener("resize", fitToWidth);
|
window.addEventListener("resize", fitToWidth);
|
||||||
|
|
@ -72,7 +75,22 @@ window.addEventListener("keypress", ev => {
|
||||||
|
|
||||||
function onSearchSubmit(aEvent)
|
function onSearchSubmit(aEvent)
|
||||||
{
|
{
|
||||||
gContentSearchController.search(aEvent);
|
if (aEvent instanceof MouseEvent && gContentSearchController &&
|
||||||
|
gContentSearchController.defaultEngine) {
|
||||||
|
gContentSearchController.search(aEvent);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
// Fallback path for builds where ContentSearch mediation fails.
|
||||||
|
let terms = searchText && searchText.value ? searchText.value.trim() : "";
|
||||||
|
if (!terms) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
document.dispatchEvent(new CustomEvent("AboutHomeSearch", {
|
||||||
|
bubbles: true,
|
||||||
|
detail: { searchString: terms },
|
||||||
|
}));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
@ -80,10 +98,13 @@ var gContentSearchController;
|
||||||
|
|
||||||
function setupSearch()
|
function setupSearch()
|
||||||
{
|
{
|
||||||
|
let searchSubmit = document.getElementById("searchSubmit");
|
||||||
|
|
||||||
// Set submit button label for when CSS background are disabled (e.g.
|
// Set submit button label for when CSS background are disabled (e.g.
|
||||||
// high contrast mode).
|
// high contrast mode).
|
||||||
document.getElementById("searchSubmit").value =
|
searchSubmit.value =
|
||||||
document.body.getAttribute("dir") == "ltr" ? "\u25B6" : "\u25C0";
|
document.body.getAttribute("dir") == "ltr" ? "\u25B6" : "\u25C0";
|
||||||
|
searchSubmit.addEventListener("click", onSearchSubmit, true);
|
||||||
|
|
||||||
// The "autofocus" attribute doesn't focus the form element
|
// The "autofocus" attribute doesn't focus the form element
|
||||||
// immediately when the element is first drawn, so the
|
// immediately when the element is first drawn, so the
|
||||||
|
|
@ -99,6 +120,14 @@ function setupSearch()
|
||||||
new ContentSearchUIController(searchText, searchText.parentNode,
|
new ContentSearchUIController(searchText, searchText.parentNode,
|
||||||
"abouthome", "homepage");
|
"abouthome", "homepage");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
searchText.addEventListener("keypress", function(event) {
|
||||||
|
if (event.keyCode == event.DOM_VK_RETURN) {
|
||||||
|
event.preventDefault();
|
||||||
|
event.stopPropagation();
|
||||||
|
onSearchSubmit(event);
|
||||||
|
}
|
||||||
|
}, true);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
|
||||||
|
|
@ -42,7 +42,7 @@
|
||||||
<div id="searchIcon"/>
|
<div id="searchIcon"/>
|
||||||
<input type="text" name="q" value="" id="searchText" maxlength="256"
|
<input type="text" name="q" value="" id="searchText" maxlength="256"
|
||||||
aria-label="&contentSearchInput.label;" autofocus="autofocus"/>
|
aria-label="&contentSearchInput.label;" autofocus="autofocus"/>
|
||||||
<input id="searchSubmit" type="button" onclick="onSearchSubmit(event)"
|
<input id="searchSubmit" type="button"
|
||||||
title="&contentSearchSubmit.tooltip;"/>
|
title="&contentSearchSubmit.tooltip;"/>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
|
|
|
||||||
|
|
@ -82,10 +82,22 @@ addMessageListener("MixedContent:ReenableProtection", function() {
|
||||||
var AboutHomeListener = {
|
var AboutHomeListener = {
|
||||||
init: function(chromeGlobal) {
|
init: function(chromeGlobal) {
|
||||||
chromeGlobal.addEventListener('AboutHomeLoad', this, false, true);
|
chromeGlobal.addEventListener('AboutHomeLoad', this, false, true);
|
||||||
|
chromeGlobal.addEventListener('AboutHomeSearch', this, false, true);
|
||||||
|
},
|
||||||
|
|
||||||
|
_isAboutHomeDocumentURI(uri) {
|
||||||
|
if (!uri) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
let lowerURI = uri.toLowerCase();
|
||||||
|
return lowerURI == "about:home" ||
|
||||||
|
lowerURI.startsWith("about:home?") ||
|
||||||
|
lowerURI.startsWith("about:home#") ||
|
||||||
|
lowerURI == "chrome://browser/content/abouthome/abouthome.xhtml";
|
||||||
},
|
},
|
||||||
|
|
||||||
get isAboutHome() {
|
get isAboutHome() {
|
||||||
return content.document.documentURI.toLowerCase() == "about:home";
|
return this._isAboutHomeDocumentURI(content.document.documentURI);
|
||||||
},
|
},
|
||||||
|
|
||||||
handleEvent: function(aEvent) {
|
handleEvent: function(aEvent) {
|
||||||
|
|
@ -96,6 +108,9 @@ var AboutHomeListener = {
|
||||||
case "AboutHomeLoad":
|
case "AboutHomeLoad":
|
||||||
this.onPageLoad();
|
this.onPageLoad();
|
||||||
break;
|
break;
|
||||||
|
case "AboutHomeSearch":
|
||||||
|
this.onSearch(aEvent);
|
||||||
|
break;
|
||||||
case "click":
|
case "click":
|
||||||
this.onClick(aEvent);
|
this.onClick(aEvent);
|
||||||
break;
|
break;
|
||||||
|
|
@ -144,7 +159,7 @@ var AboutHomeListener = {
|
||||||
|
|
||||||
let originalTarget = aEvent.originalTarget;
|
let originalTarget = aEvent.originalTarget;
|
||||||
let ownerDoc = originalTarget.ownerDocument;
|
let ownerDoc = originalTarget.ownerDocument;
|
||||||
if (ownerDoc.documentURI != "about:home") {
|
if (!this._isAboutHomeDocumentURI(ownerDoc.documentURI)) {
|
||||||
// This shouldn't happen, but we're being defensive.
|
// This shouldn't happen, but we're being defensive.
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
@ -191,6 +206,25 @@ var AboutHomeListener = {
|
||||||
removeEventListener("click", this, true);
|
removeEventListener("click", this, true);
|
||||||
removeEventListener("pagehide", this, true);
|
removeEventListener("pagehide", this, true);
|
||||||
},
|
},
|
||||||
|
|
||||||
|
onSearch: function(aEvent) {
|
||||||
|
let originalTarget = aEvent.originalTarget || aEvent.target;
|
||||||
|
let ownerDoc = originalTarget && originalTarget.ownerDocument;
|
||||||
|
if (!ownerDoc && originalTarget && originalTarget.nodeType == Ci.nsIDOMNode.DOCUMENT_NODE) {
|
||||||
|
ownerDoc = originalTarget;
|
||||||
|
}
|
||||||
|
if (!ownerDoc || !this._isAboutHomeDocumentURI(ownerDoc.documentURI)) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
let detail = aEvent.detail || {};
|
||||||
|
let searchString = (detail.searchString || "").trim();
|
||||||
|
if (!searchString) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
sendAsyncMessage("AboutHome:Search", { searchString });
|
||||||
|
},
|
||||||
};
|
};
|
||||||
AboutHomeListener.init(this);
|
AboutHomeListener.init(this);
|
||||||
|
|
||||||
|
|
@ -362,6 +396,7 @@ var ContentSearchMediator = {
|
||||||
whitelist: new Set([
|
whitelist: new Set([
|
||||||
"about:home",
|
"about:home",
|
||||||
"about:newtab",
|
"about:newtab",
|
||||||
|
"chrome://browser/content/abouthome/aboutHome.xhtml",
|
||||||
]),
|
]),
|
||||||
|
|
||||||
init: function (chromeGlobal) {
|
init: function (chromeGlobal) {
|
||||||
|
|
@ -389,7 +424,11 @@ var ContentSearchMediator = {
|
||||||
},
|
},
|
||||||
|
|
||||||
get _contentWhitelisted() {
|
get _contentWhitelisted() {
|
||||||
return this.whitelist.has(content.document.documentURI);
|
let documentURI = content.document.documentURI;
|
||||||
|
// about:home may carry query/hash fragments; whitelist should apply to the
|
||||||
|
// base page URI so search events are not dropped for those variants.
|
||||||
|
let baseURI = documentURI.replace(/[?#].*$/, "");
|
||||||
|
return this.whitelist.has(baseURI);
|
||||||
},
|
},
|
||||||
|
|
||||||
_sendMsg: function (type, data=null) {
|
_sendMsg: function (type, data=null) {
|
||||||
|
|
|
||||||
|
|
@ -27,7 +27,7 @@ this.__defineGetter__("BROWSER_NEW_TAB_URL", () => {
|
||||||
!aboutNewTabService.overridden) {
|
!aboutNewTabService.overridden) {
|
||||||
return "about:privatebrowsing";
|
return "about:privatebrowsing";
|
||||||
}
|
}
|
||||||
return aboutNewTabService.newTabURL;
|
return "about:home";
|
||||||
});
|
});
|
||||||
|
|
||||||
var TAB_DROP_TYPE = "application/x-moz-tabbrowser-tab";
|
var TAB_DROP_TYPE = "application/x-moz-tabbrowser-tab";
|
||||||
|
|
|
||||||
|
|
@ -27,7 +27,7 @@ const LOCAL_NEWTAB_URL = "chrome://browser/content/newtab/newTab.xhtml";
|
||||||
|
|
||||||
const REMOTE_NEWTAB_PATH = "/newtab/v%VERSION%/%CHANNEL%/%LOCALE%/index.html";
|
const REMOTE_NEWTAB_PATH = "/newtab/v%VERSION%/%CHANNEL%/%LOCALE%/index.html";
|
||||||
|
|
||||||
const ABOUT_URL = "about:newtab";
|
const ABOUT_URL = "about:home";
|
||||||
|
|
||||||
// Pref that tells if remote newtab is enabled
|
// Pref that tells if remote newtab is enabled
|
||||||
const PREF_REMOTE_ENABLED = "browser.newtabpage.remote";
|
const PREF_REMOTE_ENABLED = "browser.newtabpage.remote";
|
||||||
|
|
|
||||||
|
|
@ -81,6 +81,7 @@ var AboutHome = {
|
||||||
"AboutHome:Addons",
|
"AboutHome:Addons",
|
||||||
"AboutHome:Sync",
|
"AboutHome:Sync",
|
||||||
"AboutHome:Settings",
|
"AboutHome:Settings",
|
||||||
|
"AboutHome:Search",
|
||||||
"AboutHome:RequestUpdate",
|
"AboutHome:RequestUpdate",
|
||||||
"AboutHome:MaybeShowAutoMigrationUndoNotification",
|
"AboutHome:MaybeShowAutoMigrationUndoNotification",
|
||||||
],
|
],
|
||||||
|
|
@ -129,6 +130,31 @@ var AboutHome = {
|
||||||
window.openPreferences();
|
window.openPreferences();
|
||||||
break;
|
break;
|
||||||
|
|
||||||
|
case "AboutHome:Search": {
|
||||||
|
let data = aMessage.data || {};
|
||||||
|
let searchString = (data.searchString || "").trim();
|
||||||
|
if (!searchString) {
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
|
||||||
|
let engine = Services.search.defaultEngine;
|
||||||
|
if (!engine) {
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
|
||||||
|
let submission = engine.getSubmission(searchString, "", "homepage");
|
||||||
|
if (!submission) {
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
|
||||||
|
aMessage.target.loadURIWithFlags(submission.uri.spec,
|
||||||
|
Ci.nsIWebNavigation.LOAD_FLAGS_NONE,
|
||||||
|
null,
|
||||||
|
null,
|
||||||
|
submission.postData);
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
|
||||||
case "AboutHome:RequestUpdate":
|
case "AboutHome:RequestUpdate":
|
||||||
this.sendAboutHomeData(aMessage.target);
|
this.sendAboutHomeData(aMessage.target);
|
||||||
break;
|
break;
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue