You are currently viewing a snapshot of www.mozilla.org taken on April 21, 2008. Most of this content is highly out of date (some pages haven't been updated since the project began in 1998) and exists for historical purposes only. If there are any pages on this archive site that you think should be added back to www.mozilla.org, please file a bug.



Create browser snippet [ << Previous | Contents | Next >> ]
This fragment instanciates a nsWebBrowser component and sets your window as the container for this nsWebBrowser.
  // include core Mozilla system headers
  #include "nsComponentManager.h"

  // include pertinent embedding interfaces
  #include "nsIBaseWindow.h"
  #include "nsIWebBrowser.h"
  ...
  nsCOMPtr<nsIBaseWindow> baseWindow;
  nsCOMPtr<nsIWebBrowser> webBrowser;

  // Create a nsWebBrowser instance
  webBrowser = do_CreateInstance(NS_WEBBROWSER_CONTRACTID, &rv);
  if (NS_FAILED(rv)) return rv;

  // Register embedding component which implements the 
  // window level callback interface.
  rv = webBrowser->SetContainerWindow(
      NS_STATIC_CAST(nsIWebBrowserChrome*, this));
  if (NS_FAILED(rv)) return rv;