Bug 1153384 - Improve isProbablyReaderable detection. r=margaret, a=lizzard
authorGijs Kruitbosch <gijskruitbosch@gmail.com>
Mon, 27 Apr 2015 15:58:24 +0100
changeset 265801 6ab4d0b260199c846ee3a5853f32d047a3569186
parent 265800 a5fa340c2948bc7867c950a1b1013fba8ff492c1
child 265802 10fb1d23ac56c10091f94d3f95b4050e53d1ef20
push id4718
push userraliiev@mozilla.com
push dateMon, 11 May 2015 18:39:53 +0000
treeherdermozilla-beta@c20c4ef55f08 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersmargaret, lizzard
bugs1153384
milestone39.0a2
Bug 1153384 - Improve isProbablyReaderable detection. r=margaret, a=lizzard
toolkit/components/reader/ReaderMode.jsm
--- a/toolkit/components/reader/ReaderMode.jsm
+++ b/toolkit/components/reader/ReaderMode.jsm
@@ -15,16 +15,17 @@ Cu.importGlobalProperties(["XMLHttpReque
 
 XPCOMUtils.defineLazyModuleGetter(this, "CommonUtils", "resource://services-common/utils.js");
 XPCOMUtils.defineLazyModuleGetter(this, "OS", "resource://gre/modules/osfile.jsm");
 XPCOMUtils.defineLazyModuleGetter(this, "ReaderWorker", "resource://gre/modules/reader/ReaderWorker.jsm");
 XPCOMUtils.defineLazyModuleGetter(this, "Task", "resource://gre/modules/Task.jsm");
 
 XPCOMUtils.defineLazyGetter(this, "Readability", function() {
   let scope = {};
+  scope.dump = this.dump;
   Services.scriptloader.loadSubScript("resource://gre/modules/reader/Readability.js", scope);
   return scope["Readability"];
 });
 
 this.ReaderMode = {
   // Version of the cache schema.
   CACHE_VERSION: 1,
 
@@ -107,17 +108,30 @@ this.ReaderMode = {
    */
   isProbablyReaderable: function(doc) {
     let uri = Services.io.newURI(doc.location.href, null, null);
 
     if (!this._shouldCheckUri(uri)) {
       return false;
     }
 
-    return new Readability(uri, doc).isProbablyReaderable();
+    let utils = this.getUtilsForWin(doc.defaultView);
+    // We pass in a helper function to determine if a node is visible, because
+    // it uses gecko APIs that the engine-agnostic readability code can't rely
+    // upon.
+    return new Readability(uri, doc).isProbablyReaderable(this.isNodeVisible.bind(this, utils));
+  },
+
+  isNodeVisible: function(utils, node) {
+    let bounds = utils.getBoundsWithoutFlushing(node);
+    return bounds.height > 0 && bounds.width > 0;
+  },
+
+  getUtilsForWin: function(win) {
+    return win.QueryInterface(Ci.nsIInterfaceRequestor).getInterface(Ci.nsIDOMWindowUtils);
   },
 
   /**
    * Gets an article from a loaded browser's document. This method will not attempt
    * to parse certain URIs (e.g. about: URIs).
    *
    * @param doc A document to parse.
    * @return {Promise}