1 11 package org.eclipse.swt.browser; 12 13 import org.eclipse.swt.*; 14 import org.eclipse.swt.graphics.*; 15 import org.eclipse.swt.internal.*; 16 import org.eclipse.swt.internal.mozilla.*; 17 import org.eclipse.swt.layout.*; 18 import org.eclipse.swt.widgets.*; 19 20 class WindowCreator2 { 21 XPCOMObject supports; 22 XPCOMObject windowCreator; 23 XPCOMObject windowCreator2; 24 int refCount = 0; 25 26 public WindowCreator2 () { 27 createCOMInterfaces (); 28 } 29 30 int AddRef () { 31 refCount++; 32 return refCount; 33 } 34 35 void createCOMInterfaces () { 36 37 supports = new XPCOMObject (new int[] {2, 0, 0}) { 38 public int method0 (int [] args) {return QueryInterface (args[0], args[1]);} 39 public int method1 (int [] args) {return AddRef ();} 40 public int method2 (int [] args) {return Release ();} 41 }; 42 43 windowCreator = new XPCOMObject (new int[] {2, 0, 0, 3}) { 44 public int method0 (int [] args) {return QueryInterface (args[0], args[1]);} 45 public int method1 (int [] args) {return AddRef ();} 46 public int method2 (int [] args) {return Release ();} 47 public int method3 (int [] args) {return CreateChromeWindow (args[0], args[1], args[2]);} 48 }; 49 50 windowCreator2 = new XPCOMObject (new int[] {2, 0, 0, 3, 6}) { 51 public int method0 (int [] args) {return QueryInterface (args[0], args[1]);} 52 public int method1 (int [] args) {return AddRef ();} 53 public int method2 (int [] args) {return Release ();} 54 public int method3 (int [] args) {return CreateChromeWindow (args[0], args[1], args[2]);} 55 public int method4 (int [] args) {return CreateChromeWindow2 (args[0], args[1], args[2], args[3], args[4], args[5]);} 56 }; 57 } 58 59 void disposeCOMInterfaces () { 60 if (supports != null) { 61 supports.dispose (); 62 supports = null; 63 } 64 if (windowCreator != null) { 65 windowCreator.dispose (); 66 windowCreator = null; 67 } 68 69 if (windowCreator2 != null) { 70 windowCreator2.dispose (); 71 windowCreator2 = null; 72 } 73 } 74 75 int getAddress () { 76 return windowCreator.getAddress (); 77 } 78 79 int QueryInterface (int riid, int ppvObject) { 80 if (riid == 0 || ppvObject == 0) return XPCOM.NS_ERROR_NO_INTERFACE; 81 nsID guid = new nsID (); 82 XPCOM.memmove (guid, riid, nsID.sizeof); 83 84 if (guid.Equals (nsISupports.NS_ISUPPORTS_IID)) { 85 XPCOM.memmove (ppvObject, new int [] {supports.getAddress ()}, C.PTR_SIZEOF); 86 AddRef (); 87 return XPCOM.NS_OK; 88 } 89 if (guid.Equals (nsIWindowCreator.NS_IWINDOWCREATOR_IID)) { 90 XPCOM.memmove (ppvObject, new int [] {windowCreator.getAddress ()}, C.PTR_SIZEOF); 91 AddRef (); 92 return XPCOM.NS_OK; 93 } 94 if (guid.Equals (nsIWindowCreator2.NS_IWINDOWCREATOR2_IID)) { 95 XPCOM.memmove (ppvObject, new int [] {windowCreator2.getAddress ()}, C.PTR_SIZEOF); 96 AddRef (); 97 return XPCOM.NS_OK; 98 } 99 100 XPCOM.memmove (ppvObject, new int [] {0}, C.PTR_SIZEOF); 101 return XPCOM.NS_ERROR_NO_INTERFACE; 102 } 103 104 int Release () { 105 refCount--; 106 if (refCount == 0) disposeCOMInterfaces (); 107 return refCount; 108 } 109 110 111 112 int CreateChromeWindow (int parent, int chromeFlags, int _retval) { 113 return CreateChromeWindow2 (parent, chromeFlags, 0, 0, 0, _retval); 114 } 115 116 117 118 int CreateChromeWindow2 (int parent, int chromeFlags, int contextFlags, int uri, int cancel, int _retval) { 119 if (parent == 0 && (chromeFlags & nsIWebBrowserChrome.CHROME_OPENAS_CHROME) == 0) { 120 return XPCOM.NS_ERROR_NOT_IMPLEMENTED; 121 } 122 Browser src = null; 123 if (parent != 0) { 124 nsIWebBrowserChrome browserChromeParent = new nsIWebBrowserChrome (parent); 125 int [] aWebBrowser = new int [1]; 126 int rc = browserChromeParent.GetWebBrowser (aWebBrowser); 127 if (rc != XPCOM.NS_OK) Mozilla.error (rc); 128 if (aWebBrowser[0] == 0) Mozilla.error (XPCOM.NS_ERROR_NO_INTERFACE); 129 130 nsIWebBrowser webBrowser = new nsIWebBrowser (aWebBrowser[0]); 131 int [] result = new int [1]; 132 rc = webBrowser.QueryInterface (nsIBaseWindow.NS_IBASEWINDOW_IID, result); 133 if (rc != XPCOM.NS_OK) Mozilla.error (rc); 134 if (result[0] == 0) Mozilla.error (XPCOM.NS_ERROR_NO_INTERFACE); 135 webBrowser.Release (); 136 137 nsIBaseWindow baseWindow = new nsIBaseWindow (result[0]); 138 result[0] = 0; 139 int [] aParentNativeWindow = new int [1]; 140 rc = baseWindow.GetParentNativeWindow (aParentNativeWindow); 141 if (rc != XPCOM.NS_OK) Mozilla.error (rc); 142 if (aParentNativeWindow[0] == 0) Mozilla.error (XPCOM.NS_ERROR_NO_INTERFACE); 143 baseWindow.Release (); 144 145 src = Mozilla.findBrowser (aParentNativeWindow[0]); 146 } 147 final Browser browser; 148 boolean doit = true; 149 if ((chromeFlags & nsIWebBrowserChrome.CHROME_OPENAS_CHROME) != 0) { 150 155 int style = SWT.DIALOG_TRIM; 156 if ((chromeFlags & nsIWebBrowserChrome.CHROME_MODAL) != 0) style |= SWT.APPLICATION_MODAL; 157 final Shell shell = src == null ? 158 new Shell (style) : 159 new Shell (src.getShell(), style); 160 shell.setLayout (new FillLayout ()); 161 browser = new Browser (shell, src == null ? SWT.MOZILLA : src.getStyle () & SWT.MOZILLA); 162 browser.addVisibilityWindowListener (new VisibilityWindowListener () { 163 public void hide (WindowEvent event) { 164 } 165 public void show (WindowEvent event) { 166 if (event.location != null) shell.setLocation (event.location); 167 if (event.size != null) { 168 Point size = event.size; 169 shell.setSize (shell.computeSize (size.x, size.y)); 170 } 171 shell.open (); 172 } 173 }); 174 browser.addCloseWindowListener (new CloseWindowListener () { 175 public void close (WindowEvent event) { 176 shell.close (); 177 } 178 }); 179 if (uri != 0) { 180 nsIURI location = new nsIURI (uri); 181 int aSpec = XPCOM.nsEmbedCString_new (); 182 if (location.GetSpec (aSpec) == XPCOM.NS_OK) { 183 int length = XPCOM.nsEmbedCString_Length (aSpec); 184 if (length > 0) { 185 int buffer = XPCOM.nsEmbedCString_get (aSpec); 186 byte[] dest = new byte[length]; 187 XPCOM.memmove (dest, buffer, length); 188 browser.setUrl (new String (dest)); 189 } 190 } 191 XPCOM.nsEmbedCString_delete (aSpec); 192 } 193 } else { 194 WindowEvent event = new WindowEvent (src); 195 event.display = src.getDisplay (); 196 event.widget = src; 197 event.required = true; 198 for (int i = 0; i < src.webBrowser.openWindowListeners.length; i++) { 199 src.webBrowser.openWindowListeners[i].open (event); 200 } 201 browser = event.browser; 202 203 204 doit = browser != null && !browser.isDisposed (); 205 if (doit) { 206 String platform = Platform.PLATFORM; 207 boolean isMozillaNativePlatform = platform.equals ("gtk") || platform.equals ("motif"); doit = isMozillaNativePlatform || (browser.getStyle () & SWT.MOZILLA) != 0; 209 } 210 } 211 if (doit) { 212 Mozilla mozilla = (Mozilla)browser.webBrowser; 213 mozilla.isChild = true; 214 int chromePtr = mozilla.webBrowserChrome.getAddress (); 215 nsIWebBrowserChrome webBrowserChrome = new nsIWebBrowserChrome (chromePtr); 216 webBrowserChrome.SetChromeFlags ((int)chromeFlags); 217 webBrowserChrome.AddRef (); 218 XPCOM.memmove (_retval, new int [] {chromePtr}, C.PTR_SIZEOF); 219 } else { 220 if (cancel != 0) { 221 C.memmove (cancel, new int[] {1}, 4); 222 } 223 } 224 return doit ? XPCOM.NS_OK : XPCOM.NS_ERROR_NOT_IMPLEMENTED; 225 } 226 } 227 | Popular Tags |