1 16 package com.google.gwt.dev.shell.ie; 17 18 import com.google.gwt.core.ext.TreeLogger; 19 import com.google.gwt.dev.shell.BrowserWidget; 20 import com.google.gwt.dev.shell.BrowserWidgetHost; 21 import com.google.gwt.dev.shell.ModuleSpaceHost; 22 23 import org.eclipse.swt.SWTException; 24 import org.eclipse.swt.internal.ole.win32.COM; 25 import org.eclipse.swt.internal.ole.win32.IDispatch; 26 import org.eclipse.swt.ole.win32.OleAutomation; 27 import org.eclipse.swt.ole.win32.Variant; 28 import org.eclipse.swt.widgets.Shell; 29 30 import java.lang.reflect.InvocationTargetException ; 31 import java.lang.reflect.Method ; 32 33 36 public class BrowserWidgetIE6 extends BrowserWidget { 37 38 41 public class External extends IDispatchImpl { 42 43 51 public boolean gwtOnLoad(IDispatch frameWnd, String moduleName) { 52 try { 53 if (moduleName == null) { 54 handleUnload(frameWnd); 56 return true; 57 } 58 59 int moduleID = ++nextModuleID; 61 Integer key = new Integer (moduleID); 62 setIntProperty(frameWnd, "__gwt_module_id", moduleID); 63 64 ModuleSpaceHost msh = getHost().createModuleSpaceHost( 67 BrowserWidgetIE6.this, moduleName); 68 ModuleSpaceIE6 moduleSpace = new ModuleSpaceIE6(msh, frameWnd, 69 moduleName, key); 70 attachModuleSpace(moduleSpace); 71 return true; 72 } catch (Throwable e) { 73 getHost().getLogger().log(TreeLogger.ERROR, 78 "Failure to load module '" + moduleName + "'", e); 79 return false; 80 } 81 } 82 83 protected void getIDsOfNames(String [] names, int[] ids) 84 throws HResultException { 85 86 if (names.length >= 2) { 87 throw new HResultException(DISP_E_UNKNOWNNAME); 88 } 89 90 String name = names[0].toLowerCase(); 91 if (name.equals("gwtonload")) { 92 ids[0] = 1; 93 return; 94 } 95 96 throw new HResultException(DISP_E_UNKNOWNNAME); 97 } 98 99 104 protected void handleUnload(IDispatch frameWnd) { 105 Integer key = null; 106 if (frameWnd != null) { 107 key = new Integer (getIntProperty(frameWnd, "__gwt_module_id")); 108 } 109 doUnload(key); 110 } 111 112 protected Variant invoke(int dispId, int flags, Variant[] params) 113 throws HResultException, InvocationTargetException { 114 115 if (dispId == 0 && (flags & COM.DISPATCH_PROPERTYGET) != 0) { 116 return new Variant(toString()); 118 } else if (dispId == 1) { 119 if ((flags & COM.DISPATCH_METHOD) != 0) { 120 try { 121 IDispatch frameWnd = (params[0].getType() == COM.VT_DISPATCH) 122 ? params[0].getDispatch() : null; 123 String moduleName = (params[1].getType() == COM.VT_BSTR) 124 ? params[1].getString() : null; 125 boolean success = gwtOnLoad(frameWnd, moduleName); 126 127 return new Variant(success); 129 } catch (SWTException e) { 130 throw new HResultException(COM.E_INVALIDARG); 131 } 132 } else if ((flags & COM.DISPATCH_PROPERTYGET) != 0) { 133 try { 135 Method gwtOnLoadMethod = getClass().getMethod("gwtOnLoad", 136 new Class [] {IDispatch.class, String .class}); 137 IDispatchImpl funcObj = new MethodDispatch(null, gwtOnLoadMethod); 138 IDispatch disp = new IDispatch(funcObj.getAddress()); 139 disp.AddRef(); 140 return new Variant(disp); 141 } catch (Exception e) { 142 return new Variant(); 144 } 145 } 146 throw new HResultException(COM.E_NOTSUPPORTED); 147 } 148 149 throw new HResultException(COM.DISP_E_MEMBERNOTFOUND); 151 } 152 } 153 154 private static int nextModuleID = 0; 156 157 165 private static int getIntProperty(IDispatch frameWnd, String propName) { 166 OleAutomation window = null; 167 try { 168 window = new OleAutomation(frameWnd); 169 int[] dispID = window.getIDsOfNames(new String [] { propName }); 170 if (dispID == null) { 171 throw new RuntimeException ("No such property " + propName); 172 } 173 Variant value = null; 174 try { 175 value = window.getProperty(dispID[0]); 176 return value.getInt(); 177 } finally { 178 if (value != null) { 179 value.dispose(); 180 } 181 } 182 } finally { 183 if (window != null) { 184 window.dispose(); 185 } 186 } 187 } 188 189 197 private static void setIntProperty(IDispatch frameWnd, String propName, 198 int intValue) { 199 OleAutomation window = null; 200 try { 201 window = new OleAutomation(frameWnd); 202 int[] dispID = window.getIDsOfNames(new String [] { propName }); 203 if (dispID == null) { 204 throw new RuntimeException ("No such property " + propName); 205 } 206 Variant value = null; 207 try { 208 value = new Variant(intValue); 209 window.setProperty(dispID[0], value); 210 } finally { 211 if (value != null) { 212 value.dispose(); 213 } 214 } 215 } finally { 216 if (window != null) { 217 window.dispose(); 218 } 219 } 220 } 221 222 public BrowserWidgetIE6(Shell shell, BrowserWidgetHost host) { 223 super(shell, host); 224 225 SwtOleGlue.injectBrowserScriptExternalObject(browser, new External()); 229 230 LowLevelIE6.init(); 233 } 234 } 235 | Popular Tags |