Bug 764467 - Add a separate event for notifying browser.js of resize events, to avoid weird re-entrancy issues. r=Cwiiis a=lsblakk
authorKartikaya Gupta <kgupta@mozilla.com>
Thu, 14 Jun 2012 10:59:28 -0400
changeset 100441 b12557028a786f164ab994dca00708408976bad0
parent 100440 078ece5918e25f7ddfd6060820a6a71fd4d5fb71
child 100442 b40643c774f6a8b53e02496573bcb8186ee1cedb
push id1235
push userkgupta@mozilla.com
push dateTue, 07 Aug 2012 14:11:57 +0000
treeherdermozilla-beta@b12557028a78 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersCwiiis, lsblakk
bugs764467
milestone15.0
Bug 764467 - Add a separate event for notifying browser.js of resize events, to avoid weird re-entrancy issues. r=Cwiiis a=lsblakk
mobile/android/base/gfx/GeckoLayerClient.java
mobile/android/chrome/content/browser.js
--- a/mobile/android/base/gfx/GeckoLayerClient.java
+++ b/mobile/android/base/gfx/GeckoLayerClient.java
@@ -137,16 +137,17 @@ public class GeckoLayerClient implements
 
         if (windowSizeChanged) {
             Log.d(LOGTAG, "Window-size changed to " + mWindowSize);
         }
 
         GeckoEvent event = GeckoEvent.createSizeChangedEvent(mWindowSize.width, mWindowSize.height,
                                                              mScreenSize.width, mScreenSize.height);
         GeckoAppShell.sendEventToGecko(event);
+        GeckoAppShell.sendEventToGecko(GeckoEvent.createBroadcastEvent("Window:Resize", ""));
     }
 
     public Bitmap getBitmap() {
         return null;
     }
 
     void viewportSizeChanged() {
         // here we send gecko a resize message. The code in browser.js is responsible for
--- a/mobile/android/chrome/content/browser.js
+++ b/mobile/android/chrome/content/browser.js
@@ -4312,45 +4312,42 @@ const kViewportMaxHeight = 10000;
 var ViewportHandler = {
   // The cached viewport metadata for each document. We tie viewport metadata to each document
   // instead of to each tab so that we don't have to update it when the document changes. Using an
   // ES6 weak map lets us avoid leaks.
   _metadata: new WeakMap(),
 
   init: function init() {
     addEventListener("DOMMetaAdded", this, false);
-    addEventListener("resize", this, false);
+    Services.obs.addObserver(this, "Window:Resize", false);
   },
 
   uninit: function uninit() {
     removeEventListener("DOMMetaAdded", this, false);
-    removeEventListener("resize", this, false);
+    Services.obs.removeObserver(this, "Window:Resize", false);
   },
 
   handleEvent: function handleEvent(aEvent) {
     switch (aEvent.type) {
       case "DOMMetaAdded":
         let target = aEvent.originalTarget;
         if (target.name != "viewport")
           break;
         let document = target.ownerDocument;
         let browser = BrowserApp.getBrowserForDocument(document);
         let tab = BrowserApp.getTabForBrowser(browser);
         if (tab && tab.contentDocumentIsDisplayed)
           this.updateMetadata(tab);
         break;
-
-      case "resize":
-        // guard against zero values corrupting our viewport numbers. this happens sometimes
-        // during initialization.
-        if (window.outerWidth == 0 || window.outerHeight == 0)
-          break;
-
-        // check dimensions changed to avoid infinite loop because updateViewportSize
-        // triggers a resize on the content window and will trigger this listener again
+    }
+  },
+
+  observe: function(aSubject, aTopic, aData) {
+    switch (aTopic) {
+      case "Window:Resize":
         if (window.outerWidth == gScreenWidth && window.outerHeight == gScreenHeight)
           break;
         if (window.outerWidth == 0 || window.outerHeight == 0)
           break;
 
         let oldScreenWidth = gScreenWidth;
         gScreenWidth = window.outerWidth;
         gScreenHeight = window.outerHeight;