Package com.gargoylesoftware.htmlunit.javascript.host

Examples of com.gargoylesoftware.htmlunit.javascript.host.Window


    @Override
    public void initialize(WebWindow webWindow) {
      // Hook in the hosted-mode plugin after initializing the JS engine.
      super.initialize(webWindow);
      Window window = (Window) webWindow.getScriptObject();
      window.defineProperty("__gwt_HostedModePlugin",
          new HostedModePluginObject(this), ScriptableObject.READONLY);
    }
View Full Code Here


    @Override
    public void initialize(WebWindow webWindow) {
      // Hook in the hosted-mode plugin after initializing the JS engine.
      super.initialize(webWindow);
      Window window = (Window) webWindow.getScriptObject();
      window.defineProperty("__gwt_HostedModePlugin",
          new HostedModePluginObject(this), ScriptableObject.READONLY);
    }
View Full Code Here

    @Override
    public void initialize(WebWindow webWindow) {
      // Hook in the hosted-mode plugin after initializing the JS engine.
      super.initialize(webWindow);
      Window window = (Window) webWindow.getScriptObject();
      window.defineProperty("__gwt_HostedModePlugin",
          new HostedModePluginObject(this, logger), ScriptableObject.READONLY);
    }
View Full Code Here

        });
        firephoque.setThrowExceptionOnFailingStatusCode(false);
        firephoque.setAlertHandler(new AlertHandler() {
            public void handleAlert(Page page, String string) {
                try {
                    Window window = (Window)page.getEnclosingWindow().getScriptObject();
                    window.custom_eval(
                        "parent.selenium.browserbot.recordedAlerts.push('" + string.replace("'", "\\'")+ "');"
                    );
                } catch(Exception e) {
                    e.printStackTrace();
                }
            }
        });
        firephoque.setConfirmHandler(new ConfirmHandler() {
            public boolean handleConfirm(Page page, String string) {
                try {
                    Window window = (Window)page.getEnclosingWindow().getScriptObject();
                    Object result = window.custom_eval(
                        "parent.selenium.browserbot.recordedConfirmations.push('" + string.replace("'", "\\'")+ "');" +
                        "var result = parent.selenium.browserbot.nextConfirmResult;" +
                        "parent.selenium.browserbot.nextConfirmResult = true;" +
                        "result"
                    );
                    return (Boolean)result;
                } catch(Exception e) {
                    e.printStackTrace();
                    return false;
                }
            }
        });
        firephoque.setPromptHandler(new PromptHandler() {
            public String handlePrompt(Page page, String string) {
                try {
                    Window window = (Window)page.getEnclosingWindow().getScriptObject();
                    Object result = window.custom_eval(
                        "parent.selenium.browserbot.recordedPrompts.push('" + string.replace("'", "\\'")+ "');" +
                        "var result = !parent.selenium.browserbot.nextConfirmResult ? null : parent.selenium.browserbot.nextPromptResult;" +
                        "parent.selenium.browserbot.nextConfirmResult = true;" +
                        "parent.selenium.browserbot.nextPromptResult = '';" +
                        "result"
View Full Code Here

        });
        firephoque.setThrowExceptionOnFailingStatusCode(false);
        firephoque.setAlertHandler(new AlertHandler() {
            public void handleAlert(Page page, String string) {
                try {
                    Window window = (Window)page.getEnclosingWindow().getScriptObject();
                    window.custom_eval(
                        "parent.selenium.browserbot.recordedAlerts.push('" + string.replace("'", "\\'")+ "');"
                    );
                } catch(Exception e) {
                    e.printStackTrace();
                }
            }
        });
        firephoque.setConfirmHandler(new ConfirmHandler() {
            public boolean handleConfirm(Page page, String string) {
                try {
                    Window window = (Window)page.getEnclosingWindow().getScriptObject();
                    Object result = window.custom_eval(
                        "parent.selenium.browserbot.recordedConfirmations.push('" + string.replace("'", "\\'")+ "');" +
                        "var result = parent.selenium.browserbot.nextConfirmResult;" +
                        "parent.selenium.browserbot.nextConfirmResult = true;" +
                        "result"
                    );
                    return (Boolean)result;
                } catch(Exception e) {
                    e.printStackTrace();
                    return false;
                }
            }
        });
        firephoque.setPromptHandler(new PromptHandler() {
            public String handlePrompt(Page page, String string) {
                try {
                    Window window = (Window)page.getEnclosingWindow().getScriptObject();
                    Object result = window.custom_eval(
                        "parent.selenium.browserbot.recordedPrompts.push('" + string.replace("'", "\\'")+ "');" +
                        "var result = !parent.selenium.browserbot.nextConfirmResult ? null : parent.selenium.browserbot.nextPromptResult;" +
                        "parent.selenium.browserbot.nextConfirmResult = true;" +
                        "parent.selenium.browserbot.nextPromptResult = '';" +
                        "result"
View Full Code Here

    @Override
    public void initialize(WebWindow webWindow) {
      // Hook in the hosted-mode plugin after initializing the JS engine.
      super.initialize(webWindow);
      Window window = (Window) webWindow.getScriptObject();
      window.defineProperty("__gwt_HostedModePlugin",
          new HostedModePluginObject(this), ScriptableObject.READONLY);
    }
View Full Code Here

        currentWindow_ = window;
        //1. In IE activeElement becomes focused element for new current window
        //2. onFocus event is triggered for focusedElement of new current window
        final Page enclosedPage = currentWindow_.getEnclosedPage();
        if (enclosedPage instanceof HtmlPage) {
            final Window jsWindow = (Window) currentWindow_.getScriptObject();
            if (jsWindow != null) {
                if (getBrowserVersion().isIE()) {
                    final HTMLElement activeElement = (HTMLElement) jsWindow.jsxGet_document().jsxGet_activeElement();
                    if (activeElement != null) {
                        ((HtmlPage) enclosedPage).setFocusedElement(activeElement.getDomNodeOrDie(), true);
                    }
                }
                else {
View Full Code Here

            }
        }
        else {
            initializeEmptyWindow(window);
            if (openerPage != null) {
                final Window jsWindow = (Window) window.getScriptObject();
                jsWindow.setDomNode(openerPage);
                jsWindow.jsxGet_document().setDomNode(openerPage);
            }
        }
        return window;
    }
View Full Code Here

            else if (getBrowserVersion().getBrowserVersionNumeric() >= 3) { // Firefox 3
                return "[object " + getClassName() + "]";
            }
            else {
                // Firefox2 is not fully coherent here (see WindowTest#windowProperties)
                final Window window = (Window) getTopLevelScope(this);
                if (ScriptableObject.getProperty(window, getClassName()) == this) {
                    return "[" + getClassName() + "]";
                }
                return "[object " + getClassName() + "]";
            }
View Full Code Here

    private void init(final WebWindow webWindow, final Context context) throws Exception {
        final WebClient webClient = webWindow.getWebClient();
        final Map<Class< ? extends SimpleScriptable>, Scriptable> prototypes =
            new HashMap<Class< ? extends SimpleScriptable>, Scriptable>();
        final Map<String, Scriptable> prototypesPerJSName = new HashMap<String, Scriptable>();
        final Window window = new Window();
        final JavaScriptConfiguration jsConfig = JavaScriptConfiguration.getInstance(webClient.getBrowserVersion());
        context.initStandardObjects(window);

        // remove some objects, that Rhino defines in top scope but that we don't want
        deleteProperties(window, "javax", "org", "com", "edu", "net", "JavaAdapter", "JavaImporter", "Continuation");
        if (webClient.getBrowserVersion().isIE()) {
            deleteProperties(window, "Packages", "java", "getClass", "XML", "XMLList", "Namespace", "QName");
        }

        // put custom object to be called as very last prototype to call the fallback getter (if any)
        final Scriptable fallbackCaller = new FallbackCaller();
        ScriptableObject.getObjectPrototype(window).setPrototype(fallbackCaller);

        for (final String jsClassName : jsConfig.keySet()) {
            final ClassConfiguration config = jsConfig.getClassConfiguration(jsClassName);
            final boolean isWindow = Window.class.getName().equals(config.getLinkedClass().getName());
            if (isWindow) {
                configureConstantsPropertiesAndFunctions(config, window);
            }
            else {
                final ScriptableObject prototype = configureClass(config, window);
                if (config.isJsObject()) {
                    // for FF, place object with prototype property in Window scope
                    if (!getWebClient().getBrowserVersion().isIE()) {
                        final SimpleScriptable obj = config.getLinkedClass().newInstance();
                        prototype.defineProperty("__proto__", prototype, ScriptableObject.DONTENUM);
                        obj.defineProperty("prototype", prototype, ScriptableObject.DONTENUM); // but not setPrototype!
                        obj.setParentScope(window);
                        ScriptableObject.defineProperty(window, config.getClassName(), obj, ScriptableObject.DONTENUM);
                        // this obj won't have prototype, constants need to be configured on it again
                        configureConstants(config, obj);

                        if (obj.getClass() == Element.class && webWindow.getEnclosedPage() instanceof HtmlPage) {
                            final DomNode domNode =
                                new HtmlDivision(null, "", (SgmlPage) webWindow.getEnclosedPage(), null);
                            obj.setDomNode(domNode);
                        }
                    }
                    prototypes.put(config.getLinkedClass(), prototype);
                }
                prototypesPerJSName.put(config.getClassName(), prototype);
            }
        }

        // once all prototypes have been build, it's possible to configure the chains
        final Scriptable objectPrototype = ScriptableObject.getObjectPrototype(window);
        for (final Map.Entry<String, Scriptable> entry : prototypesPerJSName.entrySet()) {
            final String name = entry.getKey();
            final ClassConfiguration config = jsConfig.getClassConfiguration(name);
            Scriptable prototype = entry.getValue();
            if (prototype.getPrototype() != null) {
                prototype = prototype.getPrototype(); // "double prototype" hack for FF
            }
            if (!StringUtils.isEmpty(config.getExtendedClass())) {
                final Scriptable parentPrototype = prototypesPerJSName.get(config.getExtendedClass());
                prototype.setPrototype(parentPrototype);
            }
            else {
                prototype.setPrototype(objectPrototype);
            }
        }

        // eval hack (cf unit tests testEvalScopeOtherWindow and testEvalScopeLocal)
        final Class< ? >[] evalFnTypes = {String.class};
        final Member evalFn = Window.class.getMethod("custom_eval", evalFnTypes);
        final FunctionObject jsCustomEval = new FunctionObject("eval", evalFn, window);
        window.associateValue("custom_eval", jsCustomEval);

        for (final String jsClassName : jsConfig.keySet()) {
            final ClassConfiguration config = jsConfig.getClassConfiguration(jsClassName);
            final Method jsConstructor = config.getJsConstructor();
            if (jsConstructor != null) {
                final Scriptable prototype = prototypesPerJSName.get(jsClassName);
                if (prototype != null) {
                    final FunctionObject jsCtor = new FunctionObject(jsClassName, jsConstructor, window);
                    jsCtor.addAsConstructor(window, prototype);
                }
            }
        }

        // Rhino defines too much methods for us, particularly since implementation of ECMAScript5
        removePrototypeProperties(window, "String", "equals", "equalsIgnoreCase", "trim");
        removePrototypeProperties(window, "Function", "bind");
        removePrototypeProperties(window, "Date", "toISOString", "toJSON");

        // in IE, not all standard methods exists
        if (webClient.getBrowserVersion().isIE()) {
            deleteProperties(window, "isXMLName", "uneval");
            removePrototypeProperties(window, "Object", "__defineGetter__", "__defineSetter__", "__lookupGetter__",
                    "__lookupSetter__", "toSource");
            removePrototypeProperties(window, "Array", "every", "filter", "forEach", "indexOf", "lastIndexOf", "map",
                    "reduce", "reduceRight", "some", "toSource");
            removePrototypeProperties(window, "Date", "toSource");
            removePrototypeProperties(window, "Function", "toSource");
            removePrototypeProperties(window, "Number", "toSource");
            removePrototypeProperties(window, "String", "toSource");
        }
        else if ("FF2".equals(webClient.getBrowserVersion().getNickname())) {
            removePrototypeProperties(window, "Array", "reduce", "reduceRight");
        }

        window.setPrototypes(prototypes);
        window.initialize(webWindow);
    }
View Full Code Here

TOP

Related Classes of com.gargoylesoftware.htmlunit.javascript.host.Window

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.