/// <summary> /// Creates a TextPage for this WebResponse. /// </summary> /// <param name="webResponse">the page's source</param> /// <param name="webWindow">the WebWindow to place the TextPage in</param> /// <returns>the newly created TextPage</returns> protected TextPage CreateTextPage(WebResponse webResponse, IWebWindow webWindow) { TextPage newPage = new TextPage(webResponse, webWindow); webWindow.EnclosedPage = newPage; return(newPage); }
/// <summary> /// Creates a JavaScriptPage for this WebResponse. /// </summary> /// <param name="webResponse">the page's source</param> /// <param name="webWindow">the WebWindow to place the JavaScriptPage in</param> /// <returns>the newly created JavaScriptPage</returns> protected JavaScriptPage CreateJavaScriptPage(WebResponse webResponse, IWebWindow webWindow) { JavaScriptPage newPage = new JavaScriptPage(webResponse, webWindow); webWindow.EnclosedPage = newPage; return(newPage); }
/// <summary> /// Creates an UnexpectedPage for this WebResponse. /// </summary> /// <param name="webResponse">the page's source</param> /// <param name="webWindow">the WebWindow to place the UnexpectedPage in</param> /// <returns>the newly created UnexpectedPage</returns> protected UnexpectedPage CreateUnexpectedPage(WebResponse webResponse, IWebWindow webWindow) { UnexpectedPage newPage = new UnexpectedPage(webResponse, webWindow); webWindow.EnclosedPage = newPage; return(newPage); }
public SgmlPage(WebResponse webResponse, IWebWindow webWindow): base(null) { webResponse_ = webResponse; enclosingWindow_ = webWindow; webClient_ = webWindow.WebClient; }
/// <summary> /// Create a Page object for the specified web response. /// </summary> /// <param name="webResponse">the response from the server</param> /// <param name="webWindow">the window that this page will be loaded into</param> /// <returns>the new page object</returns> public IPage CreatePage(WebResponse webResponse, IWebWindow webWindow) { String contentType = DetermineContentType(webResponse.GetContentType().ToLower(), // TODO : Locale.ENGLISH webResponse.GetContentAsStream()); PageType pageType = DeterminePageType(contentType); switch (pageType) { case PageType.HTML: return(CreateHtmlPage(webResponse, webWindow)); case PageType.JAVASCRIPT: return(CreateJavaScriptPage(webResponse, webWindow)); case PageType.XML: SgmlPage sgmlPage = CreateXmlPage(webResponse, webWindow); DomElement doc = sgmlPage.getDocumentElement(); if (doc != null && HTMLParser.XHTML_NAMESPACE.equals(doc.getNamespaceURI())) { return(CreateXHtmlPage(webResponse, webWindow)); } return(sgmlPage); case PageType.TEXT: return(CreateTextPage(webResponse, webWindow)); default: return(CreateUnexpectedPage(webResponse, webWindow)); } }
/// <summary> /// Refreshes the specified page using the specified URL after the specified number of seconds. /// @throws IOException if the refresh fails /// </summary> /// <param name="page">the page that is going to be refreshed</param> /// <param name="url">the URL where the new page will be loaded</param> /// <param name="requestedWait">the number of seconds to wait before reloading the page; if this is greater than <tt>maxwait</tt> then <tt>maxwait</tt> will be used instead</param> public void HandleRefresh(AbstractPage page, URL url, int requestedWait) { int seconds = requestedWait; if (seconds > maxwait_ && maxwait_ > 0) { seconds = maxwait_; } try { Thread.Sleep(seconds * 1000); } catch (/*InterruptedException*/ Exception e) { /* This can happen when the refresh is happening from a navigation that started * from a setTimeout or setInterval. The navigation will cause all threads to get * interrupted, including the current thread in this case. It should be safe to * ignore it since this is the thread now doing the navigation. Eventually we should * refactor to force all navigation to happen back on the main thread. */ if (LOG.IsDebugEnabled) { LOG.Debug("Waiting thread was interrupted. Ignoring interruption to continue navigation."); } } IWebWindow window = page.EnclosingWindow; if (window == null) { return; } WebClient client = window.WebClient; client.getPage(window, new WebRequest(url)); }
/// <summary> /// Creates an SgmlPage for this WebResponse. /// @throws IOException if the page could not be created /// </summary> /// <param name="webResponse">the page's source</param> /// <param name="webWindow">the WebWindow to place the TextPage in</param> /// <returns>the newly created TextPage</returns> protected SgmlPage CreateXmlPage(WebResponse webResponse, IWebWindow webWindow) { SgmlPage page = new XmlPage(webResponse, webWindow); if (IsSvg(page)) { page = new SvgPage(webResponse, page.getDocumentElement(), webWindow); } webWindow.EnclosedPage = page; return(page); }
private String GetKey(StorageType type, IPage page) { switch (type) { case StorageType.GLOBAL_STORAGE: return(page.Url.Host); case StorageType.LOCAL_STORAGE: URL url = page.Url; return(url.Protocol + "://" + url.Host + ':' + url.Protocol); case StorageType.SESSION_STORAGE: IWebWindow topWindow = page.EnclosingWindow.TopWindow; return(topWindow.GetHashCode().ToString("X")); default: return(null); } }
/// <summary> /// Immediately refreshes the specified page using the specified URL. /// @throws IOException if the refresh fails /// </summary> /// <param name="page">the page that is going to be refreshed</param> /// <param name="url">the URL where the new page will be loaded</param> /// <param name="seconds">the number of seconds to wait before reloading the page (ignored!)</param> public void HandleRefresh(IPage page, URL url, int seconds) { IWebWindow window = page.EnclosingWindow; if (window == null) { return; } WebClient client = window.WebClient; if (String.Equals(page.Url.ToExternalForm(), url.ToExternalForm()) && HttpMethod.GET == page.WebResponse.WebRequest.HttpMethod) { String msg = "Refresh to " + url + " (" + seconds + "s) aborted by HtmlUnit: " + "Attempted to refresh a page using an ImmediateRefreshHandler " + "which could have caused an OutOfMemoryError " + "Please use WaitingRefreshHandler or ThreadedRefreshHandler instead."; throw new RuntimeException(msg); } client.getPage(window, new WebRequest(url)); }
public static void Run <TStartup>(IWebWindow webWindow) { DesktopSynchronizationContext.UnhandledException += (sender, exception) => { UnhandledException(exception); }; WebWindow = webWindow; var completed = new ManualResetEventSlim(); CancellationTokenSource appLifetimeCts = new CancellationTokenSource(); Task.Factory.StartNew(async() => { try { var ipc = new IPC(WebWindow); await RunAsync <TStartup>(ipc, appLifetimeCts.Token, completed); } catch (Exception ex) { UnhandledException(ex); throw; } }); try { completed.Wait(); // TODO We need to wait for the new IPC to finish before trying to navigate WebWindow.NavigateToUrl(BlazorAppScheme + "://app/"); WebWindow.WaitForExit(); } finally { appLifetimeCts.Cancel(); } }
/** * Creates an instance. * * @param webWindow the WebWindow that caused the event * @param type the type - one of {@link #OPEN}, {@link #CLOSE} or {@link #CHANGE} * @param oldPage the old contents of the web window * @param newPage the new contents of the web window */ public WebWindowEvent( IWebWindow webWindow, int type, IPage oldPage, IPage newPage) : base(webWindow) { oldPage_ = oldPage; newPage_ = newPage; switch (type) { case OPEN: case CLOSE: case CHANGE: type_ = type; break; default: throw new ArgumentException("type must be one of OPEN, CLOSE, CHANGE but got " + type); } }
/// <summary> /// Creates an instance. /// </summary> /// <param name="webResponse">the response from the server</param> /// <param name="enclosingWindow">the window that holds the page</param> public AbstractPage(WebResponse webResponse, IWebWindow enclosingWindow) { webResponse_ = webResponse; enclosingWindow_ = enclosingWindow; }
/// <summary> /// Creates an instance. /// </summary> /// <param name="webResponse">the response from the server that contains the data required to create this page</param> /// <param name="enclosingWindow">the window that this page is being loaded into</param> public UnexpectedPage(WebResponse webResponse, IWebWindow enclosingWindow) : base(webResponse, enclosingWindow) { }
/// <summary> /// Creates a new navigation history for the specified window. /// </summary> /// <param name="window">the window which owns the new navigation history</param> public History(IWebWindow window) { window_ = window; InitTransientFields(); }
/// <summary> /// Creates an XHtmlPage for this WebResponse. /// @throws IOException if the page could not be created /// </summary> /// <param name="webResponse">the page's source</param> /// <param name="webWindow">the WebWindow to place the HtmlPage in</param> /// <returns>the newly created XHtmlPage</returns> protected XHtmlPage CreateXHtmlPage(WebResponse webResponse, IWebWindow webWindow) { return(HTMLParser.parseXHtml(webResponse, webWindow)); }
/// <summary> /// Creates an instance. /// </summary> /// <param name="webResponse">the response from the server</param> /// <param name="enclosingWindow">the window that holds the page</param> public TextPage(WebResponse webResponse, IWebWindow enclosingWindow) : base(webResponse, enclosingWindow) { }
/// <summary> /// Creates an instance. /// </summary> /// <param name="webResponse">the response from the server</param> /// <param name="enclosingWindow">the window that holds the page</param> public JavaScriptPage(WebResponse webResponse, IWebWindow enclosingWindow) : base(webResponse, enclosingWindow) { }
public IPC(IWebWindow webWindow) { _webWindow = webWindow ?? throw new ArgumentNullException(nameof(webWindow)); _webWindow.OnWebMessageReceived += HandleScriptNotify; }