Bug 470455 - test_database_sync_embed_visits.js leaks, r=sdwilsh
[wine-gecko.git] / browser / components / preferences / phishEULA.js
blob440abd622d7143f5149e005f318ea3a9f24310c8
1 # -*- Mode: C++; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 2 -*-
2 # ***** BEGIN LICENSE BLOCK *****
3 # Version: MPL 1.1/GPL 2.0/LGPL 2.1
5 # The contents of this file are subject to the Mozilla Public License Version
6 # 1.1 (the "License"); you may not use this file except in compliance with
7 # the License. You may obtain a copy of the License at
8 # http://www.mozilla.org/MPL/
10 # Software distributed under the License is distributed on an "AS IS" basis,
11 # WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
12 # for the specific language governing rights and limitations under the
13 # License.
15 # The Original Code is Firefox Anti-Phishing Support.
17 # The Initial Developer of the Original Code is
18 # Mozilla Corporation.
19 # Portions created by the Initial Developer are Copyright (C) 2006
20 # the Initial Developer. All Rights Reserved.
22 # Contributor(s):
23 # Jeff Walden <jwalden+code@mit.edu> (original author)
25 # Alternatively, the contents of this file may be used under the terms of
26 # either the GNU General Public License Version 2 or later (the "GPL"), or
27 # the GNU Lesser General Public License Version 2.1 or later (the "LGPL"),
28 # in which case the provisions of the GPL or the LGPL are applicable instead
29 # of those above. If you wish to allow use of your version of this file only
30 # under the terms of either the GPL or the LGPL, and not to allow others to
31 # use your version of this file under the terms of the MPL, indicate your
32 # decision by deleting the provisions above and replace them with the notice
33 # and other provisions required by the GPL or the LGPL. If you do not delete
34 # the provisions above, a recipient may use your version of this file under
35 # the terms of any one of the MPL, the GPL or the LGPL.
37 # ***** END LICENSE BLOCK *****
39 /**
40 * gPhishDialog controls the user interface for displaying the privacy policy of
41 * an anti-phishing provider.
43 * The caller (gSecurityPane._userAgreedToPhishingEULA in main.js) invokes this
44 * dialog with a single argument - a reference to an object with .providerNum
45 * and .userAgreed properties. This code displays the dialog for the provider
46 * as dictated by .providerNum and loads the policy. When that load finishes,
47 * the OK button is enabled and the user can either accept or decline the
48 * agreement (a choice which is communicated by setting .userAgreed to true if
49 * the user did indeed agree).
50 */
51 var gPhishDialog = {
52 /**
53 * The nsIWebProgress object associated with the privacy policy frame.
55 _webProgress: null,
57 /**
58 * Initializes UI and starts the privacy policy loading.
60 init: function ()
62 const Cc = Components.classes, Ci = Components.interfaces;
64 var providerNum = window.arguments[0].providerNum;
66 var phishBefore = document.getElementById("phishBefore");
68 var prefb = Cc["@mozilla.org/preferences-service;1"].
69 getService(Ci.nsIPrefService).
70 getBranch("browser.safebrowsing.provider.");
72 // init before-frame and after-frame strings
73 // note that description only wraps when the string is the element's
74 // *content* and *not* when it's the value attribute
75 var providerName = prefb.getComplexValue(providerNum + ".name", Ci.nsISupportsString).data
76 var strings = document.getElementById("bundle_phish");
77 phishBefore.textContent = strings.getFormattedString("phishBeforeText", [providerName]);
79 // guaranteed to be present, because only providers with privacy policies
80 // are displayed in the prefwindow
81 var formatter = Cc["@mozilla.org/toolkit/URLFormatterService;1"].
82 getService(Ci.nsIURLFormatter);
83 var privacyURL = formatter.formatURLPref("browser.safebrowsing.provider." +
84 providerNum +
85 ".privacy.url",
86 null);
87 var fallbackURL = formatter.formatURLPref("browser.safebrowsing.provider." +
88 providerNum +
89 ".privacy.fallbackurl",
90 null);
91 this._progressListener._providerFallbackURL = fallbackURL;
93 // add progress listener to enable OK, radios when page loads
94 var frame = document.getElementById("phishPolicyFrame");
95 var docShell = frame.docShell;
97 // disable unnecessary features
98 docShell.allowAuth = false;
99 docShell.allowPlugins = false;
100 docShell.allowSubframes = false;
102 var webProgress = docShell.QueryInterface(Ci.nsIInterfaceRequestor)
103 .getInterface(Ci.nsIWebProgress);
104 webProgress.addProgressListener(this._progressListener,
105 Ci.nsIWebProgress.NOTIFY_STATE_WINDOW);
107 this._webProgress = webProgress; // for easy use later
109 // start loading the privacyURL
110 const loadFlags = Ci.nsIWebNavigation.LOAD_FLAGS_NONE;
111 frame.webNavigation.loadURI(privacyURL, loadFlags, null, null, null);
115 * The nsIWebProgressListener used to watch the status of the load of the
116 * privacy policy; enables the OK button when the load completes.
118 _progressListener:
121 * First we try to load the provider url (possibly remote). If that fails
122 * to load, we try to load the provider fallback url (must be chrome://).
123 * If that also fails, we display an error message.
125 _providerLoadFailed: false,
126 _providerFallbackLoadFailed: false,
128 _tryLoad: function(url) {
129 const Ci = Components.interfaces;
130 const loadFlags = Ci.nsIWebNavigation.LOAD_FLAGS_NONE;
131 var frame = document.getElementById("phishPolicyFrame");
132 frame.webNavigation.loadURI(url, loadFlags, null, null, null);
135 onStateChange: function (aWebProgress, aRequest, aStateFlags, aStatus)
137 // enable the OK button when the request completes
138 const Ci = Components.interfaces, Cr = Components.results;
139 if ((aStateFlags & Ci.nsIWebProgressListener.STATE_STOP) &&
140 (aStateFlags & Ci.nsIWebProgressListener.STATE_IS_WINDOW)) {
142 if (Components.isSuccessCode(aRequest.status)) {
143 try {
144 aRequest.QueryInterface(Ci.nsIHttpChannel);
145 } catch (e) {
146 // Not an http request url (might be, e.g., chrome:) that loaded
147 // successfully, so we can exit.
148 return;
151 // Any response other than 200 OK is an error.
152 if (200 == aRequest.responseStatus)
153 return;
156 // Something failed
157 if (!this._providerLoadFailed) {
158 this._provderLoadFailed = true;
159 // Remote EULA failed to load; try loading provider fallback
160 this._tryLoad(this._providerFallbackURL);
161 } else if (!this._providerFallbackLoadFailed) {
162 // Provider fallback failed to load; try loading fallback EULA
163 this._providerFallbackLoadFailed = true;
165 // fire off a load of the fallback policy
166 const fallbackURL = "chrome://browser/content/preferences/fallbackEULA.xhtml";
167 this._tryLoad(fallbackURL);
169 // disable radios
170 document.getElementById("acceptOrDecline").disabled = true;
171 } else {
172 throw "Fallback policy failed to load -- what the hay!?!";
177 onProgressChange: function(aWebProgress, aRequest, aCurSelfProgress,
178 aMaxSelfProgress, aCurTotalProgress,
179 aMaxTotalProgress)
183 onStatusChange : function(aWebProgress, aRequest, aStatus, aMessage)
187 QueryInterface : function(aIID)
189 const Ci = Components.interfaces;
190 if (aIID.equals(Ci.nsIWebProgressListener) ||
191 aIID.equals(Ci.nsISupportsWeakReference) ||
192 aIID.equals(Ci.nsISupports))
193 return this;
194 throw Components.results.NS_NOINTERFACE;
199 * Signals that the user accepted the privacy policy by setting the window
200 * arguments appropriately. Note that this does *not* change preferences;
201 * the opener of this dialog handles that.
203 accept: function ()
205 window.arguments[0].userAgreed = true;
209 * Clean up any XPCOM-JS cycles we may have created.
211 uninit: function ()
213 // overly aggressive, but better safe than sorry
214 this._webProgress.removeProgressListener(this._progressListener);
215 this._progressListener = this._webProgress = null;
219 * Called when the user changes the agree/disagree radio.
221 onchangeRadio: function ()
223 var radio = document.getElementById("acceptOrDecline");
224 document.documentElement.getButton("accept").disabled = (radio.value == "false");