Back to index

lightning-sunbird  0.9+nobinonly
BrowserView.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: Mozilla-sample-code 1.0
00004  *
00005  * Copyright (c) 2002 Netscape Communications Corporation and
00006  * other contributors
00007  *
00008  * Permission is hereby granted, free of charge, to any person obtaining a
00009  * copy of this Mozilla sample software and associated documentation files
00010  * (the "Software"), to deal in the Software without restriction, including
00011  * without limitation the rights to use, copy, modify, merge, publish,
00012  * distribute, sublicense, and/or sell copies of the Software, and to permit
00013  * persons to whom the Software is furnished to do so, subject to the
00014  * following conditions:
00015  *
00016  * The above copyright notice and this permission notice shall be included
00017  * in all copies or substantial portions of the Software.
00018  *
00019  * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
00020  * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
00021  * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
00022  * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
00023  * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
00024  * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
00025  * DEALINGS IN THE SOFTWARE.
00026  *
00027  * Contributor(s):
00028  *   Chak Nanga <chak@netscape.com>
00029  *   Rod Spears <rods@netscape.com>
00030  *
00031  * ***** END LICENSE BLOCK ***** */
00032 
00033 // File Overview....
00034 //
00035 // When the CBrowserFrm creates this View:
00036 //   - CreateBrowser() is called in OnCreate() to create the
00037 //       mozilla embeddable browser
00038 //
00039 // OnSize() method handles the window resizes and calls the approriate
00040 // interface method to resize the embedded browser properly
00041 //
00042 // Command handlers to handle browser navigation - OnNavBack(), 
00043 // OnNavForward() etc
00044 //
00045 // DestroyBrowser() called for cleaning up during object destruction
00046 //
00047 // Some important coding notes....
00048 //
00049 // 1. Make sure we do not have the CS_HREDRAW|CS_VREDRAW in the call
00050 //      to AfxRegisterWndClass() inside of PreCreateWindow() below
00051 //      If these flags are present then you'll see screen flicker when 
00052 //      you resize the frame window
00053 //
00054 // Next suggested file to look at : BrowserImpl.cpp
00055 //
00056 
00057 #include "stdafx.h"
00058 #include "MfcEmbed.h"
00059 #include "BrowserView.h"
00060 #include "BrowserImpl.h"
00061 #include "BrowserFrm.h"
00062 #include "Dialogs.h"
00063 #include "CPageSetupPropSheet.h"
00064 
00065 // Mozilla Includes
00066 #include "nsIIOService.h"
00067 #include "nsIWidget.h"
00068 #include "nsServiceManagerUtils.h"
00069 #include "nsComponentManagerUtils.h"
00070 #include "nsMemory.h"
00071 #include "nsXPCOM.h"
00072 
00073 static nsresult
00074 NewURI(nsIURI **result, const nsAString &spec)
00075 {
00076   nsEmbedCString specUtf8;
00077   NS_UTF16ToCString(spec, NS_CSTRING_ENCODING_UTF8, specUtf8);
00078 
00079   nsCOMPtr<nsIIOService> ios = do_GetService("@mozilla.org/network/io-service;1");
00080   NS_ENSURE_TRUE(ios, NS_ERROR_UNEXPECTED);
00081 
00082   return ios->NewURI(specUtf8, nsnull, nsnull, result);
00083 }
00084 
00085 static void
00086 ReplaceChar(nsAString &str, char oldChar, char newChar)
00087 {
00088   // XXX this could be much more efficient
00089 
00090   PRUnichar *data = NS_StringCloneData(str);
00091   PRUnichar *datastring = data;
00092   for (; *data; ++data)
00093   {
00094     if ((char ) *data == oldChar)
00095       *data = (PRUnichar) newChar;
00096   }
00097   NS_StringSetData(str, datastring);
00098   nsMemory::Free(datastring);
00099 }
00100 
00101 static void
00102 StripChars(nsAString &str, const char *chars)
00103 {
00104   // XXX this could be much more efficient
00105 
00106   PRUint32 len = str.Length();
00107 
00108   PRUnichar *data = NS_StringCloneData(str);
00109   PRUnichar *datastring = data;
00110   PRUnichar *dataEnd = data + len;
00111   for (; *data; ++data)
00112   {
00113     if (strchr(chars, (char ) *data))
00114     {
00115       // include trailing null terminator in the memmove
00116       memmove(data, data + 1, (dataEnd - data) * sizeof(PRUnichar));
00117       --dataEnd;
00118     }
00119   }
00120   NS_StringSetData(str, datastring);
00121   nsMemory::Free(datastring);
00122 }
00123 
00124 static void
00125 StripChars(nsACString &str, const char *chars)
00126 {
00127   // XXX this could be much more efficient
00128 
00129   PRUint32 len = str.Length();
00130 
00131   char *data = NS_CStringCloneData(str);
00132   char *datastring = data;
00133   char *dataEnd = data + len;
00134   for (; *data; ++data)
00135   {
00136     if (strchr(chars, *data))
00137     {
00138       // include trailing null terminator in the memmove
00139       memmove(data, data + 1, dataEnd - data);
00140       --dataEnd;
00141     }
00142   }
00143   NS_CStringSetData(str, datastring);
00144   nsMemory::Free(datastring);
00145 }
00146 
00147 static const char* kWhitespace="\b\t\r\n ";
00148 
00149 static void
00150 CompressWhitespace(nsAString &str)
00151 {
00152   const PRUnichar *p;
00153   PRInt32 i, len = (PRInt32) NS_StringGetData(str, &p);
00154 
00155   // trim leading whitespace
00156 
00157   for (i=0; i<len; ++i)
00158   {
00159     if (!strchr(kWhitespace, (char) p[i]))
00160       break;
00161   }
00162 
00163   if (i>0)
00164   {
00165     NS_StringCutData(str, 0, i);
00166     len = (PRInt32) NS_StringGetData(str, &p);
00167   }
00168 
00169   // trim trailing whitespace
00170 
00171   for (i=len-1; i>=0; --i)
00172   {
00173     if (!strchr(kWhitespace, (char) p[i]))
00174       break;
00175   }
00176 
00177   if (++i < len)
00178     NS_StringCutData(str, i, len - i);
00179 }
00180 
00181 #ifdef _DEBUG
00182 #define new DEBUG_NEW
00183 #undef THIS_FILE
00184 static char THIS_FILE[] = __FILE__;
00185 #endif
00186 
00187 // Register message for FindDialog communication
00188 static UINT WM_FINDMSG = ::RegisterWindowMessage(FINDMSGSTRING);
00189 
00190 BEGIN_MESSAGE_MAP(CBrowserView, CWnd)
00191     //{{AFX_MSG_MAP(CBrowserView)
00192     ON_WM_CREATE()
00193     ON_WM_DESTROY()
00194     ON_WM_SIZE()
00195 
00196     // UrlBar command handlers
00197     ON_COMMAND(IDOK, OnNewUrlEnteredInUrlBar)
00198     ON_CBN_SELENDOK(ID_URL_BAR, OnUrlSelectedInUrlBar)
00199 
00200     // Menu/Toolbar command handlers
00201     ON_COMMAND(ID_FILE_OPEN, OnFileOpen)
00202     ON_COMMAND(ID_FILE_SAVE_AS, OnFileSaveAs)
00203     ON_COMMAND(ID_VIEW_SOURCE, OnViewSource)
00204     ON_COMMAND(ID_VIEW_INFO, OnViewInfo)
00205     ON_COMMAND(ID_NAV_BACK, OnNavBack)
00206     ON_COMMAND(ID_NAV_FORWARD, OnNavForward)
00207     ON_COMMAND(ID_NAV_HOME, OnNavHome)
00208     ON_COMMAND(ID_NAV_RELOAD, OnNavReload)
00209     ON_COMMAND(ID_NAV_STOP, OnNavStop)
00210     ON_COMMAND(ID_EDIT_CUT, OnCut)
00211     ON_COMMAND(ID_EDIT_COPY, OnCopy)
00212     ON_COMMAND(ID_EDIT_PASTE, OnPaste)
00213     ON_COMMAND(ID_EDIT_UNDO, OnUndoUrlBarEditOp)
00214     ON_COMMAND(ID_EDIT_SELECT_ALL, OnSelectAll)
00215     ON_COMMAND(ID_EDIT_SELECT_NONE, OnSelectNone)
00216     ON_COMMAND(ID_OPEN_LINK_IN_NEW_WINDOW, OnOpenLinkInNewWindow)
00217     ON_COMMAND(ID_VIEW_IMAGE, OnViewImageInNewWindow)
00218     ON_COMMAND(ID_COPY_LINK_LOCATION, OnCopyLinkLocation)
00219     ON_COMMAND(ID_SAVE_LINK_AS, OnSaveLinkAs)
00220     ON_COMMAND(ID_SAVE_IMAGE_AS, OnSaveImageAs)
00221     ON_COMMAND(ID_EDIT_FIND, OnShowFindDlg)
00222     ON_COMMAND(ID_FILE_PRINT, OnFilePrint)
00223     ON_COMMAND(ID_FILE_PRINTPREVIEW, OnFilePrintPreview)
00224     ON_COMMAND(ID_FILE_PRINTSETUP, OnFilePrintSetup)
00225     ON_REGISTERED_MESSAGE(WM_FINDMSG, OnFindMsg)
00226     ON_COMMAND(ID_VIEW_FRAME_SOURCE, OnViewFrameSource)
00227     ON_COMMAND(ID_OPEN_FRAME_IN_NEW_WINDOW, OnOpenFrameInNewWindow)
00228 
00229     // Menu/Toolbar UI update handlers
00230     ON_UPDATE_COMMAND_UI(ID_NAV_BACK, OnUpdateNavBack)
00231     ON_UPDATE_COMMAND_UI(ID_NAV_FORWARD, OnUpdateNavForward)
00232     ON_UPDATE_COMMAND_UI(ID_NAV_STOP, OnUpdateNavStop)
00233     ON_UPDATE_COMMAND_UI(ID_EDIT_CUT, OnUpdateCut)
00234     ON_UPDATE_COMMAND_UI(ID_EDIT_COPY, OnUpdateCopy)
00235     ON_UPDATE_COMMAND_UI(ID_EDIT_PASTE, OnUpdatePaste)
00236     ON_UPDATE_COMMAND_UI(ID_FILE_PRINT, OnUpdateFilePrint)
00237     ON_UPDATE_COMMAND_UI(ID_FILE_PRINTSETUP, OnUpdatePrintSetup)
00238     ON_UPDATE_COMMAND_UI(ID_VIEW_IMAGE, OnUpdateViewImage)
00239     //}}AFX_MSG_MAP
00240 END_MESSAGE_MAP()
00241 
00242 
00243 CBrowserView::CBrowserView()
00244 {
00245     mWebBrowser = nsnull;
00246     mBaseWindow = nsnull;
00247     mWebNav = nsnull;
00248 
00249     mpBrowserImpl = nsnull;
00250     mpBrowserFrame = nsnull;
00251     mpBrowserFrameGlue = nsnull;
00252 
00253     mbDocumentLoading = PR_FALSE;
00254 
00255     m_pFindDlg = NULL;
00256     m_bUrlBarClipOp = FALSE;
00257     m_bCurrentlyPrinting = FALSE;
00258 
00259     m_SecurityState = SECURITY_STATE_INSECURE;
00260 
00261   m_InPrintPreview = FALSE;
00262 }
00263 
00264 CBrowserView::~CBrowserView()
00265 {
00266 }
00267 
00268 // This is a good place to create the embeddable browser
00269 // instance
00270 //
00271 int CBrowserView::OnCreate(LPCREATESTRUCT lpCreateStruct)
00272 {
00273     CreateBrowser();
00274 
00275     return 0;
00276 }
00277 
00278 void CBrowserView::OnDestroy()
00279 {
00280     DestroyBrowser();
00281 }
00282 
00283 // Create an instance of the Mozilla embeddable browser
00284 //
00285 HRESULT CBrowserView::CreateBrowser() 
00286 {       
00287     // Create web shell
00288     nsresult rv;
00289     mWebBrowser = do_CreateInstance(NS_WEBBROWSER_CONTRACTID, &rv);
00290     if(NS_FAILED(rv))
00291         return rv;
00292 
00293     // Save off the nsIWebNavigation interface pointer 
00294     // in the mWebNav member variable which we'll use 
00295     // later for web page navigation
00296     //
00297     rv = NS_OK;
00298     mWebNav = do_QueryInterface(mWebBrowser, &rv);
00299     if(NS_FAILED(rv))
00300         return rv;
00301 
00302     // Create the CBrowserImpl object - this is the object
00303     // which implements the interfaces which are required
00304     // by an app embedding mozilla i.e. these are the interfaces
00305     // thru' which the *embedded* browser communicates with the
00306     // *embedding* app
00307     //
00308     // The CBrowserImpl object will be passed in to the 
00309     // SetContainerWindow() call below
00310     //
00311     // Also note that we're passing the BrowserFrameGlue pointer 
00312     // and also the mWebBrowser interface pointer via CBrowserImpl::Init()
00313     // of CBrowserImpl object. 
00314     // These pointers will be saved by the CBrowserImpl object.
00315     // The CBrowserImpl object uses the BrowserFrameGlue pointer to 
00316     // call the methods on that interface to update the status/progress bars
00317     // etc.
00318     mpBrowserImpl = new CBrowserImpl();
00319     if(mpBrowserImpl == nsnull)
00320         return NS_ERROR_OUT_OF_MEMORY;
00321 
00322     // Pass along the mpBrowserFrameGlue pointer to the BrowserImpl object
00323     // This is the interface thru' which the XP BrowserImpl code communicates
00324     // with the platform specific code to update status bars etc.
00325     mpBrowserImpl->Init(mpBrowserFrameGlue, mWebBrowser);
00326     mpBrowserImpl->AddRef();
00327 
00328     mWebBrowser->SetContainerWindow(NS_STATIC_CAST(nsIWebBrowserChrome*, mpBrowserImpl));
00329 
00330     rv = NS_OK;
00331     nsCOMPtr<nsIDocShellTreeItem> dsti = do_QueryInterface(mWebBrowser, &rv);
00332     if(NS_FAILED(rv))
00333         return rv;
00334 
00335     // If the browser window hosting chrome or content?
00336     dsti->SetItemType(((CMfcEmbedApp *)AfxGetApp())->m_bChrome ?
00337         nsIDocShellTreeItem::typeChromeWrapper :
00338         nsIDocShellTreeItem::typeContentWrapper);
00339 
00340     // Create the real webbrowser window
00341   
00342     // Note that we're passing the m_hWnd in the call below to InitWindow()
00343     // (CBrowserView inherits the m_hWnd from CWnd)
00344     // This m_hWnd will be used as the parent window by the embeddable browser
00345     //
00346     rv = NS_OK;
00347     mBaseWindow = do_QueryInterface(mWebBrowser, &rv);
00348     if(NS_FAILED(rv))
00349         return rv;
00350 
00351     // Get the view's ClientRect which to be passed in to the InitWindow()
00352     // call below
00353     RECT rcLocation;
00354     GetClientRect(&rcLocation);
00355     if(IsRectEmpty(&rcLocation))
00356     {
00357         rcLocation.bottom++;
00358         rcLocation.top++;
00359     }
00360 
00361     rv = mBaseWindow->InitWindow(nsNativeWidget(m_hWnd), nsnull,
00362         0, 0, rcLocation.right - rcLocation.left, rcLocation.bottom - rcLocation.top);
00363     rv = mBaseWindow->Create();
00364 
00365     // Register the BrowserImpl object to receive progress messages
00366     // These callbacks will be used to update the status/progress bars
00367     nsWeakPtr weakling(
00368         do_GetWeakReference(NS_STATIC_CAST(nsIWebProgressListener*, mpBrowserImpl)));
00369     (void)mWebBrowser->AddWebBrowserListener(weakling, 
00370                                 NS_GET_IID(nsIWebProgressListener));
00371 
00372     // Finally, show the web browser window
00373     mBaseWindow->SetVisibility(PR_TRUE);
00374 
00375     return S_OK;
00376 }
00377 
00378 HRESULT CBrowserView::DestroyBrowser() 
00379 {       
00380     if(mBaseWindow)
00381     {
00382         mBaseWindow->Destroy();
00383         mBaseWindow = nsnull;
00384     }
00385 
00386     if(mpBrowserImpl)
00387     {
00388         mpBrowserImpl->Release();
00389         mpBrowserImpl = nsnull;
00390     }
00391 
00392     return NS_OK;
00393 }
00394 
00395 BOOL CBrowserView::PreCreateWindow(CREATESTRUCT& cs) 
00396 {
00397     if (!CWnd::PreCreateWindow(cs))
00398         return FALSE;
00399 
00400     cs.dwExStyle |= WS_EX_CLIENTEDGE;
00401     cs.style &= ~WS_BORDER;
00402     cs.style |= WS_CLIPCHILDREN;
00403     cs.lpszClass = AfxRegisterWndClass(CS_DBLCLKS, 
00404         ::LoadCursor(NULL, IDC_ARROW), HBRUSH(COLOR_WINDOW+1), NULL);
00405 
00406     return TRUE;
00407 }
00408 
00409 // Adjust the size of the embedded browser
00410 // in response to any container size changes
00411 //
00412 void CBrowserView::OnSize( UINT nType, int cx, int cy)
00413 {
00414     mBaseWindow->SetPositionAndSize(0, 0, cx, cy, PR_TRUE);    
00415 }
00416 
00417 // Called by this object's creator i.e. the CBrowserFrame object
00418 // to pass it's pointer to us
00419 //
00420 void CBrowserView::SetBrowserFrame(CBrowserFrame* pBrowserFrame)
00421 {
00422     mpBrowserFrame = pBrowserFrame;
00423 }
00424 
00425 void CBrowserView::SetBrowserFrameGlue(PBROWSERFRAMEGLUE pBrowserFrameGlue)
00426 {
00427     mpBrowserFrameGlue = pBrowserFrameGlue;
00428 }
00429 
00430 // A new URL was entered in the URL bar
00431 // Get the URL's text from the Urlbar's (ComboBox's) EditControl 
00432 // and navigate to that URL
00433 //
00434 void CBrowserView::OnNewUrlEnteredInUrlBar()
00435 {
00436     // Get the currently entered URL
00437     CString strUrl;
00438     mpBrowserFrame->m_wndUrlBar.GetEnteredURL(strUrl);
00439 
00440     if(IsViewSourceUrl(strUrl))
00441         OpenViewSourceWindow(strUrl.GetBuffer(0));
00442     else
00443         // Navigate to that URL
00444         OpenURL(strUrl.GetBuffer(0));
00445 
00446     // Add what was just entered into the UrlBar
00447     mpBrowserFrame->m_wndUrlBar.AddURLToList(strUrl);
00448 }
00449 
00450 // A URL has  been selected from the UrlBar's dropdown list
00451 //
00452 void CBrowserView::OnUrlSelectedInUrlBar()
00453 {
00454     CString strUrl;
00455     
00456     mpBrowserFrame->m_wndUrlBar.GetSelectedURL(strUrl);
00457 
00458     if(IsViewSourceUrl(strUrl))
00459         OpenViewSourceWindow(strUrl.GetBuffer(0));
00460     else
00461         OpenURL(strUrl.GetBuffer(0));
00462 }
00463 
00464 BOOL CBrowserView::IsViewSourceUrl(CString& strUrl)
00465 {
00466     return (strUrl.Find(_T("view-source:"), 0) != -1) ? TRUE : FALSE;
00467 }
00468 
00469 BOOL CBrowserView::OpenViewSourceWindow(const char* pUrl)
00470 {
00471     nsEmbedString str;
00472     NS_CStringToUTF16(nsEmbedCString(pUrl), NS_CSTRING_ENCODING_ASCII, str);
00473     return OpenViewSourceWindow(str.get());
00474 }
00475 
00476 BOOL CBrowserView::OpenViewSourceWindow(const PRUnichar* pUrl)
00477 {
00478     // Create a new browser frame in which we'll show the document source
00479     // Note that we're getting rid of the toolbars etc. by specifying
00480     // the appropriate chromeFlags
00481     PRUint32 chromeFlags =  nsIWebBrowserChrome::CHROME_WINDOW_BORDERS |
00482                             nsIWebBrowserChrome::CHROME_TITLEBAR |
00483                             nsIWebBrowserChrome::CHROME_WINDOW_RESIZE;
00484     CBrowserFrame* pFrm = CreateNewBrowserFrame(chromeFlags);
00485     if(!pFrm)
00486         return FALSE;
00487 
00488     // Finally, load this URI into the newly created frame
00489     pFrm->m_wndBrowserView.OpenURL(pUrl);
00490 
00491     pFrm->BringWindowToTop();
00492 
00493     return TRUE;
00494 }
00495 
00496 void CBrowserView::OnViewSource() 
00497 {
00498     if(! mWebNav)
00499         return;
00500 
00501     // Get the URI object whose source we want to view.
00502     nsresult rv = NS_OK;
00503     nsCOMPtr<nsIURI> currentURI;
00504     rv = mWebNav->GetCurrentURI(getter_AddRefs(currentURI));
00505     if(NS_FAILED(rv) || !currentURI)
00506         return;
00507 
00508     // Get the uri string associated with the nsIURI object
00509     nsEmbedCString uriString;
00510     rv = currentURI->GetSpec(uriString);
00511     if(NS_FAILED(rv))
00512         return;
00513 
00514     // Build the view-source: url
00515     nsEmbedCString viewSrcUrl("view-source:");
00516     viewSrcUrl.Append(uriString);
00517 
00518     OpenViewSourceWindow(viewSrcUrl.get());
00519 }
00520 
00521 void CBrowserView::OnViewInfo() 
00522 {
00523     AfxMessageBox(_T("To Be Done..."));
00524 }
00525 
00526 void CBrowserView::OnNavBack() 
00527 {
00528     if(mWebNav)
00529         mWebNav->GoBack();
00530 }
00531 
00532 void CBrowserView::OnUpdateNavBack(CCmdUI* pCmdUI)
00533 {
00534     PRBool canGoBack = PR_FALSE;
00535 
00536     if (mWebNav)
00537         mWebNav->GetCanGoBack(&canGoBack);
00538 
00539     pCmdUI->Enable(canGoBack);
00540 }
00541 
00542 void CBrowserView::OnNavForward() 
00543 {
00544     if(mWebNav)
00545         mWebNav->GoForward();
00546 }
00547 
00548 void CBrowserView::OnUpdateNavForward(CCmdUI* pCmdUI)
00549 {
00550     PRBool canGoFwd = PR_FALSE;
00551 
00552     if (mWebNav)
00553         mWebNav->GetCanGoForward(&canGoFwd);
00554 
00555     pCmdUI->Enable(canGoFwd);
00556 }
00557 
00558 void CBrowserView::OnNavHome() 
00559 {
00560     // Get the currently configured HomePage URL
00561     CString strHomeURL;
00562     CMfcEmbedApp *pApp = (CMfcEmbedApp *)AfxGetApp();
00563     if(pApp)
00564         pApp->GetHomePage(strHomeURL);
00565 
00566     if(strHomeURL.GetLength() > 0)
00567         OpenURL(strHomeURL);    
00568 }
00569 
00570 void CBrowserView::OnNavReload() 
00571 {
00572     PRUint32 loadFlags = nsIWebNavigation::LOAD_FLAGS_NONE;
00573     if (GetKeyState(VK_SHIFT))
00574         loadFlags = nsIWebNavigation::LOAD_FLAGS_BYPASS_CACHE;
00575     if (mWebNav)
00576         mWebNav->Reload(loadFlags);
00577 }
00578 
00579 void CBrowserView::OnNavStop() 
00580 {
00581     if(mWebNav)
00582         mWebNav->Stop(nsIWebNavigation::STOP_ALL);
00583 }
00584 
00585 void CBrowserView::OnUpdateNavStop(CCmdUI* pCmdUI)
00586 {
00587     pCmdUI->Enable(mbDocumentLoading);
00588 }
00589 
00590 void CBrowserView::OnCut()
00591 {
00592     if(m_bUrlBarClipOp)
00593     {
00594         // We need to operate on the URLBar selection
00595         mpBrowserFrame->CutUrlBarSelToClipboard();
00596         m_bUrlBarClipOp = FALSE;
00597     }
00598     else
00599     {
00600         nsCOMPtr<nsIClipboardCommands> clipCmds = do_GetInterface(mWebBrowser);
00601 
00602         if(clipCmds)
00603             clipCmds->CutSelection();
00604     }
00605 }
00606 
00607 void CBrowserView::OnUpdateCut(CCmdUI* pCmdUI)
00608 {
00609     PRBool canCutSelection = PR_FALSE;
00610 
00611     nsCOMPtr<nsIClipboardCommands> clipCmds = do_GetInterface(mWebBrowser);
00612     if (clipCmds)
00613         clipCmds->CanCutSelection(&canCutSelection);
00614 
00615     if(!canCutSelection)
00616     {
00617         // Check to see if the Cut cmd is to cut the URL 
00618         // selection in the UrlBar
00619         if(mpBrowserFrame->CanCutUrlBarSelection())
00620         {
00621             canCutSelection = TRUE;
00622             m_bUrlBarClipOp = TRUE;
00623         }
00624     }
00625 
00626     pCmdUI->Enable(canCutSelection);
00627 }
00628 
00629 void CBrowserView::OnCopy()
00630 {
00631     if(m_bUrlBarClipOp)
00632     {
00633         // We need to operate on the URLBar selection
00634         mpBrowserFrame->CopyUrlBarSelToClipboard();
00635         m_bUrlBarClipOp = FALSE;
00636     }
00637     else
00638     {
00639         // We need to operate on the web page content
00640         nsCOMPtr<nsIClipboardCommands> clipCmds = do_GetInterface(mWebBrowser);
00641 
00642         if(clipCmds)
00643             clipCmds->CopySelection();
00644     }
00645 }
00646 
00647 void CBrowserView::OnUpdateCopy(CCmdUI* pCmdUI)
00648 {
00649     PRBool canCopySelection = PR_FALSE;
00650 
00651     nsCOMPtr<nsIClipboardCommands> clipCmds = do_GetInterface(mWebBrowser);
00652     if (clipCmds)
00653         clipCmds->CanCopySelection(&canCopySelection);
00654 
00655     if(!canCopySelection)
00656     {
00657         // Check to see if the Copy cmd is to copy the URL 
00658         // selection in the UrlBar
00659         if(mpBrowserFrame->CanCopyUrlBarSelection())
00660         {
00661             canCopySelection = TRUE;
00662             m_bUrlBarClipOp = TRUE;
00663         }
00664     }
00665 
00666     pCmdUI->Enable(canCopySelection);
00667 }
00668 
00669 void CBrowserView::OnPaste()
00670 {
00671     if(m_bUrlBarClipOp)
00672     {
00673         mpBrowserFrame->PasteFromClipboardToUrlBar();
00674         m_bUrlBarClipOp = FALSE;
00675     }
00676     else
00677     {
00678         nsCOMPtr<nsIClipboardCommands> clipCmds = do_GetInterface(mWebBrowser);
00679 
00680         if(clipCmds)
00681             clipCmds->Paste();
00682     }    
00683 }
00684 
00685 void CBrowserView::OnUndoUrlBarEditOp()
00686 {
00687     if(mpBrowserFrame->CanUndoUrlBarEditOp())
00688         mpBrowserFrame->UndoUrlBarEditOp();
00689 }
00690 
00691 void CBrowserView::OnUpdatePaste(CCmdUI* pCmdUI)
00692 {
00693     PRBool canPaste = PR_FALSE;
00694 
00695     nsCOMPtr<nsIClipboardCommands> clipCmds = do_GetInterface(mWebBrowser);
00696     if (clipCmds)
00697         clipCmds->CanPaste(&canPaste);
00698 
00699     if(!canPaste)
00700     {
00701         if(mpBrowserFrame->CanPasteToUrlBar())
00702         {
00703             canPaste = TRUE;
00704             m_bUrlBarClipOp = TRUE;
00705         }
00706     }
00707 
00708     pCmdUI->Enable(canPaste);
00709 }
00710 
00711 void CBrowserView::OnSelectAll()
00712 {
00713     nsCOMPtr<nsIClipboardCommands> clipCmds = do_GetInterface(mWebBrowser);
00714 
00715     if(clipCmds)
00716         clipCmds->SelectAll();
00717 }
00718 
00719 void CBrowserView::OnSelectNone()
00720 {
00721     nsCOMPtr<nsIClipboardCommands> clipCmds = do_GetInterface(mWebBrowser);
00722 
00723     if(clipCmds)
00724         clipCmds->SelectNone();
00725 }
00726 
00727 void CBrowserView::OnFileOpen()
00728 {
00729     TCHAR *lpszFilter =
00730         _T("HTML Files Only (*.htm;*.html)|*.htm;*.html|")
00731         _T("All Files (*.*)|*.*||");
00732 
00733     CFileDialog cf(TRUE, NULL, NULL, OFN_HIDEREADONLY | OFN_OVERWRITEPROMPT,
00734                     lpszFilter, this);
00735     if(cf.DoModal() == IDOK)
00736     {
00737         CString strFullPath = cf.GetPathName(); // Will be like: c:\tmp\junk.htm
00738         OpenURL(strFullPath);
00739     }
00740 }
00741 
00742 void CBrowserView::GetBrowserWindowTitle(nsAString& title)
00743 {
00744     PRUnichar *idlStrTitle = nsnull;
00745     if(mBaseWindow)
00746         mBaseWindow->GetTitle(&idlStrTitle);
00747 
00748     title = idlStrTitle;
00749     nsMemory::Free(idlStrTitle);
00750 }
00751 
00752 void CBrowserView::OnFileSaveAs()
00753 {
00754     nsEmbedString fileName;
00755 
00756     GetBrowserWindowTitle(fileName); // Suggest the window title as the filename
00757 
00758     // Sanitize the file name of all illegal characters
00759 
00760     USES_CONVERSION;
00761     CompressWhitespace(fileName);     // Remove whitespace from the ends
00762     StripChars(fileName, "\\*|:\"><?"); // Strip illegal characters
00763     ReplaceChar(fileName, '.', L'_');   // Dots become underscores
00764     ReplaceChar(fileName, '/', L'-');   // Forward slashes become hyphens
00765 
00766     TCHAR *lpszFilter =
00767         _T("Web Page, HTML Only (*.htm;*.html)|*.htm;*.html|")
00768         _T("Web Page, Complete (*.htm;*.html)|*.htm;*.html|")
00769         _T("Text File (*.txt)|*.txt||");
00770 
00771     CFileDialog cf(FALSE, _T("htm"), W2CT(fileName.get()), OFN_HIDEREADONLY | OFN_OVERWRITEPROMPT,
00772                     lpszFilter, this);
00773 
00774     if(cf.DoModal() == IDOK)
00775     {
00776         CString strFullPath = cf.GetPathName(); // Will be like: c:\tmp\junk.htm
00777         TCHAR *pStrFullPath = strFullPath.GetBuffer(0); // Get char * for later use
00778         
00779         BOOL bSaveAll = FALSE;        
00780         CString strDataPath; 
00781         TCHAR *pStrDataPath = NULL;
00782         if(cf.m_ofn.nFilterIndex == 2) 
00783         {
00784             // cf.m_ofn.nFilterIndex == 2 indicates
00785             // user want to save the complete document including
00786             // all frames, images, scripts, stylesheets etc.
00787 
00788             bSaveAll = TRUE;
00789 
00790             int idxPeriod = strFullPath.ReverseFind('.');
00791             strDataPath = strFullPath.Mid(0, idxPeriod);
00792             strDataPath += "_files";
00793 
00794             // At this stage strDataPath will be of the form
00795             // c:\tmp\junk_files - assuming we're saving to a file
00796             // named junk.htm
00797             // Any images etc in the doc will be saved to a dir
00798             // with the name c:\tmp\junk_files
00799 
00800             pStrDataPath = strDataPath.GetBuffer(0); //Get char * for later use
00801         }
00802 
00803         // Save the file
00804         nsCOMPtr<nsIWebBrowserPersist> persist(do_QueryInterface(mWebBrowser));
00805         if(persist)
00806         {
00807             nsEmbedCString fullPath(T2CA(pStrFullPath));
00808             nsCOMPtr<nsILocalFile> file;
00809             NS_NewNativeLocalFile(fullPath, TRUE, getter_AddRefs(file));
00810 
00811             nsCOMPtr<nsILocalFile> data;
00812             if (pStrDataPath)
00813             {
00814                 nsEmbedCString dataPath(T2CA(pStrDataPath));
00815                 NS_NewNativeLocalFile(dataPath, TRUE, getter_AddRefs(data));
00816             }
00817 
00818             if(bSaveAll)
00819                 persist->SaveDocument(nsnull, file, data, nsnull, 0, 0);
00820             else
00821                 persist->SaveURI(nsnull, nsnull, nsnull, nsnull, nsnull, file);
00822         }
00823     }
00824 }
00825 
00826 void CBrowserView::OpenURL(const char* pUrl)
00827 {
00828     nsEmbedString str;
00829     NS_CStringToUTF16(nsEmbedCString(pUrl), NS_CSTRING_ENCODING_ASCII, str);
00830     OpenURL(str.get());
00831 }
00832 
00833 void CBrowserView::OpenURL(const PRUnichar* pUrl)
00834 {
00835     if(mWebNav)
00836         mWebNav->LoadURI(pUrl,                              // URI string
00837                          nsIWebNavigation::LOAD_FLAGS_NONE, // Load flags
00838                          nsnull,                            // Referring URI
00839                          nsnull,                            // Post data
00840                          nsnull);                           // Extra headers
00841 }
00842 
00843 CBrowserFrame* CBrowserView::CreateNewBrowserFrame(PRUint32 chromeMask, 
00844                                     PRInt32 x, PRInt32 y, 
00845                                     PRInt32 cx, PRInt32 cy,
00846                                     PRBool bShowWindow)
00847 {
00848     CMfcEmbedApp *pApp = (CMfcEmbedApp *)AfxGetApp();
00849     if(!pApp)
00850         return NULL;
00851 
00852     return pApp->CreateNewBrowserFrame(chromeMask, x, y, cx, cy, bShowWindow);
00853 }
00854 
00855 void CBrowserView::OpenURLInNewWindow(const PRUnichar* pUrl)
00856 {
00857     if(!pUrl)
00858         return;
00859 
00860     CBrowserFrame* pFrm = CreateNewBrowserFrame();
00861     if(!pFrm)
00862         return;
00863 
00864     // Load the URL into it...
00865 
00866     // Note that OpenURL() is overloaded - one takes a "char *"
00867     // and the other a "PRUniChar *". We're using the "PRUnichar *"
00868     // version here
00869 
00870     pFrm->m_wndBrowserView.OpenURL(pUrl);
00871 }
00872 
00873 void CBrowserView::LoadHomePage()
00874 {
00875     OnNavHome();
00876 }
00877 
00878 void CBrowserView::OnCopyLinkLocation()
00879 {
00880     if(! mCtxMenuLinkUrl.Length())
00881         return;
00882 
00883     if (! OpenClipboard())
00884         return;
00885 
00886     PRUint32 size = mCtxMenuLinkUrl.Length() + 1;
00887 
00888     HGLOBAL hClipData = ::GlobalAlloc(GMEM_MOVEABLE | GMEM_DDESHARE, size);
00889     if(! hClipData)
00890         return;
00891 
00892     char *pszClipData = (char*)::GlobalLock(hClipData);
00893     if(!pszClipData)
00894         return;
00895 
00896     memcpy(pszClipData, mCtxMenuLinkUrl.get(), size);
00897 
00898     GlobalUnlock(hClipData);
00899 
00900     EmptyClipboard();
00901     SetClipboardData(CF_TEXT, hClipData);
00902     CloseClipboard();
00903 }
00904 
00905 void CBrowserView::OnOpenLinkInNewWindow()
00906 {
00907     if(mCtxMenuLinkUrl.Length())
00908         OpenURLInNewWindow(mCtxMenuLinkUrl.get());
00909 }
00910 
00911 void CBrowserView::OnViewImageInNewWindow()
00912 {
00913     if(mCtxMenuImgSrc.Length())
00914         OpenURLInNewWindow(mCtxMenuImgSrc.get());
00915 }
00916 
00917 void CBrowserView::OnUpdateViewImage(CCmdUI *pCmdUI)
00918 {
00919     pCmdUI->Enable(mCtxMenuImgSrc.Length() > 0);
00920 }
00921 
00922 void CBrowserView::OnSaveLinkAs()
00923 {
00924     if(! mCtxMenuLinkUrl.Length())
00925         return;
00926 
00927     // Try to get the file name part from the URL
00928     // To do that we first construct an obj which supports 
00929     // nsIRUI interface. Makes it easy to extract portions
00930     // of a URL like the filename, scheme etc. + We'll also
00931     // use it while saving this link to a file
00932     nsresult rv   = NS_OK;
00933     nsCOMPtr<nsIURI> linkURI;
00934     rv = NewURI(getter_AddRefs(linkURI), mCtxMenuLinkUrl);
00935     if (NS_FAILED(rv)) 
00936         return;
00937 
00938     // Get the "path" portion (see nsIURI.h for more info
00939     // on various parts of a URI)
00940     nsEmbedCString fileName;
00941     linkURI->GetPath(fileName);
00942 
00943     // The path may have the "/" char in it - strip those
00944     StripChars(fileName, "\\/");
00945 
00946     // Now, use this file name in a File Save As dlg...
00947 
00948     TCHAR *lpszFilter =
00949         _T("HTML Files (*.htm;*.html)|*.htm;*.html|")
00950         _T("Text Files (*.txt)|*.txt|")
00951         _T("All Files (*.*)|*.*||");
00952 
00953     CString strFilename = fileName.get();
00954 
00955     CFileDialog cf(FALSE, _T("htm"), strFilename, OFN_HIDEREADONLY | OFN_OVERWRITEPROMPT,
00956         lpszFilter, this);
00957     if(cf.DoModal() == IDOK)
00958     {
00959         USES_CONVERSION;
00960         nsEmbedCString fullPath; fullPath.Assign(T2CA(cf.GetPathName()));
00961         nsCOMPtr<nsIWebBrowserPersist> persist(do_QueryInterface(mWebBrowser));
00962         if(persist)
00963         {
00964             nsCOMPtr<nsILocalFile> file;
00965             NS_NewNativeLocalFile(fullPath, TRUE, getter_AddRefs(file));
00966             persist->SaveURI(linkURI, nsnull, nsnull, nsnull, nsnull, file);
00967         }
00968     }
00969 }
00970 
00971 void CBrowserView::OnSaveImageAs()
00972 {
00973     if(! mCtxMenuImgSrc.Length())
00974         return;
00975 
00976     // Try to get the file name part from the URL
00977     // To do that we first construct an obj which supports 
00978     // nsIRUI interface. Makes it easy to extract portions
00979     // of a URL like the filename, scheme etc. + We'll also
00980     // use it while saving this link to a file
00981     nsresult rv   = NS_OK;
00982     nsCOMPtr<nsIURI> linkURI;
00983     rv = NewURI(getter_AddRefs(linkURI), mCtxMenuImgSrc);
00984     if (NS_FAILED(rv)) 
00985         return;
00986 
00987     // Get the "path" portion (see nsIURI.h for more info
00988     // on various parts of a URI)
00989     nsEmbedCString path;
00990     linkURI->GetPath(path);
00991 
00992     // The path may have the "/" char in it - strip those
00993     nsEmbedCString fileName(path);
00994     StripChars(fileName, "\\/");
00995 
00996     // Now, use this file name in a File Save As dlg...
00997 
00998     TCHAR *lpszFilter = _T("All Files (*.*)|*.*||");
00999     CString strFilename = fileName.get();
01000 
01001     CFileDialog cf(FALSE, NULL, strFilename, OFN_HIDEREADONLY | OFN_OVERWRITEPROMPT,
01002         lpszFilter, this);
01003     if(cf.DoModal() == IDOK)
01004     {
01005         USES_CONVERSION;
01006         nsEmbedCString fullPath; fullPath.Assign(T2CA(cf.GetPathName()));
01007 
01008         nsCOMPtr<nsIWebBrowserPersist> persist(do_QueryInterface(mWebBrowser));
01009         if(persist)
01010         {
01011             nsCOMPtr<nsILocalFile> file;
01012             NS_NewNativeLocalFile(fullPath, TRUE, getter_AddRefs(file));
01013             persist->SaveURI(linkURI, nsnull, nsnull, nsnull, nsnull, file);
01014         }
01015     }
01016 }
01017 
01018 void CBrowserView::OnShowFindDlg() 
01019 {
01020     // When the the user chooses the Find menu item
01021     // and if a Find dlg. is already being shown
01022     // just set focus to the existing dlg instead of
01023     // creating a new one
01024     if(m_pFindDlg)
01025     {
01026         m_pFindDlg->SetFocus();
01027         return;
01028     }
01029 
01030     CString csSearchStr;
01031     PRBool bMatchCase = PR_FALSE;
01032     PRBool bMatchWholeWord = PR_FALSE;
01033     PRBool bWrapAround = PR_FALSE;
01034     PRBool bSearchBackwards = PR_FALSE;
01035 
01036     // See if we can get and initialize the dlg box with
01037     // the values/settings the user specified in the previous search
01038     nsCOMPtr<nsIWebBrowserFind> finder(do_GetInterface(mWebBrowser));
01039     if(finder)
01040     {
01041         PRUnichar *stringBuf = nsnull;
01042         finder->GetSearchString(&stringBuf);
01043         csSearchStr = stringBuf;
01044         nsMemory::Free(stringBuf);
01045 
01046         finder->GetMatchCase(&bMatchCase);
01047         finder->GetEntireWord(&bMatchWholeWord);
01048         finder->GetWrapFind(&bWrapAround);
01049         finder->GetFindBackwards(&bSearchBackwards);        
01050     }
01051 
01052     m_pFindDlg = new CFindDialog(csSearchStr, bMatchCase, bMatchWholeWord,
01053                             bWrapAround, bSearchBackwards, this);
01054     m_pFindDlg->Create(TRUE, NULL, NULL, 0, this);
01055 }
01056 
01057 // This will be called whenever the user pushes the Find
01058 // button in the Find dialog box
01059 // This method gets bound to the WM_FINDMSG windows msg via the 
01060 //
01061 //       ON_REGISTERED_MESSAGE(WM_FINDMSG, OnFindMsg) 
01062 //
01063 //    message map entry.
01064 //
01065 // WM_FINDMSG (which is registered towards the beginning of this file)
01066 // is the message via which the FindDialog communicates with this view
01067 //
01068 LRESULT CBrowserView::OnFindMsg(WPARAM wParam, LPARAM lParam)
01069 {
01070     nsCOMPtr<nsIWebBrowserFind> finder(do_GetInterface(mWebBrowser));
01071     if(!finder)
01072         return NULL;
01073 
01074     // Get the pointer to the current Find dialog box
01075     CFindDialog* dlg = (CFindDialog *) CFindReplaceDialog::GetNotifier(lParam);
01076     if(!dlg) 
01077         return NULL;
01078 
01079     // Has the user decided to terminate the dialog box?
01080     if(dlg->IsTerminating())
01081         return NULL;
01082 
01083     if(dlg->FindNext())
01084     {
01085         USES_CONVERSION;
01086         finder->SetSearchString(T2W(dlg->GetFindString().GetBuffer(0)));
01087         finder->SetMatchCase(dlg->MatchCase() ? PR_TRUE : PR_FALSE);
01088         finder->SetEntireWord(dlg->MatchWholeWord() ? PR_TRUE : PR_FALSE);
01089         finder->SetWrapFind(dlg->WrapAround() ? PR_TRUE : PR_FALSE);
01090         finder->SetFindBackwards(dlg->SearchBackwards() ? PR_TRUE : PR_FALSE);
01091 
01092         PRBool didFind;
01093         nsresult rv = finder->FindNext(&didFind);
01094         
01095         if(!didFind)
01096         {
01097             AfxMessageBox(IDS_SRCH_STR_NOT_FOUND);
01098             dlg->SetFocus();
01099         }
01100 
01101         return (NS_SUCCEEDED(rv) && didFind);
01102     }
01103 
01104     return 0;
01105 }
01106 
01107 void CBrowserView::OnFilePrint()
01108 {
01109   nsCOMPtr<nsIWebBrowserPrint> print(do_GetInterface(mWebBrowser));
01110     if(print)
01111     {
01112     if (!m_PrintSettings) 
01113     {
01114       if (NS_FAILED(print->GetGlobalPrintSettings(getter_AddRefs(m_PrintSettings)))) {
01115         return;
01116       }
01117     }
01118     nsCOMPtr<nsIWebBrowserPrint> print(do_GetInterface(mWebBrowser));
01119       if(print)
01120     {
01121       print->Print(m_PrintSettings, nsnull);
01122     }
01123 
01124   }
01125 }
01126 
01127 void CBrowserView::OnFilePrintPreview()
01128 {
01129   nsCOMPtr<nsIWebBrowserPrint> print(do_GetInterface(mWebBrowser));
01130     if(print)
01131     {
01132     if (!m_PrintSettings) 
01133     {
01134       if (NS_FAILED(print->GetGlobalPrintSettings(getter_AddRefs(m_PrintSettings)))) {
01135         return;
01136       }
01137     }
01138     if (!m_InPrintPreview) 
01139     {
01140       if (NS_SUCCEEDED(print->PrintPreview(m_PrintSettings, nsnull, nsnull))) 
01141       {
01142         m_InPrintPreview = TRUE;
01143 
01144         CMenu* menu = mpBrowserFrame->GetMenu();
01145         if (menu) 
01146         {
01147           menu->CheckMenuItem( ID_FILE_PRINTPREVIEW, MF_CHECKED );
01148         }
01149       }
01150     } 
01151     else 
01152     {
01153       if (NS_SUCCEEDED(print->ExitPrintPreview())) 
01154       {
01155         m_InPrintPreview = FALSE;
01156         CMenu* menu = mpBrowserFrame->GetMenu();
01157         if (menu) 
01158         {
01159           menu->CheckMenuItem( ID_FILE_PRINTPREVIEW, MF_UNCHECKED );
01160         }
01161       }
01162     }
01163   }
01164 }
01165 
01166 void CBrowserView::OnFilePrintSetup()
01167 {
01168   nsCOMPtr<nsIWebBrowserPrint> print(do_GetInterface(mWebBrowser));
01169     if(print)
01170   {
01171     if (!m_PrintSettings) 
01172     {
01173       if (NS_FAILED(print->GetGlobalPrintSettings(getter_AddRefs(m_PrintSettings)))) {
01174         return;
01175       }
01176     }
01177     CPageSetupPropSheet propSheet(_T("Page Setup"), this);
01178 
01179     propSheet.SetPrintSettingsValues(m_PrintSettings);
01180 
01181     int status = propSheet.DoModal();
01182     if (status == IDOK) 
01183     {
01184       propSheet.GetPrintSettingsValues(m_PrintSettings);
01185     }
01186   }
01187 }
01188 
01190 void CBrowserView::OnUpdateFilePrint(CCmdUI* pCmdUI)
01191 {
01192     pCmdUI->Enable(!m_bCurrentlyPrinting);
01193 }
01194 
01196 void CBrowserView::OnUpdatePrintSetup(CCmdUI* pCmdUI)
01197 {
01198     pCmdUI->Enable(!m_bCurrentlyPrinting && !m_InPrintPreview);
01199 }
01200 
01201 
01202 
01203 // Called from the busy state related methods in the 
01204 // BrowserFrameGlue object
01205 //
01206 // When aBusy is TRUE it means that browser is busy loading a URL
01207 // When aBusy is FALSE, it's done loading
01208 // We use this to update our STOP tool bar button
01209 //
01210 // We basically note this state into a member variable
01211 // The actual toolbar state will be updated in response to the
01212 // ON_UPDATE_COMMAND_UI method - OnUpdateNavStop() being called
01213 //
01214 void CBrowserView::UpdateBusyState(PRBool aBusy)
01215 {
01216   if (mbDocumentLoading && !aBusy && m_InPrintPreview)
01217   {
01218       nsCOMPtr<nsIWebBrowserPrint> print(do_GetInterface(mWebBrowser));
01219         if(print)
01220         {
01221           PRBool isDoingPP;
01222           print->GetDoingPrintPreview(&isDoingPP);
01223           if (!isDoingPP) 
01224           {
01225               m_InPrintPreview = FALSE;
01226               CMenu* menu = mpBrowserFrame->GetMenu();
01227               if (menu) 
01228               {
01229                   menu->CheckMenuItem( ID_FILE_PRINTPREVIEW, MF_UNCHECKED );
01230               }
01231           }
01232       }
01233   }
01234     mbDocumentLoading = aBusy;
01235 }
01236 
01237 void CBrowserView::SetCtxMenuLinkUrl(nsEmbedString& strLinkUrl)
01238 {
01239     mCtxMenuLinkUrl = strLinkUrl;
01240 }
01241 
01242 void CBrowserView::SetCtxMenuImageSrc(nsEmbedString& strImgSrc)
01243 {
01244     mCtxMenuImgSrc = strImgSrc;
01245 }
01246 
01247 void CBrowserView::SetCurrentFrameURL(nsEmbedString& strCurrentFrameURL)
01248 {
01249     mCtxMenuCurrentFrameURL = strCurrentFrameURL;
01250 }
01251 
01252 void CBrowserView::Activate(UINT nState, CWnd* pWndOther, BOOL bMinimized) 
01253 {
01254     if(bMinimized)  // This isn't an activate event that Gecko cares about
01255         return;
01256 
01257     nsCOMPtr<nsIWebBrowserFocus> focus(do_GetInterface(mWebBrowser));
01258     if(!focus)
01259         return;
01260     
01261     switch(nState) {
01262         case WA_ACTIVE:
01263         case WA_CLICKACTIVE:
01264             focus->Activate();
01265             break;
01266         case WA_INACTIVE:
01267             focus->Deactivate();
01268             break;
01269         default:
01270             break;
01271     }
01272 }
01273 
01274 void CBrowserView::ShowSecurityInfo()
01275 {
01276     HWND hParent = mpBrowserFrame->m_hWnd;
01277 
01278     if(m_SecurityState == SECURITY_STATE_INSECURE) {
01279         CString csMsg;
01280         csMsg.LoadString(IDS_NOSECURITY_INFO);
01281         ::MessageBox(hParent, csMsg, _T("MfcEmbed"), MB_OK);
01282         return;
01283     }
01284 
01285     ::MessageBox(hParent, _T("To Be Done.........."), _T("MfcEmbed"), MB_OK);
01286 }
01287 
01288 // Determintes if the currently loaded document
01289 // contains frames
01290 //
01291 BOOL CBrowserView::ViewContentContainsFrames()
01292 {
01293     nsresult rv = NS_OK;
01294 
01295     // Get nsIDOMDocument from nsIWebNavigation
01296     nsCOMPtr<nsIDOMDocument> domDoc;
01297     rv = mWebNav->GetDocument(getter_AddRefs(domDoc));
01298     if(NS_FAILED(rv))
01299        return FALSE;
01300 
01301     // QI nsIDOMDocument for nsIDOMHTMLDocument
01302     nsCOMPtr<nsIDOMHTMLDocument> htmlDoc = do_QueryInterface(domDoc);
01303     if (!htmlDoc)
01304         return FALSE;
01305    
01306     // Get the <body> element of the doc
01307     nsCOMPtr<nsIDOMHTMLElement> body;
01308     rv = htmlDoc->GetBody(getter_AddRefs(body));
01309     if(NS_FAILED(rv))
01310        return FALSE;
01311 
01312     // Is it of type nsIDOMHTMLFrameSetElement?
01313     nsCOMPtr<nsIDOMHTMLFrameSetElement> frameset = do_QueryInterface(body);
01314 
01315     return (frameset != nsnull);
01316 }
01317 
01318 void CBrowserView::OnViewFrameSource()
01319 {
01320     // Build the view-source: url
01321     //
01322     nsEmbedString viewSrcUrl;
01323     viewSrcUrl.Append(L"view-source:");
01324     viewSrcUrl.Append(mCtxMenuCurrentFrameURL);
01325 
01326     OpenViewSourceWindow(viewSrcUrl.get());
01327 }
01328 
01329 void CBrowserView::OnOpenFrameInNewWindow()
01330 {
01331     if(mCtxMenuCurrentFrameURL.Length())
01332         OpenURLInNewWindow(mCtxMenuCurrentFrameURL.get());
01333 }