com.gargoylesoftware.htmlunit.html.FrameWindow Java Examples

The following examples show how to use com.gargoylesoftware.htmlunit.html.FrameWindow. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: HTMLDocument.java    From HtmlUnit-Android with Apache License 2.0 6 votes vote down vote up
/**
 * 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 = (Window) frame.getPage().getEnclosingWindow().getScriptableObject();
                ((HTMLDocument) winWithFrame.getDocument()).setActiveElement(
                            (HTMLElement) frame.getScriptableObject());
            }
        }
    }
}
 
Example #2
Source File: HTMLDocument.java    From HtmlUnit-Android with Apache License 2.0 6 votes vote down vote up
/**
 * JavaScript function "open".
 *
 * See http://www.whatwg.org/specs/web-apps/current-work/multipage/section-dynamic.html for
 * a good description of the semantics of open(), write(), writeln() and close().
 *
 * @param url when a new document is opened, <i>url</i> is a String that specifies a MIME type for the document.
 *        When a new window is opened, <i>url</i> is a String that specifies the URL to render in the new window
 * @param name the name
 * @param features the features
 * @param replace whether to replace in the history list or no
 * @return a reference to the new document object.
 * @see <a href="http://msdn.microsoft.com/en-us/library/ms536652.aspx">MSDN documentation</a>
 */
@JsxFunction
public Object open(final Object url, final Object name, final Object features,
        final Object replace) {
    // Any open() invocations are ignored during the parsing stage, because write() and
    // writeln() invocations will directly append content to the current insertion point.
    final HtmlPage page = getPage();
    if (page.isBeingParsed()) {
        LOG.warn("Ignoring call to open() during the parsing stage.");
        return null;
    }

    // We're not in the parsing stage; OK to continue.
    if (!writeInCurrentDocument_) {
        LOG.warn("Function open() called when document is already open.");
    }
    writeInCurrentDocument_ = false;
    final WebWindow ww = getWindow().getWebWindow();
    if (ww instanceof FrameWindow
            && WebClient.ABOUT_BLANK.equals(getPage().getUrl().toExternalForm())) {
        final URL enclosingUrl = ((FrameWindow) ww).getEnclosingPage().getUrl();
        getPage().getWebResponse().getWebRequest().setUrl(enclosingUrl);
    }
    return this;
}
 
Example #3
Source File: Document.java    From htmlunit with Apache License 2.0 6 votes vote down vote up
/**
 * Returns the domain name of the server that served the document, or {@code null} if the server
 * cannot be identified by a domain name.
 * @return the domain name of the server that served the document
 * @see <a href="http://www.w3.org/TR/2000/WD-DOM-Level-1-20000929/level-one-html.html#ID-2250147">
 * W3C documentation</a>
 */
@JsxGetter({CHROME, IE})
public String getDomain() {
    if (domain_ == null && getPage().getWebResponse() != null) {
        URL url = getPage().getUrl();
        if (url == WebClient.URL_ABOUT_BLANK) {
            final WebWindow w = getWindow().getWebWindow();
            if (w instanceof FrameWindow) {
                url = ((FrameWindow) w).getEnclosingPage().getUrl();
            }
            else {
                return null;
            }
        }
        domain_ = url.getHost().toLowerCase(Locale.ROOT);
    }

    return domain_;
}
 
Example #4
Source File: Document.java    From HtmlUnit-Android with Apache License 2.0 6 votes vote down vote up
/**
 * Returns the domain name of the server that served the document, or {@code null} if the server
 * cannot be identified by a domain name.
 * @return the domain name of the server that served the document
 * @see <a href="http://www.w3.org/TR/2000/WD-DOM-Level-1-20000929/level-one-html.html#ID-2250147">
 * W3C documentation</a>
 */
@JsxGetter({CHROME, IE})
public String getDomain() {
    if (domain_ == null && getPage().getWebResponse() != null) {
        URL url = getPage().getUrl();
        if (url == WebClient.URL_ABOUT_BLANK) {
            final WebWindow w = getWindow().getWebWindow();
            if (w instanceof FrameWindow) {
                url = ((FrameWindow) w).getEnclosingPage().getUrl();
            }
            else {
                return null;
            }
        }
        domain_ = url.getHost().toLowerCase(Locale.ROOT);
    }

    return domain_;
}
 
