Back to index

lightning-sunbird  0.9+nobinonly
Public Member Functions | Public Attributes | Private Member Functions | Private Attributes
CMfcEmbedApp Class Reference

#include <MfcEmbed.h>

Inheritance diagram for CMfcEmbedApp:
Inheritance graph
[legend]
Collaboration diagram for CMfcEmbedApp:
Collaboration graph
[legend]

List of all members.

Public Member Functions

 CMfcEmbedApp ()
NS_DECL_ISUPPORTS
NS_DECL_NSIOBSERVER
NS_DECL_NSIWINDOWCREATOR
CBrowserFrame
CreateNewBrowserFrame (PRUint32 chromeMask=nsIWebBrowserChrome::CHROME_ALL, PRInt32 x=-1, PRInt32 y=-1, PRInt32 cx=-1, PRInt32 cy=-1, PRBool bShowWindow=PR_TRUE, PRBool bIsEditor=PR_FALSE)
void RemoveFrameFromList (CBrowserFrame *pFrm, BOOL bCloseAppOnLastFrame=TRUE)
void ShowDebugConsole ()
nsresult OverrideComponents ()
virtual BOOL InitInstance ()
virtual int ExitInstance ()
virtual BOOL OnIdle (LONG lCount)
BOOL GetHomePage (CString &strHomePage)
int GetStartupPageMode ()
afx_msg void OnAppAbout ()
afx_msg void OnNewBrowser ()
afx_msg void OnNewEditor ()
afx_msg void OnManageProfiles ()
afx_msg void OnEditPreferences ()
void observe (in nsISupports aSubject, in string aTopic, in wstring aData)
 Observe will be called when there is a notification for the topic |aTopic|.
nsIWebBrowserChrome createChromeWindow (in nsIWebBrowserChrome parent, in PRUint32 chromeFlags)
 Create a new window.

Public Attributes

CObList m_FrameWndLst
BOOL m_bChrome
CString m_strHomePage
int m_iStartupPage

Private Member Functions

BOOL InitializeProfiles ()
BOOL CreateHiddenWindow ()
nsresult InitializePrefs ()
nsresult InitializeWindowCreator ()

Private Attributes

nsProfileDirServiceProviderm_ProfileDirServiceProvider

Detailed Description

Definition at line 57 of file MfcEmbed.h.


Constructor & Destructor Documentation

Definition at line 227 of file MfcEmbed.cpp.

{
    mRefCnt = 1; // Start at one - nothing is going to addref this object

#ifdef USE_PROFILES
    m_ProfileMgr = NULL;
#endif

    m_strHomePage = "";

    m_iStartupPage = 0; 

    m_bChrome = FALSE;
}

Member Function Documentation

Create a new window.

Gecko will/may call this method, if made available to it, to create new windows.

Parameters:
parentparent window, if any. null if not. the newly created window should be made a child/dependent window of the parent, if any (and if the concept applies to the underlying OS).
chromeFlagschrome features from nsIWebBrowserChrome
Returns:
the new window

Definition at line 722 of file MfcEmbed.cpp.

{
    CFrameWnd *hiddenWnd = new CFrameWnd;
    if(!hiddenWnd)
        return FALSE;

    RECT bounds = { -10010, -10010, -10000, -10000 };
    hiddenWnd->Create(NULL, _T("main"), WS_DISABLED, bounds, NULL, NULL, 0, NULL);
    m_pMainWnd = hiddenWnd;

    return TRUE;
}

Here is the caller graph for this function:

CBrowserFrame * CMfcEmbedApp::CreateNewBrowserFrame ( PRUint32  chromeMask = nsIWebBrowserChrome::CHROME_ALL,
PRInt32  x = -1,
PRInt32  y = -1,
PRInt32  cx = -1,
PRInt32  cy = -1,
PRBool  bShowWindow = PR_TRUE,
PRBool  bIsEditor = PR_FALSE 
)

Definition at line 482 of file MfcEmbed.cpp.

