Bug 1042991 - Fix history use in share panel. r=bmcbride, a=sledru
authorShane Caraveo <scaraveo@mozilla.com>
Wed, 30 Jul 2014 18:32:07 -0700
changeset 208210 fd04691e6c71
parent 208209 011c4355f782
child 208211 adc6758d943d
push id3770
push userryanvm@gmail.com
push date2014-07-31 17:17 +0000
treeherdermozilla-beta@fd04691e6c71 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersbmcbride, sledru
bugs1042991
milestone32.0
Bug 1042991 - Fix history use in share panel. r=bmcbride, a=sledru
browser/base/content/browser-social.js
browser/base/content/test/social/head.js
browser/base/content/test/social/share.html
--- a/browser/base/content/browser-social.js
+++ b/browser/base/content/browser-social.js
@@ -460,21 +460,22 @@ SocialShare = {
   },
 
   _createFrame: function() {
     let panel = this.panel;
     if (!SocialUI.enabled || this.iframe)
       return;
     this.panel.hidden = false;
     // create and initialize the panel for this window
-    let iframe = document.createElement("iframe");
+    let iframe = document.createElement("browser");
     iframe.setAttribute("type", "content");
     iframe.setAttribute("class", "social-share-frame");
     iframe.setAttribute("context", "contentAreaContextMenu");
     iframe.setAttribute("tooltip", "aHTMLTooltip");
+    iframe.setAttribute("disableglobalhistory", "true");
     iframe.setAttribute("flex", "1");
     panel.appendChild(iframe);
     this.populateProviderMenu();
   },
 
   getSelectedProvider: function() {
     let provider;
     let lastProviderOrigin = this.iframe && this.iframe.getAttribute("origin");
@@ -587,17 +588,25 @@ SocialShare = {
     this.anchor.setAttribute("open", "true");
     this.iframe.addEventListener("click", this._onclick, true);
   },
 
   onHidden: function() {
     this.anchor.removeAttribute("open");
     this.iframe.removeEventListener("click", this._onclick, true);
     this.iframe.setAttribute("src", "data:text/plain;charset=utf8,");
+    // make sure that the frame is unloaded after it is hidden
+    this.iframe.docShell.createAboutBlankContentViewer(null);
     this.currentShare = null;
+    // share panel use is over, purge any history
+    if (this.iframe.sessionHistory) {
+      let purge = this.iframe.sessionHistory.count;
+      if (purge > 0)
+        this.iframe.sessionHistory.PurgeHistory(purge);
+    }
   },
 
   setErrorMessage: function() {
     let iframe = this.iframe;
     if (!iframe)
       return;
 
     iframe.removeAttribute("src");
@@ -694,16 +703,24 @@ SocialShare = {
             SocialShare._dynamicResizer.start(iframe.parentNode, iframe);
           }
         }, 0);
         let evt = iframe.contentDocument.createEvent("CustomEvent");
         evt.initCustomEvent("OpenGraphData", true, true, JSON.stringify(pageData));
         iframe.contentDocument.documentElement.dispatchEvent(evt);
       }, true);
     }
+    // if the user switched between share providers we do not want that history
+    // available.
+    if (iframe.sessionHistory) {
+      let purge = iframe.sessionHistory.count;
+      if (purge > 0)
+        iframe.sessionHistory.PurgeHistory(purge);
+    }
+
     // always ensure that origin belongs to the endpoint
     let uri = Services.io.newURI(shareEndpoint, null, null);
     iframe.setAttribute("origin", provider.origin);
     iframe.setAttribute("src", shareEndpoint);
 
     let anchor = document.getAnonymousElementByAttribute(this.anchor, "class", "toolbarbutton-icon");
     this.panel.openPopup(anchor, "bottomcenter topright", 0, 0, false, false);
     Social.setErrorListener(iframe, this.setErrorMessage.bind(this));
--- a/browser/base/content/test/social/head.js
+++ b/browser/base/content/test/social/head.js
@@ -73,17 +73,17 @@ function runSocialTestWithProvider(manif
   let manifests = Array.isArray(manifest) ? manifest : [manifest];
 
   // Check that none of the provider's content ends up in history.
   function finishCleanUp() {
     ok(!SocialSidebar.provider, "no provider in sidebar");
     SessionStore.setWindowValue(window, "socialSidebar", "");
     for (let i = 0; i < manifests.length; i++) {
       let m = manifests[i];
-      for (let what of ['sidebarURL', 'workerURL', 'iconURL']) {
+      for (let what of ['sidebarURL', 'workerURL', 'iconURL', 'shareURL', 'markURL']) {
         if (m[what]) {
           yield promiseSocialUrlNotRemembered(m[what]);
         }
       };
     }
     for (let i = 0; i < gURLsNotRemembered.length; i++) {
       yield promiseSocialUrlNotRemembered(gURLsNotRemembered[i]);
     }
--- a/browser/base/content/test/social/share.html
+++ b/browser/base/content/test/social/share.html
@@ -3,16 +3,17 @@
     <meta charset="utf-8">
     <script>
       var shareData;
       addEventListener("OpenGraphData", function(e) {
         shareData = JSON.parse(e.detail);
         var port = navigator.mozSocial.getWorker().port;
         port.postMessage({topic: "share-data-message", result: shareData});
         // share windows self-close
+        history.back(); // bug 1042991, ensure history is available
         window.close();
       })
     </script>
   </head>
   <body>
     <p>This is a test social share window.</p>
   </body>
 </html>