use of com.gargoylesoftware.htmlunit.javascript.configuration.JsxFunction in project htmlunit by HtmlUnit.
the class HTMLCollectionFrames method alert.
/**
* The JavaScript function {@code alert()}.
* @param message the message
*/
@JsxFunction
public void alert(final Object message) {
// use Object as parameter and perform String conversion by ourself
// this allows to place breakpoint here and "see" the message object and its properties
final String stringMessage = Context.toString(message);
final AlertHandler handler = getWebWindow().getWebClient().getAlertHandler();
if (handler == null) {
if (LOG.isWarnEnabled()) {
LOG.warn("window.alert(\"" + stringMessage + "\") no alert handler installed");
}
} else {
handler.handleAlert(document_.getPage(), stringMessage);
}
}
use of com.gargoylesoftware.htmlunit.javascript.configuration.JsxFunction in project htmlunit by HtmlUnit.
the class HTMLCollectionFrames method open.
/**
* Opens a new window.
*
* @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 the newly opened window, or {@code null} if popup windows have been disabled
* @see com.gargoylesoftware.htmlunit.WebClientOptions#isPopupBlockerEnabled()
* @see <a href="http://msdn.microsoft.com/en-us/library/ms536651.aspx">MSDN documentation</a>
*/
@JsxFunction
public WindowProxy open(final Object url, final Object name, final Object features, final Object replace) {
String urlString = null;
if (!Undefined.isUndefined(url)) {
urlString = Context.toString(url);
}
String windowName = "";
if (!Undefined.isUndefined(name)) {
windowName = Context.toString(name);
}
String featuresString = null;
if (!Undefined.isUndefined(features)) {
featuresString = Context.toString(features);
}
final WebClient webClient = getWebWindow().getWebClient();
if (webClient.getOptions().isPopupBlockerEnabled()) {
if (LOG.isDebugEnabled()) {
LOG.debug("Ignoring window.open() invocation because popups are blocked.");
}
return null;
}
boolean replaceCurrentEntryInBrowsingHistory = false;
if (!Undefined.isUndefined(replace)) {
replaceCurrentEntryInBrowsingHistory = Context.toBoolean(replace);
}
if ((featuresString != null || replaceCurrentEntryInBrowsingHistory) && LOG.isDebugEnabled()) {
LOG.debug("window.open: features and replaceCurrentEntryInBrowsingHistory " + "not implemented: url=[" + urlString + "] windowName=[" + windowName + "] features=[" + featuresString + "] replaceCurrentEntry=[" + replaceCurrentEntryInBrowsingHistory + "]");
}
// if specified name is the name of an existing window, then hold it
if (StringUtils.isEmpty(urlString) && !"".equals(windowName)) {
try {
final WebWindow webWindow = webClient.getWebWindowByName(windowName);
return getProxy(webWindow);
} catch (final WebWindowNotFoundException e) {
// nothing
}
}
final URL newUrl = makeUrlForOpenWindow(urlString);
final WebWindow newWebWindow = webClient.openWindow(newUrl, windowName, webWindow_);
return getProxy(newWebWindow);
}
use of com.gargoylesoftware.htmlunit.javascript.configuration.JsxFunction in project htmlunit by HtmlUnit.
the class HTMLCollectionFrames method scrollByPages.
/**
* Scrolls the window content down by the specified number of pages.
* @param pages the number of pages to scroll down
*/
@JsxFunction({ FF, FF_ESR })
public void scrollByPages(final int pages) {
final HTMLElement body = document_.getBody();
if (body != null) {
body.setScrollTop(body.getScrollTop() + (getInnerHeight() * pages));
final Event event = new Event(body, Event.TYPE_SCROLL);
body.fireEvent(event);
}
}
use of com.gargoylesoftware.htmlunit.javascript.configuration.JsxFunction in project htmlunit by HtmlUnit.
the class HTMLCollectionFrames method matchMedia.
/**
* Returns a new MediaQueryList object representing the parsed results of the specified media query string.
*
* @param mediaQueryString the media query
* @return a new MediaQueryList object
*/
@JsxFunction
public MediaQueryList matchMedia(final String mediaQueryString) {
final MediaQueryList mediaQueryList = new MediaQueryList(mediaQueryString);
mediaQueryList.setParentScope(this);
mediaQueryList.setPrototype(getPrototype(mediaQueryList.getClass()));
return mediaQueryList;
}
use of com.gargoylesoftware.htmlunit.javascript.configuration.JsxFunction in project htmlunit by HtmlUnit.
the class XMLHTTPRequest method open.
/**
* Initializes the request and specifies the method, URL, and authentication information for the request.
* @param method the HTTP method used to open the connection, such as GET, POST, PUT, or PROPFIND;
* for XMLHTTP, this parameter is not case-sensitive; the verbs TRACE and TRACK are not allowed.
* @param url the requested URL; this can be either an absolute URL or a relative URL
* @param asyncParam indicator of whether the call is asynchronous; the default is {@code true} (the call
* returns immediately); if set to {@code true}, attach an <code>onreadystatechange</code> property
* callback so that you can tell when the <code>send</code> call has completed
* @param user the name of the user for authentication
* @param password the password for authentication
*/
@JsxFunction
public void open(final String method, final Object url, final Object asyncParam, final Object user, final Object password) {
if (method == null || "null".equals(method)) {
throw Context.reportRuntimeError("Type mismatch (method is null).");
}
if (url == null || "null".equals(url)) {
throw Context.reportRuntimeError("Type mismatch (url is null).");
}
state_ = STATE_UNSENT;
openedMultipleTimes_ = webRequest_ != null;
sent_ = false;
webRequest_ = null;
webResponse_ = null;
if ("".equals(method) || "TRACE".equalsIgnoreCase(method)) {
throw Context.reportRuntimeError("Invalid procedure call or argument (method is invalid).");
}
if ("".equals(url)) {
throw Context.reportRuntimeError("Invalid procedure call or argument (url is empty).");
}
// defaults to true if not specified
boolean async = true;
if (!Undefined.isUndefined(asyncParam)) {
async = ScriptRuntime.toBoolean(asyncParam);
}
final String urlAsString = Context.toString(url);
// (URL + Method + User + Password) become a WebRequest instance.
containingPage_ = (HtmlPage) getWindow().getWebWindow().getEnclosedPage();
try {
final URL fullUrl = containingPage_.getFullyQualifiedUrl(urlAsString);
final WebRequest request = new WebRequest(fullUrl);
request.setCharset(UTF_8);
request.setAdditionalHeader(HttpHeader.REFERER, containingPage_.getUrl().toExternalForm());
request.setHttpMethod(HttpMethod.valueOf(method.toUpperCase(Locale.ROOT)));
// password is ignored if no user defined
if (user != null && !Undefined.isUndefined(user)) {
final String userCred = user.toString();
String passwordCred = "";
if (password != null && !Undefined.isUndefined(password)) {
passwordCred = password.toString();
}
request.setCredentials(new UsernamePasswordCredentials(userCred, passwordCred));
}
webRequest_ = request;
} catch (final MalformedURLException e) {
if (LOG.isErrorEnabled()) {
LOG.error("Unable to initialize XMLHTTPRequest using malformed URL '" + urlAsString + "'.");
}
return;
} catch (final IllegalArgumentException e) {
if (LOG.isErrorEnabled()) {
LOG.error("Unable to initialize XMLHTTPRequest using illegal argument '" + e.getMessage() + "'.");
}
webRequest_ = null;
}
// Async stays a boolean.
async_ = async;
// Change the state!
setState(STATE_OPENED, null);
}
Aggregations