From af5c9c32131cce700bb12735a18a2b180146a7c6 Mon Sep 17 00:00:00 2001 From: Justin Dolske Date: Fri, 27 Jul 2012 23:25:11 -0700 Subject: [PATCH] Bug 769960 - Refactor the terrifying code in nsSafebrowsingApplication.js. r=fryn, f=gcp --- browser/app/profile/firefox.js | 3 + .../content/browser-safebrowsing.js} | 33 +-- browser/base/content/browser.js | 17 +- browser/base/content/browser.xul | 3 - browser/base/content/utilityOverlay.js | 7 +- browser/components/safebrowsing/Makefile.in | 8 +- .../components/safebrowsing/SafeBrowsing.jsm | 216 ++++++++++++++++++ .../safebrowsing/content/application.js | 108 --------- .../safebrowsing/content/globalstore.js | 191 ---------------- .../safebrowsing/content/list-warden.js | 102 --------- .../safebrowsing/content/malware-warden.js | 123 ---------- .../safebrowsing/content/phishing-warden.js | 131 ----------- .../content/report-phishing-overlay.xul | 4 +- browser/components/safebrowsing/jar.mn | 1 - .../src/nsSafebrowsingApplication.js | 60 ----- .../src/nsSafebrowsingApplication.manifest | 2 - browser/installer/package-manifest.in | 4 - 17 files changed, 248 insertions(+), 765 deletions(-) rename browser/{components/safebrowsing/content/sb-loader.js => base/content/browser-safebrowsing.js} (67%) create mode 100644 browser/components/safebrowsing/SafeBrowsing.jsm delete mode 100644 browser/components/safebrowsing/content/application.js delete mode 100644 browser/components/safebrowsing/content/globalstore.js delete mode 100644 browser/components/safebrowsing/content/list-warden.js delete mode 100644 browser/components/safebrowsing/content/malware-warden.js delete mode 100644 browser/components/safebrowsing/content/phishing-warden.js delete mode 100644 browser/components/safebrowsing/src/nsSafebrowsingApplication.js delete mode 100644 browser/components/safebrowsing/src/nsSafebrowsingApplication.manifest diff --git a/browser/app/profile/firefox.js b/browser/app/profile/firefox.js index 0d9772a508b..17ee5ee76c2 100644 --- a/browser/app/profile/firefox.js +++ b/browser/app/profile/firefox.js @@ -721,6 +721,9 @@ pref("browser.safebrowsing.enabled", true); // Prevent loading of pages identified as malware pref("browser.safebrowsing.malware.enabled", true); +// Debug logging to error console +pref("browser.safebrowsing.debug", false); + // Non-enhanced mode (local url lists) URL list to check for updates pref("browser.safebrowsing.provider.0.updateURL", "http://safebrowsing.clients.google.com/safebrowsing/downloads?client={moz:client}&appver={moz:version}&pver=2.2"); diff --git a/browser/components/safebrowsing/content/sb-loader.js b/browser/base/content/browser-safebrowsing.js similarity index 67% rename from browser/components/safebrowsing/content/sb-loader.js rename to browser/base/content/browser-safebrowsing.js index 966b9484ecb..96cf1f35897 100644 --- a/browser/components/safebrowsing/content/sb-loader.js +++ b/browser/base/content/browser-safebrowsing.js @@ -2,23 +2,14 @@ # 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/. -var safebrowsing = { - startup: function() { - setTimeout(function() { - safebrowsing.deferredStartup(); - }, 2000); - window.removeEventListener("load", safebrowsing.startup, false); - }, - - deferredStartup: function() { - this.appContext.initialize(); - }, +#ifdef MOZ_SAFE_BROWSING +var gSafeBrowsing = { setReportPhishingMenu: function() { - + // A phishing page will have a specific about:blocked content documentURI var isPhishingPage = /^about:blocked\?e=phishingBlocked/.test(content.document.documentURI); - + // Show/hide the appropriate menu item. document.getElementById("menu_HelpPopup_reportPhishingtoolmenu") .hidden = isPhishingPage; @@ -39,15 +30,6 @@ var safebrowsing = { else broadcaster.setAttribute("disabled", true); }, - - /** - * Lazy init getter for appContext - */ - get appContext() { - delete this.appContext; - return this.appContext = Cc["@mozilla.org/safebrowsing/application;1"] - .getService().wrappedJSObject; - }, /** * Used to report a phishing page or a false positive @@ -55,13 +37,12 @@ var safebrowsing = { * @return String the report phishing URL. */ getReportURL: function(name) { - var reportUrl = this.appContext.getReportURL(name); + var reportUrl = SafeBrowsing.getReportURL(name); - var pageUrl = getBrowser().currentURI.asciiSpec; + var pageUrl = gBrowser.currentURI.asciiSpec; reportUrl += "&url=" + encodeURIComponent(pageUrl); return reportUrl; } } - -window.addEventListener("load", safebrowsing.startup, false); +#endif diff --git a/browser/base/content/browser.js b/browser/base/content/browser.js index 1966dbed7d7..4b9454bd8ce 100644 --- a/browser/base/content/browser.js +++ b/browser/base/content/browser.js @@ -140,6 +140,14 @@ XPCOMUtils.defineLazyGetter(this, "Social", function() { return tmp.Social; }); +#ifdef MOZ_SAFE_BROWSING +XPCOMUtils.defineLazyGetter(this, "SafeBrowsing", function() { + let tmp = {}; + Cu.import("resource://gre/modules/SafeBrowsing.jsm", tmp); + return tmp.SafeBrowsing; +}); +#endif + let gInitialPages = [ "about:blank", "about:newtab", @@ -154,6 +162,7 @@ let gInitialPages = [ #include browser-fullZoom.js #include browser-places.js #include browser-plugins.js +#include browser-safebrowsing.js #include browser-social.js #include browser-tabPreviews.js #include browser-tabview.js @@ -1241,6 +1250,10 @@ var gBrowserInit = { TelemetryTimestamps.add("delayedStartupStarted"); gDelayedStartupTimeoutId = null; +#ifdef MOZ_SAFE_BROWSING + SafeBrowsing.init(); +#endif + Services.obs.addObserver(gSessionHistoryObserver, "browser:purge-session-history", false); Services.obs.addObserver(gXPInstallObserver, "addon-install-disabled", false); Services.obs.addObserver(gXPInstallObserver, "addon-install-started", false); @@ -2580,7 +2593,7 @@ function BrowserOnClick(event) { label: gNavigatorBundle.getString("safebrowsing.notAnAttackButton.label"), accessKey: gNavigatorBundle.getString("safebrowsing.notAnAttackButton.accessKey"), callback: function() { - openUILinkIn(safebrowsing.getReportURL('MalwareError'), 'tab'); + openUILinkIn(gSafeBrowsing.getReportURL('MalwareError'), 'tab'); } }; } else { @@ -2589,7 +2602,7 @@ function BrowserOnClick(event) { label: gNavigatorBundle.getString("safebrowsing.notAForgeryButton.label"), accessKey: gNavigatorBundle.getString("safebrowsing.notAForgeryButton.accessKey"), callback: function() { - openUILinkIn(safebrowsing.getReportURL('Error'), 'tab'); + openUILinkIn(gSafeBrowsing.getReportURL('Error'), 'tab'); } }; } diff --git a/browser/base/content/browser.xul b/browser/base/content/browser.xul index 7992353d303..cabd330e9dd 100644 --- a/browser/base/content/browser.xul +++ b/browser/base/content/browser.xul @@ -55,9 +55,6 @@ #include global-scripts.inc