Example #5
Source File: HTMLDocument.java    From htmlunit with Apache License 2.0 6 votes vote down vote up
/**
 * JavaScript function "open".
 *
 * See http://www.whatwg.org/specs/web-apps/current-work/multipage/section-dynamic.html for
 * a good description of the semantics of open(), write(), writeln() and close().
 *
 * @param url when a new document is opened, <i>url</i> is a String that specifies a MIME type for the document.
 *        When a new window is opened, <i>url</i> is a String that specifies the URL to render in the new window
 * @param name the name
 * @param features the features
 * @param replace whether to replace in the history list or no
 * @return a reference to the new document object.
 * @see <a href="http://msdn.microsoft.com/en-us/library/ms536652.aspx">MSDN documentation</a>
 */
@JsxFunction
public Object open(final Object url, final Object name, final Object features,
        final Object replace) {
    // Any open() invocations are ignored during the parsing stage, because write() and
    // writeln() invocations will directly append content to the current insertion point.
    final HtmlPage page = getPage();
    if (page.isBeingParsed()) {
        LOG.warn("Ignoring call to open() during the parsing stage.");
        return null;
    }

    // We're not in the parsing stage; OK to continue.
    if (!writeInCurrentDocument_) {
        LOG.warn("Function open() called when document is already open.");
    }
    writeInCurrentDocument_ = false;
    final WebWindow ww = getWindow().getWebWindow();
    if (ww instanceof FrameWindow
            && WebClient.ABOUT_BLANK.equals(getPage().getUrl().toExternalForm())) {
        final URL enclosingUrl = ((FrameWindow) ww).getEnclosingPage().getUrl();
        getPage().getWebResponse().getWebRequest().setUrl(enclosingUrl);
    }
    return this;
}
 
Example #6
Source File: HTMLDocument.java    From htmlunit with Apache License 2.0 6 votes vote down vote up
/**
 * 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());
            }
        }
    }
}
 
Example #7
Source File: Window.java    From htmlunit with Apache License 2.0 5 votes vote down vote up
/**
 * Returns the (i)frame in which the window is contained.
 * @return {@code null} for a top level window
 */
@JsxGetter
public Object getFrameElement() {
    final WebWindow window = getWebWindow();
    if (window instanceof FrameWindow) {
        return ((FrameWindow) window).getFrameElement().getScriptableObject();
    }
    return null;
}
 
Example #8
Source File: HTMLDocument.java    From HtmlUnit-Android with Apache License 2.0 5 votes vote down vote up
/**
 * {@inheritDoc}
 */
@Override
@JsxFunction(FF)
public void close() throws IOException {
    if (writeInCurrentDocument_) {
        LOG.warn("close() called when document is not open.");
    }
    else {
        final HtmlPage page = getPage();
        final URL url = page.getUrl();
        final StringWebResponse webResponse = new StringWebResponse(writeBuilder_.toString(), url);
        webResponse.setFromJavascript(true);
        writeInCurrentDocument_ = true;
        writeBuilder_.setLength(0);

        final WebClient webClient = page.getWebClient();
        final WebWindow window = page.getEnclosingWindow();
        // reset isAttachedToPageDuringOnload_ to trigger the onload event for chrome also
        if (window instanceof FrameWindow) {
            final BaseFrameElement frame = ((FrameWindow) window).getFrameElement();
            final ScriptableObject scriptable = frame.getScriptableObject();
            if (scriptable instanceof HTMLIFrameElement) {
                ((HTMLIFrameElement) scriptable).onRefresh();
            }
        }
        webClient.loadWebResponseInto(webResponse, window);
    }
}
 
Example #9
Source File: Window.java    From HtmlUnit-Android with Apache License 2.0 5 votes vote down vote up
@Override
protected Scriptable getScriptableForElement(final Object obj) {
    final WebWindow window;
    if (obj instanceof BaseFrameElement) {
        window = ((BaseFrameElement) obj).getEnclosedWindow();
    }
    else {
        window = ((FrameWindow) obj).getFrameElement().getEnclosedWindow();
    }

    return window.getScriptableObject();
}
 
Example #10
Source File: Window.java    From HtmlUnit-Android with Apache License 2.0 5 votes vote down vote up
/**
 * Returns the current selection.
 * @return the current selection
 */
