/** * Returns the HTML page in which the <frame> or <iframe> tag is contained * for this frame window. * This is a facility method for <code>(HtmlPage) (getParentWindow().getEnclosedPage())</code>. * @return the page in the parent window */ public HtmlPage getEnclosingPage() { return (HtmlPage) frame_.getPage(); }
/** * Returns the HTML page in which the <frame> or <iframe> tag is contained * for this frame window. * This is a facility method for <code>(HtmlPage) (getParentWindow().getEnclosedPage())</code>. * @return the page in the parent window */ public HtmlPage getEnclosingPage() { return (HtmlPage) frame_.getPage(); }
/** * {@inheritDoc} */ @Override public WebWindow getParentWindow() { return frame_.getPage().getEnclosingWindow(); }
/** * {@inheritDoc} */ @Override public WebWindow getParentWindow() { return frame_.getPage().getEnclosingWindow(); }
/** * Creates an instance for a given frame. */ FrameWindow(final BaseFrameElement frame) { super(frame.getPage().getWebClient()); frame_ = frame; final WebWindowImpl parent = (WebWindowImpl) getParentWindow(); performRegistration(); parent.addChildWindow(this); }
private void loadSrc() { loadSrcWhenAddedToPage_ = false; final String src = getSrcAttribute(); final AbstractJavaScriptEngine<?> jsEngine = getPage().getWebClient().getJavaScriptEngine(); // When src is set from a script, loading is postponed until script finishes // in fact this implementation is probably wrong: JavaScript URL should be // first evaluated and only loading, when any, should be postponed. if (!jsEngine.isScriptRunning() || src.startsWith(JavaScriptURLConnection.JAVASCRIPT_PREFIX)) { loadInnerPageIfPossible(src); } else { final Page pageInFrame = getEnclosedPage(); final PostponedAction action = new PostponedAction(getPage()) { @Override public void execute() throws Exception { if (!src.isEmpty() && getSrcAttribute().equals(src)) { loadInnerPage(); } } @Override public boolean isStillAlive() { // skip if page in frame has already been changed return super.isStillAlive() && pageInFrame == getEnclosedPage(); } }; jsEngine.addPostponedAction(action); } }
private void loadSrc() { loadSrcWhenAddedToPage_ = false; final String src = getSrcAttribute(); final AbstractJavaScriptEngine<?> jsEngine = getPage().getWebClient().getJavaScriptEngine(); // When src is set from a script, loading is postponed until script finishes // in fact this implementation is probably wrong: JavaScript URL should be // first evaluated and only loading, when any, should be postponed. if (!jsEngine.isScriptRunning() || src.startsWith(JavaScriptURLConnection.JAVASCRIPT_PREFIX)) { loadInnerPageIfPossible(src); } else { final Page pageInFrame = getEnclosedPage(); final PostponedAction action = new PostponedAction(getPage()) { @Override public void execute() throws Exception { if (!src.isEmpty() && getSrcAttribute().equals(src)) { loadInnerPage(); } } @Override public boolean isStillAlive() { // skip if page in frame has already been changed return super.isStillAlive() && pageInFrame == getEnclosedPage(); } }; jsEngine.addPostponedAction(action); } }
/** * @throws FailingHttpStatusCodeException if the server returns a failing status code AND the property * {@link WebClient#setThrowExceptionOnFailingStatusCode(boolean)} is set to true */ private void loadInnerPageIfPossible(final String src) throws FailingHttpStatusCodeException { setContentLoaded(); if (!src.isEmpty()) { final URL url; try { url = ((HtmlPage) getPage()).getFullyQualifiedUrl(src); } catch (final MalformedURLException e) { notifyIncorrectness("Invalid src attribute of " + getTagName() + ": url=[" + src + "]. Ignored."); return; } if (isAlreadyLoadedByAncestor(url)) { notifyIncorrectness("Recursive src attribute of " + getTagName() + ": url=[" + src + "]. Ignored."); return; } try { final WebRequest request = new WebRequest(url); request.setCharset(getPage().getCharset()); request.setAdditionalHeader(HttpHeader.REFERER, getPage().getUrl().toExternalForm()); getPage().getEnclosingWindow().getWebClient().getPage(enclosedWindow_, request); } catch (final IOException e) { LOG.error("IOException when getting content for " + getTagName() + ": url=[" + url + "]", e); } } }
if (enclosedPage != null && enclosedPage.isHtmlPage()) { final HtmlPage htmlPage = (HtmlPage) enclosedPage; final AbstractJavaScriptEngine<?> jsEngine = getPage().getWebClient().getJavaScriptEngine(); if (jsEngine.isScriptRunning()) { final PostponedAction action = new PostponedAction(getPage()) { @Override public void execute() throws Exception {
if (enclosedPage != null && enclosedPage.isHtmlPage()) { final HtmlPage htmlPage = (HtmlPage) enclosedPage; final AbstractJavaScriptEngine<?> jsEngine = getPage().getWebClient().getJavaScriptEngine(); if (jsEngine.isScriptRunning()) { final PostponedAction action = new PostponedAction(getPage()) { @Override public void execute() throws Exception {
/** * Test if the provided URL is the one of one of the parents which would cause an infinite loop. * @param url the URL to test * @return {@code false} if no parent has already this URL */ private boolean isAlreadyLoadedByAncestor(final URL url) { WebWindow window = getPage().getEnclosingWindow(); while (window != null) { if (UrlUtils.sameFile(url, window.getEnclosedPage().getUrl())) { return true; } if (window == window.getParentWindow()) { // TODO: should getParentWindow() return null on top windows? window = null; } else { window = window.getParentWindow(); } } return false; }
/** * Test if the provided URL is the one of one of the parents which would cause an infinite loop. * @param url the URL to test * @return {@code false} if no parent has already this URL */ private boolean isAlreadyLoadedByAncestor(final URL url) { WebWindow window = getPage().getEnclosingWindow(); while (window != null) { if (UrlUtils.sameFile(url, window.getEnclosedPage().getUrl())) { return true; } if (window == window.getParentWindow()) { // TODO: should getParentWindow() return null on top windows? window = null; } else { window = window.getParentWindow(); } } return false; }
if (!isOnbeforeunloadAccepted((HtmlPage) frame.getPage(), event, result)) { return false;
if (!isOnbeforeunloadAccepted((HtmlPage) frame.getPage(), event)) { return false;
/** * Sets the specified element as the document's active element. * @see HTMLElement#setActive() * @param element the new active element for this document */ public void setActiveElement(final HTMLElement element) { // TODO update page focus element also activeElement_ = element; if (element != null) { // if this is part of an iFrame, make the iFrame tag the // active element of his doc final WebWindow window = element.getDomNodeOrDie().getPage().getEnclosingWindow(); if (window instanceof FrameWindow) { final BaseFrameElement frame = ((FrameWindow) window).getFrameElement(); if (frame instanceof HtmlInlineFrame) { final Window winWithFrame = frame.getPage().getEnclosingWindow().getScriptableObject(); ((HTMLDocument) winWithFrame.getDocument()).setActiveElement( (HTMLElement) frame.getScriptableObject()); } } } }
/** * Sets the specified element as the document's active element. * @see HTMLElement#setActive() * @param element the new active element for this document */ public void setActiveElement(final HTMLElement element) { // TODO update page focus element also activeElement_ = element; if (element != null) { // if this is part of an iFrame, make the iFrame tag the // active element of his doc final WebWindow window = element.getDomNodeOrDie().getPage().getEnclosingWindow(); if (window instanceof FrameWindow) { final BaseFrameElement frame = ((FrameWindow) window).getFrameElement(); if (frame instanceof HtmlInlineFrame) { final Window winWithFrame = frame.getPage().getEnclosingWindow().getScriptableObject(); ((HTMLDocument) winWithFrame.getDocument()).setActiveElement( (HTMLElement) frame.getScriptableObject()); } } } }