Mozilla.dev.embedding

From CDOT Wiki
Revision as of 17:29, 13 October 2006 by Cdolivei (talk | contribs) (FAQ)
Jump to: navigation, search

Newsgroup

Mozilla.dev.embedding

Authors

  1. Cesar

There is already an FAQ on mozilla that probably wasn't properly linked in with Mozilla's FAQ page. Instead, I am going to make a list of asked questions on this page and mozilla can put it into their FAQ at their discretion.

FAQ

How to start Embedding

You can find a examples, FAQs, and the API from mozilla itself.
You can get more detailed information on what interfaces are required and which are optional to impelement here. Scroll down to "Initalization and Teardown.

How to customize document retrieval

One method is to implement your own protocol method. You can find more information on adding new protocols here

How to embedding mozilla inside of Java

There hasn't been any good code examples found. However, there is a stripped down, uncommented code with eclipse libraries in this thread. Here is the code :

import org.eclipse.swt.SWT;
import org.eclipse.swt.browser.MozillaBrowser;
import org.eclipse.swt.browser.ProgressEvent;
import org.eclipse.swt.browser.ProgressListener;
import org.eclipse.swt.widgets.Display;
import org.eclipse.swt.widgets.Shell;
import org.mozilla.xpcom.nsIDOMDocument;

public class Test {
        public static void main(String args[]) {
                Display display = new Display();
                Shell shell = new Shell(display);

                final MozillaBrowser browser = new MozillaBrowser(shell,WT.BORDER);
                browser.setUrl("http://www.google.com");
                browser.addProgressListener(new ProgressListener() {
                        public void changed(ProgressEvent event) {
                        }

                        public void completed(ProgressEvent event) {
                            nsIDOMDocument doc = browser.getDocument();
                                System.out.println(doc);
                        }
                });

                while (!shell.isDisposed()) {
                        if (!display.readAndDispatch()) {
                                display.sleep();
                        }
                }
        }

How to map a Javascript function to a C++ function

Define an XPCOM class defining the function you'll be doing in javascript. Then pass the object to your XPCOM coded object and call it from C++. You can find a better quality answer repeated and with an example in this newsgroup thread.

nsIPromptService with secure sites

The problem is getting "Security Error: Domain Name Mismatch" when visting certain secure sites. You get no text and no functionality. There are two possible solutions to this error.

  1. The Dialog is not handled by the prompt service. You must implement another interface (for example, nsIBadCertListener)
  2. The original dialog does not work correctly because your application is not handling chrome correctly. Here are some things other people have used to solve their problems :
    • This will get the text in the security popup and allow you to view the certificate :
      In the nsIWindowCreator::CreateChromeWindow() implementation, change the doc shell tree item's type to nsIDocShellTreeItem::typeChromeWrapper to nsIDocShellTreeItem::typeContentWrapper to view the certificate. You can nsIWebBrowserChrome::CHROME_OPENAS_CHROME to check when to use typeChromeWrapper and typeContentWrapper
    • This will tell the browser to progress to the secure site

:nsCOMPtr<nsIJSContextStack> stack(do_GetService("@mozilla.org/js/xpc/ContextStack;1"));
if (stack && NS_SUCCEEDED(stack->Push(nsnull))) {
  /* Display the modal window here */
  JSContext* cx;
  stack->Pop(&cx);
}