Search in sources :

Example 1 with ActiveXObjectImpl

use of com.gargoylesoftware.htmlunit.javascript.host.ActiveXObjectImpl in project htmlunit by HtmlUnit.

the class HTMLObjectElement method setClassid.

/**
 * Sets the {@code classid} attribute.
 * @param classid the {@code classid} attribute
 */
@JsxSetter(IE)
public void setClassid(final String classid) {
    getDomNodeOrDie().setAttribute("classid", classid);
    if (classid.indexOf(':') != -1 && getBrowserVersion().hasFeature(HTML_OBJECT_CLASSID)) {
        final WebClient webClient = getWindow().getWebWindow().getWebClient();
        final Map<String, String> map = webClient.getActiveXObjectMap();
        if (map != null) {
            final String xClassString = map.get(classid);
            if (xClassString != null) {
                try {
                    final Class<?> xClass = Class.forName(xClassString);
                    final Object object = xClass.newInstance();
                    boolean contextCreated = false;
                    if (Context.getCurrentContext() == null) {
                        new HtmlUnitContextFactory(webClient).enterContext();
                        contextCreated = true;
                    }
                    wrappedActiveX_ = Context.toObject(object, getParentScope());
                    if (contextCreated) {
                        Context.exit();
                    }
                } catch (final Exception e) {
                    throw Context.reportRuntimeError("ActiveXObject Error: failed instantiating class " + xClassString + " because " + e.getMessage() + ".");
                }
                return;
            }
        }
        if (webClient.getOptions().isActiveXNative() && System.getProperty("os.name").contains("Windows")) {
            try {
                wrappedActiveX_ = new ActiveXObjectImpl(classid);
                wrappedActiveX_.setParentScope(getParentScope());
            } catch (final Exception e) {
                Context.throwAsScriptRuntimeEx(e);
            }
        }
    }
}
Also used : HtmlUnitContextFactory(com.gargoylesoftware.htmlunit.javascript.HtmlUnitContextFactory) ScriptableObject(net.sourceforge.htmlunit.corejs.javascript.ScriptableObject) HtmlObject(com.gargoylesoftware.htmlunit.html.HtmlObject) NativeJavaObject(net.sourceforge.htmlunit.corejs.javascript.NativeJavaObject) ActiveXObjectImpl(com.gargoylesoftware.htmlunit.javascript.host.ActiveXObjectImpl) WebClient(com.gargoylesoftware.htmlunit.WebClient) JsxSetter(com.gargoylesoftware.htmlunit.javascript.configuration.JsxSetter)

Aggregations

WebClient (com.gargoylesoftware.htmlunit.WebClient)1 HtmlObject (com.gargoylesoftware.htmlunit.html.HtmlObject)1 HtmlUnitContextFactory (com.gargoylesoftware.htmlunit.javascript.HtmlUnitContextFactory)1 JsxSetter (com.gargoylesoftware.htmlunit.javascript.configuration.JsxSetter)1 ActiveXObjectImpl (com.gargoylesoftware.htmlunit.javascript.host.ActiveXObjectImpl)1 NativeJavaObject (net.sourceforge.htmlunit.corejs.javascript.NativeJavaObject)1 ScriptableObject (net.sourceforge.htmlunit.corejs.javascript.ScriptableObject)1