@JsxFunction
public Selection getSelection() {
    final WebWindow webWindow = getWebWindow();
    // return null if the window is in a frame that is not displayed
    if (webWindow instanceof FrameWindow) {
        final FrameWindow frameWindow = (FrameWindow) webWindow;
        if (getBrowserVersion().hasFeature(JS_WINDOW_SELECTION_NULL_IF_INVISIBLE)
                && !frameWindow.getFrameElement().isDisplayed()) {
            return null;
        }
    }
    return getSelectionImpl();
}
 
Example #11
Source File: Window.java    From HtmlUnit-Android with Apache License 2.0 5 votes vote down vote up
/**
 * Returns the (i)frame in which the window is contained.
 * @return {@code null} for a top level window
 */
@JsxGetter
public Object getFrameElement() {
    final WebWindow window = getWebWindow();
    if (window instanceof FrameWindow) {
        return ((FrameWindow) window).getFrameElement().getScriptableObject();
    }
    return null;
}
 
Example #12
Source File: WebClient.java    From HtmlUnit-Android with Apache License 2.0 5 votes vote down vote up
/**
 * {@inheritDoc}
 */
@Override
public void webWindowContentChanged(final WebWindowEvent event) {
    final WebWindow window = event.getWebWindow();
    boolean use = false;
    if (window instanceof DialogWindow) {
        use = true;
    }
    else if (window instanceof TopLevelWindow) {
        use = event.getOldPage() == null;
    }
    else if (window instanceof FrameWindow) {
        final FrameWindow fw = (FrameWindow) window;
        final String enclosingPageState = fw.getEnclosingPage().getDocumentElement().getReadyState();
        final URL frameUrl = fw.getEnclosedPage().getUrl();
        if (!DomNode.READY_STATE_COMPLETE.equals(enclosingPageState) || frameUrl == URL_ABOUT_BLANK) {
            return;
        }

        // now looks at the visibility of the frame window
        final BaseFrameElement frameElement = fw.getFrameElement();
        if (frameElement.isDisplayed()) {
            final Object element = frameElement.getScriptableObject();
            final HTMLElement htmlElement = (HTMLElement) element;
            final ComputedCSSStyleDeclaration style =
                    htmlElement.getWindow().getComputedStyle(htmlElement, null);
            use = style.getCalculatedWidth(false, false) != 0
                    && style.getCalculatedHeight(false, false) != 0;
        }
    }
    if (use) {
        webClient_.setCurrentWindow(window);
    }
}
 
Example #13
Source File: HTMLIFrameElementTest.java    From htmlunit with Apache License 2.0 5 votes vote down vote up
/**
 * @throws Exception if the test fails
 */
@Test
public void removeFrameWindow() throws Exception {
    final String index = "<html><head></head><body>\n"
            + "<div id='content'>\n"
            + "  <iframe name='content' src='second/'></iframe>\n"
            + "</div>\n"
            + "<button id='clickId' "
            +     "onClick=\"document.getElementById('content').innerHTML = 'new content';\">Item</button>\n"
            + "</body></html>";

    final String frame1 = "<html><head></head><body>\n"
            + "<p>frame content</p>\n"
            + "</body></html>";

    final WebClient webClient = getWebClient();
    final MockWebConnection webConnection = getMockWebConnection();

    webConnection.setResponse(URL_SECOND, frame1);
    webClient.setWebConnection(webConnection);

    final HtmlPage page = loadPage(index);

    assertEquals("frame content", page.getElementById("content").asText());
    // check frame on page
    List<FrameWindow> frames = page.getFrames();
    assertEquals(1, frames.size());
    assertEquals("frame content", ((HtmlPage) page.getFrameByName("content").getEnclosedPage()).asText());

    // replace frame tag with javascript
    ((HtmlElement) page.getElementById("clickId")).click();

    assertEquals("new content", page.getElementById("content").asText());

    // frame has to be gone
    frames = page.getFrames();
    assertTrue(frames.isEmpty());
}
 
Example #14
Source File: HTMLDocumentWriteTest.java    From htmlunit with Apache License 2.0 5 votes vote down vote up
/**
 * @throws Exception if the test fails
 */