{
    UINT resId = bIsEditor ? IDR_EDITOR : IDR_MAINFRAME;

    // Setup a CRect with the requested window dimensions
    CRect winSize(x, y, cx, cy);

    // Use the Windows default if all are specified as -1
    if(x == -1 && y == -1 && cx == -1 && cy == -1)
        winSize = CFrameWnd::rectDefault;

    // Load the window title from the string resource table
    CString strTitle;
    strTitle.LoadString(IDR_MAINFRAME);

    // Now, create the browser frame
    CBrowserFrame* pFrame = bIsEditor ? ( new  CEditorFrame(chromeMask) ) :
                        ( new  CBrowserFrame(chromeMask) );
    pFrame->SetEditable(bIsEditor);

    if (!pFrame->Create(NULL, strTitle, WS_OVERLAPPEDWINDOW, 
                    winSize, NULL, MAKEINTRESOURCE(resId), 0L, NULL))
    {
        return NULL;
    }

    // load accelerator resource
    pFrame->LoadAccelTable(MAKEINTRESOURCE(IDR_MAINFRAME));

    // Show the window...
    if(bShowWindow)
    {
        pFrame->ShowWindow(SW_SHOW);
        pFrame->UpdateWindow();
    }

    // Add to the list of BrowserFrame windows
    m_FrameWndLst.AddHead(pFrame);

    return pFrame;
}

Here is the call graph for this function:

Here is the caller graph for this function:

Definition at line 575 of file MfcEmbed.cpp.

{
    // When File/Exit is chosen and if the user
    // has opened multiple browser windows shut all
    // of them down properly before exiting the app

    CBrowserFrame* pBrowserFrame = NULL;

    POSITION pos = m_FrameWndLst.GetHeadPosition();
    while( pos != NULL )
    {
        pBrowserFrame = (CBrowserFrame *) m_FrameWndLst.GetNext(pos);
        if(pBrowserFrame)
        {
            pBrowserFrame->ShowWindow(false);
            pBrowserFrame->DestroyWindow();
        }
    }
    m_FrameWndLst.RemoveAll();

    if (m_pMainWnd)
        m_pMainWnd->DestroyWindow();

#ifdef USE_PROFILES
    delete m_ProfileMgr;
#else
    if (m_ProfileDirServiceProvider)
    {
        m_ProfileDirServiceProvider->Shutdown();
        NS_RELEASE(m_ProfileDirServiceProvider);
    }
#endif

    NS_TermEmbedding();

#ifdef XPCOM_GLUE
    XPCOMGlueShutdown();
#endif

    return 1;
}

Here is the call graph for this function:

BOOL CMfcEmbedApp::GetHomePage ( CString &  strHomePage) [inline]

Definition at line 91 of file MfcEmbed.h.

                                                  {
        strHomePage = m_strHomePage;
        return TRUE;
    }

Definition at line 97 of file MfcEmbed.h.

                                    {
        return m_iStartupPage;
    }

Here is the caller graph for this function:

Definition at line 735 of file MfcEmbed.cpp.

{
   nsresult rv;
   nsCOMPtr<nsIPref> prefs(do_GetService(NS_PREF_CONTRACTID, &rv));
   if (NS_SUCCEEDED(rv)) {      

        // We are using the default prefs from mozilla. If you were
        // disributing your own, this would be done simply by editing
        // the default pref files.
        
        PRBool inited;
        rv = prefs->GetBoolPref("mfcbrowser.prefs_inited", &inited);
        if (NS_FAILED(rv) || !inited)
        {
            USES_CONVERSION;
            m_iStartupPage = 1;
            m_strHomePage = "http://www.mozilla.org/projects/embedding";

            prefs->SetIntPref("browser.startup.page", m_iStartupPage);
            prefs->SetCharPref("browser.startup.homepage", T2CA(m_strHomePage));
            prefs->SetIntPref("font.size.variable.x-western", 16);
            prefs->SetIntPref("font.size.fixed.x-western", 13);
            rv = prefs->SetBoolPref("mfcbrowser.prefs_inited", PR_TRUE);
            if (NS_SUCCEEDED(rv))
                rv = prefs->SavePrefFile(nsnull);
        }
        else
        {
            // The prefs are present, read them in

            prefs->GetIntPref("browser.startup.page", &m_iStartupPage);

            char* str = nsnull;
            prefs->GetCharPref("browser.startup.homepage", &str);
            if (str)
            {
                USES_CONVERSION;
                m_strHomePage = A2CT(str);
            }
            else
            {
                m_strHomePage.Empty();
            }
            nsMemory::Free(str);
        }       
    }
    else
        NS_ASSERTION(PR_FALSE, "Could not get preferences service");
        
    return rv;
}

