Bug 764467 - Add a separate event for notifying browser.js of resize events, to avoid weird re-entrancy issues. r=Cwiiis
authorKartikaya Gupta <kgupta@mozilla.com>
Thu, 14 Jun 2012 10:59:28 -0400
changeset 96704 c1df07bc54e56f55e48ad6c25b4b51b315c62bd7
parent 96703 428b1777daa122844a5af2579c4f3f045bd4b5b6
child 96705 9efa5af3c1d873795a7fd61c5152cb91b0aec00b
push id22934
push useremorley@mozilla.com
push dateFri, 15 Jun 2012 12:37:14 +0000
treeherdermozilla-central@892f95753777 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersCwiiis
bugs764467
milestone16.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 764467 - Add a separate event for notifying browser.js of resize events, to avoid weird re-entrancy issues. r=Cwiiis
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
@@ -129,16 +129,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
@@ -3667,45 +3667,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;
 
         let oldScreenWidth = gScreenWidth;
         gScreenWidth = window.outerWidth;
         gScreenHeight = window.outerHeight;
         let tabs = BrowserApp.tabs;
         for (let i = 0; i < tabs.length; i++)