зеркало из https://github.com/mozilla/snowl.git
implement nsIAuthPrompt2::asyncPromptAuth so Namoroka nightly buids don't throw exceptions about its non-implementation to the error console
This commit is contained in:
Родитель
1d12770ec4
Коммит
f34868d57c
|
@ -0,0 +1,97 @@
|
|||
/* ***** 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 Snowl.
|
||||
*
|
||||
* The Initial Developer of the Original Code is Mozilla.
|
||||
* Portions created by the Initial Developer are Copyright (C) 2008
|
||||
* the Initial Developer. All Rights Reserved.
|
||||
*
|
||||
* Contributor(s):
|
||||
* Myk Melez <myk@mozilla.org>
|
||||
*
|
||||
* 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 ***** */
|
||||
|
||||
const Cc = Components.classes;
|
||||
const Ci = Components.interfaces;
|
||||
const Cr = Components.results;
|
||||
const Cu = Components.utils;
|
||||
|
||||
let source = window.arguments[0].wrappedJSObject;
|
||||
let authInfo = window.arguments[1].QueryInterface(Ci.nsIAuthInformation);
|
||||
let okCallback = window.arguments[2].wrappedJSObject;
|
||||
let cancelCallback = window.arguments[3].wrappedJSObject;
|
||||
|
||||
function doOnLoad() {
|
||||
let stringBundle = document.getElementById("snowlStringBundle");
|
||||
|
||||
let prompt;
|
||||
let sourceURL = (source.humanURI || source.machineURI).spec;
|
||||
if (source.name)
|
||||
prompt = stringBundle.getFormattedString("namedSourcePrompt", [source.name, sourceURL]);
|
||||
else
|
||||
prompt = stringBundle.getFormattedString("namelessSourcePrompt", [sourceURL]);
|
||||
document.getElementById("prompt").appendChild(document.createTextNode(prompt));
|
||||
|
||||
document.getElementById("realm").value = authInfo.realm;
|
||||
|
||||
document.getElementById("username").value = source.username || authInfo.username;
|
||||
document.getElementById("password").value = authInfo.password;
|
||||
|
||||
if (source.username) {
|
||||
document.getElementById("username").readOnly = true;
|
||||
document.getElementById("password").focus();
|
||||
}
|
||||
|
||||
// FIXME: handle authInfo.flags (i.e. don't prompt for username if it's
|
||||
// already available, and prompt for domain if necessary).
|
||||
}
|
||||
|
||||
function doShowPassword() {
|
||||
if (document.getElementById("showPassword").checked)
|
||||
document.getElementById("password").removeAttribute("type");
|
||||
else
|
||||
document.getElementById("password").setAttribute("type", "password");
|
||||
}
|
||||
|
||||
function doOK() {
|
||||
// FIXME: validate input.
|
||||
let remember = document.getElementById("rememberPassword").checked;
|
||||
authInfo.username = document.getElementById("username").value;
|
||||
authInfo.password = document.getElementById("password").value;
|
||||
try {
|
||||
okCallback(remember);
|
||||
}
|
||||
catch(ex) {}
|
||||
return true;
|
||||
}
|
||||
|
||||
function doCancel() {
|
||||
try {
|
||||
cancelCallback(true);
|
||||
}
|
||||
catch(ex) {}
|
||||
return true;
|
||||
}
|
|
@ -0,0 +1,98 @@
|
|||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
|
||||
<!-- ***** 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 Snowl.
|
||||
-
|
||||
- The Initial Developer of the Original Code is Mozilla.
|
||||
- Portions created by the Initial Developer are Copyright (C) 2008
|
||||
- the Initial Developer. All Rights Reserved.
|
||||
-
|
||||
- Contributor(s):
|
||||
- Myk Melez <myk@mozilla.org>
|
||||
-
|
||||
- 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 ***** -->
|
||||
|
||||
<?xml-stylesheet href="chrome://global/skin/" type="text/css"?>
|
||||
|
||||
<!DOCTYPE dialog SYSTEM "chrome://snowl/locale/login.dtd">
|
||||
|
||||
<dialog title="&dialog.title;"
|
||||
xmlns="http://www.mozilla.org/keymaster/gatekeeper/there.is.only.xul"
|
||||
onload="doOnLoad()"
|
||||
ondialogaccept="return doOK()"
|
||||
ondialogcancel="return doCancel()">
|
||||
|
||||
<script type="application/javascript" src="chrome://snowl/content/login-async.js"/>
|
||||
|
||||
<stringbundleset id="stringbundleset">
|
||||
<stringbundle id="snowlStringBundle" src="chrome://snowl/locale/login.properties"/>
|
||||
</stringbundleset>
|
||||
|
||||
<hbox flex="1">
|
||||
<image class="spaced authentication-icon question-icon"/>
|
||||
<description id="prompt" flex="1" style="width: 0;"/>
|
||||
<image src="chrome://snowl/content/icons/snowl-40.jpg"/>
|
||||
</hbox>
|
||||
|
||||
<grid>
|
||||
<columns>
|
||||
<column/>
|
||||
<column/>
|
||||
</columns>
|
||||
<rows>
|
||||
<row align="center">
|
||||
<hbox flex="1" pack="end">
|
||||
<label value="&realm.label;"/>
|
||||
</hbox>
|
||||
<description id="realm" flex="1" crop="end"/>
|
||||
</row>
|
||||
<row align="center">
|
||||
<hbox flex="1" pack="end">
|
||||
<label value="&username.label;" control="username"/>
|
||||
</hbox>
|
||||
<textbox id="username"/>
|
||||
</row>
|
||||
<row align="center">
|
||||
<hbox flex="1" pack="end">
|
||||
<label value="&password.label;" control="password"/>
|
||||
</hbox>
|
||||
<textbox id="password" type="password"/>
|
||||
</row>
|
||||
<row align="center">
|
||||
<box/>
|
||||
<checkbox id="showPassword" label="&showPassword.label;"
|
||||
oncommand="doShowPassword()"/>
|
||||
</row>
|
||||
<row align="center">
|
||||
<box/>
|
||||
<checkbox id="rememberPassword" label="&rememberPassword.label;"/>
|
||||
</row>
|
||||
</rows>
|
||||
</grid>
|
||||
|
||||
|
||||
</dialog>
|
|
@ -182,8 +182,76 @@ SnowlFeed.prototype = {
|
|||
return result.proceed;
|
||||
},
|
||||
|
||||
asyncPromptAuth: function() {
|
||||
throw Cr.NS_ERROR_NOT_IMPLEMENTED;
|
||||
asyncPromptAuth: function(channel, callback, context, level, authInfo) {
|
||||
this._log.debug("asyncPromptAuth: this.name = " + this.name + "; this.username = " + this.username);
|
||||
this._log.debug("asyncPromptAuth: this.name = " + this.name + "; authInfo.realm = " + authInfo.realm);
|
||||
|
||||
let cancelable = {
|
||||
cancel: function() {
|
||||
if (win)
|
||||
win.QueryInterface(Ci.nsIDOMWindowInternal).close();
|
||||
callback.onAuthCancelled(context, false);
|
||||
}
|
||||
};
|
||||
|
||||
// Check saved logins before prompting the user. We get them
|
||||
// from the login manager and try each in turn until one of them works
|
||||
// or we run out of them.
|
||||
if (!this._logins) {
|
||||
let lm = Cc["@mozilla.org/login-manager;1"].getService(Ci.nsILoginManager);
|
||||
// XXX Should we be using channel.URI.prePath in case the old URI
|
||||
// redirects us to a new one at a different hostname?
|
||||
this._logins = lm.findLogins({}, this.machineURI.prePath, null, authInfo.realm);
|
||||
}
|
||||
|
||||
let login = this._logins[this._loginIndex];
|
||||
if (login) {
|
||||
authInfo.username = login.username;
|
||||
authInfo.password = login.password;
|
||||
++this._loginIndex;
|
||||
|
||||
let timer = Cc["@mozilla.org/timer;1"].createInstance(Ci.nsITimer);
|
||||
let timerCallback = {
|
||||
notify: function(timer) {
|
||||
callback.onAuthAvailable(context, authInfo);
|
||||
}
|
||||
}
|
||||
timer.initWithCallback(timerCallback, 0, Ci.nsITimer.TYPE_ONE_SHOT);
|
||||
|
||||
return cancelable;
|
||||
}
|
||||
|
||||
// If we've made it this far, none of the saved logins worked, so we prompt
|
||||
// the user to provide one.
|
||||
|
||||
let args = Cc["@mozilla.org/supports-array;1"].createInstance(Ci.nsISupportsArray);
|
||||
args.AppendElement({ wrappedJSObject: this });
|
||||
args.AppendElement(authInfo);
|
||||
|
||||
let t = this;
|
||||
let okCallback = function(remember) {
|
||||
if (remember)
|
||||
t._authInfo = authInfo;
|
||||
else
|
||||
t._authInfo = null;
|
||||
callback.onAuthAvailable(context, authInfo);
|
||||
}
|
||||
args.AppendElement({ wrappedJSObject: okCallback });
|
||||
|
||||
let cancelCallback = function() {
|
||||
t._authInfo = null;
|
||||
callback.onAuthCancelled(context, true);
|
||||
}
|
||||
args.AppendElement({ wrappedJSObject: cancelCallback });
|
||||
|
||||
let ww = Cc["@mozilla.org/embedcomp/window-watcher;1"].getService(Ci.nsIWindowWatcher);
|
||||
let win = ww.openWindow(null,
|
||||
"chrome://snowl/content/loginAsync.xul",
|
||||
null,
|
||||
"chrome,centerscreen,dialog",
|
||||
args);
|
||||
|
||||
return cancelable;
|
||||
},
|
||||
|
||||
|
||||
|
|
|
@ -252,8 +252,43 @@ SnowlTwitter.prototype = {
|
|||
return result.proceed;
|
||||
},
|
||||
|
||||
asyncPromptAuth: function() {
|
||||
throw Cr.NS_ERROR_NOT_IMPLEMENTED;
|
||||
asyncPromptAuth: function(channel, callback, context, level, authInfo) {
|
||||
this._log.debug("asyncPromptAuth: this.name = " + this.name + "; this.username = " + this.username);
|
||||
this._log.debug("asyncPromptAuth: this.name = " + this.name + "; authInfo.realm = " + authInfo.realm);
|
||||
|
||||
let args = Cc["@mozilla.org/supports-array;1"].createInstance(Ci.nsISupportsArray);
|
||||
args.AppendElement({ wrappedJSObject: this });
|
||||
args.AppendElement(authInfo);
|
||||
|
||||
let t = this;
|
||||
let okCallback = function(remember) {
|
||||
if (remember)
|
||||
t._authInfo = authInfo;
|
||||
else
|
||||
t._authInfo = null;
|
||||
callback.onAuthAvailable(context, authInfo);
|
||||
}
|
||||
args.AppendElement({ wrappedJSObject: okCallback });
|
||||
|
||||
let cancelCallback = function() {
|
||||
t._authInfo = null;
|
||||
callback.onAuthCancelled(context, true);
|
||||
}
|
||||
args.AppendElement({ wrappedJSObject: cancelCallback });
|
||||
|
||||
let ww = Cc["@mozilla.org/embedcomp/window-watcher;1"].getService(Ci.nsIWindowWatcher);
|
||||
let win = ww.openWindow(null,
|
||||
"chrome://snowl/content/loginAsync.xul",
|
||||
null,
|
||||
"chrome,centerscreen,dialog",
|
||||
args);
|
||||
|
||||
return {
|
||||
cancel: function() {
|
||||
win.QueryInterface(Ci.nsIDOMWindowInternal).close();
|
||||
callback.onAuthCancelled(context, false);
|
||||
}
|
||||
}
|
||||
},
|
||||
|
||||
|
||||
|
|
Загрузка…
Ссылка в новой задаче