Bug 1164940 - lazily create iframe, r=jaws
authorGijs Kruitbosch <gijskruitbosch@gmail.com>
Thu, 14 May 2015 21:33:31 +0100
changeset 243963 80b9c8af0d35179141e07ca990625a4503169ed2
parent 243962 d20045f6280bba9e8f3d10b26a77ec2b586b07cb
child 243964 98d3f93bb94a1cf196c58e9db38a08b3adfdcea9
push id28761
push usercbook@mozilla.com
push dateFri, 15 May 2015 14:50:10 +0000
treeherdermozilla-central@c0e709a5baca [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersjaws
bugs1164940
milestone41.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 1164940 - lazily create iframe, r=jaws
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);