Bug 573908 - Tab thumbnail must support remote tabs [r=vingtetun r=mbrubeck]
authorMark Finkle <mfinkle@mozilla.com>
Wed, 23 Jun 2010 15:23:06 -0400
changeset 1660 ac0d623c0b7dd7dd8a8ff6f63716d3f2f36c8688
parent 1659 cdfed9c4e662e4e11110e0148feb755ca67a432c
child 1661 9558884b0ee7095016b49a8284ed9151fbeacc47
push id1491
push usermfinkle@mozilla.com
push dateWed, 23 Jun 2010 19:23:17 +0000
reviewersvingtetun, mbrubeck
bugs573908
Bug 573908 - Tab thumbnail must support remote tabs [r=vingtetun r=mbrubeck]
chrome/content/BrowserView.js
chrome/content/TileManager.js.in
chrome/content/bindings/browser.xml
chrome/content/browser.js
chrome/content/tabs.xml
--- a/chrome/content/BrowserView.js
+++ b/chrome/content/BrowserView.js
@@ -230,17 +230,16 @@ BrowserView.prototype = {
   // Public instance methods
   //
 
   init: function init(container, visibleRectFactory) {
     this._batchOps = [];
     this._container = container;
     this._browser = null;
     this._browserViewportState = null;
-    this._contentWindow = null;
     this._renderMode = 0;
     this._offscreenDepth = 0;
 
     let cacheSize = kBrowserViewCacheSize;
     try {
       cacheSize = gPrefService.getIntPref("tile.cache.size");
     } catch(e) {}
 
@@ -476,21 +475,16 @@ BrowserView.prototype = {
 
     if (oldBrowser) {
       oldBrowser.setAttribute("type", "content");
       oldBrowser.messageManager.sendAsyncMessage("Browser:Blur", {});
     }
 
     this._browser = browser;
     this._browserViewportState = browserViewportState;
-    try {
-      this._contentWindow = browser.contentWindow;
-    } catch(e) {
-      this._contentWindow = null;
-    }
 
     if (browser) {
       browser.setAttribute("type", "content-primary");
       browser.messageManager.sendAsyncMessage("Browser:Focus", {});
 
       this.beginBatchOperation();
 
       if (browserChanged)
--- a/chrome/content/TileManager.js.in
+++ b/chrome/content/TileManager.js.in
@@ -94,35 +94,16 @@ const kXHTMLNamespaceURI  = "http://www.
 // base-2 exponent for width, height of a single tile.
 const kTileExponentWidth  = 9;
 const kTileExponentHeight = 9;
 const kTileWidth  = Math.pow(2, kTileExponentWidth);   // 2^9 = 512
 const kTileHeight = Math.pow(2, kTileExponentHeight);  // 2^9 = 512
 const kTileCrawlTimeCap = 100;    // millis
 const kTileCrawlComeAgain = 0;    // millis
 
-// Helper used to hide IPC / non-IPC differences for renering to a canvas
-function rendererFactory(isRemote, aCanvas, aBrowser) {
-  if (isRemote) {
-    let wrapper = {};
-    wrapper.ctx = aCanvas.MozGetIPCContext("2d");
-    wrapper.drawContent = function(aLeft, aTop, aWidth, aHeight, aColor, aFlags) {
-      this.ctx.asyncDrawXULElement(aBrowser, aLeft, aTop, aWidth, aHeight, aColor, aFlags);
-    };
-    return wrapper;
-  }
-
-  let wrapper = {};
-  wrapper.ctx = aCanvas.getContext("2d");
-  wrapper.drawContent = function(aLeft, aTop, aWidth, aHeight, aColor, aFlags) {
-    this.ctx.drawWindow(aBrowser.contentWindow, aLeft, aTop, aWidth, aHeight, aColor, aFlags);
-  };
-  return wrapper;
-}
-
 
 /**
  * The Tile Manager!
  *
  * @param appendTile The function the tile manager should call in order to
  * "display" a tile (e.g. append it to the DOM).  The argument to this
  * function is a TileManager.Tile object.
  * @param removeTile The function the tile manager should call in order to
@@ -396,17 +377,17 @@ TileManager.prototype = {
 
   /**
    * Render a rect to the canvas under the given scale.
    */
   renderRectToCanvas: function renderRectToCanvas(srcRect, destCanvas, scalex, scaley, drawMissing) {
     let bv = this._browserView;
     let tc = this._tileCache;
 
-    let renderer = rendererFactory(!bv._contentWindow, destCanvas, bv._browser);
+    let renderer = rendererFactory(bv._browser, destCanvas);
     let ctx = renderer.ctx;
 
     bv.viewportToBrowserRect(srcRect);
 
     ctx.save();
     bv.browserToViewportCanvasContext(ctx);
     ctx.scale(scalex, scaley);
 
@@ -772,17 +753,17 @@ TileManager.Tile.prototype = {
       this.markDirty();
 
     let rect = this._dirtyTileCanvasRect;
     let x = rect.left - this.boundRect.left;
     let y = rect.top - this.boundRect.top;
 
     browserView.viewportToBrowserRect(rect);
 
-    let renderer = rendererFactory(!browserView._contentWindow, this._canvas, browserView._browser);
+    let renderer = rendererFactory(browserView._browser, this._canvas);
     let ctx = renderer.ctx;
 
     ctx.save();
     ctx.translate(x, y);
     browserView.browserToViewportCanvasContext(ctx);
 
     // We expand the rect to working around a gfx issue (bug 534054)
     renderer.drawContent(rect.left , rect.top, rect.right - rect.left + 1, rect.bottom - rect.top + 1,
--- a/chrome/content/bindings/browser.xml
+++ b/chrome/content/bindings/browser.xml
@@ -581,17 +581,17 @@
                 item.listener[aName].apply(item.listener, aArguments);
             });
           }
         })
       ]]></field>
 
       <property name="contentWindow"
                 readonly="true"
