Bug 662008 - Handle document title changes across processes (r=felipe)

This commit is contained in:
Bill McCloskey 2013-04-24 22:29:39 -07:00
Родитель e2b59dbc67
Коммит 8398923bb7
3 изменённых файлов: 71 добавлений и 2 удалений

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

@ -39,7 +39,7 @@
</xul:tabbox>
<children/>
</content>
<implementation implements="nsIDOMEventListener">
<implementation implements="nsIDOMEventListener, nsIMessageListener">
<property name="tabContextMenu" readonly="true"
onget="return this.tabContainer.contextMenu;"/>
@ -293,6 +293,19 @@
</body>
</method>
<method name="_getTabForBrowser">
<parameter name="aBrowser"/>
<body>
<![CDATA[
for (let i = 0; i < this.tabs.length; i++) {
if (this.tabs[i].linkedBrowser == aBrowser)
return this.tabs[i];
}
return null;
]]>
</body>
</method>
<method name="getNotificationBox">
<parameter name="aBrowser"/>
<body>
@ -2685,6 +2698,24 @@
]]></body>
</method>
<method name="receiveMessage">
<parameter name="aMessage"/>
<body><![CDATA[
let json = aMessage.json;
let browser = aMessage.target;
switch (aMessage.name) {
case "DOMTitleChanged":
let tab = this._getTabForBrowser(browser);
if (!tab)
return;
let titleChanged = this.setTabTitle(tab);
if (titleChanged && !tab.selected && !tab.hasAttribute("busy"))
tab.setAttribute("titlechanged", "true");
}
]]></body>
</method>
<constructor>
<![CDATA[
this.mCurrentBrowser = document.getAnonymousElementByAttribute(this, "anonid", "initialBrowser");
@ -2721,6 +2752,9 @@
Services.prefs.getBoolPref("browser.display.use_system_colors") ?
"-moz-default-background-color" :
Services.prefs.getCharPref("browser.display.background_color");
if (Services.prefs.getBoolPref("browser.tabs.remote"))
messageManager.addMessageListener("DOMTitleChanged", this);
]]>
</constructor>
@ -2754,6 +2788,9 @@
}
document.removeEventListener("keypress", this, false);
window.removeEventListener("sizemodechange", this, false);
if (Services.prefs.getBoolPref("browser.tabs.remote"))
messageManager.removeMessageListener("DOMTitleChanged", this);
]]>
</destructor>

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

@ -148,3 +148,15 @@ let WebNavigation = {
};
WebNavigation.init();
addEventListener("DOMTitleChanged", function (aEvent) {
let document = content.document;
switch (aEvent.type) {
case "DOMTitleChanged":
if (!aEvent.isTrusted || aEvent.target.defaultView != content)
return;
sendAsyncMessage("DOMTitleChanged", { title: document.title });
break;
}
}, false);

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

@ -10,7 +10,7 @@
<binding id="remote-browser" extends="chrome://global/content/bindings/browser.xml#browser">
<implementation type="application/javascript" implements="nsIAccessibleProvider, nsIObserver, nsIDOMEventListener, nsIMessageListener">
<implementation type="application/javascript" implements="nsIAccessibleProvider, nsIObserver, nsIDOMEventListener, nsIMessageListener, nsIMessageListener">
<property name="securityUI"
onget="return null;"/>
@ -34,8 +34,15 @@
</getter>
</property>
<field name="_contentTitle">null</field>
<property name="contentTitle"
onget="return this._contentTitle"
readonly="true"/>
<constructor>
<![CDATA[
this.messageManager.addMessageListener("DOMTitleChanged", this);
this.messageManager.loadFrameScript("chrome://global/content/browser-child.js", true);
this.webProgress._init();
]]>
@ -43,10 +50,23 @@
<destructor>
<![CDATA[
this.messageManager.removeMessageListener("DOMTitleChanged", this);
this.webProgress._destroy();
]]>
</destructor>
<method name="receiveMessage">
<parameter name="aMessage"/>
<body><![CDATA[
let json = aMessage.json;
switch (aMessage.name) {
case "DOMTitleChanged":
this._contentTitle = json.title;
break;
}
]]></body>
</method>
</implementation>
</binding>