@Test
public void writeFrameRelativeURLMultipleFrameset() throws Exception {
    final String html = "<html><head><title>frameset</title></head>\n"
        + "<script>\n"
        + "    document.write('<frameset><frame src=\"frame.html\"/></frameset>');\n"
        + "</script>\n"
        + "<frameset><frame src='blank.html'/></frameset>\n"
        + "</html>";

    final URL baseURL = new URL("http://base/subdir/");
    final URL framesetURL = new URL(baseURL + "test.html");
    final URL frameURL = new URL(baseURL + "frame.html");
    final URL blankURL = new URL(baseURL + "blank.html");

    final WebClient client = getWebClient();
    final MockWebConnection webConnection = new MockWebConnection();
    webConnection.setResponse(framesetURL, html);
    webConnection.setResponseAsGenericHtml(frameURL, "frame");
    webConnection.setResponseAsGenericHtml(blankURL, "blank");
    client.setWebConnection(webConnection);

    final HtmlPage framesetPage = client.getPage(framesetURL);
    final FrameWindow frame = framesetPage.getFrames().get(0);
    final HtmlPage framePage = (HtmlPage) frame.getEnclosedPage();

    assertNotNull(frame);
    assertEquals(frameURL.toExternalForm(), framePage.getUrl().toExternalForm());
    assertEquals("frame", framePage.getTitleText());
}
 
Example #15
Source File: HtmlUnitNekoHtmlParser.java    From htmlunit with Apache License 2.0 5 votes vote down vote up
/**
 * Adds a body element to the current page, if necessary. Strictly speaking, this should
 * probably be done by NekoHTML. See the bug linked below. If and when that bug is fixed,
 * we may be able to get rid of this code.
 *
 * http://sourceforge.net/p/nekohtml/bugs/15/
 * @param page
 * @param originalCall
 * @param checkInsideFrameOnly true if the original page had body that was removed by JavaScript
 */
private void addBodyToPageIfNecessary(
        final HtmlPage page, final boolean originalCall, final boolean checkInsideFrameOnly) {
    // IE waits for the whole page to load before initializing bodies for frames.
    final boolean waitToLoad = page.hasFeature(PAGE_WAIT_LOAD_BEFORE_BODY);
    if (page.getEnclosingWindow() instanceof FrameWindow && originalCall && waitToLoad) {
        return;
    }

    // Find out if the document already has a body element (or frameset).
    final Element doc = page.getDocumentElement();
    boolean hasBody = false;
    for (Node child = doc.getFirstChild(); child != null; child = child.getNextSibling()) {
        if (child instanceof HtmlBody || child instanceof HtmlFrameSet) {
            hasBody = true;
            break;
        }
    }

    // If the document does not have a body, add it.
    if (!hasBody && !checkInsideFrameOnly) {
        final DomElement body = getFactory("body").createElement(page, "body", null);
        doc.appendChild(body);
    }

    // If this is IE, we need to initialize the bodies of any frames, as well.
    // This will already have been done when emulating FF (see above).
    if (waitToLoad) {
        for (final FrameWindow frame : page.getFrames()) {
            final Page containedPage = frame.getEnclosedPage();
            if (containedPage != null && containedPage.isHtmlPage()) {
                addBodyToPageIfNecessary((HtmlPage) containedPage, false, false);
            }
        }
    }
}
 
Example #16
Source File: HTMLIFrameElement.java    From htmlunit with Apache License 2.0 5 votes vote down vote up
/**
 * Returns the document the frame contains, if any.
 * @return {@code null} if no document is contained
 * @see <a href="http://www.mozilla.org/docs/dom/domref/dom_frame_ref4.html">Gecko DOM Reference</a>
 */
@JsxGetter
public DocumentProxy getContentDocument() {
    final FrameWindow frameWindow = getFrame().getEnclosedWindow();
    if (PageDenied.NONE != frameWindow.getPageDenied()) {
        if (getBrowserVersion().hasFeature(JS_FRAME_CONTENT_DOCUMENT_ACCESS_DENIED_THROWS)) {
            throw Context.reportRuntimeError("Error access denied");
        }
        return null;
    }
    return ((Window) frameWindow.getScriptableObject()).getDocument_js();
}
 
