phishing-warden.js
Go to the documentation of this file.
1 # ***** BEGIN LICENSE BLOCK *****
2 # Version: MPL 1.1/GPL 2.0/LGPL 2.1
3 #
4 # The contents of this file are subject to the Mozilla Public License Version
5 # 1.1 (the "License"); you may not use this file except in compliance with
6 # the License. You may obtain a copy of the License at
7 # http://www.mozilla.org/MPL/
8 #
9 # Software distributed under the License is distributed on an "AS IS" basis,
10 # WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
11 # for the specific language governing rights and limitations under the
12 # License.
13 #
14 # The Original Code is Google Safe Browsing.
15 #
16 # The Initial Developer of the Original Code is Google Inc.
17 # Portions created by the Initial Developer are Copyright (C) 2006
18 # the Initial Developer. All Rights Reserved.
19 #
20 # Contributor(s):
21 # Fritz Schneider <fritz@google.com> (original author)
22 #
23 # Alternatively, the contents of this file may be used under the terms of
24 # either the GNU General Public License Version 2 or later (the "GPL"), or
25 # the GNU Lesser General Public License Version 2.1 or later (the "LGPL"),
26 # in which case the provisions of the GPL or the LGPL are applicable instead
27 # of those above. If you wish to allow use of your version of this file only
28 # under the terms of either the GPL or the LGPL, and not to allow others to
29 # use your version of this file under the terms of the MPL, indicate your
30 # decision by deleting the provisions above and replace them with the notice
31 # and other provisions required by the GPL or the LGPL. If you do not delete
32 # the provisions above, a recipient may use your version of this file under
33 # the terms of any one of the MPL, the GPL or the LGPL.
34 #
35 # ***** END LICENSE BLOCK *****
36 
37 
38 // The warden checks request to see if they are for phishy pages. It
39 // does so by querying our locally stored blacklists.
40 //
41 // When the warden notices a problem, it queries all browser views
42 // (each of which corresopnds to an open browser window) to see
43 // whether one of them can handle it. A browser view can handle a
44 // problem if its browser window has an HTMLDocument loaded with the
45 // given URL and that Document hasn't already been flagged as a
46 // problem. For every problematic URL we notice loading, at most one
47 // Document is flagged as problematic. Otherwise you can get into
48 // trouble if multiple concurrent phishy pages load with the same URL.
49 //
50 // Since we check URLs very early in the request cycle (in a progress
51 // listener), the URL might not yet be associated with a Document when
52 // we determine that it is phishy. So the the warden retries finding
53 // a browser view to handle the problem until one can, or until it
54 // determines it should give up (see complicated logic below).
55 //
56 // The warden has displayers that the browser view uses to render
57 // different kinds of warnings (e.g., one that's shown before a page
58 // loads as opposed to one that's shown after the page has already
59 // loaded).
60 //
61 // Note: There is a single warden for the whole application.
62 //
63 // TODO better way to expose displayers/views to browser view
64 
65 const kPhishWardenEnabledPref = "browser.safebrowsing.enabled";
66 
75 function PROT_PhishingWarden() {
76  PROT_ListWarden.call(this);
77 
78  this.debugZone = "phishwarden";
79 
80  // Use this to query preferences
81  this.prefs_ = new G_Preferences();
82 
83  // We need to know whether we're enabled and whether we're in advanced
84  // mode, so reflect the appropriate preferences into our state.
85 
86  // Global preference to enable the phishing warden
87  this.phishWardenEnabled_ = this.prefs_.getPref(kPhishWardenEnabledPref, null);
88 
89  // Get notifications when the phishing warden enabled pref changes
90  var phishWardenPrefObserver =
91  BindToObject(this.onPhishWardenEnabledPrefChanged, this);
92  this.prefs_.addObserver(kPhishWardenEnabledPref, phishWardenPrefObserver);
93 
94  G_Debug(this, "phishWarden initialized");
95 }
96 
98 
99 PROT_PhishingWarden.prototype.QueryInterface = function(iid) {
100  if (iid.equals(Ci.nsISupports) ||
101  iid.equals(Ci.nsISupportsWeakReference))
102  return this;
103  throw Components.results.NS_ERROR_NO_INTERFACE;
104 }
105 
109 PROT_PhishingWarden.prototype.shutdown = function() {
110  this.prefs_.removeAllObservers();
111  this.listManager_ = null;
112 }
113 
125 PROT_PhishingWarden.prototype.maybeToggleUpdateChecking = function() {
126  var phishWardenEnabled = this.prefs_.getPref(kPhishWardenEnabledPref, null);
127 
128  G_Debug(this, "Maybe toggling update checking. " +
129  "Warden enabled? " + phishWardenEnabled);
130 
131  // Do nothing unless both prefs are set. They can be null (unset), true, or
132  // false.
133  if (phishWardenEnabled === null)
134  return;
135 
136  // We update and save to disk all tables
137  if (phishWardenEnabled === true) {
138  this.enableBlacklistTableUpdates();
139  this.enableWhitelistTableUpdates();
140  } else {
141  // Anti-phishing is off, disable table updates
142  this.disableBlacklistTableUpdates();
143  this.disableWhitelistTableUpdates();
144  }
145 }
146 
154 PROT_PhishingWarden.prototype.onPhishWardenEnabledPrefChanged = function(
155  prefName) {
156  // Just to be safe, ignore changes to sub prefs.
157  if (prefName != "browser.safebrowsing.enabled")
158  return;
159 
160  this.phishWardenEnabled_ =
161  this.prefs_.getPref(prefName, this.phishWardenEnabled_);
162  this.maybeToggleUpdateChecking();
163 }
function PROT_PhishingWarden()
function PROT_ListWarden()
Definition: list-warden.js:55
return null
Definition: FeedWriter.js:1143
const Ci
const kPhishWardenEnabledPref