Here is the call graph for this function:

Definition at line 660 of file MfcEmbed.cpp.

{

#ifdef MOZ_PROFILESHARING
    // If we are using profile sharing, get the sharing setup service
    nsCOMPtr<nsIProfileSharingSetup> sharingSetup =
        do_GetService("@mozilla.org/embedcomp/profile-sharing-setup;1");
    if (sharingSetup)
    {
        USES_CONVERSION;
        CString strRes;
        strRes.LoadString(IDS_PROFILES_NONSHARED_NAME);
        nsEmbedString nonSharedName(T2W(strRes));
        sharingSetup->EnableSharing(nonSharedName);
    }
#endif

    nsCOMPtr<nsIObserverService> observerService = 
             do_GetService("@mozilla.org/observer-service;1");
    if (!observerService)
        return FALSE;

    // Both the profile mgr and standalone nsProfileDirServiceProvider
    // send this notification.
    observerService->AddObserver(this, "profile-after-change", PR_TRUE);

#ifdef USE_PROFILES
    m_ProfileMgr = new CProfileMgr;
    if (!m_ProfileMgr)
        return FALSE;

    observerService->AddObserver(this, "profile-approve-change", PR_TRUE);
    observerService->AddObserver(this, "profile-change-teardown", PR_TRUE);

    m_ProfileMgr->StartUp();
#else
    nsresult rv;
    nsCOMPtr<nsIFile> appDataDir;
    NS_GetSpecialDirectory(NS_APP_APPLICATION_REGISTRY_DIR,
                                getter_AddRefs(appDataDir));
    if (!appDataDir)
        return FALSE;
    nsCOMPtr<nsProfileDirServiceProvider> profProvider;
    NS_NewProfileDirServiceProvider(PR_TRUE, getter_AddRefs(profProvider));
    if (!profProvider)
        return FALSE;
    profProvider->Register();    
    nsCOMPtr<nsILocalFile> localAppDataDir(do_QueryInterface(appDataDir));
    rv = profProvider->SetProfileDir(localAppDataDir);
    if (NS_FAILED(rv))
        return FALSE;
    NS_ADDREF(m_ProfileDirServiceProvider = profProvider);
#endif

    return TRUE;
}

Here is the call graph for this function:

Here is the caller graph for this function:

Definition at line 794 of file MfcEmbed.cpp.

{
  // give an nsIWindowCreator to the WindowWatcher service
  nsCOMPtr<nsIWindowCreator> windowCreator(NS_STATIC_CAST(nsIWindowCreator *, this));
  if (windowCreator) {
    nsCOMPtr<nsIWindowWatcher> wwatch(do_GetService(NS_WINDOWWATCHER_CONTRACTID));
    if (wwatch) {
      wwatch->SetWindowCreator(windowCreator);
      return NS_OK;
    }
  }
  return NS_ERROR_FAILURE;
}

Here is the call graph for this function:

Here is the caller graph for this function:

Definition at line 383 of file MfcEmbed.cpp.

