use of com.gargoylesoftware.htmlunit.javascript.configuration.JsxFunction in project htmlunit by HtmlUnit.
the class XMLDOMElement method setAttributeNode.
/**
* Sets or updates the supplied attribute node on this element.
* @param newAtt the attribute node to be associated with this element
* @return the replaced attribute node, if any, {@code null} otherwise
*/
@JsxFunction
public XMLDOMAttribute setAttributeNode(final XMLDOMAttribute newAtt) {
if (newAtt == null) {
throw Context.reportRuntimeError("Type mismatch.");
}
final String name = newAtt.getBaseName();
final XMLDOMNamedNodeMap nodes = (XMLDOMNamedNodeMap) getAttributes();
final XMLDOMAttribute replacedAtt = (XMLDOMAttribute) nodes.getNamedItemWithoutSyntheticClassAttr(name);
if (replacedAtt != null) {
replacedAtt.detachFromParent();
}
final DomAttr newDomAttr = newAtt.getDomNodeOrDie();
getDomNodeOrDie().setAttributeNode(newDomAttr);
return replacedAtt;
}
use of com.gargoylesoftware.htmlunit.javascript.configuration.JsxFunction in project htmlunit by HtmlUnit.
the class HTMLCollectionFrames method showModelessDialog.
/**
* Creates a modeless dialog box that displays the specified HTML document.
* @param url the URL of the document to load and display
* @param arguments object to be made available via <tt>window.dialogArguments</tt> in the dialog window
* @param features string that specifies the window ornaments for the dialog window
* @return a reference to the new window object created for the modeless dialog
* @see <a href="http://msdn.microsoft.com/en-us/library/ms536761.aspx">MSDN Documentation</a>
*/
@JsxFunction(IE)
public Object showModelessDialog(final String url, final Object arguments, final String features) {
final WebWindow webWindow = getWebWindow();
final WebClient client = webWindow.getWebClient();
try {
final URL completeUrl = ((HtmlPage) getDomNodeOrDie()).getFullyQualifiedUrl(url);
final DialogWindow dialog = client.openDialogWindow(completeUrl, webWindow, arguments);
return dialog.getScriptableObject();
} catch (final IOException e) {
throw Context.throwAsScriptRuntimeEx(e);
}
}
use of com.gargoylesoftware.htmlunit.javascript.configuration.JsxFunction in project htmlunit by HtmlUnit.
the class HTMLCollectionFrames method focus.
/**
* Sets the focus to this element.
*/
@JsxFunction
public void focus() {
final WebWindow window = getWebWindow();
window.getWebClient().setCurrentWindow(window);
}
use of com.gargoylesoftware.htmlunit.javascript.configuration.JsxFunction in project htmlunit by HtmlUnit.
the class HTMLCollectionFrames method postMessage.
/**
* Posts a message.
* @param message the object passed to the window
* @param targetOrigin the origin this window must be for the event to be dispatched
* @param transfer an optional sequence of Transferable objects
* @see <a href="https://developer.mozilla.org/en-US/docs/Web/API/window.postMessage">MDN documentation</a>
*/
@JsxFunction
public void postMessage(final String message, final String targetOrigin, final Object transfer) {
final WebWindow webWindow = getWebWindow();
final Page page = webWindow.getEnclosedPage();
final URL currentURL = page.getUrl();
if (!"*".equals(targetOrigin) && !"/".equals(targetOrigin)) {
final URL targetURL;
try {
targetURL = new URL(targetOrigin);
} catch (final Exception e) {
throw Context.throwAsScriptRuntimeEx(new Exception("SyntaxError: Failed to execute 'postMessage' on 'Window': Invalid target origin '" + targetOrigin + "' was specified (reason: " + e.getMessage() + "."));
}
if (getPort(targetURL) != getPort(currentURL)) {
return;
}
if (!targetURL.getHost().equals(currentURL.getHost())) {
return;
}
if (!targetURL.getProtocol().equals(currentURL.getProtocol())) {
return;
}
}
final MessageEvent event = new MessageEvent();
final String origin = currentURL.getProtocol() + "://" + currentURL.getHost() + ':' + currentURL.getPort();
event.initMessageEvent(Event.TYPE_MESSAGE, false, false, message, origin, "", this, transfer);
event.setParentScope(this);
event.setPrototype(getPrototype(event.getClass()));
final JavaScriptEngine jsEngine = (JavaScriptEngine) webWindow.getWebClient().getJavaScriptEngine();
final PostponedAction action = new PostponedAction(page, "Window.postMessage") {
@Override
public void execute() throws Exception {
final ContextAction<Object> contextAction = cx -> dispatchEvent(event);
final ContextFactory cf = jsEngine.getContextFactory();
cf.call(contextAction);
}
};
jsEngine.addPostponedAction(action);
}
use of com.gargoylesoftware.htmlunit.javascript.configuration.JsxFunction in project htmlunit by HtmlUnit.
the class HTMLCollectionFrames method scrollByLines.
/**
* Scrolls the window content down by the specified number of lines.
* @param lines the number of lines to scroll down
*/
@JsxFunction({ FF, FF_ESR })
public void scrollByLines(final int lines) {
final HTMLElement body = document_.getBody();
if (body != null) {
body.setScrollTop(body.getScrollTop() + (19 * lines));
final Event event = new Event(body, Event.TYPE_SCROLL);
body.fireEvent(event);
}
}
Aggregations