Bug 806038. Sidebar docShell is not defined after sidebar has been unloaded. r=gavin

This commit is contained in:
Felipe Gomes 2012-10-29 20:52:56 -07:00
parent a31fb1c20e
commit ecffccef43

View File

@ -902,9 +902,21 @@ var SocialToolbar = {
var SocialSidebar = {
// Called once, after window load, when the Social.provider object is initialized
init: function SocialSidebar_init() {
let sbrowser = document.getElementById("social-sidebar-browser");
this.errorListener = new SocialErrorListener("sidebar");
this.configureSidebarDocShell(sbrowser.docShell);
this.updateSidebar();
},
configureSidebarDocShell: function SocialSidebar_configureDocShell(aDocShell) {
// setting isAppTab causes clicks on untargeted links to open new tabs
aDocShell.isAppTab = true;
aDocShell.QueryInterface(Ci.nsIWebProgress)
.addProgressListener(SocialSidebar.errorListener,
Ci.nsIWebProgress.NOTIFY_STATE_REQUEST |
Ci.nsIWebProgress.NOTIFY_LOCATION);
},
// Whether the sidebar can be shown for this window.
get canShow() {
return Social.uiVisible && Social.provider.sidebarURL && !this.chromeless;
@ -923,10 +935,11 @@ var SocialSidebar = {
return Services.prefs.getBoolPref("social.sidebar.open") && !document.mozFullScreen;
},
dispatchEvent: function(aType, aDetail) {
setSidebarVisibilityState: function(aEnabled) {
let sbrowser = document.getElementById("social-sidebar-browser");
sbrowser.docShell.isActive = aEnabled;
let evt = sbrowser.contentDocument.createEvent("CustomEvent");
evt.initCustomEvent(aType, true, true, aDetail ? aDetail : {});
evt.initCustomEvent(aEnabled ? "socialFrameShow" : "socialFrameHide", true, true, {});
sbrowser.contentDocument.documentElement.dispatchEvent(evt);
},
@ -944,9 +957,8 @@ var SocialSidebar = {
command.setAttribute("checked", !hideSidebar);
let sbrowser = document.getElementById("social-sidebar-browser");
sbrowser.docShell.isActive = !hideSidebar;
if (hideSidebar) {
this.dispatchEvent("socialFrameHide");
this.setSidebarVisibilityState(false);
// If we've been disabled, unload the sidebar content immediately;
// if the sidebar was just toggled to invisible, wait a timeout
// before unloading.
@ -962,21 +974,16 @@ var SocialSidebar = {
// Make sure the right sidebar URL is loaded
if (sbrowser.getAttribute("origin") != Social.provider.origin) {
sbrowser.setAttribute("origin", Social.provider.origin);
// setting isAppTab causes clicks on untargeted links to open new tabs
sbrowser.docShell.isAppTab = true;
sbrowser.webProgress.addProgressListener(new SocialErrorListener("sidebar"),
Ci.nsIWebProgress.NOTIFY_STATE_REQUEST |
Ci.nsIWebProgress.NOTIFY_LOCATION);
sbrowser.setAttribute("src", Social.provider.sidebarURL);
sbrowser.addEventListener("load", function sidebarOnShow() {
sbrowser.removeEventListener("load", sidebarOnShow);
sbrowser.removeEventListener("load", sidebarOnShow, true);
// let load finish, then fire our event
setTimeout(function () {
SocialSidebar.dispatchEvent("socialFrameShow");
SocialSidebar.setSidebarVisibilityState(true);
}, 0);
});
}, true);
} else {
this.dispatchEvent("socialFrameShow");
this.setSidebarVisibilityState(true);
}
}
},
@ -993,6 +1000,18 @@ var SocialSidebar = {
container.removeChild(sbrowser);
sbrowser.removeAttribute("origin");
sbrowser.removeAttribute("src");
function resetDocShell(docshellSupports) {
let docshell = docshellSupports.QueryInterface(Ci.nsIDocShell);
if (docshell.chromeEventHandler != sbrowser)
return;
SocialSidebar.configureSidebarDocShell(docshell);
Services.obs.removeObserver(resetDocShell, "webnavigation-create");
}
Services.obs.addObserver(resetDocShell, "webnavigation-create", false);
container.appendChild(sbrowser);
SocialFlyout.unload();