Bug 574260 - Remove last uses of contentWindow and contentDocument [r=vingtetun]
authorMark Finkle <mfinkle@mozilla.com>
Thu, 24 Jun 2010 18:13:01 -0400
changeset 66314 62be8fb056329c6c61cedd69097acc37fdc40ef3
parent 66313 7aa7b52837038f5654b7d8051ed81eed327902ab
child 66315 47191a7fd0d59a30c6c18ad62aa87d0371e807c0
push id1
push userroot
push dateTue, 26 Apr 2011 22:38:44 +0000
treeherdermozilla-beta@bfdb6e623a36 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersvingtetun
bugs574260
Bug 574260 - Remove last uses of contentWindow and contentDocument [r=vingtetun]
mobile/chrome/content/BrowserView.js
mobile/chrome/content/bindings/browser.xml
mobile/chrome/content/browser-ui.js
mobile/chrome/content/browser.js
mobile/chrome/content/preferences.js
mobile/components/SessionStore.js
--- a/mobile/chrome/content/BrowserView.js
+++ b/mobile/chrome/content/BrowserView.js
@@ -156,76 +156,32 @@ BrowserView.Util = {
   createBrowserViewportState: function createBrowserViewportState() {
     return new BrowserView.BrowserViewportState(new Rect(0, 0, 1, 1), 0, 0, 1);
   },
 
   getViewportStateFromBrowser: function getViewportStateFromBrowser(browser) {
     return browser.__BrowserView__vps;
   },
 
-  /**
-   * Calling this is likely to cause a reflow of the browser's document.  Use
-   * wisely.
-   */
-  getBrowserDimensions: function getBrowserDimensions(browser) {
-    let cdoc = browser.contentDocument;
-    if (cdoc instanceof SVGDocument) {
-      let rect = cdoc.rootElement.getBoundingClientRect();
-      return [Math.ceil(rect.width), Math.ceil(rect.height)];
-    }
-
-    // These might not exist yet depending on page load state
-    let body = cdoc.body || {};
-    let html = cdoc.documentElement || {};
-    let w = Math.max(body.scrollWidth || 1, html.scrollWidth);
-    let h = Math.max(body.scrollHeight || 1, html.scrollHeight);
-
-    return [w, h];
-  },
-
-  getContentScrollOffset: function getContentScrollOffset(browser) {
-    let cwu = BrowserView.Util.getBrowserDOMWindowUtils(browser);
-    let scrollX = {};
-    let scrollY = {};
-    cwu.getScrollXY(false, scrollX, scrollY);
-
-    return new Point(scrollX.value, scrollY.value);
-  },
-
-  getBrowserDOMWindowUtils: function getBrowserDOMWindowUtils(browser) {
-    return browser.contentWindow
-      .QueryInterface(Ci.nsIInterfaceRequestor)
-      .getInterface(Ci.nsIDOMWindowUtils);
-  },
-
   getNewBatchOperationState: function getNewBatchOperationState() {
     return {
       viewportSizeChanged: false,
       dirtyAll: false
     };
   },
 
   initContainer: function initContainer(container, visibleRect) {
     container.style.width = visibleRect.width  + 'px';
     container.style.height = visibleRect.height + 'px';
     container.style.overflow = '-moz-hidden-unscrollable';
   },
 
   resizeContainerToViewport: function resizeContainerToViewport(container, viewportRect) {
     container.style.width = viewportRect.width  + 'px';
     container.style.height = viewportRect.height + 'px';
-  },
-
-  ensureMozScrolledAreaEvent: function ensureMozScrolledAreaEvent(aBrowser, aWidth, aHeight) {
-    let message = {};
-    message.target = aBrowser;
-    message.name = "Browser:MozScrolledAreaChanged";
-    message.json = { width: aWidth, height: aHeight };
-
-    Browser._browserView.updateScrolledArea(message);
   }
 };
 
 BrowserView.prototype = {
 
   // -----------------------------------------------------------
   // Public instance methods
   //
--- a/mobile/chrome/content/bindings/browser.xml
+++ b/mobile/chrome/content/bindings/browser.xml
@@ -394,55 +394,49 @@
         </getter>
       </property>
 
       <property name="docShell"
                 onget="throw 'docShell: Not Remotable'"
                 readonly="true"/>
 
       <field name="_contentTitle">null</field>
-      <field name="_contentDocument"><![CDATA[
-        ({
-          get title() { return this._browser._contentTitle; },
-          get location() { return null; },
-          set location(aURI) { this._browser.loadURI(aURI, null, null); },
-          get nodePrincipal() { throw "nodePrincipal: Not Remotable"; },
 
-          _browser: this,
-        })
-      ]]></field>
+      <property name="contentTitle"
+                onget="return this._contentTitle;"
+                readonly="true"/>
 
       <field name="_webNavigation"><![CDATA[
         ({
           canGoBack: false,
           canGoForward: false,
-          goBack: function() { this._sendSyncMessage("WebNavigation:GoBack", {}); },
-          goForward: function() { this._sendSyncMessage("WebNavigation:GoForward", {}); },
-          gotoIndex: function(aIndex) { this._sendSyncMessage("WebNavigation:GotoIndex", {index: aIndex}); },
+          goBack: function() { this._sendMessage("WebNavigation:GoBack", {}); },
+          goForward: function() { this._sendMessage("WebNavigation:GoForward", {}); },
+          gotoIndex: function(aIndex) { this._sendMessage("WebNavigation:GotoIndex", {index: aIndex}); },
           loadURI: function(aURI, aLoadFlags, aReferrer, aPostData, aHeaders) {
             this._currentURI = this._browser._ios.newURI(aURI, null, null);
             this._browser._contentTitle = "";
-            this._sendSyncMessage("WebNavigation:LoadURI", {uri: aURI, flags: aLoadFlags});
+            this._sendMessage("WebNavigation:LoadURI", {uri: aURI, flags: aLoadFlags});
           },
-          reload: function(aReloadFlags) { this._sendSyncMessage("WebNavigation:Reload", {flags: aReloadFlags}); },
-          stop: function(aStopFlags) { this._sendSyncMessage("WebNavigation:Stop", {flags: aStopFlags}); },
-          get document() { return this._browser._contentDocument; },
+          reload: function(aReloadFlags) { this._sendMessage("WebNavigation:Reload", {flags: aReloadFlags}); },
+          stop: function(aStopFlags) { this._sendMessage("WebNavigation:Stop", {flags: aStopFlags}); },
+          get document() { debugger; Components.utils.reportError("contentDocument is not available"); return null; },
           get currentURI() {
             if (!this._currentURI)
                this._currentURI = this._browser._ios.newURI("about:blank", null, null);
 
             return this._currentURI;
           },
           set currentURI(aURI) { this.loadURI(aURI.spec, null, null, null); },
           referringURI: null,
           get sessionHistory() { throw "sessionHistory: Not Remoteable"; },
 
           _currentURI: null,
           _browser: this,
-          _sendSyncMessage: function(aMessage, aData) {
+          _sendMessage: function(aMessage, aData) {
             try {
               this._browser.messageManager.sendAsyncMessage(aMessage, aData);
             }
             catch (e) {
               Components.utils.reportError(e);
             }
          }
         })
--- a/mobile/chrome/content/browser-ui.js
+++ b/mobile/chrome/content/browser-ui.js
@@ -149,32 +149,16 @@ var BrowserUI = {
         Browser.closeTab(Browser.getTabAtIndex(i));
         return { preventDefault: true };
       }
     }
 
     return { };
   },
 
-  _metaAdded : function(aEvent) {
-    let meta = aEvent.originalTarget;
-    if (!meta)
-      return;
-
-    if (meta.name == "viewport" || meta.name == "HandheldFriendly") {
-      // Must have an owner document and not be in a frame
-      var ownerDoc = meta.ownerDocument;
-      if (!ownerDoc || ownerDoc.defaultView.frameElement)
-        return;
-
-      let tab = Browser.getTabForDocument(ownerDoc);
-      tab.updateViewportMetadata();
-    }
-  },
-
   _updateButtons : function(aBrowser) {
     let back = document.getElementById("cmd_back");
     let forward = document.getElementById("cmd_forward");
 
     back.setAttribute("disabled", !aBrowser.canGoBack);
     forward.setAttribute("disabled", !aBrowser.canGoForward);
   },
 
@@ -720,19 +704,16 @@ var BrowserUI = {
       window.QueryInterface(Ci.nsIDOMChromeWindow).minimize();
     }
 #endif
   },
 
   handleEvent: function handleEvent(aEvent) {
     switch (aEvent.type) {
       // Browser events
-      case "DOMMetaAdded":
-        this._metaAdded(aEvent);
-        break;
       case "TabSelect":
         this._tabSelect(aEvent);
         break;
       case "TabOpen":
       {
         let [tabsVisibility,,,] = Browser.computeSidebarVisibility();
         if (!(tabsVisibility == 1.0) && Browser.selectedTab.chromeTab != aEvent.target)
           NewTabPopup.show(aEvent.target);
@@ -1189,18 +1170,19 @@ var PageActions = {
       filePath: picker.file.path
     };
 
     Browser.selectedBrowser.messageManager.sendAsyncMessage("Browser:SaveAs", data);
   },
 
   updatePageSaveAs: function updatePageSaveAs() {
     this.removeItems("saveas");
-    if (Browser.selectedBrowser.contentDocument instanceof XULDocument)
-      return;
+    // XXX Not sure if we care about this
+    //if (Browser.selectedBrowser.contentDocument instanceof XULDocument)
+    //  return;
 
     let strings = Elements.browserBundle;
     let node = this.appendItem("saveas", strings.getString("pageactions.saveas.pdf"), "");
     node.onclick = function(event) {
       PageActions._savePageAsPDF();
     }
   },
 
--- a/mobile/chrome/content/browser.js
+++ b/mobile/chrome/content/browser.js
@@ -422,21 +422,16 @@ var Browser = {
       let dpiScale = gPrefService.getIntPref("zoom.dpiScale") / 100;
 
       Browser.styles["viewport-width"].width = (w / dpiScale) + "px";
       Browser.styles["viewport-height"].height = (h / dpiScale) + "px";
       Browser.styles["window-width"].width = w + "px";
       Browser.styles["window-height"].height = h + "px";
       Browser.styles["toolbar-height"].height = toolbarHeight + "px";
 
-      // Cause a resize of the viewport if the current browser holds a XUL document
-      let browser = Browser.selectedBrowser;
-      if (browser.contentDocument instanceof XULDocument)
-        BrowserView.Util.ensureMozScrolledAreaEvent(browser, w, h);
-
       // Tell the UI to resize the browser controls
       BrowserUI.sizeControls(w, h);
 
       // XXX During the launch, the resize of the window arrive after we add
       // the first tab, so we need to force the viewport state for this case
       // see bug 558840
       let bvs = bv._browserViewportState;
       if (bvs.viewportRect.width == 1 && bvs.viewportRect.height == 1) {
@@ -445,18 +440,18 @@ var Browser = {
       }
 
       bv.updateDefaultZoom();
       if (bv.isDefaultZoom())
         // XXX this should really only happen on browser startup, not every resize
         Browser.hideSidebars();
       bv.onAfterVisibleMove();
 
-      for (let i = Browser._tabs.length - 1; i >= 0; i--)
-        Browser._tabs[i].updateViewportSize();
+      for (let i = Browser.tabs.length - 1; i >= 0; i--)
+        Browser.tabs[i].updateViewportSize();
 
       bv.commitBatchOperation();
       
       let curEl = document.activeElement;
       if (curEl && curEl.scrollIntoView)
         curEl.scrollIntoView(false);
     }
     window.addEventListener("resize", resizeHandler, false);
@@ -718,25 +713,16 @@ var Browser = {
   get selectedBrowser() {
     return this._selectedTab.browser;
   },
 
   get tabs() {
     return this._tabs;
   },
 
-  getTabForDocument: function(aDocument) {
-    let tabs = this._tabs;
-    for (let i = 0; i < tabs.length; i++) {
-      if (tabs[i].browser.contentDocument == aDocument)
-        return tabs[i];
-    }
-    return null;
-  },
-
   getTabForBrowser: function getTabForBrowser(aBrowser) {
     let tabs = this._tabs;
     for (let i = 0; i < tabs.length; i++) {
       if (tabs[i].browser == aBrowser)
         return tabs[i];
     }
     return null;
   },
@@ -2327,33 +2313,33 @@ ProgressController.prototype = {
       BrowserUI.update(TOOLBARSTATE_LOADED);
 
     if (this.browser.currentURI.spec != "about:blank")
       this._tab.updateThumbnail();
   },
 
   _documentStop: function _documentStop() {
     if (this._tab == Browser.selectedTab) {
-      // XXX Sometimes MozScrollSizeChange has not occurred, so the scroll pane will not
+      // XXX Sometimes MozScrolledAreaChanged has not occurred, so the scroll pane will not
       // be resized yet. We are assuming this event is on the queue, so scroll the pane
       // "soon."
       Util.executeSoon(function() {
         let scroll = Browser.getScrollboxPosition(Browser.contentScrollboxScroller);
         if (scroll.isZero())
           Browser.scrollContentToBrowser(0, 0);
       });
     }
     else {
-      let scroll = BrowserView.Util.getContentScrollOffset(this._tab.browser);
-      this._tab.contentScrollOffset = new Point(scroll.x, scroll.y);
-
-      // If the document content is scrolled to the top, make sure the URLbar is in view.
-      // If this were the selected tab, onLocationChange would scroll to top.
-      if (scroll.isZero())
-        this._tab.pageScrollOffset = new Point(0, 0);
+      // XXX: We don't know the current scroll position of the content, so assume
+      // it's at the top. This will be fixed by Layers
+      this._tab.contentScrollOffset = new Point(0, 0);
+
+      // Make sure the URLbar is in view. If this were the selected tab,
+      // onLocationChange would scroll to top.
+      this._tab.pageScrollOffset = new Point(0, 0);
     }
   }
 };
 
 var OfflineApps = {
   get _pm() {
     delete this._pm;
     return this._pm = Cc["@mozilla.org/permissionmanager;1"].getService(Ci.nsIPermissionManager);
@@ -2528,24 +2514,16 @@ Tab.prototype = {
       } else {
         viewportW = kDefaultBrowserWidth;
         viewportH = kDefaultBrowserWidth * (screenH / screenW);
       }
 
       browser.style.width = viewportW + "px";
       browser.style.height = viewportH + "px";
     }
-
-    // Some documents are not firing MozScrolledAreaChanged and/or fired it for
-    // sub-documents only
-    let doc = browser.contentDocument;
-    if (doc instanceof XULDocument || doc.body instanceof HTMLFrameSetElement) {
-       let [width, height] = BrowserView.Util.getBrowserDimensions(browser);
-       BrowserView.Util.ensureMozScrolledAreaEvent(browser, width, height);
-    }
   },
 
   startLoading: function startLoading() {
     if (this._loading) throw "Already Loading!";
 
     this._loading = true;
 
     let bv = Browser._browserView;
--- a/mobile/chrome/content/preferences.js
+++ b/mobile/chrome/content/preferences.js
@@ -250,17 +250,17 @@ var PreferencesView = {
       case "none":
         url = "about:blank";
         break;
       case "default":
         url = "about:home";
         break;
       case "currentpage":
         url = Browser.selectedBrowser.currentURI.spec;
-        display = Browser.selectedBrowser.contentDocument.title || url;
+        display = Browser.selectedBrowser.contentTitle || url;
         break;
     }
 
     // Show or hide the title or URL of the custom homepage
     this._showHomePageHint(display);
 
     // Is the helper already in the list
     let helper = null;
--- a/mobile/components/SessionStore.js
+++ b/mobile/components/SessionStore.js
@@ -331,17 +331,17 @@ SessionStore.prototype = {
       data.windows.push(this._windows[index]);
     
     this._writeFile(this._sessionFile, JSON.stringify(data));
 
     this._lastSaveTime = Date.now();
   },
   
   _collectTabData: function ss__collectTabData(aBrowser) {
-    let tabData = { url: aBrowser.currentURI.spec, title: aBrowser.contentDocument.title };
+    let tabData = { url: aBrowser.currentURI.spec, title: aBrowser.contentTitle };
     aBrowser.__SS_data = tabData;
   },
   
   _collectWindowData: function ss__collectWindowData(aWindow) {
     // Ignore windows not tracked by SessionStore
     if (!aWindow.__SSID || !this._windows[aWindow.__SSID])
       return;