{
#ifdef _BUILD_STATIC_BIN
    // Initialize XPCOM's module info table
    NSGetStaticModuleInfo = app_getModuleInfo;
#endif

#ifdef XPCOM_GLUE
    if (NS_FAILED(XPCOMGlueStartup(GRE_GetXPCOMPath()))) {
        MessageBox(NULL, "Could not initialize XPCOM. Perhaps the GRE\nis not installed or could not be found?", "MFCEmbed", MB_OK | MB_ICONERROR);
        return FALSE;
    }
#endif

    CMfcEmbedCommandLine cmdLine(*this);
    ParseCommandLine(cmdLine);
    
    Enable3dControls();

    //
    // 1. Determine the name of the dir from which the GRE based app is being run
    // from [It's OK to do this even if you're not running in an GRE env]
    //
    // 2. Create an nsILocalFile out of it which will passed in to NS_InitEmbedding()
    //
    // Please see http://www.mozilla.org/projects/embedding/GRE.html
    // for more info. on GRE

    TCHAR path[_MAX_PATH+1];
    ::GetModuleFileName(0, path, _MAX_PATH);
    TCHAR* lastSlash = _tcsrchr(path, _T('\\'));
    if (!lastSlash) {
        NS_ERROR("No slash in module file name... something is wrong.");
        return FALSE;
    }
    *lastSlash = _T('\0');

    USES_CONVERSION;
    nsresult rv;
    nsCOMPtr<nsILocalFile> mreAppDir;
    rv = NS_NewNativeLocalFile(nsEmbedCString(T2A(path)), TRUE, getter_AddRefs(mreAppDir));
    NS_ASSERTION(NS_SUCCEEDED(rv), "failed to create mreAppDir localfile");

    // Take a look at 
    // http://www.mozilla.org/projects/xpcom/file_locations.html
    // for more info on File Locations

    CString strRes;
    strRes.LoadString(IDS_PROFILES_FOLDER_NAME);
    winEmbedFileLocProvider *provider = new winEmbedFileLocProvider(nsEmbedCString(strRes));
    if(!provider)
    {
        ASSERT(FALSE);
        return FALSE;
    }

    rv = NS_InitEmbedding(mreAppDir, provider);
    if(NS_FAILED(rv))
    {
        ASSERT(FALSE);
        return FALSE;
    }

    rv = OverrideComponents();
    if(NS_FAILED(rv))
    {
        ASSERT(FALSE);
        return FALSE;
    }


    rv = InitializeWindowCreator();
    if (NS_FAILED(rv))
    {
        ASSERT(FALSE);
        return FALSE;
    }

    if(!InitializeProfiles())
    {
        ASSERT(FALSE);
        NS_TermEmbedding();
        return FALSE;
    }


    if(!CreateHiddenWindow())
    {
        ASSERT(FALSE);
        NS_TermEmbedding();
        return FALSE;
    }

    // Create the first browser frame window
    OnNewBrowser();

    return TRUE;
}

Here is the call graph for this function:

void nsIObserver::observe ( in nsISupports  aSubject,
in string  aTopic,
in wstring  aData 
) [inherited]

Observe will be called when there is a notification for the topic |aTopic|.

This assumes that the object implementing this interface has been registered with an observer service such as the nsIObserverService.

If you expect multiple topics/subjects, the impl is responsible for filtering.

You should not modify, add, remove, or enumerate notifications in the implemention of observe.

Parameters:
aSubject: Notification specific interface pointer.
aTopic: The notification topic or subject.
aData: Notification specific wide string. subject event.

Definition at line 918 of file MfcEmbed.cpp.

{
    CAboutDlg aboutDlg;
    aboutDlg.DoModal();
}

Definition at line 631 of file MfcEmbed.cpp.