Example #17
Source File: HTMLDocument.java    From htmlunit with Apache License 2.0 5 votes vote down vote up
@Override
@JsxFunction({FF, FF68, FF60})
public void close() throws IOException {
    if (writeInCurrentDocument_) {
        LOG.warn("close() called when document is not open.");
    }
    else {
        final HtmlPage page = getPage();
        final URL url = page.getUrl();
        final StringWebResponse webResponse = new StringWebResponse(writeBuilder_.toString(), url);
        webResponse.setFromJavascript(true);
        writeInCurrentDocument_ = true;
        writeBuilder_.setLength(0);

        final WebClient webClient = page.getWebClient();
        final WebWindow window = page.getEnclosingWindow();
        // reset isAttachedToPageDuringOnload_ to trigger the onload event for chrome also
        if (window instanceof FrameWindow) {
            final BaseFrameElement frame = ((FrameWindow) window).getFrameElement();
            final ScriptableObject scriptable = frame.getScriptableObject();
            if (scriptable instanceof HTMLIFrameElement) {
                ((HTMLIFrameElement) scriptable).onRefresh();
            }
        }
        webClient.loadWebResponseInto(webResponse, window);
    }
}
 
Example #18
Source File: HTMLFrameElement.java    From htmlunit with Apache License 2.0 5 votes vote down vote up
/**
 * Returns the document the frame contains, if any.
 * @return {@code null} if no document is contained
 * @see <a href="http://www.mozilla.org/docs/dom/domref/dom_frame_ref4.html">Gecko DOM Reference</a>
 */
@JsxGetter
public DocumentProxy getContentDocument() {
    final FrameWindow frameWindow = getFrame().getEnclosedWindow();
    if (PageDenied.NONE != frameWindow.getPageDenied()) {
        if (getBrowserVersion().hasFeature(JS_FRAME_CONTENT_DOCUMENT_ACCESS_DENIED_THROWS)) {
            throw Context.reportRuntimeError("Error access denied");
        }
        return null;
    }
    return ((Window) frameWindow.getScriptableObject()).getDocument_js();
}
 
Example #19
Source File: Window.java    From htmlunit with Apache License 2.0 5 votes vote down vote up
@Override
protected Scriptable getScriptableForElement(final Object obj) {
    final WebWindow window;
    if (obj instanceof BaseFrameElement) {
        window = ((BaseFrameElement) obj).getEnclosedWindow();
    }
    else {
        window = ((FrameWindow) obj).getFrameElement().getEnclosedWindow();
    }

    return window.getScriptableObject();
}
 
Example #20
Source File: Window.java    From htmlunit with Apache License 2.0 5 votes vote down vote up
/**
 * Returns the current selection.
 * @return the current selection
 */
@JsxFunction
public Selection getSelection() {
    final WebWindow webWindow = getWebWindow();
    // return null if the window is in a frame that is not displayed
    if (webWindow instanceof FrameWindow) {
        final FrameWindow frameWindow = (FrameWindow) webWindow;
        if (getBrowserVersion().hasFeature(JS_WINDOW_SELECTION_NULL_IF_INVISIBLE)
                && !frameWindow.getFrameElement().isDisplayed()) {
            return null;
        }
    }
    return getSelectionImpl();
}
 
Example #21
Source File: WebClient.java    From htmlunit with Apache License 2.0 5 votes vote down vote up
/**
 * {@inheritDoc}
 */
@Override
public void webWindowContentChanged(final WebWindowEvent event) {
    final WebWindow window = event.getWebWindow();
    boolean use = false;
    if (window instanceof DialogWindow) {
        use = true;
    }
    else if (window instanceof TopLevelWindow) {
        use = event.getOldPage() == null;
    }
    else if (window instanceof FrameWindow) {
        final FrameWindow fw = (FrameWindow) window;
        final String enclosingPageState = fw.getEnclosingPage().getDocumentElement().getReadyState();
        final URL frameUrl = fw.getEnclosedPage().getUrl();
        if (!DomNode.READY_STATE_COMPLETE.equals(enclosingPageState) || frameUrl == URL_ABOUT_BLANK) {
            return;
        }

        // now looks at the visibility of the frame window
        final BaseFrameElement frameElement = fw.getFrameElement();
        if (webClient_.isJavaScriptEnabled() && frameElement.isDisplayed()) {
            final Object element = frameElement.getScriptableObject();
            final HTMLElement htmlElement = (HTMLElement) element;
            final ComputedCSSStyleDeclaration style =
                    htmlElement.getWindow().getComputedStyle(htmlElement, null);
            use = style.getCalculatedWidth(false, false) != 0
                    && style.getCalculatedHeight(false, false) != 0;
        }
    }
    if (use) {
        webClient_.setCurrentWindow(window);
    }
}
 
