Bug 1164940 - Lazily create iframe. r=jaws, a=sledru
authorGijs Kruitbosch <gijskruitbosch@gmail.com>
Thu, 14 May 2015 21:33:31 +0100
changeset 260519 24524667128b
parent 260518 e13a7a312aa5
child 260520 6ec85b777880
push id805
push userryanvm@gmail.com
push date2015-05-18 17:06 +0000
treeherdermozilla-release@4bfd19d00ed4 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersjaws, sledru
bugs1164940
milestone38.0.5
Bug 1164940 - Lazily create iframe. r=jaws, a=sledru
browser/components/customizableui/content/panelUI.inc.xul
browser/components/pocket/Pocket.jsm
browser/components/pocket/main.js
--- a/browser/components/customizableui/content/panelUI.inc.xul
+++ b/browser/components/customizableui/content/panelUI.inc.xul
@@ -230,17 +230,16 @@
         </vbox>
         <button id="PanelUI-panic-view-button"
                 label="&panicButton.view.forgetButton;"/>
       </vbox>
     </panelview>
 
     <panelview id="PanelUI-pocketView" flex="1">
       <vbox class="panel-subview-body">
-        <iframe id="pocket-panel-iframe" type="content"/>
       </vbox>
     </panelview>
 
 
   </panelmultiview>
   <!-- These menupopups are located here to prevent flickering,
        see bug 492960 comment 20. -->
   <menupopup id="customizationPanelItemContextMenu">
--- a/browser/components/pocket/Pocket.jsm
+++ b/browser/components/pocket/Pocket.jsm
@@ -20,17 +20,17 @@ let Pocket = {
   get listURL() { return "https://" + Pocket.site + "/?src=ff_ext"; },
 
   /**
    * Functions related to the Pocket panel UI.
    */
   onPanelViewShowing(event) {
     let document = event.target.ownerDocument;
     let window = document.defaultView;
-    let iframe = document.getElementById('pocket-panel-iframe');
+    let iframe = window.pktUI.getPanelFrame();
 
     let urlToSave = Pocket._urlToSave;
     let titleToSave = Pocket._titleToSave;
     Pocket._urlToSave = null;
     Pocket._titleToSave = null;
     // ViewShowing fires immediately before it creates the contents,
     // in lieu of an AfterViewShowing event, just spin the event loop.
     window.setTimeout(function() {
@@ -50,17 +50,17 @@ let Pocket = {
         iframe.addEventListener("load", Pocket.onFrameLoaded, true);
       }
     }, 0);
   },
 
   onFrameLoaded(event) {
     let document = event.currentTarget.ownerDocument;
     let window = document.defaultView;
-    let iframe = document.getElementById('pocket-panel-iframe');
+    let iframe = window.pktUI.getPanelFrame();
 
     iframe.removeEventListener("load", Pocket.onFrameLoaded, true);
     window.pktUI.pocketPanelDidShow();
   },
 
   onPanelViewHiding(event) {
     let window = event.target.ownerDocument.defaultView;
     window.pktUI.pocketPanelDidHide(event);
--- a/browser/components/pocket/main.js
+++ b/browser/components/pocket/main.js
@@ -639,17 +639,25 @@ var pktUI = (function() {
         var panel = frame;
         while (panel && panel.localName != "panel") {
             panel = panel.parentNode;
         }
     	return panel;
     }
 
     function getPanelFrame() {
-    	return document.getElementById('pocket-panel-iframe');
+        var frame = document.getElementById('pocket-panel-iframe');
+        if (!frame) {
+            var frameParent = document.getElementById("PanelUI-pocketView").firstChild;
+            frame = document.createElement("iframe");
+            frame.id = 'pocket-panel-iframe';
+            frame.setAttribute("type", "content");
+            frameParent.appendChild(frame);
+        }
+        return frame;
     }
 
     function getSubview() {
         var frame = getPanelFrame();
         var view = frame;
         while (view && view.localName != "panelview") {
             view = view.parentNode;
         }
@@ -774,16 +782,17 @@ var pktUI = (function() {
     }
     
     
 	/**
      * Public functions
      */
     return {
     	onLoad: onLoad,
+    	getPanelFrame: getPanelFrame,
 
     	pocketButtonOnCommand: pocketButtonOnCommand,
     	pocketPanelDidShow: pocketPanelDidShow,
     	pocketPanelDidHide: pocketPanelDidHide,
 
         pocketContextSaveLinkOnCommand,
         pocketContextSavePageOnCommand,
 
@@ -836,17 +845,17 @@ var pktUIMessaging = (function() {
 
     /**
      * Send a message to the panel's iframe
      */
     function sendMessageToPanel(panelId, messageId, payload) {
 
         if (!isPanelIdValid(panelId)) { return; };
 
-        var panelFrame = document.getElementById('pocket-panel-iframe');
+        var panelFrame = pktUI.getPanelFrame();
         if (!isPocketPanelFrameValid(panelFrame)) { return; }
 
         var doc = panelFrame.contentWindow.document;
         var documentElement = doc.documentElement;
 
         // Send message to panel
         var panelMessageId = prefixedMessageId(panelId + '_' + messageId);