Refine search
/** * Returns the value of the parent property. * @return the value of window.parent */ public SimpleScriptable jsxGet_parent() { final WebWindow parentWebWindow = webWindow_.getParentWindow(); return (SimpleScriptable) parentWebWindow.getScriptObject(); }
/** * Returns the value of the top property. * @return the value of "top" */ public SimpleScriptable jsxGet_top() { final WebWindow topWebWindow = webWindow_.getTopWindow(); return (SimpleScriptable) topWebWindow.getScriptObject(); }
private void cleanUp() { Page p = page.get(); if (p != null) { p.cleanUp(); } for (WebWindow window : webClient.get().getWebWindows()) { window.getJobManager().removeAllJobs(); } page.remove(); webClient.get().close(); webClient.remove(); }
private URL makeUrlForOpenWindow(final String urlString) { if (urlString.isEmpty()) { return WebClient.URL_ABOUT_BLANK; } try { final Page page = getWebWindow().getEnclosedPage(); if (page != null && page.isHtmlPage()) { return ((HtmlPage) page).getFullyQualifiedUrl(urlString); } return new URL(urlString); } catch (final MalformedURLException e) { LOG.error("Unable to create URL for openWindow: relativeUrl=[" + urlString + "]", e); return null; } }
@Override public String getSource(final DebuggableScript script) { String sourceName = script.getSourceName(); if (sourceName.endsWith("(eval)") || sourceName.endsWith("(Function)")) { return null; // script is result of eval call. Rhino already knows the source and we don't } if (sourceName.startsWith("script in ")) { sourceName = StringUtils.substringBetween(sourceName, "script in ", " from"); for (final WebWindow ww : client.getWebWindows()) { final WebResponse wr = ww.getEnclosedPage().getWebResponse(); if (sourceName.equals(wr.getWebRequest().getUrl().toString())) { return wr.getContentAsString(); } } } return null; } };
@Override public String getCurrentUrl() { getWebClient(); // check that session is active Page page = getCurrentWindow().getTopWindow().getEnclosedPage(); if (page == null) { return null; } URL url = page.getUrl(); if (url == null) { return null; } return url.toString(); }
/** * <p><span style="color:red">INTERNAL API - SUBJECT TO CHANGE AT ANY TIME - USE AT YOUR OWN RISK.</span></p> * * Opens a new dialog window. * @param url the URL of the document to load and display * @param opener the web window that is opening the dialog * @param dialogArguments the object to make available inside the dialog via <tt>window.dialogArguments</tt> * @return the new dialog window * @throws IOException if there is an IO error */ public DialogWindow openDialogWindow(final URL url, final WebWindow opener, final Object dialogArguments) throws IOException { WebAssert.notNull("url", url); WebAssert.notNull("opener", opener); final DialogWindow window = new DialogWindow(this, dialogArguments); fireWindowOpened(new WebWindowEvent(window, WebWindowEvent.OPEN, null, null)); final HtmlPage openerPage = (HtmlPage) opener.getEnclosedPage(); final WebRequestSettings settings = new WebRequestSettings(url); if (!getBrowserVersion().isIE()) { final String referer = openerPage.getWebResponse().getRequestSettings().getUrl().toExternalForm(); settings.setAdditionalHeader("Referer", referer); } getPage(window, settings); return window; }
/** * Reloads the current page, possibly forcing retrieval from the server even if * the browser cache contains the latest version of the document. * @param force if {@code true}, force reload from server; otherwise, may reload from cache * @throws IOException if there is a problem reloading the page * @see <a href="http://msdn.microsoft.com/en-us/library/ms536342.aspx">MSDN Documentation</a> */ @JsxFunction public void reload(final boolean force) throws IOException { final HtmlPage htmlPage = (HtmlPage) getWindow(getStartingScope()).getWebWindow().getEnclosedPage(); final WebRequest request = htmlPage.getWebResponse().getWebRequest(); String referer = htmlPage.getUrl().toExternalForm(); request.setAdditionalHeader(HttpHeader.REFERER, referer); referer = UrlUtils.getUrlWithNewQuery(htmlPage.getUrl(), null).toExternalForm(); referer = StringUtils.stripEnd(referer, "/"); request.setAdditionalHeader(HttpHeader.ORIGIN, referer); final WebWindow webWindow = window_.getWebWindow(); webWindow.getWebClient().download(webWindow, "", request, true, false, "JS location.reload"); }
/** * Implementation of the IE behavior #default#download. * @param uri the URI of the download source * @param callback the method which should be called when the download is finished * @see <a href="http://msdn.microsoft.com/en-us/library/ms531406.aspx">MSDN documentation</a> * @throws MalformedURLException if the URL cannot be created */ public void startDownload(final String uri, final Function callback) throws MalformedURLException { final HtmlPage page = (HtmlPage) getWindow().getWebWindow().getEnclosedPage(); final URL url = page.getFullyQualifiedUrl(uri); if (!page.getWebResponse().getRequestSettings().getUrl().getHost().equals(url.getHost())) { throw Context.reportRuntimeError("Not authorized url: " + url); } final JavaScriptJob job = new DownloadBehaviorJob(url, callback); page.getEnclosingWindow().getJobManager().addJob(job, page); }
/** * Implementation of the IE behavior #default#download. * @param uri the URI of the download source * @param callback the method which should be called when the download is finished * @see <a href="http://msdn.microsoft.com/en-us/library/ms531406.aspx">MSDN documentation</a> * @throws MalformedURLException if the URL cannot be created */ public void startDownload(final String uri, final Function callback) throws MalformedURLException { final WebWindow ww = getWindow().getWebWindow(); final HtmlPage page = (HtmlPage) ww.getEnclosedPage(); final URL url = page.getFullyQualifiedUrl(uri); if (!page.getUrl().getHost().equals(url.getHost())) { throw Context.reportRuntimeError("Not authorized url: " + url); } final JavaScriptJob job = BackgroundJavaScriptFactory.theFactory(). createDownloadBehaviorJob(url, callback, ww.getWebClient()); page.getEnclosingWindow().getJobManager().addJob(job, page); }
/** * Initializes the object. * * @param window the window that this location belongs to */ public void initialize(final Window window) { window_ = window; if (window_ != null && window_.getWebWindow().getEnclosedPage() != null) { hash_ = window_.getWebWindow().getEnclosedPage().getWebResponse().getRequestSettings().getUrl().getRef(); } }
/** * Initializes the object. * * @param window the window that this location belongs to */ public void initialize(final Window window) { window_ = window; if (window_ != null && window_.getWebWindow().getEnclosedPage() != null) { setHash(window_.getWebWindow().getEnclosedPage().getUrl().getRef()); } }
/** * Convenient method to load a URL into the current top WebWindow as it would be done * by {@link #getPage(WebWindow, WebRequest)}. * @param url the URL of the new content * @param <P> the page type * @return the new page * @throws FailingHttpStatusCodeException if the server returns a failing status code AND the property * {@link WebClientOptions#setThrowExceptionOnFailingStatusCode(boolean)} is set to true. * @throws IOException if an IO problem occurs */ @SuppressWarnings("unchecked") public <P extends Page> P getPage(final URL url) throws IOException, FailingHttpStatusCodeException { final WebRequest request = new WebRequest(url, getBrowserVersion().getHtmlAcceptHeader()); request.setCharset(StandardCharsets.UTF_8); return (P) getPage(getCurrentWindow().getTopWindow(), request); }
@Override public String getServerResponse() { StringBuffer result = new StringBuffer(); WebResponse wr = wc.getCurrentWindow().getEnclosedPage() .getWebResponse(); result.append(wr.getStatusCode()).append(" ").append( wr.getStatusMessage()).append("\n"); result.append("Location: ").append(wr.getWebRequest().getUrl()).append("\n"); for (NameValuePair h : wr.getResponseHeaders()) { result.append(h.getName()).append(": ").append(h.getValue()) .append("\n"); } result.append("\n"); result.append(wr.getContentAsString()); return result.toString(); }
private boolean isAlreadyLoadedByAncestor( final URL url, HtmlPage page ) { WebWindow window = page.getEnclosingWindow(); while (window != null) { if (url.sameFile(window.getEnclosedPage().getWebResponse().getWebRequest().getUrl())) { return true; } if (window == window.getParentWindow()) { window = null; } else { window = window.getParentWindow(); } } return false; }
/** * Returns the {@code doNotTrack} property. * @return the {@code doNotTrack} property */ @JsxGetter({CHROME, FF}) public Object getDoNotTrack() { final WebClient client = getWindow().getWebWindow().getWebClient(); if (client.getOptions().isDoNotTrackEnabled()) { return 1; } if (client.getBrowserVersion().hasFeature(JS_NAVIGATOR_DO_NOT_TRACK_UNSPECIFIED)) { return "unspecified"; } return null; }
/** {@inheritDoc} */ @Override protected void runJavaScript(final HtmlPage page) { final HtmlElement doc = page.getDocumentElement(); final Scriptable scriptable = (Scriptable) page.getEnclosingWindow().getScriptObject(); page.executeJavaScriptFunctionIfPossible(function_, scriptable, new Object[0], doc); }
/** * Sets this location's URL, triggering a server hit and loading the resultant document * into this location's window. * @param url This location's new URL * @throws IOException if there is a problem loading the new location */ private void setUrl(final URL url) throws IOException { window_.getWebWindow().getWebClient().getPage(window_.getWebWindow(), new WebRequest(url)); }
public WebDriver frame(int frameIndex) { HtmlPage page = (HtmlPage) webClient.getCurrentWindow().getEnclosedPage(); try { currentWindow = page.getFrames().get(frameIndex); } catch (IndexOutOfBoundsException e) { throw new NoSuchFrameException("Cannot find frame: " + frameIndex); } return HtmlUnitDriver.this; }
private HtmlForm getForm(String nameOrID) { try { return (HtmlForm) ((HtmlPage) win.getEnclosedPage()) .getHtmlElementById(nameOrID); } catch (ElementNotFoundException e) { } try { return ((HtmlPage) win.getEnclosedPage()).getFormByName(nameOrID); } catch (ElementNotFoundException e) { } return null; }