1 11 package org.eclipse.swt.browser; 12 13 import org.eclipse.swt.*; 14 import org.eclipse.swt.internal.ole.win32.*; 15 import org.eclipse.swt.ole.win32.*; 16 import org.eclipse.swt.widgets.*; 17 import org.eclipse.swt.internal.win32.*; 18 19 class WebSite extends OleControlSite { 20 COMObject iDocHostUIHandler; 21 COMObject iDocHostShowUI; 22 COMObject iServiceProvider; 23 COMObject iInternetSecurityManager; 24 COMObject iOleCommandTarget; 25 26 static final int OLECMDID_SHOWSCRIPTERROR = 40; 27 static final String CONSUME_KEY = "org.eclipse.swt.OleFrame.ConsumeKey"; 29 public WebSite(Composite parent, int style, String progId) { 30 super(parent, style, progId); 31 } 32 33 protected void createCOMInterfaces () { 34 super.createCOMInterfaces(); 35 iDocHostUIHandler = new COMObject(new int[]{2, 0, 0, 4, 1, 5, 0, 0, 1, 1, 1, 3, 3, 2, 2, 1, 3, 2}){ 36 public int method0(int[] args) {return QueryInterface(args[0], args[1]);} 37 public int method1(int[] args) {return AddRef();} 38 public int method2(int[] args) {return Release();} 39 public int method3(int[] args) {return ShowContextMenu(args[0], args[1], args[2], args[3]);} 40 public int method4(int[] args) {return GetHostInfo(args[0]);} 41 public int method5(int[] args) {return ShowUI(args[0], args[1], args[2], args[3], args[4]);} 42 public int method6(int[] args) {return HideUI();} 43 public int method7(int[] args) {return UpdateUI();} 44 public int method8(int[] args) {return EnableModeless(args[0]);} 45 public int method9(int[] args) {return OnDocWindowActivate(args[0]);} 46 public int method10(int[] args) {return OnFrameWindowActivate(args[0]);} 47 public int method11(int[] args) {return ResizeBorder(args[0], args[1], args[2]);} 48 public int method12(int[] args) {return TranslateAccelerator(args[0], args[1], args[2]);} 49 public int method13(int[] args) {return GetOptionKeyPath(args[0], args[1]);} 50 public int method14(int[] args) {return GetDropTarget(args[0], args[1]);} 51 public int method15(int[] args) {return GetExternal(args[0]);} 52 public int method16(int[] args) {return TranslateUrl(args[0], args[1], args[2]);} 53 public int method17(int[] args) {return FilterDataObject(args[0], args[1]);} 54 }; 55 iDocHostShowUI = new COMObject(new int[]{2, 0, 0, 7, 7}){ 56 public int method0(int[] args) {return QueryInterface(args[0], args[1]);} 57 public int method1(int[] args) {return AddRef();} 58 public int method2(int[] args) {return Release();} 59 public int method3(int[] args) {return ShowMessage(args[0], args[1], args[2], args[3], args[4], args[5], args[6]);} 60 public int method4(int[] args) {return ShowHelp(args[0], args[1], args[2], args[3], args[4], args[5], args[6]);} 61 }; 62 iServiceProvider = new COMObject(new int[]{2, 0, 0, 3}){ 63 public int method0(int[] args) {return QueryInterface(args[0], args[1]);} 64 public int method1(int[] args) {return AddRef();} 65 public int method2(int[] args) {return Release();} 66 public int method3(int[] args) {return QueryService(args[0], args[1], args[2]);} 67 }; 68 iInternetSecurityManager = new COMObject(new int[]{2, 0, 0, 1, 1, 3, 4, 8, 7, 3, 3}){ 69 public int method0(int[] args) {return QueryInterface(args[0], args[1]);} 70 public int method1(int[] args) {return AddRef();} 71 public int method2(int[] args) {return Release();} 72 public int method3(int[] args) {return SetSecuritySite(args[0]);} 73 public int method4(int[] args) {return GetSecuritySite(args[0]);} 74 public int method5(int[] args) {return MapUrlToZone(args[0], args[1], args[2]);} 75 public int method6(int[] args) {return GetSecurityId(args[0], args[1], args[2], args[3]);} 76 public int method7(int[] args) {return ProcessUrlAction(args[0], args[1], args[2], args[3], args[4], args[5], args[6], args[7]);} 77 public int method8(int[] args) {return QueryCustomPolicy(args[0], args[1], args[2], args[3], args[4], args[5], args[6]);} 78 public int method9(int[] args) {return SetZoneMapping(args[0], args[1], args[2]);} 79 public int method10(int[] args) {return GetZoneMappings(args[0], args[1], args[2]);} 80 }; 81 iOleCommandTarget = new COMObject(new int[]{2, 0, 0, 4, 5}) { 82 public int method0(int[] args) {return QueryInterface(args[0], args[1]);} 83 public int method1(int[] args) {return AddRef();} 84 public int method2(int[] args) {return Release();} 85 public int method3(int[] args) {return QueryStatus(args[0], args[1], args[2], args[3]);} 86 public int method4(int[] args) {return Exec(args[0], args[1], args[2], args[3], args[4]);} 87 }; 88 } 89 90 protected void disposeCOMInterfaces() { 91 super.disposeCOMInterfaces(); 92 if (iDocHostUIHandler != null) { 93 iDocHostUIHandler.dispose(); 94 iDocHostUIHandler = null; 95 } 96 if (iDocHostShowUI != null) { 97 iDocHostShowUI.dispose(); 98 iDocHostShowUI = null; 99 } 100 if (iServiceProvider != null) { 101 iServiceProvider.dispose(); 102 iServiceProvider = null; 103 } 104 if (iInternetSecurityManager != null) { 105 iInternetSecurityManager.dispose(); 106 iInternetSecurityManager = null; 107 } 108 if (iOleCommandTarget != null) { 109 iOleCommandTarget.dispose(); 110 iOleCommandTarget = null; 111 } 112 } 113 114 protected int AddRef() { 115 116 return super.AddRef(); 117 } 118 119 protected int QueryInterface(int riid, int ppvObject) { 120 int result = super.QueryInterface(riid, ppvObject); 121 if (result == COM.S_OK) return result; 122 if (riid == 0 || ppvObject == 0) return COM.E_INVALIDARG; 123 GUID guid = new GUID(); 124 COM.MoveMemory(guid, riid, GUID.sizeof); 125 if (COM.IsEqualGUID(guid, COM.IIDIDocHostUIHandler)) { 126 COM.MoveMemory(ppvObject, new int[] {iDocHostUIHandler.getAddress()}, 4); 127 AddRef(); 128 return COM.S_OK; 129 } 130 if (COM.IsEqualGUID(guid, COM.IIDIDocHostShowUI)) { 131 COM.MoveMemory(ppvObject, new int[] {iDocHostShowUI.getAddress()}, 4); 132 AddRef(); 133 return COM.S_OK; 134 } 135 if (COM.IsEqualGUID(guid, COM.IIDIServiceProvider)) { 136 COM.MoveMemory(ppvObject, new int[] {iServiceProvider.getAddress()}, 4); 137 AddRef(); 138 return COM.S_OK; 139 } 140 if (COM.IsEqualGUID(guid, COM.IIDIInternetSecurityManager)) { 141 COM.MoveMemory(ppvObject, new int[] {iInternetSecurityManager.getAddress()}, 4); 142 AddRef(); 143 return COM.S_OK; 144 } 145 if (COM.IsEqualGUID(guid, COM.IIDIOleCommandTarget)) { 146 COM.MoveMemory(ppvObject, new int[] {iOleCommandTarget.getAddress()}, 4); 147 AddRef(); 148 return COM.S_OK; 149 } 150 COM.MoveMemory(ppvObject, new int[] {0}, 4); 151 return COM.E_NOINTERFACE; 152 } 153 154 155 156 int EnableModeless(int EnableModeless) { 157 return COM.E_NOTIMPL; 158 } 159 160 int FilterDataObject(int pDO, int ppDORet) { 161 return COM.E_NOTIMPL; 162 } 163 164 int GetDropTarget(int pDropTarget, int ppDropTarget) { 165 return COM.E_NOTIMPL; 166 } 167 168 int GetExternal(int ppDispatch) { 169 OS.MoveMemory(ppDispatch, new int[] {0}, 4); 170 return COM.S_FALSE; 171 } 172 173 int GetHostInfo(int pInfo) { 174 IE browser = (IE)((Browser)getParent().getParent()).webBrowser; 175 OS.MoveMemory(pInfo + 4, new int[] {browser.info}, 4); 176 return COM.S_OK; 177 } 178 179 int GetOptionKeyPath(int pchKey, int dw) { 180 return COM.E_NOTIMPL; 181 } 182 183 int HideUI() { 184 return COM.E_NOTIMPL; 185 } 186 187 int OnDocWindowActivate(int fActivate) { 188 return COM.E_NOTIMPL; 189 } 190 191 int OnFrameWindowActivate(int fActivate) { 192 return COM.E_NOTIMPL; 193 } 194 195 protected int Release() { 196 197 return super.Release(); 198 } 199 200 int ResizeBorder(int prcBorder, int pUIWindow, int fFrameWindow) { 201 return COM.E_NOTIMPL; 202 } 203 204 int ShowContextMenu(int dwID, int ppt, int pcmdtReserved, int pdispReserved) { 205 Browser browser = (Browser)getParent().getParent(); 206 Event event = new Event(); 207 POINT pt = new POINT(); 208 OS.MoveMemory(pt, ppt, POINT.sizeof); 209 event.x = pt.x; 210 event.y = pt.y; 211 browser.notifyListeners(SWT.MenuDetect, event); 212 if (!event.doit) return COM.S_OK; 213 Menu menu = browser.getMenu(); 214 if (menu != null && !menu.isDisposed ()) { 215 if (pt.x != event.x || pt.y != event.y) { 216 menu.setLocation (event.x, event.y); 217 } 218 menu.setVisible (true); 219 return COM.S_OK; 220 } 221 222 return COM.S_FALSE; 223 } 224 225 int ShowUI(int dwID, int pActiveObject, int pCommandTarget, int pFrame, int pDoc) { 226 return COM.S_FALSE; 227 } 228 229 int TranslateAccelerator(int lpMsg, int pguidCmdGroup, int nCmdID) { 230 236 Menu menubar = getShell().getMenuBar(); 237 if (menubar != null && !menubar.isDisposed() && menubar.isEnabled()) { 238 Shell shell = menubar.getShell(); 239 int hwnd = shell.handle; 240 int hAccel = OS.SendMessage(hwnd, OS.WM_APP+1, 0, 0); 241 if (hAccel != 0) { 242 MSG msg = new MSG(); 243 OS.MoveMemory(msg, lpMsg, MSG.sizeof); 244 if (OS.TranslateAccelerator(hwnd, hAccel, msg) != 0) return COM.S_OK; 245 } 246 } 247 256 int result = COM.S_FALSE; 257 MSG msg = new MSG(); 258 OS.MoveMemory(msg, lpMsg, MSG.sizeof); 259 if (msg.message == OS.WM_KEYDOWN) { 260 switch (msg.wParam) { 261 case OS.VK_N: 262 case OS.VK_O: 263 if (OS.GetKeyState (OS.VK_CONTROL) < 0) { 264 getParent().setData(CONSUME_KEY, "false"); result = COM.S_OK; 266 } 267 break; 268 case OS.VK_F5: 269 OleAutomation auto = new OleAutomation(this); 270 int[] rgdispid = auto.getIDsOfNames(new String [] { "LocationURL" }); Variant pVarResult = auto.getProperty(rgdispid[0]); 272 auto.dispose(); 273 if (pVarResult != null) { 274 if (pVarResult.getType() == OLE.VT_BSTR) { 275 String url = pVarResult.getString(); 276 if (url.equals(IE.ABOUT_BLANK)) result = COM.S_OK; 277 } 278 pVarResult.dispose(); 279 } 280 break; 281 } 282 } 283 return result; 284 } 285 286 int TranslateUrl(int dwTranslate, int pchURLIn, int ppchURLOut) { 287 return COM.E_NOTIMPL; 288 } 289 290 int UpdateUI() { 291 return COM.E_NOTIMPL; 292 } 293 294 295 296 int ShowMessage(int hwnd, int lpstrText, int lpstrCaption, int dwType, int lpstrHelpFile, int dwHelpContext, int plResult) { 297 303 306 int IDS_MESSAGE_BOX_CAPTION = 8033; 307 if (lpstrText != 0) { 308 TCHAR lpLibFileName = new TCHAR (0, "SHDOCLC.DLL", true); int hModule = OS.LoadLibrary(lpLibFileName); 310 if (hModule != 0) { 311 316 int cnt = OS.wcslen(lpstrText); 317 char[] buffer = new char[cnt]; 318 323 OS.MoveMemory(buffer, lpstrText, cnt * 2); 324 String text = new String (buffer); 325 326 int length = (OS.IsUnicode ? cnt : OS.WideCharToMultiByte (OS.CP_ACP, 0, buffer, cnt, 0, 0, null, null)) + 1; 327 328 TCHAR lpBuffer = new TCHAR(0, length); 329 int result = OS.LoadString(hModule, IDS_MESSAGE_BOX_CAPTION, lpBuffer, length); 330 OS.FreeLibrary(hModule); 331 return result > 0 && text.equals(lpBuffer.toString(0, result)) ? COM.S_OK : COM.S_FALSE; 332 } 333 } 334 return COM.S_FALSE; 335 } 336 337 342 int ShowHelp(int hwnd, int pszHelpFile, int uCommand, int dwData, int ptMouse_x, int ptMouse_y, int pDispatchObjectHit) { 343 Browser browser = (Browser)getParent().getParent(); 344 Event event = new Event(); 345 event.type = SWT.Help; 346 event.display = getDisplay(); 347 event.widget = browser; 348 Shell shell = browser.getShell(); 349 Control control = browser; 350 do { 351 if (control.isListening(SWT.Help)) { 352 control.notifyListeners(SWT.Help, event); 353 break; 354 } 355 if (control == shell) break; 356 control = control.getParent(); 357 } while (true); 358 return COM.S_OK; 359 } 360 361 362 363 int QueryService(int guidService, int riid, int ppvObject) { 364 if (riid == 0 || ppvObject == 0) return COM.E_INVALIDARG; 365 GUID guid = new GUID(); 366 COM.MoveMemory(guid, riid, GUID.sizeof); 367 if (COM.IsEqualGUID(guid, COM.IIDIInternetSecurityManager)) { 368 COM.MoveMemory(ppvObject, new int[] {iInternetSecurityManager.getAddress()}, 4); 369 AddRef(); 370 return COM.S_OK; 371 } 372 COM.MoveMemory(ppvObject, new int[] {0}, 4); 373 return COM.E_NOINTERFACE; 374 } 375 376 377 378 int SetSecuritySite(int pSite) { 379 return IE.INET_E_DEFAULT_ACTION; 380 } 381 382 int GetSecuritySite(int ppSite) { 383 return IE.INET_E_DEFAULT_ACTION; 384 } 385 386 int MapUrlToZone(int pwszUrl, int pdwZone, int dwFlags) { 387 395 COM.MoveMemory(pdwZone, new int[] {IE.URLZONE_INTRANET}, 4); 396 return COM.S_OK; 397 } 398 399 int GetSecurityId(int pwszUrl, int pbSecurityId, int pcbSecurityId, int dwReserved) { 400 return IE.INET_E_DEFAULT_ACTION; 401 } 402 403 int ProcessUrlAction(int pwszUrl, int dwAction, int pPolicy, int cbPolicy, int pContext, int cbContext, int dwFlags, int dwReserved) { 404 417 int policy = IE.URLPOLICY_ALLOW; 418 426 if (dwAction >= IE.URLACTION_JAVA_MIN && dwAction <= IE.URLACTION_JAVA_MAX) { 427 policy = IE.URLPOLICY_JAVA_PROHIBIT; 428 } 429 436 if (dwAction == IE.URLACTION_ACTIVEX_RUN) { 437 GUID guid = new GUID(); 438 COM.MoveMemory(guid, pContext, GUID.sizeof); 439 if (COM.IsEqualGUID(guid, COM.IIDJavaBeansBridge) || COM.IsEqualGUID(guid, COM.IIDShockwaveActiveXControl)) { 440 policy = IE.URLPOLICY_DISALLOW; 441 } 442 } 443 if (cbPolicy >= 4) COM.MoveMemory(pPolicy, new int[] {policy}, 4); 444 return policy == IE.URLPOLICY_ALLOW ? COM.S_OK : COM.S_FALSE; 445 } 446 447 int QueryCustomPolicy(int pwszUrl, int guidKey, int ppPolicy, int pcbPolicy, int pContext, int cbContext, int dwReserved) { 448 return IE.INET_E_DEFAULT_ACTION; 449 } 450 451 int SetZoneMapping(int dwZone, int lpszPattern, int dwFlags) { 452 return IE.INET_E_DEFAULT_ACTION; 453 } 454 455 int GetZoneMappings(int dwZone, int ppenumString, int dwFlags) { 456 return COM.E_NOTIMPL; 457 } 458 459 460 int QueryStatus(int pguidCmdGroup, int cCmds, int prgCmds, int pCmdText) { 461 return COM.E_NOTSUPPORTED; 462 } 463 464 int Exec(int pguidCmdGroup, int nCmdID, int nCmdExecOpt, int pvaIn, int pvaOut) { 465 if (pguidCmdGroup != 0) { 466 GUID guid = new GUID(); 467 COM.MoveMemory(guid, pguidCmdGroup, GUID.sizeof); 468 469 472 if (COM.IsEqualGUID(guid, COM.CGID_DocHostCommandHandler)) { 473 if (nCmdID == OLECMDID_SHOWSCRIPTERROR) return COM.S_OK; 474 } 475 476 483 if (nCmdID == 1 && COM.IsEqualGUID(guid, COM.CGID_Explorer) && ((nCmdExecOpt & 0xFFFF) == 0xA)) { 484 IE browser = (IE)((Browser)getParent().getParent()).webBrowser; 485 browser.toolBar = (nCmdExecOpt & 0xFFFF0000) != 0; 486 } 487 } 488 return COM.E_NOTSUPPORTED; 489 } 490 491 } 492 | Popular Tags |