Permalink
Browse files

Issue #31 - implement browser window title customization

  • Loading branch information...
1 parent c061e36 commit 286bb22dae2c7560c6cfa8414390b2f726213787 @xabolcs committed Oct 26, 2012
Showing with 69 additions and 5 deletions.
  1. +69 −5 extension/chrome/content/suite.js
@@ -6,6 +6,18 @@ var nightlyApp = {
repository: ['comm-central','comm-aurora'],
+oldUpdateTitlebar: null,
@xabolcs

xabolcs Nov 9, 2012

Owner

I'd like to convert nightly.oldUpdateTitlebar into a getter/setter: it would work as now, but the getter would log a warning if it doesn't have a value yet.

+
+get defaultTitle() {
+ var tabbrowser = gBrowser;
+ return nightlyApp.getWindowTitleForNavigator(tabbrowser.mCurrentBrowser);
+},
+
+get tabTitle() {
+ var tabbrowser = gBrowser;
+ return tabbrowser.mCurrentBrowser.contentTitle;
+},
+
init: function()
{
var brandbundle = document.getElementById("bundle_brand");
@@ -14,7 +26,14 @@ init: function()
nightly.variables.name=brandbundle.getString("brandShortName");
}
nightly.variables.brandname=brandbundle.getString("brandFullName");
- nightly.variables.defaulttitle=nightlyApp.storedTitle;
+
+ var tabbrowser = document.getElementById("content");
+ if (tabbrowser && typeof(tabbrowser.updateTitlebar) === "function") {
+ nightlyApp.oldUpdateTitlebar = tabbrowser.updateTitlebar;
+
+ tabbrowser.updateTitlebar = nightly.updateTitlebar;
+ tabbrowser.addEventListener("DOMTitleChanged", nightly.updateTitlebar, false);
+ }
},
openURL: function(url, event)
@@ -24,14 +43,59 @@ openURL: function(url, event)
setCustomTitle: function(title)
{
+ document.getElementById("content").ownerDocument.title = title;
},
-setBlankTitle: function()
+setStandardTitle: function()
{
+ if (nightlyApp.oldUpdateTitlebar) {
+ var tabbrowser = document.getElementById("content");
+ nightlyApp.oldUpdateTitlebar.call(tabbrowser);
+ }
+},
+
+/**
+ * Calculates the title like tabbrowser's updateTitlebar(), but doesn't set.
+ * See related Bug 457548 and suite/browser/tabbrowser.xml for details.
+ */
+getWindowTitleForNavigator: function (aBrowser) {
+ var newTitle = "";
+ var docTitle;
+ var docElement = document.documentElement;
+ var sep = docElement.getAttribute("titlemenuseparator");
+ var modifier = docElement.getAttribute("titlemodifier");
+
+ if (aBrowser.docShell.contentViewer)
+ docTitle = aBrowser.contentTitle;
+
+ if (!docTitle && !modifier) {
+ docTitle = aBrowser.getTitleForURI(aBrowser.mCurrentBrowser.currentURI);
+ if (!docTitle) {
+ docTitle = aBrowser.mStringBundle.getString("tabs.untitled");
+ }
+ }
+
+ if (docTitle) {
+ newTitle += docElement.getAttribute("titlepreface") + docTitle;
+ if (modifier)
+ newTitle += sep;
+ }
+ newTitle += modifier;
+
+ try {
+ if (docElement.getAttribute("chromehidden").indexOf("location") != -1) {
+ var uri = aBrowser.mURIFixup.createExposableURI(
+ aBrowser.mCurrentBrowser.currentURI);
+ if (uri.schemeIs("about"))
+ newTitle = uri.spec + sep + newTitle;
+ else if (uri.host)
+ newTitle = uri.prePath + sep + newTitle;
+ }
+ } catch (e) {
+ }
+
+ return newTitle;
},
-setStandardTitle: function()
-{
-}
}

0 comments on commit 286bb22

Please sign in to comment.