{
    CPreferences prefs(_T("Preferences"));
    
    prefs.m_startupPage.m_iStartupPage = m_iStartupPage;
    prefs.m_startupPage.m_strHomePage = m_strHomePage;   

    if(prefs.DoModal() == IDOK)
    {
        // Update our member vars with these new pref values
        m_iStartupPage = prefs.m_startupPage.m_iStartupPage;
        m_strHomePage = prefs.m_startupPage.m_strHomePage;

        // Save these changes to disk now
        nsresult rv;
        nsCOMPtr<nsIPref> prefs(do_GetService(NS_PREF_CONTRACTID, &rv));
        if (NS_SUCCEEDED(rv)) 
        {
            USES_CONVERSION;
            prefs->SetIntPref("browser.startup.page", m_iStartupPage);
            rv = prefs->SetCharPref("browser.startup.homepage", T2CA(m_strHomePage));
            if (NS_SUCCEEDED(rv))
                rv = prefs->SavePrefFile(nsnull);
        }
        else
            NS_ASSERTION(PR_FALSE, "Could not get preferences service");
    }
}

Here is the call graph for this function:

BOOL CMfcEmbedApp::OnIdle ( LONG  lCount) [virtual]

Definition at line 617 of file MfcEmbed.cpp.

Definition at line 624 of file MfcEmbed.cpp.

{
#ifdef USE_PROFILES
    m_ProfileMgr->DoManageProfilesDialog(PR_FALSE);
#endif
}

Definition at line 529 of file MfcEmbed.cpp.

{
    CBrowserFrame *pBrowserFrame = CreateNewBrowserFrame();

    //Load the HomePage into the browser view
    if(pBrowserFrame && (GetStartupPageMode() == 1))
        pBrowserFrame->m_wndBrowserView.LoadHomePage();
}

Here is the call graph for this function:

Here is the caller graph for this function:

Definition at line 538 of file MfcEmbed.cpp.

{
    CEditorFrame *pEditorFrame = (CEditorFrame *)CreateNewBrowserFrame(nsIWebBrowserChrome::CHROME_ALL, 
                                    -1, -1, -1, -1,
                                    PR_TRUE,PR_TRUE);
    if (pEditorFrame)
    {
        pEditorFrame->InitEditor();
        pEditorFrame->m_wndBrowserView.OpenURL("about:blank");
    }
}

Here is the call graph for this function:

Definition at line 256 of file MfcEmbed.cpp.

{
    nsCOMPtr<nsIComponentRegistrar> compReg;
    nsresult rv = NS_GetComponentRegistrar(getter_AddRefs(compReg));
    NS_ENSURE_SUCCESS(rv, rv);
    
    // replace Mozilla's default PromptService with our own, if the
    // expected override DLL is present
    HMODULE overlib = ::LoadLibrary(kComponentsLibname);
    if (overlib) {
        InitPromptServiceType InitLib;
        MakeFactoryType MakeFactory;
        InitLib = reinterpret_cast<InitPromptServiceType>(::GetProcAddress(overlib, kPromptServiceInitFuncName));
        MakeFactory = reinterpret_cast<MakeFactoryType>(::GetProcAddress(overlib, kPromptServiceFactoryFuncName));

        if (InitLib && MakeFactory) {
            InitLib(overlib);

            nsCOMPtr<nsIFactory> promptFactory;
            rv = MakeFactory(getter_AddRefs(promptFactory));
            if (NS_SUCCEEDED(rv)) {
                compReg->RegisterFactory(kPromptServiceCID,
                                         "Prompt Service",
                                         "@mozilla.org/embedcomp/prompt-service;1",
                                         promptFactory);
            }
        } else
          ::FreeLibrary(overlib);
    }

    // Replace Mozilla's helper app launcher dialog with our own
    overlib = ::LoadLibrary(kComponentsLibname);
    if (overlib) {
        InitHelperAppDlgType InitLib;
        MakeFactoryType MakeFactory;
        InitLib = reinterpret_cast<InitHelperAppDlgType>(::GetProcAddress(overlib, kHelperAppDlgInitFuncName));
        MakeFactory = reinterpret_cast<MakeFactoryType>(::GetProcAddress(overlib, kHelperAppDlgFactoryFuncName));

        if (InitLib && MakeFactory) {
            InitLib(overlib);

            nsCOMPtr<nsIFactory> helperAppDlgFactory;
            rv = MakeFactory(getter_AddRefs(helperAppDlgFactory));
            if (NS_SUCCEEDED(rv))
                compReg->RegisterFactory(kHelperAppLauncherDialogCID,
                                         "Helper App Launcher Dialog",
                                         "@mozilla.org/helperapplauncherdialog;1",
                                         helperAppDlgFactory);
        } else
          ::FreeLibrary(overlib);
    }

    // replace Mozilla's default PrintingPromptService with our own, if the
    // expected override DLL is present
    overlib = ::LoadLibrary(kComponentsLibname);
    if (overlib) {
        InitPrintingPromptServiceType InitLib;
        MakeFactoryType MakeFactory;
        InitLib = reinterpret_cast<InitPrintingPromptServiceType>(::GetProcAddress(overlib, kPrintingPromptServiceInitFuncName));
        MakeFactory = reinterpret_cast<MakeFactoryType>(::GetProcAddress(overlib, kPrintingPromptServiceFactoryFuncName));

        if (InitLib && MakeFactory) {
            InitLib(overlib);

            nsCOMPtr<nsIFactory> printingPromptFactory;
            rv = MakeFactory(getter_AddRefs(printingPromptFactory));
            if (NS_SUCCEEDED(rv))
                compReg->RegisterFactory(kPrintingPromptServiceCID,
                                         "Printing Prompt Service",
                                         "@mozilla.org/embedcomp/printingprompt-service;1",
                                         printingPromptFactory);
        } else
          ::FreeLibrary(overlib);
    }
    return rv;
}

