Java Code Examples for com.gargoylesoftware.htmlunit.html.BaseFrameElement#getScriptableObject()

The following examples show how to use com.gargoylesoftware.htmlunit.html.BaseFrameElement#getScriptableObject() . 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: 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 2
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 3
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 4
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);
    }
}