Some Eclipse Foundation services are deprecated, or will be soon. Please ensure you've read this important communication.
Bug 343675 - Cannot get nsIDocShell on Mac OSX with SWT Browser
Summary: Cannot get nsIDocShell on Mac OSX with SWT Browser
Status: RESOLVED WORKSFORME
Alias: None
Product: Platform
Classification: Eclipse Project
Component: SWT (show other bugs)
Version: 4.1   Edit
Hardware: Macintosh Mac OS X - Carbon (unsup.)
: P3 major with 2 votes (vote)
Target Milestone: ---   Edit
Assignee: Project Inbox CLA
QA Contact: Grant Gayed CLA
URL:
Whiteboard:
Keywords:
Depends on:
Blocks:
 
Reported: 2011-04-22 19:28 EDT by Brian McGann CLA
Modified: 2011-04-29 10:42 EDT (History)
1 user (show)

See Also:


Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description Brian McGann CLA 2011-04-22 19:28:49 EDT
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
Comment 1 Stan Pratt CLA 2011-04-22 19:42:13 EDT
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
Comment 2 Grant Gayed CLA 2011-04-27 15:12:14 EDT
(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 .
Comment 3 Brian McGann CLA 2011-04-27 18:22:50 EDT
(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?
Comment 4 Grant Gayed CLA 2011-04-28 10:31:48 EDT
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 .
Comment 5 Grant Gayed CLA 2011-04-29 10:42:32 EDT
Closing report, as I don't think there's anything to be fixed in swt.