Here is the call graph for this function:

Here is the caller graph for this function:

void CMfcEmbedApp::RemoveFrameFromList ( CBrowserFrame pFrm,
BOOL  bCloseAppOnLastFrame = TRUE 
)

Definition at line 559 of file MfcEmbed.cpp.

{
    POSITION pos = m_FrameWndLst.Find(pFrm);
    m_FrameWndLst.RemoveAt(pos);

    // Send a WM_QUIT msg. to the hidden window if we've
    // just closed the last browserframe window and
    // if the bCloseAppOnLastFrame is TRUE. This be FALSE
    // only in the case we're switching profiles
    // Without this the hidden window will stick around
    // i.e. the app will never die even after all the 
    // visible windows are gone.
    if(m_FrameWndLst.GetCount() == 0 && bCloseAppOnLastFrame)
        m_pMainWnd->PostMessage(WM_QUIT);
}

Definition at line 333 of file MfcEmbed.cpp.

{
#ifdef _DEBUG
    // Show console only in debug mode

    if(! AllocConsole())
        return;

    // Redirect stdout to the console
    int hCrtOut = _open_osfhandle(
                (long) GetStdHandle(STD_OUTPUT_HANDLE),
                _O_TEXT);
    if(hCrtOut == -1)
        return;

    FILE *hfOut = _fdopen(hCrtOut, "w");
    if(hfOut != NULL)
    {
        // Setup for unbuffered I/O so the console 
        // output shows up right away
        *stdout = *hfOut;
        setvbuf(stdout, NULL, _IONBF, 0); 
    }

    // Redirect stderr to the console
    int hCrtErr = _open_osfhandle(
                (long) GetStdHandle(STD_ERROR_HANDLE),
                _O_TEXT);
    if(hCrtErr == -1)
        return;

    FILE *hfErr = _fdopen(hCrtErr, "w");
    if(hfErr != NULL)
    {
        // Setup for unbuffered I/O so the console 
        // output shows up right away
        *stderr = *hfErr;
        setvbuf(stderr, NULL, _IONBF, 0); 
    }
#endif
}

Here is the call graph for this function:

Here is the caller graph for this function:


Member Data Documentation

Definition at line 89 of file MfcEmbed.h.

Definition at line 87 of file MfcEmbed.h.

Definition at line 96 of file MfcEmbed.h.

Definition at line 126 of file MfcEmbed.h.

Definition at line 90 of file MfcEmbed.h.


The documentation for this class was generated from the following files: