Bug 805260: turn can't-attach-mozSocialAPI error into a warning, since it's not usually a problem, r=markh
authorGavin Sharp <gavin@gavinsharp.com>
Wed, 24 Oct 2012 17:29:09 -0700
changeset 111308 d408a2592685803980fd331ee6a0690fcf7ab951
parent 111307 834551729be15b81a971a34cce844eaabaeae807
child 111309 c90c5809e56ea77a060daee2ed9f665d482f3766
push id23740
push userryanvm@gmail.com
push dateThu, 25 Oct 2012 12:13:42 +0000
treeherdermozilla-central@5374fb480634 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersmarkh
bugs805260
milestone19.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 805260: turn can't-attach-mozSocialAPI error into a warning, since it's not usually a problem, r=markh
toolkit/components/social/MozSocialAPI.jsm
--- a/toolkit/components/social/MozSocialAPI.jsm
+++ b/toolkit/components/social/MozSocialAPI.jsm
@@ -54,35 +54,36 @@ function injectController(doc, topic, da
                                   .chromeEventHandler;
 
     let origin = containingBrowser.getAttribute("origin");
     if (!origin) {
       return;
     }
 
     SocialService.getProvider(origin, function(provider) {
-      if (provider && provider.workerURL) {
+      if (provider && provider.workerURL && provider.enabled) {
         attachToWindow(provider, window);
       }
     });
   } catch(e) {
     Cu.reportError("MozSocialAPI injectController: unable to attachToWindow for " + doc.location + ": " + e);
   }
 }
 
 // Loads mozSocial support functions associated with provider into targetWindow
 function attachToWindow(provider, targetWindow) {
+  // If the loaded document isn't from the provider's origin, don't attach
+  // the mozSocial API.
   let origin = provider.origin;
-  if (!provider.enabled) {
-    throw new Error("MozSocialAPI: cannot attach disabled provider " + origin);
-  }
-
   let targetDocURI = targetWindow.document.documentURIObject;
   if (provider.origin != targetDocURI.prePath) {
-    throw new Error("MozSocialAPI: cannot attach " + origin + " to " + targetDocURI.spec);
+    let msg = "MozSocialAPI: not attaching mozSocial API for " + origin +
+              " to " + targetDocURI.spec + " since origins differ."
+    Services.console.logStringMessage(msg);
+    return;
   }
 
   var port = provider.getWorkerPort(targetWindow);
 
   let mozSocialObj = {
     // Use a method for backwards compat with existing providers, but we
     // should deprecate this in favor of a simple .port getter.
     getWorker: {
@@ -174,16 +175,17 @@ function attachToWindow(provider, target
   });
 
   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(); });
   });
+
   // 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();