Search in sources :

Example 86 with JsxFunction

use of com.gargoylesoftware.htmlunit.javascript.configuration.JsxFunction in project htmlunit by HtmlUnit.

the class History method replaceState.

/**
 * Replaces a state.
 * @param object the state object
 * @param title the title
 * @param url an optional URL
 */
@JsxFunction
public void replaceState(final Object object, final String title, final String url) {
    final WebWindow w = getWindow().getWebWindow();
    try {
        URL newStateUrl = null;
        final HtmlPage page = (HtmlPage) w.getEnclosedPage();
        if (StringUtils.isNotBlank(url)) {
            newStateUrl = page.getFullyQualifiedUrl(url);
        }
        w.getHistory().replaceState(object, newStateUrl);
    } catch (final MalformedURLException e) {
        Context.throwAsScriptRuntimeEx(e);
    }
}
Also used : MalformedURLException(java.net.MalformedURLException) HtmlPage(com.gargoylesoftware.htmlunit.html.HtmlPage) URL(java.net.URL) WebWindow(com.gargoylesoftware.htmlunit.WebWindow) JsxFunction(com.gargoylesoftware.htmlunit.javascript.configuration.JsxFunction)

Example 87 with JsxFunction

use of com.gargoylesoftware.htmlunit.javascript.configuration.JsxFunction in project htmlunit by HtmlUnit.

the class History method pushState.

/**
 * Pushes a state.
 * @param object the state object
 * @param title the title
 * @param url an optional URL
 */
@JsxFunction
public void pushState(final Object object, final String title, final String url) {
    final WebWindow w = getWindow().getWebWindow();
    try {
        URL newStateUrl = null;
        final HtmlPage page = (HtmlPage) w.getEnclosedPage();
        if (StringUtils.isNotBlank(url)) {
            newStateUrl = page.getFullyQualifiedUrl(url);
        }
        w.getHistory().pushState(object, newStateUrl);
    } catch (final IOException e) {
        Context.throwAsScriptRuntimeEx(e);
    }
}
Also used : HtmlPage(com.gargoylesoftware.htmlunit.html.HtmlPage) IOException(java.io.IOException) URL(java.net.URL) WebWindow(com.gargoylesoftware.htmlunit.WebWindow) JsxFunction(com.gargoylesoftware.htmlunit.javascript.configuration.JsxFunction)

Example 88 with JsxFunction

use of com.gargoylesoftware.htmlunit.javascript.configuration.JsxFunction in project htmlunit by HtmlUnit.

the class Location method reload.

/**
 * 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 WebWindow webWindow = window_.getWebWindow();
    final HtmlPage htmlPage = (HtmlPage) webWindow.getEnclosedPage();
    final WebRequest request = htmlPage.getWebResponse().getWebRequest();
    if (webWindow.getWebClient().getBrowserVersion().hasFeature(JS_LOCATION_RELOAD_REFERRER)) {
        request.setRefererlHeader(htmlPage.getUrl());
    }
    webWindow.getWebClient().download(webWindow, "", request, true, false, false, "JS location.reload");
}
Also used : WebRequest(com.gargoylesoftware.htmlunit.WebRequest) HtmlPage(com.gargoylesoftware.htmlunit.html.HtmlPage) WebWindow(com.gargoylesoftware.htmlunit.WebWindow) JsxFunction(com.gargoylesoftware.htmlunit.javascript.configuration.JsxFunction)

Example 89 with JsxFunction

use of com.gargoylesoftware.htmlunit.javascript.configuration.JsxFunction in project htmlunit by HtmlUnit.

the class Console method error.

/**
 * This method performs logging to the console at {@code error} level.
 * @param cx the JavaScript context
 * @param thisObj the scriptable
 * @param args the arguments passed into the method
 * @param funObj the function
 */
