diff options
Diffstat (limited to 'bundles/org.eclipse.swt/Eclipse SWT Mozilla/common/org/eclipse/swt/browser')
2 files changed, 296 insertions, 62 deletions
diff --git a/bundles/org.eclipse.swt/Eclipse SWT Mozilla/common/org/eclipse/swt/browser/Mozilla.java b/bundles/org.eclipse.swt/Eclipse SWT Mozilla/common/org/eclipse/swt/browser/Mozilla.java index 150635f476..69e41c1c42 100644 --- a/bundles/org.eclipse.swt/Eclipse SWT Mozilla/common/org/eclipse/swt/browser/Mozilla.java +++ b/bundles/org.eclipse.swt/Eclipse SWT Mozilla/common/org/eclipse/swt/browser/Mozilla.java @@ -46,7 +46,7 @@ class Mozilla extends WebBrowser { int chromeFlags = nsIWebBrowserChrome.CHROME_DEFAULT; int registerFunctionsOnState = 0; int refCount, lastKeyCode, lastCharCode, authCount; - int /*long*/ request; + int /*long*/ request, badCertRequest; Point location, size; boolean visible, isChild, ignoreDispose, isRetrievingBadCert, isViewingErrorPage, ignoreAllMessages, untrustedText; boolean updateLastNavigateUrl; @@ -83,7 +83,8 @@ class Mozilla extends WebBrowser { static final char SEPARATOR_OS = System.getProperty ("file.separator").charAt (0); //$NON-NLS-1$ static final String ABOUT_BLANK = "about:blank"; //$NON-NLS-1$ static final String DISPOSE_LISTENER_HOOKED = "org.eclipse.swt.browser.Mozilla.disposeListenerHooked"; //$NON-NLS-1$ - static final String HEADER_CONTENTTYPE = "Content-Type"; //$NON-NLS-1 + static final String HEADER_CONTENTLENGTH = "content-length"; //$NON-NLS-1 + static final String HEADER_CONTENTTYPE = "content-type"; //$NON-NLS-1 static final String MIMETYPE_FORMURLENCODED = "application/x-www-form-urlencoded"; //$NON-NLS-1$ static final String PREFIX_JAVASCRIPT = "javascript:"; //$NON-NLS-1$ static final String PREFERENCE_CHARSET = "intl.charset.default"; //$NON-NLS-1$ @@ -953,7 +954,56 @@ public void create (Composite parent, int style) { break; } case SWT.Resize: onResize (); break; - case SWT.FocusIn: Activate (); break; + case SWT.FocusIn: { + Activate (); + + /* if tabbing onto a page for the first time then full-Browser focus ring should be shown */ + + int /*long*/[] result = new int /*long*/[1]; + int 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[] aContractID = MozillaDelegate.wcsToMbcs (null, XPCOM.NS_FOCUSMANAGER_CONTRACTID, true); + rc = serviceManager.GetServiceByContractID (aContractID, nsIFocusManager.NS_IFOCUSMANAGER_IID, result); + serviceManager.Release (); + + if (rc == XPCOM.NS_OK && result[0] != 0) { + nsIFocusManager focusManager = new nsIFocusManager (result[0]); + result[0] = 0; + rc = focusManager.GetFocusedElement (result); + if (rc == XPCOM.NS_OK) { + if (result[0] != 0) { + new nsISupports (result[0]).Release (); + result[0] = 0; + } else { + /* show full browser focus ring */ + rc = webBrowser.GetContentDOMWindow (result); + if (rc == XPCOM.NS_OK && result[0] != 0) { + nsIDOMWindow domWindow = new nsIDOMWindow (result[0]); + result[0] = 0; + rc = domWindow.GetDocument (result); + domWindow.Release (); + if (rc == XPCOM.NS_OK && result[0] != 0) { + nsIDOMDocument domDocument = new nsIDOMDocument (result[0]); + result[0] = 0; + rc = domDocument.GetDocumentElement (result); + domDocument.Release (); + if (rc == XPCOM.NS_OK && result[0] != 0) { + nsIDOMElement domElement = new nsIDOMElement (result[0]); + result[0] = 0; + rc = focusManager.SetFocus (domElement.getAddress (), nsIFocusManager.FLAG_BYKEY); + domElement.Release (); + } + } + } + } + } + focusManager.Release (); + } + break; + } case SWT.Activate: Activate (); break; case SWT.Deactivate: { Display display = event.display; @@ -2513,6 +2563,10 @@ void onDispose (Display display) { locationListeners = oldLocationListeners; } + if (badCertRequest != 0) { + new nsISupports (badCertRequest).Release (); + } + int rc = webBrowser.RemoveWebBrowserListener (weakReference.getAddress (), nsIWebProgressListener.NS_IWEBPROGRESSLISTENER_IID); if (rc != XPCOM.NS_OK) error (rc); @@ -2592,6 +2646,150 @@ void Deactivate () { webBrowserFocus.Release (); } +void navigate (int /*long*/ requestHandle) { + nsIRequest request = new nsIRequest (requestHandle); + + /* get the request post data, if any */ + int /*long*/[] result = new int /*long*/[1]; + byte[] postData = null; + final Vector headers = new Vector (); + int rc = request.QueryInterface (nsIUploadChannel.NS_IUPLOADCHANNEL_IID, result); + if (rc == XPCOM.NS_OK && result[0] != 0) { + nsIUploadChannel uploadChannel = new nsIUploadChannel (result[0]); + result[0] = 0; + rc = uploadChannel.GetUploadStream (result); + if (rc == XPCOM.NS_OK && result[0] != 0) { + nsIInputStream inputStream = new nsIInputStream (result[0]); + result[0] = 0; + rc = inputStream.QueryInterface (nsISeekableStream.NS_ISEEKABLESTREAM_IID, result); + if (rc == XPCOM.NS_OK && result[0] != 0) { + nsISeekableStream seekableStream = new nsISeekableStream (result[0]); + result[0] = 0; + long[] initialOffset = new long[1]; + rc = seekableStream.Tell (initialOffset); + if (rc == XPCOM.NS_OK) { + rc = seekableStream.Seek (nsISeekableStream.NS_SEEK_SET, 0); + if (rc == XPCOM.NS_OK) { + int[] available = new int[1]; + rc = inputStream.Available (available); + if (rc == XPCOM.NS_OK) { + int length = available[0]; + byte[] bytes = new byte[length]; + int[] retVal = new int[1]; + rc = inputStream.Read (bytes, length, retVal); + if (rc == XPCOM.NS_OK) { + int start = 0; + for (int i = 0; i < length; i++) { + if (bytes[i] == 13) { + byte[] current = new byte[i - start]; + System.arraycopy (bytes, start, current, 0, i - start); + String string = new String (current).trim (); + if (string.length () != 0) { + headers.add (string); + } else { + start = i + 2; /* skip \r\n */ + postData = new byte[length - start]; + System.arraycopy (bytes, start, postData, 0, length - start); + break; + } + start = i; + } + } + } + } + } + seekableStream.Seek (nsISeekableStream.NS_SEEK_SET, initialOffset[0]); + } + seekableStream.Release (); + } + inputStream.Release (); + } + uploadChannel.Release (); + } + + /* get the request headers */ + XPCOMObject visitor = new XPCOMObject (new int[] {2, 0, 0, 2}) { + int refCount = 0; + public int /*long*/ method0 (int /*long*/[] args) { + /* QueryInterface */ + int /*long*/ riid = args[0]; + int /*long*/ ppvObject = args[1]; + if (riid == 0 || ppvObject == 0) return XPCOM.NS_ERROR_NO_INTERFACE; + nsID guid = new nsID (); + XPCOM.memmove (guid, riid, nsID.sizeof); + if (guid.Equals (nsISupports.NS_ISUPPORTS_IID) || guid.Equals (nsIHttpHeaderVisitor.NS_IHTTPHEADERVISITOR_IID)) { + XPCOM.memmove (ppvObject, new int /*long*/[] {getAddress ()}, C.PTR_SIZEOF); + refCount++; + return XPCOM.NS_OK; + } + XPCOM.memmove (ppvObject, new int /*long*/[] {0}, C.PTR_SIZEOF); + return XPCOM.NS_ERROR_NO_INTERFACE; + } + public int /*long*/ method1 (int /*long*/[] args) { + /* AddRef */ + return ++refCount; + } + public int /*long*/ method2 (int /*long*/[] args) { + /* Release */ + if (--refCount == 0) dispose (); + return refCount; + } + public int /*long*/ method3 (int /*long*/[] args) { + /* VisitHeader */ + int /*long*/ aHeader = args[0]; + int /*long*/ aValue = args[1]; + + int length = XPCOM.nsEmbedCString_Length (aHeader); + int /*long*/ buffer = XPCOM.nsEmbedCString_get (aHeader); + byte[] dest = new byte[length]; + XPCOM.memmove (dest, buffer, length); + String header = new String (dest); + + length = XPCOM.nsEmbedCString_Length (aValue); + buffer = XPCOM.nsEmbedCString_get (aValue); + dest = new byte[length]; + XPCOM.memmove (dest, buffer, length); + String value = new String (dest); + + headers.add(header + ':' + value); + return XPCOM.NS_OK; + } + }; + + new nsISupports (visitor.getAddress ()).AddRef (); + rc = request.QueryInterface (nsIHttpChannel.NS_IHTTPCHANNEL_IID, result); + if (rc == XPCOM.NS_OK && result[0] != 0) { + nsIHttpChannel httpChannel = new nsIHttpChannel (result[0]); + result[0] = 0; + httpChannel.VisitRequestHeaders (visitor.getAddress ()); + httpChannel.Release (); + } + new nsISupports (visitor.getAddress ()).Release (); + + String[] headersArray = null; + int size = headers.size (); + if (size > 0) { + headersArray = new String[size]; + headers.copyInto (headersArray); + } + + /* a request's name often (but not always) is its url */ + String url = lastNavigateURL; + int /*long*/ name = XPCOM.nsEmbedCString_new (); + rc = request.GetName (name); + if (rc == XPCOM.NS_OK) { + int length = XPCOM.nsEmbedCString_Length (name); + int /*long*/ buffer = XPCOM.nsEmbedCString_get (name); + byte[] bytes = new byte[length]; + XPCOM.memmove (bytes, buffer, length); + String value = new String (bytes); + if (value.indexOf (":/") != -1) url = value; //$NON-NLS-1$ + } + XPCOM.nsEmbedCString_delete (name); + + setUrl (url, postData, headersArray); +} + void onResize () { Rectangle rect = browser.getClientArea (); int width = Math.max (1, rect.width); @@ -2781,6 +2979,14 @@ public boolean setText (String html, boolean trusted) { } public boolean setUrl (String url, String postData, String[] headers) { + byte[] postDataBytes = null; + if (postData != null) { + postDataBytes = MozillaDelegate.wcsToMbcs (null, postData, false); + } + return setUrl (url, postDataBytes, headers); +} + +boolean setUrl (String url, byte[] postData, String[] headers) { htmlBytes = null; int /*long*/[] result = new int /*long*/[1]; @@ -2813,18 +3019,35 @@ public boolean setUrl (String url, String postData, String[] headers) { componentManager.Release(); if (rc == XPCOM.NS_OK && result[0] != 0) { /* nsIMIMEInputStream is not in mozilla 1.4 */ - byte[] bytes = MozillaDelegate.wcsToMbcs (null, postData, false); - dataStream = new InputStream (bytes); + dataStream = new InputStream (postData); dataStream.AddRef (); postDataStream = new nsIMIMEInputStream (result[0]); rc = postDataStream.SetData (dataStream.getAddress ()); if (rc != XPCOM.NS_OK) error (rc); - rc = postDataStream.SetAddContentLength (1); - if (rc != XPCOM.NS_OK) error (rc); - byte[] name = MozillaDelegate.wcsToMbcs (null, HEADER_CONTENTTYPE, true); - byte[] value = MozillaDelegate.wcsToMbcs (null, MIMETYPE_FORMURLENCODED, true); - rc = postDataStream.AddHeader (name, value); + + boolean foundLength = false; + boolean foundType = false; + if (headers != null) { + for (int i = 0; i < headers.length; i++) { + int index = headers[i].indexOf (':'); + if (index != -1) { + String name = headers[i].substring (0, index).trim ().toLowerCase (); + if (name.equals (HEADER_CONTENTLENGTH)) { + foundLength = true; + } else if (name.equals (HEADER_CONTENTTYPE)) { + foundType = true; + } + } + } + } + rc = postDataStream.SetAddContentLength (foundLength ? 0 : 1); if (rc != XPCOM.NS_OK) error (rc); + if (!foundType) { + byte[] name = MozillaDelegate.wcsToMbcs (null, HEADER_CONTENTTYPE, true); + byte[] value = MozillaDelegate.wcsToMbcs (null, MIMETYPE_FORMURLENCODED, true); + rc = postDataStream.AddHeader (name, value); + if (rc != XPCOM.NS_OK) error (rc); + } } result[0] = 0; } @@ -3182,7 +3405,6 @@ int OnStateChange (int /*long*/ aWebProgress, int /*long*/ aRequest, int aStateF * callbacks on the channel so that our nsIBadCertListener2 will be invoked. */ if (isRetrievingBadCert) { - isRetrievingBadCert = false; nsIRequest request = new nsIRequest (aRequest); int rc = request.QueryInterface (nsIChannel.NS_ICHANNEL_IID, result); if (rc != XPCOM.NS_OK) error (rc); @@ -3214,6 +3436,37 @@ int OnStateChange (int /*long*/ aWebProgress, int /*long*/ aRequest, int aStateF registerFunctionsOnState = nsIWebProgressListener.STATE_TRANSFERRING; updateLastNavigateUrl = true; } else if ((aStateFlags & nsIWebProgressListener.STATE_STOP) != 0) { + if (isRetrievingBadCert) { + isRetrievingBadCert = false; + return XPCOM.NS_OK; + } + + /* + * If a site with a bad certificate is being encountered for the first time + * then store the request for future reference, set the isRetrievingBadCert + * flag and re-navigate to the site so that notification callbacks can be + * hooked on it to get its certificate info. + */ + switch (aStatus) { + case XPCOM.SSL_ERROR_BAD_CERT_DOMAIN: + case XPCOM.SEC_ERROR_CA_CERT_INVALID: + case XPCOM.SEC_ERROR_EXPIRED_CERTIFICATE: + case XPCOM.SEC_ERROR_EXPIRED_ISSUER_CERTIFICATE: + case XPCOM.SEC_ERROR_INADEQUATE_KEY_USAGE: + case XPCOM.SEC_ERROR_UNKNOWN_ISSUER: + case XPCOM.SEC_ERROR_UNTRUSTED_CERT: + case XPCOM.SEC_ERROR_UNTRUSTED_ISSUER: { + new nsISupports (aRequest).AddRef (); + if (badCertRequest != 0) { + new nsISupports (badCertRequest).Release (); + } + badCertRequest = aRequest; + isRetrievingBadCert = true; + navigate (aRequest); + return XPCOM.NS_OK; + } + } + /* * If this page's nsIDOMWindow handle is still in unhookedDOMWindows then * add its DOM listeners now. It's possible for this to happen since @@ -3954,7 +4207,7 @@ int OnStartURIOpen (int /*long*/ aURI, int /*long*/ retval) { if (value.indexOf ("aboutCertError.xhtml") != -1 || (isViewingErrorPage && value.indexOf ("javascript:showSecuritySection") != -1)) { //$NON-NLS-1$ //$NON-NLS-2$ XPCOM.memmove (retval, new int[] {1}, 4); /* PRBool */ isRetrievingBadCert = true; - setUrl (lastNavigateURL, null, null); + setUrl (lastNavigateURL, (byte[])null, null); return XPCOM.NS_OK; } isViewingErrorPage = value.indexOf ("netError.xhtml") != -1; //$NON-NLS-1$ @@ -4616,33 +4869,35 @@ int NotifyCertProblem (int /*long*/ socketInfo, int /*long*/ status, int /*long* browser.getDisplay().asyncExec(new Runnable() { public void run() { if (browser.isDisposed ()) return; - if (!url.equals (lastNavigateURL)) return; /* user has navigated elsewhere */ - - String message = Compatibility.getMessage ("SWT_InvalidCert_Message", new String[] {urlPort}); //$NON-NLS-1$ - if (new PromptDialog (browser.getShell ()).invalidCert (browser, message, finalProblems, cert)) { - int /*long*/[] result = new int /*long*/[1]; - int 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[] aContractID = MozillaDelegate.wcsToMbcs (null, XPCOM.NS_CERTOVERRIDE_CONTRACTID, true); - rc = serviceManager.GetServiceByContractID (aContractID, nsICertOverrideService.NS_ICERTOVERRIDESERVICE_IID, result); - if (rc != XPCOM.NS_OK) error (rc); - if (result[0] == 0) error (XPCOM.NS_NOINTERFACE); - serviceManager.Release (); - - nsICertOverrideService overrideService = new nsICertOverrideService (result[0]); - result[0] = 0; - byte[] hostBytes = MozillaDelegate.wcsToMbcs (null, host, false); - int /*long*/ hostString = XPCOM.nsEmbedCString_new (hostBytes, hostBytes.length); - rc = overrideService.RememberValidityOverride (hostString, port, cert.getAddress (), finalFlags, 1); - browser.setUrl (url); - XPCOM.nsEmbedCString_delete (hostString); - overrideService.Release (); + if (url.equals (lastNavigateURL)) { + String message = Compatibility.getMessage ("SWT_InvalidCert_Message", new String[] {urlPort}); //$NON-NLS-1$ + if (new PromptDialog (browser.getShell ()).invalidCert (browser, message, finalProblems, cert)) { + int /*long*/[] result = new int /*long*/[1]; + int 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[] aContractID = MozillaDelegate.wcsToMbcs (null, XPCOM.NS_CERTOVERRIDE_CONTRACTID, true); + rc = serviceManager.GetServiceByContractID (aContractID, nsICertOverrideService.NS_ICERTOVERRIDESERVICE_IID, result); + if (rc != XPCOM.NS_OK) error (rc); + if (result[0] == 0) error (XPCOM.NS_NOINTERFACE); + serviceManager.Release (); + + nsICertOverrideService overrideService = new nsICertOverrideService (result[0]); + result[0] = 0; + byte[] hostBytes = MozillaDelegate.wcsToMbcs (null, host, false); + int /*long*/ hostString = XPCOM.nsEmbedCString_new (hostBytes, hostBytes.length); + rc = overrideService.RememberValidityOverride (hostString, port, cert.getAddress (), finalFlags, 1); + navigate (badCertRequest); + XPCOM.nsEmbedCString_delete (hostString); + overrideService.Release (); + } } cert.Release (); + new nsISupports (badCertRequest).Release (); + badCertRequest = 0; } }); diff --git a/bundles/org.eclipse.swt/Eclipse SWT Mozilla/common/org/eclipse/swt/browser/PromptService2.java b/bundles/org.eclipse.swt/Eclipse SWT Mozilla/common/org/eclipse/swt/browser/PromptService2.java index 7f1d718a43..c641a2409b 100644 --- a/bundles/org.eclipse.swt/Eclipse SWT Mozilla/common/org/eclipse/swt/browser/PromptService2.java +++ b/bundles/org.eclipse.swt/Eclipse SWT Mozilla/common/org/eclipse/swt/browser/PromptService2.java @@ -21,17 +21,6 @@ class PromptService2 { XPCOMObject promptService2; int refCount = 0; - static final String[] certErrorCodes = new String[] { - "ssl_error_bad_cert_domain", - "sec_error_ca_cert_invalid", - "sec_error_expired_certificate", - "sec_error_expired_issuer_certificate", - "sec_error_inadequate_key_usage", - "sec_error_unknown_issuer", - "sec_error_untrusted_cert", - "sec_error_untrusted_issuer", - }; //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ //$NON-NLS-4$ //$NON-NLS-5$ //$NON-NLS-6$ //$NON-NLS-7$ //$NON-NLS-8$ - PromptService2 () { createCOMInterfaces (); } @@ -173,22 +162,12 @@ int Alert (int /*long*/ aParent, int /*long*/ aDialogTitle, int /*long*/ aText) String textLabel = new String (dest); /* - * If mozilla is showing its errors with dialogs (as opposed to pages) then the only - * opportunity to detect that a page has an invalid certificate, without receiving - * all notification callbacks on the channel, is to detect the displaying of an alert - * whose message contains an internal cert error code. If a such a message is - * detected then instead of showing it, re-navigate to the page with the invalid - * certificate so that the browser's nsIBadCertListener2 will be invoked. + * If mozilla is re-navigating to a page with a bad certificate in order + * to get its certificate info then do not show cert error message alerts. */ if (browser != null) { - for (int i = 0; i < certErrorCodes.length; i++) { - if (textLabel.indexOf (certErrorCodes[i]) != -1) { - Mozilla mozilla = (Mozilla)browser.webBrowser; - mozilla.isRetrievingBadCert = true; - browser.setUrl (mozilla.lastNavigateURL); - return XPCOM.NS_OK; - } - } + Mozilla mozilla = (Mozilla)browser.webBrowser; + if (mozilla.isRetrievingBadCert) return XPCOM.NS_OK; } Shell shell = browser == null ? new Shell () : browser.getShell (); |