Back to index

lightning-sunbird  0.9+nobinonly
Defines | Functions
nsCocoaBrowserService.mm File Reference
#include "nsCocoaBrowserService.h"
#include "nsIWindowWatcher.h"
#include "nsIWebBrowserChrome.h"
#include "nsIEmbeddingSiteWindow.h"
#include "nsIProfile.h"
#include "NSBrowserView.h"
#include "nsCRT.h"
#include "nsString.h"

Go to the source code of this file.

Defines

#define NS_PROMPTSERVICE_CID   {0xa2112d6a, 0x0e28, 0x421f, {0xb4, 0x6a, 0x25, 0xc0, 0xb3, 0x8, 0xcb, 0xd0}}
#define NS_ALERT_NIB_NAME   "alert"

Functions

 NS_IMPL_ISUPPORTS3 (nsCocoaBrowserService, nsIWindowCreator, nsIPromptService, nsIFactory) nsresult nsCocoaBrowserService
static NSWindow * GetNSWindowForDOMWindow (nsIDOMWindow *window)

Define Documentation

#define NS_ALERT_NIB_NAME   "alert"

Definition at line 156 of file nsCocoaBrowserService.mm.

#define NS_PROMPTSERVICE_CID   {0xa2112d6a, 0x0e28, 0x421f, {0xb4, 0x6a, 0x25, 0xc0, 0xb3, 0x8, 0xcb, 0xd0}}

Function Documentation

static NSWindow* GetNSWindowForDOMWindow ( nsIDOMWindow window) [static]

Definition at line 195 of file nsCocoaBrowserService.mm.

{
  nsCOMPtr<nsIWindowWatcher> watcher(do_GetService("@mozilla.org/embedcomp/window-watcher;1"));
  if (!watcher) {
    return nsnull;
  }
  
  nsCOMPtr<nsIWebBrowserChrome> chrome;
  watcher->GetChromeForWindow(window, getter_AddRefs(chrome));
  if (!chrome) {
    return nsnull;
  }

  nsCOMPtr<nsIEmbeddingSiteWindow> siteWindow(do_QueryInterface(chrome));
  if (!siteWindow) {
    return nsnull;
  }

  NSWindow* nswin;
  siteWindow->GetSiteWindow((void**)&nswin);

  return nswin;
}

Here is the call graph for this function:

Definition at line 62 of file nsCocoaBrowserService.mm.

{
  if (sSingleton) {
    sNumBrowsers++;
    return NS_OK;
  }

  // XXX Temporary hack to make sure we find the 
  // right executable directory
  NSBundle* mainBundle = [NSBundle mainBundle];
  NSString* path = [mainBundle bundlePath];
  NSMutableString* mutablePath = [NSMutableString stringWithString:path];
  [mutablePath appendString:@"/Contents/MacOS/"];
  const char* cstr = [mutablePath cString];
  setenv("MOZILLA_FIVE_HOME", cstr, 1);

  sSingleton = new nsCocoaBrowserService();
  if (!sSingleton) {
    return NS_ERROR_OUT_OF_MEMORY;
  }
  NS_ADDREF(sSingleton);
  sNumBrowsers = 1;

  nsresult rv = NS_InitEmbedding(nsnull, nsnull);
  if (NS_FAILED(rv)) {
    return rv;
  }

  // Register as the prompt service
#define NS_PROMPTSERVICE_CID \
     {0xa2112d6a, 0x0e28, 0x421f, {0xb4, 0x6a, 0x25, 0xc0, 0xb3, 0x8, 0xcb, 0xd0}}
  static NS_DEFINE_CID(kPromptServiceCID, NS_PROMPTSERVICE_CID);

  nsCOMPtr<nsIComponentRegistrar> registrar;
  rv = NS_GetComponentRegistrar(getter_AddRefs(registrar));
  if (NS_FAILED(rv)) {
    return rv;
  }

  rv = registrar->RegisterFactory(kPromptServiceCID,
                                  "Prompt Service",
                                  "@mozilla.org/embedcomp/prompt-service;1",
                                  sSingleton);
  if (NS_FAILED(rv)) {
    return rv;
  }

  // Register as the window creator
  nsCOMPtr<nsIWindowWatcher> watcher(do_GetService("@mozilla.org/embedcomp/window-watcher;1"));
  if (!watcher) {
    return NS_ERROR_FAILURE;
  }

  watcher->SetWindowCreator(sSingleton);

  // Set the profile which the control will use
  nsCOMPtr<nsIProfile> profileService(do_GetService(NS_PROFILE_CONTRACTID, &rv));
  if (NS_FAILED(rv))
    return rv;

  // Make a new default profile for the control if none exists.
  nsAutoString newProfileName(NS_LITERAL_STRING("CocoazillaControl"));
  PRBool profileExists = PR_FALSE;
  rv = profileService->ProfileExists(newProfileName.get(), &profileExists);
  if (NS_FAILED(rv))
    return rv;
  
  if (!profileExists) {
    rv = profileService->CreateNewProfile(newProfileName.get(), nsnull, nsnull, PR_FALSE);
    if (NS_FAILED(rv))
      return rv;
  }

  rv = profileService->SetCurrentProfile(newProfileName.get());
  if (NS_FAILED(rv))
    return rv;

  return NS_OK;
}

Here is the call graph for this function: