use of com.gargoylesoftware.htmlunit.javascript.host.Window in project htmlunit by HtmlUnit.
the class WebWindowImpl method setEnclosedPage.
/**
* {@inheritDoc}
*/
@Override
public void setEnclosedPage(final Page page) {
if (LOG.isDebugEnabled()) {
LOG.debug("setEnclosedPage: " + page);
}
if (page == enclosedPage_) {
return;
}
destroyChildren();
if (isJavaScriptInitializationNeeded(page)) {
webClient_.initialize(this, page);
}
if (webClient_.isJavaScriptEngineEnabled()) {
final Window window = getScriptableObject();
window.initialize(page);
}
// has to be done after page initialization to make sure
// the enclosedPage has a scriptable object
enclosedPage_ = page;
history_.addPage(page);
}
use of com.gargoylesoftware.htmlunit.javascript.host.Window in project htmlunit by HtmlUnit.
the class MutationObserver method attributeReplaced.
/**
* {@inheritDoc}
*/
@Override
public void attributeReplaced(final HtmlAttributeChangeEvent event) {
final HtmlElement target = event.getHtmlElement();
if (subtree_ || target == node_.getDomNodeOrDie()) {
final String attributeName = event.getName();
if (attributeFilter_ == null || attributeFilter_.contains(attributeName)) {
final MutationRecord mutationRecord = new MutationRecord();
final Scriptable scope = getParentScope();
mutationRecord.setParentScope(scope);
mutationRecord.setPrototype(getPrototype(mutationRecord.getClass()));
mutationRecord.setAttributeName(attributeName);
mutationRecord.setType("attributes");
mutationRecord.setTarget(target.getScriptableObject());
if (attributeOldValue_) {
mutationRecord.setOldValue(event.getValue());
}
final Window window = getWindow();
final HtmlPage owningPage = (HtmlPage) window.getDocument().getPage();
final JavaScriptEngine jsEngine = (JavaScriptEngine) window.getWebWindow().getWebClient().getJavaScriptEngine();
jsEngine.addPostponedAction(new PostponedAction(owningPage, "MutationObserver.attributeReplaced") {
@Override
public void execute() throws Exception {
final NativeArray array = new NativeArray(new Object[] { mutationRecord });
ScriptRuntime.setBuiltinProtoAndParent(array, scope, TopLevel.Builtins.Array);
jsEngine.callFunction(owningPage, function_, scope, MutationObserver.this, new Object[] { array });
}
});
}
}
}
use of com.gargoylesoftware.htmlunit.javascript.host.Window in project htmlunit by HtmlUnit.
the class HTMLStyleElement method getSheet.
/**
* Gets the associated sheet.
* @see <a href="http://www.xulplanet.com/references/objref/HTMLStyleElement.html">Mozilla doc</a>
* @return the sheet
*/
@JsxGetter
public CSSStyleSheet getSheet() {
if (sheet_ != null) {
return sheet_;
}
final HtmlStyle style = (HtmlStyle) getDomNodeOrDie();
final String css = style.getTextContent();
final Window window = getWindow();
final Cache cache = window.getWebWindow().getWebClient().getCache();
final CSSStyleSheetImpl cached = cache.getCachedStyleSheet(css);
final String uri = getDomNodeOrDie().getPage().getWebResponse().getWebRequest().getUrl().toExternalForm();
if (cached != null) {
sheet_ = new CSSStyleSheet(this, window, cached, uri);
} else {
sheet_ = new CSSStyleSheet(this, css, uri);
cache.cache(css, sheet_.getWrappedSheet());
}
return sheet_;
}
use of com.gargoylesoftware.htmlunit.javascript.host.Window in project htmlunit by HtmlUnit.
the class AudioContext method decodeAudioData.
/**
* The decodeAudioData() method of the BaseAudioContext Interface is used to asynchronously
* decode audio file data contained in an ArrayBuffer. In this case the ArrayBuffer is
* loaded from XMLHttpRequest and FileReader.
* The decoded AudioBuffer is resampled to the AudioContext's sampling rate,
* then passed to a callback or promise.
* @param buffer An ArrayBuffer containing the audio data to be decoded, usually grabbed
* from XMLHttpRequest, WindowOrWorkerGlobalScope.fetch() or FileReader
* @param success A callback function to be invoked when the decoding successfully finishes.
* The single argument to this callback is an AudioBuffer representing the decodedData
* (the decoded PCM audio data). Usually you'll want to put the decoded data into
* an AudioBufferSourceNode, from which it can be played and manipulated how you want.
* @param error An optional error callback, to be invoked if an error occurs
* when the audio data is being decoded.
* @return the promise or null
*/
@JsxFunction
public Object decodeAudioData(final NativeArrayBuffer buffer, final Function success, final Function error) {
final Window window = getWindow();
final HtmlPage owningPage = (HtmlPage) window.getDocument().getPage();
final JavaScriptEngine jsEngine = (JavaScriptEngine) window.getWebWindow().getWebClient().getJavaScriptEngine();
if (error != null) {
jsEngine.addPostponedAction(new PostponedAction(owningPage, "AudioContext.decodeAudioData") {
@Override
public void execute() throws Exception {
jsEngine.callFunction(owningPage, error, getParentScope(), AudioContext.this, new Object[] {});
}
});
return null;
}
final Scriptable scope = ScriptableObject.getTopLevelScope(this);
final LambdaConstructor ctor = (LambdaConstructor) getProperty(scope, "Promise");
final LambdaFunction reject = (LambdaFunction) getProperty(ctor, "reject");
return reject.call(Context.getCurrentContext(), this, ctor, new Object[] {});
}
use of com.gargoylesoftware.htmlunit.javascript.host.Window in project htmlunit by HtmlUnit.
the class DateTimeFormat method jsConstructor.
/**
* JavaScript constructor.
* @param cx the current context
* @param args the arguments to the WebSocket constructor
* @param ctorObj the function object
* @param inNewExpr Is new or not
* @return the java object to allow JavaScript to access
*/
@JsxConstructor
public static Scriptable jsConstructor(final Context cx, final Object[] args, final Function ctorObj, final boolean inNewExpr) {
final String[] locales;
if (args.length != 0) {
if (args[0] instanceof NativeArray) {
final NativeArray array = (NativeArray) args[0];
locales = new String[(int) array.getLength()];
for (int i = 0; i < locales.length; i++) {
locales[i] = Context.toString(array.get(i));
}
} else {
locales = new String[] { Context.toString(args[0]) };
}
} else {
locales = new String[] { "" };
}
final Window window = getWindow(ctorObj);
final DateTimeFormat format = new DateTimeFormat(locales, window.getBrowserVersion());
format.setParentScope(window);
format.setPrototype(window.getPrototype(format.getClass()));
return format;
}
Aggregations