| Summary: | Cannot get nsIDocShell on Mac OSX with SWT Browser | ||
|---|---|---|---|
| Product: | [Eclipse Project] Platform | Reporter: | Brian McGann <brianm> |
| Component: | SWT | Assignee: | Project Inbox <swt-triaged> |
| Status: | RESOLVED WORKSFORME | QA Contact: | Grant Gayed <grant_gayed> |
| Severity: | major | ||
| Priority: | P3 | CC: | stan.pratt |
| Version: | 4.1 | ||
| Target Milestone: | --- | ||
| Hardware: | Macintosh | ||
| OS: | Mac OS X - Carbon (unsup.) | ||
| Whiteboard: | |||
I was referred to a snippet of code from bug 160620 for accomplishing the fullZoom. This snippet doesn't even compile. static void setZoom(int zoom) { nsIWebBrowser webBrowser = (nsIWebBrowser)browser.getWebBrowser(); nsIInterfaceRequestor req = (nsIInterfaceRequestor)webBrowser.queryInterface(nsIInterfaceRequestor.NS_IINTERFACEREQUESTOR_IID); nsIDocShell docShell = (nsIDocShell)req.getInterface(nsIDocShell.NS_IDOCSHELL_IID); nsIContentViewer contentView = docShell.getContentViewer(); nsIMarkupDocumentViewer docView = (nsIMarkupDocumentViewer)contentView.queryInterface(nsIMarkupDocumentViewer.NS_IMARKUPDOCUMENTVIEWER_IID); float value = zoom / 10f; System.out.println("zoom: " + value); docView.setFullZoom(value); } the nsIWebBrowser class in SWT doesn't have a queryInterface function? I'm also on Mac OSX 10.6 and I've tried SWT 3.6-3.7 and XULRunner 1.9.2 (In reply to comment #0) The code snippet you provided doesn't match the SWT Browser's Mozilla implementation (eg.- SWT's Browser never uses IllegalStateException). Are you using a different browser implementation? Also, the SWT Browser should not attempt to use nsIDocShell for any real work unless a XULRunner version < 1.9 is detected. (In reply to comment #1) That snippet is using JavaXPCOM, so the nsIWebBrowser it references isn't the one from swt, but from org.mozilla.interfaces.*. For info on using JavaXPCOM see http://www.eclipse.org/swt/faq.php#howusejavaxpcom . (In reply to comment #2) > (In reply to comment #0) > > The code snippet you provided doesn't match the SWT Browser's Mozilla > implementation (eg.- SWT's Browser never uses IllegalStateException). Are you > using a different browser implementation? Also, the SWT Browser should not > attempt to use nsIDocShell for any real work unless a XULRunner version < 1.9 > is detected. > > > (In reply to comment #1) > > That snippet is using JavaXPCOM, so the nsIWebBrowser it references isn't the > one from swt, but from org.mozilla.interfaces.*. For info on using JavaXPCOM > see http://www.eclipse.org/swt/faq.php#howusejavaxpcom . My snippet was apparently not as illustrative as I intended: in the snippet, it is MY code that is throwing the exception in response to receiving XPCOM.NS_NOINTERFACE as a result code from the swt call. The main point, though, is that I have been unable to get access to nsIDocShell when using XULRunner 1.9; which you point out is something I should not be attempting to do. What I am actually attempting to do is setFullZoom(), and my understanding was that I needed: 1. nsIDocShell to get nsIDocContentViewer 2. nsIDocContentViewer to get nsIMarkupDocumentViewer 3. nsIMarkupDocumentViewer to invoke setFullZoom(zoomValue) Is there any way to setFullZoom() other than through the chain listed above for which I need access to nsIDocShell? I don't know if there's another path to use to set the zoom. Going through nsIDocShell as shown in the snippet in bug 160620 is fine though, as long as you are shipping a XULRunner and are accessing its internals via JavaXPCOM (not via SWT's internal XPCOM wrapper classes). The SWT Browser stopped using nsIDocShell because Eclipse does not ship a XULRunner, and the nsIDocShell interface was changing with each new XULRunner release, which would break the Browser. However if you nail the nsIDocShell interface down to the implementation contained in the XULRunner that you ship then it will remain stable for you. You can point the Browser at your shipped XULRunner as described in http://www.eclipse.org/swt/faq.php#specifyxulrunner . Closing report, as I don't think there's anything to be fixed in swt. |
Build Identifier: SWT 3.6 and 3.7 SWT Browser consistently generates failure on attempting to gain access to an nsIDocShell instance. On Mac OSX 10.6, using SWT 3.6.2 and 3.7M6 with XULRunner 1.9.2.13: ... int[] result = {0}; // get interface requestor int rc = webBrowser.QueryInterface(nsIInterfaceRequestor.NS_IINTERFAC EREQUESTOR_IID, result); if (rc != XPCOM.NS_OK){ throw new IllegalStateException("QueryInterface error=" + rc);} if (result[0] == 0) {throw new IllegalStateException("Interface unavailable");} nsIInterfaceRequestor interfaceRequestor = new nsIInterfaceRequestor(result[0]); // get docShell result[0] = 0; int rc = interfaceRequestor.GetInterface(nsIDocShell.NS_IDOCSHELL_IID , result); // always returns XPCOM.NS_NOINTERFACE Reproducible: Always