Bug 904104 - Fix window.close usage from chat and social panels. r=felipc, a=akeybl
authorShane Caraveo <scaraveo@mozilla.com>
Thu, 19 Sep 2013 10:41:32 -0700
changeset 160386 51cf3d1d796826459f1c80e819e2cc7927e8549b
parent 160385 8de790b4863acaca0f8012bea80c11049e40c544
child 160387 c01876298cb0d5565bd502c2655c66b973530e96
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, akeybl
bugs904104
milestone26.0a2
Bug 904104 - Fix window.close usage from chat and social panels. r=felipc, a=akeybl
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();