2008-11-03 14:36:29 -08:00
|
|
|
/* ***** BEGIN LICENSE BLOCK *****
|
|
|
|
* Version: MPL 1.1/GPL 2.0/LGPL 2.1
|
|
|
|
*
|
|
|
|
* The contents of this file are subject to the Mozilla Public License Version
|
|
|
|
* 1.1 (the "License"); you may not use this file except in compliance with
|
|
|
|
* the License. You may obtain a copy of the License at
|
|
|
|
* http://www.mozilla.org/MPL/
|
|
|
|
*
|
|
|
|
* Software distributed under the License is distributed on an "AS IS" basis,
|
|
|
|
* WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
|
|
|
|
* for the specific language governing rights and limitations under the
|
|
|
|
* License.
|
|
|
|
*
|
|
|
|
* The Original Code is Bookmarks Sync.
|
|
|
|
*
|
|
|
|
* The Initial Developer of the Original Code is Mozilla.
|
|
|
|
* Portions created by the Initial Developer are Copyright (C) 2007
|
|
|
|
* the Initial Developer. All Rights Reserved.
|
|
|
|
*
|
|
|
|
* Contributor(s):
|
|
|
|
* Dan Mills <thunder@mozilla.com>
|
2008-12-18 15:42:12 -08:00
|
|
|
* Anant Narayanan <anant@kix.in>
|
2008-11-03 14:36:29 -08:00
|
|
|
*
|
|
|
|
* Alternatively, the contents of this file may be used under the terms of
|
|
|
|
* either the GNU General Public License Version 2 or later (the "GPL"), or
|
|
|
|
* the GNU Lesser General Public License Version 2.1 or later (the "LGPL"),
|
|
|
|
* in which case the provisions of the GPL or the LGPL are applicable instead
|
|
|
|
* of those above. If you wish to allow use of your version of this file only
|
|
|
|
* under the terms of either the GPL or the LGPL, and not to allow others to
|
|
|
|
* use your version of this file under the terms of the MPL, indicate your
|
|
|
|
* decision by deleting the provisions above and replace them with the notice
|
|
|
|
* and other provisions required by the GPL or the LGPL. If you do not delete
|
|
|
|
* the provisions above, a recipient may use your version of this file under
|
|
|
|
* the terms of any one of the MPL, the GPL or the LGPL.
|
|
|
|
*
|
|
|
|
* ***** END LICENSE BLOCK ***** */
|
|
|
|
|
2009-09-10 11:05:13 -07:00
|
|
|
const EXPORTED_SYMBOLS = ["Resource"];
|
2008-11-03 14:36:29 -08:00
|
|
|
|
|
|
|
const Cc = Components.classes;
|
|
|
|
const Ci = Components.interfaces;
|
|
|
|
const Cr = Components.results;
|
|
|
|
const Cu = Components.utils;
|
|
|
|
|
2010-06-16 14:30:08 -07:00
|
|
|
Cu.import("resource://services-sync/auth.js");
|
|
|
|
Cu.import("resource://services-sync/constants.js");
|
|
|
|
Cu.import("resource://services-sync/ext/Observers.js");
|
|
|
|
Cu.import("resource://services-sync/ext/Preferences.js");
|
|
|
|
Cu.import("resource://services-sync/ext/Sync.js");
|
|
|
|
Cu.import("resource://services-sync/log4moz.js");
|
|
|
|
Cu.import("resource://services-sync/util.js");
|
2008-11-03 14:36:29 -08:00
|
|
|
|
2009-06-25 16:13:52 -07:00
|
|
|
// = Resource =
|
|
|
|
//
|
|
|
|
// Represents a remote network resource, identified by a URI.
|
2009-01-06 13:54:18 -08:00
|
|
|
function Resource(uri) {
|
2010-02-11 15:25:31 -08:00
|
|
|
this._log = Log4Moz.repository.getLogger(this._logName);
|
|
|
|
this._log.level =
|
|
|
|
Log4Moz.Level[Utils.prefs.getCharPref("log.logger.network.resources")];
|
|
|
|
this.uri = uri;
|
2010-06-01 15:15:53 -07:00
|
|
|
this._headers = {};
|
2008-11-03 14:36:29 -08:00
|
|
|
}
|
|
|
|
Resource.prototype = {
|
|
|
|
_logName: "Net.Resource",
|
|
|
|
|
2010-06-01 15:15:53 -07:00
|
|
|
// ** {{{ Resource.serverTime }}} **
|
|
|
|
//
|
|
|
|
// Caches the latest server timestamp (X-Weave-Timestamp header).
|
|
|
|
serverTime: null,
|
|
|
|
|
2009-06-25 16:13:52 -07:00
|
|
|
// ** {{{ Resource.authenticator }}} **
|
|
|
|
//
|
|
|
|
// Getter and setter for the authenticator module
|
|
|
|
// responsible for this particular resource. The authenticator
|
|
|
|
// module may modify the headers to perform authentication
|
|
|
|
// while performing a request for the resource, for example.
|
2008-11-03 14:36:29 -08:00
|
|
|
get authenticator() {
|
|
|
|
if (this._authenticator)
|
|
|
|
return this._authenticator;
|
|
|
|
else
|
|
|
|
return Auth.lookupAuthenticator(this.spec);
|
|
|
|
},
|
|
|
|
set authenticator(value) {
|
|
|
|
this._authenticator = value;
|
|
|
|
},
|
|
|
|
|
2009-06-25 16:13:52 -07:00
|
|
|
// ** {{{ Resource.headers }}} **
|
|
|
|
//
|
2010-06-01 15:15:53 -07:00
|
|
|
// Headers to be included when making a request for the resource.
|
|
|
|
// Note: Header names should be all lower case, there's no explicit
|
|
|
|
// check for duplicates due to case!
|
2008-11-03 14:36:29 -08:00
|
|
|
get headers() {
|
|
|
|
return this.authenticator.onRequest(this._headers);
|
|
|
|
},
|
|
|
|
set headers(value) {
|
|
|
|
this._headers = value;
|
|
|
|
},
|
2009-03-25 19:30:16 -07:00
|
|
|
setHeader: function Res_setHeader() {
|
|
|
|
if (arguments.length % 2)
|
|
|
|
throw "setHeader only accepts arguments in multiples of 2";
|
|
|
|
for (let i = 0; i < arguments.length; i += 2) {
|
2010-06-01 15:15:53 -07:00
|
|
|
this._headers[arguments[i].toLowerCase()] = arguments[i + 1];
|
2009-03-25 19:30:16 -07:00
|
|
|
}
|
|
|
|
},
|
2008-11-03 14:36:29 -08:00
|
|
|
|
2009-06-25 16:13:52 -07:00
|
|
|
// ** {{{ Resource.uri }}} **
|
|
|
|
//
|
|
|
|
// URI representing this resource.
|
2008-11-03 14:36:29 -08:00
|
|
|
get uri() {
|
|
|
|
return this._uri;
|
|
|
|
},
|
|
|
|
set uri(value) {
|
2008-11-08 02:00:33 -08:00
|
|
|
if (typeof value == 'string')
|
|
|
|
this._uri = Utils.makeURI(value);
|
|
|
|
else
|
|
|
|
this._uri = value;
|
2008-11-03 14:36:29 -08:00
|
|
|
},
|
|
|
|
|
2009-06-25 16:13:52 -07:00
|
|
|
// ** {{{ Resource.spec }}} **
|
|
|
|
//
|
|
|
|
// Get the string representation of the URI.
|
2008-11-03 14:36:29 -08:00
|
|
|
get spec() {
|
2008-11-08 02:00:33 -08:00
|
|
|
if (this._uri)
|
|
|
|
return this._uri.spec;
|
|
|
|
return null;
|
2008-11-03 14:36:29 -08:00
|
|
|
},
|
|
|
|
|
2009-06-25 16:13:52 -07:00
|
|
|
// ** {{{ Resource.data }}} **
|
|
|
|
//
|
|
|
|
// Get and set the data encapulated in the resource.
|
2008-11-06 23:23:35 -08:00
|
|
|
_data: null,
|
|
|
|
get data() this._data,
|
2008-11-03 14:36:29 -08:00
|
|
|
set data(value) {
|
|
|
|
this._data = value;
|
|
|
|
},
|
|
|
|
|
2009-06-25 16:13:52 -07:00
|
|
|
// ** {{{ Resource._createRequest }}} **
|
|
|
|
//
|
|
|
|
// This method returns a new IO Channel for requests to be made
|
|
|
|
// through. It is never called directly, only {{{_request}}} uses it
|
|
|
|
// to obtain a request channel.
|
|
|
|
//
|
2008-12-18 15:42:12 -08:00
|
|
|
_createRequest: function Res__createRequest() {
|
2009-08-26 15:32:46 -07:00
|
|
|
let channel = Svc.IO.newChannel(this.spec, null, null).
|
|
|
|
QueryInterface(Ci.nsIRequest).QueryInterface(Ci.nsIHttpChannel);
|
2009-06-25 16:13:52 -07:00
|
|
|
|
2009-02-27 18:28:26 -08:00
|
|
|
// Always validate the cache:
|
2009-08-26 15:32:46 -07:00
|
|
|
channel.loadFlags |= Ci.nsIRequest.LOAD_BYPASS_CACHE;
|
|
|
|
channel.loadFlags |= Ci.nsIRequest.INHIBIT_CACHING;
|
2009-11-20 14:34:20 -08:00
|
|
|
|
2009-06-25 16:13:52 -07:00
|
|
|
// Setup a callback to handle bad HTTPS certificates.
|
2010-06-01 15:15:53 -07:00
|
|
|
channel.notificationCallbacks = new BadCertListener();
|
2009-11-20 14:34:20 -08:00
|
|
|
|
2009-06-25 16:13:52 -07:00
|
|
|
// Avoid calling the authorizer more than once
|
2009-11-20 14:34:20 -08:00
|
|
|
let headers = this.headers;
|
2008-11-03 14:36:29 -08:00
|
|
|
for (let key in headers) {
|
|
|
|
if (key == 'Authorization')
|
|
|
|
this._log.trace("HTTP Header " + key + ": ***** (suppressed)");
|
|
|
|
else
|
|
|
|
this._log.trace("HTTP Header " + key + ": " + headers[key]);
|
2009-08-26 15:32:46 -07:00
|
|
|
channel.setRequestHeader(key, headers[key], false);
|
2008-11-03 14:36:29 -08:00
|
|
|
}
|
2009-08-26 15:32:46 -07:00
|
|
|
return channel;
|
2008-11-03 14:36:29 -08:00
|
|
|
},
|
|
|
|
|
2009-07-22 16:38:34 -07:00
|
|
|
_onProgress: function Res__onProgress(channel) {},
|
2008-11-03 14:36:29 -08:00
|
|
|
|
2009-06-25 16:13:52 -07:00
|
|
|
// ** {{{ Resource._request }}} **
|
|
|
|
//
|
|
|
|
// Perform a particular HTTP request on the resource. This method
|
2009-11-20 14:34:20 -08:00
|
|
|
// is never called directly, but is used by the high-level
|
2009-06-25 16:13:52 -07:00
|
|
|
// {{{get}}}, {{{put}}}, {{{post}}} and {{delete}} methods.
|
2008-11-03 14:36:29 -08:00
|
|
|
_request: function Res__request(action, data) {
|
|
|
|
let iter = 0;
|
2008-12-18 15:42:12 -08:00
|
|
|
let channel = this._createRequest();
|
2009-01-22 11:48:36 -08:00
|
|
|
|
2008-11-19 16:19:51 -08:00
|
|
|
if ("undefined" != typeof(data))
|
|
|
|
this._data = data;
|
|
|
|
|
2009-11-20 14:34:20 -08:00
|
|
|
// PUT and POST are trreated differently because
|
2009-06-25 16:13:52 -07:00
|
|
|
// they have payload data.
|
2008-11-19 16:19:51 -08:00
|
|
|
if ("PUT" == action || "POST" == action) {
|
2009-09-10 11:05:13 -07:00
|
|
|
// Convert non-string bodies into JSON
|
|
|
|
if (this._data.constructor.toString() != String)
|
|
|
|
this._data = JSON.stringify(this._data);
|
|
|
|
|
2009-07-14 13:59:46 -07:00
|
|
|
this._log.debug(action + " Length: " + this._data.length);
|
2009-07-09 17:44:41 -07:00
|
|
|
this._log.trace(action + " Body: " + this._data);
|
2009-01-22 11:48:36 -08:00
|
|
|
|
2010-06-01 15:15:53 -07:00
|
|
|
let type = ('content-type' in this._headers) ?
|
|
|
|
this._headers['content-type'] : 'text/plain';
|
2009-03-25 19:30:16 -07:00
|
|
|
|
2009-01-27 13:35:10 -08:00
|
|
|
let stream = Cc["@mozilla.org/io/string-input-stream;1"].
|
2008-12-18 15:42:12 -08:00
|
|
|
createInstance(Ci.nsIStringInputStream);
|
2009-01-27 13:35:10 -08:00
|
|
|
stream.setData(this._data, this._data.length);
|
2008-11-03 14:36:29 -08:00
|
|
|
|
2009-01-27 13:35:10 -08:00
|
|
|
channel.QueryInterface(Ci.nsIUploadChannel);
|
2009-03-25 19:30:16 -07:00
|
|
|
channel.setUploadStream(stream, type, this._data.length);
|
2008-12-18 15:42:12 -08:00
|
|
|
}
|
2008-11-03 14:36:29 -08:00
|
|
|
|
2009-06-25 16:13:52 -07:00
|
|
|
// Setup a channel listener so that the actual network operation
|
|
|
|
// is performed asynchronously.
|
2009-06-04 10:14:54 -07:00
|
|
|
let [chanOpen, chanCb] = Sync.withCb(channel.asyncOpen, channel);
|
|
|
|
let listener = new ChannelListener(chanCb, this._onProgress, this._log);
|
2008-12-18 15:42:12 -08:00
|
|
|
channel.requestMethod = action;
|
2009-08-12 20:28:46 -07:00
|
|
|
|
|
|
|
// The channel listener might get a failure code
|
|
|
|
try {
|
|
|
|
this._data = chanOpen(listener, null);
|
|
|
|
}
|
|
|
|
catch(ex) {
|
|
|
|
// Combine the channel stack with this request stack
|
|
|
|
let error = Error(ex.message);
|
2010-04-01 15:25:47 -07:00
|
|
|
let chanStack = [];
|
|
|
|
if (ex.stack)
|
|
|
|
chanStack = ex.stack.trim().split(/\n/).slice(1);
|
2009-08-12 20:28:46 -07:00
|
|
|
let requestStack = error.stack.split(/\n/).slice(1);
|
|
|
|
|
|
|
|
// Strip out the args for the last 2 frames because they're usually HUGE!
|
|
|
|
for (let i = 0; i <= 1; i++)
|
|
|
|
requestStack[i] = requestStack[i].replace(/\(".*"\)@/, "(...)@");
|
|
|
|
|
|
|
|
error.stack = chanStack.concat(requestStack).join("\n");
|
|
|
|
throw error;
|
|
|
|
}
|
2008-12-18 15:42:12 -08:00
|
|
|
|
2009-08-26 15:32:46 -07:00
|
|
|
// Set some default values in-case there's no response header
|
|
|
|
let headers = {};
|
|
|
|
let status = 0;
|
|
|
|
let success = true;
|
|
|
|
try {
|
|
|
|
// Read out the response headers if available
|
|
|
|
channel.visitResponseHeaders({
|
|
|
|
visitHeader: function visitHeader(header, value) {
|
2010-06-01 15:15:53 -07:00
|
|
|
headers[header.toLowerCase()] = value;
|
2009-08-26 15:32:46 -07:00
|
|
|
}
|
|
|
|
});
|
|
|
|
status = channel.responseStatus;
|
|
|
|
success = channel.requestSucceeded;
|
|
|
|
|
2009-12-17 18:51:55 -08:00
|
|
|
// Log the status of the request
|
|
|
|
let mesg = [action, success ? "success" : "fail", status,
|
|
|
|
channel.URI.spec].join(" ");
|
|
|
|
if (mesg.length > 200)
|
|
|
|
mesg = mesg.substr(0, 200) + "…";
|
|
|
|
this._log.debug(mesg);
|
|
|
|
// Additionally give the full response body when Trace logging
|
|
|
|
if (this._log.level <= Log4Moz.Level.Trace)
|
|
|
|
this._log.trace(action + " body: " + this._data);
|
2009-09-15 18:38:52 -07:00
|
|
|
|
|
|
|
// this is a server-side safety valve to allow slowing down clients without hurting performance
|
2010-06-01 15:15:53 -07:00
|
|
|
if (headers["x-weave-backoff"])
|
|
|
|
Observers.notify("weave:service:backoff:interval", parseInt(headers["x-weave-backoff"], 10))
|
2009-08-26 15:32:46 -07:00
|
|
|
}
|
|
|
|
// Got a response but no header; must be cached (use default values)
|
|
|
|
catch(ex) {
|
|
|
|
this._log.debug(action + " cached: " + status);
|
2008-11-03 14:36:29 -08:00
|
|
|
}
|
2009-01-22 11:48:36 -08:00
|
|
|
|
2009-08-26 15:32:46 -07:00
|
|
|
let ret = new String(this._data);
|
|
|
|
ret.headers = headers;
|
|
|
|
ret.status = status;
|
|
|
|
ret.success = success;
|
2009-09-10 11:04:36 -07:00
|
|
|
|
|
|
|
// Make a lazy getter to convert the json response into an object
|
|
|
|
Utils.lazy2(ret, "obj", function() JSON.parse(ret));
|
|
|
|
|
2010-06-03 18:37:07 -07:00
|
|
|
// Notify if we get a 401 to maybe try again with a new uri
|
|
|
|
if (status == 401) {
|
|
|
|
// Create an object to allow observers to decide if we should try again
|
|
|
|
let subject = {
|
|
|
|
newUri: "",
|
|
|
|
resource: this,
|
|
|
|
response: ret
|
|
|
|
}
|
|
|
|
Observers.notify("weave:resource:status:401", subject);
|
|
|
|
|
|
|
|
// Do the same type of request but with the new uri
|
|
|
|
if (subject.newUri != "") {
|
|
|
|
this.uri = subject.newUri;
|
|
|
|
return this._request.apply(this, arguments);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2009-08-26 15:32:46 -07:00
|
|
|
return ret;
|
2008-11-03 14:36:29 -08:00
|
|
|
},
|
|
|
|
|
2009-06-25 16:13:52 -07:00
|
|
|
// ** {{{ Resource.get }}} **
|
|
|
|
//
|
|
|
|
// Perform an asynchronous HTTP GET for this resource.
|
|
|
|
// onComplete will be called on completion of the request.
|
2009-06-04 10:16:07 -07:00
|
|
|
get: function Res_get() {
|
|
|
|
return this._request("GET");
|
2008-11-03 14:36:29 -08:00
|
|
|
},
|
|
|
|
|
2009-06-25 16:13:52 -07:00
|
|
|
// ** {{{ Resource.get }}} **
|
|
|
|
//
|
|
|
|
// Perform a HTTP PUT for this resource.
|
2009-06-04 10:16:07 -07:00
|
|
|
put: function Res_put(data) {
|
|
|
|
return this._request("PUT", data);
|
2008-11-03 14:36:29 -08:00
|
|
|
},
|
|
|
|
|
2009-06-25 16:13:52 -07:00
|
|
|
// ** {{{ Resource.post }}} **
|
|
|
|
//
|
|
|
|
// Perform a HTTP POST for this resource.
|
2009-06-04 10:16:07 -07:00
|
|
|
post: function Res_post(data) {
|
|
|
|
return this._request("POST", data);
|
2008-11-19 16:19:51 -08:00
|
|
|
},
|
|
|
|
|
2009-06-25 16:13:52 -07:00
|
|
|
// ** {{{ Resource.delete }}} **
|
|
|
|
//
|
|
|
|
// Perform a HTTP DELETE for this resource.
|
2009-06-04 10:16:07 -07:00
|
|
|
delete: function Res_delete() {
|
|
|
|
return this._request("DELETE");
|
2008-11-03 14:36:29 -08:00
|
|
|
}
|
|
|
|
};
|
|
|
|
|
2009-06-25 16:13:52 -07:00
|
|
|
// = ChannelListener =
|
2009-11-20 14:34:20 -08:00
|
|
|
//
|
2009-06-25 16:13:52 -07:00
|
|
|
// This object implements the {{{nsIStreamListener}}} interface
|
|
|
|
// and is called as the network operation proceeds.
|
2008-12-18 15:42:12 -08:00
|
|
|
function ChannelListener(onComplete, onProgress, logger) {
|
|
|
|
this._onComplete = onComplete;
|
|
|
|
this._onProgress = onProgress;
|
|
|
|
this._log = logger;
|
2010-04-21 11:10:21 -07:00
|
|
|
this.delayAbort();
|
2008-12-18 15:42:12 -08:00
|
|
|
}
|
|
|
|
ChannelListener.prototype = {
|
2010-04-01 15:25:47 -07:00
|
|
|
// Wait 5 minutes before killing a request
|
|
|
|
ABORT_TIMEOUT: 300000,
|
|
|
|
|
2008-12-18 15:42:12 -08:00
|
|
|
onStartRequest: function Channel_onStartRequest(channel) {
|
2009-03-10 04:30:30 -07:00
|
|
|
channel.QueryInterface(Ci.nsIHttpChannel);
|
2010-04-01 15:54:53 -07:00
|
|
|
|
|
|
|
// Save the latest server timestamp when possible
|
|
|
|
try {
|
|
|
|
Resource.serverTime = channel.getResponseHeader("X-Weave-Timestamp") - 0;
|
|
|
|
}
|
|
|
|
catch(ex) {}
|
|
|
|
|
2009-12-17 18:51:55 -08:00
|
|
|
this._log.trace(channel.requestMethod + " " + channel.URI.spec);
|
2008-12-18 15:42:12 -08:00
|
|
|
this._data = '';
|
2010-04-21 11:10:21 -07:00
|
|
|
this.delayAbort();
|
2008-12-18 15:42:12 -08:00
|
|
|
},
|
|
|
|
|
2009-08-12 20:28:46 -07:00
|
|
|
onStopRequest: function Channel_onStopRequest(channel, context, status) {
|
2010-04-01 15:25:47 -07:00
|
|
|
// Clear the abort timer now that the channel is done
|
|
|
|
this.abortTimer.clear();
|
|
|
|
|
2008-12-18 15:42:12 -08:00
|
|
|
if (this._data == '')
|
|
|
|
this._data = null;
|
|
|
|
|
2009-08-12 20:28:46 -07:00
|
|
|
// Throw the failure code name (and stop execution)
|
|
|
|
if (!Components.isSuccessCode(status))
|
|
|
|
this._onComplete.throw(Error(Components.Exception("", status).name));
|
|
|
|
|
2008-12-18 15:42:12 -08:00
|
|
|
this._onComplete(this._data);
|
|
|
|
},
|
|
|
|
|
|
|
|
onDataAvailable: function Channel_onDataAvail(req, cb, stream, off, count) {
|
|
|
|
let siStream = Cc["@mozilla.org/scriptableinputstream;1"].
|
|
|
|
createInstance(Ci.nsIScriptableInputStream);
|
|
|
|
siStream.init(stream);
|
|
|
|
|
|
|
|
this._data += siStream.read(count);
|
2009-07-22 16:38:34 -07:00
|
|
|
this._onProgress();
|
2010-04-21 11:10:21 -07:00
|
|
|
this.delayAbort();
|
|
|
|
},
|
2010-04-01 15:25:47 -07:00
|
|
|
|
2010-04-21 11:10:21 -07:00
|
|
|
/**
|
|
|
|
* Create or push back the abort timer that kills this request
|
|
|
|
*/
|
|
|
|
delayAbort: function delayAbort() {
|
2010-04-01 15:25:47 -07:00
|
|
|
Utils.delay(this.abortRequest, this.ABORT_TIMEOUT, this, "abortTimer");
|
|
|
|
},
|
|
|
|
|
|
|
|
abortRequest: function abortRequest() {
|
|
|
|
// Ignore any callbacks if we happen to get any now
|
|
|
|
this.onStopRequest = function() {};
|
|
|
|
this.onDataAvailable = function() {};
|
|
|
|
this._onComplete.throw(Error("Aborting due to channel inactivity."));
|
2009-01-07 21:29:55 -08:00
|
|
|
}
|
|
|
|
};
|
|
|
|
|
2010-06-01 15:15:53 -07:00
|
|
|
// = BadCertListener =
|
2009-06-25 16:13:52 -07:00
|
|
|
//
|
|
|
|
// We use this listener to ignore bad HTTPS
|
|
|
|
// certificates and continue a request on a network
|
|
|
|
// channel. Probably not a very smart thing to do,
|
|
|
|
// but greatly simplifies debugging and is just very
|
|
|
|
// convenient.
|
2010-06-01 15:15:53 -07:00
|
|
|
function BadCertListener() {
|
2009-02-11 09:11:18 -08:00
|
|
|
}
|
2010-06-01 15:15:53 -07:00
|
|
|
BadCertListener.prototype = {
|
2009-02-11 09:11:18 -08:00
|
|
|
getInterface: function(aIID) {
|
|
|
|
return this.QueryInterface(aIID);
|
|
|
|
},
|
2009-02-20 01:50:26 -08:00
|
|
|
|
2009-02-11 09:11:18 -08:00
|
|
|
QueryInterface: function(aIID) {
|
|
|
|
if (aIID.equals(Components.interfaces.nsIBadCertListener2) ||
|
|
|
|
aIID.equals(Components.interfaces.nsIInterfaceRequestor) ||
|
|
|
|
aIID.equals(Components.interfaces.nsISupports))
|
|
|
|
return this;
|
2009-02-20 01:50:26 -08:00
|
|
|
|
2009-02-11 09:11:18 -08:00
|
|
|
throw Components.results.NS_ERROR_NO_INTERFACE;
|
|
|
|
},
|
2009-02-20 01:50:26 -08:00
|
|
|
|
2009-02-11 09:11:18 -08:00
|
|
|
notifyCertProblem: function certProblem(socketInfo, sslStatus, targetHost) {
|
|
|
|
// Silently ignore?
|
|
|
|
let log = Log4Moz.repository.getLogger("Service.CertListener");
|
|
|
|
log.level =
|
|
|
|
Log4Moz.Level[Utils.prefs.getCharPref("log.logger.network.resources")];
|
|
|
|
log.debug("Invalid HTTPS certificate encountered, ignoring!");
|
|
|
|
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
};
|