Back to index

lightning-sunbird  0.9+nobinonly
TestEmbed.cpp
Go to the documentation of this file.
00001 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
00002 /* ***** BEGIN LICENSE BLOCK *****
00003  * Version: MPL 1.1/GPL 2.0/LGPL 2.1
00004  *
00005  * The contents of this file are subject to the Mozilla Public License Version
00006  * 1.1 (the "License"); you may not use this file except in compliance with
00007  * the License. You may obtain a copy of the License at
00008  * http://www.mozilla.org/MPL/
00009  *
00010  * Software distributed under the License is distributed on an "AS IS" basis,
00011  * WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
00012  * for the specific language governing rights and limitations under the
00013  * License.
00014  *
00015  * The Original Code is mozilla.org code.
00016  *
00017  * The Initial Developer of the Original Code is
00018  * Netscape Communications Corporation.
00019  * Portions created by the Initial Developer are Copyright (C) 1998
00020  * the Initial Developer. All Rights Reserved.
00021  *
00022  * Contributor(s):
00023  *   Chak Nanga <chak@netscape.com>
00024  *   Conrad Carlen <ccarlen@netscape.com>
00025  *
00026  * Alternatively, the contents of this file may be used under the terms of
00027  * either the GNU General Public License Version 2 or later (the "GPL"), or
00028  * the GNU Lesser General Public License Version 2.1 or later (the "LGPL"),
00029  * in which case the provisions of the GPL or the LGPL are applicable instead
00030  * of those above. If you wish to allow use of your version of this file only
00031  * under the terms of either the GPL or the LGPL, and not to allow others to
00032  * use your version of this file under the terms of the MPL, indicate your
00033  * decision by deleting the provisions above and replace them with the notice
00034  * and other provisions required by the GPL or the LGPL. If you do not delete
00035  * the provisions above, a recipient may use your version of this file under
00036  * the terms of any one of the MPL, the GPL or the LGPL.
00037  *
00038  * ***** END LICENSE BLOCK ***** */
00039 
00040 // File Overview....
00041 //
00042 // The typical MFC app, frame creation code + AboutDlg handling
00043 //
00044 // NS_InitEmbedding() is called in InitInstance()
00045 // 
00046 // NS_TermEmbedding() is called in ExitInstance()
00047 // ExitInstance() also takes care of cleaning up of
00048 // multiple browser frame windows on app exit
00049 //
00050 //
00051 // Code to handle the creation of a new browser window
00052 
00053 // Next suggested file to look at : BrowserFrm.cpp
00054 
00055 // Local Includes
00056 #include "stdafx.h"
00057 #include "BrowserImpl.h"
00058 #include "TestEmbed.h"
00059 #include "BrowserFrm.h"
00060 #include "winEmbedFileLocProvider.h"
00061 #include "ProfileMgr.h"
00062 #include "BrowserView.h"
00063 #include "nsIWindowWatcher.h"
00064 #include "nsIComponentRegistrar.h"
00065 #include "plstr.h"
00066 #include "Preferences.h"
00067 #include <io.h>
00068 #include <fcntl.h>
00069 
00070 #include "QAUtils.h"
00071 
00072 #ifdef _DEBUG
00073 #define new DEBUG_NEW
00074 #undef THIS_FILE
00075 static char THIS_FILE[] = __FILE__;
00076 #endif
00077 
00078 // this is for overriding the Mozilla default PromptService component
00079 #include "PromptService.h"
00080 #define kComponentsLibname "testEmbedComponents.dll"
00081 #define NS_PROMPTSERVICE_CID \
00082  {0xa2112d6a, 0x0e28, 0x421f, {0xb4, 0x6a, 0x25, 0xc0, 0xb3, 0x8, 0xcb, 0xd0}}
00083 static NS_DEFINE_CID(kPromptServiceCID, NS_PROMPTSERVICE_CID);
00084 
00085 BEGIN_MESSAGE_MAP(CTestEmbedApp, CWinApp)
00086        //{{AFX_MSG_MAP(CTestEmbedApp)
00087        ON_COMMAND(ID_NEW_BROWSER, OnNewBrowser)
00088        ON_COMMAND(ID_MANAGE_PROFILES, OnManageProfiles)
00089        ON_COMMAND(ID_APP_ABOUT, OnAppAbout)
00090     ON_COMMAND(ID_EDIT_PREFERENCES, OnEditPreferences)
00091        // NOTE - the ClassWizard will add and remove mapping macros here.
00092        //    DO NOT EDIT what you see in these blocks of generated code!
00093        //}}AFX_MSG_MAP
00094 END_MESSAGE_MAP()
00095 
00096 CTestEmbedApp::CTestEmbedApp() :
00097     m_ProfileMgr(NULL)
00098 {
00099     mRefCnt = 1; // Start at one - nothing is going to addref this object
00100 
00101     m_strHomePage = "";
00102 
00103     m_iStartupPage = 0; 
00104 
00105 }
00106 
00107 CTestEmbedApp theApp;
00108 
00109 BOOL CTestEmbedApp::IsCmdLineSwitch(const char *pSwitch, BOOL bRemove)
00110 {
00111     //  Search for the switch in the command line.
00112     //  Don't take it out of m_lpCmdLine by default
00113     char *pFound = PL_strcasestr(m_lpCmdLine, pSwitch);
00114     if(pFound == NULL ||
00115         // Switch must be at beginning of command line
00116         // or have a space in front of it to avoid
00117         // mangling filenames
00118         ( (pFound != m_lpCmdLine) &&
00119           *(pFound-1) != ' ' ) ) 
00120     {
00121         return(FALSE);
00122     }
00123 
00124     if (bRemove) 
00125     {
00126         // remove the flag from the command line
00127         char *pTravEnd = pFound + strlen(pSwitch);
00128         char *pTraverse = pFound;
00129 
00130         *pTraverse = *pTravEnd;
00131         while(*pTraverse != '\0')   
00132         {
00133             pTraverse++;
00134             pTravEnd++;
00135             *pTraverse = *pTravEnd;
00136         }
00137     }
00138 
00139     return(TRUE);
00140 }
00141 
00142 void CTestEmbedApp::ParseCmdLine()
00143 {
00144     // Show Debug Console?
00145     if(IsCmdLineSwitch("-console"))
00146         ShowDebugConsole();
00147 }
00148 
00149 /* Some Gecko interfaces are implemented as components, automatically
00150    registered at application initialization. nsIPrompt is an example:
00151    the default implementation uses XUL, not native windows. Embedding
00152    apps can override the default implementation by implementing the
00153    nsIPromptService interface and registering a factory for it with
00154    the same CID and Contract ID as the default's.
00155 
00156    Note that this example implements the service in a separate DLL,
00157    replacing the default if the override DLL is present. This could
00158    also have been done in the same module, without a separate DLL.
00159    See the PowerPlant example for, well, an example.
00160 */
00161 nsresult CTestEmbedApp::OverrideComponents()
00162 {
00163     nsresult rv = NS_OK;
00164 
00165     // replace Mozilla's default PromptService with our own, if the
00166     // expected override DLL is present
00167     HMODULE overlib = ::LoadLibrary(kComponentsLibname);
00168     if (overlib) {
00169         InitPromptServiceType InitLib;
00170         MakeFactoryType MakeFactory;
00171         InitLib = reinterpret_cast<InitPromptServiceType>(::GetProcAddress(overlib, kPromptServiceInitFuncName));
00172         MakeFactory = reinterpret_cast<MakeFactoryType>(::GetProcAddress(overlib, kPromptServiceFactoryFuncName));
00173 
00174         if (InitLib && MakeFactory) {
00175             InitLib(overlib);
00176 
00177             nsCOMPtr<nsIFactory> promptFactory;
00178             rv = MakeFactory(getter_AddRefs(promptFactory));
00179             if (NS_SUCCEEDED(rv)) {
00180                 nsCOMPtr<nsIComponentRegistrar> registrar;
00181                 NS_GetComponentRegistrar(getter_AddRefs(registrar));
00182                 if (registrar)
00183                     registrar->RegisterFactory(kPromptServiceCID,
00184                                                "Prompt Service",
00185                                                "@mozilla.org/embedcomp/prompt-service;1",
00186                                                promptFactory);
00187             }
00188         } else
00189           ::FreeLibrary(overlib);
00190     }
00191 
00192     return rv;
00193 }
00194 
00195 void CTestEmbedApp::ShowDebugConsole()
00196 {
00197 #ifdef _DEBUG
00198     // Show console only in debug mode
00199 
00200     if(! AllocConsole())
00201         return;
00202 
00203     // Redirect stdout to the console
00204     int hCrtOut = _open_osfhandle(
00205                 (long) GetStdHandle(STD_OUTPUT_HANDLE),
00206                 _O_TEXT);
00207     if(hCrtOut == -1)
00208         return;
00209 
00210     FILE *hfOut = _fdopen(hCrtOut, "w");
00211     if(hfOut != NULL)
00212     {
00213         // Setup for unbuffered I/O so the console 
00214         // output shows up right away
00215         *stdout = *hfOut;
00216         setvbuf(stdout, NULL, _IONBF, 0); 
00217     }
00218 
00219     // Redirect stderr to the console
00220     int hCrtErr = _open_osfhandle(
00221                 (long) GetStdHandle(STD_ERROR_HANDLE),
00222                 _O_TEXT);
00223     if(hCrtErr == -1)
00224         return;
00225 
00226     FILE *hfErr = _fdopen(hCrtErr, "w");
00227     if(hfErr != NULL)
00228     {
00229         // Setup for unbuffered I/O so the console 
00230         // output shows up right away
00231         *stderr = *hfErr;
00232         setvbuf(stderr, NULL, _IONBF, 0); 
00233     }
00234 #endif
00235 }
00236 
00237 // Initialize our MFC application and also init
00238 // the Gecko embedding APIs
00239 // Note that we're also init'ng the profile switching
00240 // code here
00241 // Then, create a new BrowserFrame and load our
00242 // default homepage
00243 //
00244 BOOL CTestEmbedApp::InitInstance()
00245 {
00246        QAOutput("****************************************************\r\n");
00247 
00248     ParseCmdLine();
00249 
00250        Enable3dControls();
00251 
00252        //
00253        // 1. Determine the name of the dir from which the MRE based app is being run
00254        // from [It's OK to do this even if you're not running in an MRE env]
00255        //
00256        // 2. Create an nsILocalFile out of it which will passed in to NS_InitEmbedding()
00257        //
00258        // Please see http://www.mozilla.org/projects/embedding/MRE.html
00259        // for more info. on MRE
00260 
00261        char curDir[_MAX_PATH+1];
00262        ::GetCurrentDirectory(_MAX_PATH, curDir);
00263        nsresult rv;
00264        nsCOMPtr<nsILocalFile> mreAppDir;
00265        rv = NS_NewNativeLocalFile(nsDependentCString(curDir), TRUE, getter_AddRefs(mreAppDir));
00266        NS_ASSERTION(NS_SUCCEEDED(rv), "failed to create mreAppDir localfile");
00267 
00268        // Take a look at 
00269        // http://www.mozilla.org/projects/xpcom/file_locations.html
00270        // for more info on File Locations
00271 
00272     winEmbedFileLocProvider *provider = new winEmbedFileLocProvider("TestEmbed");
00273     if(!provider)
00274     {
00275         ASSERT(FALSE);
00276         return FALSE;
00277     }
00278 
00279     rv = NS_InitEmbedding(mreAppDir, provider);
00280     if(NS_FAILED(rv))
00281     {
00282               QAOutput("TestEmbed didn't start up.");
00283         ASSERT(FALSE);
00284         return FALSE;
00285     }
00286        else
00287               QAOutput("TestEmbed started up.");
00288 
00289     rv = OverrideComponents();
00290     if(NS_FAILED(rv))
00291     {
00292         ASSERT(FALSE);
00293         return FALSE;
00294     }
00295 
00296 
00297     rv = InitializeWindowCreator();
00298     if (NS_FAILED(rv))
00299     {
00300         ASSERT(FALSE);
00301         return FALSE;
00302     }
00303 
00304        if(!InitializeProfiles())
00305        {
00306         ASSERT(FALSE);
00307         rv = NS_TermEmbedding();
00308               RvTestResult(rv, "TestEmbed shutdown");
00309               return FALSE;
00310        }
00311 
00312        rv = InitializePrefs();
00313        if (NS_FAILED(rv))
00314        {
00315         ASSERT(FALSE);
00316         NS_TermEmbedding();
00317               return FALSE;
00318        }
00319 
00320     if(!CreateHiddenWindow())
00321        {
00322         ASSERT(FALSE);
00323         rv = NS_TermEmbedding();
00324               RvTestResult(rv, "TestEmbed shutdown");
00325               return FALSE;
00326        }
00327 
00328 
00329        // Create the first browser frame window
00330        OnNewBrowser();
00331 
00332        return TRUE;
00333 }
00334 
00335 CBrowserFrame* CTestEmbedApp::CreateNewBrowserFrame(PRUint32 chromeMask,
00336                                                                                        PRInt32 x, PRInt32 y,
00337                                                                                        PRInt32 cx, PRInt32 cy,
00338                                                                                        PRBool bShowWindow)
00339 {
00340        // Setup a CRect with the requested window dimensions
00341        CRect winSize(x, y, cx, cy);
00342 
00343        // Use the Windows default if all are specified as -1
00344        if(x == -1 && y == -1 && cx == -1 && cy == -1)
00345               winSize = CFrameWnd::rectDefault;
00346 
00347        // Load the window title from the string resource table
00348        CString strTitle;
00349        strTitle.LoadString(IDR_MAINFRAME);
00350 
00351        // Now, create the browser frame
00352        CBrowserFrame* pFrame = new CBrowserFrame(chromeMask);
00353        if (!pFrame->Create(NULL, strTitle, WS_OVERLAPPEDWINDOW, 
00354                                    winSize, NULL, MAKEINTRESOURCE(IDR_MAINFRAME), 0L, NULL))
00355        {
00356               return NULL;
00357        }
00358 
00359        // load accelerator resource
00360        pFrame->LoadAccelTable(MAKEINTRESOURCE(IDR_MAINFRAME));
00361 
00362        // Show the window...
00363        if(bShowWindow)
00364        {
00365               pFrame->ShowWindow(SW_SHOW);
00366               pFrame->UpdateWindow();
00367        }
00368 
00369        // Add to the list of BrowserFrame windows
00370        m_FrameWndLst.AddHead(pFrame);
00371 
00372        return pFrame;
00373 }
00374 
00375 void CTestEmbedApp::OnNewBrowser()
00376 {
00377        CBrowserFrame *pBrowserFrame = CreateNewBrowserFrame();
00378 
00379        //Load the HomePage into the browser view
00380        if(pBrowserFrame && (GetStartupPageMode() == 1))
00381               pBrowserFrame->m_wndBrowserView.LoadHomePage();
00382 }
00383 
00384 // This gets called anytime a BrowserFrameWindow is
00385 // closed i.e. by choosing the "close" menu item from
00386 // a window's system menu or by dbl clicking on the
00387 // system menu box
00388 // 
00389 // Sends a WM_QUIT to the hidden window which results
00390 // in ExitInstance() being called and the app is
00391 // properly cleaned up and shutdown
00392 //
00393 void CTestEmbedApp::RemoveFrameFromList(CBrowserFrame* pFrm, BOOL bCloseAppOnLastFrame/*= TRUE*/)
00394 {
00395        POSITION pos = m_FrameWndLst.Find(pFrm);
00396        m_FrameWndLst.RemoveAt(pos);
00397 
00398        // Send a WM_QUIT msg. to the hidden window if we've
00399        // just closed the last browserframe window and
00400        // if the bCloseAppOnLastFrame is TRUE. This be FALSE
00401        // only in the case we're switching profiles
00402        // Without this the hidden window will stick around
00403        // i.e. the app will never die even after all the 
00404        // visible windows are gone.
00405        if(m_FrameWndLst.GetCount() == 0 && bCloseAppOnLastFrame)
00406               m_pMainWnd->PostMessage(WM_QUIT);
00407 }
00408 
00409 int CTestEmbedApp::ExitInstance()
00410 {
00411        // When File/Exit is chosen and if the user
00412        // has opened multiple browser windows shut all
00413        // of them down properly before exiting the app
00414 
00415        CBrowserFrame* pBrowserFrame = NULL;
00416        nsresult rv;
00417 
00418        POSITION pos = m_FrameWndLst.GetHeadPosition();
00419        while( pos != NULL )
00420        {
00421               pBrowserFrame = (CBrowserFrame *) m_FrameWndLst.GetNext(pos);
00422               if(pBrowserFrame)
00423               {
00424                      pBrowserFrame->ShowWindow(false);
00425                      pBrowserFrame->DestroyWindow();
00426               }
00427        }
00428        m_FrameWndLst.RemoveAll();
00429 
00430     if (m_pMainWnd)
00431         m_pMainWnd->DestroyWindow();
00432 
00433     delete m_ProfileMgr;
00434 
00435        rv = NS_TermEmbedding();
00436        if (NS_FAILED(rv))
00437               QAOutput("TestEmbed didn't shut down.");
00438        else
00439               QAOutput("TestEmbed shut down.");
00440 
00441        return 1;
00442 }
00443 
00444 BOOL CTestEmbedApp::OnIdle(LONG lCount)
00445 {
00446        CWinApp::OnIdle(lCount);
00447 
00448        return FALSE;
00449 }
00450 
00451 void CTestEmbedApp::OnManageProfiles()
00452 {
00453     m_ProfileMgr->DoManageProfilesDialog(PR_FALSE);
00454 }
00455 
00456 void CTestEmbedApp::OnEditPreferences()
00457 {
00458     CPreferences prefs(_T("Preferences"));
00459     
00460     prefs.m_startupPage.m_iStartupPage = m_iStartupPage;
00461     prefs.m_startupPage.m_strHomePage = m_strHomePage;   
00462 
00463     if(prefs.DoModal() == IDOK)
00464     {
00465         // Update our member vars with these new pref values
00466         m_iStartupPage = prefs.m_startupPage.m_iStartupPage;
00467         m_strHomePage = prefs.m_startupPage.m_strHomePage;
00468 
00469         // Save these changes to disk now
00470         nsresult rv;
00471 
00472               nsCOMPtr<nsIPref> prefs(do_GetService(NS_PREF_CONTRACTID,&rv));
00473 
00474         if (NS_SUCCEEDED(rv)) 
00475         {     
00476             prefs->SetIntPref("browser.startup.page", m_iStartupPage);
00477             rv = prefs->SetCharPref("browser.startup.homepage", m_strHomePage);
00478             if (NS_SUCCEEDED(rv))
00479                 rv = prefs->SavePrefFile(nsnull);
00480         }
00481         else
00482                   NS_ASSERTION(PR_FALSE, "Could not get preferences service");
00483     }
00484 }
00485 
00486 BOOL CTestEmbedApp::InitializeProfiles()
00487 {
00488     m_ProfileMgr = new CProfileMgr;
00489     if (!m_ProfileMgr)
00490         return FALSE;
00491 
00492        nsresult rv;
00493 
00494     nsCOMPtr<nsIObserverService>observerService(do_GetService("@mozilla.org/observer-service;1",&rv));
00495        if (NS_SUCCEEDED(rv)) 
00496        {        
00497               observerService->AddObserver(this, "profile-approve-change", PR_TRUE);
00498               observerService->AddObserver(this, "profile-change-teardown", PR_TRUE);
00499               observerService->AddObserver(this, "profile-after-change", PR_TRUE);
00500        }
00501 
00502     m_ProfileMgr->StartUp();
00503 
00504        return TRUE;
00505 }
00506 
00507 // When the profile switch happens, all open browser windows need to be 
00508 // closed. 
00509 // In order for that not to kill off the app, we just make the MFC app's 
00510 // mainframe be an invisible window which doesn't get closed on profile 
00511 // switches
00512 BOOL CTestEmbedApp::CreateHiddenWindow()
00513 {
00514        CFrameWnd *hiddenWnd = new CFrameWnd;
00515        if(!hiddenWnd)
00516               return FALSE;
00517 
00518     RECT bounds = { -10010, -10010, -10000, -10000 };
00519     hiddenWnd->Create(NULL, "main", WS_DISABLED, bounds, NULL, NULL, 0, NULL);
00520     m_pMainWnd = hiddenWnd;
00521 
00522        return TRUE;
00523 }
00524 
00525 nsresult CTestEmbedApp::InitializePrefs()
00526 {
00527    nsresult rv;
00528 
00529    nsCOMPtr<nsIPref> prefs(do_GetService(NS_PREF_CONTRACTID,&rv));
00530 
00531    if (NS_SUCCEEDED(rv)) {    
00532 
00533               // We are using the default prefs from mozilla. If you were
00534               // disributing your own, this would be done simply by editing
00535               // the default pref files.
00536               PRBool inited;
00537               rv = prefs->GetBoolPref("mfcbrowser.prefs_inited", &inited);
00538               if (NS_FAILED(rv) || !inited)
00539               {
00540             m_iStartupPage = 1;
00541             m_strHomePage = "http://www.mozilla.org/projects/embedding";
00542 
00543             prefs->SetIntPref("browser.startup.page", m_iStartupPage);
00544             prefs->SetCharPref("browser.startup.homepage", m_strHomePage);
00545             prefs->SetIntPref("font.size.variable.x-western", 16);
00546             prefs->SetIntPref("font.size.fixed.x-western", 13);
00547             rv = prefs->SetBoolPref("mfcbrowser.prefs_inited", PR_TRUE);
00548             if (NS_SUCCEEDED(rv))
00549                 rv = prefs->SavePrefFile(nsnull);
00550         }
00551         else
00552         {
00553             // The prefs are present, read them in
00554             prefs->GetIntPref("browser.startup.page", &m_iStartupPage);
00555 
00556             CString strBuf;
00557             char *pBuf = strBuf.GetBuffer(_MAX_PATH);
00558             prefs->CopyCharPref("browser.startup.homepage", &pBuf);
00559             strBuf.ReleaseBuffer(-1);
00560             if(pBuf)
00561                 m_strHomePage = pBuf;
00562         }       
00563        }
00564        else
00565               NS_ASSERTION(PR_FALSE, "Could not get preferences service");
00566               
00567     return rv;
00568 }
00569 
00570 
00571 /* InitializeWindowCreator creates and hands off an object with a callback
00572    to a window creation function. This will be used by Gecko C++ code
00573    (never JS) to create new windows when no previous window is handy
00574    to begin with. This is done in a few exceptional cases, like PSM code.
00575    Failure to set this callback will only disable the ability to create
00576    new windows under these circumstances. */
00577 nsresult CTestEmbedApp::InitializeWindowCreator()
00578 {
00579   // give an nsIWindowCreator to the WindowWatcher service
00580   nsCOMPtr<nsIWindowCreator> windowCreator(NS_STATIC_CAST(nsIWindowCreator *, this));
00581   if (windowCreator) {
00582     nsCOMPtr<nsIWindowWatcher> wwatch(do_GetService(NS_WINDOWWATCHER_CONTRACTID));
00583     if (wwatch) {
00584       wwatch->SetWindowCreator(windowCreator);
00585       return NS_OK;
00586     }
00587   }
00588   return NS_ERROR_FAILURE;
00589 }
00590 
00591 // ---------------------------------------------------------------------------
00592 //  CTestEmbedApp : nsISupports
00593 // ---------------------------------------------------------------------------
00594 
00595 NS_IMPL_THREADSAFE_ISUPPORTS3(CTestEmbedApp, nsIObserver, nsIWindowCreator, nsISupportsWeakReference)
00596 
00597 // ---------------------------------------------------------------------------
00598 //  CTestEmbedApp : nsIObserver
00599 // ---------------------------------------------------------------------------
00600 
00601 // Mainly needed to support "on the fly" profile switching
00602 
00603 NS_IMETHODIMP CTestEmbedApp::Observe(nsISupports *aSubject, const char *aTopic, const PRUnichar *someData)
00604 {
00605     nsresult rv = NS_OK;
00606     
00607     if (nsCRT::strcmp(aTopic, "profile-approve-change") == 0)
00608     {
00609         // Ask the user if they want to
00610         int result = MessageBox(NULL, "Do you want to close all windows in order to switch the profile?", "Confirm", MB_YESNO | MB_ICONQUESTION);
00611         if (result != IDYES)
00612         {
00613             nsCOMPtr<nsIProfileChangeStatus> status = do_QueryInterface(aSubject);
00614             NS_ENSURE_TRUE(status, NS_ERROR_FAILURE);
00615             status->VetoChange();
00616         }
00617     }
00618     else if (nsCRT::strcmp(aTopic, "profile-change-teardown") == 0)
00619     {
00620         // Close all open windows. Alternatively, we could just call CBrowserWindow::Stop()
00621         // on each. Either way, we have to stop all network activity on this phase.
00622         
00623            POSITION pos = m_FrameWndLst.GetHeadPosition();
00624            while( pos != NULL )
00625            {
00626                   CBrowserFrame *pBrowserFrame = (CBrowserFrame *) m_FrameWndLst.GetNext(pos);
00627                   if(pBrowserFrame)
00628                   {
00629                          pBrowserFrame->ShowWindow(false);
00630 
00631                             // Passing in FALSE below so that we do not
00632                             // kill the main app during a profile switch
00633                             RemoveFrameFromList(pBrowserFrame, FALSE);
00634 
00635                             pBrowserFrame->DestroyWindow();
00636                   }
00637            }
00638     }
00639     else if (nsCRT::strcmp(aTopic, "profile-after-change") == 0)
00640     {
00641         InitializePrefs(); // In case we have just switched to a newly created profile.
00642         
00643         // Only make a new browser window on a switch. This also gets
00644         // called at start up and we already make a window then.
00645         if (!nsCRT::strcmp(someData, NS_LITERAL_STRING("switch").get()))      
00646             OnNewBrowser();
00647     }
00648     return rv;
00649 }
00650 
00651 // ---------------------------------------------------------------------------
00652 //  CTestEmbedApp : nsIWindowCreator
00653 // ---------------------------------------------------------------------------
00654 NS_IMETHODIMP CTestEmbedApp::CreateChromeWindow(nsIWebBrowserChrome *parent,
00655                                                PRUint32 chromeFlags,
00656                                                nsIWebBrowserChrome **_retval)
00657 {
00658   // XXX we're ignoring the "parent" parameter
00659   NS_ENSURE_ARG_POINTER(_retval);
00660   *_retval = 0;
00661 
00662   CBrowserFrame *pBrowserFrame = CreateNewBrowserFrame(chromeFlags);
00663   if(pBrowserFrame) {
00664     *_retval = NS_STATIC_CAST(nsIWebBrowserChrome *, pBrowserFrame->GetBrowserImpl());
00665     NS_ADDREF(*_retval);
00666   }
00667   return NS_OK;
00668 }
00669 
00670 // AboutDlg Stuff
00671 
00672 class CAboutDlg : public CDialog
00673 {
00674 public:
00675        CAboutDlg();
00676 
00677        enum { IDD = IDD_ABOUTBOX };
00678 
00679 protected:
00680        virtual void DoDataExchange(CDataExchange* pDX);    // DDX/DDV support
00681 
00682 protected:
00683        DECLARE_MESSAGE_MAP()
00684 };
00685 
00686 CAboutDlg::CAboutDlg() : CDialog(CAboutDlg::IDD)
00687 {
00688 }
00689 
00690 void CAboutDlg::DoDataExchange(CDataExchange* pDX)
00691 {
00692        CDialog::DoDataExchange(pDX);
00693 }
00694 
00695 BEGIN_MESSAGE_MAP(CAboutDlg, CDialog)
00696 END_MESSAGE_MAP()
00697 
00698 // Show the AboutDlg
00699 void CTestEmbedApp::OnAppAbout()
00700 {
00701        CAboutDlg aboutDlg;
00702        aboutDlg.DoModal();
00703 }