Back to index

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

#include <TestEmbed.h>

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

List of all members.

Public Member Functions

 CTestEmbedApp ()
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)
void RemoveFrameFromList (CBrowserFrame *pFrm, BOOL bCloseAppOnLastFrame=TRUE)
void ShowDebugConsole ()
BOOL IsCmdLineSwitch (const char *pSwitch, BOOL bRemove=TRUE)
void ParseCmdLine ()
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 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
CString m_strHomePage
int m_iStartupPage

Private Member Functions

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

Private Attributes

CProfileMgrm_ProfileMgr

Detailed Description

Definition at line 63 of file TestEmbed.h.


Constructor & Destructor Documentation

Definition at line 96 of file TestEmbed.cpp.

                             :
    m_ProfileMgr(NULL)
{
    mRefCnt = 1; // Start at one - nothing is going to addref this object

    m_strHomePage = "";

    m_iStartupPage = 0; 

}

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 512 of file TestEmbed.cpp.

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

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

       return TRUE;
}

Here is the caller graph for this function:

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

Definition at line 335 of file TestEmbed.cpp.

{
       // 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 = new CBrowserFrame(chromeMask);
       if (!pFrame->Create(NULL, strTitle, WS_OVERLAPPEDWINDOW, 
                                   winSize, NULL, MAKEINTRESOURCE(IDR_MAINFRAME), 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 caller graph for this function:

Definition at line 409 of file TestEmbed.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;
       nsresult rv;

       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();

    delete m_ProfileMgr;

       rv = NS_TermEmbedding();
       if (NS_FAILED(rv))
              QAOutput("TestEmbed didn't shut down.");
       else
              QAOutput("TestEmbed shut down.");

       return 1;
}

Here is the call graph for this function:

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

Definition at line 98 of file TestEmbed.h.

                                                  {
        strHomePage = m_strHomePage;
        return TRUE;
    }

Here is the caller graph for this function:

Definition at line 104 of file TestEmbed.h.

                                    {
        return m_iStartupPage;
    }

Here is the caller graph for this function:

Definition at line 525 of file TestEmbed.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)
              {
            m_iStartupPage = 1;
            m_strHomePage = "http://www.mozilla.org/projects/embedding";

            prefs->SetIntPref("browser.startup.page", m_iStartupPage);
            prefs->SetCharPref("browser.startup.homepage", 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);

            CString strBuf;
            char *pBuf = strBuf.GetBuffer(_MAX_PATH);
            prefs->CopyCharPref("browser.startup.homepage", &pBuf);
            strBuf.ReleaseBuffer(-1);
            if(pBuf)
                m_strHomePage = pBuf;
        }       
       }
       else
              NS_ASSERTION(PR_FALSE, "Could not get preferences service");
              
    return rv;
}

Here is the call graph for this function:

Here is the caller graph for this function:

Definition at line 486 of file TestEmbed.cpp.

{
    m_ProfileMgr = new CProfileMgr;
    if (!m_ProfileMgr)
        return FALSE;

       nsresult rv;

    nsCOMPtr<nsIObserverService>observerService(do_GetService("@mozilla.org/observer-service;1",&rv));
       if (NS_SUCCEEDED(rv)) 
       {        
              observerService->AddObserver(this, "profile-approve-change", PR_TRUE);
              observerService->AddObserver(this, "profile-change-teardown", PR_TRUE);
              observerService->AddObserver(this, "profile-after-change", PR_TRUE);
       }

    m_ProfileMgr->StartUp();

       return TRUE;
}

Here is the call graph for this function:

Here is the caller graph for this function:

Definition at line 577 of file TestEmbed.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 244 of file TestEmbed.cpp.