@JsxFunction
public static void error(final Context cx, final Scriptable thisObj, final Object[] args, final Function funObj) {
    final WebConsole webConsole = toWebConsole(thisObj);
    final Formatter oldFormatter = webConsole.getFormatter();
    webConsole.setFormatter(FORMATTER_);
    webConsole.error(args);
    webConsole.setFormatter(oldFormatter);
}
Also used : WebConsole(com.gargoylesoftware.htmlunit.WebConsole) Formatter(com.gargoylesoftware.htmlunit.WebConsole.Formatter) JsxFunction(com.gargoylesoftware.htmlunit.javascript.configuration.JsxFunction)

Example 90 with JsxFunction

use of com.gargoylesoftware.htmlunit.javascript.configuration.JsxFunction in project htmlunit by HtmlUnit.

the class Console method dir.

/**
 * Implementation of console {@code dir} function. This method does not enter recursively
 * in the passed object, nor prints the details of objects or functions.
 * @param o the object to be printed
 */
@JsxFunction
public void dir(final Object o) {
    if (o instanceof ScriptableObject) {
        final ScriptableObject obj = (ScriptableObject) o;
        final Object[] ids = obj.getIds();
        if (ids != null && ids.length > 0) {
            final StringBuilder sb = new StringBuilder();
            for (final Object id : ids) {
                final Object value = obj.get(id);
                if (value instanceof Delegator) {
                    sb.append(id).append(": ").append(((Delegator) value).getClassName()).append('\n');
                } else if (value instanceof HtmlUnitScriptable) {
                    sb.append(id).append(": ").append(((HtmlUnitScriptable) value).getClassName()).append('\n');
                } else if (value instanceof BaseFunction) {
                    sb.append(id).append(": function ").append(((BaseFunction) value).getFunctionName()).append("()\n");
                } else {
                    sb.append(id).append(": ").append(value).append('\n');
                }
            }
            getWebConsole().info(sb.toString());
        }
    }
}
Also used : HtmlUnitScriptable(com.gargoylesoftware.htmlunit.javascript.HtmlUnitScriptable) BaseFunction(net.sourceforge.htmlunit.corejs.javascript.BaseFunction) ScriptableObject(net.sourceforge.htmlunit.corejs.javascript.ScriptableObject) Delegator(net.sourceforge.htmlunit.corejs.javascript.Delegator) ScriptableObject(net.sourceforge.htmlunit.corejs.javascript.ScriptableObject) NativeObject(net.sourceforge.htmlunit.corejs.javascript.NativeObject) JsxFunction(com.gargoylesoftware.htmlunit.javascript.configuration.JsxFunction)

Aggregations

JsxFunction (com.gargoylesoftware.htmlunit.javascript.configuration.JsxFunction)133 DomNode (com.gargoylesoftware.htmlunit.html.DomNode)30 HtmlPage (com.gargoylesoftware.htmlunit.html.HtmlPage)20 ScriptableObject (net.sourceforge.htmlunit.corejs.javascript.ScriptableObject)19 WebWindow (com.gargoylesoftware.htmlunit.WebWindow)16 URL (java.net.URL)14 IOException (java.io.IOException)11 Scriptable (net.sourceforge.htmlunit.corejs.javascript.Scriptable)11 WebClient (com.gargoylesoftware.htmlunit.WebClient)10 DomElement (com.gargoylesoftware.htmlunit.html.DomElement)10 SimpleRange (com.gargoylesoftware.htmlunit.html.impl.SimpleRange)10 Event (com.gargoylesoftware.htmlunit.javascript.host.event.Event)10 SgmlPage (com.gargoylesoftware.htmlunit.SgmlPage)8 HtmlUnitScriptable (com.gargoylesoftware.htmlunit.javascript.HtmlUnitScriptable)8 MessageEvent (com.gargoylesoftware.htmlunit.javascript.host.event.MessageEvent)8 HTMLElement (com.gargoylesoftware.htmlunit.javascript.host.html.HTMLElement)8 NameValuePair (com.gargoylesoftware.htmlunit.util.NameValuePair)8 Range (org.w3c.dom.ranges.Range)8 HtmlAttributeChangeEvent (com.gargoylesoftware.htmlunit.html.HtmlAttributeChangeEvent)7 HtmlElement (com.gargoylesoftware.htmlunit.html.HtmlElement)7