mirror of
https://github.com/roytam1/mozilla45esr.git
synced 2026-06-20 23:48:59 +00:00
a118552a79
- fix M1607443 as a precaution (b8657e696) - #369: add back build system changes [partly] (a7ee0d3a4) - revert #489 (#576): enable CHACHA20/POLY1305, remove TLS_ECDHE_RSA_WITH_AES_128_CBC_SHA256 as it is no longer needed [partly] (581cb94a7) - closes #585: check parse-on-load is enabled first (0d448f2ba) - #587: M1513855 M1596668 M1602944 M1599420 M1595399 (35a4358b3) - #585: derp (71110bf96) - #587: update TLDs, certs, pins, etc. (35584e5e6) - #369: bustage fix for opt builds (cc2e336b2)
96 lines
2.6 KiB
JavaScript
96 lines
2.6 KiB
JavaScript
// -*- indent-tabs-mode: nil; js-indent-level: 2 -*-
|
|
/* This Source Code Form is subject to the terms of the Mozilla Public
|
|
* License, v. 2.0. If a copy of the MPL was not distributed with this file,
|
|
* You can obtain one at http://mozilla.org/MPL/2.0/. */
|
|
"use strict";
|
|
|
|
// This file and Readability-readerable.js are merged together into
|
|
// Readerable.jsm.
|
|
|
|
/* exported Readerable */
|
|
/* import-globals-from Readability-readerable.js */
|
|
|
|
const { classes: Cc, interfaces: Ci, utils: Cu } = Components;
|
|
|
|
Cu.import("resource://gre/modules/Services.jsm");
|
|
Cu.import("resource://gre/modules/XPCOMUtils.jsm");
|
|
|
|
function isNodeVisible(node) {
|
|
return node.clientHeight > 0 && node.clientWidth > 0;
|
|
}
|
|
|
|
var Readerable = {
|
|
isEnabled: true,
|
|
isForceEnabled: false,
|
|
|
|
get isEnabledForParseOnLoad() {
|
|
return this.isEnabled || this.isForceEnabled;
|
|
},
|
|
|
|
/**
|
|
* Decides whether or not a document is reader-able without parsing the whole thing.
|
|
*
|
|
* @param doc A document to parse.
|
|
* @return boolean Whether or not we should show the reader mode button.
|
|
*/
|
|
isProbablyReaderable(doc) {
|
|
// Only care about 'real' HTML documents:
|
|
if (doc.mozSyntheticDocument || !(doc instanceof doc.defaultView.HTMLDocument)) {
|
|
return false;
|
|
}
|
|
|
|
let uri = Services.io.newURI(doc.location.href, null, null);
|
|
if (!this.shouldCheckUri(uri)) {
|
|
return false;
|
|
}
|
|
return isProbablyReaderable(doc, isNodeVisible);
|
|
},
|
|
|
|
_blockedHosts: [
|
|
"amazon.com",
|
|
"github.com",
|
|
"mail.google.com",
|
|
"pinterest.com",
|
|
"reddit.com",
|
|
"twitter.com",
|
|
"youtube.com",
|
|
],
|
|
|
|
shouldCheckUri(uri, isBaseUri = false) {
|
|
if (!(uri.schemeIs("http") || uri.schemeIs("https"))) {
|
|
return false;
|
|
}
|
|
if (!(this.isEnabledForParseOnLoad)) {
|
|
// TenFourFox issue 585
|
|
// Do this check here as well.
|
|
return false;
|
|
}
|
|
if (!isBaseUri) {
|
|
// Sadly, some high-profile pages have false positives, so bail early for those:
|
|
let asciiHost = uri.asciiHost;
|
|
if (this._blockedHosts.some(blockedHost => asciiHost.endsWith(blockedHost))) {
|
|
return false;
|
|
}
|
|
if (uri.filePath == "/") {
|
|
return false;
|
|
}
|
|
}
|
|
|
|
return true;
|
|
},
|
|
|
|
observe: function(aMessage, aTopic, aData) {
|
|
switch(aTopic) {
|
|
case "nsPref:changed":
|
|
if (aData === "reader.parse-on-load.enabled") {
|
|
this.isEnabled = Services.prefs.getBoolPref(aData);
|
|
} else if (aData === "reader.parse-on-load.force-enabled") {
|
|
this.isForceEnabled = Services.prefs.getBoolPref(aData);
|
|
}
|
|
break;
|
|
}
|
|
}
|
|
};
|
|
Services.prefs.addObserver("reader.parse-on-load.", Readerable, false);
|
|
|