-                onget="throw 'Not Remoteable'"/>
+                onget="return null"/>
 
       <property name="sessionHistory"
                 onget="throw 'sessionHistory: Not Remoteable'"
                 readonly="true"/>
 
       <property name="markupDocumentViewer"
                 onget="throw 'markupDocumentViewer: Not Remoteable'"
                 readonly="true"/>
--- a/chrome/content/browser.js
+++ b/chrome/content/browser.js
@@ -2685,20 +2685,20 @@ Tab.prototype = {
     let bvs = this._browserViewportState;
     bvs.defaultZoomLevel = bvs.zoomLevel;
   },
 
   updateThumbnail: function updateThumbnail() {
     if (!this._browser)
       return;
 
-    let bv = Browser._browserView;
-    let browserView = (Browser.selectedBrowser == this._browser && bv.isDefaultZoom()) ? Browser._browserView 
-                                                                                       : null;
-    this._chromeTab.updateThumbnail(this._browser, browserView);
+    // XXX: We don't know the size of the browser at this time and we can't fallback
+    // to contentWindow.innerWidth and .innerHeight. The viewport meta data is not
+    // even set yet. So fallback to something sane for now.
+    this._chromeTab.updateThumbnail(this._browser, 800, 500);
   },
 
   toString: function() {
     return "[Tab " + (this._browser ? this._browser.currentURI.spec : "(no browser)") + "]";
   }
 };
 
 var ImagePreloader = {
@@ -2724,8 +2724,28 @@ var ImagePreloader = {
 
     let size = screen.width > 400 ? "-64" : "-36";
     for (let i = 0; i < images.length; i++) {
       let image = new Image();
       image.src = "chrome://browser/skin/images/" + images[i] + size + ".png";
     }
   }
 }
+
+
+// Helper used to hide IPC / non-IPC differences for renering to a canvas
+function rendererFactory(aBrowser, aCanvas) {
+  if (aBrowser.contentWindow) {
+    let wrapper = {};
+    wrapper.ctx = aCanvas.getContext("2d");
+    wrapper.drawContent = function(aLeft, aTop, aWidth, aHeight, aColor, aFlags) {
+      this.ctx.drawWindow(aBrowser.contentWindow, aLeft, aTop, aWidth, aHeight, aColor, aFlags);
+    };
+    return wrapper;
+  }
+
+  let wrapper = {};
+  wrapper.ctx = aCanvas.MozGetIPCContext("2d");
+  wrapper.drawContent = function(aLeft, aTop, aWidth, aHeight, aColor, aFlags) {
+    this.ctx.asyncDrawXULElement(aBrowser, aLeft, aTop, aWidth, aHeight, aColor, aFlags);
+  };
+  return wrapper;
+}
--- a/chrome/content/tabs.xml
+++ b/chrome/content/tabs.xml
@@ -35,37 +35,31 @@
             let closeFn = new Function("event", this.parentNode.getAttribute('onclosetab'));
             closeFn.call(this);
           ]]>
         </body>
       </method>
 
       <method name="updateThumbnail">
         <parameter name="browser"/>
-        <parameter name="browserView"/>
+        <parameter name="width"/>
+        <parameter name="height"/>
         <body>
           <![CDATA[
             const tabWidth = 106;
             const tabHeight = 64;
 
-            let destCanvas = document.getAnonymousElementByAttribute(this, "anonid", "canvas");
-
-            if (browserView) {
-              browserView.renderToCanvas(destCanvas, tabWidth, tabHeight);
-            } else {
-              let domWin = browser.contentWindow;
-              let ctx = destCanvas.getContext("2d");
-              let width = domWin.innerWidth;
-              let height = domWin.innerHeight;
-              ctx.clearRect(0, 0, tabWidth, tabHeight);
-              ctx.save();
-              ctx.scale(tabWidth / width, tabHeight / height);
-              ctx.drawWindow(domWin, 0, 0, width, height, "white");
-              ctx.restore();
-            }
+            let canvas = document.getAnonymousElementByAttribute(this, "anonid", "canvas");
+            let renderer = rendererFactory(browser, canvas)
+            let ctx = renderer.ctx;
+            ctx.clearRect(0, 0, tabWidth, tabHeight);
+            ctx.save();
+            ctx.scale(tabWidth / width, tabHeight / height);
+            renderer.drawContent(0, 0, width, height, "white");
+            ctx.restore();
           ]]>
         </body>
       </method>
     </implementation>
   </binding>
 
   <binding id="tablist">
     <implementation>