public Browser(Composite parent, int style) { super(parent,style);
public Browser(Composite parent, int style) { super(fixIM(parent), style); Display display = parent.getDisplay(); display.	setData(NO_INPUT_METHOD, null);
public Browser(Composite parent, int style) { 	super(parent,style);		int /*long*/[] result = new int /*long*/[1];	if (!mozilla) {		String mozillaPath = null;		int /*long*/ ptr = OS.getenv(Converter.wcsToMbcs(null, XPCOM.MOZILLA_FIVE_HOME, true));		if (ptr != 0) {			int length = OS.strlen(ptr);			byte[] buffer = new byte[length];			OS.memmove(buffer, ptr, length);			mozillaPath = new String (Converter.mbcsToWcs (null, buffer));		}		if (mozillaPath == null) {			dispose();			SWT.error(SWT.ERROR_NO_HANDLES, null, " [Unknown Mozilla path (MOZILLA_FIVE_HOME not set)]"); //$NON-NLS-1$		}		/*		* Note.  Embedding a Mozilla GTK1.2 causes a crash.  The workaround		* is to check the version of GTK used by Mozilla by looking for		* the libwidget_gtk.so library used by Mozilla GTK1.2. Mozilla GTK2		* uses the libwidget_gtk2.so library.   		*/		File file = new File(mozillaPath, "components/libwidget_gtk.so"); //$NON-NLS-1$		if (file.exists()) {			dispose();			SWT.error(SWT.ERROR_NO_HANDLES, null, " [Mozilla GTK2 required (GTK1.2 detected)]"); //$NON-NLS-1$									}		try {			Library.loadLibrary ("swt-mozilla"); //$NON-NLS-1$		} catch (UnsatisfiedLinkError e) {			dispose();			SWT.error(SWT.ERROR_NO_HANDLES, e);		}				int /*long*/[] retVal = new int /*long*/[1];		nsEmbedString path = new nsEmbedString(mozillaPath);		int rc = XPCOM.NS_NewLocalFile(path.getAddress(), true, retVal);		path.dispose();		if (rc != XPCOM.NS_OK) error(rc);		if (retVal[0] == 0) error(XPCOM.NS_ERROR_NULL_POINTER);				nsILocalFile localFile = new nsILocalFile(retVal[0]);		rc = XPCOM.NS_InitEmbedding(localFile.getAddress(), 0);		localFile.Release();		if (rc != XPCOM.NS_OK) {			dispose();			SWT.error(SWT.ERROR_NO_HANDLES, null, " [NS_InitEmbedding "+mozillaPath+" error "+rc+"]"); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$		}		rc = XPCOM.NS_GetComponentManager(result);		if (rc != XPCOM.NS_OK) error(rc);		if (result[0] == 0) error(XPCOM.NS_NOINTERFACE);				nsIComponentManager componentManager = new nsIComponentManager(result[0]);		result[0] = 0;		rc = componentManager.CreateInstance(XPCOM.NS_APPSHELL_CID, 0, nsIAppShell.NS_IAPPSHELL_IID, result);		if (rc != XPCOM.NS_OK) error(rc);		if (result[0] == 0) error(XPCOM.NS_NOINTERFACE);				AppShell = new nsIAppShell(result[0]);		rc = AppShell.Create(0, null);		if (rc != XPCOM.NS_OK) error(rc);		rc = AppShell.Spinup();		if (rc != XPCOM.NS_OK) error(rc);				WindowCreator = new WindowCreator();		WindowCreator.AddRef();				rc = XPCOM.NS_GetServiceManager(result);		if (rc != XPCOM.NS_OK) error(rc);		if (result[0] == 0) error(XPCOM.NS_NOINTERFACE);				nsIServiceManager serviceManager = new nsIServiceManager(result[0]);		result[0] = 0;				byte[] buffer = XPCOM.NS_WINDOWWATCHER_CONTRACTID.getBytes();		byte[] aContractID = new byte[buffer.length + 1];		System.arraycopy(buffer, 0, aContractID, 0, buffer.length);		rc = serviceManager.GetServiceByContractID(aContractID, nsIWindowWatcher.NS_IWINDOWWATCHER_IID, result);		if (rc != XPCOM.NS_OK) error(rc);		if (result[0] == 0) error(XPCOM.NS_NOINTERFACE);				serviceManager.Release();				nsIWindowWatcher windowWatcher = new nsIWindowWatcher(result[0]);		result[0] = 0;		rc = windowWatcher.SetWindowCreator(WindowCreator.getAddress());		if (rc != XPCOM.NS_OK) error(rc);		windowWatcher.Release();				PromptServiceFactory factory = new PromptServiceFactory();		factory.AddRef();				rc = componentManager.QueryInterface(nsIComponentRegistrar.NS_ICOMPONENTREGISTRAR_IID, result);		if (rc != XPCOM.NS_OK) error(rc);		if (result[0] == 0) error(XPCOM.NS_NOINTERFACE);				nsIComponentRegistrar componentRegistrar = new nsIComponentRegistrar(result[0]);		result[0] = 0;		buffer = XPCOM.NS_PROMPTSERVICE_CONTRACTID.getBytes();		aContractID = new byte[buffer.length + 1];		System.arraycopy(buffer, 0, aContractID, 0, buffer.length);		buffer = "Prompt Service".getBytes(); //$NON-NLS-1$		byte[] aClassName = new byte[buffer.length + 1];		System.arraycopy(buffer, 0, aClassName, 0, buffer.length);		rc = componentRegistrar.RegisterFactory(XPCOM.NS_PROMPTSERVICE_CID, aClassName, aContractID, factory.getAddress());		if (rc != XPCOM.NS_OK) error(rc);		factory.Release();				HelperAppLauncherDialogFactory dialogFactory = new HelperAppLauncherDialogFactory();		dialogFactory.AddRef();				buffer = XPCOM.NS_HELPERAPPLAUNCHERDIALOG_CONTRACTID.getBytes();		aContractID = new byte[buffer.length + 1];		System.arraycopy(buffer, 0, aContractID, 0, buffer.length);		buffer = "Helper App Launcher Dialog".getBytes(); //$NON-NLS-1$		aClassName = new byte[buffer.length + 1];		System.arraycopy(buffer, 0, aClassName, 0, buffer.length);		rc = componentRegistrar.RegisterFactory(XPCOM.NS_HELPERAPPLAUNCHERDIALOG_CID, aClassName, aContractID, dialogFactory.getAddress());		if (rc != XPCOM.NS_OK) error(rc);		dialogFactory.Release();				DownloadFactory downloadFactory = new DownloadFactory();		downloadFactory.AddRef();				buffer = XPCOM.NS_DOWNLOAD_CONTRACTID.getBytes();		aContractID = new byte[buffer.length + 1];		System.arraycopy(buffer, 0, aContractID, 0, buffer.length);		buffer = "Download".getBytes(); //$NON-NLS-1$		aClassName = new byte[buffer.length + 1];		System.arraycopy(buffer, 0, aClassName, 0, buffer.length);		rc = componentRegistrar.RegisterFactory(XPCOM.NS_DOWNLOAD_CID, aClassName, aContractID, downloadFactory.getAddress());		if (rc != XPCOM.NS_OK) error(rc);		downloadFactory.Release();				componentRegistrar.Release();		componentManager.Release();		mozilla = true;	}	BrowserCount++;	int rc = XPCOM.NS_GetComponentManager(result);	if (rc != XPCOM.NS_OK) error(rc);	if (result[0] == 0) error(XPCOM.NS_NOINTERFACE);		nsIComponentManager componentManager = new nsIComponentManager(result[0]);	result[0] = 0;	nsID NS_IWEBBROWSER_CID = new nsID("F1EAC761-87E9-11d3-AF80-00A024FFC08C"); //$NON-NLS-1$	rc = componentManager.CreateInstance(NS_IWEBBROWSER_CID, 0, nsIWebBrowser.NS_IWEBBROWSER_IID, result);	if (rc != XPCOM.NS_OK) error(rc);	if (result[0] == 0) error(XPCOM.NS_NOINTERFACE);		componentManager.Release();		webBrowser = new nsIWebBrowser(result[0]); 	createCOMInterfaces();	AddRef();	rc = webBrowser.SetContainerWindow(webBrowserChrome.getAddress());	if (rc != XPCOM.NS_OK) error(rc);				rc = webBrowser.QueryInterface(nsIBaseWindow.NS_IBASEWINDOW_IID, result);	if (rc != XPCOM.NS_OK) error(rc);	if (result[0] == 0) error(XPCOM.NS_ERROR_NO_INTERFACE);		nsIBaseWindow baseWindow = new nsIBaseWindow(result[0]);		Rectangle rect = getClientArea();	if (rect.isEmpty()) {		rect.width = 1;		rect.height = 1;	}	/*	* Bug in Mozilla Linux GTK.  Embedding Mozilla into a GtkFixed	* handle causes problems with some Mozilla plug-ins.  For some	* reason, the Flash plug-in causes the child of the GtkFixed	* handle to be resized to 1 when the Flash document is loaded.	* That could be due to gtk_container_resize_children being called	* by Mozilla - or one of its plug-ins - on the GtkFixed handle,	* causing the child of the GtkFixed handle to be resized to 1.	* The workaround is to embed Mozilla into a GtkHBox handle.	*/	embedHandle = OS.gtk_hbox_new (false, 0);	OS.gtk_container_add (handle, embedHandle);	OS.gtk_widget_show (embedHandle);		rc = baseWindow.InitWindow(embedHandle, 0, 0, 0, rect.width, rect.height);	if (rc != XPCOM.NS_OK) error(XPCOM.NS_ERROR_FAILURE);	rc = baseWindow.Create();	if (rc != XPCOM.NS_OK) error(XPCOM.NS_ERROR_FAILURE);	rc = baseWindow.SetVisibility(true);	if (rc != XPCOM.NS_OK) error(XPCOM.NS_ERROR_FAILURE);	baseWindow.Release();	rc = webBrowser.AddWebBrowserListener(weakReference.getAddress(), nsIWebProgressListener.NS_IWEBPROGRESSLISTENER_IID);	if (rc != XPCOM.NS_OK) error(rc);	rc = webBrowser.SetParentURIContentListener(uriContentListener.getAddress());	if (rc != XPCOM.NS_OK) error(rc);	if (eventCallback == null) {		eventCallback = new Callback(Browser.class, "eventProc", 3);		eventProc = eventCallback.getAddress();		if (eventProc == 0) error(SWT.ERROR_NO_MORE_CALLBACKS);	}	/*	* Feature in Mozilla.  GtkEvents such as key down, key pressed may be consumed	* by Mozilla and never be received by the parent embedder.  The workaround	* is to find the top Mozilla gtk widget that receives all the Mozilla GtkEvents,	* i.e. the first child of the parent embedder. Then hook event callbacks and	* forward the event to the parent embedder before Mozilla received and consumed	* them.	*/	int /*long*/ list = OS.gtk_container_get_children(embedHandle);	if (list != 0) {		mozillaHandle = OS.g_list_data(list);		OS.g_list_free(list);				if (mozillaHandle != 0) {						getDisplay().setData(ADD_WIDGET_KEY, new Object[] {new LONG(mozillaHandle), this});			/* Note. Callback to get events before Mozilla receives and consumes them. */			OS.g_signal_connect (mozillaHandle, OS.event, eventProc, 1);						/* 			* Note.  Callback to get the events not consumed by Mozilla - and to block 			* them so that they don't get propagated to the parent handle twice.  			* This hook is set after Mozilla and is therefore called after Mozilla's 			* handler because GTK dispatches the event in the order of registration.			*/			OS.g_signal_connect (mozillaHandle, OS.key_press_event, eventProc, 2);		}	}		Listener listener = new Listener() {		public void handleEvent(Event event) {			switch (event.type) {				case SWT.Dispose: onDispose(event.display); break;				case SWT.Resize: onResize(); break;				case SWT.FocusIn: Activate(); break;				case SWT.Deactivate: {					Display display = event.display;					if (Browser.this == display.getFocusControl()) Deactivate();					break;				}				case SWT.Show: {					/*					* Feature on GTK Mozilla.  Mozilla does not show up when					* its container (a GTK fixed handle) is made visible					* after having been hidden.  The workaround is to reset					* its size after the container has been made visible. 					*/					Display display = event.display;					display.asyncExec(new Runnable() {						public void run() {							if (Browser.this.isDisposed()) return;							onResize();						}					});					break;				}			}		}	};		int[] folderEvents = new int[]{		SWT.Dispose,		SWT.Resize,  		SWT.FocusIn, 		SWT.KeyDown,		SWT.Deactivate,		SWT.Show	};	for (int i = 0; i < folderEvents.length; i++) {		addListener(folderEvents[i], listener);	}}