зеркало из https://github.com/mozilla/pjs.git
bug 339839: isolate safe browsing provider prefs in globalstore.js
r+a=bryner
This commit is contained in:
Родитель
2b0c4224da
Коммит
99b71abd80
|
@ -72,27 +72,6 @@ function PROT_Controller(win, tabWatcher, phishingWarden) {
|
|||
// Use this to query preferences
|
||||
this.prefs_ = new G_Preferences();
|
||||
|
||||
// Read state: are we in advanced mode?
|
||||
this.checkRemotePrefName_ = PROT_GlobalStore.getServerCheckEnabledPrefName();
|
||||
this.checkRemote_ = this.prefs_.getPref(this.checkRemotePrefName_, null);
|
||||
|
||||
// Get notifications when the advanced mode preference changes
|
||||
this.checkRemotePrefObserver = BindToObject(this.onCheckRemotePrefChanged,
|
||||
this);
|
||||
this.prefs_.addObserver(this.checkRemotePrefName_,
|
||||
this.checkRemotePrefObserver);
|
||||
|
||||
// Global preference to enable the phishing warden
|
||||
this.phishWardenPrefName_ = PROT_GlobalStore.getPhishWardenEnabledPrefName();
|
||||
this.phishWardenEnabled_ = this.prefs_.getPref(this.phishWardenPrefName_,
|
||||
null);
|
||||
|
||||
// Get notifications when the phishing warden enabled pref changes
|
||||
this.phishWardenPrefObserver =
|
||||
BindToObject(this.onPhishWardenEnabledPrefChanged, this);
|
||||
this.prefs_.addObserver(this.phishWardenPrefName_,
|
||||
this.phishWardenPrefObserver);
|
||||
|
||||
// Set us up to receive the events we want.
|
||||
this.tabWatcher_ = tabWatcher;
|
||||
this.onTabSwitchCallback_ = BindToObject(this.onTabSwitch, this);
|
||||
|
@ -171,10 +150,6 @@ PROT_Controller.prototype.shutdown = function(e) {
|
|||
// down, and it will remove them.
|
||||
this.browserView_ = null;
|
||||
|
||||
this.prefs_.removeObserver(this.checkRemotePrefName_,
|
||||
this.checkRemotePrefObserver);
|
||||
this.prefs_.removeObserver(this.phishWardenPrefName_,
|
||||
this.phishWardenPrefObserver);
|
||||
if (this.tabWatcher_) {
|
||||
this.tabWatcher_.removeListener("tabswitch",
|
||||
this.onTabSwitchCallback_);
|
||||
|
@ -189,31 +164,6 @@ PROT_Controller.prototype.shutdown = function(e) {
|
|||
G_Debug(this, "Controller shut down.");
|
||||
}
|
||||
|
||||
/**
|
||||
* Deal with a user changing the pref that says whether we're in advanced
|
||||
* mode (and thus should check the remote server)
|
||||
*
|
||||
* @param prefName Name of the pref holding the value indicating whether
|
||||
* we should check remote server
|
||||
*/
|
||||
PROT_Controller.prototype.onCheckRemotePrefChanged = function(prefName) {
|
||||
this.checkRemote_ = this.prefs_.getBoolPrefOrDefault(prefName,
|
||||
this.checkRemote_);
|
||||
}
|
||||
|
||||
/**
|
||||
* Deal with a user changing the pref that says whether we should
|
||||
* enable the phishing warden
|
||||
*
|
||||
* @param prefName Name of the pref holding the value indicating whether
|
||||
* we should enable the phishing warden
|
||||
*/
|
||||
PROT_Controller.prototype.onPhishWardenEnabledPrefChanged = function(
|
||||
prefName) {
|
||||
this.phishWardenEnabled_ =
|
||||
this.prefs_.getBoolPrefOrDefault(prefName, this.phishWardenEnabled_);
|
||||
}
|
||||
|
||||
/**
|
||||
* The user clicked the urlbar icon; they want to see the warning message
|
||||
* again.
|
||||
|
|
|
@ -60,60 +60,6 @@ PROT_GlobalStore.getPref_ = function(prefname) {
|
|||
return pref.getPref(prefname);
|
||||
}
|
||||
|
||||
/**
|
||||
* @returns The name of the pref determining whether phishing protection
|
||||
* is enabled (i.e., whether SafeBrowsing is enabled)
|
||||
*/
|
||||
PROT_GlobalStore.getPhishWardenEnabledPrefName = function() {
|
||||
return "browser.safebrowsing.enabled";
|
||||
}
|
||||
|
||||
/**
|
||||
* @returns The name of the pref determining whether we enable remote
|
||||
* checking (advanced protection)
|
||||
*/
|
||||
PROT_GlobalStore.getServerCheckEnabledPrefName = function() {
|
||||
return "browser.safebrowsing.remoteLookups";
|
||||
}
|
||||
|
||||
/**
|
||||
* @returns The name of the pref determining whether we send reports
|
||||
* about user actions
|
||||
*/
|
||||
PROT_GlobalStore.getSendUserReportsPrefName = function() {
|
||||
// We send reports iff advanced protection mode is on
|
||||
return PROT_GlobalStore.getServerCheckEnabledPrefName();
|
||||
}
|
||||
|
||||
/**
|
||||
* @returns The name of the directory in which we should store data (like
|
||||
* blacklists and whitelists). This is relative to the user's
|
||||
* profile.
|
||||
*/
|
||||
PROT_GlobalStore.getAppDirectoryName = function() {
|
||||
return "safebrowsing_data";
|
||||
}
|
||||
|
||||
/**
|
||||
* @returns String containing the URL to nav to when the user clicks
|
||||
* "get me out of here"
|
||||
*/
|
||||
PROT_GlobalStore.getGetMeOutOfHereURL = function() {
|
||||
// Try to get their homepage from prefs.
|
||||
var prefs = Cc["@mozilla.org/preferences-service;1"]
|
||||
.getService(Ci.nsIPrefService).getBranch(null);
|
||||
|
||||
var url = "about:blank";
|
||||
try {
|
||||
url = prefs.getComplexValue("browser.startup.homepage",
|
||||
Ci.nsIPrefLocalizedString).data;
|
||||
} catch(e) {
|
||||
G_Debug(this, "Couldn't get homepage pref: " + e);
|
||||
}
|
||||
|
||||
return url;
|
||||
}
|
||||
|
||||
/**
|
||||
* TODO: maybe deprecate because antiphishing.org isn't localized
|
||||
* @returns String containing the URL to nav to when the user clicks
|
||||
|
@ -128,6 +74,8 @@ PROT_GlobalStore.getAntiPhishingURL = function() {
|
|||
* on the policy link in the preferences.
|
||||
*/
|
||||
PROT_GlobalStore.getPolicyURL = function() {
|
||||
// XXX: Url to a mozilla page describing a safe browsing? This used to
|
||||
// like to google toolbar's privacy page.
|
||||
return "TODO";
|
||||
}
|
||||
|
||||
|
@ -190,13 +138,6 @@ PROT_GlobalStore.getLookupserverURL = function() {
|
|||
return PROT_GlobalStore.getPref_("browser.safebrowsing.provider.0.lookupURL");
|
||||
}
|
||||
|
||||
/**
|
||||
* @returns String giving url to use for updates (diff of lists)
|
||||
*/
|
||||
PROT_GlobalStore.getUpdateserverURL = function() {
|
||||
return PROT_GlobalStore.getPref_("browser.safebrowsing.provider.0.updateURL");
|
||||
}
|
||||
|
||||
/**
|
||||
* TODO: maybe deprecate?
|
||||
* @returns String giving url to use to report actions (advanced mode only
|
||||
|
|
|
@ -161,10 +161,31 @@ PROT_PhishMsgDisplayerBase.prototype.acceptAction = function() {
|
|||
G_Debug(this, "User accepted warning.");
|
||||
this.reporter_.report("phishaccept", this.url_);
|
||||
|
||||
var url = PROT_GlobalStore.getGetMeOutOfHereURL();
|
||||
var url = this.getMeOutOfHereUrl_();
|
||||
this.browser_.loadURI(url);
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the url for "Get me out of here." This is the user's home page if
|
||||
* one is set, ow, about:blank.
|
||||
* @return String url
|
||||
*/
|
||||
PROT_PhishMsgDisplayerBase.prototype.getMeOutOfHereUrl_ = function() {
|
||||
// Try to get their homepage from prefs.
|
||||
var prefs = Cc["@mozilla.org/preferences-service;1"]
|
||||
.getService(Ci.nsIPrefService).getBranch(null);
|
||||
|
||||
var url = "about:blank";
|
||||
try {
|
||||
url = prefs.getComplexValue("browser.startup.homepage",
|
||||
Ci.nsIPrefLocalizedString).data;
|
||||
} catch(e) {
|
||||
G_Debug(this, "Couldn't get homepage pref: " + e);
|
||||
}
|
||||
|
||||
return url;
|
||||
}
|
||||
|
||||
/**
|
||||
* Invoked when the browser is resized
|
||||
*/
|
||||
|
|
|
@ -63,6 +63,10 @@
|
|||
// Note: There is a single warden for the whole application.
|
||||
//
|
||||
// TODO better way to expose displayers/views to browser view
|
||||
|
||||
const kPhishWardenEnabledPref = "browser.safebrowsing.enabled";
|
||||
const kPhishWardenRemoteLookups = "browser.safebrowsing.remoteLookups";
|
||||
|
||||
/**
|
||||
* Abtracts the checking of user/browser actions for signs of
|
||||
* phishing.
|
||||
|
@ -91,22 +95,20 @@ function PROT_PhishingWarden() {
|
|||
// mode, so reflect the appropriate preferences into our state.
|
||||
|
||||
// Read state: should we be checking remote preferences?
|
||||
var checkRemotePrefName = PROT_GlobalStore.getServerCheckEnabledPrefName();
|
||||
this.checkRemote_ = this.prefs_.getPref(checkRemotePrefName, null);
|
||||
this.checkRemote_ = this.prefs_.getPref(kPhishWardenRemoteLookups, null);
|
||||
|
||||
// Get notifications when the remote check preference changes
|
||||
var checkRemotePrefObserver = BindToObject(this.onCheckRemotePrefChanged,
|
||||
this);
|
||||
this.prefs_.addObserver(checkRemotePrefName, checkRemotePrefObserver);
|
||||
this.prefs_.addObserver(kPhishWardenRemoteLookups, checkRemotePrefObserver);
|
||||
|
||||
// Global preference to enable the phishing warden
|
||||
var phishWardenPrefName = PROT_GlobalStore.getPhishWardenEnabledPrefName();
|
||||
this.phishWardenEnabled_ = this.prefs_.getPref(phishWardenPrefName, null);
|
||||
this.phishWardenEnabled_ = this.prefs_.getPref(kPhishWardenEnabledPref, null);
|
||||
|
||||
// Get notifications when the phishing warden enabled pref changes
|
||||
var phishWardenPrefObserver =
|
||||
BindToObject(this.onPhishWardenEnabledPrefChanged, this);
|
||||
this.prefs_.addObserver(phishWardenPrefName, phishWardenPrefObserver);
|
||||
this.prefs_.addObserver(kPhishWardenEnabledPref, phishWardenPrefObserver);
|
||||
|
||||
// We have a hardcoded URLs we let people navigate to in order to
|
||||
// check out the warning.
|
||||
|
@ -159,11 +161,9 @@ PROT_PhishingWarden.prototype.maybeToggleUpdateChecking = function() {
|
|||
if (this.testing_)
|
||||
return;
|
||||
|
||||
var phishWardenPrefName = PROT_GlobalStore.getPhishWardenEnabledPrefName();
|
||||
var phishWardenEnabled = this.prefs_.getPref(phishWardenPrefName, null);
|
||||
var phishWardenEnabled = this.prefs_.getPref(kPhishWardenEnabledPref, null);
|
||||
|
||||
var checkRemotePrefName = PROT_GlobalStore.getServerCheckEnabledPrefName();
|
||||
this.checkRemote_ = this.prefs_.getPref(checkRemotePrefName, null);
|
||||
this.checkRemote_ = this.prefs_.getPref(kPhishWardenRemoteLookups, null);
|
||||
|
||||
G_Debug(this, "Maybe toggling update checking. " +
|
||||
"Warden enabled? " + phishWardenEnabled + " || " +
|
||||
|
|
|
@ -72,8 +72,7 @@ function PROT_Reporter() {
|
|||
*/
|
||||
PROT_Reporter.prototype.report = function(subject, data) {
|
||||
// Send a report iff we're in advanced protection mode
|
||||
if (!this.prefs_.getPref(PROT_GlobalStore.getSendUserReportsPrefName(),
|
||||
false))
|
||||
if (!this.prefs_.getPref(kPhishWardenRemoteLookups, false))
|
||||
return;
|
||||
// Make sure a report url is defined
|
||||
var url = null;
|
||||
|
|
|
@ -118,11 +118,6 @@ PROT_TRFetcher.prototype.get = function(forPage, callback) {
|
|||
var url = this.getRequestURL_(forPage);
|
||||
var closure = BindToObject(this.onFetchComplete_, this, callback);
|
||||
(new PROT_XMLFetcher()).get(url, closure);
|
||||
|
||||
// Make this true if you want to dump URLs in a format we can use
|
||||
// for testing
|
||||
if (false)
|
||||
dump("\ntests[\"" + url + "\"] = \"" + forPage + "\";\n");
|
||||
};
|
||||
|
||||
/**
|
||||
|
|
Загрузка…
Ссылка в новой задаче