Bug 571814 - Remove PluginObserver [r=vingtetun]
authorMark Finkle <mfinkle@mozilla.com>
Mon, 14 Jun 2010 09:08:06 -0400
changeset 1630 5699ce3e4350b58b844f7ee8c75d1459e2805db3
parent 1629 c1d9961f4677d5da9f2f2299e428ff928a994b81
child 1631 2935fc0e9bb76d488dc952ae376dac6e498219e8
push id1466
push usermfinkle@mozilla.com
push dateMon, 14 Jun 2010 13:08:18 +0000
reviewersvingtetun
bugs571814
Bug 571814 - Remove PluginObserver [r=vingtetun]
chrome/content/browser.js
--- a/chrome/content/browser.js
+++ b/chrome/content/browser.js
@@ -573,18 +573,16 @@ var Browser = {
     }
 
     // Force commonly used border-images into the image cache
     ImagePreloader.cache();
 
     messageManager.addMessageListener("FennecViewportMetadata", this);
     messageManager.addMessageListener("Browser:MozApplicationManifest", OfflineApps);
 
-    this._pluginObserver = new PluginObserver(bv);
-
     // broadcast a UIReady message so add-ons know we are finished with startup
     let event = document.createEvent("Events");
     event.initEvent("UIReady", true, false);
     window.dispatchEvent(event);
   },
 
   _waitingToClose: false,
   closing: function closing() {
@@ -645,17 +643,16 @@ var Browser = {
   
     gObserverService.notifyObservers(null, "browser-lastwindow-close-granted", null);
     return true;
   },
 
   shutdown: function shutdown() {
     this._browserView.uninit();
     BrowserUI.uninit();
-    this._pluginObserver.stop();
 
     var os = Cc["@mozilla.org/observer-service;1"].getService(Ci.nsIObserverService);
     os.removeObserver(gXPInstallObserver, "addon-install-blocked");
     os.removeObserver(gSessionHistoryObserver, "browser:purge-session-history");
     os.removeObserver(MemoryObserver, "memory-pressure");
     os.removeObserver(BrowserSearch, "browser-search-engine-modified");
     os.removeObserver(FormSubmitObserver, "formsubmit");
 
@@ -3371,203 +3368,8 @@ 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";
     }
   }
 }
