Bug 799600 - allow data urls in social panels. r=jaws
☠☠ backed out by ba9fb2ed910c ☠ ☠
authorMark Hammond <mhammond@skippinet.com.au>
Thu, 25 Oct 2012 16:45:34 +1100
changeset 111713 9c064c78d86aeb5b37cbd595484475bc150ee9ff
parent 111712 a32865b52f011804c5bfdd07fe5d08063f2ae1e9
child 111714 a0c4f4bd8a9d7702b139eebd0f7b419baff6117e
push id93
push usernmatsakis@mozilla.com
push dateWed, 31 Oct 2012 21:26:57 +0000
reviewersjaws
bugs799600
milestone19.0a1
Bug 799600 - allow data urls in social panels. r=jaws
browser/base/content/test/browser_social_toolbar.js
toolkit/components/social/MozSocialAPI.jsm
--- a/browser/base/content/test/browser_social_toolbar.js
+++ b/browser/base/content/test/browser_social_toolbar.js
@@ -91,16 +91,58 @@ var tests = {
         let menuitem = socialToggleMore.querySelector("menuitem");
         is(menuitem.getAttribute("label"), "Test Ambient 1", "Keyboard accessible ambient menuitem should have specified label");
         toolsPopup.hidePopup();
         next();
       }, false);
       document.getElementById("menu_ToolsPopup").openPopup();
     }, "statusIcon was never found");
   },
+  testAmbientNotificationContent: function(next) {
+    let ambience = {
+      name: "testIcon",
+      iconURL: "https://example.com/browser/browser/base/content/test/moz.png",
+      contentPanel: "data:text/html;charset=utf-8," +
+                    encodeURI('<html><body><div id="testdiv"/></body></html>'),
+      counter: 42,
+      label: "Test Ambient 1",
+      menuURL: "https://example.com/testAmbient1"
+    };
+    Social.provider.setAmbientNotification(ambience);
+
+    let statusIcon = document.querySelector("#social-toolbar-item > box");
+    waitForCondition(function() {
+      statusIcon = document.querySelector("#social-toolbar-item > box");
+      return !!statusIcon;
+    }, function () {
+      let panel = document.getElementById("social-notification-panel");
+      panel.addEventListener("popupshown", function ontoolspopupshownAmbient() {
+        panel.removeEventListener("popupshown", ontoolspopupshownAmbient);
+        let iframe = panel.firstChild;
+        let afterLoad = function() {
+          ok(iframe.contentDocument.getElementById("testdiv"), "could find our div in the content");
+          ok(iframe.contentWindow.wrappedJSObject.navigator.mozSocial, "data: panel has mozSocial object");
+          panel.addEventListener("popuphidden", function popuphidden() {
+            panel.removeEventListener("popuphidden", popuphidden);
+            next();
+          });
+          panel.hidePopup();
+        }
+        if (iframe.contentDocument.readyState == "loading") {
+          iframe.contentWindow.addEventListener("load", function frame_load() {
+            iframe.contentWindow.removeEventListener("load", frame_load, true);
+            executeSoon(afterLoad);
+          }, true);
+        } else {
+          afterLoad();
+        }
+      });
+      panel.openPopup();
+    }, "statusIcon was never found");
+  },
   testProfileUnset: function(next) {
     Social.provider.updateUserProfile({});
     // check dom values
     let userButton = document.getElementById("social-statusarea-username");
     ok(userButton.hidden, "username is not visible");
     let ambientIcons = document.querySelectorAll("#social-toolbar-item > box");
     for (let ambientIcon of ambientIcons) {
       ok(ambientIcon.collapsed, "ambient icon (" + ambientIcon.id + ") is collapsed");
--- a/toolkit/components/social/MozSocialAPI.jsm
+++ b/toolkit/components/social/MozSocialAPI.jsm
@@ -69,17 +69,20 @@ function injectController(doc, topic, da
 }
 
 // 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;
   let targetDocURI = targetWindow.document.documentURIObject;
-  if (provider.origin != targetDocURI.prePath) {
+  // We allow data: URLs as it might be far more efficient for a provider to
+  // synthesize a data URL from content already loaded in its sidebar or
+  // worker.
+  if (provider.origin != targetDocURI.prePath && targetDocURI.scheme != "data") {
     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);