Package com.google.gdt.eclipse.designer.moz.jsni

Source Code of com.google.gdt.eclipse.designer.moz.jsni.ModuleSpaceMoz64

/*******************************************************************************
* Copyright 2011 Google Inc. All Rights Reserved.
*
* All rights reserved. This program and the accompanying materials
* are made available under the terms of the Eclipse Public License v1.0
* which accompanies this distribution, and is available at
* http://www.eclipse.org/legal/epl-v10.html
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*******************************************************************************/
package com.google.gdt.eclipse.designer.moz.jsni;

import com.google.gwt.core.ext.TreeLogger;
import com.google.gwt.dev.shell.CompilingClassLoader;
import com.google.gwt.dev.shell.JsValue;
import com.google.gwt.dev.shell.JsValueGlue;
import com.google.gwt.dev.shell.ModuleSpace;
import com.google.gwt.dev.shell.ModuleSpaceHost;

/**
* An implementation of {@link com.google.gwt.dev.shell.ModuleSpace} for
* Mozilla.
*/
public class ModuleSpaceMoz64 extends ModuleSpace {

  private final long window;

  /**
   * Constructs a browser interface for use with a Mozilla global window object.
   */
  public ModuleSpaceMoz64(ModuleSpaceHost host, long scriptGlobalObject,
      String moduleName) {
    super(host.getLogger(), host, moduleName);

    // Hang on to the parent window.
    //
    window = scriptGlobalObject;
  }

  @Override
  protected void doCreateNativeMethods(String jsni) {
    LowLevelMoz64.executeScriptWithInfo(window, jsni, "", 0);
  }
  @Override
  protected void createStaticDispatcher(TreeLogger logger) {
  String newScript = createNativeMethodInjector("__defineStatic", new String[] {"__arg0"}, "window.__static = __arg0;");
    LowLevelMoz64.executeScriptWithInfo(window, newScript, "", 0);
  }
  /*
   * (non-Javadoc)
   *
   * @see com.google.gwt.dev.shell.ModuleSpace#dispose()
   */
  @Override
  public void dispose() {
    super.dispose();
  }

  /**
   * Invokes a native JavaScript function.
   *
   * @param name the name of the function to invoke
   * @param jthis the function's 'this' context
   * @param types the type of each argument
   * @param args the arguments to be passed
   * @return the return value as a Object.
   */
  @Override
  protected JsValue doInvoke(String name, Object jthis, Class<?>[] types,
      Object[] args) {
    CompilingClassLoader isolatedClassLoader = getIsolatedClassLoader();

    JsValueMoz64 jsthis = new JsValueMoz64();
    Class<?> jthisType = (jthis == null) ? Object.class : jthis.getClass();
    JsValueGlue.set(jsthis, isolatedClassLoader, jthisType, jthis);

    int argc = args.length;
    JsValueMoz64 argv[] = new JsValueMoz64[argc];
    long [] jsArgsInt = new long [argc];
    for (int i = 0; i < argc; ++i) {
      argv[i] = new JsValueMoz64();
      JsValueGlue.set(argv[i], isolatedClassLoader, types[i], args[i]);
      jsArgsInt[i] = argv[i].getJsRootedValue();
    }
    JsValueMoz64 returnVal = new JsValueMoz64();
    LowLevelMoz64.invoke(window, name, jsthis.getJsRootedValue(), jsArgsInt,
        returnVal.getJsRootedValue());
    return returnVal;
  }

  @Override
  protected Object getStaticDispatcher() {
    return new GeckoDispatchAdapter64(getIsolatedClassLoader());
  }
}
TOP

Related Classes of com.google.gdt.eclipse.designer.moz.jsni.ModuleSpaceMoz64

TOP
Copyright © 2018 www.massapi.com. 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.