-
-const nsIObjectLoadingContent = Ci.nsIObjectLoadingContent_MOZILLA_1_9_2_BRANCH || Ci.nsIObjectLoadingContent;
-
-/**
- * Allows fast-path embed rendering by letting objects know where to absolutely
- * render on the screen.
- */
-function PluginObserver(bv) {
-  this._emptyRect = new Rect(0, 0, 0, 0);
-  this._contentShowing = document.getElementById("observe_contentShowing");
-  this._bv = bv;
-  this._started = false;
-  this._isRendering = false;
-
-  let disabled = gPrefService.getBoolPref("plugin.disable");
-  if (!disabled)
-    this.start();
-}
-
-PluginObserver.prototype = {
-  // When calculating critical rect, subtract N pixels around popup boxes
-  POPUP_PADDING: 4,
-
-  /** Starts flash objects fast path. */
-  start: function() {
-    if (this._started)
-      return;
-    this._started = true;
-
-    document.getElementById("tabs-container").addEventListener("TabSelect", this, false);
-    this._contentShowing.addEventListener("broadcast", this, false);
-    let browsers = document.getElementById("browsers");
-    browsers.addEventListener("RenderStateChanged", this, false);
-    gObserverService.addObserver(this, "plugin-changed-event", false);
-    Elements.stack.addEventListener("PopupChanged", this, false);
-
-    let browser = Browser.selectedBrowser;
-    if (browser) {
-      browser.addEventListener("ZoomChanged", this, false);
-      browser.addEventListener("MozAfterPaint", this, false);
-    }
-  },
-
-  /** Stops listening for events. */
-  stop: function() {
-    if (!this._started)
-      return;
-    this._started = false;
-
-    document.getElementById("tabs-container").removeEventListener("TabSelect", this, false);
-    this._contentShowing.removeEventListener("broadcast", this, false);
-    let browsers = document.getElementById("browsers");
-    browsers.removeEventListener("RenderStateChanged", this, false);
-    gObserverService.removeObserver(this, "plugin-changed-event");
-    Elements.stack.removeEventListener("PopupChanged", this, false);
-
-    let browser = Browser.selectedBrowser;
-    if (browser) {
-      browser.removeEventListener("ZoomChanged", this, false);
-      browser.removeEventListener("MozAfterPaint", this, false);
-    }
-  },
-
-  /** Observe listens for plugin change events and maintains an embed cache. */
-  observe: function observe(subject, topic, data) {
-    if (topic == "plugin-changed-event")
-      this.updateCurrentBrowser();
-  },
-
-  /** Update flash objects */
-  handleEvent: function handleEvent(ev) {
-    if (ev.type == "TabSelect") {
-      if (ev.lastTab) {
-        let browser = ev.lastTab.browser;
-        let oldDoc = browser.contentDocument;
-
-        browser.removeEventListener("ZoomChanged", this, false);
-        browser.removeEventListener("MozAfterPaint", this, false);
-        this.updateEmbedRegions(this.getPluginNodes(oldDoc), this._emptyRect);
-      }
-
-      let browser = Browser.selectedBrowser;
-      browser.addEventListener("ZoomChanged", this, false);
-      browser.addEventListener("MozAfterPaint", this, false);
-    }
-
-    this.updateCurrentBrowser();
-  },
-
-  /** Find all embedded objects in document and its frames */
-  getPluginNodes: function getPluginNodes(doc) {
-    let docs = Util.getAllDocuments(doc);
-    let result = [];
-
-    let i;
-    let plugins;
-    for (i = 0; i < docs.length; i++) {
-      plugins = docs[i].querySelectorAll("embed,object");
-      result.push.apply(result, Array.prototype.slice.call(plugins));
-    }
-
-    return result;
-  },
-
-  /** Update the current browser's flash objects. */
-  updateCurrentBrowser: function updateCurrentBrowser() {
-    let doc = Browser.selectedTab.browser.contentDocument;
-
-    let rect = this.getCriticalRect();
-    if (rect == this._emptyRect && !this._isRendering)
-      return;
-
-    if (this._isRendering) {
-      // Update immediately if not just starting to render
-      if (rect == this._emptyRect)
-        this._isRendering = false;
-      this.updateEmbedRegions(this.getPluginNodes(doc), rect);
-    } else {
-      // Wait a moment so that any chrome redraws occur first.
-      let self = this;
-      setTimeout(function() {
-        self._isRendering = true;
-        // Recalculate critical rect so we don't render when we ought not to.
-        self.updateEmbedRegions(self.getPluginNodes(doc), self.getCriticalRect());
-      }, 0);
-    }
-  },
-
-  /** More accurate version of finding the current visible region. Returns client coords. */
-  getCriticalRect: function getCriticalRect() {
-    let bv = this._bv;
-    if (Browser.selectedTab._loading)
-      return this._emptyRect;
-    if (!bv.isRendering())
-      return this._emptyRect;
-    if (Elements.contentShowing.hasAttribute("disabled"))
-      return this._emptyRect;
-
-    let vs = bv._browserViewportState;
-    let vr = bv.getVisibleRect();
-    let crit = BrowserView.Util.visibleRectToCriticalRect(vr, vs);
-    crit = Browser.browserViewToClientRect(crit);
-
-    if (BrowserUI.isToolbarLocked()) {
-      let urlbarRect = Elements.toolbarContainer.getBoundingClientRect();
-      // Subtract urlbar area from critical rect area.  In general subtracting a rect from another
-      // results in a region that can be described by a union of rects.  Luckily in this case,
-      // we can cheat because the resulting area is still just one rect.
-      crit.top = Math.max(Math.round(urlbarRect.height) + 1, crit.top);
-      // XXX we add 1 to the height so that flash overlays don't leak into URL bar (otherwise
-      // you may see a strip of junk if you pop up the identity panel over flash)
-    }
-
-    let popup = BrowserUI._popup;
-    if (popup) {
-      let p = this.POPUP_PADDING;
-      let elements = BrowserUI._popup.elements;
-      for (let i = elements.length - 1; i >= 0; i--) {
-        let popupRect = Rect.fromRect(elements[i].getBoundingClientRect()).expandToIntegers();
-        // XXX Our CSS shadows don't seem to be included in getBoundingClientRect.  Compensate
-        // with some padding; may need to be changed depending on the theme. Otherwise, flash
-        // can "leak into" the popup.
-        popupRect.setBounds(popupRect.left - p, popupRect.top - p, popupRect.right + p, popupRect.bottom + p);
-        let areaRects = crit.subtract(popupRect);
-        if (areaRects.length == 1) {
-          // Yay, critical region is still just a rect!
-          crit = areaRects[0];
-        } else if (areaRects.length > 1) {
-          // Critical region is a union of rects. Give up.
-          return this._emptyRect;
-        }
-      }
-    }
-
-    return crit;
-  },
-
-  /**
-   * Tell embedded objects where to absolutely render, using crit for clipping.
-   * @param crit Specified in client coordinates
-   */
-  updateEmbedRegions: function updateEmbedRegions(objects, crit) {
-    let bv = this._bv;
-    let oprivate, r, dest, clip;
-    for (let i = objects.length - 1; i >= 0; i--) {
-      r = bv.browserToViewportRect(Browser.getBoundingContentRect(objects[i]));
-      dest = Browser.browserViewToClientRect(r);
-      clip = dest.intersect(crit).translate(-dest.left, -dest.top);
-      oprivate = objects[i].QueryInterface(nsIObjectLoadingContent);
-      try {
-        oprivate.setAbsoluteScreenPosition(Browser.contentScrollbox, dest, clip);
-      } catch(e) {};
-    }
-  }
-};