Bug 1586889 - Stop re-initializing the urlbar when exiting customize mode. r=mak

Differential Revision: https://phabricator.services.mozilla.com/D49405

--HG--
extra : moz-landing-system : lando
This commit is contained in:
Dão Gottwald 2019-10-17 09:03:12 +00:00
Родитель 459b71deed
Коммит 97dc13cb94
5 изменённых файлов: 29 добавлений и 153 удалений

Просмотреть файл

@ -40,8 +40,6 @@ var CustomizationHandler = {
UpdateUrlbarSearchSplitterState();
PlacesToolbarHelper.customizeStart();
gURLBarHandler.customizeStart();
},
_afterCustomization() {
@ -65,7 +63,6 @@ var CustomizationHandler = {
gBrowser.selectedBrowser.focus();
// Update the urlbar
gURLBarHandler.customizeEnd();
URLBarSetURI();
UpdateUrlbarSearchSplitterState();
},

Просмотреть файл

@ -311,59 +311,12 @@ XPCOMUtils.defineLazyGetter(this, "gNavToolbox", () => {
return document.getElementById("navigator-toolbox");
});
XPCOMUtils.defineLazyGetter(this, "gURLBar", () => gURLBarHandler.urlbar);
/**
* Tracks the urlbar object, allowing to reinitiate it when necessary, e.g. on
* customization.
*/
var gURLBarHandler = {
/**
* The urlbar binding or object.
*/
get urlbar() {
if (!this._urlbar) {
let textbox = document.getElementById("urlbar");
this._urlbar = new UrlbarInput({
textbox,
eventTelemetryCategory: "urlbar",
});
if (this._lastValue) {
this._urlbar.value = this._lastValue;
delete this._lastValue;
}
}
return this._urlbar;
},
/**
* Invoked by CustomizationHandler when a customization starts.
*/
customizeStart() {
if (this._urlbar) {
this._urlbar.removeCopyCutController();
}
},
/**
* Invoked by CustomizationHandler when a customization ends.
*/
customizeEnd() {
this._reset();
},
/**
* Used to reset the gURLBar value.
*/
_reset() {
if (this._urlbar) {
this._lastValue = this._urlbar.value;
this._urlbar.uninit();
delete this._urlbar;
gURLBar = this.urlbar;
}
},
};
XPCOMUtils.defineLazyGetter(this, "gURLBar", () => {
return new UrlbarInput({
textbox: document.getElementById("urlbar"),
eventTelemetryCategory: "urlbar",
});
});
XPCOMUtils.defineLazyGetter(this, "ReferrerInfo", () =>
Components.Constructor(

Просмотреть файл

@ -80,13 +80,6 @@ class UrlbarController {
this.engagementEvent = new TelemetryEvent(options.eventTelemetryCategory);
}
uninit() {
this.browserWindow = null;
this.input = null;
this.view = null;
this._listeners.clear();
}
get NOTIFICATIONS() {
return NOTIFICATIONS;
}

Просмотреть файл

@ -208,11 +208,12 @@ class UrlbarInput {
this.window.gBrowser.tabContainer.addEventListener("TabSelect", this);
this._copyCutController = new CopyCutController(this);
this.inputField.controllers.insertControllerAt(0, this._copyCutController);
this.window.addEventListener("customizationstarting", this);
this.window.addEventListener("aftercustomization", this);
this.updateLayoutBreakout();
this._initCopyCutController();
this._initPasteAndGo();
// Tracks IME composition.
@ -226,71 +227,6 @@ class UrlbarInput {
Services.prefs.addObserver("browser.urlbar.openViewOnFocus", this);
}
/**
* Uninitializes this input object, detaching it from the inputField.
*/
uninit() {
this.window.removeEventListener("unload", this);
for (let name of this._inputFieldEvents) {
this.removeEventListener(name, this);
}
this.dropmarker.removeEventListener("mousedown", this);
this.window.removeEventListener("mousedown", this);
this.textbox.removeEventListener("mousedown", this);
this._inputContainer.removeEventListener("click", this);
this.window.gBrowser.tabContainer.removeEventListener("TabSelect", this);
this.view.panel.remove();
this.endLayoutExtend(true);
// When uninit is called due to exiting the browser's customize mode,
// this.inputField.controllers is not the original list of controllers, and
// it doesn't contain CopyCutController. That's why removeCopyCutController
// must be called when entering customize mode. If uninit ends up getting
// called by something else though, try to remove the controller now.
try {
// If removeCopyCutController throws, then the controller isn't in the
// list of the input's controllers, and the consumer should have called
// removeCopyCutController at some earlier point, e.g., when customize
// mode was entered.
this.removeCopyCutController();
} catch (ex) {
Cu.reportError(
"Leaking UrlbarInput._copyCutController! You should have called removeCopyCutController!"
);
}
if (Object.getOwnPropertyDescriptor(this, "valueFormatter").get) {
this.valueFormatter.uninit();
}
Services.prefs.removeObserver("browser.urlbar.openViewOnFocus", this);
this.controller.uninit();
delete this.document;
delete this.window;
delete this.eventBufferer;
delete this.valueFormatter;
delete this.panel;
delete this.view;
delete this.controller;
delete this.textbox;
delete this.inputField;
delete this._layoutBreakoutUpdateKey;
}
/**
* Removes the CopyCutController from the input's controllers list. This must
* be called when the browser's customize mode is entered.
*/
removeCopyCutController() {
if (this._copyCutController) {
this.inputField.controllers.removeController(this._copyCutController);
delete this._copyCutController;
}
}
/**
* Shortens the given value, usually by removing http:// and trailing slashes,
* such that calling nsIURIFixup::createFixupURI with the result will produce
@ -1017,11 +953,6 @@ class UrlbarInput {
return;
}
await this._updateLayoutBreakoutDimensions();
if (!this.textbox) {
// We may have been uninitialized while waiting for
// _updateLayoutBreakoutDimensions.
return;
}
this.startLayoutExtend();
}
@ -1061,13 +992,7 @@ class UrlbarInput {
// doesn't run when opening a new window.
if (!this.hasAttribute("breakout-extend-animate")) {
this.window.promiseDocumentFlushed(() => {
if (!this.window) {
return;
}
this.window.requestAnimationFrame(() => {
if (!this.textbox) {
return;
}
this.setAttribute("breakout-extend-animate", "true");
});
});
@ -1103,11 +1028,6 @@ class UrlbarInput {
await this.window.promiseDocumentFlushed(() => {});
await new Promise(resolve => {
if (!this.window) {
// We may have been uninitialized while waiting for layout.
resolve();
return;
}
this.window.requestAnimationFrame(() => {
if (this._layoutBreakoutUpdateKey != updateKey) {
return;
@ -1647,6 +1567,11 @@ class UrlbarInput {
return where;
}
_initCopyCutController() {
this._copyCutController = new CopyCutController(this);
this.inputField.controllers.insertControllerAt(0, this._copyCutController);
}
_initPasteAndGo() {
let inputBox = this.querySelector("moz-input-box");
let contextMenu = inputBox.menupopup;
@ -2184,10 +2109,22 @@ class UrlbarInput {
}
}
_on_customizationstarting() {
this.blur();
this.inputField.controllers.removeController(this._copyCutController);
delete this._copyCutController;
}
_on_aftercustomization() {
this._initCopyCutController();
this._initPasteAndGo();
}
_on_unload() {
// FIXME: This is needed because uninit calls removePrefObserver. We can
// remove this once UrlbarPrefs has support for listeners. (bug 1560013)
this.uninit();
// We can remove this once UrlbarPrefs has support for listeners.
// (bug 1560013)
Services.prefs.removeObserver("browser.urlbar.openViewOnFocus", this);
}
}

Просмотреть файл

@ -38,10 +38,6 @@ class UrlbarValueFormatter {
this.window.addEventListener("resize", this);
}
uninit() {
this.window.removeEventListener("resize", this);
}
get inputField() {
return this.urlbarInput.inputField;
}