Example #22
Source File: WebClient.java    From HtmlUnit-Android with Apache License 2.0 4 votes vote down vote up
/**
 * <p>Creates a page based on the specified response and inserts it into the specified window. All page
 * initialization and event notification is handled here.</p>
 *
 * <p>Note that if the page created is an attachment page, and an {@link AttachmentHandler} has been
 * registered with this client, the page is <b>not</b> loaded into the specified window; in this case,
 * the page is loaded into a new window, and attachment handling is delegated to the registered
 * <tt>AttachmentHandler</tt>.</p>
 *
 * @param webResponse the response that will be used to create the new page
 * @param webWindow the window that the new page will be placed within
 * @throws IOException if an IO error occurs
 * @throws FailingHttpStatusCodeException if the server returns a failing status code AND the property
 *         {@link WebClientOptions#setThrowExceptionOnFailingStatusCode(boolean)} is set to true
 * @return the newly created page
 * @see #setAttachmentHandler(AttachmentHandler)
 */
public Page loadWebResponseInto(final WebResponse webResponse, final WebWindow webWindow)
    throws IOException, FailingHttpStatusCodeException {

    WebAssert.notNull("webResponse", webResponse);
    WebAssert.notNull("webWindow", webWindow);

    if (webResponse.getStatusCode() == HttpStatus.SC_NO_CONTENT) {
        return webWindow.getEnclosedPage();
    }

    if (webStartHandler_ != null && "application/x-java-jnlp-file".equals(webResponse.getContentType())) {
        webStartHandler_.handleJnlpResponse(webResponse);
        return webWindow.getEnclosedPage();
    }

    if (attachmentHandler_ != null && Attachment.isAttachment(webResponse)) {
        final WebWindow w = openWindow(null, null, webWindow);
        final Page page = pageCreator_.createPage(webResponse, w);
        attachmentHandler_.handleAttachment(page);
        return page;
    }

    final Page oldPage = webWindow.getEnclosedPage();
    if (oldPage != null) {
        // Remove the old windows before create new ones.
        oldPage.cleanUp();
    }
    Page newPage = null;
    if (windows_.contains(webWindow) || getBrowserVersion().hasFeature(WINDOW_EXECUTE_EVENTS)) {
        newPage = pageCreator_.createPage(webResponse, webWindow);

        if (windows_.contains(webWindow)) {
            fireWindowContentChanged(new WebWindowEvent(webWindow, WebWindowEvent.CHANGE, oldPage, newPage));

            // The page being loaded may already have been replaced by another page via JavaScript code.
            if (webWindow.getEnclosedPage() == newPage) {
                newPage.initialize();
                // hack: onload should be fired the same way for all type of pages
                // here is a hack to handle non HTML pages
                if (webWindow instanceof FrameWindow && !newPage.isHtmlPage()) {
                    final FrameWindow fw = (FrameWindow) webWindow;
                    final BaseFrameElement frame = fw.getFrameElement();
                    if (frame.hasEventHandlers("onload")) {
                        if (LOG.isDebugEnabled()) {
                            LOG.debug("Executing onload handler for " + frame);
                        }
                        final Event event = new Event(frame, Event.TYPE_LOAD);
                        ((Node) frame.getScriptableObject()).executeEventLocally(event);
                    }
                }
            }
        }
    }
    return newPage;
}
 
Example #23
Source File: WebWindowImpl.java    From htmlunit with Apache License 2.0 2 votes vote down vote up
/**
 * <p><span style="color:red">INTERNAL API - SUBJECT TO CHANGE AT ANY TIME - USE AT YOUR OWN RISK.</span></p>
 *
 * <p>Adds a child to this window, for shutdown purposes.</p>
 *
 * @param child the child window to associate with this window
 */
public void addChildWindow(final FrameWindow child) {
    synchronized (childWindows_) {
        childWindows_.add(child);
    }
}
 
Example #24
Source File: WebWindowImpl.java    From HtmlUnit-Android with Apache License 2.0 2 votes vote down vote up
/**
 * <p><span style="color:red">INTERNAL API - SUBJECT TO CHANGE AT ANY TIME - USE AT YOUR OWN RISK.</span></p>
 *
 * <p>Adds a child to this window, for shutdown purposes.</p>
 *
 * @param child the child window to associate with this window
 */
public void addChildWindow(final FrameWindow child) {
    synchronized (childWindows_) {
        childWindows_.add(child);
    }
}