зеркало из https://github.com/mozilla/pjs.git
Bug 370242 - check HTTP status code to determine auth (and other) failures. r=myk
This commit is contained in:
Родитель
0c37acd02f
Коммит
1cd86360e7
|
@ -1,41 +1,42 @@
|
||||||
/* ***** BEGIN LICENSE BLOCK *****
|
# ***** BEGIN LICENSE BLOCK *****
|
||||||
* Version: MPL 1.1/GPL 2.0/LGPL 2.1
|
# Version: MPL 1.1/GPL 2.0/LGPL 2.1
|
||||||
*
|
#
|
||||||
* The contents of this file are subject to the Mozilla Public License Version
|
# 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
|
# 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
|
# the License. You may obtain a copy of the License at
|
||||||
* http://www.mozilla.org/MPL/
|
# http://www.mozilla.org/MPL/
|
||||||
*
|
#
|
||||||
* Software distributed under the License is distributed on an "AS IS" basis,
|
# Software distributed under the License is distributed on an "AS IS" basis,
|
||||||
* WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
|
# WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
|
||||||
* for the specific language governing rights and limitations under the
|
# for the specific language governing rights and limitations under the
|
||||||
* License.
|
# License.
|
||||||
*
|
#
|
||||||
* The Original Code is Microsummarizer.
|
# The Original Code is Microsummarizer.
|
||||||
*
|
#
|
||||||
* The Initial Developer of the Original Code is Mozilla.
|
# The Initial Developer of the Original Code is Mozilla.
|
||||||
* Portions created by the Initial Developer are Copyright (C) 2006
|
# Portions created by the Initial Developer are Copyright (C) 2006
|
||||||
* the Initial Developer. All Rights Reserved.
|
# the Initial Developer. All Rights Reserved.
|
||||||
*
|
#
|
||||||
* Contributor(s):
|
# Contributor(s):
|
||||||
* Myk Melez <myk@mozilla.org> (Original Author)
|
# Myk Melez <myk@mozilla.org> (Original Author)
|
||||||
* Simon Bünzli <zeniko@gmail.com>
|
# Simon Bünzli <zeniko@gmail.com>
|
||||||
* Asaf Romano <mano@mozilla.com>
|
# Asaf Romano <mano@mozilla.com>
|
||||||
* Dan Mills <thunder@mozilla.com>
|
# Dan Mills <thunder@mozilla.com>
|
||||||
*
|
# Ryan Flint <rflint@dslr.net>
|
||||||
* 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
|
# Alternatively, the contents of this file may be used under the terms of
|
||||||
* the GNU Lesser General Public License Version 2.1 or later (the "LGPL"),
|
# either the GNU General Public License Version 2 or later (the "GPL"), or
|
||||||
* in which case the provisions of the GPL or the LGPL are applicable instead
|
# the GNU Lesser General Public License Version 2.1 or later (the "LGPL"),
|
||||||
* of those above. If you wish to allow use of your version of this file only
|
# in which case the provisions of the GPL or the LGPL are applicable instead
|
||||||
* under the terms of either the GPL or the LGPL, and not to allow others to
|
# of those above. If you wish to allow use of your version of this file only
|
||||||
* use your version of this file under the terms of the MPL, indicate your
|
# under the terms of either the GPL or the LGPL, and not to allow others to
|
||||||
* decision by deleting the provisions above and replace them with the notice
|
# use your version of this file under the terms of the MPL, indicate your
|
||||||
* and other provisions required by the GPL or the LGPL. If you do not delete
|
# decision by deleting the provisions above and replace them with the notice
|
||||||
* the provisions above, a recipient may use your version of this file under
|
# and other provisions required by the GPL or the LGPL. If you do not delete
|
||||||
* the terms of any one of the MPL, the GPL or the LGPL.
|
# 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 ***** */
|
#
|
||||||
|
# ***** END LICENSE BLOCK *****
|
||||||
|
|
||||||
const Cc = Components.classes;
|
const Cc = Components.classes;
|
||||||
const Ci = Components.interfaces;
|
const Ci = Components.interfaces;
|
||||||
|
@ -1691,6 +1692,8 @@ function MicrosummaryResource(uri) {
|
||||||
this._contentType = null;
|
this._contentType = null;
|
||||||
this._isXML = false;
|
this._isXML = false;
|
||||||
this.__authFailed = false;
|
this.__authFailed = false;
|
||||||
|
this._status = null;
|
||||||
|
this._method = "GET";
|
||||||
|
|
||||||
// A function to call when we finish loading/parsing the resource.
|
// A function to call when we finish loading/parsing the resource.
|
||||||
this._loadCallback = null;
|
this._loadCallback = null;
|
||||||
|
@ -1726,6 +1729,12 @@ MicrosummaryResource.prototype = {
|
||||||
return this._isXML;
|
return this._isXML;
|
||||||
},
|
},
|
||||||
|
|
||||||
|
get status() { return this._status },
|
||||||
|
set status(aStatus) { this._status = aStatus },
|
||||||
|
|
||||||
|
get method() { return this._method },
|
||||||
|
set method(aMethod) { this._method = aMethod },
|
||||||
|
|
||||||
// Implement notification callback interfaces so we can suppress UI
|
// Implement notification callback interfaces so we can suppress UI
|
||||||
// and abort loads for bad SSL certs and HTTP authorization requests.
|
// and abort loads for bad SSL certs and HTTP authorization requests.
|
||||||
|
|
||||||
|
@ -1933,10 +1942,16 @@ MicrosummaryResource.prototype = {
|
||||||
if (this._self._loadTimer)
|
if (this._self._loadTimer)
|
||||||
this._self._loadTimer.cancel();
|
this._self._loadTimer.cancel();
|
||||||
|
|
||||||
if (this._self._authFailed) {
|
this._self.status = event.target.status;
|
||||||
|
|
||||||
|
if (this._self._authFailed || this._self.status >= 400) {
|
||||||
// Technically the request succeeded, but we treat it as a failure,
|
// Technically the request succeeded, but we treat it as a failure,
|
||||||
// since we aren't able to handle HTTP authentication.
|
// since we won't be able to extract anything relevant from the result.
|
||||||
LOG(this._self.uri.spec + " load failed; HTTP auth required");
|
|
||||||
|
// XXX For now HTTP is the only protocol we handle that might fail
|
||||||
|
// auth. This message will need to change once we support FTP, which
|
||||||
|
// returns 0 for all statuses.
|
||||||
|
LOG(this._self.uri.spec + " load failed; HTTP status: " + this._self.status);
|
||||||
try { this._self._handleError(event) }
|
try { this._self._handleError(event) }
|
||||||
finally { this._self = null }
|
finally { this._self = null }
|
||||||
}
|
}
|
||||||
|
@ -1988,7 +2003,7 @@ MicrosummaryResource.prototype = {
|
||||||
request.addEventListener("error", errorHandler, false);
|
request.addEventListener("error", errorHandler, false);
|
||||||
|
|
||||||
request = request.QueryInterface(Ci.nsIXMLHttpRequest);
|
request = request.QueryInterface(Ci.nsIXMLHttpRequest);
|
||||||
request.open("GET", this.uri.spec, true);
|
request.open(this.method, this.uri.spec, true);
|
||||||
request.setRequestHeader("X-Moz", "microsummary");
|
request.setRequestHeader("X-Moz", "microsummary");
|
||||||
|
|
||||||
// Register ourselves as a listener for notification callbacks so we
|
// Register ourselves as a listener for notification callbacks so we
|
||||||
|
|
|
@ -234,6 +234,9 @@ function (generatorURL)
|
||||||
{
|
{
|
||||||
debug("addMicrosummaryGenerator(" + generatorURL + ")");
|
debug("addMicrosummaryGenerator(" + generatorURL + ")");
|
||||||
|
|
||||||
|
if (!/^https?:/i.test(generatorURL))
|
||||||
|
return;
|
||||||
|
|
||||||
var stringBundle = srGetStrBundle("chrome://browser/locale/sidebar/sidebar.properties");
|
var stringBundle = srGetStrBundle("chrome://browser/locale/sidebar/sidebar.properties");
|
||||||
var titleMessage = stringBundle.GetStringFromName("addMicsumGenConfirmTitle");
|
var titleMessage = stringBundle.GetStringFromName("addMicsumGenConfirmTitle");
|
||||||
var dialogMessage = stringBundle.formatStringFromName("addMicsumGenConfirmText", [generatorURL], 1);
|
var dialogMessage = stringBundle.formatStringFromName("addMicsumGenConfirmText", [generatorURL], 1);
|
||||||
|
|
Загрузка…
Ссылка в новой задаче