{
       QAOutput("****************************************************\r\n");

    ParseCmdLine();

       Enable3dControls();

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

       char curDir[_MAX_PATH+1];
       ::GetCurrentDirectory(_MAX_PATH, curDir);
       nsresult rv;
       nsCOMPtr<nsILocalFile> mreAppDir;
       rv = NS_NewNativeLocalFile(nsDependentCString(curDir), 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

    winEmbedFileLocProvider *provider = new winEmbedFileLocProvider("TestEmbed");
    if(!provider)
    {
        ASSERT(FALSE);
        return FALSE;
    }

    rv = NS_InitEmbedding(mreAppDir, provider);
    if(NS_FAILED(rv))
    {
              QAOutput("TestEmbed didn't start up.");
        ASSERT(FALSE);
        return FALSE;
    }
       else
              QAOutput("TestEmbed started up.");

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


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

       if(!InitializeProfiles())
       {
        ASSERT(FALSE);
        rv = NS_TermEmbedding();
              RvTestResult(rv, "TestEmbed shutdown");
              return FALSE;
       }

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

    if(!CreateHiddenWindow())
       {
        ASSERT(FALSE);
        rv = NS_TermEmbedding();
              RvTestResult(rv, "TestEmbed shutdown");
              return FALSE;
       }


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

       return TRUE;
}

Here is the call graph for this function:

BOOL CTestEmbedApp::IsCmdLineSwitch ( const char *  pSwitch,
BOOL  bRemove = TRUE 
)

Definition at line 109 of file TestEmbed.cpp.

{
    //  Search for the switch in the command line.
    //  Don't take it out of m_lpCmdLine by default
    char *pFound = PL_strcasestr(m_lpCmdLine, pSwitch);
    if(pFound == NULL ||
        // Switch must be at beginning of command line
        // or have a space in front of it to avoid
        // mangling filenames
        ( (pFound != m_lpCmdLine) &&
          *(pFound-1) != ' ' ) ) 
    {
        return(FALSE);
    }

    if (bRemove) 
    {
        // remove the flag from the command line
        char *pTravEnd = pFound + strlen(pSwitch);
        char *pTraverse = pFound;

        *pTraverse = *pTravEnd;
        while(*pTraverse != '\0')   
        {
            pTraverse++;
            pTravEnd++;
            *pTraverse = *pTravEnd;
        }
    }

    return(TRUE);
}

Here is the call graph for this function:

Here is the caller 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 699 of file TestEmbed.cpp.

{
       CAboutDlg aboutDlg;
       aboutDlg.DoModal();
}

Definition at line 456 of file TestEmbed.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)) 
        {     
            prefs->SetIntPref("browser.startup.page", m_iStartupPage);
            rv = prefs->SetCharPref("browser.startup.homepage", 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 CTestEmbedApp::OnIdle ( LONG  lCount) [virtual]

Definition at line 444 of file TestEmbed.cpp.

Definition at line 451 of file TestEmbed.cpp.

Here is the call graph for this function:

Definition at line 375 of file TestEmbed.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 161 of file TestEmbed.cpp.

{
    nsresult rv = NS_OK;

    // 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)) {
                nsCOMPtr<nsIComponentRegistrar> registrar;
                NS_GetComponentRegistrar(getter_AddRefs(registrar));
                if (registrar)
                    registrar->RegisterFactory(kPromptServiceCID,
                                               "Prompt Service",
                                               "@mozilla.org/embedcomp/prompt-service;1",
                                               promptFactory);
            }
        } else
          ::FreeLibrary(overlib);
    }

    return rv;
}

Here is the call graph for this function:

Here is the caller graph for this function:

Definition at line 142 of file TestEmbed.cpp.

{
    // Show Debug Console?
    if(IsCmdLineSwitch("-console"))
        ShowDebugConsole();
}

Here is the call graph for this function:

Here is the caller graph for this function:

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

Definition at line 393 of file TestEmbed.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);
}

Here is the caller graph for this function:

Definition at line 195 of file TestEmbed.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 95 of file TestEmbed.h.

Definition at line 103 of file TestEmbed.h.

Definition at line 128 of file TestEmbed.h.

Definition at line 97 of file TestEmbed.h.


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