Bug 1365780 - Consistently dispatch the TabAttrModified event and update the title bar when setting tab labels. r=mikedeboer

MozReview-Commit-ID: 1SNHtyw5hQ8

--HG--
extra : rebase_source : ab9176f3a90531f57a448f2661fa0b70e48d4f7a
This commit is contained in:
Dão Gottwald 2017-05-19 14:19:06 +02:00
Родитель 5a98022984
Коммит 5675800b1d
3 изменённых файлов: 45 добавлений и 14 удалений

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

@ -1000,11 +1000,15 @@
var newTitle = "";
var docElement = this.ownerDocument.documentElement;
var sep = docElement.getAttribute("titlemenuseparator");
let tab = this.getTabForBrowser(aBrowser);
let docTitle;
// Strip out any null bytes in the content title, since the
// underlying widget implementations of nsWindow::SetTitle pass
// null-terminated strings to system APIs.
var docTitle = aBrowser.contentTitle.replace(/\0/g, "");
if (tab._labelIsContentTitle) {
// Strip out any null bytes in the content title, since the
// underlying widget implementations of nsWindow::SetTitle pass
// null-terminated strings to system APIs.
docTitle = tab.getAttribute("label").replace(/\0/g, "");
}
if (!docTitle)
docTitle = docElement.getAttribute("titledefault");
@ -1412,13 +1416,14 @@
<method name="setInitialTabTitle">
<parameter name="aTab"/>
<parameter name="aTitle"/>
<parameter name="aOptions"/>
<body><![CDATA[
if (aTitle) {
aTab.setAttribute("label", aTitle);
// Don't replace the set label with the empty tab label or the URL
// while the tab is loading.
aTab._suppressTransientPlaceholderLabel = true;
this._setTabLabel(aTab, aTitle, aOptions);
}
]]></body>
</method>
@ -1437,7 +1442,10 @@
delete aTab._suppressTransientPlaceholderLabel;
}
if (!title) {
let isContentTitle = false;
if (title) {
isContentTitle = true;
} else {
if (browser.currentURI.spec) {
try {
title = this.mURIFixup.createExposableURI(browser.currentURI).spec;
@ -1465,14 +1473,33 @@
title = this.mStringBundle.getString("tabs.emptyTabTitle");
}
if (aTab.label == title)
return this._setTabLabel(aTab, title, { isContentTitle });
]]>
</body>
</method>
<method name="_setTabLabel">
<parameter name="aTab"/>
<parameter name="aLabel"/>
<parameter name="aOptions"/>
<body>
<![CDATA[
if (!aLabel || aTab.getAttribute("label") == aLabel) {
return false;
}
aTab.label = title;
this._tabAttrModified(aTab, ["label"]);
aTab.setAttribute("label", aLabel);
aTab._labelIsContentTitle = aOptions && aOptions.isContentTitle;
if (aTab.selected)
// Dispatch TabAttrModified event unless we're setting the label
// before the TabOpen event was dispatched.
if (!aOptions || !aOptions.beforeTabOpen) {
this._tabAttrModified(aTab, ["label"]);
}
if (aTab.selected) {
this.updateTitlebar();
}
return true;
]]>
@ -2313,7 +2340,7 @@
t.setAttribute("label", this.mStringBundle.getString("tabs.emptyTabTitle"));
} else {
// Set URL as label so that the tab isn't empty initially.
this.setInitialTabTitle(t, aURI);
this.setInitialTabTitle(t, aURI, { beforeTabOpen: true });
}
}

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

@ -2646,7 +2646,7 @@ var SessionStoreInternal = {
// If the page has a title, set it.
if (activePageData) {
if (activePageData.title) {
win.gBrowser.setInitialTabTitle(tab, activePageData.title);
win.gBrowser.setInitialTabTitle(tab, activePageData.title, { isContentTitle: true });
} else if (activePageData.url != "about:blank") {
win.gBrowser.setInitialTabTitle(tab, activePageData.url);
}

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

@ -51,6 +51,7 @@ add_task(async function() {
isnot(CONTENT_TITLE.length, 0, "content title isn't empty");
isnot(CONTENT_TITLE, TEST_URL, "content title is different from the URL");
is(firstTab.label, CONTENT_TITLE, "first tab displays content title");
ok(document.title.startsWith(CONTENT_TITLE), "title bar displays content title");
ok(secondTab.hasAttribute("pending"), "second tab is pending");
is(secondTab.label, TEST_URL, "second tab displays URL as its title");
@ -60,7 +61,8 @@ add_task(async function() {
gBrowser.selectedTab = secondTab;
await browserLoadedPromise;
ok(!secondTab.hasAttribute("pending"), "second tab isn't pending anymore");
is(gBrowser.selectedTab.label, CONTENT_TITLE, "second tab displays content title");
is(secondTab.label, CONTENT_TITLE, "second tab displays content title");
ok(document.title.startsWith(CONTENT_TITLE), "title bar displays content title");
checkLabelChangeCount(1);
info("restoring the modified browser state");
@ -68,6 +70,7 @@ add_task(async function() {
await promiseBrowserState(SessionStore.getBrowserState());
[firstTab, secondTab] = gBrowser.tabs;
is(secondTab, gBrowser.selectedTab, "second tab is selected after restoring");
ok(document.title.startsWith(CONTENT_TITLE), "title bar displays content title");
ok(firstTab.hasAttribute("pending"), "first tab is pending after restoring");
is(firstTab.label, CONTENT_TITLE, "first tab displays content title in pending state");
@ -75,6 +78,7 @@ add_task(async function() {
checkLabelChangeCount = observeLabelChanges(firstTab);
let tabContentRestored = TestUtils.topicObserved("sessionstore-debug-tab-restored");
gBrowser.selectedTab = firstTab;
ok(document.title.startsWith(CONTENT_TITLE), "title bar displays content title");
await tabContentRestored;
ok(!firstTab.hasAttribute("pending"), "first tab isn't pending anymore");
checkLabelChangeCount(0);