diff options
author | Andrew Arnott <andrewarnott@gmail.com> | 2008-08-22 16:42:31 -0700 |
---|---|---|
committer | Andrew Arnott <andrewarnott@gmail.com> | 2008-08-22 16:46:17 -0700 |
commit | 461efb0f72aebb2e89e70b3771bc4364d8a3eb02 (patch) | |
tree | 1406ef6404de866d911ddc319f4cd5228e2b8761 | |
parent | b4c99327708a3749e04e602e1bfcc9fbe484cf78 (diff) | |
download | DotNetOpenAuth-461efb0f72aebb2e89e70b3771bc4364d8a3eb02.zip DotNetOpenAuth-461efb0f72aebb2e89e70b3771bc4364d8a3eb02.tar.gz DotNetOpenAuth-461efb0f72aebb2e89e70b3771bc4364d8a3eb02.tar.bz2 |
Added timeout facility to AJAX control.
-rw-r--r-- | src/DotNetOpenId/RelyingParty/OpenIdAjaxTextBox.cs | 20 | ||||
-rw-r--r-- | src/DotNetOpenId/RelyingParty/OpenIdAjaxTextBox.js | 8 |
2 files changed, 25 insertions, 3 deletions
diff --git a/src/DotNetOpenId/RelyingParty/OpenIdAjaxTextBox.cs b/src/DotNetOpenId/RelyingParty/OpenIdAjaxTextBox.cs index 4e8467d..3a7bedd 100644 --- a/src/DotNetOpenId/RelyingParty/OpenIdAjaxTextBox.cs +++ b/src/DotNetOpenId/RelyingParty/OpenIdAjaxTextBox.cs @@ -126,6 +126,21 @@ namespace DotNetOpenId.RelyingParty { }
}
+ const string timeoutViewStateKey = "Timeout";
+ readonly TimeSpan timeoutDefault = TimeSpan.FromSeconds(8);
+ /// <summary>
+ /// Gets/sets the time duration for the AJAX control to wait for an OP to respond before reporting failure to the user.
+ /// </summary>
+ [Browsable(true), DefaultValue(typeof(TimeSpan), "00:00:08"), Category("Behavior")]
+ [Description("The time duration for the AJAX control to wait for an OP to respond before reporting failure to the user.")]
+ public TimeSpan Timeout {
+ get { return (TimeSpan)(ViewState[timeoutViewStateKey] ?? timeoutDefault); }
+ set {
+ if (value.TotalMilliseconds <= 0) throw new ArgumentOutOfRangeException("value");
+ ViewState[timeoutViewStateKey] = value;
+ }
+ }
+
#endregion
#region Properties to hide
@@ -255,10 +270,11 @@ document.getElementsByName({0})[0].focus(); Page.ClientScript.RegisterStartupScript(GetType(), "ajaxstartup", string.Format(CultureInfo.InvariantCulture, @"
<script language='javascript'>
var openidbox = document.getElementsByName('{0}')[0];
-if (openidbox) {{ initAjaxOpenId(openidbox, '{1}', '{2}'); }}
+if (openidbox) {{ initAjaxOpenId(openidbox, '{1}', '{2}', {3}); }}
</script>", Name,
Page.ClientScript.GetWebResourceUrl(GetType(), EmbeddedDotNetOpenIdLogoResourceName),
- Page.ClientScript.GetWebResourceUrl(GetType(), EmbeddedSpinnerResourceName)));
+ Page.ClientScript.GetWebResourceUrl(GetType(), EmbeddedSpinnerResourceName),
+ Timeout.TotalMilliseconds));
}
private void performDiscovery(string userSuppliedIdentifier) {
diff --git a/src/DotNetOpenId/RelyingParty/OpenIdAjaxTextBox.js b/src/DotNetOpenId/RelyingParty/OpenIdAjaxTextBox.js index 53aab8a..b3c35a5 100644 --- a/src/DotNetOpenId/RelyingParty/OpenIdAjaxTextBox.js +++ b/src/DotNetOpenId/RelyingParty/OpenIdAjaxTextBox.js @@ -3,8 +3,9 @@ //window.status = msg;
}
-function initAjaxOpenId(box, dotnetopenid_logo_url, spinner_url) {
+function initAjaxOpenId(box, dotnetopenid_logo_url, spinner_url, timeout) {
box.originalBackground = box.style.background;
+ box.timeout = timeout;
// Construct the login button
var loginButton = document.createElement('button');
@@ -126,18 +127,23 @@ function initAjaxOpenId(box, dotnetopenid_logo_url, spinner_url) { iframe.setAttribute("src", url);
iframe.openidBox = box;
box.parentNode.insertBefore(iframe, box);
+ box.discoveryTimeout = setTimeout(function() { trace("timeout"); box.openidDiscoveryFailure("Timed out"); }, box.timeout);
return iframe;
}
this.parentForm = findParentForm(box);
box.openidDiscoveryFailure = function(msg) {
+ box.closeDiscoveryIFrame();
trace('Discovery failure: ' + msg);
box.setVisualCue('failed');
box.title = msg;
}
box.closeDiscoveryIFrame = function() {
+ if (box.discoveryTimeout) {
+ clearTimeout(box.discoveryTimeout);
+ }
if (box.discoveryIFrame) {
box.discoveryIFrame.parentNode.removeChild(box.discoveryIFrame);
box.discoveryIFrame = null;
|