bug 904104 fix window.close usage from chat and social panels, r=felipc
authorShane Caraveo <scaraveo@mozilla.com>
Sat, 14 Sep 2013 10:06:09 -0700
changeset 160096 926d081e02d64683215361ce72368def495d803d
parent 160095 a04d4a5738638f353756acb2bcede42f03db9fc4
child 160097 1d12266ddc4ca4ee0da3444b1689d281cfc1f402
push id2961
push userlsblakk@mozilla.com
push dateMon, 28 Oct 2013 21:59:28 +0000
treeherdermozilla-beta@73ef4f13486f [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersfelipc
bugs904104
milestone26.0a1
first release with
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
last release without
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
bug 904104 fix window.close usage from chat and social panels, r=felipc
toolkit/components/social/MozSocialAPI.jsm
--- a/toolkit/components/social/MozSocialAPI.jsm
+++ b/toolkit/components/social/MozSocialAPI.jsm
@@ -61,16 +61,21 @@ function injectController(doc, topic, da
                   Services.prefs.getBoolPref("social.debug.injectIntoTabs");
     } catch(e) {}
 
     let origin = containingBrowser.getAttribute("origin");
     if (!allowTabs && !origin) {
       return;
     }
 
+    // we always handle window.close on social content, even if they are not
+    // "enabled".  "enabled" is about the worker state and a provider may
+    // still be in e.g. the share panel without having their worker enabled.
+    handleWindowClose(window);
+
     SocialService.getProvider(doc.nodePrincipal.origin, function(provider) {
       if (provider && provider.enabled) {
         attachToWindow(provider, window);
       }
     });
   } catch(e) {
     Cu.reportError("MozSocialAPI injectController: unable to attachToWindow for " + doc.location + ": " + e);
   }
@@ -209,17 +214,19 @@ function attachToWindow(provider, target
   if (port) {
     targetWindow.addEventListener("unload", function () {
       // We want to close the port, but also want the target window to be
       // able to use the port during an unload event they setup - so we
       // set a timer which will fire after the unload events have all fired.
       schedule(function () { port.close(); });
     });
   }
+}
 
+function handleWindowClose(targetWindow) {
   // We allow window.close() to close the panel, so add an event handler for
   // this, then cancel the event (so the window itself doesn't die) and
   // close the panel instead.
   // However, this is typically affected by the dom.allow_scripts_to_close_windows
   // preference, but we can avoid that check by setting a flag on the window.
   let dwu = targetWindow.QueryInterface(Ci.nsIInterfaceRequestor)
                         .getInterface(Ci.nsIDOMWindowUtils);
   dwu.allowScriptsToClose();