//----------------------------------------------------------------------- // // Copyright (c) Andrew Arnott. All rights reserved. // //----------------------------------------------------------------------- namespace DotNetOpenAuth.OpenId.Extensions.UI { using System; using System.Diagnostics.Contracts; using System.Globalization; using DotNetOpenAuth.Messaging; using DotNetOpenAuth.OpenId.RelyingParty; /// /// Constants used in implementing support for the UI extension. /// public static class UIUtilities { /// /// The required width of the popup window the relying party creates for the provider. /// public const int PopupWidth = 500; // UI extension calls for 450px, but Yahoo needs 500px /// /// The required height of the popup window the relying party creates for the provider. /// public const int PopupHeight = 500; /// /// Gets the window.open javascript snippet to use to open a popup window /// compliant with the UI extension. /// /// The relying party. /// The authentication request to place in the window. /// The name to assign to the popup window. /// A string starting with 'window.open' and forming just that one method call. internal static string GetWindowPopupScript(OpenIdRelyingParty relyingParty, IAuthenticationRequest request, string windowName) { Requires.NotNull(relyingParty, "relyingParty"); Requires.NotNull(request, "request"); Requires.NotNullOrEmpty(windowName, "windowName"); Uri popupUrl = request.RedirectingResponse.GetDirectUriRequest(relyingParty.Channel); return string.Format( CultureInfo.InvariantCulture, "(window.showModalDialog ? window.showModalDialog({0}, {1}, 'status:0;resizable:1;scroll:1;center:1;dialogWidth:{2}px; dialogHeight:{3}') : window.open({0}, {1}, 'status=0,toolbar=0,location=1,resizable=1,scrollbars=1,left=' + ((screen.width - {2}) / 2) + ',top=' + ((screen.height - {3}) / 2) + ',width={2},height={3}'));", MessagingUtilities.GetSafeJavascriptValue(popupUrl.AbsoluteUri), MessagingUtilities.GetSafeJavascriptValue(windowName), PopupWidth, PopupHeight); } } }