From 1aa28c50ac2a229897f0541d54fe1b36cb51086e Mon Sep 17 00:00:00 2001 From: "amasri%netscape.com" Date: Wed, 20 Jun 2001 18:28:48 +0000 Subject: [PATCH] Adding files to qa embedding project. Not part of the build. git-svn-id: svn://10.0.0.236/trunk@97609 18797224-902f-48f8-a5cc-f745e15eee43 --- .../qa/testembed/BrowserFrameGlue.cpp | 393 ++++ mozilla/embedding/qa/testembed/BrowserFrm.cpp | 306 ++++ mozilla/embedding/qa/testembed/BrowserFrm.h | 195 ++ .../embedding/qa/testembed/BrowserImpl.cpp | 372 ++++ mozilla/embedding/qa/testembed/BrowserImpl.h | 63 + .../qa/testembed/BrowserImplCtxMenuLstnr.cpp | 40 + .../qa/testembed/BrowserImplHistoryLstnr.cpp | 98 + .../qa/testembed/BrowserImplPrompt.cpp | 150 ++ .../qa/testembed/BrowserImplWebPrgrsLstnr.cpp | 285 +++ .../embedding/qa/testembed/BrowserView.cpp | 1035 +++++++++++ .../qa/testembed/BrowserView.cpp.mod | 1611 +++++++++++++++++ mozilla/embedding/qa/testembed/BrowserView.h | 181 ++ mozilla/embedding/qa/testembed/Dialogs.cpp | 107 ++ mozilla/embedding/qa/testembed/Dialogs.h | 53 + .../qa/testembed/IBrowserFrameGlue.h | 96 + .../embedding/qa/testembed/MostRecentUrls.cpp | 135 ++ .../embedding/qa/testembed/MostRecentUrls.h | 41 + .../embedding/qa/testembed/Preferences.cpp | 99 + mozilla/embedding/qa/testembed/Preferences.h | 110 ++ .../qa/testembed/PrintProgressDialog.cpp | 246 +++ .../qa/testembed/PrintProgressDialog.h | 70 + mozilla/embedding/qa/testembed/ProfileMgr.cpp | 189 ++ mozilla/embedding/qa/testembed/ProfileMgr.h | 55 + .../embedding/qa/testembed/ProfilesDlg.cpp | 292 +++ mozilla/embedding/qa/testembed/ProfilesDlg.h | 120 ++ mozilla/embedding/qa/testembed/QaUtils.cpp | 161 ++ mozilla/embedding/qa/testembed/QaUtils.h | 61 + mozilla/embedding/qa/testembed/README.TXT | 137 ++ mozilla/embedding/qa/testembed/StdAfx.cpp | 31 + mozilla/embedding/qa/testembed/StdAfx.h | 105 ++ mozilla/embedding/qa/testembed/TestEmbed.cpp | 661 +++++++ mozilla/embedding/qa/testembed/TestEmbed.h | 122 ++ mozilla/embedding/qa/testembed/Tests.cpp | 1080 +++++++++++ mozilla/embedding/qa/testembed/Tests.h | 158 ++ mozilla/embedding/qa/testembed/UrlDialog.cpp | 54 + mozilla/embedding/qa/testembed/UrlDialog.h | 46 + mozilla/embedding/qa/testembed/makefile.win | 78 + .../embedding/qa/testembed/res/Toolbar.bmp | Bin 0 -> 838 bytes .../embedding/qa/testembed/res/testembed.ico | Bin 0 -> 1078 bytes .../embedding/qa/testembed/res/testembed.rc2 | 13 + .../embedding/qa/testembed/res/toolbar1.bmp | Bin 0 -> 238 bytes mozilla/embedding/qa/testembed/resource.h | 104 ++ mozilla/embedding/qa/testembed/testembed.aps | Bin 0 -> 2750 bytes mozilla/embedding/qa/testembed/testembed.dsp | 261 +++ mozilla/embedding/qa/testembed/testembed.dsw | 29 + mozilla/embedding/qa/testembed/testembed.htm | 58 + mozilla/embedding/qa/testembed/testembed.rc | 666 +++++++ .../qa/testembed/winEmbedFileLocProvider.cpp | 265 +++ .../qa/testembed/winEmbedFileLocProvider.h | 53 + 49 files changed, 10485 insertions(+) create mode 100644 mozilla/embedding/qa/testembed/BrowserFrameGlue.cpp create mode 100644 mozilla/embedding/qa/testembed/BrowserFrm.cpp create mode 100644 mozilla/embedding/qa/testembed/BrowserFrm.h create mode 100644 mozilla/embedding/qa/testembed/BrowserImpl.cpp create mode 100644 mozilla/embedding/qa/testembed/BrowserImpl.h create mode 100644 mozilla/embedding/qa/testembed/BrowserImplCtxMenuLstnr.cpp create mode 100644 mozilla/embedding/qa/testembed/BrowserImplHistoryLstnr.cpp create mode 100644 mozilla/embedding/qa/testembed/BrowserImplPrompt.cpp create mode 100644 mozilla/embedding/qa/testembed/BrowserImplWebPrgrsLstnr.cpp create mode 100644 mozilla/embedding/qa/testembed/BrowserView.cpp create mode 100644 mozilla/embedding/qa/testembed/BrowserView.cpp.mod create mode 100644 mozilla/embedding/qa/testembed/BrowserView.h create mode 100644 mozilla/embedding/qa/testembed/Dialogs.cpp create mode 100644 mozilla/embedding/qa/testembed/Dialogs.h create mode 100644 mozilla/embedding/qa/testembed/IBrowserFrameGlue.h create mode 100644 mozilla/embedding/qa/testembed/MostRecentUrls.cpp create mode 100644 mozilla/embedding/qa/testembed/MostRecentUrls.h create mode 100644 mozilla/embedding/qa/testembed/Preferences.cpp create mode 100644 mozilla/embedding/qa/testembed/Preferences.h create mode 100644 mozilla/embedding/qa/testembed/PrintProgressDialog.cpp create mode 100644 mozilla/embedding/qa/testembed/PrintProgressDialog.h create mode 100644 mozilla/embedding/qa/testembed/ProfileMgr.cpp create mode 100644 mozilla/embedding/qa/testembed/ProfileMgr.h create mode 100644 mozilla/embedding/qa/testembed/ProfilesDlg.cpp create mode 100644 mozilla/embedding/qa/testembed/ProfilesDlg.h create mode 100644 mozilla/embedding/qa/testembed/QaUtils.cpp create mode 100644 mozilla/embedding/qa/testembed/QaUtils.h create mode 100644 mozilla/embedding/qa/testembed/README.TXT create mode 100644 mozilla/embedding/qa/testembed/StdAfx.cpp create mode 100644 mozilla/embedding/qa/testembed/StdAfx.h create mode 100644 mozilla/embedding/qa/testembed/TestEmbed.cpp create mode 100644 mozilla/embedding/qa/testembed/TestEmbed.h create mode 100644 mozilla/embedding/qa/testembed/Tests.cpp create mode 100644 mozilla/embedding/qa/testembed/Tests.h create mode 100644 mozilla/embedding/qa/testembed/UrlDialog.cpp create mode 100644 mozilla/embedding/qa/testembed/UrlDialog.h create mode 100644 mozilla/embedding/qa/testembed/makefile.win create mode 100644 mozilla/embedding/qa/testembed/res/Toolbar.bmp create mode 100644 mozilla/embedding/qa/testembed/res/testembed.ico create mode 100644 mozilla/embedding/qa/testembed/res/testembed.rc2 create mode 100644 mozilla/embedding/qa/testembed/res/toolbar1.bmp create mode 100644 mozilla/embedding/qa/testembed/resource.h create mode 100644 mozilla/embedding/qa/testembed/testembed.aps create mode 100644 mozilla/embedding/qa/testembed/testembed.dsp create mode 100644 mozilla/embedding/qa/testembed/testembed.dsw create mode 100644 mozilla/embedding/qa/testembed/testembed.htm create mode 100644 mozilla/embedding/qa/testembed/testembed.rc create mode 100644 mozilla/embedding/qa/testembed/winEmbedFileLocProvider.cpp create mode 100644 mozilla/embedding/qa/testembed/winEmbedFileLocProvider.h diff --git a/mozilla/embedding/qa/testembed/BrowserFrameGlue.cpp b/mozilla/embedding/qa/testembed/BrowserFrameGlue.cpp new file mode 100644 index 00000000000..c23b1566623 --- /dev/null +++ b/mozilla/embedding/qa/testembed/BrowserFrameGlue.cpp @@ -0,0 +1,393 @@ +/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- + * + * The contents of this file are subject to the Netscape Public + * License Version 1.1 (the "License"); you may not use this file + * except in compliance with the License. You may obtain a copy of + * the License at http://www.mozilla.org/NPL/ + * + * Software distributed under the License is distributed on an "AS + * IS" basis, WITHOUT WARRANTY OF ANY KIND, either express or + * implied. See the License for the specific language governing + * rights and limitations under the License. + * + * The Original Code is mozilla.org code. + * + * The Initial Developer of the Original Code is Netscape + * Communications Corporation. Portions created by Netscape are + * Copyright (C) 1998 Netscape Communications Corporation. All + * Rights Reserved. + * + * Contributor(s): + * Chak Nanga + */ + +// File Overview.... +// +// This file has the IBrowserFrameGlueObj implementation +// This frame glue object is nested inside of the BrowserFrame +// object(See BrowserFrm.h for more info) +// +// This is the place where all the platform specific interaction +// with the browser frame window takes place in response to +// callbacks from Gecko interface methods +// +// The main purpose of this interface is to separate the cross +// platform code in BrowserImpl*.cpp from the platform specific +// code(which is in this file) +// +// You'll also notice the use of a macro named "METHOD_PROLOGUE" +// through out this file. This macro essentially makes the pointer +// to a "containing" class available inside of the class which is +// being contained via a var named "pThis". In our case, the +// BrowserFrameGlue object is contained inside of the BrowserFrame +// object so "pThis" will be a pointer to a BrowserFrame object +// Refer to MFC docs for more info on METHOD_PROLOGUE macro + + +#include "stdafx.h" +#include "TestEmbed.h" +#include "BrowserFrm.h" +#include "Dialogs.h" + +///////////////////////////////////////////////////////////////////////////// +// IBrowserFrameGlue implementation + +void CBrowserFrame::BrowserFrameGlueObj::UpdateStatusBarText(const PRUnichar *aMessage) +{ + METHOD_PROLOGUE(CBrowserFrame, BrowserFrameGlueObj) + + nsCString strStatus; + + if(aMessage) + strStatus.AssignWithConversion(aMessage); + + pThis->m_wndStatusBar.SetPaneText(0, strStatus.get()); +} + +void CBrowserFrame::BrowserFrameGlueObj::UpdateProgress(PRInt32 aCurrent, PRInt32 aMax) +{ + METHOD_PROLOGUE(CBrowserFrame, BrowserFrameGlueObj) + + pThis->m_wndProgressBar.SetRange32(0, aMax); + pThis->m_wndProgressBar.SetPos(aCurrent); +} + +void CBrowserFrame::BrowserFrameGlueObj::UpdateBusyState(PRBool aBusy) +{ + METHOD_PROLOGUE(CBrowserFrame, BrowserFrameGlueObj) + + // Just notify the view of the busy state + // There's code in there which will take care of + // updating the STOP toolbar btn. etc + + pThis->m_wndBrowserView.UpdateBusyState(aBusy); +} + +// Called from the OnLocationChange() method in the nsIWebProgressListener +// interface implementation in CBrowserImpl to update the current URI +// Will get called after a URI is successfully loaded in the browser +// We use this info to update the URL bar's edit box +// +void CBrowserFrame::BrowserFrameGlueObj::UpdateCurrentURI(nsIURI *aLocation) +{ + METHOD_PROLOGUE(CBrowserFrame, BrowserFrameGlueObj) + + if(aLocation) + { + nsXPIDLCString uriString; + aLocation->GetSpec(getter_Copies(uriString)); + + pThis->m_wndUrlBar.SetCurrentURL(uriString.get()); + } +} + +void CBrowserFrame::BrowserFrameGlueObj::GetBrowserFrameTitle(PRUnichar **aTitle) +{ + METHOD_PROLOGUE(CBrowserFrame, BrowserFrameGlueObj) + + CString title; + pThis->GetWindowText(title); + + if(!title.IsEmpty()) + { + nsString nsTitle; + nsTitle.AssignWithConversion(title.GetBuffer(0)); + + *aTitle = nsTitle.ToNewUnicode(); + } +} + +void CBrowserFrame::BrowserFrameGlueObj::SetBrowserFrameTitle(const PRUnichar *aTitle) +{ + METHOD_PROLOGUE(CBrowserFrame, BrowserFrameGlueObj) + + USES_CONVERSION; + + if(W2T(aTitle)) + { + pThis->SetWindowText(W2T(aTitle)); + } + else + { + // Use the AppName i.e. testembed as the title if we + // do not get one from GetBrowserWindowTitle() + // + CString cs; + cs.LoadString(AFX_IDS_APP_TITLE); + pThis->SetWindowText(cs); + } +} + +void CBrowserFrame::BrowserFrameGlueObj::SetBrowserFrameSize(PRInt32 aCX, PRInt32 aCY) +{ + METHOD_PROLOGUE(CBrowserFrame, BrowserFrameGlueObj) + + pThis->SetWindowPos(NULL, 0, 0, aCX, aCY, + SWP_NOMOVE | SWP_NOACTIVATE | SWP_NOZORDER + ); +} + +void CBrowserFrame::BrowserFrameGlueObj::GetBrowserFrameSize(PRInt32 *aCX, PRInt32 *aCY) +{ + METHOD_PROLOGUE(CBrowserFrame, BrowserFrameGlueObj) + + RECT wndRect; + pThis->GetWindowRect(&wndRect); + + if (aCX) + *aCX = wndRect.right - wndRect.left; + + if (aCY) + *aCY = wndRect.bottom - wndRect.top; +} + +void CBrowserFrame::BrowserFrameGlueObj::SetBrowserFramePosition(PRInt32 aX, PRInt32 aY) +{ + METHOD_PROLOGUE(CBrowserFrame, BrowserFrameGlueObj) + + pThis->SetWindowPos(NULL, aX, aY, 0, 0, + SWP_NOSIZE | SWP_NOACTIVATE | SWP_NOZORDER); +} + +void CBrowserFrame::BrowserFrameGlueObj::GetBrowserFramePosition(PRInt32 *aX, PRInt32 *aY) +{ + METHOD_PROLOGUE(CBrowserFrame, BrowserFrameGlueObj) + + RECT wndRect; + pThis->GetWindowRect(&wndRect); + + if (aX) + *aX = wndRect.left; + + if (aY) + *aY = wndRect.top; +} + +void CBrowserFrame::BrowserFrameGlueObj::GetBrowserFramePositionAndSize(PRInt32 *aX, PRInt32 *aY, PRInt32 *aCX, PRInt32 *aCY) +{ + METHOD_PROLOGUE(CBrowserFrame, BrowserFrameGlueObj) + + RECT wndRect; + pThis->GetWindowRect(&wndRect); + + if (aX) + *aX = wndRect.left; + + if (aY) + *aY = wndRect.top; + + if (aCX) + *aCX = wndRect.right - wndRect.left; + + if (aCY) + *aCY = wndRect.bottom - wndRect.top; +} + +void CBrowserFrame::BrowserFrameGlueObj::SetBrowserFramePositionAndSize(PRInt32 aX, PRInt32 aY, PRInt32 aCX, PRInt32 aCY, PRBool fRepaint) +{ + METHOD_PROLOGUE(CBrowserFrame, BrowserFrameGlueObj) + + pThis->SetWindowPos(NULL, aX, aY, aCX, aCY, + SWP_NOACTIVATE | SWP_NOZORDER); +} + +void CBrowserFrame::BrowserFrameGlueObj::SetFocus() +{ + METHOD_PROLOGUE(CBrowserFrame, BrowserFrameGlueObj) + + pThis->SetFocus(); +} + +void CBrowserFrame::BrowserFrameGlueObj::FocusAvailable(PRBool *aFocusAvail) +{ + METHOD_PROLOGUE(CBrowserFrame, BrowserFrameGlueObj) + + HWND focusWnd = GetFocus()->m_hWnd; + + if ((focusWnd == pThis->m_hWnd) || ::IsChild(pThis->m_hWnd, focusWnd)) + *aFocusAvail = PR_TRUE; + else + *aFocusAvail = PR_FALSE; +} + +void CBrowserFrame::BrowserFrameGlueObj::ShowBrowserFrame(PRBool aShow) +{ + METHOD_PROLOGUE(CBrowserFrame, BrowserFrameGlueObj) + + if(aShow) + { + pThis->ShowWindow(SW_SHOW); + pThis->SetActiveWindow(); + pThis->UpdateWindow(); + } + else + { + pThis->ShowWindow(SW_HIDE); + } +} + +void CBrowserFrame::BrowserFrameGlueObj::GetBrowserFrameVisibility(PRBool *aVisible) +{ + METHOD_PROLOGUE(CBrowserFrame, BrowserFrameGlueObj) + + // Is the current BrowserFrame the active one? + if (GetActiveWindow()->m_hWnd != pThis->m_hWnd) + { + *aVisible = PR_FALSE; + return; + } + + // We're the active one + //Return FALSE if we're minimized + WINDOWPLACEMENT wpl; + pThis->GetWindowPlacement(&wpl); + + if ((wpl.showCmd == SW_RESTORE) || (wpl.showCmd == SW_MAXIMIZE)) + *aVisible = PR_TRUE; + else + *aVisible = PR_FALSE; +} + +PRBool CBrowserFrame::BrowserFrameGlueObj::CreateNewBrowserFrame(PRUint32 chromeMask, + PRInt32 x, PRInt32 y, + PRInt32 cx, PRInt32 cy, + nsIWebBrowser** aWebBrowser) +{ + NS_ENSURE_ARG_POINTER(aWebBrowser); + + *aWebBrowser = nsnull; + + CTestEmbedApp *pApp = (CTestEmbedApp *)AfxGetApp(); + if(!pApp) + return PR_FALSE; + + // Note that we're calling with the last param set to "false" i.e. + // this instructs not to show the frame window + // This is mainly needed when the window size is specified in the window.open() + // JS call. In those cases Gecko calls us to create the browser with a default + // size (all are -1) and then it calls the SizeBrowserTo() method to set + // the proper window size. If this window were to be visible then you'll see + // the window size changes on the screen causing an unappealing flicker + // + + CBrowserFrame* pFrm = pApp->CreateNewBrowserFrame(chromeMask, x, y, cx, cy, PR_FALSE); + if(!pFrm) + return PR_FALSE; + + // At this stage we have a new CBrowserFrame and a new CBrowserView + // objects. The CBrowserView also would have an embedded browser + // object created. Get the mWebBrowser member from the CBrowserView + // and return it. (See CBrowserView's CreateBrowser() on how the + // embedded browser gets created and how it's mWebBrowser member + // gets initialized) + + NS_IF_ADDREF(*aWebBrowser = pFrm->m_wndBrowserView.mWebBrowser); + + return PR_TRUE; +} + +void CBrowserFrame::BrowserFrameGlueObj::DestroyBrowserFrame() +{ + METHOD_PROLOGUE(CBrowserFrame, BrowserFrameGlueObj) + + pThis->PostMessage(WM_CLOSE); +} + +void CBrowserFrame::BrowserFrameGlueObj::ShowContextMenu(PRUint32 aContextFlags, nsIDOMNode *aNode) +{ + METHOD_PROLOGUE(CBrowserFrame, BrowserFrameGlueObj) + + UINT nIDResource = IDR_CTXMENU_DOCUMENT; + + if(aContextFlags & nsIContextMenuListener::CONTEXT_DOCUMENT) + nIDResource = IDR_CTXMENU_DOCUMENT; + else if(aContextFlags & nsIContextMenuListener::CONTEXT_TEXT) + nIDResource = IDR_CTXMENU_TEXT; + else if(aContextFlags & nsIContextMenuListener::CONTEXT_LINK) + { + nIDResource = IDR_CTXMENU_LINK; + + // Since we handle all the browser menu/toolbar commands + // in the View, we basically setup the Link's URL in the + // BrowserView object. When a menu selection in the context + // menu is made, the appropriate command handler in the + // BrowserView will be invoked and the value of the URL + // will be accesible in the view + + // Reset the value from the last invocation + // (A new value will be set after we determine it below) + // + nsAutoString strUrlUcs2; + pThis->m_wndBrowserView.SetCtxMenuLinkUrl(strUrlUcs2); + + // Get the URL from the link. This is two step process + // 1. We first get the nsIDOMHTMLAnchorElement + // 2. We then get the URL associated with the link + nsresult rv = NS_OK; + nsCOMPtr linkElement(do_QueryInterface(aNode, &rv)); + if(NS_FAILED(rv)) + return; + + rv = linkElement->GetHref(strUrlUcs2); + if(NS_FAILED(rv)) + return; + + // Update the view with the new LinkUrl + // Note that this string is in UCS2 format + pThis->m_wndBrowserView.SetCtxMenuLinkUrl(strUrlUcs2); + } + else if(aContextFlags & nsIContextMenuListener::CONTEXT_IMAGE) + { + nIDResource = IDR_CTXMENU_IMAGE; + + nsAutoString strImgSrcUcs2; + pThis->m_wndBrowserView.SetCtxMenuImageSrc(strImgSrcUcs2); // Clear it + + // Get the IMG SRC + nsresult rv = NS_OK; + nsCOMPtr imgElement(do_QueryInterface(aNode, &rv)); + if(NS_FAILED(rv)) + return; + + rv = imgElement->GetSrc(strImgSrcUcs2); + if(NS_FAILED(rv)) + return; + + pThis->m_wndBrowserView.SetCtxMenuImageSrc(strImgSrcUcs2); // Set the new Img Src + } + + CMenu ctxMenu; + if(ctxMenu.LoadMenu(nIDResource)) + { + POINT cursorPos; + GetCursorPos(&cursorPos); + + (ctxMenu.GetSubMenu(0))->TrackPopupMenu(TPM_LEFTALIGN, cursorPos.x, cursorPos.y, pThis); + } +} + +HWND CBrowserFrame::BrowserFrameGlueObj::GetBrowserFrameNativeWnd() +{ + METHOD_PROLOGUE(CBrowserFrame, BrowserFrameGlueObj) + return pThis->m_hWnd; +} diff --git a/mozilla/embedding/qa/testembed/BrowserFrm.cpp b/mozilla/embedding/qa/testembed/BrowserFrm.cpp new file mode 100644 index 00000000000..f5fb18acff2 --- /dev/null +++ b/mozilla/embedding/qa/testembed/BrowserFrm.cpp @@ -0,0 +1,306 @@ +/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- + * + * The contents of this file are subject to the Netscape Public + * License Version 1.1 (the "License"); you may not use this file + * except in compliance with the License. You may obtain a copy of + * the License at http://www.mozilla.org/NPL/ + * + * Software distributed under the License is distributed on an "AS + * IS" basis, WITHOUT WARRANTY OF ANY KIND, either express or + * implied. See the License for the specific language governing + * rights and limitations under the License. + * + * The Original Code is mozilla.org code. + * + * The Initial Developer of the Original Code is Netscape + * Communications Corporation. Portions created by Netscape are + * Copyright (C) 1998 Netscape Communications Corporation. All + * Rights Reserved. + * + * Contributor(s): + * Chak Nanga + */ + +// File Overview.... +// +// The typical MFC View, toolbar, statusbar creation done +// in CBrowserFrame::OnCreate() +// +// Code to update the Status/Tool bars in response to the +// Web page loading progress(called from methods in CBrowserImpl) +// +// SetupFrameChrome() determines what, if any, UI elements this Frame +// will sport based on the current "chromeMask" +// +// Also take a look at OnClose() which gets used when you close a browser +// window. This needs to be overrided mainly to handle supporting multiple +// browser frame windows via the "New Browser Window" menu item +// Without this being overridden the MFC framework handles the OnClose and +// shutsdown the complete application when a frame window is closed. +// In our case, we want the app to shutdown when the File/Exit menu is chosen +// +// Another key functionality this object implements is the IBrowserFrameGlue +// interface - that's the interface the Gecko embedding interfaces call +// upong to update the status bar etc. +// (Take a look at IBrowserFrameGlue.h for the interface definition and +// the BrowserFrm.h to see how we implement this interface - as a nested +// class) +// We pass this Glue object pointer to the CBrowserView object via the +// SetBrowserFrameGlue() method. The CBrowserView passes this on to the +// embedding interface implementaion +// +// Please note the use of the macro METHOD_PROLOGUE in the implementation +// of the nested BrowserFrameGlue object. Essentially what this macro does +// is to get you access to the outer (or the object which is containing the +// nested object) object via the pThis pointer. +// Refer to the AFXDISP.H file in VC++ include dirs +// +// Next suggested file to look at : BrowserView.cpp + +#include "stdafx.h" +#include "TestEmbed.h" +#include "BrowserFrm.h" + +#ifdef _DEBUG +#define new DEBUG_NEW +#undef THIS_FILE +static char THIS_FILE[] = __FILE__; +#endif + +///////////////////////////////////////////////////////////////////////////// +// CBrowserFrame + +IMPLEMENT_DYNAMIC(CBrowserFrame, CFrameWnd) + +BEGIN_MESSAGE_MAP(CBrowserFrame, CFrameWnd) + //{{AFX_MSG_MAP(CBrowserFrame) + ON_WM_CREATE() + ON_WM_SETFOCUS() + ON_WM_SIZE() + ON_WM_CLOSE() + ON_WM_ACTIVATE() + //}}AFX_MSG_MAP +END_MESSAGE_MAP() + +static UINT indicators[] = +{ + ID_SEPARATOR, // For the Status line + ID_SEPARATOR, // For the Progress Bar +}; + +///////////////////////////////////////////////////////////////////////////// +// CBrowserFrame construction/destruction + +CBrowserFrame::CBrowserFrame(PRUint32 chromeMask) +{ + // Save the chromeMask off. It'll be used + // later to determine whether this browser frame + // will have menubar, toolbar, statusbar etc. + + m_chromeMask = chromeMask; +} + +CBrowserFrame::~CBrowserFrame() +{ +} + +void CBrowserFrame::OnClose() +{ + CTestEmbedApp *pApp = (CTestEmbedApp *)AfxGetApp(); + pApp->RemoveFrameFromList(this); + + DestroyWindow(); +} + +// This is where the UrlBar, ToolBar, StatusBar, ProgressBar +// get created +// +int CBrowserFrame::OnCreate(LPCREATESTRUCT lpCreateStruct) +{ + if (CFrameWnd::OnCreate(lpCreateStruct) == -1) + return -1; + + // Pass "this" to the View for later callbacks + // and/or access to any public data members, if needed + // + m_wndBrowserView.SetBrowserFrame(this); + + // Pass on the BrowserFrameGlue also to the View which + // it will use during the Init() process after creation + // of the BrowserImpl obj. Essentially, the View object + // hooks up the Embedded browser's callbacks to the BrowserFrame + // via this BrowserFrameGlue object + m_wndBrowserView.SetBrowserFrameGlue((PBROWSERFRAMEGLUE)&m_xBrowserFrameGlueObj); + + // create a view to occupy the client area of the frame + // This will be the view in which the embedded browser will + // be displayed in + // + if (!m_wndBrowserView.Create(NULL, NULL, AFX_WS_DEFAULT_VIEW, + CRect(0, 0, 0, 0), this, AFX_IDW_PANE_FIRST, NULL)) + { + TRACE0("Failed to create view window\n"); + return -1; + } + + // create the URL bar (essentially a ComboBoxEx object) + if (!m_wndUrlBar.Create(CBS_DROPDOWN | WS_CHILD, CRect(0, 0, 200, 150), this, ID_URL_BAR)) + { + TRACE0("Failed to create URL Bar\n"); + return -1; // fail to create + } + + // Load the Most Recently Used(MRU) Urls into the UrlBar + m_wndUrlBar.LoadMRUList(); + + // Create the toolbar with Back, Fwd, Stop, etc. buttons.. + if (!m_wndToolBar.CreateEx(this, TBSTYLE_FLAT, WS_CHILD | WS_VISIBLE | CBRS_TOP + | CBRS_TOOLTIPS | CBRS_FLYBY | CBRS_SIZE_DYNAMIC) || + !m_wndToolBar.LoadToolBar(IDR_MAINFRAME)) + { + TRACE0("Failed to create toolbar\n"); + return -1; // fail to create + } + + // Create a ReBar window to which the toolbar and UrlBar + // will be added + if (!m_wndReBar.Create(this)) + { + TRACE0("Failed to create ReBar\n"); + return -1; // fail to create + } + + //Add the ToolBar and UrlBar windows to the rebar + m_wndReBar.AddBar(&m_wndToolBar); + m_wndReBar.AddBar(&m_wndUrlBar, "Enter URL:"); + + // Create the status bar with two panes - one pane for actual status + // text msgs. and the other for the progress control + if (!m_wndStatusBar.Create(this) || + !m_wndStatusBar.SetIndicators(indicators, + sizeof(indicators)/sizeof(UINT))) + { + TRACE0("Failed to create status bar\n"); + return -1; // fail to create + } + + // Create the progress bar as a child of the status bar. + // Note that the ItemRect which we'll get at this stage + // is bogus since the status bar panes are not fully + // positioned yet i.e. we'll be passing in an invalid rect + // to the Create function below + // The actual positioning of the progress bar will be done + // in response to OnSize() + RECT rc; + m_wndStatusBar.GetItemRect (1, &rc); + if (!m_wndProgressBar.Create(WS_CHILD|WS_VISIBLE|PBS_SMOOTH, rc, &m_wndStatusBar, ID_PROG_BAR)) + { + TRACE0("Failed to create progress bar\n"); + return -1; // fail to create + } + + // Based on the "chromeMask" we were supplied during construction + // hide any requested UI elements - statusbar, menubar etc... + // Note that the window styles (WM_RESIZE etc) are set inside + // of PreCreateWindow() + + SetupFrameChrome(); + + return 0; +} + +void CBrowserFrame::SetupFrameChrome() +{ + if(m_chromeMask == nsIWebBrowserChrome::CHROME_ALL) + return; + + if(! (m_chromeMask & nsIWebBrowserChrome::CHROME_MENUBAR) ) + SetMenu(NULL); // Hide the MenuBar + + if(! (m_chromeMask & nsIWebBrowserChrome::CHROME_TOOLBAR) ) + m_wndReBar.ShowWindow(SW_HIDE); // Hide the ToolBar + + if(! (m_chromeMask & nsIWebBrowserChrome::CHROME_STATUSBAR) ) + m_wndStatusBar.ShowWindow(SW_HIDE); // Hide the StatusBar +} + +BOOL CBrowserFrame::PreCreateWindow(CREATESTRUCT& cs) +{ + if( !CFrameWnd::PreCreateWindow(cs) ) + return FALSE; + + cs.dwExStyle &= ~WS_EX_CLIENTEDGE; + + // Change window style based on the chromeMask + + if(! (m_chromeMask & nsIWebBrowserChrome::CHROME_TITLEBAR) ) + cs.style &= ~WS_CAPTION; // No caption + + if(! (m_chromeMask & nsIWebBrowserChrome::CHROME_WINDOW_RESIZE) ) + { + // Can't resize this window + cs.style &= ~WS_SIZEBOX; + cs.style &= ~WS_THICKFRAME; + cs.style &= ~WS_MINIMIZEBOX; + cs.style &= ~WS_MAXIMIZEBOX; + } + + cs.lpszClass = AfxRegisterWndClass(0); + + return TRUE; +} + +///////////////////////////////////////////////////////////////////////////// +// CBrowserFrame message handlers +void CBrowserFrame::OnSetFocus(CWnd* pOldWnd) +{ + // forward focus to the view window + m_wndBrowserView.SetFocus(); +} + +BOOL CBrowserFrame::OnCmdMsg(UINT nID, int nCode, void* pExtra, AFX_CMDHANDLERINFO* pHandlerInfo) +{ + // let the view have first crack at the command + if (m_wndBrowserView.OnCmdMsg(nID, nCode, pExtra, pHandlerInfo)) + return TRUE; + + // otherwise, do default handling + return CFrameWnd::OnCmdMsg(nID, nCode, pExtra, pHandlerInfo); +} + +// Needed to properly position/resize the progress bar +// +void CBrowserFrame::OnSize(UINT nType, int cx, int cy) +{ + CFrameWnd::OnSize(nType, cx, cy); + + // Get the ItemRect of the status bar's Pane 1 + // That's where the progress bar will be located + RECT rc; + m_wndStatusBar.GetItemRect(1, &rc); + + // Move the progress bar into it's correct location + // + m_wndProgressBar.MoveWindow(&rc); +} + +#ifdef _DEBUG +void CBrowserFrame::AssertValid() const +{ + CFrameWnd::AssertValid(); +} + +void CBrowserFrame::Dump(CDumpContext& dc) const +{ + CFrameWnd::Dump(dc); +} + +#endif //_DEBUG + + +void CBrowserFrame::OnActivate(UINT nState, CWnd* pWndOther, BOOL bMinimized) +{ + CFrameWnd::OnActivate(nState, pWndOther, bMinimized); + + m_wndBrowserView.Activate(nState, pWndOther, bMinimized); +} diff --git a/mozilla/embedding/qa/testembed/BrowserFrm.h b/mozilla/embedding/qa/testembed/BrowserFrm.h new file mode 100644 index 00000000000..d9209984ffd --- /dev/null +++ b/mozilla/embedding/qa/testembed/BrowserFrm.h @@ -0,0 +1,195 @@ +/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- + * + * The contents of this file are subject to the Netscape Public + * License Version 1.1 (the "License"); you may not use this file + * except in compliance with the License. You may obtain a copy of + * the License at http://www.mozilla.org/NPL/ + * + * Software distributed under the License is distributed on an "AS + * IS" basis, WITHOUT WARRANTY OF ANY KIND, either express or + * implied. See the License for the specific language governing + * rights and limitations under the License. + * + * The Original Code is mozilla.org code. + * + * The Initial Developer of the Original Code is Netscape + * Communications Corporation. Portions created by Netscape are + * Copyright (C) 1998 Netscape Communications Corporation. All + * Rights Reserved. + * + * Contributor(s): + * Chak Nanga + */ + +// BrowserFrm.h : interface of the CBrowserFrame class +// +///////////////////////////////////////////////////////////////////////////// + +#ifndef _IBROWSERFRM_H +#define _IBROWSERFRM_H + +#if _MSC_VER > 1000 +#pragma once +#endif // _MSC_VER > 1000 + +#include "BrowserView.h" +#include "IBrowserFrameGlue.h" +#include "MostRecentUrls.h" + +// A simple UrlBar class... +class CUrlBar : public CComboBoxEx +{ +public: + inline void GetEnteredURL(CString& url) { + GetEditCtrl()->GetWindowText(url); + } + inline void GetSelectedURL(CString& url) { + GetLBText(GetCurSel(), url); + } + inline void SetCurrentURL(LPCTSTR pUrl) { + SetWindowText(pUrl); + } + inline void AddURLToList(CString& url, bool bAddToMRUList = true) { + COMBOBOXEXITEM ci; + ci.mask = CBEIF_TEXT; ci.iItem = -1; + ci.pszText = (LPTSTR)(LPCTSTR)url; + InsertItem(&ci); + + if(bAddToMRUList) + m_MRUList.AddURL((LPTSTR)(LPCTSTR)url); + } + inline void LoadMRUList() { + for (int i=0;im_hWnd == CWnd::GetFocus()->m_hWnd); + } + inline BOOL EditCtrlHasSelection() { + int nStartChar = 0, nEndChar = 0; + if(EditCtrlHasFocus()) + GetEditCtrl()->GetSel(nStartChar, nEndChar); + return (nEndChar > nStartChar) ? TRUE : FALSE; + } + inline BOOL CanCutToClipboard() { + return EditCtrlHasSelection(); + } + inline void CutToClipboard() { + GetEditCtrl()->Cut(); + } + inline BOOL CanCopyToClipboard() { + return EditCtrlHasSelection(); + } + inline void CopyToClipboard() { + GetEditCtrl()->Copy(); + } + inline BOOL CanPasteFromClipboard() { + return EditCtrlHasFocus(); + } + inline void PasteFromClipboard() { + GetEditCtrl()->Paste(); + } + inline BOOL CanUndoEditOp() { + return EditCtrlHasFocus() ? GetEditCtrl()->CanUndo() : FALSE; + } + inline void UndoEditOp() { + if(EditCtrlHasFocus()) + GetEditCtrl()->Undo(); + } + +protected: + CMostRecentUrls m_MRUList; +}; + +class CBrowserFrame : public CFrameWnd +{ +public: + CBrowserFrame(PRUint32 chromeMask); + +protected: + DECLARE_DYNAMIC(CBrowserFrame) + +public: + inline CBrowserImpl *GetBrowserImpl() { return m_wndBrowserView.mpBrowserImpl; } + + CToolBar m_wndToolBar; + CStatusBar m_wndStatusBar; + CProgressCtrl m_wndProgressBar; + CUrlBar m_wndUrlBar; + CReBar m_wndReBar; + // The view inside which the embedded browser will + // be displayed in + CBrowserView m_wndBrowserView; + + // Wrapper functions for UrlBar clipboard operations + inline BOOL CanCutUrlBarSelection() { return m_wndUrlBar.CanCutToClipboard(); } + inline void CutUrlBarSelToClipboard() { m_wndUrlBar.CutToClipboard(); } + inline BOOL CanCopyUrlBarSelection() { return m_wndUrlBar.CanCopyToClipboard(); } + inline void CopyUrlBarSelToClipboard() { m_wndUrlBar.CopyToClipboard(); } + inline BOOL CanPasteToUrlBar() { return m_wndUrlBar.CanPasteFromClipboard(); } + inline void PasteFromClipboardToUrlBar() { m_wndUrlBar.PasteFromClipboard(); } + inline BOOL CanUndoUrlBarEditOp() { return m_wndUrlBar.CanUndoEditOp(); } + inline void UndoUrlBarEditOp() { m_wndUrlBar.UndoEditOp(); } + + // This specifies what UI elements this frame will sport + // w.r.t. toolbar, statusbar, urlbar etc. + PRUint32 m_chromeMask; + +protected: + // + // This nested class implements the IBrowserFramGlue interface + // The Gecko embedding interfaces call on this interface + // to update the status bars etc. + // + class BrowserFrameGlueObj : public IBrowserFrameGlue + { + // + // NS_DECL_BROWSERFRAMEGLUE below is a macro which expands + // to the function prototypes of methods in IBrowserFrameGlue + // Take a look at IBrowserFrameGlue.h for this macro define + // + + NS_DECL_BROWSERFRAMEGLUE + + } m_xBrowserFrameGlueObj; + friend class BrowserFrameGlueObj; + +public: + void SetupFrameChrome(); + +// Overrides + // ClassWizard generated virtual function overrides + //{{AFX_VIRTUAL(CBrowserFrame) + virtual BOOL PreCreateWindow(CREATESTRUCT& cs); + virtual BOOL OnCmdMsg(UINT nID, int nCode, void* pExtra, AFX_CMDHANDLERINFO* pHandlerInfo); + //}}AFX_VIRTUAL + +// Implementation +public: + virtual ~CBrowserFrame(); +#ifdef _DEBUG + virtual void AssertValid() const; + virtual void Dump(CDumpContext& dc) const; +#endif + +// Generated message map functions +protected: + //{{AFX_MSG(CBrowserFrame) + afx_msg int OnCreate(LPCREATESTRUCT lpCreateStruct); + afx_msg void OnSetFocus(CWnd *pOldWnd); + afx_msg void OnSize(UINT nType, int cx, int cy); + afx_msg void OnClose(); + afx_msg void OnActivate(UINT nState, CWnd* pWndOther, BOOL bMinimized); + //}}AFX_MSG + DECLARE_MESSAGE_MAP() +}; + +///////////////////////////////////////////////////////////////////////////// + +//{{AFX_INSERT_LOCATION}} +// Microsoft Visual C++ will insert additional declarations immediately before the previous line. + +#endif //_IBROWSERFRM_H diff --git a/mozilla/embedding/qa/testembed/BrowserImpl.cpp b/mozilla/embedding/qa/testembed/BrowserImpl.cpp new file mode 100644 index 00000000000..613976a32bc --- /dev/null +++ b/mozilla/embedding/qa/testembed/BrowserImpl.cpp @@ -0,0 +1,372 @@ +/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- + * + * The contents of this file are subject to the Netscape Public + * License Version 1.1 (the "License"); you may not use this file + * except in compliance with the License. You may obtain a copy of + * the License at http://www.mozilla.org/NPL/ + * + * Software distributed under the License is distributed on an "AS + * IS" basis, WITHOUT WARRANTY OF ANY KIND, either express or + * implied. See the License for the specific language governing + * rights and limitations under the License. + * + * The Original Code is mozilla.org code. + * + * The Initial Developer of the Original Code is Netscape + * Communications Corporation. Portions created by Netscape are + * Copyright (C) 1998 Netscape Communications Corporation. All + * Rights Reserved. + * + * Contributor(s): + * Chak Nanga + */ + +// File Overview.... +// This is the class which implements all the interfaces +// required(and optional) by the mozilla embeddable browser engine +// +// Note that this obj gets passed in the IBrowserFrameGlue* using the +// Init() method. Many of the interface implementations use this +// to get the actual task done. Ex: to update the status bar +// +// Look at the INTERFACE_MAP_ENTRY's below for the list of +// the currently implemented interfaces +// +// This file currently has the implementation for all the interfaces +// which are required of an app embedding Gecko +// Implementation of other optional interfaces are in separate files +// to avoid cluttering this one and to demonstrate other embedding +// principles. For example, nsIPrompt is implemented in a separate DLL. +// +// nsIWebBrowserChrome - This is a required interface to be implemented +// by embeddors +// +// nsIEmbeddingSiteWindow - This is a required interface to be implemented +// by embedders +// - SetTitle() gets called after a document +// load giving us the chance to update our +// titlebar +// +// Some points to note... +// +// nsIWebBrowserChrome interface's SetStatus() gets called when a user +// mouses over the links on a page +// +// nsIWebProgressListener interface's OnStatusChange() gets called +// to indicate progress when a page is being loaded +// +// Next suggested file(s) to look at : +// Any of the BrowserImpl*.cpp files for other interface +// implementation details +// + +#ifdef _WINDOWS + #include "stdafx.h" +#endif + +#include "nsIDOMWindow.h" +#include "BrowserImpl.h" + +#include "QaUtils.h" + +CBrowserImpl::CBrowserImpl() +{ + NS_INIT_ISUPPORTS(); + + m_pBrowserFrameGlue = NULL; + mWebBrowser = nsnull; +} + + +CBrowserImpl::~CBrowserImpl() +{ +} + +// It's very important that the creator of this CBrowserImpl object +// Call on this Init() method with proper values after creation +// +NS_METHOD CBrowserImpl::Init(PBROWSERFRAMEGLUE pBrowserFrameGlue, + nsIWebBrowser* aWebBrowser) +{ + m_pBrowserFrameGlue = pBrowserFrameGlue; + + SetWebBrowser(aWebBrowser); + + return NS_OK; +} + +//***************************************************************************** +// CBrowserImpl::nsISupports +//***************************************************************************** + +NS_IMPL_ADDREF(CBrowserImpl) +NS_IMPL_RELEASE(CBrowserImpl) + +NS_INTERFACE_MAP_BEGIN(CBrowserImpl) + NS_INTERFACE_MAP_ENTRY_AMBIGUOUS(nsISupports, nsIWebBrowserChrome) + NS_INTERFACE_MAP_ENTRY(nsIInterfaceRequestor) + NS_INTERFACE_MAP_ENTRY(nsIWebBrowserChrome) + NS_INTERFACE_MAP_ENTRY(nsIWebBrowserChromeFocus) + NS_INTERFACE_MAP_ENTRY(nsIEmbeddingSiteWindow) + NS_INTERFACE_MAP_ENTRY(nsIWebProgressListener) + NS_INTERFACE_MAP_ENTRY(nsIContextMenuListener) + NS_INTERFACE_MAP_ENTRY(nsISupportsWeakReference) + NS_INTERFACE_MAP_ENTRY(nsISHistoryListener) // de: added 5/11 +NS_INTERFACE_MAP_END + +//***************************************************************************** +// CBrowserImpl::nsIInterfaceRequestor +//***************************************************************************** + +NS_IMETHODIMP CBrowserImpl::GetInterface(const nsIID &aIID, void** aInstancePtr) +{ + if(aIID.Equals(NS_GET_IID(nsIDOMWindow))) + { + if (mWebBrowser) + return mWebBrowser->GetContentDOMWindow((nsIDOMWindow **) aInstancePtr); + return NS_ERROR_NOT_INITIALIZED; + } + + return QueryInterface(aIID, aInstancePtr); +} + +//***************************************************************************** +// CBrowserImpl::nsIWebBrowserChrome +//***************************************************************************** + +//Gets called when you mouseover links etc. in a web page +// +NS_IMETHODIMP CBrowserImpl::SetStatus(PRUint32 aType, const PRUnichar* aStatus) +{ + if(! m_pBrowserFrameGlue) + return NS_ERROR_FAILURE; + + m_pBrowserFrameGlue->UpdateStatusBarText(aStatus); + + return NS_OK; +} + +NS_IMETHODIMP CBrowserImpl::GetWebBrowser(nsIWebBrowser** aWebBrowser) +{ + NS_ENSURE_ARG_POINTER(aWebBrowser); + + *aWebBrowser = mWebBrowser; + + NS_IF_ADDREF(*aWebBrowser); + + return NS_OK; +} + +// Currently called from Init(). I'm not sure who else +// calls this +// +NS_IMETHODIMP CBrowserImpl::SetWebBrowser(nsIWebBrowser* aWebBrowser) +{ + NS_ENSURE_ARG_POINTER(aWebBrowser); + + mWebBrowser = aWebBrowser; + + return NS_OK; +} + +NS_IMETHODIMP CBrowserImpl::GetChromeFlags(PRUint32* aChromeMask) +{ + return NS_ERROR_NOT_IMPLEMENTED; +} + +NS_IMETHODIMP CBrowserImpl::SetChromeFlags(PRUint32 aChromeMask) +{ + return NS_ERROR_NOT_IMPLEMENTED; +} + +// Gets called in response to create a new browser window. +// Ex: In response to a JavaScript Window.Open() call +// +// +NS_IMETHODIMP CBrowserImpl::CreateBrowserWindow(PRUint32 chromeMask, PRInt32 aX, PRInt32 aY, PRInt32 aCX, PRInt32 aCY, nsIWebBrowser **aWebBrowser) +{ + if(! m_pBrowserFrameGlue) + return NS_ERROR_FAILURE; + + if(m_pBrowserFrameGlue->CreateNewBrowserFrame(chromeMask, + aX, aY, aCX, aCY, aWebBrowser)) + return NS_OK; + else + return NS_ERROR_FAILURE; +} + +// Will get called in response to JavaScript window.close() +// +NS_IMETHODIMP CBrowserImpl::DestroyBrowserWindow() +{ + if(! m_pBrowserFrameGlue) + return NS_ERROR_FAILURE; + + m_pBrowserFrameGlue->DestroyBrowserFrame(); + + return NS_OK; +} + +// Gets called in response to set the size of a window +// Ex: In response to a JavaScript Window.Open() call of +// the form +// +// window.open("http://www.mozilla.org", "theWin", "width=200, height=400"); +// +// First the CreateBrowserWindow() call will be made followed by a +// call to this method to resize the window +// +NS_IMETHODIMP CBrowserImpl::SizeBrowserTo(PRInt32 aCX, PRInt32 aCY) +{ + if(! m_pBrowserFrameGlue) + return NS_ERROR_FAILURE; + + m_pBrowserFrameGlue->SetBrowserFrameSize(aCX, aCY); + + return NS_OK; +} + +NS_IMETHODIMP CBrowserImpl::ShowAsModal(void) +{ + return NS_ERROR_NOT_IMPLEMENTED; +} + +NS_IMETHODIMP CBrowserImpl::IsWindowModal(PRBool *retval) +{ + // We're not modal + *retval = PR_FALSE; + + return NS_OK; +} + +NS_IMETHODIMP CBrowserImpl::ExitModalEventLoop(nsresult aStatus) +{ + return NS_OK; +} + +//***************************************************************************** +// CBrowserImpl::nsIWebBrowserChromeFocus +//***************************************************************************** + +NS_IMETHODIMP CBrowserImpl::FocusNextElement() +{ + return NS_ERROR_NOT_IMPLEMENTED; +} + +NS_IMETHODIMP CBrowserImpl::FocusPrevElement() +{ + return NS_ERROR_NOT_IMPLEMENTED; +} + +//***************************************************************************** +// CBrowserImpl::nsIEmbeddingSiteWindow +//***************************************************************************** + +NS_IMETHODIMP CBrowserImpl::SetDimensions(PRUint32 aFlags, PRInt32 x, PRInt32 y, PRInt32 cx, PRInt32 cy) +{ + if(! m_pBrowserFrameGlue) + return NS_ERROR_FAILURE; + + if (aFlags & nsIEmbeddingSiteWindow::DIM_FLAGS_POSITION && + (aFlags & nsIEmbeddingSiteWindow::DIM_FLAGS_SIZE_INNER || + aFlags & nsIEmbeddingSiteWindow::DIM_FLAGS_SIZE_OUTER)) + { + m_pBrowserFrameGlue->SetBrowserFramePositionAndSize(x, y, cx, cy, PR_TRUE); + } + else + { + if (aFlags & nsIEmbeddingSiteWindow::DIM_FLAGS_POSITION) + { + m_pBrowserFrameGlue->SetBrowserFramePosition(x, y); + } + if (aFlags & nsIEmbeddingSiteWindow::DIM_FLAGS_SIZE_INNER || + aFlags & nsIEmbeddingSiteWindow::DIM_FLAGS_SIZE_OUTER) + { + m_pBrowserFrameGlue->SetBrowserFrameSize(cx, cy); + } + } + + return NS_OK; +} + +NS_IMETHODIMP CBrowserImpl::GetDimensions(PRUint32 aFlags, PRInt32 *x, PRInt32 *y, PRInt32 *cx, PRInt32 *cy) +{ + if(! m_pBrowserFrameGlue) + return NS_ERROR_FAILURE; + + if (aFlags & nsIEmbeddingSiteWindow::DIM_FLAGS_POSITION) + { + m_pBrowserFrameGlue->GetBrowserFramePosition(x, y); + } + if (aFlags & nsIEmbeddingSiteWindow::DIM_FLAGS_SIZE_INNER || + aFlags & nsIEmbeddingSiteWindow::DIM_FLAGS_SIZE_OUTER) + { + m_pBrowserFrameGlue->GetBrowserFrameSize(cx, cy); + } + + return NS_OK; +} + +NS_IMETHODIMP CBrowserImpl::GetSiteWindow(void** aSiteWindow) +{ + if (!aSiteWindow) + return NS_ERROR_NULL_POINTER; + + *aSiteWindow = 0; + if (m_pBrowserFrameGlue) { + HWND w = m_pBrowserFrameGlue->GetBrowserFrameNativeWnd(); + *aSiteWindow = NS_REINTERPRET_CAST(void *, w); + } + return NS_OK; +} + +NS_IMETHODIMP CBrowserImpl::SetFocus() +{ + if(! m_pBrowserFrameGlue) + return NS_ERROR_FAILURE; + + m_pBrowserFrameGlue->SetFocus(); + + return NS_OK; +} + +NS_IMETHODIMP CBrowserImpl::GetTitle(PRUnichar** aTitle) +{ + if(! m_pBrowserFrameGlue) + return NS_ERROR_FAILURE; + + m_pBrowserFrameGlue->GetBrowserFrameTitle(aTitle); + + return NS_OK; +} + +NS_IMETHODIMP CBrowserImpl::SetTitle(const PRUnichar* aTitle) +{ + if(! m_pBrowserFrameGlue) + return NS_ERROR_FAILURE; + + m_pBrowserFrameGlue->SetBrowserFrameTitle(aTitle); + + return NS_OK; +} + +NS_IMETHODIMP CBrowserImpl::GetVisibility(PRBool *aVisibility) +{ + if(! m_pBrowserFrameGlue) + return NS_ERROR_FAILURE; + + m_pBrowserFrameGlue->GetBrowserFrameVisibility(aVisibility); + + return NS_OK; +} + +NS_IMETHODIMP CBrowserImpl::SetVisibility(PRBool aVisibility) +{ + if(! m_pBrowserFrameGlue) + return NS_ERROR_FAILURE; + + m_pBrowserFrameGlue->ShowBrowserFrame(aVisibility); + + return NS_OK; +} + diff --git a/mozilla/embedding/qa/testembed/BrowserImpl.h b/mozilla/embedding/qa/testembed/BrowserImpl.h new file mode 100644 index 00000000000..f433947c905 --- /dev/null +++ b/mozilla/embedding/qa/testembed/BrowserImpl.h @@ -0,0 +1,63 @@ +/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- + * + * The contents of this file are subject to the Netscape Public + * License Version 1.1 (the "License"); you may not use this file + * except in compliance with the License. You may obtain a copy of + * the License at http://www.mozilla.org/NPL/ + * + * Software distributed under the License is distributed on an "AS + * IS" basis, WITHOUT WARRANTY OF ANY KIND, either express or + * implied. See the License for the specific language governing + * rights and limitations under the License. + * + * The Original Code is mozilla.org code. + * + * The Initial Developer of the Original Code is Netscape + * Communications Corporation. Portions created by Netscape are + * Copyright (C) 1998 Netscape Communications Corporation. All + * Rights Reserved. + * + * Contributor(s): + * Chak Nanga + */ + +#ifndef _BROWSERIMPL_H +#define _BROWSERIMPL_H + +#include "IBrowserFrameGlue.h" +#include "nsIWebBrowserChromeFocus.h" + +class CBrowserImpl : public nsIInterfaceRequestor, + public nsIWebBrowserChrome, + public nsIWebBrowserChromeFocus, + public nsIEmbeddingSiteWindow, + public nsIWebProgressListener, + public nsIContextMenuListener, + public nsSupportsWeakReference, + public nsISHistoryListener + // de: added this in 5/11 +{ +public: + CBrowserImpl(); + ~CBrowserImpl(); + NS_METHOD Init(PBROWSERFRAMEGLUE pBrowserFrameGlue, + nsIWebBrowser* aWebBrowser); +// de: macros that declare methods for the ifaces implemented + // (instead of .h declarations) + NS_DECL_ISUPPORTS + NS_DECL_NSIINTERFACEREQUESTOR + NS_DECL_NSIWEBBROWSERCHROME + NS_DECL_NSIWEBBROWSERCHROMEFOCUS + NS_DECL_NSIEMBEDDINGSITEWINDOW + NS_DECL_NSIWEBPROGRESSLISTENER + NS_DECL_NSICONTEXTMENULISTENER + NS_DECL_NSISHISTORYLISTENER // de: added this in 5/11 + +protected: + + PBROWSERFRAMEGLUE m_pBrowserFrameGlue; + + nsCOMPtr mWebBrowser; +}; + +#endif //_BROWSERIMPL_H diff --git a/mozilla/embedding/qa/testembed/BrowserImplCtxMenuLstnr.cpp b/mozilla/embedding/qa/testembed/BrowserImplCtxMenuLstnr.cpp new file mode 100644 index 00000000000..2c2b334cff5 --- /dev/null +++ b/mozilla/embedding/qa/testembed/BrowserImplCtxMenuLstnr.cpp @@ -0,0 +1,40 @@ +/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- + * + * The contents of this file are subject to the Netscape Public + * License Version 1.1 (the "License"); you may not use this file + * except in compliance with the License. You may obtain a copy of + * the License at http://www.mozilla.org/NPL/ + * + * Software distributed under the License is distributed on an "AS + * IS" basis, WITHOUT WARRANTY OF ANY KIND, either express or + * implied. See the License for the specific language governing + * rights and limitations under the License. + * + * The Original Code is mozilla.org code. + * + * The Initial Developer of the Original Code is Netscape + * Communications Corporation. Portions created by Netscape are + * Copyright (C) 1998 Netscape Communications Corporation. All + * Rights Reserved. + * + * Contributor(s): + * Chak Nanga + */ + +#ifdef _WINDOWS + #include "stdafx.h" +#endif +#include "BrowserImpl.h" +#include "IBrowserFrameGlue.h" + +//***************************************************************************** +// CBrowserImpl::nsIContextMenuListener +//***************************************************************************** + +NS_IMETHODIMP CBrowserImpl::OnShowContextMenu(PRUint32 aContextFlags, nsIDOMEvent *aEvent, nsIDOMNode *aNode) +{ + if(m_pBrowserFrameGlue) + m_pBrowserFrameGlue->ShowContextMenu(aContextFlags, aNode); + + return NS_OK; +} \ No newline at end of file diff --git a/mozilla/embedding/qa/testembed/BrowserImplHistoryLstnr.cpp b/mozilla/embedding/qa/testembed/BrowserImplHistoryLstnr.cpp new file mode 100644 index 00000000000..c280519731e --- /dev/null +++ b/mozilla/embedding/qa/testembed/BrowserImplHistoryLstnr.cpp @@ -0,0 +1,98 @@ +/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- + * + * The contents of this file are subject to the Netscape Public + * License Version 1.1 (the "License"); you may not use this file + * except in compliance with the License. You may obtain a copy of + * the License at http://www.mozilla.org/NPL/ + * + * Software distributed under the License is distributed on an "AS + * IS" basis, WITHOUT WARRANTY OF ANY KIND, either express or + * implied. See the License for the specific language governing + * rights and limitations under the License. + * + * The Original Code is mozilla.org code. + * + * The Initial Developer of the Original Code is Netscape + * Communications Corporation. Portions created by Netscape are + * Copyright (C) 1998 Netscape Communications Corporation. All + * Rights Reserved. + * + * Contributor(s): + * David Epstein + * + */ + +#ifdef _WINDOWS + #include "stdafx.h" +#endif +#include "BrowserImpl.h" +#include "IBrowserFrameGlue.h" + +#include "TestEmbed.h" +#include "BrowserView.h" +#include "BrowserFrm.h" + +#include "QaUtils.h" + +//***************************************************************************** +// CBrowserImpl::nsIHistoryListener Implementation +//***************************************************************************** +// +// - Implements browser history listener methods. Activated through various events +// (i.e. forward, back, reload) +// +// - Calls methods via the IBrowserFrameGlue interace +// (available thru' the m_pBrowserFrameGlue member var) +// to do the actual statusbar/progress bar updates. +// + +class CBrowserView; + + +//***************************************************************************** +// CBrowserImpl::nsISHistoryListener methods +//***************************************************************************** + +NS_IMETHODIMP CBrowserImpl::OnHistoryNewEntry(nsIURI *theURI) +{ + CQaUtils::QAOutput("nsIHistoryListener::OnHistoryNewEntry()", 2); + + return NS_OK; +} + + +NS_IMETHODIMP CBrowserImpl::OnHistoryGoBack(nsIURI *theURI, PRBool *notify) +{ + CQaUtils::QAOutput("nsIHistoryListener::OnHistoryGoBack()", 2); + + return NS_OK; +} + +NS_IMETHODIMP CBrowserImpl::OnHistoryGoForward(nsIURI *theURI, PRBool *notify) +{ + CQaUtils::QAOutput("nsIHistoryListener::OnHistoryGoForward()", 2); + + return NS_OK; +} + +NS_IMETHODIMP CBrowserImpl::OnHistoryReload(nsIURI *theURI, PRUint32 reloadFlags, PRBool *notify) +{ + CQaUtils::QAOutput("nsIHistoryListener::OnHistoryReload()", 2); + + return NS_OK; +} + +NS_IMETHODIMP CBrowserImpl::OnHistoryGotoIndex(PRInt32 theIndex, nsIURI *theURI, PRBool *notify) +{ + CQaUtils::QAOutput("nsIHistoryListener::OnHistoryGotoIndex()", 2); + + return NS_OK; +} + +NS_IMETHODIMP CBrowserImpl::OnHistoryPurge(PRInt32 theNumEntries, PRBool *notify) +{ + CQaUtils::QAOutput("nsIHistoryListener::OnHistoryPurge()", 2); + + return NS_OK; +} + diff --git a/mozilla/embedding/qa/testembed/BrowserImplPrompt.cpp b/mozilla/embedding/qa/testembed/BrowserImplPrompt.cpp new file mode 100644 index 00000000000..cd5b010c4cb --- /dev/null +++ b/mozilla/embedding/qa/testembed/BrowserImplPrompt.cpp @@ -0,0 +1,150 @@ +/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- + * + * The contents of this file are subject to the Netscape Public + * License Version 1.1 (the "License"); you may not use this file + * except in compliance with the License. You may obtain a copy of + * the License at http://www.mozilla.org/NPL/ + * + * Software distributed under the License is distributed on an "AS + * IS" basis, WITHOUT WARRANTY OF ANY KIND, either express or + * implied. See the License for the specific language governing + * rights and limitations under the License. + * + * The Original Code is mozilla.org code. + * + * The Initial Developer of the Original Code is Netscape + * Communications Corporation. Portions created by Netscape are + * Copyright (C) 1998 Netscape Communications Corporation. All + * Rights Reserved. + * + * Contributor(s): + * Chak Nanga + */ + +// File overview..... +// +// The nsIPrompt interface is mainly used to convey/get information +// from a user via Alerts, Prompts etc. +// + +#ifdef _WINDOWS + #include "stdafx.h" +#endif +#include "BrowserImpl.h" +#include "IBrowserFrameGlue.h" + +//***************************************************************************** +// CBrowserImpl::nsIPrompt Implementation +//***************************************************************************** + + +// Needed for JavaScript and other cases where a msg needs to be +// shown to the user. For ex, when a page has some JS such as +// "Alert("Hello")" this method will be invoked +NS_IMETHODIMP +CBrowserImpl::Alert(const PRUnichar *dialogTitle, const PRUnichar *text) +{ + if(! m_pBrowserFrameGlue) + return NS_ERROR_FAILURE; + + m_pBrowserFrameGlue->Alert(dialogTitle, text); + + return NS_OK; +} + +// Invoked in the case of a JS confirm() method invocation +NS_IMETHODIMP +CBrowserImpl::Confirm(const PRUnichar *dialogTitle, + const PRUnichar *text, PRBool *retval) +{ + if(! m_pBrowserFrameGlue) + return NS_ERROR_FAILURE; + + m_pBrowserFrameGlue->Confirm(dialogTitle, text, retval); + + return NS_OK; +} + +NS_IMETHODIMP +CBrowserImpl::Prompt(const PRUnichar *dialogTitle, const PRUnichar *text, + PRUnichar **promptText, + const PRUnichar *checkMsg, PRBool *checkValue, + PRBool *_retval) +{ + if(! m_pBrowserFrameGlue) + return NS_ERROR_FAILURE; + + m_pBrowserFrameGlue->Prompt(dialogTitle, text, promptText, checkMsg, checkValue, _retval); + + return NS_OK; +} + +NS_IMETHODIMP +CBrowserImpl::PromptPassword(const PRUnichar *dialogTitle, const PRUnichar *text, + PRUnichar **password, + const PRUnichar *checkMsg, PRBool *checkValue, + PRBool *_retval) +{ + if(! m_pBrowserFrameGlue) + return NS_ERROR_FAILURE; + + m_pBrowserFrameGlue->PromptPassword(dialogTitle, text, password, + checkMsg, checkValue, _retval); + + return NS_OK; +} + +NS_IMETHODIMP +CBrowserImpl::PromptUsernameAndPassword(const PRUnichar *dialogTitle, const PRUnichar *text, + PRUnichar **username, PRUnichar **password, + const PRUnichar *checkMsg, PRBool *checkValue, + PRBool *_retval) +{ + if(! m_pBrowserFrameGlue) + return NS_ERROR_FAILURE; + + m_pBrowserFrameGlue->PromptUserNamePassword(dialogTitle, text, + username, password, + checkMsg, checkValue, + _retval); + + return NS_OK; +} + +NS_IMETHODIMP +CBrowserImpl::AlertCheck(const PRUnichar *dialogTitle, + const PRUnichar *text, + const PRUnichar *checkMsg, + PRBool *checkValue) +{ + return NS_ERROR_NOT_IMPLEMENTED; +} + +NS_IMETHODIMP +CBrowserImpl::ConfirmCheck(const PRUnichar *dialogTitle, + const PRUnichar *text, + const PRUnichar *checkMsg, + PRBool *checkValue, PRBool *retval) +{ + return NS_ERROR_NOT_IMPLEMENTED; +} + +NS_IMETHODIMP +CBrowserImpl::ConfirmEx(const PRUnichar *dialogTitle, const PRUnichar *text, + PRUint32 buttonFlags, const PRUnichar *button0Title, + const PRUnichar *button1Title, const PRUnichar *button2Title, + const PRUnichar *checkMsg, PRBool *checkValue, + PRInt32 *buttonPressed) +{ + return NS_ERROR_NOT_IMPLEMENTED; +} + +NS_IMETHODIMP +CBrowserImpl::Select(const PRUnichar *dialogTitle, + const PRUnichar *text, PRUint32 count, + const PRUnichar **selectList, + PRInt32 *outSelection, PRBool *retval) +{ + return NS_ERROR_NOT_IMPLEMENTED; +} + diff --git a/mozilla/embedding/qa/testembed/BrowserImplWebPrgrsLstnr.cpp b/mozilla/embedding/qa/testembed/BrowserImplWebPrgrsLstnr.cpp new file mode 100644 index 00000000000..fe766108af1 --- /dev/null +++ b/mozilla/embedding/qa/testembed/BrowserImplWebPrgrsLstnr.cpp @@ -0,0 +1,285 @@ +/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- + * + * The contents of this file are subject to the Netscape Public + * License Version 1.1 (the "License"); you may not use this file + * except in compliance with the License. You may obtain a copy of + * the License at http://www.mozilla.org/NPL/ + * + * Software distributed under the License is distributed on an "AS + * IS" basis, WITHOUT WARRANTY OF ANY KIND, either express or + * implied. See the License for the specific language governing + * rights and limitations under the License. + * + * The Original Code is mozilla.org code. + * + * The Initial Developer of the Original Code is Netscape + * Communications Corporation. Portions created by Netscape are + * Copyright (C) 1998 Netscape Communications Corporation. All + * Rights Reserved. + * + * Contributor(s): + * Chak Nanga + * David Epstein + */ + +#ifdef _WINDOWS + #include "stdafx.h" +#endif +#include "BrowserImpl.h" +#include "IBrowserFrameGlue.h" + +#include "TestEmbed.h" +#include "BrowserView.h" +#include "BrowserFrm.h" + +#include "QaUtils.h" + +//***************************************************************************** +// CBrowserImpl::nsIWebProgressListener Implementation +//***************************************************************************** +// +// - Implements browser progress update functionality +// while loading a page into the embedded browser +// +// - Calls methods via the IBrowserFrameGlue interace +// (available thru' the m_pBrowserFrameGlue member var) +// to do the actual statusbar/progress bar updates. +// + +class CBrowserView; + +NS_IMETHODIMP CBrowserImpl::OnProgressChange(nsIWebProgress *progress, nsIRequest *request, + PRInt32 curSelfProgress, PRInt32 maxSelfProgress, + PRInt32 curTotalProgress, PRInt32 maxTotalProgress) +{ + + nsCString stringMsg; + + if(! m_pBrowserFrameGlue) + return NS_ERROR_FAILURE; + + CQaUtils::QAOutput("Entering nsIWebProgLstnr::OnProgressChange()."); + + PRInt32 nProgress = curTotalProgress; + PRInt32 nProgressMax = maxTotalProgress; + + CQaUtils::RequestName(request, stringMsg); + + if (nProgressMax == 0) + nProgressMax = LONG_MAX; + + if (curSelfProgress > maxSelfProgress) + CQaUtils::QAOutput("nsIWebProgLstnr::OnProgressChange(): Self progress complete!", 1); + + if (nProgress > nProgressMax) + { + nProgress = nProgressMax; // Progress complete + CQaUtils::QAOutput("nsIWebProgLstnr::OnProgressChange(): Progress Update complete!", 1); + } + + m_pBrowserFrameGlue->UpdateProgress(nProgress, nProgressMax); + + CQaUtils::QAOutput("Exiting nsIWebProgLstnr::OnProgressChange().\r\n"); + + return NS_OK; +} + +NS_IMETHODIMP CBrowserImpl::OnStateChange(nsIWebProgress *progress, nsIRequest *request, + PRInt32 progressStateFlags, PRUint32 status) +{ + char theDocType[100]; + char theStateType[100]; + char theTotalString[1000]; + int displayMode = 1; + nsCString stringMsg; + nsCString totalMsg; + + if(! m_pBrowserFrameGlue) + return NS_ERROR_FAILURE; + + CQaUtils::QAOutput("Entering nsIWebProgLstnr::OnStateChange()."); + + CQaUtils::RequestName(request, stringMsg); + + if (progressStateFlags & STATE_IS_DOCUMENT) // DOCUMENT + { + strcpy(theDocType, "DOCUMENT"); + if (progressStateFlags & STATE_START) + { + // Navigation has begun + strcpy(theStateType, "STATE_START"); + displayMode = 2; + + if(m_pBrowserFrameGlue) + m_pBrowserFrameGlue->UpdateBusyState(PR_TRUE); + } + + else if (progressStateFlags & STATE_REDIRECTING) + strcpy(theStateType, "STATE_REDIRECTING"); + + else if (progressStateFlags & STATE_TRANSFERRING) + strcpy(theStateType, "STATE_TRANSFERRING"); + + else if (progressStateFlags & STATE_NEGOTIATING) + strcpy(theStateType, "STATE_NEGOTIATING"); + + else if (progressStateFlags & STATE_STOP) + { + // We've completed the navigation + + strcpy(theStateType, "STATE_STOP"); + displayMode = 2; + + m_pBrowserFrameGlue->UpdateBusyState(PR_FALSE); + m_pBrowserFrameGlue->UpdateProgress(0, 100); // Clear the prog bar + m_pBrowserFrameGlue->UpdateStatusBarText(nsnull); // Clear the status bar + } + } // end STATE_IS_DOCUMENT + if (progressStateFlags & STATE_IS_REQUEST) // REQUEST + { + strcpy(theDocType, "REQUEST"); + if (progressStateFlags & STATE_START) + strcpy(theStateType, "STATE_START"); + else if (progressStateFlags & STATE_REDIRECTING) + strcpy(theStateType, "STATE_REDIRECTING"); + + else if (progressStateFlags & STATE_TRANSFERRING) + strcpy(theStateType, "STATE_TRANSFERRING"); + + else if (progressStateFlags & STATE_NEGOTIATING) + strcpy(theStateType, "STATE_NEGOTIATING"); + + else if (progressStateFlags & STATE_STOP) + strcpy(theStateType, "STATE_STOP"); + } + + if (progressStateFlags & STATE_IS_NETWORK) // NETWORK + { + strcpy(theDocType, "NETWORK"); + if (progressStateFlags & STATE_START) + strcpy(theStateType, "STATE_START"); + else if (progressStateFlags & STATE_REDIRECTING) + strcpy(theStateType, "STATE_REDIRECTING"); + + else if (progressStateFlags & STATE_TRANSFERRING) + strcpy(theStateType, "STATE_TRANSFERRING"); + + else if (progressStateFlags & STATE_NEGOTIATING) + strcpy(theStateType, "STATE_NEGOTIATING"); + + else if (progressStateFlags & STATE_STOP) + strcpy(theStateType, "STATE_STOP"); + } + if (progressStateFlags & STATE_IS_WINDOW) // WINDOW + { + strcpy(theDocType, "WINDOW"); + if (progressStateFlags & STATE_START) + strcpy(theStateType, "STATE_START"); + else if (progressStateFlags & STATE_REDIRECTING) + strcpy(theStateType, "STATE_REDIRECTING"); + + else if (progressStateFlags & STATE_TRANSFERRING) + strcpy(theStateType, "STATE_TRANSFERRING"); + + else if (progressStateFlags & STATE_NEGOTIATING) + strcpy(theStateType, "STATE_NEGOTIATING"); + + else if (progressStateFlags & STATE_STOP) + strcpy(theStateType, "STATE_STOP"); + } + + totalMsg = "OnStateChange(): "; + totalMsg += theStateType; + totalMsg += ", "; + totalMsg += theDocType; + totalMsg += ", "; + totalMsg += stringMsg; + + CQaUtils::QAOutput(totalMsg.get(), displayMode); + CQaUtils::QAOutput("Exiting nsIWebProgLstnr::OnStateChange().\r\n"); + + return NS_OK; +} + + +NS_IMETHODIMP CBrowserImpl::OnLocationChange(nsIWebProgress* aWebProgress, + nsIRequest* aRequest, + nsIURI *location) +{ + nsCString stringMsg; + + if(! m_pBrowserFrameGlue) + return NS_ERROR_FAILURE; + + CQaUtils::QAOutput("Entering nsIWebProgLstnr::OnLocationChange()."); + + nsresult rv; + char *uriSpec; + rv = location->GetSpec(&uriSpec); + if (NS_FAILED(rv)) + CQaUtils::QAOutput("Bad result for GetSpec()."); + else + CQaUtils::QAOutput("Good result for GetSpec()."); + + CQaUtils::FormatAndPrintOutput("The location url = ", uriSpec, 1); + +// CQaUtils::RequestName(aRequest, stringMsg); + + PRBool isSubFrameLoad = PR_FALSE; // Is this a subframe load + if (aWebProgress) { + nsCOMPtr domWindow; + nsCOMPtr topDomWindow; + aWebProgress->GetDOMWindow(getter_AddRefs(domWindow)); + if (domWindow) { // Get root domWindow + domWindow->GetTop(getter_AddRefs(topDomWindow)); + } + if (domWindow != topDomWindow) + isSubFrameLoad = PR_TRUE; + } + + if (!isSubFrameLoad) // Update urlbar only if it is not a subframe load + m_pBrowserFrameGlue->UpdateCurrentURI(location); + + CQaUtils::QAOutput("Exiting nsIWebProgLstnr::OnLocationChange().\r\n"); + return NS_OK; +} + +NS_IMETHODIMP +CBrowserImpl::OnStatusChange(nsIWebProgress* aWebProgress, + nsIRequest* aRequest, + nsresult aStatus, + const PRUnichar* aMessage) +{ + nsCString stringMsg; + + if(! m_pBrowserFrameGlue) + return NS_ERROR_FAILURE; + + CQaUtils::QAOutput("Entering nsIWebProgLstnr::OnStatusChange()."); + + + CQaUtils::RequestName(aRequest, stringMsg); + + m_pBrowserFrameGlue->UpdateStatusBarText(aMessage); + + CQaUtils::QAOutput("Exiting nsIWebProgLstnr::OnStatusChange().\r\n"); + + return NS_OK; +} + + +NS_IMETHODIMP +CBrowserImpl::OnSecurityChange(nsIWebProgress *aWebProgress, + nsIRequest *aRequest, + PRInt32 state) +{ + nsCString stringMsg; + + CQaUtils::QAOutput("Entering nsIWebProgLstnr::OnSecurityChange()."); + + CQaUtils::RequestName(aRequest, stringMsg); + + CQaUtils::QAOutput("Exiting nsIWebProgLstnr::OnSecurityChange().\r\n"); + + return NS_OK; +} diff --git a/mozilla/embedding/qa/testembed/BrowserView.cpp b/mozilla/embedding/qa/testembed/BrowserView.cpp new file mode 100644 index 00000000000..5ad8cfb78cb --- /dev/null +++ b/mozilla/embedding/qa/testembed/BrowserView.cpp @@ -0,0 +1,1035 @@ +/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- + * + * The contents of this file are subject to the Netscape Public + * License Version 1.1 (the "License"); you may not use this file + * except in compliance with the License. You may obtain a copy of + * the License at http://www.mozilla.org/NPL/ + * + * Software distributed under the License is distributed on an "AS + * IS" basis, WITHOUT WARRANTY OF ANY KIND, either express or + * implied. See the License for the specific language governing + * rights and limitations under the License. + * + * The Original Code is mozilla.org code. + * + * The Initial Developer of the Original Code is Netscape + * Communications Corporation. Portions created by Netscape are + * Copyright (C) 1998 Netscape Communications Corporation. All + * Rights Reserved. + * + * Contributor(s): + * Chak Nanga + */ + +// File Overview.... +// +// When the CBrowserFrm creates this View: +// - CreateBrowser() is called in OnCreate() to create the +// mozilla embeddable browser +// +// OnSize() method handles the window resizes and calls the approriate +// interface method to resize the embedded browser properly +// +// Command handlers to handle browser navigation - OnNavBack(), +// OnNavForward() etc +// +// DestroyBrowser() called for cleaning up during object destruction +// +// Some important coding notes.... +// +// 1. Make sure we do not have the CS_HREDRAW|CS_VREDRAW in the call +// to AfxRegisterWndClass() inside of PreCreateWindow() below +// If these flags are present then you'll see screen flicker when +// you resize the frame window +// +// Next suggested file to look at : BrowserImpl.cpp +// + +#include "stdafx.h" +#include "TestEmbed.h" +#include "BrowserView.h" +#include "BrowserImpl.h" +#include "BrowserFrm.h" +#include "Dialogs.h" +#include "ProfileMgr.h" +#include "ProfilesDlg.h" +#include "UrlDialog.h" +#include "Tests.h" +#include "QaUtils.h" + +// Print Includes +#include "PrintProgressDialog.h" + + +#ifdef _DEBUG +#define new DEBUG_NEW +#undef THIS_FILE +static char THIS_FILE[] = __FILE__; +#endif + +// Register message for FindDialog communication +static UINT WM_FINDMSG = ::RegisterWindowMessage(FINDMSGSTRING); + +BEGIN_MESSAGE_MAP(CBrowserView, CWnd) + //{{AFX_MSG_MAP(CBrowserView) + ON_WM_CREATE() + ON_WM_DESTROY() + ON_WM_SIZE() + ON_CBN_SELENDOK(ID_URL_BAR, OnUrlSelectedInUrlBar) + ON_COMMAND(IDOK, OnNewUrlEnteredInUrlBar) + ON_COMMAND(ID_FILE_OPEN, OnFileOpen) + ON_COMMAND(ID_FILE_SAVE_AS, OnFileSaveAs) + ON_COMMAND(ID_VIEW_SOURCE, OnViewSource) + ON_COMMAND(ID_VIEW_INFO, OnViewInfo) + ON_COMMAND(ID_NAV_BACK, OnNavBack) + ON_COMMAND(ID_NAV_FORWARD, OnNavForward) + ON_COMMAND(ID_NAV_HOME, OnNavHome) + ON_COMMAND(ID_NAV_RELOAD, OnNavReload) + ON_COMMAND(ID_NAV_STOP, OnNavStop) + ON_COMMAND(ID_EDIT_CUT, OnCut) + ON_COMMAND(ID_EDIT_COPY, OnCopy) + ON_COMMAND(ID_EDIT_PASTE, OnPaste) + ON_COMMAND(ID_EDIT_UNDO, OnUndoUrlBarEditOp) + ON_COMMAND(ID_EDIT_SELECT_ALL, OnSelectAll) + ON_COMMAND(ID_EDIT_SELECT_NONE, OnSelectNone) + ON_COMMAND(ID_COPY_LINK_LOCATION, OnCopyLinkLocation) + ON_COMMAND(ID_OPEN_LINK_IN_NEW_WINDOW, OnOpenLinkInNewWindow) + ON_COMMAND(ID_VIEW_IMAGE, OnViewImageInNewWindow) + ON_COMMAND(ID_SAVE_LINK_AS, OnSaveLinkAs) + ON_COMMAND(ID_SAVE_IMAGE_AS, OnSaveImageAs) + ON_COMMAND(ID_EDIT_FIND, OnShowFindDlg) + ON_COMMAND(ID_FILE_PRINT, OnFilePrint) + ON_UPDATE_COMMAND_UI(ID_FILE_PRINT, OnUpdateFilePrint) + ON_REGISTERED_MESSAGE(WM_FINDMSG, OnFindMsg) + + // Menu/Toolbar UI update handlers + ON_UPDATE_COMMAND_UI(ID_NAV_BACK, OnUpdateNavBack) + ON_UPDATE_COMMAND_UI(ID_NAV_FORWARD, OnUpdateNavForward) + ON_UPDATE_COMMAND_UI(ID_NAV_STOP, OnUpdateNavStop) + ON_UPDATE_COMMAND_UI(ID_EDIT_CUT, OnUpdateCut) + ON_UPDATE_COMMAND_UI(ID_EDIT_COPY, OnUpdateCopy) + ON_UPDATE_COMMAND_UI(ID_EDIT_PASTE, OnUpdatePaste) + + //}}AFX_MSG_MAP +END_MESSAGE_MAP() + + +CBrowserView::CBrowserView() +{ + mWebBrowser = nsnull; + mBaseWindow = nsnull; + mWebNav = nsnull; + + mpBrowserImpl = nsnull; + mpBrowserFrame = nsnull; + mpBrowserFrameGlue = nsnull; + + mbDocumentLoading = PR_FALSE; + + m_pFindDlg = NULL; + m_pPrintProgressDlg = NULL; + + m_bUrlBarClipOp = FALSE; + m_bCurrentlyPrinting = FALSE; + + char *theUrl = "http://www.aol.com/"; +} + +CBrowserView::~CBrowserView() +{ +} + +// This is a good place to create the embeddable browser +// instance +// +int CBrowserView::OnCreate(LPCREATESTRUCT lpCreateStruct) +{ + CreateBrowser(); + + return 0; +} + +void CBrowserView::OnDestroy() +{ + DestroyBrowser(); +} + +// Create an instance of the Mozilla embeddable browser +// +HRESULT CBrowserView::CreateBrowser() +{ + // Create web shell + nsresult rv; + mWebBrowser = do_CreateInstance(NS_WEBBROWSER_CONTRACTID, &rv); + if(NS_FAILED(rv)) + return rv; + + // Save off the nsIWebNavigation interface pointer + // in the mWebNav member variable which we'll use + // later for web page navigation + // + rv = NS_OK; + mWebNav = do_QueryInterface(mWebBrowser, &rv); + if(NS_FAILED(rv)) + return rv; + +// mSessionHistory = do_GetInterface(mWebBrowser, &rv); // de: added 5/11 + + // Create the CBrowserImpl object - this is the object + // which implements the interfaces which are required + // by an app embedding mozilla i.e. these are the interfaces + // thru' which the *embedded* browser communicates with the + // *embedding* app + // + // The CBrowserImpl object will be passed in to the + // SetContainerWindow() call below + // + // Also note that we're passing the BrowserFrameGlue pointer + // and also the mWebBrowser interface pointer via CBrowserImpl::Init() + // of CBrowserImpl object. + // These pointers will be saved by the CBrowserImpl object. + // The CBrowserImpl object uses the BrowserFrameGlue pointer to + // call the methods on that interface to update the status/progress bars + // etc. + mpBrowserImpl = new CBrowserImpl(); + if(mpBrowserImpl == nsnull) + return NS_ERROR_OUT_OF_MEMORY; + + // Pass along the mpBrowserFrameGlue pointer to the BrowserImpl object + // This is the interface thru' which the XP BrowserImpl code communicates + // with the platform specific code to update status bars etc. + mpBrowserImpl->Init(mpBrowserFrameGlue, mWebBrowser); + mpBrowserImpl->AddRef(); + + mWebBrowser->SetContainerWindow(NS_STATIC_CAST(nsIWebBrowserChrome*, mpBrowserImpl)); + + rv = NS_OK; + nsCOMPtr dsti = do_QueryInterface(mWebBrowser, &rv); + if(NS_FAILED(rv)) + return rv; + dsti->SetItemType(nsIDocShellTreeItem::typeContentWrapper); + + // Create the real webbrowser window + + // Note that we're passing the m_hWnd in the call below to InitWindow() + // (CBrowserView inherits the m_hWnd from CWnd) + // This m_hWnd will be used as the parent window by the embeddable browser + // + rv = NS_OK; + mBaseWindow = do_QueryInterface(mWebBrowser, &rv); + if(NS_FAILED(rv)) + return rv; + + // Get the view's ClientRect which to be passed in to the InitWindow() + // call below + RECT rcLocation; + GetClientRect(&rcLocation); + if(IsRectEmpty(&rcLocation)) + { + rcLocation.bottom++; + rcLocation.top++; + } + + rv = mBaseWindow->InitWindow(nsNativeWidget(m_hWnd), nsnull, + 0, 0, rcLocation.right - rcLocation.left, rcLocation.bottom - rcLocation.top); + rv = mBaseWindow->Create(); + + // Register the BrowserImpl object to receive progress messages + // These callbacks will be used to update the status/progress bars + +/* // from WinEmbed.cpp + nsCOMPtr listener(NS_STATIC_CAST(nsIWebProgressListener*, this)); + nsCOMPtr thisListener(dont_AddRef(NS_GetWeakReference(listener))); + (void)mWebBrowser->AddWebBrowserListener(thisListener, + NS_GET_IID(nsIWebProgressListener)); + + // The window has been created. Now register for history notifications + rv = mWebBrowser->AddWebBrowserListener(thisListener, NS_GET_IID(nsISHistoryListener)); +*/ + + // Finally, show the web browser window + mBaseWindow->SetVisibility(PR_TRUE); + + qaTests = new CTests(mWebBrowser, mBaseWindow, mWebNav, mpBrowserImpl); + + return S_OK; +} + +HRESULT CBrowserView::DestroyBrowser() +{ + if(mBaseWindow) + { + mBaseWindow->Destroy(); + mBaseWindow = nsnull; + } + + if(mpBrowserImpl) + { + mpBrowserImpl->Release(); + mpBrowserImpl = nsnull; + } +/* + nsWeakPtr weakling( + dont_AddRef(NS_GetWeakReference(NS_STATIC_CAST(nsIWebProgressListener*, mpBrowserImpl)))); + nsresult rv; + rv = mWebBrowser->RemoveWebBrowserListener(weakling, NS_GET_IID(nsIWebProgressListener)); + if (NS_FAILED(rv)) + { + CQaUtils::QAOutput("Web Progress Listener not removed."); + } + else + { + CQaUtils::QAOutput("Web Progress Listener removed."); + } +*/ + return NS_OK; +} + +BOOL CBrowserView::PreCreateWindow(CREATESTRUCT& cs) +{ + if (!CWnd::PreCreateWindow(cs)) + return FALSE; + + cs.dwExStyle |= WS_EX_CLIENTEDGE; + cs.style &= ~WS_BORDER; + cs.lpszClass = AfxRegisterWndClass(CS_DBLCLKS, + ::LoadCursor(NULL, IDC_ARROW), HBRUSH(COLOR_WINDOW+1), NULL); + + return TRUE; +} + +// Adjust the size of the embedded browser +// in response to any container size changes +// +void CBrowserView::OnSize( UINT nType, int cx, int cy) +{ + mBaseWindow->SetPositionAndSize(0, 0, cx, cy, PR_TRUE); +} + +// Called by this object's creator i.e. the CBrowserFrame object +// to pass it's pointer to us +// +void CBrowserView::SetBrowserFrame(CBrowserFrame* pBrowserFrame) +{ + mpBrowserFrame = pBrowserFrame; +} + +void CBrowserView::SetBrowserFrameGlue(PBROWSERFRAMEGLUE pBrowserFrameGlue) +{ + mpBrowserFrameGlue = pBrowserFrameGlue; +} + +// A new URL was entered in the URL bar +// Get the URL's text from the Urlbar's (ComboBox's) EditControl +// and navigate to that URL +// +void CBrowserView::OnNewUrlEnteredInUrlBar() +{ + // Get the currently entered URL + CString strUrl; + mpBrowserFrame->m_wndUrlBar.GetEnteredURL(strUrl); + + if(IsViewSourceUrl(strUrl)) + OpenViewSourceWindow(strUrl.GetBuffer(0)); + else + // Navigate to that URL + OpenURL(strUrl.GetBuffer(0)); + + // Add what was just entered into the UrlBar + mpBrowserFrame->m_wndUrlBar.AddURLToList(strUrl); +} + +// A URL has been selected from the UrlBar's dropdown list +// +void CBrowserView::OnUrlSelectedInUrlBar() +{ + CString strUrl; + + mpBrowserFrame->m_wndUrlBar.GetSelectedURL(strUrl); + + if(IsViewSourceUrl(strUrl)) + OpenViewSourceWindow(strUrl.GetBuffer(0)); + else + OpenURL(strUrl.GetBuffer(0)); +} + +BOOL CBrowserView::IsViewSourceUrl(CString& strUrl) +{ + return (strUrl.Find("view-source:", 0) != -1) ? TRUE : FALSE; +} + +BOOL CBrowserView::OpenViewSourceWindow(const char* pUrl) +{ + // Create a new browser frame in which we'll show the document source + // Note that we're getting rid of the toolbars etc. by specifying + // the appropriate chromeFlags + PRUint32 chromeFlags = nsIWebBrowserChrome::CHROME_WINDOW_BORDERS | + nsIWebBrowserChrome::CHROME_TITLEBAR | + nsIWebBrowserChrome::CHROME_WINDOW_RESIZE; + CBrowserFrame* pFrm = CreateNewBrowserFrame(chromeFlags); + if(!pFrm) + return FALSE; + + // Finally, load this URI into the newly created frame + pFrm->m_wndBrowserView.OpenURL(pUrl); + + pFrm->BringWindowToTop(); + + return TRUE; +} + +void CBrowserView::OnViewSource() +{ + if(! mWebNav) + return; + + // Get the URI object whose source we want to view. + nsresult rv = NS_OK; + nsCOMPtr currentURI; + rv = mWebNav->GetCurrentURI(getter_AddRefs(currentURI)); + if(NS_FAILED(rv) || !currentURI) + return; + + // Get the uri string associated with the nsIURI object + nsXPIDLCString uriString; + rv = currentURI->GetSpec(getter_Copies(uriString)); + if(NS_FAILED(rv)) + return; + + // Build the view-source: url + nsCAutoString viewSrcUrl; + viewSrcUrl.Append("view-source:"); + viewSrcUrl.Append(uriString); + + OpenViewSourceWindow(viewSrcUrl.get()); +} + +void CBrowserView::OnViewInfo() +{ + AfxMessageBox("To Be Done..."); +} + +void CBrowserView::OnNavBack() +{ + if(mWebNav) + { + mWebNav->GoBack(); + } +} + +void CBrowserView::OnUpdateNavBack(CCmdUI* pCmdUI) +{ + PRBool canGoBack = PR_FALSE; + + if (mWebNav) + mWebNav->GetCanGoBack(&canGoBack); + + pCmdUI->Enable(canGoBack); +} + +void CBrowserView::OnNavForward() +{ + if(mWebNav) + { + mWebNav->GoForward(); + } +} + +void CBrowserView::OnUpdateNavForward(CCmdUI* pCmdUI) +{ + PRBool canGoFwd = PR_FALSE; + + if (mWebNav) + mWebNav->GetCanGoForward(&canGoFwd); + + pCmdUI->Enable(canGoFwd); +} + +void CBrowserView::OnNavHome() +{ + // Get the currently configured HomePage URL + CString strHomeURL; + CTestEmbedApp *pApp = (CTestEmbedApp *)AfxGetApp(); + if(pApp) + pApp->GetHomePage(strHomeURL); + + if(strHomeURL.GetLength() > 0) + OpenURL(strHomeURL); +} + +void CBrowserView::OnNavReload() +{ + if(mWebNav) + mWebNav->Reload(nsIWebNavigation::LOAD_FLAGS_NONE); +} + +void CBrowserView::OnNavStop() +{ + if(mWebNav) + mWebNav->Stop(); +} + +void CBrowserView::OnUpdateNavStop(CCmdUI* pCmdUI) +{ + pCmdUI->Enable(mbDocumentLoading); +} + +void CBrowserView::OnCut() +{ + if(m_bUrlBarClipOp) + { + // We need to operate on the URLBar selection + mpBrowserFrame->CutUrlBarSelToClipboard(); + m_bUrlBarClipOp = FALSE; + } + else + { + nsCOMPtr clipCmds = do_GetInterface(mWebBrowser); + + if(clipCmds) + clipCmds->CutSelection(); + } +} + +void CBrowserView::OnUpdateCut(CCmdUI* pCmdUI) +{ + PRBool canCutSelection = PR_FALSE; + + nsCOMPtr clipCmds = do_GetInterface(mWebBrowser); + if (clipCmds) + clipCmds->CanCutSelection(&canCutSelection); + + if(!canCutSelection) + { + // Check to see if the Cut cmd is to cut the URL + // selection in the UrlBar + if(mpBrowserFrame->CanCutUrlBarSelection()) + { + canCutSelection = TRUE; + m_bUrlBarClipOp = TRUE; + } + } + + pCmdUI->Enable(canCutSelection); +} + +void CBrowserView::OnCopy() +{ + if(m_bUrlBarClipOp) + { + // We need to operate on the URLBar selection + mpBrowserFrame->CopyUrlBarSelToClipboard(); + m_bUrlBarClipOp = FALSE; + } + else + { + // We need to operate on the web page content + nsCOMPtr clipCmds = do_GetInterface(mWebBrowser); + + if(clipCmds) + clipCmds->CopySelection(); + } +} + +void CBrowserView::OnUpdateCopy(CCmdUI* pCmdUI) +{ + PRBool canCopySelection = PR_FALSE; + + nsCOMPtr clipCmds = do_GetInterface(mWebBrowser); + if (clipCmds) + clipCmds->CanCopySelection(&canCopySelection); + + if(!canCopySelection) + { + // Check to see if the Copy cmd is to copy the URL + // selection in the UrlBar + if(mpBrowserFrame->CanCopyUrlBarSelection()) + { + canCopySelection = TRUE; + m_bUrlBarClipOp = TRUE; + } + } + + pCmdUI->Enable(canCopySelection); +} + +void CBrowserView::OnPaste() +{ + if(m_bUrlBarClipOp) + { + mpBrowserFrame->PasteFromClipboardToUrlBar(); + m_bUrlBarClipOp = FALSE; + } + else + { + nsCOMPtr clipCmds = do_GetInterface(mWebBrowser); + + if(clipCmds) + clipCmds->Paste(); + } +} + +void CBrowserView::OnUndoUrlBarEditOp() +{ + if(mpBrowserFrame->CanUndoUrlBarEditOp()) + mpBrowserFrame->UndoUrlBarEditOp(); +} + +void CBrowserView::OnUpdatePaste(CCmdUI* pCmdUI) +{ + PRBool canPaste = PR_FALSE; + + nsCOMPtr clipCmds = do_GetInterface(mWebBrowser); + if (clipCmds) + clipCmds->CanPaste(&canPaste); + + if(!canPaste) + { + if(mpBrowserFrame->CanPasteToUrlBar()) + { + canPaste = TRUE; + m_bUrlBarClipOp = TRUE; + } + } + + pCmdUI->Enable(canPaste); +} + +void CBrowserView::OnSelectAll() +{ + nsCOMPtr clipCmds = do_GetInterface(mWebBrowser); + + if(clipCmds) + clipCmds->SelectAll(); +} + +void CBrowserView::OnSelectNone() +{ + nsCOMPtr clipCmds = do_GetInterface(mWebBrowser); + + if(clipCmds) + clipCmds->SelectNone(); +} + +void CBrowserView::OnFileOpen() +{ + char *lpszFilter = + "HTML Files Only (*.htm;*.html)|*.htm;*.html|" + "All Files (*.*)|*.*||"; + + CFileDialog cf(TRUE, NULL, NULL, OFN_HIDEREADONLY | OFN_OVERWRITEPROMPT, + lpszFilter, this); + if(cf.DoModal() == IDOK) + { + CString strFullPath = cf.GetPathName(); // Will be like: c:\tmp\junk.htm + OpenURL(strFullPath); + } +} + +void CBrowserView::GetBrowserWindowTitle(nsCString& title) +{ + nsXPIDLString idlStrTitle; + if(mBaseWindow) + mBaseWindow->GetTitle(getter_Copies(idlStrTitle)); + + title.AssignWithConversion(idlStrTitle); + + // Sanitize the title of all illegal characters + title.CompressWhitespace(); // Remove whitespace from the ends + title.StripChars("\\*|:\"> persist(do_QueryInterface(mWebBrowser)); + if(persist) + persist->SaveDocument(nsnull, pStrFullPath, pStrDataPath); + } +} + +void CBrowserView::OpenURL(const char* pUrl) +{ + if(mWebNav) + mWebNav->LoadURI(NS_ConvertASCIItoUCS2(pUrl).GetUnicode(), nsIWebNavigation::LOAD_FLAGS_NONE); +} + +void CBrowserView::OpenURL(const PRUnichar* pUrl) +{ + if(mWebNav) + mWebNav->LoadURI(pUrl, nsIWebNavigation::LOAD_FLAGS_NONE); +} + +CBrowserFrame* CBrowserView::CreateNewBrowserFrame(PRUint32 chromeMask, + PRInt32 x, PRInt32 y, + PRInt32 cx, PRInt32 cy, + PRBool bShowWindow) +{ + CTestEmbedApp *pApp = (CTestEmbedApp *)AfxGetApp(); + if(!pApp) + return NULL; + + return pApp->CreateNewBrowserFrame(chromeMask, x, y, cx, cy, bShowWindow); +} + +void CBrowserView::OpenURLInNewWindow(const PRUnichar* pUrl) +{ + if(!pUrl) + return; + + CBrowserFrame* pFrm = CreateNewBrowserFrame(); + if(!pFrm) + return; + + // Load the URL into it... + + // Note that OpenURL() is overloaded - one takes a "char *" + // and the other a "PRUniChar *". We're using the "PRUnichar *" + // version here + + pFrm->m_wndBrowserView.OpenURL(pUrl); +} + +void CBrowserView::LoadHomePage() +{ + OnNavHome(); +} + +void CBrowserView::OnCopyLinkLocation() +{ + if(! mCtxMenuLinkUrl.Length()) + return; + + if (! OpenClipboard()) + return; + + HGLOBAL hClipData = ::GlobalAlloc(GMEM_MOVEABLE | GMEM_DDESHARE, mCtxMenuLinkUrl.Length() + 1); + if(! hClipData) + return; + + char *pszClipData = (char*)::GlobalLock(hClipData); + if(!pszClipData) + return; + + mCtxMenuLinkUrl.ToCString(pszClipData, mCtxMenuLinkUrl.Length() + 1); + + GlobalUnlock(hClipData); + + EmptyClipboard(); + SetClipboardData(CF_TEXT, hClipData); + CloseClipboard(); +} + +void CBrowserView::OnOpenLinkInNewWindow() +{ + if(mCtxMenuLinkUrl.Length()) + OpenURLInNewWindow(mCtxMenuLinkUrl.GetUnicode()); +} + +void CBrowserView::OnViewImageInNewWindow() +{ + if(mCtxMenuImgSrc.Length()) + OpenURLInNewWindow(mCtxMenuImgSrc.GetUnicode()); +} + +void CBrowserView::OnSaveLinkAs() +{ + if(! mCtxMenuLinkUrl.Length()) + return; + + // Try to get the file name part from the URL + // To do that we first construct an obj which supports + // nsIRUI interface. Makes it easy to extract portions + // of a URL like the filename, scheme etc. + We'll also + // use it while saving this link to a file + nsresult rv = NS_OK; + nsCOMPtr linkURI; + rv = NS_NewURI(getter_AddRefs(linkURI), mCtxMenuLinkUrl); + if (NS_FAILED(rv)) + return; + + // Get the "path" portion (see nsIURI.h for more info + // on various parts of a URI) + nsXPIDLCString path; + linkURI->GetPath(getter_Copies(path)); + + // The path may have the "/" char in it - strip those + nsCAutoString fileName(path); + fileName.StripChars("\\/"); + + // Now, use this file name in a File Save As dlg... + + char *lpszFilter = + "HTML Files (*.htm;*.html)|*.htm;*.html|" + "Text Files (*.txt)|*.txt|" + "All Files (*.*)|*.*||"; + + const char *pFileName = fileName.Length() ? fileName.get() : NULL; + + CFileDialog cf(FALSE, "htm", pFileName, OFN_HIDEREADONLY | OFN_OVERWRITEPROMPT, + lpszFilter, this); + if(cf.DoModal() == IDOK) + { + CString strFullPath = cf.GetPathName(); + + nsCOMPtr persist(do_QueryInterface(mWebBrowser)); + if(persist) + persist->SaveURI(linkURI, nsnull, strFullPath.GetBuffer(0)); + } +} + +void CBrowserView::OnSaveImageAs() +{ + if(! mCtxMenuImgSrc.Length()) + return; + + // Try to get the file name part from the URL + // To do that we first construct an obj which supports + // nsIRUI interface. Makes it easy to extract portions + // of a URL like the filename, scheme etc. + We'll also + // use it while saving this link to a file + nsresult rv = NS_OK; + nsCOMPtr linkURI; + rv = NS_NewURI(getter_AddRefs(linkURI), mCtxMenuImgSrc); + if (NS_FAILED(rv)) + return; + + // Get the "path" portion (see nsIURI.h for more info + // on various parts of a URI) + nsXPIDLCString path; + linkURI->GetPath(getter_Copies(path)); + + // The path may have the "/" char in it - strip those + nsCAutoString fileName(path); + fileName.StripChars("\\/"); + + // Now, use this file name in a File Save As dlg... + + char *lpszFilter = "All Files (*.*)|*.*||"; + const char *pFileName = fileName.Length() ? fileName.get() : NULL; + + CFileDialog cf(FALSE, NULL, pFileName, OFN_HIDEREADONLY | OFN_OVERWRITEPROMPT, + lpszFilter, this); + if(cf.DoModal() == IDOK) + { + CString strFullPath = cf.GetPathName(); + + nsCOMPtr persist(do_QueryInterface(mWebBrowser)); + if(persist) + persist->SaveURI(linkURI, nsnull, strFullPath.GetBuffer(0)); + } +} + +void CBrowserView::OnShowFindDlg() +{ + // When the the user chooses the Find menu item + // and if a Find dlg. is already being shown + // just set focus to the existing dlg instead of + // creating a new one + if(m_pFindDlg) + { + m_pFindDlg->SetFocus(); + return; + } + + CString csSearchStr; + PRBool bMatchCase = PR_FALSE; + PRBool bMatchWholeWord = PR_FALSE; + PRBool bWrapAround = PR_FALSE; + PRBool bSearchBackwards = PR_FALSE; + + // See if we can get and initialize the dlg box with + // the values/settings the user specified in the previous search + nsCOMPtr finder(do_GetInterface(mWebBrowser)); + if(finder) + { + nsXPIDLString stringBuf; + finder->GetSearchString(getter_Copies(stringBuf)); + csSearchStr = stringBuf.get(); + + finder->GetMatchCase(&bMatchCase); + finder->GetEntireWord(&bMatchWholeWord); + finder->GetWrapFind(&bWrapAround); + finder->GetFindBackwards(&bSearchBackwards); + } + + m_pFindDlg = new CFindDialog(csSearchStr, bMatchCase, bMatchWholeWord, + bWrapAround, bSearchBackwards, this); + m_pFindDlg->Create(TRUE, NULL, NULL, 0, this); +} + +// This will be called whenever the user pushes the Find +// button in the Find dialog box +// This method gets bound to the WM_FINDMSG windows msg via the +// +// ON_REGISTERED_MESSAGE(WM_FINDMSG, OnFindMsg) +// +// message map entry. +// +// WM_FINDMSG (which is registered towards the beginning of this file) +// is the message via which the FindDialog communicates with this view +// +LRESULT CBrowserView::OnFindMsg(WPARAM wParam, LPARAM lParam) +{ + nsCOMPtr finder(do_GetInterface(mWebBrowser)); + if(!finder) + return NULL; + + // Get the pointer to the current Find dialog box + CFindDialog* dlg = (CFindDialog *) CFindReplaceDialog::GetNotifier(lParam); + if(!dlg) + return NULL; + + // Has the user decided to terminate the dialog box? + if(dlg->IsTerminating()) + return NULL; + + if(dlg->FindNext()) + { + nsString searchString; + searchString.AssignWithConversion(dlg->GetFindString().GetBuffer(0)); + finder->SetSearchString(searchString.GetUnicode()); + + finder->SetMatchCase(dlg->MatchCase() ? PR_TRUE : PR_FALSE); + finder->SetEntireWord(dlg->MatchWholeWord() ? PR_TRUE : PR_FALSE); + finder->SetWrapFind(dlg->WrapAround() ? PR_TRUE : PR_FALSE); + finder->SetFindBackwards(dlg->SearchBackwards() ? PR_TRUE : PR_FALSE); + + PRBool didFind; + nsresult rv = finder->FindNext(&didFind); + + return (NS_SUCCEEDED(rv) && didFind); + } + + return 0; +} + +void CBrowserView::OnFilePrint() +{ + nsCOMPtr domWindow; + mWebBrowser->GetContentDOMWindow(getter_AddRefs(domWindow)); + if(domWindow) { + nsCOMPtr print(do_GetInterface(mWebBrowser)); + if(print) + { + CPrintProgressDialog dlg(mWebBrowser, domWindow); + + nsCOMPtr currentURI; + nsresult rv = mWebNav->GetCurrentURI(getter_AddRefs(currentURI)); + if(NS_SUCCEEDED(rv) || currentURI) + { + nsXPIDLCString path; + currentURI->GetPath(getter_Copies(path)); + dlg.SetURI(path.get()); + } + m_bCurrentlyPrinting = TRUE; + dlg.DoModal(); + m_bCurrentlyPrinting = FALSE; + } + } +} + +///////////////////////////////////////////////////////////////////////////// +void CBrowserView::OnUpdateFilePrint(CCmdUI* pCmdUI) +{ + pCmdUI->Enable(!m_bCurrentlyPrinting); +} + + + +// Called from the busy state related methods in the +// BrowserFrameGlue object +// +// When aBusy is TRUE it means that browser is busy loading a URL +// When aBusy is FALSE, it's done loading +// We use this to update our STOP tool bar button +// +// We basically note this state into a member variable +// The actual toolbar state will be updated in response to the +// ON_UPDATE_COMMAND_UI method - OnUpdateNavStop() being called +// +void CBrowserView::UpdateBusyState(PRBool aBusy) +{ + mbDocumentLoading = aBusy; +} + +void CBrowserView::SetCtxMenuLinkUrl(nsAutoString& strLinkUrl) +{ + mCtxMenuLinkUrl = strLinkUrl; +} + +void CBrowserView::SetCtxMenuImageSrc(nsAutoString& strImgSrc) +{ + mCtxMenuImgSrc = strImgSrc; +} + +void CBrowserView::Activate(UINT nState, CWnd* pWndOther, BOOL bMinimized) +{ + nsCOMPtr focus(do_GetInterface(mWebBrowser)); + if(!focus) + return; + + switch(nState) { + case WA_ACTIVE: + case WA_CLICKACTIVE: + focus->Activate(); + break; + case WA_INACTIVE: + focus->Deactivate(); + break; + default: + break; + } +} + +BOOL CBrowserView::OnCmdMsg(UINT nID, int nCode, void* pExtra, AFX_CMDHANDLERINFO* pHandlerInfo) +{ + // Since CTests has all the test menu handlers try and route it to it first + // We do not need to do this if all the menu handlers were in CBrowserView itself + + if ((qaTests != NULL) && qaTests->OnCmdMsg(nID, nCode, pExtra, pHandlerInfo)) + return TRUE; + + return CWnd::OnCmdMsg(nID, nCode, pExtra, pHandlerInfo); +} + diff --git a/mozilla/embedding/qa/testembed/BrowserView.cpp.mod b/mozilla/embedding/qa/testembed/BrowserView.cpp.mod new file mode 100644 index 00000000000..f5d748ac7c2 --- /dev/null +++ b/mozilla/embedding/qa/testembed/BrowserView.cpp.mod @@ -0,0 +1,1611 @@ +/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- + * + * The contents of this file are subject to the Netscape Public + * License Version 1.1 (the "License"); you may not use this file + * except in compliance with the License. You may obtain a copy of + * the License at http://www.mozilla.org/NPL/ + * + * Software distributed under the License is distributed on an "AS + * IS" basis, WITHOUT WARRANTY OF ANY KIND, either express or + * implied. See the License for the specific language governing + * rights and limitations under the License. + * + * The Original Code is mozilla.org code. + * + * The Initial Developer of the Original Code is Netscape + * Communications Corporation. Portions created by Netscape are + * Copyright (C) 1998 Netscape Communications Corporation. All + * Rights Reserved. + * + * Contributor(s): + * Chak Nanga + */ + +// File Overview.... +// +// When the CBrowserFrm creates this View: +// - CreateBrowser() is called in OnCreate() to create the +// mozilla embeddable browser +// +// OnSize() method handles the window resizes and calls the approriate +// interface method to resize the embedded browser properly +// +// Command handlers to handle browser navigation - OnNavBack(), +// OnNavForward() etc +// +// DestroyBrowser() called for cleaning up during object destruction +// +// Some important coding notes.... +// +// 1. Make sure we do not have the CS_HREDRAW|CS_VREDRAW in the call +// to AfxRegisterWndClass() inside of PreCreateWindow() below +// If these flags are present then you'll see screen flicker when +// you resize the frame window +// +// Next suggested file to look at : BrowserImpl.cpp +// + +#include "stdafx.h" +#include "MfcEmbed.h" +#include "BrowserView.h" +#include "BrowserImpl.h" +#include "BrowserFrm.h" +#include "Dialogs.h" +#include "UrlDialog.h" +#include "ProfileMgr.h" +#include "ProfilesDlg.h" + +// Print Includes +#include "PrintProgressDialog.h" + + +#ifdef _DEBUG +#define new DEBUG_NEW +#undef THIS_FILE +static char THIS_FILE[] = __FILE__; +#endif + +// Register message for FindDialog communication +static UINT WM_FINDMSG = ::RegisterWindowMessage(FINDMSGSTRING); + +BEGIN_MESSAGE_MAP(CBrowserView, CWnd) + //{{AFX_MSG_MAP(CBrowserView) + ON_WM_CREATE() + ON_WM_DESTROY() + ON_WM_SIZE() + ON_CBN_SELENDOK(ID_URL_BAR, OnUrlSelectedInUrlBar) + ON_COMMAND(IDOK, OnNewUrlEnteredInUrlBar) + ON_COMMAND(ID_FILE_OPEN, OnFileOpen) + ON_COMMAND(ID_FILE_SAVE_AS, OnFileSaveAs) + ON_COMMAND(ID_VIEW_SOURCE, OnViewSource) + ON_COMMAND(ID_VIEW_INFO, OnViewInfo) + ON_COMMAND(ID_NAV_BACK, OnNavBack) + ON_COMMAND(ID_NAV_FORWARD, OnNavForward) + ON_COMMAND(ID_NAV_HOME, OnNavHome) + ON_COMMAND(ID_NAV_RELOAD, OnNavReload) + ON_COMMAND(ID_NAV_STOP, OnNavStop) + ON_COMMAND(ID_EDIT_CUT, OnCut) + ON_COMMAND(ID_EDIT_COPY, OnCopy) + ON_COMMAND(ID_EDIT_PASTE, OnPaste) + ON_COMMAND(ID_EDIT_UNDO, OnUndoUrlBarEditOp) + ON_COMMAND(ID_EDIT_SELECT_ALL, OnSelectAll) + ON_COMMAND(ID_EDIT_SELECT_NONE, OnSelectNone) + ON_COMMAND(ID_COPY_LINK_LOCATION, OnCopyLinkLocation) + ON_COMMAND(ID_OPEN_LINK_IN_NEW_WINDOW, OnOpenLinkInNewWindow) + ON_COMMAND(ID_VIEW_IMAGE, OnViewImageInNewWindow) + ON_COMMAND(ID_SAVE_LINK_AS, OnSaveLinkAs) + ON_COMMAND(ID_SAVE_IMAGE_AS, OnSaveImageAs) + ON_COMMAND(ID_EDIT_FIND, OnShowFindDlg) + ON_COMMAND(ID_FILE_PRINT, OnFilePrint) + ON_UPDATE_COMMAND_UI(ID_FILE_PRINT, OnUpdateFilePrint) + ON_REGISTERED_MESSAGE(WM_FINDMSG, OnFindMsg) + ON_COMMAND(ID_TESTS_CHANGEURL, OnTestsChangeUrl) + ON_COMMAND(ID_TESTS_GLOBALHISTORY, OnTestsGlobalHistory) + ON_COMMAND(ID_TOOLS_REMOVEGHPAGE, OnToolsRemoveGHPage) + ON_COMMAND(ID_TESTS_CREATEFILE, OnTestsCreateFile) + ON_UPDATE_COMMAND_UI(ID_NAV_BACK, OnUpdateNavBack) + ON_UPDATE_COMMAND_UI(ID_NAV_FORWARD, OnUpdateNavForward) + ON_UPDATE_COMMAND_UI(ID_NAV_STOP, OnUpdateNavStop) + ON_UPDATE_COMMAND_UI(ID_EDIT_CUT, OnUpdateCut) + ON_UPDATE_COMMAND_UI(ID_EDIT_COPY, OnUpdateCopy) + ON_UPDATE_COMMAND_UI(ID_EDIT_PASTE, OnUpdatePaste) + ON_COMMAND(ID_INTERFACES_NSIFILE, OnInterfacesNsifile) + ON_COMMAND(ID_TESTS_CREATEPROFILE, OnTestsCreateprofile) + ON_COMMAND(ID_INTERFACES_NSISHISTORY, OnInterfacesNsishistory) + ON_COMMAND(ID_VERIFYBUGS_70228, OnVerifybugs70228) + //}}AFX_MSG_MAP +END_MESSAGE_MAP() + + +CBrowserView::CBrowserView() +{ + mWebBrowser = nsnull; + mBaseWindow = nsnull; + mWebNav = nsnull; + + mpBrowserImpl = nsnull; + mpBrowserFrame = nsnull; + mpBrowserFrameGlue = nsnull; + + mbDocumentLoading = PR_FALSE; + + m_pFindDlg = NULL; + m_pPrintProgressDlg = NULL; + + m_bUrlBarClipOp = FALSE; + m_bCurrentlyPrinting = FALSE; + + char *theUrl = "http://www.aol.com/"; +} + +CBrowserView::~CBrowserView() +{ +} + +// This is a good place to create the embeddable browser +// instance +// +int CBrowserView::OnCreate(LPCREATESTRUCT lpCreateStruct) +{ + CreateBrowser(); + + return 0; +} + +void CBrowserView::OnDestroy() +{ + DestroyBrowser(); +} + +// Create an instance of the Mozilla embeddable browser +// +HRESULT CBrowserView::CreateBrowser() +{ + // Create web shell + nsresult rv; + mWebBrowser = do_CreateInstance(NS_WEBBROWSER_CONTRACTID, &rv); + if(NS_FAILED(rv)) + return rv; + + // Save off the nsIWebNavigation interface pointer + // in the mWebNav member variable which we'll use + // later for web page navigation + // + rv = NS_OK; + mWebNav = do_QueryInterface(mWebBrowser, &rv); + if(NS_FAILED(rv)) + return rv; + +// mSessionHistory = do_GetInterface(mWebBrowser, &rv); // de: added 5/11 + + // Create the CBrowserImpl object - this is the object + // which implements the interfaces which are required + // by an app embedding mozilla i.e. these are the interfaces + // thru' which the *embedded* browser communicates with the + // *embedding* app + // + // The CBrowserImpl object will be passed in to the + // SetContainerWindow() call below + // + // Also note that we're passing the BrowserFrameGlue pointer + // and also the mWebBrowser interface pointer via CBrowserImpl::Init() + // of CBrowserImpl object. + // These pointers will be saved by the CBrowserImpl object. + // The CBrowserImpl object uses the BrowserFrameGlue pointer to + // call the methods on that interface to update the status/progress bars + // etc. + mpBrowserImpl = new CBrowserImpl(); + if(mpBrowserImpl == nsnull) + return NS_ERROR_OUT_OF_MEMORY; + + // Pass along the mpBrowserFrameGlue pointer to the BrowserImpl object + // This is the interface thru' which the XP BrowserImpl code communicates + // with the platform specific code to update status bars etc. + mpBrowserImpl->Init(mpBrowserFrameGlue, mWebBrowser); + mpBrowserImpl->AddRef(); + + mWebBrowser->SetContainerWindow(NS_STATIC_CAST(nsIWebBrowserChrome*, mpBrowserImpl)); + + rv = NS_OK; + nsCOMPtr dsti = do_QueryInterface(mWebBrowser, &rv); + if(NS_FAILED(rv)) + return rv; + dsti->SetItemType(nsIDocShellTreeItem::typeContentWrapper); + + // Create the real webbrowser window + + // Note that we're passing the m_hWnd in the call below to InitWindow() + // (CBrowserView inherits the m_hWnd from CWnd) + // This m_hWnd will be used as the parent window by the embeddable browser + // + rv = NS_OK; + mBaseWindow = do_QueryInterface(mWebBrowser, &rv); + if(NS_FAILED(rv)) + return rv; + + // Get the view's ClientRect which to be passed in to the InitWindow() + // call below + RECT rcLocation; + GetClientRect(&rcLocation); + if(IsRectEmpty(&rcLocation)) + { + rcLocation.bottom++; + rcLocation.top++; + } + + rv = mBaseWindow->InitWindow(nsNativeWidget(m_hWnd), nsnull, + 0, 0, rcLocation.right - rcLocation.left, rcLocation.bottom - rcLocation.top); + rv = mBaseWindow->Create(); + + // Register the BrowserImpl object to receive progress messages + // These callbacks will be used to update the status/progress bars + nsWeakPtr weakling( + dont_AddRef(NS_GetWeakReference(NS_STATIC_CAST(nsIWebProgressListener*, mpBrowserImpl)))); + rv = mWebBrowser->AddWebBrowserListener(weakling, NS_GET_IID(nsIWebProgressListener)); + + if (NS_FAILED(rv)) + { + AfxMessageBox("Web Progress Listener not added."); + WriteToOutputFile("Web Progress Listener not added.\r\n"); + } + else + { + AfxMessageBox("Web Progress Listener added."); + WriteToOutputFile("Web Progress Listener added.\r\n"); + } + + // Finally, show the web browser window + mBaseWindow->SetVisibility(PR_TRUE); + + return S_OK; +} + +HRESULT CBrowserView::DestroyBrowser() +{ + if(mBaseWindow) + { + mBaseWindow->Destroy(); + mBaseWindow = nsnull; + } + + if(mpBrowserImpl) + { + mpBrowserImpl->Release(); + mpBrowserImpl = nsnull; + } + + nsWeakPtr weakling( + dont_AddRef(NS_GetWeakReference(NS_STATIC_CAST(nsIWebProgressListener*, mpBrowserImpl)))); + nsresult rv; + rv = mWebBrowser->RemoveWebBrowserListener(weakling, NS_GET_IID(nsIWebProgressListener)); + if (NS_FAILED(rv)) + { + AfxMessageBox("Web Progress Listener not removed."); + WriteToOutputFile("Web Progress Listener not removed.\r\n"); + } + else + { + AfxMessageBox("Web Progress Listener removed."); + WriteToOutputFile("Web Progress Listener removed.\r\n"); + } + + return NS_OK; +} + +BOOL CBrowserView::PreCreateWindow(CREATESTRUCT& cs) +{ + if (!CWnd::PreCreateWindow(cs)) + return FALSE; + + cs.dwExStyle |= WS_EX_CLIENTEDGE; + cs.style &= ~WS_BORDER; + cs.lpszClass = AfxRegisterWndClass(CS_DBLCLKS, + ::LoadCursor(NULL, IDC_ARROW), HBRUSH(COLOR_WINDOW+1), NULL); + + return TRUE; +} + +// Adjust the size of the embedded browser +// in response to any container size changes +// +void CBrowserView::OnSize( UINT nType, int cx, int cy) +{ + mBaseWindow->SetPositionAndSize(0, 0, cx, cy, PR_TRUE); +} + +// Called by this object's creator i.e. the CBrowserFrame object +// to pass it's pointer to us +// +void CBrowserView::SetBrowserFrame(CBrowserFrame* pBrowserFrame) +{ + mpBrowserFrame = pBrowserFrame; +} + +void CBrowserView::SetBrowserFrameGlue(PBROWSERFRAMEGLUE pBrowserFrameGlue) +{ + mpBrowserFrameGlue = pBrowserFrameGlue; +} + +// A new URL was entered in the URL bar +// Get the URL's text from the Urlbar's (ComboBox's) EditControl +// and navigate to that URL +// +void CBrowserView::OnNewUrlEnteredInUrlBar() +{ + // Get the currently entered URL + CString strUrl; + mpBrowserFrame->m_wndUrlBar.GetEnteredURL(strUrl); + + if(IsViewSourceUrl(strUrl)) + OpenViewSourceWindow(strUrl.GetBuffer(0)); + else + // Navigate to that URL + OpenURL(strUrl.GetBuffer(0)); + + // Add what was just entered into the UrlBar + mpBrowserFrame->m_wndUrlBar.AddURLToList(strUrl); +} + +// A URL has been selected from the UrlBar's dropdown list +// +void CBrowserView::OnUrlSelectedInUrlBar() +{ + CString strUrl; + + mpBrowserFrame->m_wndUrlBar.GetSelectedURL(strUrl); + + if(IsViewSourceUrl(strUrl)) + OpenViewSourceWindow(strUrl.GetBuffer(0)); + else + OpenURL(strUrl.GetBuffer(0)); +} + +BOOL CBrowserView::IsViewSourceUrl(CString& strUrl) +{ + return (strUrl.Find("view-source:", 0) != -1) ? TRUE : FALSE; +} + +BOOL CBrowserView::OpenViewSourceWindow(const char* pUrl) +{ + // Create a new browser frame in which we'll show the document source + // Note that we're getting rid of the toolbars etc. by specifying + // the appropriate chromeFlags + PRUint32 chromeFlags = nsIWebBrowserChrome::CHROME_WINDOW_BORDERS | + nsIWebBrowserChrome::CHROME_TITLEBAR | + nsIWebBrowserChrome::CHROME_WINDOW_RESIZE; + CBrowserFrame* pFrm = CreateNewBrowserFrame(chromeFlags); + if(!pFrm) + return FALSE; + + // Finally, load this URI into the newly created frame + pFrm->m_wndBrowserView.OpenURL(pUrl); + + pFrm->BringWindowToTop(); + + return TRUE; +} + +void CBrowserView::OnViewSource() +{ + if(! mWebNav) + return; + + // Get the URI object whose source we want to view. + nsresult rv = NS_OK; + nsCOMPtr currentURI; + rv = mWebNav->GetCurrentURI(getter_AddRefs(currentURI)); + if(NS_FAILED(rv) || !currentURI) + return; + + // Get the uri string associated with the nsIURI object + nsXPIDLCString uriString; + rv = currentURI->GetSpec(getter_Copies(uriString)); + if(NS_FAILED(rv)) + return; + + // Build the view-source: url + nsCAutoString viewSrcUrl; + viewSrcUrl.Append("view-source:"); + viewSrcUrl.Append(uriString); + + OpenViewSourceWindow(viewSrcUrl.get()); +} + +void CBrowserView::OnViewInfo() +{ + AfxMessageBox("To Be Done..."); +} + +void CBrowserView::OnNavBack() +{ + if(mWebNav) + mWebNav->GoBack(); +} + +void CBrowserView::OnUpdateNavBack(CCmdUI* pCmdUI) +{ + PRBool canGoBack = PR_FALSE; + + if (mWebNav) + mWebNav->GetCanGoBack(&canGoBack); + + pCmdUI->Enable(canGoBack); +} + +void CBrowserView::OnNavForward() +{ + if(mWebNav) + mWebNav->GoForward(); +} + +void CBrowserView::OnUpdateNavForward(CCmdUI* pCmdUI) +{ + PRBool canGoFwd = PR_FALSE; + + if (mWebNav) + mWebNav->GetCanGoForward(&canGoFwd); + + pCmdUI->Enable(canGoFwd); +} + +void CBrowserView::OnNavHome() +{ + // Get the currently configured HomePage URL + CString strHomeURL; + CMfcEmbedApp *pApp = (CMfcEmbedApp *)AfxGetApp(); + if(pApp) + pApp->GetHomePage(strHomeURL); + + if(strHomeURL.GetLength() > 0) + OpenURL(strHomeURL); +} + +void CBrowserView::OnNavReload() +{ + if(mWebNav) + mWebNav->Reload(nsIWebNavigation::LOAD_FLAGS_NONE); +} + +void CBrowserView::OnNavStop() +{ + if(mWebNav) + mWebNav->Stop(); +} + +void CBrowserView::OnUpdateNavStop(CCmdUI* pCmdUI) +{ + pCmdUI->Enable(mbDocumentLoading); +} + +void CBrowserView::OnCut() +{ + if(m_bUrlBarClipOp) + { + // We need to operate on the URLBar selection + mpBrowserFrame->CutUrlBarSelToClipboard(); + m_bUrlBarClipOp = FALSE; + } + else + { + nsCOMPtr clipCmds = do_GetInterface(mWebBrowser); + + if(clipCmds) + clipCmds->CutSelection(); + } +} + +void CBrowserView::OnUpdateCut(CCmdUI* pCmdUI) +{ + PRBool canCutSelection = PR_FALSE; + + nsCOMPtr clipCmds = do_GetInterface(mWebBrowser); + if (clipCmds) + clipCmds->CanCutSelection(&canCutSelection); + + if(!canCutSelection) + { + // Check to see if the Cut cmd is to cut the URL + // selection in the UrlBar + if(mpBrowserFrame->CanCutUrlBarSelection()) + { + canCutSelection = TRUE; + m_bUrlBarClipOp = TRUE; + } + } + + pCmdUI->Enable(canCutSelection); +} + +void CBrowserView::OnCopy() +{ + if(m_bUrlBarClipOp) + { + // We need to operate on the URLBar selection + mpBrowserFrame->CopyUrlBarSelToClipboard(); + m_bUrlBarClipOp = FALSE; + } + else + { + // We need to operate on the web page content + nsCOMPtr clipCmds = do_GetInterface(mWebBrowser); + + if(clipCmds) + clipCmds->CopySelection(); + } +} + +void CBrowserView::OnUpdateCopy(CCmdUI* pCmdUI) +{ + PRBool canCopySelection = PR_FALSE; + + nsCOMPtr clipCmds = do_GetInterface(mWebBrowser); + if (clipCmds) + clipCmds->CanCopySelection(&canCopySelection); + + if(!canCopySelection) + { + // Check to see if the Copy cmd is to copy the URL + // selection in the UrlBar + if(mpBrowserFrame->CanCopyUrlBarSelection()) + { + canCopySelection = TRUE; + m_bUrlBarClipOp = TRUE; + } + } + + pCmdUI->Enable(canCopySelection); +} + +void CBrowserView::OnPaste() +{ + if(m_bUrlBarClipOp) + { + mpBrowserFrame->PasteFromClipboardToUrlBar(); + m_bUrlBarClipOp = FALSE; + } + else + { + nsCOMPtr clipCmds = do_GetInterface(mWebBrowser); + + if(clipCmds) + clipCmds->Paste(); + } +} + +void CBrowserView::OnUndoUrlBarEditOp() +{ + if(mpBrowserFrame->CanUndoUrlBarEditOp()) + mpBrowserFrame->UndoUrlBarEditOp(); +} + +void CBrowserView::OnUpdatePaste(CCmdUI* pCmdUI) +{ + PRBool canPaste = PR_FALSE; + + nsCOMPtr clipCmds = do_GetInterface(mWebBrowser); + if (clipCmds) + clipCmds->CanPaste(&canPaste); + + if(!canPaste) + { + if(mpBrowserFrame->CanPasteToUrlBar()) + { + canPaste = TRUE; + m_bUrlBarClipOp = TRUE; + } + } + + pCmdUI->Enable(canPaste); +} + +void CBrowserView::OnSelectAll() +{ + nsCOMPtr clipCmds = do_GetInterface(mWebBrowser); + + if(clipCmds) + clipCmds->SelectAll(); +} + +void CBrowserView::OnSelectNone() +{ + nsCOMPtr clipCmds = do_GetInterface(mWebBrowser); + + if(clipCmds) + clipCmds->SelectNone(); +} + +void CBrowserView::OnFileOpen() +{ + char *lpszFilter = + "HTML Files Only (*.htm;*.html)|*.htm;*.html|" + "All Files (*.*)|*.*||"; + + CFileDialog cf(TRUE, NULL, NULL, OFN_HIDEREADONLY | OFN_OVERWRITEPROMPT, + lpszFilter, this); + if(cf.DoModal() == IDOK) + { + CString strFullPath = cf.GetPathName(); // Will be like: c:\tmp\junk.htm + OpenURL(strFullPath); + } +} + +void CBrowserView::GetBrowserWindowTitle(nsCString& title) +{ + nsXPIDLString idlStrTitle; + if(mBaseWindow) + mBaseWindow->GetTitle(getter_Copies(idlStrTitle)); + + title.AssignWithConversion(idlStrTitle); + + // Sanitize the title of all illegal characters + title.CompressWhitespace(); // Remove whitespace from the ends + title.StripChars("\\*|:\"> persist(do_QueryInterface(mWebBrowser)); + if(persist) + persist->SaveDocument(nsnull, pStrFullPath, pStrDataPath); + } +} + +void CBrowserView::OpenURL(const char* pUrl) +{ + if(mWebNav) + mWebNav->LoadURI(NS_ConvertASCIItoUCS2(pUrl).GetUnicode(), nsIWebNavigation::LOAD_FLAGS_NONE); +} + +void CBrowserView::OpenURL(const PRUnichar* pUrl) +{ + if(mWebNav) + mWebNav->LoadURI(pUrl, nsIWebNavigation::LOAD_FLAGS_NONE); +} + +CBrowserFrame* CBrowserView::CreateNewBrowserFrame(PRUint32 chromeMask, + PRInt32 x, PRInt32 y, + PRInt32 cx, PRInt32 cy, + PRBool bShowWindow) +{ + CMfcEmbedApp *pApp = (CMfcEmbedApp *)AfxGetApp(); + if(!pApp) + return NULL; + + return pApp->CreateNewBrowserFrame(chromeMask, x, y, cx, cy, bShowWindow); +} + +void CBrowserView::OpenURLInNewWindow(const PRUnichar* pUrl) +{ + if(!pUrl) + return; + + CBrowserFrame* pFrm = CreateNewBrowserFrame(); + if(!pFrm) + return; + + // Load the URL into it... + + // Note that OpenURL() is overloaded - one takes a "char *" + // and the other a "PRUniChar *". We're using the "PRUnichar *" + // version here + + pFrm->m_wndBrowserView.OpenURL(pUrl); +} + +void CBrowserView::LoadHomePage() +{ + OnNavHome(); +} + +void CBrowserView::OnCopyLinkLocation() +{ + if(! mCtxMenuLinkUrl.Length()) + return; + + if (! OpenClipboard()) + return; + + HGLOBAL hClipData = ::GlobalAlloc(GMEM_MOVEABLE | GMEM_DDESHARE, mCtxMenuLinkUrl.Length() + 1); + if(! hClipData) + return; + + char *pszClipData = (char*)::GlobalLock(hClipData); + if(!pszClipData) + return; + + mCtxMenuLinkUrl.ToCString(pszClipData, mCtxMenuLinkUrl.Length() + 1); + + GlobalUnlock(hClipData); + + EmptyClipboard(); + SetClipboardData(CF_TEXT, hClipData); + CloseClipboard(); +} + +void CBrowserView::OnOpenLinkInNewWindow() +{ + if(mCtxMenuLinkUrl.Length()) + OpenURLInNewWindow(mCtxMenuLinkUrl.GetUnicode()); +} + +void CBrowserView::OnViewImageInNewWindow() +{ + if(mCtxMenuImgSrc.Length()) + OpenURLInNewWindow(mCtxMenuImgSrc.GetUnicode()); +} + +void CBrowserView::OnSaveLinkAs() +{ + if(! mCtxMenuLinkUrl.Length()) + return; + + // Try to get the file name part from the URL + // To do that we first construct an obj which supports + // nsIRUI interface. Makes it easy to extract portions + // of a URL like the filename, scheme etc. + We'll also + // use it while saving this link to a file + nsresult rv = NS_OK; + nsCOMPtr linkURI; + rv = NS_NewURI(getter_AddRefs(linkURI), mCtxMenuLinkUrl); + if (NS_FAILED(rv)) + return; + + // Get the "path" portion (see nsIURI.h for more info + // on various parts of a URI) + nsXPIDLCString path; + linkURI->GetPath(getter_Copies(path)); + + // The path may have the "/" char in it - strip those + nsCAutoString fileName(path); + fileName.StripChars("\\/"); + + // Now, use this file name in a File Save As dlg... + + char *lpszFilter = + "HTML Files (*.htm;*.html)|*.htm;*.html|" + "Text Files (*.txt)|*.txt|" + "All Files (*.*)|*.*||"; + + const char *pFileName = fileName.Length() ? fileName.get() : NULL; + + CFileDialog cf(FALSE, "htm", pFileName, OFN_HIDEREADONLY | OFN_OVERWRITEPROMPT, + lpszFilter, this); + if(cf.DoModal() == IDOK) + { + CString strFullPath = cf.GetPathName(); + + nsCOMPtr persist(do_QueryInterface(mWebBrowser)); + if(persist) + persist->SaveURI(linkURI, nsnull, strFullPath.GetBuffer(0)); + } +} + +void CBrowserView::OnSaveImageAs() +{ + if(! mCtxMenuImgSrc.Length()) + return; + + // Try to get the file name part from the URL + // To do that we first construct an obj which supports + // nsIRUI interface. Makes it easy to extract portions + // of a URL like the filename, scheme etc. + We'll also + // use it while saving this link to a file + nsresult rv = NS_OK; + nsCOMPtr linkURI; + rv = NS_NewURI(getter_AddRefs(linkURI), mCtxMenuImgSrc); + if (NS_FAILED(rv)) + return; + + // Get the "path" portion (see nsIURI.h for more info + // on various parts of a URI) + nsXPIDLCString path; + linkURI->GetPath(getter_Copies(path)); + + // The path may have the "/" char in it - strip those + nsCAutoString fileName(path); + fileName.StripChars("\\/"); + + // Now, use this file name in a File Save As dlg... + + char *lpszFilter = "All Files (*.*)|*.*||"; + const char *pFileName = fileName.Length() ? fileName.get() : NULL; + + CFileDialog cf(FALSE, NULL, pFileName, OFN_HIDEREADONLY | OFN_OVERWRITEPROMPT, + lpszFilter, this); + if(cf.DoModal() == IDOK) + { + CString strFullPath = cf.GetPathName(); + + nsCOMPtr persist(do_QueryInterface(mWebBrowser)); + if(persist) + persist->SaveURI(linkURI, nsnull, strFullPath.GetBuffer(0)); + } +} + +void CBrowserView::OnShowFindDlg() +{ + // When the the user chooses the Find menu item + // and if a Find dlg. is already being shown + // just set focus to the existing dlg instead of + // creating a new one + if(m_pFindDlg) + { + m_pFindDlg->SetFocus(); + return; + } + + CString csSearchStr; + PRBool bMatchCase = PR_FALSE; + PRBool bMatchWholeWord = PR_FALSE; + PRBool bWrapAround = PR_FALSE; + PRBool bSearchBackwards = PR_FALSE; + + // See if we can get and initialize the dlg box with + // the values/settings the user specified in the previous search + nsCOMPtr finder(do_GetInterface(mWebBrowser)); + if(finder) + { + nsXPIDLString stringBuf; + finder->GetSearchString(getter_Copies(stringBuf)); + csSearchStr = stringBuf.get(); + + finder->GetMatchCase(&bMatchCase); + finder->GetEntireWord(&bMatchWholeWord); + finder->GetWrapFind(&bWrapAround); + finder->GetFindBackwards(&bSearchBackwards); + } + + m_pFindDlg = new CFindDialog(csSearchStr, bMatchCase, bMatchWholeWord, + bWrapAround, bSearchBackwards, this); + m_pFindDlg->Create(TRUE, NULL, NULL, 0, this); +} + +// This will be called whenever the user pushes the Find +// button in the Find dialog box +// This method gets bound to the WM_FINDMSG windows msg via the +// +// ON_REGISTERED_MESSAGE(WM_FINDMSG, OnFindMsg) +// +// message map entry. +// +// WM_FINDMSG (which is registered towards the beginning of this file) +// is the message via which the FindDialog communicates with this view +// +LRESULT CBrowserView::OnFindMsg(WPARAM wParam, LPARAM lParam) +{ + nsCOMPtr finder(do_GetInterface(mWebBrowser)); + if(!finder) + return NULL; + + // Get the pointer to the current Find dialog box + CFindDialog* dlg = (CFindDialog *) CFindReplaceDialog::GetNotifier(lParam); + if(!dlg) + return NULL; + + // Has the user decided to terminate the dialog box? + if(dlg->IsTerminating()) + return NULL; + + if(dlg->FindNext()) + { + nsString searchString; + searchString.AssignWithConversion(dlg->GetFindString().GetBuffer(0)); + finder->SetSearchString(searchString.GetUnicode()); + + finder->SetMatchCase(dlg->MatchCase() ? PR_TRUE : PR_FALSE); + finder->SetEntireWord(dlg->MatchWholeWord() ? PR_TRUE : PR_FALSE); + finder->SetWrapFind(dlg->WrapAround() ? PR_TRUE : PR_FALSE); + finder->SetFindBackwards(dlg->SearchBackwards() ? PR_TRUE : PR_FALSE); + + PRBool didFind; + nsresult rv = finder->FindNext(&didFind); + + return (NS_SUCCEEDED(rv) && didFind); + } + + return 0; +} + +void CBrowserView::OnFilePrint() +{ + nsCOMPtr domWindow; + mWebBrowser->GetContentDOMWindow(getter_AddRefs(domWindow)); + if(domWindow) { + nsCOMPtr print(do_GetInterface(mWebBrowser)); + if(print) + { + CPrintProgressDialog dlg(mWebBrowser, domWindow); + + nsCOMPtr currentURI; + nsresult rv = mWebNav->GetCurrentURI(getter_AddRefs(currentURI)); + if(NS_SUCCEEDED(rv) || currentURI) + { + nsXPIDLCString path; + currentURI->GetPath(getter_Copies(path)); + dlg.SetURI(path.get()); + } + m_bCurrentlyPrinting = TRUE; + dlg.DoModal(); + m_bCurrentlyPrinting = FALSE; + } + } +} + +///////////////////////////////////////////////////////////////////////////// +void CBrowserView::OnUpdateFilePrint(CCmdUI* pCmdUI) +{ + pCmdUI->Enable(!m_bCurrentlyPrinting); +} + + + +// Called from the busy state related methods in the +// BrowserFrameGlue object +// +// When aBusy is TRUE it means that browser is busy loading a URL +// When aBusy is FALSE, it's done loading +// We use this to update our STOP tool bar button +// +// We basically note this state into a member variable +// The actual toolbar state will be updated in response to the +// ON_UPDATE_COMMAND_UI method - OnUpdateNavStop() being called +// +void CBrowserView::UpdateBusyState(PRBool aBusy) +{ + mbDocumentLoading = aBusy; +} + +void CBrowserView::SetCtxMenuLinkUrl(nsAutoString& strLinkUrl) +{ + mCtxMenuLinkUrl = strLinkUrl; +} + +void CBrowserView::SetCtxMenuImageSrc(nsAutoString& strImgSrc) +{ + mCtxMenuImgSrc = strImgSrc; +} + +void CBrowserView::Activate(UINT nState, CWnd* pWndOther, BOOL bMinimized) +{ + nsCOMPtr focus(do_GetInterface(mWebBrowser)); + if(!focus) + return; + + switch(nState) { + case WA_ACTIVE: + case WA_CLICKACTIVE: + focus->Activate(); + break; + case WA_INACTIVE: + focus->Deactivate(); + break; + default: + break; + } +} + +// de: Start QA test cases here +// ********************************************************* +// ********************************************************* + +void CBrowserView::OnTestsChangeUrl() +{ + char *theUrl = "http://www.aol.com/"; + CUrlDialog myDialog; + nsresult rv; + +// nsCOMPtr pURI; + + if (!mWebNav) + { + AfxMessageBox("Web navigation object not found. Change URL test not performed."); + WriteToOutputFile("Web navigation object not found. Change URL test not performed.\r\n"); + return; + } + + if (myDialog.DoModal() == IDOK) + { + AfxMessageBox("Begin Change URL test."); + WriteToOutputFile("Begin Change URL test.\r\n"); + strcpy(theUrl, myDialog.m_urlfield); + mWebNav->LoadURI(NS_ConvertASCIItoUCS2(theUrl).GetUnicode(), + nsIWebNavigation::LOAD_FLAGS_NONE); + WriteToOutputFile("\r\nLoadURI() method is called."); + WriteToOutputFile("theUrl = "); + WriteToOutputFile(theUrl); + +/* + char *uriSpec; + // GetcurrentURI() declared in nsIP3PUI.idl + // used with webNav obj in nsP3PObserverHTML.cpp, line 239 + // this will be used as an indep routine to verify the URI load + rv = mWebNav->GetCurrentURI( getter_AddRefs( pURI ) ); + if(NS_FAILED(rv) || !pURI) + AfxMessageBox("Bad result for GetCurrentURI()."); + + rv = pURI->GetSpec(&uriSpec);; + if (NS_FAILED(rv)) + AfxMessageBox("Bad result for GetSpec()."); + + AfxMessageBox("Start URL validation test()."); + if (strcmp(uriSpec, theUrl) == 0) + { + WriteToOutputFile("Url loaded successfully. Test Passed."); + } + else + { + WriteToOutputFile("Url didn't load successfully. Test Failed."); + } +*/ + AfxMessageBox("End Change URL test."); + WriteToOutputFile("End Change URL test.\r\n"); + } + else + { + AfxMessageBox("Change URL test not executed."); + WriteToOutputFile("Change URL test not executed.\r\n"); + } +} + +// ********************************************************* + +void CBrowserView::OnTestsGlobalHistory() +{ + // create instance of myHistory object. Call's XPCOM + // service manager to pass the contract ID. + + char *theUrl = "http://www.bogussite.com/"; + CUrlDialog myDialog; + + PRBool theRetVal = PR_FALSE; + nsresult rv; + + nsCOMPtr myHistory(do_GetService(NS_GLOBALHISTORY_CONTRACTID)); + + if (!myHistory) + { + WriteToOutputFile("Couldn't find history object. No GH tests performed.\r\n"); + AfxMessageBox("Couldn't find history object. No GH tests performed."); + return; + } + + if (myDialog.DoModal() == IDOK) + { + AfxMessageBox("Begin IsVisited() and AddPage() tests."); + WriteToOutputFile("Begin IsVisited() and AddPage() tests.\r\n"); + + strcpy(theUrl, myDialog.m_urlfield); + + WriteToOutputFile("theUrl = "); + WriteToOutputFile(theUrl); + + // see if url is already in the GH file (pre-AddPage() test) + myHistory->IsVisited(theUrl, &theRetVal); + + if (theRetVal) + { + WriteToOutputFile("URL has been visited. Won't execute AddPage().\r\n"); + AfxMessageBox("URL has been visited. Won't execute AddPage()."); + } + else + { + WriteToOutputFile("URL hasn't been visited. Will execute AddPage().\r\n"); + AfxMessageBox("URL hasn't been visited. Will execute AddPage()."); + // adds a url to the global history file + rv = myHistory->AddPage(theUrl); + + // prints addPage() results to output file + if (NS_FAILED(rv)) + { + WriteToOutputFile("Invalid results for AddPage(). Url not added. Test failed.\r\n"); + return; + } + else + { + WriteToOutputFile("Valid results for AddPage(). Url added. Test passed.\r\n"); + } + + // checks if url was visited (post-AddPage() test) + myHistory->IsVisited(theUrl, &theRetVal); + + if (theRetVal) + { + WriteToOutputFile("URL is visited; post-AddPage() test. IsVisited() test passed.\r\n"); + } + else + { + WriteToOutputFile("URL isn't visited; post-AddPage() test. IsVisited() test failed.\r\n"); + } + } + AfxMessageBox("End IsVisited() and AddPage() tests."); + WriteToOutputFile("End IsVisited() and AddPage() tests.\r\n"); + } + else + { + AfxMessageBox("IsVisited() and AddPage() tests not executed."); + WriteToOutputFile("IsVisited() and AddPage() tests not executed.\r\n"); + } +} + + + +// ********************************************************* + +void CBrowserView::OnTestsCreateFile() +{ + nsresult rv; + PRBool exists; + nsCOMPtr theTestFile(do_GetService(NS_LOCAL_FILE_CONTRACTID)); + + if (!theTestFile) + { + WriteToOutputFile("File object doesn't exist. No File tests performed.\r\n"); + AfxMessageBox("File object doesn't exist. No File tests performed."); + return; + } + + + AfxMessageBox("Start Create File test."); + WriteToOutputFile("\r\nStart Create File test.\r\n"); + + rv = theTestFile->InitWithPath("c:\\temp\\theFile.txt"); + rv = theTestFile->Exists(&exists); + + WriteToOutputFile("File doesn't exist. We'll create it.\r\n"); + rv = theTestFile->Create(nsIFile::NORMAL_FILE_TYPE, 0777); + if (NS_FAILED(rv)) + { + AfxMessageBox("We failed to create the file (theFile.txt)."); + WriteToOutputFile("Create() test Failed.\r\n"); + } + else + { + AfxMessageBox("We created the file (theFile.txt)."); + WriteToOutputFile("Create() test Passed.\r\n"); + } +} + +// ********************************************************* + +void CBrowserView::OnTestsCreateprofile() +{ + CProfilesDlg myDialog; + nsresult rv; + + if (myDialog.DoModal() == IDOK) + { +// NS_WITH_SERVICE(nsIProfile, profileService, NS_PROFILE_CONTRACTID, &rv); + nsCOMPtr theProfServ(do_GetService(NS_PROFILE_CONTRACTID)); + if (!theProfServ) + { + WriteToOutputFile("Didn't get profile service. No profile tests performed.\r\n"); + AfxMessageBox("Didn't get profile service. No profile tests performed."); + return; + } + + if (theProfServ) + { + AfxMessageBox("Start Profile switch test."); + WriteToOutputFile("Start Profile switch test.\r\n"); + + AfxMessageBox("Retrieved profile service."); + rv = theProfServ->SetCurrentProfile(myDialog.m_SelectedProfile.GetUnicode()); + if (NS_SUCCEEDED(rv)) + AfxMessageBox("SetCurrentProfile() passed. Profile switched."); + else + AfxMessageBox("SetCurrentProfile() didn't pass.Profile not switched."); + + AfxMessageBox("End Profile switch test."); + WriteToOutputFile("End Profile switch test.\r\n"); + } + } + else + { + AfxMessageBox("Profile switch test not executed."); + WriteToOutputFile("Profile switch test not executed.\r\n"); + } +} + +// ********************************************************* +// ********************************************************* +// TOOLS to help us + + +void CBrowserView::OnToolsRemoveGHPage() +{ + char *theUrl = "http://www.bogussite.com/"; + CUrlDialog myDialog; + PRBool theRetVal = PR_FALSE; + nsresult rv; + nsCOMPtr myGHistory(do_GetService(NS_GLOBALHISTORY_CONTRACTID)); + if (!myGHistory) + { + WriteToOutputFile("Could not get the global history object.\r\n"); + AfxMessageBox("Could not get the global history object."); + return; + } + nsCOMPtr myHistory = do_QueryInterface(myGHistory, &rv); + if(!NS_SUCCEEDED(rv)) { + WriteToOutputFile("Could not get the history object.\r\n"); + AfxMessageBox("Could not get the global history object."); + return; + } +// nsCOMPtr myHistory(do_GetInterface(myGHistory)); + + + if (myDialog.DoModal() == IDOK) + { + WriteToOutputFile("Begin URL removal from the GH file.\r\n"); + AfxMessageBox("Begin URL removal from the GH file."); + strcpy(theUrl, myDialog.m_urlfield); + + myGHistory->IsVisited(theUrl, &theRetVal); + if (theRetVal) + { + rv = myHistory->RemovePage(theUrl); + if (NS_SUCCEEDED(rv)) + { + WriteToOutputFile("\r\nThe URL was removed from the GH file.\r\n"); + AfxMessageBox("The URL was removed from the GH file."); + } + else + { + WriteToOutputFile("\r\nThe URL wasn't removed from the GH file.\r\n"); + AfxMessageBox("The URL wasn't removed from the GH file."); + } + } + else + { + WriteToOutputFile("The URL wasn't in the GH file.\r\n"); + } + WriteToOutputFile("End URL removal from the GH file.\r\n"); + AfxMessageBox("End URL removal from the GH file."); + } + else + { + WriteToOutputFile("URL removal from the GH file not executed.\r\n"); + AfxMessageBox("URL removal from the GH file not executed."); + } +} + +// *********************************************************************** +// ************************** Interface Tests **************************** +// *********************************************************************** + +// nsIFile: + +void CBrowserView::OnInterfacesNsifile() +{ + nsCOMPtr theTestFile(do_CreateInstance(NS_LOCAL_FILE_CONTRACTID)); + nsCOMPtr theFileOpDir(do_CreateInstance(NS_LOCAL_FILE_CONTRACTID)); + + nsresult rv; + PRBool exists; + + if (!theTestFile) + { + WriteToOutputFile("File object doesn't exist. No File tests performed.\r\n"); + AfxMessageBox("File object doesn't exist. No File tests performed."); + return; + } + if (!theFileOpDir) + { + WriteToOutputFile("Dir object doesn't exist. No File tests performed.\r\n"); + AfxMessageBox("File object doesn't exist. No File tests performed."); + return; + } + + AfxMessageBox("Begin nsIFile tests."); + WriteToOutputFile("\r\nBegin testing nsIFile InitWithPath(), AppendRelativePath(), \ + Create(), and Exists() methods.\r\n"); + + rv = theTestFile->InitWithPath("c:\\temp\\"); + if (NS_FAILED(rv)) + { + AfxMessageBox("We failed to initialize file path."); + WriteToOutputFile("InitWithPath() test Failed."); + } + else + { + AfxMessageBox("We initialized file path."); + WriteToOutputFile("InitWithPath() test Passed."); + } + + rv = theTestFile->AppendRelativePath("myFile.txt"); + if (NS_FAILED(rv)) + { + AfxMessageBox("We failed to append the file."); + WriteToOutputFile("AppendRelativePath() test Failed."); + } + else + { + AfxMessageBox("We appended the file."); + WriteToOutputFile("AppendRelativePath() test Passed."); + } + + rv = theTestFile->Exists(&exists); + if (!exists) + { + AfxMessageBox("File doesn't exist. We'll try creating it."); + WriteToOutputFile("File doesn't exist. We'll try creating it.\r\n"); + rv = theTestFile->Create(nsIFile::NORMAL_FILE_TYPE, 0777); + if (NS_FAILED(rv)) + { + AfxMessageBox("We failed to create the file (myFile.txt)."); + WriteToOutputFile("Create() test Failed."); + } + else + { + AfxMessageBox("We created the file (myFile.txt)."); + WriteToOutputFile("Create() test Passed."); + } + } + else + { + AfxMessageBox("File already exists (myFile.txt). We won't create it."); + WriteToOutputFile("File already exists (myFile.txt). We won't create it."); + } + + + rv = theTestFile->Exists(&exists); + if (!exists) + { + AfxMessageBox("File (myFile.txt) doesn't exist."); + WriteToOutputFile("Exists() test Failed."); + } + else + { + AfxMessageBox("File (myFile.txt) exists."); + WriteToOutputFile("Exists() test Passed."); + } + + // FILE COPY test + + AfxMessageBox("Start File Copy test."); + WriteToOutputFile("Start File Copy test."); + + rv = theFileOpDir->InitWithPath("c:\\temp\\"); + if (NS_FAILED(rv)) + { + AfxMessageBox("The target dir wasn't found."); + WriteToOutputFile("The target dir wasn't found."); + } + else + { + AfxMessageBox("The target dir was found."); + WriteToOutputFile("The target dir was found."); + } + rv = theTestFile->InitWithPath("c:\\temp\\myFile.txt"); + if (NS_FAILED(rv)) + AfxMessageBox("The path wasn't found."); + else + AfxMessageBox("The path was found."); + rv = theTestFile->CopyTo(theFileOpDir, "myFile2.txt"); + if (NS_FAILED(rv)) + AfxMessageBox("rv CopyTo() test failed."); + else + AfxMessageBox("rv CopyTo() test succeeded."); + + rv = theTestFile->InitWithPath("c:\\temp\\myFile2.txt"); + rv = theTestFile->Exists(&exists); + if (!exists) + { + AfxMessageBox("File didn't copy."); + WriteToOutputFile("CopyTo() test Failed."); + } + else + { + AfxMessageBox("File copied."); + WriteToOutputFile("CopyTo() test Passed."); + } + + // FILE MOVE test + + AfxMessageBox("Start File Move test."); + WriteToOutputFile("Start File Move test."); + + rv = theFileOpDir->InitWithPath("c:\\Program Files\\"); + if (NS_FAILED(rv)) + { + AfxMessageBox("The target dir wasn't found."); + WriteToOutputFile("The target dir wasn't found."); + } + + rv = theTestFile->InitWithPath("c:\\temp\\myFile2.txt"); + if (NS_FAILED(rv)) + AfxMessageBox("The path wasn't found."); + + rv = theTestFile->MoveTo(theFileOpDir, "myFile2.txt"); + if (NS_FAILED(rv)) + AfxMessageBox("rv MoveTo() test failed."); + else + AfxMessageBox("rv MoveTo() test succeeded."); + rv = theTestFile->InitWithPath("c:\\Program Files\\myFile2.txt"); + rv = theTestFile->Exists(&exists); + if (!exists) + { + AfxMessageBox("File wasn't moved."); + WriteToOutputFile("MoveTo() test Failed."); + } + else + { + AfxMessageBox("File was moved."); + WriteToOutputFile("MoveTo() test Passed."); + } + + AfxMessageBox("End nsIFile tests."); + WriteToOutputFile("\r\nEnd testing nsIFile InitWithPath(), AppendRelativePath(), \ + Create(), and Exists() methods.\r\n"); + +} + +// nsISHistory: + +void CBrowserView::OnInterfacesNsishistory() +{ + nsresult rv; + boolean modifyIndex; + long numEntries = 0; + + nsCOMPtr theSessionHistory(do_CreateInstance(NS_SHISTORY_CONTRACTID)); + nsCOMPtr theHistoryEntry(do_CreateInstance(NS_HISTORYENTRY_CONTRACTID)); + nsCOMPtr theSHListener(do_CreateInstance(NS_SHISTORYLISTENER_CONTRACTID)); + // do_QueryInterface + // NS_HISTORYENTRY_CONTRACTID + // NS_SHISTORYLISTENER_CONTRACTID + + + if (!theSessionHistory) + { + AfxMessageBox("theSessionHistory object wasn't created. No tests performed."); + return; + } + if (!theHistoryEntry) + { + AfxMessageBox("NSISHistory Listener not added."); + return; + } + + // addSHistoryListener test + nsWeakPtr weakling( + dont_AddRef(NS_GetWeakReference(NS_STATIC_CAST(nsISHistoryListener*, mpBrowserImpl)))); + rv = mWebBrowser->AddWebBrowserListener(weakling, NS_GET_IID(nsISHistoryListener)); + + if (NS_FAILED(rv)) + { + AfxMessageBox("NSISHistory Listener not added."); + WriteToOutputFile("NSISHistory Listener not added.\r\n"); + } + else + { + AfxMessageBox("NSISHistory Listener added."); + WriteToOutputFile("NSISHistory Listener added.\r\n"); + } + +/* + // getEntryAtIndex() test + theHistoryEntry = theSessionHistory->GetEntryAtIndex(index, modifyIndex); + if (!theHistoryEntry) + { + AfxMessageBox("We got the History Entry."); + } + else + { + AfxMessageBox("We didn't get the History Entry."); + } + +*/ + +///* + // PurgeHistory() test + rv = theSessionHistory->PurgeHistory(numEntries); + if (NS_FAILED(rv)) + AfxMessageBox("Purge History test failed."); + else + AfxMessageBox("Purge History test succeeded."); +//*/ + + // RemoveSHistoryListener test +/* + nsWeakPtr weakling( + dont_AddRef(NS_GetWeakReference(NS_STATIC_CAST(nsISHistoryListener*, mpBrowserImpl)))); + rv = theSessionHistory->RemoveSHistoryListener(weakling); +*/ +} + + +// ***************** Local Methods ****************** + +void CBrowserView::WriteToOutputFile(char *pLine) +{ + CStdioFile myFile; + CFileException e; + CString strFileName = "c:\\temp\\MFCoutfile"; + + if(! myFile.Open( strFileName, CStdioFile::modeCreate | CStdioFile::modeWrite + | CStdioFile::modeNoTruncate, &e ) ) + { + CString failCause = "Unable to open file. Reason : "; + failCause += e.m_cause; + AfxMessageBox(failCause); + } + else + { + myFile.SeekToEnd(); + CString strLine = pLine; + strLine += "\r\n"; + + myFile.WriteString(strLine); + + myFile.Close(); + } +} + + +// ***************** Bug Verifications ****************** + +void CBrowserView::OnVerifybugs70228() +{ +/* + nsCOMPtr + myHALD(do_GetService(NS_IHELPERAPPLAUNCHERDLG_CONTRACTID)); + if (!myHALD) + AfxMessageBox("Object not created. It's NOT a service!"); + else + AfxMessageBox("Object is created. But should it?! It's NOT a service!"); + + nsCOMPtr + myHALD(do_CreateInstance(NS_IHELPERAPPLAUNCHERDLG_CONTRACTID)); + if (!myHALD) + AfxMessageBox("Object not created. It should be. It's a component!"); + else + AfxMessageBox("Object is created. It's a component!"); +*/ +/* +nsCOMPtr + myHAL(do_CreateInstance(NS_IHELPERAPPLAUNCHERDLG_CONTRACTID)); + + rv = myHALD->show(myHal, mySupp); +*/ +} diff --git a/mozilla/embedding/qa/testembed/BrowserView.h b/mozilla/embedding/qa/testembed/BrowserView.h new file mode 100644 index 00000000000..3a950df43f3 --- /dev/null +++ b/mozilla/embedding/qa/testembed/BrowserView.h @@ -0,0 +1,181 @@ +/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- + * + * The contents of this file are subject to the Netscape Public + * License Version 1.1 (the "License"); you may not use this file + * except in compliance with the License. You may obtain a copy of + * the License at http://www.mozilla.org/NPL/ + * + * Software distributed under the License is distributed on an "AS + * IS" basis, WITHOUT WARRANTY OF ANY KIND, either express or + * implied. See the License for the specific language governing + * rights and limitations under the License. + * + * The Original Code is mozilla.org code. + * + * The Initial Developer of the Original Code is Netscape + * Communications Corporation. Portions created by Netscape are + * Copyright (C) 1998 Netscape Communications Corporation. All + * Rights Reserved. + * + * Contributor(s): + * Chak Nanga + */ + +// BrowserView.h : interface of the CBrowserView class +// +///////////////////////////////////////////////////////////////////////////// + +#ifndef _BROWSERVIEW_H +#define _BROWSERVIEW_H + +#if _MSC_VER > 1000 + #pragma once +#endif + +#include "IBrowserFrameGlue.h" + +///////////////////////////////////////////////////////////////////////////// +// CBrowserView window + +class CBrowserFrame; +class CBrowserImpl; +class CFindDialog; +class CPrintProgressDialog; + +class CTests; + +class CBrowserView : public CWnd +{ +public: + CBrowserView(); + virtual ~CBrowserView(); + + // Some helper methods + HRESULT CreateBrowser(); + HRESULT DestroyBrowser(); + void OpenURL(const char* pUrl); + void OpenURL(const PRUnichar* pUrl); + CBrowserFrame* CreateNewBrowserFrame(PRUint32 chromeMask = nsIWebBrowserChrome::CHROME_ALL, + PRInt32 x = -1, PRInt32 y = -1, + PRInt32 cx = -1, PRInt32 cy = -1, + PRBool bShowWindow = PR_TRUE); + void OpenURLInNewWindow(const PRUnichar* pUrl); + void LoadHomePage(); + + void GetBrowserWindowTitle(nsCString& title); + + // Called by the CBrowserFrame after it creates the view + // Essentially a back pointer to the BrowserFrame + void SetBrowserFrame(CBrowserFrame* pBrowserFrame); + CBrowserFrame* mpBrowserFrame; + + // Called by the CBrowserFrame after it creates the view + // The view passes this on to the embedded Browser's Impl + // obj + void SetBrowserFrameGlue(PBROWSERFRAMEGLUE pBrowserFrameGlue); + PBROWSERFRAMEGLUE mpBrowserFrameGlue; + + // Pointer to the object which implements + // the inerfaces required by Mozilla embedders + // + CBrowserImpl* mpBrowserImpl; + + CTests *qaTests; + + // Mozilla interfaces + // + nsCOMPtr mWebBrowser; + nsCOMPtr mBaseWindow; + nsCOMPtr mWebNav; + + //nsCOMPtr mSessionHistory; // de: added in 5/11/01 + + void UpdateBusyState(PRBool aBusy); + PRBool mbDocumentLoading; + + void SetCtxMenuLinkUrl(nsAutoString& strLinkUrl); + nsAutoString mCtxMenuLinkUrl; + + void SetCtxMenuImageSrc(nsAutoString& strImgSrc); + nsAutoString mCtxMenuImgSrc; + + inline void ClearFindDialog() { m_pFindDlg = NULL; } + CFindDialog* m_pFindDlg; + CPrintProgressDialog* m_pPrintProgressDlg; + // When set to TRUE... + // indicates that the clipboard operation needs to be + // performed on the UrlBar rather than on + // the web page content + // + BOOL m_bUrlBarClipOp; + + // indicates whether we are currently printing + BOOL m_bCurrentlyPrinting; + + void Activate(UINT nState, CWnd* pWndOther, BOOL bMinimized); + + BOOL OpenViewSourceWindow(const char* pUrl); + BOOL IsViewSourceUrl(CString& strUrl); + + // Overrides + // ClassWizard generated virtual function overrides + //{{AFX_VIRTUAL(CBrowserView) + + + // de: qa methods + static void WriteToOutputFile(char * strInput); + static char *theUrl; + static void RvTestResult(nsresult rv, char *pLine, int displayMethod=1); + static void QAOutput(char *pLine, int displayMethod=1); + + public: + virtual BOOL OnCmdMsg(UINT nID, int nCode, void* pExtra, AFX_CMDHANDLERINFO* pHandlerInfo); + protected: + virtual BOOL PreCreateWindow(CREATESTRUCT& cs); + //}}AFX_VIRTUAL + + + // Generated message map functions +protected: + //{{AFX_MSG(CBrowserView) + afx_msg int OnCreate(LPCREATESTRUCT lpCreateStruct); + afx_msg void OnDestroy(); + afx_msg void OnSize( UINT, int, int ); + afx_msg void OnUrlSelectedInUrlBar(); + afx_msg void OnNewUrlEnteredInUrlBar(); + afx_msg void OnFileOpen(); + afx_msg void OnFileSaveAs(); + afx_msg void OnViewSource(); + afx_msg void OnViewInfo(); + afx_msg void OnNavBack(); + afx_msg void OnNavForward(); + afx_msg void OnNavHome(); + afx_msg void OnNavReload(); + afx_msg void OnNavStop(); + afx_msg void OnCut(); + afx_msg void OnCopy(); + afx_msg void OnPaste(); + afx_msg void OnUndoUrlBarEditOp(); + afx_msg void OnSelectAll(); + afx_msg void OnSelectNone(); + afx_msg void OnCopyLinkLocation(); + afx_msg void OnOpenLinkInNewWindow(); + afx_msg void OnViewImageInNewWindow(); + afx_msg void OnSaveLinkAs(); + afx_msg void OnSaveImageAs(); + afx_msg void OnShowFindDlg(); + afx_msg void OnFilePrint(); + afx_msg void OnUpdateFilePrint(CCmdUI* pCmdUI); + afx_msg LRESULT OnFindMsg(WPARAM wParam, LPARAM lParam); + afx_msg void OnUpdateNavBack(CCmdUI* pCmdUI); + afx_msg void OnUpdateNavForward(CCmdUI* pCmdUI); + afx_msg void OnUpdateNavStop(CCmdUI* pCmdUI); + afx_msg void OnUpdateCut(CCmdUI* pCmdUI); + afx_msg void OnUpdateCopy(CCmdUI* pCmdUI); + afx_msg void OnUpdatePaste(CCmdUI* pCmdUI); + + //}}AFX_MSG + DECLARE_MESSAGE_MAP() +}; + +#endif //_BROWSERVIEW_H diff --git a/mozilla/embedding/qa/testembed/Dialogs.cpp b/mozilla/embedding/qa/testembed/Dialogs.cpp new file mode 100644 index 00000000000..a77f9c97ac2 --- /dev/null +++ b/mozilla/embedding/qa/testembed/Dialogs.cpp @@ -0,0 +1,107 @@ +/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- + * + * The contents of this file are subject to the Netscape Public + * License Version 1.1 (the "License"); you may not use this file + * except in compliance with the License. You may obtain a copy of + * the License at http://www.mozilla.org/NPL/ + * + * Software distributed under the License is distributed on an "AS + * IS" basis, WITHOUT WARRANTY OF ANY KIND, either express or + * implied. See the License for the specific language governing + * rights and limitations under the License. + * + * The Original Code is mozilla.org code. + * + * The Initial Developer of the Original Code is Netscape + * Communications Corporation. Portions created by Netscape are + * Copyright (C) 1998 Netscape Communications Corporation. All + * Rights Reserved. + * + * Contributor(s): + * Chak Nanga + */ + +#include "stdafx.h" +#include "Dialogs.h" +#include "BrowserView.h" + +// File overview.... +// +// contains Find dialog box code +// + +//--------------------------------------------------------------------------// +// CFindDialog Stuff +//--------------------------------------------------------------------------// + +CFindDialog::CFindDialog(CString& csSearchStr, PRBool bMatchCase, + PRBool bMatchWholeWord, PRBool bWrapAround, + PRBool bSearchBackwards, CBrowserView* pOwner) + : CFindReplaceDialog() +{ + // Save these initial settings off in member vars + // We'll use these to initialize the controls + // in InitDialog() + m_csSearchStr = csSearchStr; + m_bMatchCase = bMatchCase; + m_bMatchWholeWord = bMatchWholeWord; + m_bWrapAround = bWrapAround; + m_bSearchBackwards = bSearchBackwards; + m_pOwner = pOwner; + + // Set up to load our customized Find dialog template + // rather than the default one MFC provides + m_fr.Flags |= FR_ENABLETEMPLATE; + m_fr.hInstance = AfxGetInstanceHandle(); + m_fr.lpTemplateName = MAKEINTRESOURCE(IDD_FINDDLG); +} + +BOOL CFindDialog::OnInitDialog() +{ + CFindReplaceDialog::OnInitDialog(); + + CEdit* pEdit = (CEdit *)GetDlgItem(IDC_FIND_EDIT); + if(pEdit) + pEdit->SetWindowText(m_csSearchStr); + + CButton* pChk = (CButton *)GetDlgItem(IDC_MATCH_CASE); + if(pChk) + pChk->SetCheck(m_bMatchCase); + + pChk = (CButton *)GetDlgItem(IDC_MATCH_WHOLE_WORD); + if(pChk) + pChk->SetCheck(m_bMatchWholeWord); + + pChk = (CButton *)GetDlgItem(IDC_WRAP_AROUND); + if(pChk) + pChk->SetCheck(m_bWrapAround); + + pChk = (CButton *)GetDlgItem(IDC_SEARCH_BACKWARDS); + if(pChk) + pChk->SetCheck(m_bSearchBackwards); + + return TRUE; +} + +void CFindDialog::PostNcDestroy() +{ + // Let the owner know we're gone + if(m_pOwner != NULL) + m_pOwner->ClearFindDialog(); + + CFindReplaceDialog::PostNcDestroy(); +} + +BOOL CFindDialog::WrapAround() +{ + CButton* pChk = (CButton *)GetDlgItem(IDC_WRAP_AROUND); + + return pChk ? pChk->GetCheck() : FALSE; +} + +BOOL CFindDialog::SearchBackwards() +{ + CButton* pChk = (CButton *)GetDlgItem(IDC_SEARCH_BACKWARDS); + + return pChk ? pChk->GetCheck() : FALSE; +} diff --git a/mozilla/embedding/qa/testembed/Dialogs.h b/mozilla/embedding/qa/testembed/Dialogs.h new file mode 100644 index 00000000000..98b257ea3ee --- /dev/null +++ b/mozilla/embedding/qa/testembed/Dialogs.h @@ -0,0 +1,53 @@ +/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- + * + * The contents of this file are subject to the Netscape Public + * License Version 1.1 (the "License"); you may not use this file + * except in compliance with the License. You may obtain a copy of + * the License at http://www.mozilla.org/NPL/ + * + * Software distributed under the License is distributed on an "AS + * IS" basis, WITHOUT WARRANTY OF ANY KIND, either express or + * implied. See the License for the specific language governing + * rights and limitations under the License. + * + * The Original Code is mozilla.org code. + * + * The Initial Developer of the Original Code is Netscape + * Communications Corporation. Portions created by Netscape are + * Copyright (C) 1998 Netscape Communications Corporation. All + * Rights Reserved. + * + * Contributor(s): + * Chak Nanga + */ + +#ifndef _DIALOGS_H_ +#define _DIALOGS_H_ + +#include "resource.h" + +class CBrowserView; + +class CFindDialog : public CFindReplaceDialog +{ +public: + CFindDialog(CString& csSearchStr, PRBool bMatchCase, + PRBool bMatchWholeWord, PRBool bWrapAround, + PRBool bSearchBackwards, CBrowserView* pOwner); + BOOL WrapAround(); + BOOL SearchBackwards(); + +private: + CString m_csSearchStr; + PRBool m_bMatchCase; + PRBool m_bMatchWholeWord; + PRBool m_bWrapAround; + PRBool m_bSearchBackwards; + CBrowserView* m_pOwner; + +protected: + virtual BOOL OnInitDialog(); + virtual void PostNcDestroy(); +}; + +#endif //_DIALOG_H_ diff --git a/mozilla/embedding/qa/testembed/IBrowserFrameGlue.h b/mozilla/embedding/qa/testembed/IBrowserFrameGlue.h new file mode 100644 index 00000000000..c4e5af4685e --- /dev/null +++ b/mozilla/embedding/qa/testembed/IBrowserFrameGlue.h @@ -0,0 +1,96 @@ +/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- + * + * The contents of this file are subject to the Netscape Public + * License Version 1.1 (the "License"); you may not use this file + * except in compliance with the License. You may obtain a copy of + * the License at http://www.mozilla.org/NPL/ + * + * Software distributed under the License is distributed on an "AS + * IS" basis, WITHOUT WARRANTY OF ANY KIND, either express or + * implied. See the License for the specific language governing + * rights and limitations under the License. + * + * The Original Code is mozilla.org code. + * + * The Initial Developer of the Original Code is Netscape + * Communications Corporation. Portions created by Netscape are + * Copyright (C) 1998 Netscape Communications Corporation. All + * Rights Reserved. + * + * Contributor(s): + * Chak Nanga + */ + +// This interface acts as a glue between the required/optional +// Gecko embedding interfaces and the actual platform specific +// way of doing things - such as updating a statusbar etc. +// +// For ex, in the mfcembed sample the required interfaces such as +// IWebBrowserChrome etc. are implemented in a XP way in the +// BrowserImp*.cpp files. However, when they get called to update the +// statusbar etc. they call on this interface to get the actual job +// done. During the BrowserFrame creation some object must implement +// this interface and pass the pointer to it via the Init() member of +// the CBrowserImpl class + +#ifndef _IBROWSERFRAMEGLUE_H +#define _IBROWSERFRAMEGLUE_H + +struct IBrowserFrameGlue { + // Progress Related Methods + virtual void UpdateStatusBarText(const PRUnichar *aMessage) = 0; + virtual void UpdateProgress(PRInt32 aCurrent, PRInt32 aMax) = 0; + virtual void UpdateBusyState(PRBool aBusy) = 0; + virtual void UpdateCurrentURI(nsIURI *aLocation) = 0; + + // BrowserFrame Related Methods + virtual PRBool CreateNewBrowserFrame(PRUint32 chromeMask, + PRInt32 x, PRInt32 y, + PRInt32 cx, PRInt32 cy, + nsIWebBrowser ** aWebBrowser) = 0; + virtual void DestroyBrowserFrame() = 0; + virtual void GetBrowserFrameTitle(PRUnichar **aTitle) = 0; + virtual void SetBrowserFrameTitle(const PRUnichar *aTitle) = 0; + virtual void GetBrowserFramePosition(PRInt32 *aX, PRInt32 *aY) = 0; + virtual void SetBrowserFramePosition(PRInt32 aX, PRInt32 aY) = 0; + virtual void GetBrowserFrameSize(PRInt32 *aCX, PRInt32 *aCY) = 0; + virtual void SetBrowserFrameSize(PRInt32 aCX, PRInt32 aCY) = 0; + virtual void GetBrowserFramePositionAndSize(PRInt32 *aX, PRInt32 *aY, PRInt32 *aCX, PRInt32 *aCY) = 0; + virtual void SetBrowserFramePositionAndSize(PRInt32 aX, PRInt32 aY, PRInt32 aCX, PRInt32 aCY, PRBool fRepaint) = 0; + virtual void ShowBrowserFrame(PRBool aShow) = 0; + virtual void SetFocus() = 0; + virtual void FocusAvailable(PRBool *aFocusAvail) = 0; + virtual void GetBrowserFrameVisibility(PRBool *aVisible) = 0; + + // ContextMenu Related Methods + virtual void ShowContextMenu(PRUint32 aContextFlags, nsIDOMNode *aNode) = 0; + + virtual HWND GetBrowserFrameNativeWnd() = 0; +}; + +#define NS_DECL_BROWSERFRAMEGLUE \ + public: \ + virtual void UpdateStatusBarText(const PRUnichar *aMessage); \ + virtual void UpdateProgress(PRInt32 aCurrent, PRInt32 aMax); \ + virtual void UpdateBusyState(PRBool aBusy); \ + virtual void UpdateCurrentURI(nsIURI *aLocation); \ + virtual PRBool CreateNewBrowserFrame(PRUint32 chromeMask, PRInt32 x, PRInt32 y, PRInt32 cx, PRInt32 cy, nsIWebBrowser** aWebBrowser); \ + virtual void DestroyBrowserFrame(); \ + virtual void GetBrowserFrameTitle(PRUnichar **aTitle); \ + virtual void SetBrowserFrameTitle(const PRUnichar *aTitle); \ + virtual void GetBrowserFramePosition(PRInt32 *aX, PRInt32 *aY); \ + virtual void SetBrowserFramePosition(PRInt32 aX, PRInt32 aY); \ + virtual void GetBrowserFrameSize(PRInt32 *aCX, PRInt32 *aCY); \ + virtual void SetBrowserFrameSize(PRInt32 aCX, PRInt32 aCY); \ + virtual void GetBrowserFramePositionAndSize(PRInt32 *aX, PRInt32 *aY, PRInt32 *aCX, PRInt32 *aCY); \ + virtual void SetBrowserFramePositionAndSize(PRInt32 aX, PRInt32 aY, PRInt32 aCX, PRInt32 aCY, PRBool fRepaint); \ + virtual void ShowBrowserFrame(PRBool aShow); \ + virtual void SetFocus(); \ + virtual void FocusAvailable(PRBool *aFocusAvail); \ + virtual void GetBrowserFrameVisibility(PRBool *aVisible); \ + virtual void ShowContextMenu(PRUint32 aContextFlags, nsIDOMNode *aNode); \ + virtual HWND GetBrowserFrameNativeWnd(); + +typedef IBrowserFrameGlue *PBROWSERFRAMEGLUE; + +#endif //_IBROWSERFRAMEGLUE_H diff --git a/mozilla/embedding/qa/testembed/MostRecentUrls.cpp b/mozilla/embedding/qa/testembed/MostRecentUrls.cpp new file mode 100644 index 00000000000..78b14be3994 --- /dev/null +++ b/mozilla/embedding/qa/testembed/MostRecentUrls.cpp @@ -0,0 +1,135 @@ +/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- + * + * The contents of this file are subject to the Netscape Public + * License Version 1.1 (the "License"); you may not use this file + * except in compliance with the License. You may obtain a copy of + * the License at http://www.mozilla.org/NPL/ + * + * Software distributed under the License is distributed on an "AS + * IS" basis, WITHOUT WARRANTY OF ANY KIND, either express or + * implied. See the License for the specific language governing + * rights and limitations under the License. + * + * The Original Code is mozilla.org code. + * + * The Initial Developer of the Original Code is Netscape + * Communications Corporation. Portions created by Netscape are + * Copyright (C) 1998 Netscape Communications Corporation. All + * Rights Reserved. + * + * Contributor(s): + * Rod Spears + */ + +// +// CMostRecentUrls object is responsible for keeping track of the +// 16 most recently used URLs. It stores this list in a file named +// "urls.txt" on a per profile basis in the user's profile directory +// +// The constructor loads the URL list +// The destructor saves the URL list +// + +#include "StdAfx.h" +#include "nsIFile.h" +#include "nsILocalFile.h" +#include "nsAppDirectoryServiceDefs.h" +#include "MostRecentUrls.h" + +//-------------------------------------------------------- +//-- CMostRecentUrls +//-------------------------------------------------------- +CMostRecentUrls::CMostRecentUrls() : + mNumURLs(0) +{ + for (int i=0;i 1) { + line[strlen(line)-1] = 0; + mURLs[mNumURLs++] = _strdup(line); + } + } + fclose(fd); + } + +} + +FILE * CMostRecentUrls::GetFD(const char * aMode) +{ + FILE * fd = nsnull; + nsCOMPtr file; + nsresult rv = NS_GetSpecialDirectory(NS_APP_USER_PROFILE_50_DIR, getter_AddRefs(file)); + if (NS_SUCCEEDED(rv)) { + nsCOMPtr local_file(do_QueryInterface(file)); + local_file->Append("urls.txt"); + local_file->OpenANSIFileDesc(aMode, &fd); + } + + return fd; +} + +CMostRecentUrls::~CMostRecentUrls() +{ + FILE * fd = GetFD("w"); + if (fd) { + for (int i=0;i0; i--) + { + if(mURLs[i]) + free(mURLs[i]); + + if(mURLs[i-1]) + mURLs[i] = _strdup(mURLs[i-1]); + } + + // place this url at the top + if(mURLs[0]) + free(mURLs[0]); + mURLs[0] = _strdup(szTemp); +} diff --git a/mozilla/embedding/qa/testembed/MostRecentUrls.h b/mozilla/embedding/qa/testembed/MostRecentUrls.h new file mode 100644 index 00000000000..6322e5e61ad --- /dev/null +++ b/mozilla/embedding/qa/testembed/MostRecentUrls.h @@ -0,0 +1,41 @@ +/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- + * + * The contents of this file are subject to the Netscape Public + * License Version 1.1 (the "License"); you may not use this file + * except in compliance with the License. You may obtain a copy of + * the License at http://www.mozilla.org/NPL/ + * + * Software distributed under the License is distributed on an "AS + * IS" basis, WITHOUT WARRANTY OF ANY KIND, either express or + * implied. See the License for the specific language governing + * rights and limitations under the License. + * + * The Original Code is mozilla.org code. + * + * The Initial Developer of the Original Code is Netscape + * Communications Corporation. Portions created by Netscape are + * Copyright (C) 1998 Netscape Communications Corporation. All + * Rights Reserved. + * + * Contributor(s): + * Rod Spears + */ + +class CMostRecentUrls { +public: + enum _maxUrls { + MAX_URLS = 16 + }; + + CMostRecentUrls(); + virtual ~CMostRecentUrls(); + + char * GetURL(int aInx); + void AddURL(const char * aURL); + inline int GetNumURLs() { return mNumURLs; } + FILE * CMostRecentUrls::GetFD(const char * aMode); + +protected: + char * mURLs[MAX_URLS]; + int mNumURLs; +}; diff --git a/mozilla/embedding/qa/testembed/Preferences.cpp b/mozilla/embedding/qa/testembed/Preferences.cpp new file mode 100644 index 00000000000..027af1de00f --- /dev/null +++ b/mozilla/embedding/qa/testembed/Preferences.cpp @@ -0,0 +1,99 @@ +/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- + * + * The contents of this file are subject to the Netscape Public + * License Version 1.1 (the "License"); you may not use this file + * except in compliance with the License. You may obtain a copy of + * the License at http://www.mozilla.org/NPL/ + * + * Software distributed under the License is distributed on an "AS + * IS" basis, WITHOUT WARRANTY OF ANY KIND, either express or + * implied. See the License for the specific language governing + * rights and limitations under the License. + * + * The Original Code is mozilla.org code. + * + * The Initial Developer of the Original Code is Netscape + * Communications Corporation. Portions created by Netscape are + * Copyright (C) 1998 Netscape Communications Corporation. All + * Rights Reserved. + * + * Contributor(s): + * Chak Nanga + */ + +#include "stdafx.h" +#include "Preferences.h" + +#ifdef _DEBUG +#define new DEBUG_NEW +#undef THIS_FILE +static char THIS_FILE[] = __FILE__; +#endif + +///////////////////////////////////////////////////////////////// +// CPreferences + +IMPLEMENT_DYNAMIC(CPreferences, CPropertySheet) + +CPreferences::CPreferences(LPCTSTR pszCaption, CWnd* pParentWnd, UINT iSelectPage) + :CPropertySheet(pszCaption, pParentWnd, iSelectPage) +{ + AddPage(&m_startupPage); +} + +CPreferences::~CPreferences() +{ +} + +BEGIN_MESSAGE_MAP(CPreferences, CPropertySheet) + //{{AFX_MSG_MAP(CPreferences) + // NOTE - the ClassWizard will add and remove mapping macros here. + //}}AFX_MSG_MAP +END_MESSAGE_MAP() + + +BOOL CPreferences::OnInitDialog() +{ + BOOL bResult = CPropertySheet::OnInitDialog(); + + // Hide the Apply button + CWnd* pApplyButton = GetDlgItem(ID_APPLY_NOW); + ASSERT(pApplyButton); + pApplyButton->ShowWindow(SW_HIDE); + + return bResult; +} + + +///////////////////////////////////////////////////////////////// +// CStartupPrefsPage property page + +IMPLEMENT_DYNCREATE(CStartupPrefsPage, CPropertyPage) + +CStartupPrefsPage::CStartupPrefsPage() : CPropertyPage(CStartupPrefsPage::IDD) +{ + //{{AFX_DATA_INIT(CStartupPrefsPage) + m_strHomePage = _T(""); + m_iStartupPage = -1; + //}}AFX_DATA_INIT +} + +CStartupPrefsPage::~CStartupPrefsPage() +{ +} + +void CStartupPrefsPage::DoDataExchange(CDataExchange* pDX) +{ + CPropertyPage::DoDataExchange(pDX); + //{{AFX_DATA_MAP(CStartupPrefsPage) + DDX_Control(pDX, IDC_EDIT_HOMEPAGE, m_HomePage); + DDX_Text(pDX, IDC_EDIT_HOMEPAGE, m_strHomePage); + DDX_Radio(pDX, IDC_RADIO_BLANK_PAGE, m_iStartupPage); + //}}AFX_DATA_MAP +} + + +BEGIN_MESSAGE_MAP(CStartupPrefsPage, CPropertyPage) + //{{AFX_MSG_MAP(CStartupPrefsPage) + //}}AFX_MSG_MAP +END_MESSAGE_MAP() diff --git a/mozilla/embedding/qa/testembed/Preferences.h b/mozilla/embedding/qa/testembed/Preferences.h new file mode 100644 index 00000000000..58430512a05 --- /dev/null +++ b/mozilla/embedding/qa/testembed/Preferences.h @@ -0,0 +1,110 @@ +/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 2 -*- + * + * The contents of this file are subject to the Netscape Public + * License Version 1.1 (the "License"); you may not use this file + * except in compliance with the License. You may obtain a copy of + * the License at http://www.mozilla.org/NPL/ + * + * Software distributed under the License is distributed on an "AS + * IS" basis, WITHOUT WARRANTY OF ANY KIND, either express or + * implied. See the License for the specific language governing + * rights and limitations under the License. + * + * The Original Code is mozilla.org code. + * + * The Initial Developer of the Original Code is Netscape + * Communications Corporation. Portions created by Netscape are + * Copyright (C) 1998 Netscape Communications Corporation. All + * Rights Reserved. + * + * Contributor(s): + * Chak Nanga + */ + +#ifndef _PREFERENCES_H_ +#define _PREFERENCES_H_ + +#include "resource.h" + +#if _MSC_VER > 1000 +#pragma once +#endif // _MSC_VER > 1000 + +///////////////////////////////////////////////////////////////////////////// +// CStartupPrefsPage dialog + +class CStartupPrefsPage : public CPropertyPage +{ + DECLARE_DYNCREATE(CStartupPrefsPage) + +// Construction +public: + CStartupPrefsPage(); + ~CStartupPrefsPage(); + +// Dialog Data + //{{AFX_DATA(CStartupPrefsPage) + enum { IDD = IDD_PREFS_START_PAGE }; + CEdit m_HomePage; + CString m_strHomePage; + int m_iStartupPage; + //}}AFX_DATA + + +// Overrides + // ClassWizard generate virtual function overrides + //{{AFX_VIRTUAL(CStartupPrefsPage) + protected: + virtual void DoDataExchange(CDataExchange* pDX); // DDX/DDV support + //}}AFX_VIRTUAL + +// Implementation +protected: + // Generated message map functions + //{{AFX_MSG(CStartupPrefsPage) + //}}AFX_MSG + DECLARE_MESSAGE_MAP() + +}; + +///////////////////////////////////////////////////////////////////////////// +// CPreferences + +class CPreferences : public CPropertySheet +{ + DECLARE_DYNAMIC(CPreferences) + +// Construction +public: + CPreferences(LPCTSTR pszCaption, CWnd* pParentWnd = NULL, UINT iSelectPage = 0); + +// Attributes +public: + CStartupPrefsPage m_startupPage; + +// Operations +public: + +// Overrides + // ClassWizard generated virtual function overrides + //{{AFX_VIRTUAL(CPreferences) + public: + virtual BOOL OnInitDialog(); + //}}AFX_VIRTUAL + +// Implementation +public: + virtual ~CPreferences(); + + // Generated message map functions +protected: + //{{AFX_MSG(CPreferences) + // NOTE - the ClassWizard will add and remove member functions here. + //}}AFX_MSG + DECLARE_MESSAGE_MAP() +}; + +//{{AFX_INSERT_LOCATION}} +// Microsoft Visual C++ will insert additional declarations immediately before the previous line. + +#endif // _PREFERENCES_H_ diff --git a/mozilla/embedding/qa/testembed/PrintProgressDialog.cpp b/mozilla/embedding/qa/testembed/PrintProgressDialog.cpp new file mode 100644 index 00000000000..89d82042036 --- /dev/null +++ b/mozilla/embedding/qa/testembed/PrintProgressDialog.cpp @@ -0,0 +1,246 @@ +// PrintProgressDialog.cpp : implementation file +// + +#include "stdafx.h" +#include "Testembed.h" +#include "PrintProgressDialog.h" +#include "BrowserView.h" +#include "nsIWebBrowser.h" +#include "nsIWebBrowserPrint.h" + +#ifdef _DEBUG +#define new DEBUG_NEW +#undef THIS_FILE +static char THIS_FILE[] = __FILE__; +#endif + +///////////////////////////////////////////////////////////////////////////// +// CPrintProgressDialog dialog + +class CDlgPrintListener : public nsIPrintListener +{ +// Construction +public: + CDlgPrintListener(CPrintProgressDialog* aDlg); + + NS_DECL_ISUPPORTS + NS_DECL_NSIPRINTLISTENER + + void ClearDlg() { m_PrintDlg = NULL; } // weak reference + +// Implementation +protected: + CPrintProgressDialog* m_PrintDlg; +}; + +NS_IMPL_ADDREF(CDlgPrintListener) +NS_IMPL_RELEASE(CDlgPrintListener) + +NS_INTERFACE_MAP_BEGIN(CDlgPrintListener) + NS_INTERFACE_MAP_ENTRY_AMBIGUOUS(nsISupports, nsIPrintListener) + NS_INTERFACE_MAP_ENTRY(nsIPrintListener) +NS_INTERFACE_MAP_END + + +CDlgPrintListener::CDlgPrintListener(CPrintProgressDialog* aDlg) : + m_PrintDlg(aDlg) +{ + NS_INIT_ISUPPORTS(); + //NS_ADDREF_THIS(); +} + +/* void OnStartPrinting (); */ +NS_IMETHODIMP +CDlgPrintListener::OnStartPrinting() +{ + if (m_PrintDlg) { + return m_PrintDlg->OnStartPrinting(); + } + return NS_OK; +} + +/* void OnProgressPrinting (in PRUint32 aProgress, in PRUint32 aProgressMax); */ +NS_IMETHODIMP +CDlgPrintListener::OnProgressPrinting(PRUint32 aProgress, PRUint32 aProgressMax) +{ + if (m_PrintDlg) { + return m_PrintDlg->OnProgressPrinting(aProgress, aProgressMax); + } + return NS_OK; +} + +/* void OnEndPrinting (in PRUint32 aStatus); */ +NS_IMETHODIMP +CDlgPrintListener::OnEndPrinting(PRUint32 aStatus) +{ + if (m_PrintDlg) { + return m_PrintDlg->OnEndPrinting(aStatus); + } + return NS_OK; +} + +///////////////////////////////////////////////////////////////////////////// +// CPrintProgressDialog dialog + + +CPrintProgressDialog::CPrintProgressDialog(nsIWebBrowser* aWebBrowser, + nsIDOMWindow* aDOMWin, + CWnd* pParent /*=NULL*/) + : CDialog(CPrintProgressDialog::IDD, pParent), + m_WebBrowser(aWebBrowser), + m_DOMWin(aDOMWin), + m_PrintListener(nsnull), + m_InModalMode(PR_FALSE) +{ + //{{AFX_DATA_INIT(CPrintProgressDialog) + // NOTE: the ClassWizard will add member initialization here + //}}AFX_DATA_INIT +} + +CPrintProgressDialog::~CPrintProgressDialog() +{ + CDlgPrintListener * pl = (CDlgPrintListener*)m_PrintListener.get(); + if (pl) { + pl->ClearDlg(); + } +} + + +void CPrintProgressDialog::DoDataExchange(CDataExchange* pDX) +{ + CDialog::DoDataExchange(pDX); + //{{AFX_DATA_MAP(CPrintProgressDialog) + // NOTE: the ClassWizard will add DDX and DDV calls here + //}}AFX_DATA_MAP +} + + +BEGIN_MESSAGE_MAP(CPrintProgressDialog, CDialog) + //{{AFX_MSG_MAP(CPrintProgressDialog) + //}}AFX_MSG_MAP +END_MESSAGE_MAP() + +///////////////////////////////////////////////////////////////////////////// +// CPrintProgressDialog message handlers +static void GetLocalRect(CWnd * aWnd, CRect& aRect, CWnd * aParent) +{ + CRect wr; + aParent->GetWindowRect(wr); + + CRect cr; + aParent->GetClientRect(cr); + + aWnd->GetWindowRect(aRect); + + int borderH = wr.Height() - cr.Height(); + int borderW = (wr.Width() - cr.Width())/2; + aRect.top -= wr.top+borderH-borderW; + aRect.left -= wr.left+borderW; + aRect.right -= wr.left+borderW; + aRect.bottom -= wr.top+borderH-borderW; + +} + +BOOL CPrintProgressDialog::OnInitDialog() +{ + CDialog::OnInitDialog(); + + CRect clientRect; + GetClientRect(&clientRect); + + CRect titleRect; + GetLocalRect(GetDlgItem(IDC_PPD_DOC_TITLE_STATIC), titleRect, this); + + CRect itemRect; + GetLocalRect(GetDlgItem(IDC_PPD_DOC_TXT), itemRect, this); + + CRect progRect; + progRect.left = titleRect.left; + progRect.top = itemRect.top+itemRect.Height()+5; + progRect.right = clientRect.Width()-(2*titleRect.left); + progRect.bottom = progRect.top+titleRect.Height(); + + + m_wndProgress.Create (WS_CHILD | WS_VISIBLE, progRect, this, -1); + m_wndProgress.SetPos (0); + + return TRUE; // return TRUE unless you set the focus to a control + // EXCEPTION: OCX Property Pages should return FALSE +} + + +int CPrintProgressDialog::DoModal( ) +{ + PRBool doModal = PR_FALSE; + nsCOMPtr print(do_GetInterface(m_WebBrowser)); + if(print) + { + m_PrintListener = new CDlgPrintListener(this); // constructor addrefs + if (m_PrintListener) { + // doModal will be set to false if the print job was cancelled + doModal = NS_SUCCEEDED(print->Print(m_DOMWin, nsnull, m_PrintListener)) == PR_TRUE; + } + } + + if (doModal) { + m_InModalMode = PR_TRUE; + return CDialog::DoModal(); + } + return 0; +} + + +/* void OnStartPrinting (); */ +NS_IMETHODIMP +CPrintProgressDialog::OnStartPrinting() +{ + return NS_OK; +} + +/* void OnProgressPrinting (in PRUint32 aProgress, in PRUint32 aProgressMax); */ +NS_IMETHODIMP +CPrintProgressDialog::OnProgressPrinting(PRUint32 aProgress, PRUint32 aProgressMax) +{ + // Initialize the progress meter we we get the "zero" progress + // which also tells us the max progress + if (aProgress == 0) { + CWnd *pWnd = GetDlgItem(IDC_PPD_DOC_TXT); + if(pWnd) + pWnd->SetWindowText(m_URL); + + m_wndProgress.SetRange(0, aProgressMax); + m_wndProgress.SetPos(0); + } + m_wndProgress.SetPos(aProgress); + RedrawWindow(NULL, NULL, RDW_INVALIDATE | RDW_UPDATENOW); + + return NS_OK; +} + +/* void OnEndPrinting (in PRUint32 aStatus); */ +NS_IMETHODIMP +CPrintProgressDialog::OnEndPrinting(PRUint32 aStatus) +{ + // Here we need to know whether we have gone "modal" + // because we could get notified here if the user cancels + // before we ever get a chance to go into the modal loop + if (m_InModalMode) { + EndDialog(1); + } + return NS_OK; +} + +void CPrintProgressDialog::OnCancel() +{ + nsCOMPtr print(do_GetInterface(m_WebBrowser)); + if (print) { + print->Cancel(); + } + + CDialog::OnCancel(); +} + +void CPrintProgressDialog::SetURI(const char* aTitle) +{ + m_URL = _T(aTitle); +} diff --git a/mozilla/embedding/qa/testembed/PrintProgressDialog.h b/mozilla/embedding/qa/testembed/PrintProgressDialog.h new file mode 100644 index 00000000000..e5f081d03d8 --- /dev/null +++ b/mozilla/embedding/qa/testembed/PrintProgressDialog.h @@ -0,0 +1,70 @@ +#if !defined(AFX_PRINTPROGRESSDIALOG_H__1BAF9B13_1875_11D5_9773_000064657374__INCLUDED_) +#define AFX_PRINTPROGRESSDIALOG_H__1BAF9B13_1875_11D5_9773_000064657374__INCLUDED_ + +#if _MSC_VER > 1000 +#pragma once +#endif // _MSC_VER > 1000 +// PrintProgressDialog.h : header file +// + +#include "nsIPrintListener.h" +class nsIWebBrowser; +class nsIDOMWindow; +class nsIPrintListener; + +///////////////////////////////////////////////////////////////////////////// +// CPrintProgressDialog dialog + +class CPrintProgressDialog : public CDialog +{ +// Construction +public: + CPrintProgressDialog(nsIWebBrowser* aWebBrowser, + nsIDOMWindow* aDOMWin, + CWnd* pParent = NULL); + virtual ~CPrintProgressDialog(); + virtual int DoModal( ); + + // Helper + void SetURI(const char* aTitle); + + // same as nsIPrintListener + NS_IMETHOD OnStartPrinting(void); + NS_IMETHOD OnProgressPrinting(PRUint32 aProgress, PRUint32 aProgressMax); + NS_IMETHOD OnEndPrinting(PRUint32 aStatus); + +// Dialog Data + //{{AFX_DATA(CPrintProgressDialog) + enum { IDD = IDD_PRINT_PROGRESS_DIALOG }; + // NOTE: the ClassWizard will add data members here + //}}AFX_DATA + + +// Overrides + // ClassWizard generated virtual function overrides + //{{AFX_VIRTUAL(CPrintProgressDialog) + protected: + virtual void DoDataExchange(CDataExchange* pDX); // DDX/DDV support + //}}AFX_VIRTUAL + +// Implementation +protected: + CProgressCtrl m_wndProgress; + CString m_URL; + nsIWebBrowser* m_WebBrowser; + nsIDOMWindow* m_DOMWin; + nsCOMPtr m_PrintListener; + BOOL m_InModalMode; + + // Generated message map functions + //{{AFX_MSG(CPrintProgressDialog) + virtual BOOL OnInitDialog(); + virtual void OnCancel(); + //}}AFX_MSG + DECLARE_MESSAGE_MAP() +}; + +//{{AFX_INSERT_LOCATION}} +// Microsoft Visual C++ will insert additional declarations immediately before the previous line. + +#endif // !defined(AFX_PRINTPROGRESSDIALOG_H__1BAF9B13_1875_11D5_9773_000064657374__INCLUDED_) diff --git a/mozilla/embedding/qa/testembed/ProfileMgr.cpp b/mozilla/embedding/qa/testembed/ProfileMgr.cpp new file mode 100644 index 00000000000..f0db7b975bc --- /dev/null +++ b/mozilla/embedding/qa/testembed/ProfileMgr.cpp @@ -0,0 +1,189 @@ +/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 2 -*- + * + * The contents of this file are subject to the Mozilla Public + * License Version 1.1 (the "License"); you may not use this file + * except in compliance with the License. You may obtain a copy of + * the License at http://www.mozilla.org/MPL/ + * + * Software distributed under the License is distributed on an "AS + * IS" basis, WITHOUT WARRANTY OF ANY KIND, either express or + * implied. See the License for the specific language governing + * rights and limitations under the License. + * + * The Original Code is the Mozilla browser. + * + * The Initial Developer of the Original Code is Netscape + * Communications, Inc. Portions created by Netscape are + * Copyright (C) 1999, Mozilla. All Rights Reserved. + * + * Contributor(s): + * Conrad Carlen + */ + +// Local Includes +#include "stdafx.h" +#include "Testembed.h" +#include "ProfileMgr.h" +#include "ProfilesDlg.h" + +// Mozilla Includes +#include "nsString.h" +#include "nsXPIDLString.h" +#include "nsIRegistry.h" +#include "nsIProfile.h" + +// Constants +#define kRegistryGlobalPrefsSubtreeString (NS_LITERAL_STRING("global-prefs")) +#define kRegistryShowProfilesAtStartup "start-show-dialog" + +//***************************************************************************** +//*** CProfileMgr: Object Management +//***************************************************************************** + +CProfileMgr::CProfileMgr() +{ +} + +CProfileMgr::~CProfileMgr() +{ +} + + +//***************************************************************************** +//*** CProfileMgr: Public Methods +//***************************************************************************** + +nsresult CProfileMgr::StartUp() +{ + nsresult rv; + + NS_WITH_SERVICE(nsIProfile, profileService, NS_PROFILE_CONTRACTID, &rv); + if (NS_FAILED(rv)) return rv; + + PRInt32 profileCount; + rv = profileService->GetProfileCount(&profileCount); + if (NS_FAILED(rv)) return rv; + if (profileCount == 0) + { + // Make a new default profile + NS_NAMED_LITERAL_STRING(newProfileName, "default"); + + rv = profileService->CreateNewProfile(newProfileName.get(), nsnull, nsnull, PR_FALSE); + if (NS_FAILED(rv)) return rv; + rv = profileService->SetCurrentProfile(newProfileName.get()); + if (NS_FAILED(rv)) return rv; + } + else + { + // Use our flag here to check for whether to show profile mgr UI. If the flag + // says don't show it, just start with the last used profile. + + PRBool showIt; + rv = GetShowDialogOnStart(&showIt); + + if (NS_FAILED(rv) || (profileCount > 1 && showIt)) + { + DoManageProfilesDialog(TRUE); + } + else + { + // GetCurrentProfile returns the profile which was last used but is not nescesarily + // active. Call SetCurrentProfile to make it installed and active. + + nsXPIDLString currProfileName; + rv = profileService->GetCurrentProfile(getter_Copies(currProfileName)); + if (NS_FAILED(rv)) return rv; + rv = profileService->SetCurrentProfile(currProfileName); + if (NS_FAILED(rv)) return rv; + } + } + + return NS_OK; +} + +nsresult CProfileMgr::DoManageProfilesDialog(PRBool bAtStartUp) +{ + CProfilesDlg dialog; + nsresult rv; + PRBool showIt; + + rv = GetShowDialogOnStart(&showIt); + dialog.m_bAtStartUp = bAtStartUp; + dialog.m_bAskAtStartUp = NS_SUCCEEDED(rv) ? showIt : TRUE; + + if (dialog.DoModal() == IDOK) + { + SetShowDialogOnStart(dialog.m_bAskAtStartUp); + + NS_WITH_SERVICE(nsIProfile, profileService, NS_PROFILE_CONTRACTID, &rv); + if (NS_SUCCEEDED(rv)) + rv = profileService->SetCurrentProfile(dialog.m_SelectedProfile.GetUnicode()); + } + return NS_OK; +} + + +//***************************************************************************** +//*** CProfileMgr: Protected Methods +//***************************************************************************** + +nsresult CProfileMgr::GetShowDialogOnStart(PRBool* showIt) +{ + nsresult rv = NS_OK; + + *showIt = PR_TRUE; + + nsCOMPtr registry(do_CreateInstance(NS_REGISTRY_CONTRACTID, &rv)); + rv = registry->OpenWellKnownRegistry(nsIRegistry::ApplicationRegistry); + if (NS_FAILED(rv)) return rv; + + nsRegistryKey profilesTreeKey; + + rv = registry->GetKey(nsIRegistry::Common, + kRegistryGlobalPrefsSubtreeString.get(), + &profilesTreeKey); + + if (NS_SUCCEEDED(rv)) + { + PRInt32 flagValue; + rv = registry->GetInt(profilesTreeKey, + kRegistryShowProfilesAtStartup, + &flagValue); + + if (NS_SUCCEEDED(rv)) + *showIt = (flagValue != 0); + } + return rv; +} + +nsresult CProfileMgr::SetShowDialogOnStart(PRBool showIt) +{ + nsresult rv = NS_OK; + + nsCOMPtr registry(do_CreateInstance(NS_REGISTRY_CONTRACTID, &rv)); + rv = registry->OpenWellKnownRegistry(nsIRegistry::ApplicationRegistry); + if (NS_FAILED(rv)) return rv; + + nsRegistryKey profilesTreeKey; + + rv = registry->GetKey(nsIRegistry::Common, + kRegistryGlobalPrefsSubtreeString.get(), + &profilesTreeKey); + + if (NS_FAILED(rv)) + { + rv = registry->AddKey(nsIRegistry::Common, + kRegistryGlobalPrefsSubtreeString.get(), + &profilesTreeKey); + } + if (NS_SUCCEEDED(rv)) + { + + rv = registry->SetInt(profilesTreeKey, + kRegistryShowProfilesAtStartup, + showIt); + } + + return rv; +} + diff --git a/mozilla/embedding/qa/testembed/ProfileMgr.h b/mozilla/embedding/qa/testembed/ProfileMgr.h new file mode 100644 index 00000000000..76ef2571ebb --- /dev/null +++ b/mozilla/embedding/qa/testembed/ProfileMgr.h @@ -0,0 +1,55 @@ +/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 2 -*- + * + * The contents of this file are subject to the Mozilla Public + * License Version 1.1 (the "License"); you may not use this file + * except in compliance with the License. You may obtain a copy of + * the License at http://www.mozilla.org/MPL/ + * + * Software distributed under the License is distributed on an "AS + * IS" basis, WITHOUT WARRANTY OF ANY KIND, either express or + * implied. See the License for the specific language governing + * rights and limitations under the License. + * + * The Original Code is the Mozilla browser. + * + * The Initial Developer of the Original Code is Netscape + * Communications, Inc. Portions created by Netscape are + * Copyright (C) 1999, Mozilla. All Rights Reserved. + * + * Contributor(s): + * Conrad Carlen + */ + +#ifndef __ProfileMgr__ +#define __ProfileMgr__ + +// Mozilla Includes +#include "nsError.h" + +// Forward Declarations +class nsIRegistry; + +//***************************************************************************** +//*** CProfileMgr +//***************************************************************************** + +class CProfileMgr +{ + public: + CProfileMgr(); + virtual ~CProfileMgr(); + + virtual nsresult StartUp(); + virtual nsresult DoManageProfilesDialog(PRBool bAtStartUp); + // If bAtStartUp is TRUE, a profile must be selected. + + protected: + + nsresult GetShowDialogOnStart(PRBool* showIt); + nsresult SetShowDialogOnStart(PRBool showIt); +}; + + + + +#endif diff --git a/mozilla/embedding/qa/testembed/ProfilesDlg.cpp b/mozilla/embedding/qa/testembed/ProfilesDlg.cpp new file mode 100644 index 00000000000..73db97a45ec --- /dev/null +++ b/mozilla/embedding/qa/testembed/ProfilesDlg.cpp @@ -0,0 +1,292 @@ +// ProfilesDlg.cpp : implementation file +// + +#include "stdafx.h" +#include +#include "Testembed.h" +#include "ProfilesDlg.h" + +// Mozilla +#include "nsIProfile.h" +#include "nsIServiceManager.h" + +#ifdef _DEBUG +#define new DEBUG_NEW +#undef THIS_FILE +static char THIS_FILE[] = __FILE__; +#endif + +// Static Routines +static void ValidateProfileName(const CString& profileName, CDataExchange* pDX) +{ + USES_CONVERSION; + + nsresult rv; + PRBool exists = FALSE; + + { + NS_WITH_SERVICE(nsIProfile, profileService, NS_PROFILE_CONTRACTID, &rv); + rv = profileService->ProfileExists(T2W(profileName), &exists); + } + + if (NS_SUCCEEDED(rv) && exists) + { + CString errMsg; + + errMsg.Format(_T("Error: A profile named \"%s\" already exists."), (const char *)profileName); + AfxMessageBox( errMsg, MB_ICONEXCLAMATION ); + errMsg.Empty(); + pDX->Fail(); + } + + if (profileName.FindOneOf("\\/") != -1) + { + AfxMessageBox( _T("Error: A profile name cannot contain the characters \"\\\" or \"/\"."), MB_ICONEXCLAMATION ); + pDX->Fail(); + } +} + +///////////////////////////////////////////////////////////////////////////// +// CNewProfileDlg dialog + + +CNewProfileDlg::CNewProfileDlg(CWnd* pParent /*=NULL*/) + : CDialog(CNewProfileDlg::IDD, pParent) +{ + //{{AFX_DATA_INIT(CNewProfileDlg) + m_LocaleIndex = -1; + m_Name = _T(""); + //}}AFX_DATA_INIT +} + + +void CNewProfileDlg::DoDataExchange(CDataExchange* pDX) +{ + CDialog::DoDataExchange(pDX); + //{{AFX_DATA_MAP(CNewProfileDlg) + DDX_CBIndex(pDX, IDC_LOCALE_COMBO, m_LocaleIndex); + DDX_Text(pDX, IDC_NEW_PROF_NAME, m_Name); + //}}AFX_DATA_MAP + + pDX->PrepareEditCtrl(IDC_NEW_PROF_NAME); + if (pDX->m_bSaveAndValidate) + { + ValidateProfileName(m_Name, pDX); + } +} + + +BEGIN_MESSAGE_MAP(CNewProfileDlg, CDialog) + //{{AFX_MSG_MAP(CNewProfileDlg) + // NOTE: the ClassWizard will add message map macros here + //}}AFX_MSG_MAP +END_MESSAGE_MAP() + +///////////////////////////////////////////////////////////////////////////// +// CNewProfileDlg message handlers + + +///////////////////////////////////////////////////////////////////////////// +// CRenameProfileDlg dialog + + +CRenameProfileDlg::CRenameProfileDlg(CWnd* pParent /*=NULL*/) + : CDialog(CRenameProfileDlg::IDD, pParent) +{ + //{{AFX_DATA_INIT(CRenameProfileDlg) + m_NewName = _T(""); + //}}AFX_DATA_INIT +} + + +void CRenameProfileDlg::DoDataExchange(CDataExchange* pDX) +{ + CDialog::DoDataExchange(pDX); + //{{AFX_DATA_MAP(CRenameProfileDlg) + DDX_Text(pDX, IDC_NEW_NAME, m_NewName); + //}}AFX_DATA_MAP + + pDX->PrepareEditCtrl(IDC_NEW_NAME); + if (pDX->m_bSaveAndValidate) + { + ValidateProfileName(m_NewName, pDX); + } +} + + +BEGIN_MESSAGE_MAP(CRenameProfileDlg, CDialog) + //{{AFX_MSG_MAP(CRenameProfileDlg) + // NOTE: the ClassWizard will add message map macros here + //}}AFX_MSG_MAP +END_MESSAGE_MAP() + +///////////////////////////////////////////////////////////////////////////// +// CRenameProfileDlg message handlers + + +///////////////////////////////////////////////////////////////////////////// +// CProfilesDlg dialog + + +CProfilesDlg::CProfilesDlg(CWnd* pParent /*=NULL*/) + : CDialog(CProfilesDlg::IDD, pParent) +{ + //{{AFX_DATA_INIT(CProfilesDlg) + m_bAtStartUp = FALSE; + m_bAskAtStartUp = FALSE; + //}}AFX_DATA_INIT +} + + +void CProfilesDlg::DoDataExchange(CDataExchange* pDX) +{ + CDialog::DoDataExchange(pDX); + //{{AFX_DATA_MAP(CProfilesDlg) + DDX_Control(pDX, IDC_LIST1, m_ProfileList); + DDX_Check(pDX, IDC_CHECK_ASK_AT_START, m_bAskAtStartUp); + //}}AFX_DATA_MAP + + if (pDX->m_bSaveAndValidate) + { + USES_CONVERSION; + + int itemIndex = m_ProfileList.GetCurSel(); + if (itemIndex != LB_ERR) + { + CString itemText; + m_ProfileList.GetText(itemIndex, itemText); + m_SelectedProfile.Assign(T2W(itemText)); + } + } +} + + +BEGIN_MESSAGE_MAP(CProfilesDlg, CDialog) + //{{AFX_MSG_MAP(CProfilesDlg) + ON_BN_CLICKED(IDC_PROF_NEW, OnNewProfile) + ON_BN_CLICKED(IDC_PROF_RENAME, OnRenameProfile) + ON_BN_CLICKED(IDC_PROF_DELETE, OnDeleteProfile) + //}}AFX_MSG_MAP +END_MESSAGE_MAP() + +///////////////////////////////////////////////////////////////////////////// +// CProfilesDlg message handlers + +BOOL CProfilesDlg::OnInitDialog() +{ + USES_CONVERSION; + + CDialog::OnInitDialog(); + + nsCAutoString cStr; + nsXPIDLString curProfileName; + + // Fill the list of profiles + nsresult rv; + NS_WITH_SERVICE(nsIProfile, profileService, NS_PROFILE_CONTRACTID, &rv); + profileService->GetCurrentProfile(getter_Copies(curProfileName)); + + PRInt32 selectedRow = 0; + PRUint32 listLen; + PRUnichar **profileList; + rv = profileService->GetProfileList(&listLen, &profileList); + + for (PRUint32 index = 0; index < listLen; index++) + { + CString tmpStr(W2T(profileList[index])); + m_ProfileList.AddString(tmpStr); + if (nsCRT::strcmp(profileList[index], curProfileName.get()) == 0) + selectedRow = index; + } + + m_ProfileList.SetCurSel(selectedRow); + + if (m_bAtStartUp) + { + GetDlgItem(IDCANCEL)->EnableWindow(FALSE); + } + + return TRUE; // return TRUE unless you set the focus to a control + // EXCEPTION: OCX Property Pages should return FALSE +} + +void CProfilesDlg::OnNewProfile() +{ + CNewProfileDlg dialog; + + if (dialog.DoModal() == IDOK) + { + nsresult rv; + + NS_WITH_SERVICE(nsIProfile, profileService, NS_PROFILE_CONTRACTID, &rv); + ASSERT(NS_SUCCEEDED(rv)); + if (NS_SUCCEEDED(rv)) + { + USES_CONVERSION; + + rv = profileService->CreateNewProfile(T2W(dialog.m_Name), nsnull, nsnull, PR_FALSE); + ASSERT(NS_SUCCEEDED(rv)); + if (NS_SUCCEEDED(rv)) + { + int item = m_ProfileList.AddString(dialog.m_Name); + m_ProfileList.SetCurSel(item); + GetDlgItem(IDOK)->EnableWindow(TRUE); + } + } + } +} + +void CProfilesDlg::OnRenameProfile() +{ + CRenameProfileDlg dialog; + + int itemIndex = m_ProfileList.GetCurSel(); + ASSERT(itemIndex != LB_ERR); + if (itemIndex == LB_ERR) + return; + + m_ProfileList.GetText(itemIndex, dialog.m_CurrentName); + + if (dialog.DoModal() == IDOK) + { + USES_CONVERSION; + + nsresult rv; + + NS_WITH_SERVICE(nsIProfile, profileService, NS_PROFILE_CONTRACTID, &rv); + ASSERT(NS_SUCCEEDED(rv)); + if (NS_SUCCEEDED(rv)) + { + rv = profileService->RenameProfile(T2W(dialog.m_CurrentName), T2W(dialog.m_NewName)); + ASSERT(NS_SUCCEEDED(rv)); + } + } +} + +void CProfilesDlg::OnDeleteProfile() +{ + int itemIndex = m_ProfileList.GetCurSel(); + ASSERT(itemIndex != LB_ERR); + if (itemIndex == LB_ERR) + return; + + CString selectedProfile; + m_ProfileList.GetText(itemIndex, selectedProfile); + + nsresult rv; + NS_WITH_SERVICE(nsIProfile, profileService, NS_PROFILE_CONTRACTID, &rv); + ASSERT(NS_SUCCEEDED(rv)); + if (NS_SUCCEEDED(rv)) + { + USES_CONVERSION; + + rv = profileService->DeleteProfile(T2W(selectedProfile), PR_TRUE); + ASSERT(NS_SUCCEEDED(rv)); + if (NS_SUCCEEDED(rv)) + { + int itemCount = m_ProfileList.DeleteString(itemIndex); + if (itemCount == 0) + GetDlgItem(IDOK)->EnableWindow(FALSE); + } + } +} diff --git a/mozilla/embedding/qa/testembed/ProfilesDlg.h b/mozilla/embedding/qa/testembed/ProfilesDlg.h new file mode 100644 index 00000000000..f82cb2d2c89 --- /dev/null +++ b/mozilla/embedding/qa/testembed/ProfilesDlg.h @@ -0,0 +1,120 @@ +#if !defined(AFX_PROFILESDLG_H__48358887_EBFA_11D4_9905_00B0D0235410__INCLUDED_) +#define AFX_PROFILESDLG_H__48358887_EBFA_11D4_9905_00B0D0235410__INCLUDED_ + +#if _MSC_VER > 1000 +#pragma once +#endif // _MSC_VER > 1000 +// ProfilesDlg.h : header file +// + +///////////////////////////////////////////////////////////////////////////// +// CNewProfileDlg dialog + +class CNewProfileDlg : public CDialog +{ +// Construction +public: + CNewProfileDlg(CWnd* pParent = NULL); // standard constructor + +// Dialog Data + //{{AFX_DATA(CNewProfileDlg) + enum { IDD = IDD_PROFILE_NEW }; + int m_LocaleIndex; + CString m_Name; + //}}AFX_DATA + + +// Overrides + // ClassWizard generated virtual function overrides + //{{AFX_VIRTUAL(CNewProfileDlg) + protected: + virtual void DoDataExchange(CDataExchange* pDX); // DDX/DDV support + //}}AFX_VIRTUAL + +// Implementation +protected: + + // Generated message map functions + //{{AFX_MSG(CNewProfileDlg) + // NOTE: the ClassWizard will add member functions here + //}}AFX_MSG + DECLARE_MESSAGE_MAP() +}; + +///////////////////////////////////////////////////////////////////////////// +// CRenameProfileDlg dialog + +class CRenameProfileDlg : public CDialog +{ +// Construction +public: + CRenameProfileDlg(CWnd* pParent = NULL); // standard constructor + +// Dialog Data + //{{AFX_DATA(CRenameProfileDlg) + enum { IDD = IDD_PROFILE_RENAME }; + CString m_NewName; + //}}AFX_DATA + + CString m_CurrentName; + +// Overrides + // ClassWizard generated virtual function overrides + //{{AFX_VIRTUAL(CRenameProfileDlg) + protected: + virtual void DoDataExchange(CDataExchange* pDX); // DDX/DDV support + //}}AFX_VIRTUAL + +// Implementation +protected: + + // Generated message map functions + //{{AFX_MSG(CRenameProfileDlg) + // NOTE: the ClassWizard will add member functions here + //}}AFX_MSG + DECLARE_MESSAGE_MAP() +}; + +///////////////////////////////////////////////////////////////////////////// +// CProfilesDlg dialog + +class CProfilesDlg : public CDialog +{ +// Construction +public: + CProfilesDlg(CWnd* pParent = NULL); // standard constructor + +// Dialog Data + //{{AFX_DATA(CProfilesDlg) + enum { IDD = IDD_PROFILES }; + CListBox m_ProfileList; + BOOL m_bAtStartUp; + BOOL m_bAskAtStartUp; + //}}AFX_DATA + + nsAutoString m_SelectedProfile; + +// Overrides + // ClassWizard generated virtual function overrides + //{{AFX_VIRTUAL(CProfilesDlg) + protected: + virtual void DoDataExchange(CDataExchange* pDX); // DDX/DDV support + //}}AFX_VIRTUAL + +// Implementation +protected: + + // Generated message map functions + //{{AFX_MSG(CProfilesDlg) + virtual BOOL OnInitDialog(); + afx_msg void OnNewProfile(); + afx_msg void OnRenameProfile(); + afx_msg void OnDeleteProfile(); + //}}AFX_MSG + DECLARE_MESSAGE_MAP() +}; + +//{{AFX_INSERT_LOCATION}} +// Microsoft Visual C++ will insert additional declarations immediately before the previous line. + +#endif // !defined(AFX_PROFILESDLG_H__48358887_EBFA_11D4_9905_00B0D0235410__INCLUDED_) diff --git a/mozilla/embedding/qa/testembed/QaUtils.cpp b/mozilla/embedding/qa/testembed/QaUtils.cpp new file mode 100644 index 00000000000..5ea62a58288 --- /dev/null +++ b/mozilla/embedding/qa/testembed/QaUtils.cpp @@ -0,0 +1,161 @@ +/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- + * + * The contents of this file are subject to the Netscape Public + * License Version 1.1 (the "License"); you may not use this file + * except in compliance with the License. You may obtain a copy of + * the License at http://www.mozilla.org/NPL/ + * + * Software distributed under the License is distributed on an "AS + * IS" basis, WITHOUT WARRANTY OF ANY KIND, either express or + * implied. See the License for the specific language governing + * rights and limitations under the License. + * + * The Original Code is mozilla.org code. + * + * The Initial Developer of the Original Code is Netscape + * Communications Corporation. Portions created by Netscape are + * Copyright (C) 1998 Netscape Communications Corporation. All + * Rights Reserved. + * + * Contributor(s): + * David Epstein + */ + +// File Overview.... +// +// These are utilities to help with QA tasks. + +// Includes routine to post results to a QA log file. + +#include "stdafx.h" +#include "TestEmbed.h" +#include "BrowserView.h" +#include "BrowserImpl.h" +#include "BrowserFrm.h" +#include "QAUtils.h" + +#ifdef _DEBUG +#define new DEBUG_NEW +#undef THIS_FILE +static char THIS_FILE[] = __FILE__; +#endif + +BEGIN_MESSAGE_MAP(CQaUtils, CWnd) + //{{AFX_MSG_MAP(CQaUtils) + //}}AFX_MSG_MAP +END_MESSAGE_MAP() + + +CQaUtils::CQaUtils() +{ + +} + +CQaUtils::~CQaUtils() +{ +} + +// *********************************************************************** +// ***************** Local QA Methods ****************** +// *********************************************************************** + +void CQaUtils::WriteToOutputFile(const char *pLine) +{ + CStdioFile myFile; + CFileException e; + CString strFileName = "c:\\temp\\TestOutput.txt"; + + if(! myFile.Open( strFileName, CStdioFile::modeCreate | CStdioFile::modeWrite + | CStdioFile::modeNoTruncate, &e ) ) + { + CString failCause = "Unable to open file. Reason : "; + failCause += e.m_cause; + AfxMessageBox(failCause); + } + else + { + myFile.SeekToEnd(); + CString strLine = pLine; + strLine += "\r\n"; + + myFile.WriteString(strLine); + + myFile.Close(); + } +} + +void CQaUtils::RvTestResult(nsresult rv, const char *pLine, int displayMethod) +{ + // note: default displayMethod = 1 in .h file + + CString strLine = pLine; + char theOutputLine[100]; + + if (NS_FAILED(rv)) + strLine += " failed."; + else + strLine += " passed."; + + strcpy(theOutputLine, strLine); + QAOutput(theOutputLine, displayMethod); +} + +void CQaUtils::QAOutput(const char *pLine, int displayMethod) +{ + // note: default displayMethod = 1 in .h file +//#if 0 + CString strLine = pLine; + + if (displayMethod == 0) + AfxMessageBox(strLine); + else if (displayMethod == 1) + WriteToOutputFile(pLine); + else + { + WriteToOutputFile(pLine); + AfxMessageBox(strLine); + } +//#endif +} + +void CQaUtils::FormatAndPrintOutput(const char *theOutput, const char *theVar, int outputMode) +{ + nsCString outStr; + CString strMsg; + + outStr = theOutput; + outStr += theVar; + + strMsg = outStr.get(); + + switch (outputMode) + { + case 0: + AfxMessageBox(strMsg); + break; + case 1: + WriteToOutputFile(outStr.get()); + break; + case 2: + WriteToOutputFile(outStr.get()); + AfxMessageBox(strMsg); + break; + } +} + +void CQaUtils::RequestName(nsIRequest *request, nsCString &stringMsg) +{ + nsXPIDLString theReqName; + nsresult rv; + + rv = request->GetName(getter_Copies(theReqName)); + if(NS_SUCCEEDED(rv)) + { + stringMsg.AssignWithConversion(theReqName); + FormatAndPrintOutput("The request name = ", stringMsg.get(), 1); + } + else + QAOutput("We didn't get the request name."); + +} + diff --git a/mozilla/embedding/qa/testembed/QaUtils.h b/mozilla/embedding/qa/testembed/QaUtils.h new file mode 100644 index 00000000000..aab5d516584 --- /dev/null +++ b/mozilla/embedding/qa/testembed/QaUtils.h @@ -0,0 +1,61 @@ +/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- + * + * The contents of this file are subject to the Netscape Public + * License Version 1.1 (the "License"); you may not use this file + * except in compliance with the License. You may obtain a copy of + * the License at http://www.mozilla.org/NPL/ + * + * Software distributed under the License is distributed on an "AS + * IS" basis, WITHOUT WARRANTY OF ANY KIND, either express or + * implied. See the License for the specific language governing + * rights and limitations under the License. + * + * The Original Code is mozilla.org code. + * + * The Initial Developer of the Original Code is Netscape + * Communications Corporation. Portions created by Netscape are + * Copyright (C) 1998 Netscape Communications Corporation. All + * Rights Reserved. + * + * Contributor(s): + * David Epstein + */ + +// QAUtils.h : utilities for CQAUtils class. Includes writing to output log. +// +///////////////////////////////////////////////////////////////////////////// + +#ifndef _QAUTILS_H +#define _QAUTILS_H + +#if _MSC_VER > 1000 + #pragma once +#endif + +#include "BrowserView.h" +#include "stdafx.h" + +///////////////////////////////////////////////////////////////////////////// +// CQaUtils window + +class CQaUtils : public CWnd +{ +public: + CQaUtils(); + virtual ~CQaUtils(); + + void static WriteToOutputFile(const char *); + void static RvTestResult(nsresult, const char *, int displayMethod=1); + void static QAOutput(const char *pLine, int displayMethod=1); + void static FormatAndPrintOutput(const char *, const char *, int); + void static RequestName(nsIRequest *, nsCString &); + + // Some helper methods + + // Generated message map functions +protected: + //{{AFX_MSG(CQaUtils) + DECLARE_MESSAGE_MAP() +}; + +#endif //_QAUTILS_H diff --git a/mozilla/embedding/qa/testembed/README.TXT b/mozilla/embedding/qa/testembed/README.TXT new file mode 100644 index 00000000000..ab1c632a372 --- /dev/null +++ b/mozilla/embedding/qa/testembed/README.TXT @@ -0,0 +1,137 @@ +/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- + * + * The contents of this file are subject to the Netscape Public + * License Version 1.1 (the "License"); you may not use this file + * except in compliance with the License. You may obtain a copy of + * the License at http://www.mozilla.org/NPL/ + * + * Software distributed under the License is distributed on an "AS + * IS" basis, WITHOUT WARRANTY OF ANY KIND, either express or + * implied. See the License for the specific language governing + * rights and limitations under the License. + * + * The Original Code is mozilla.org code. + * + * The Initial Developer of the Original Code is Netscape + * Communications Corporation. Portions created by Netscape are + * Copyright (C) 1998 Netscape Communications Corporation. All + * Rights Reserved. + * + * Contributor(s): + * Chak Nanga + */ + +This sample shows how to embed Mozilla from within +an MFC Windows application + +Mainly demonstrates the use of the following interfaces: + + nsIWebBrowserChrome + nsIEmbeddingSiteWindow + nsIWebProgressListener + nsIContextMenuListener + nsIPrompt + nsIWebBrowserFind + +General Overview: +----------------- + +1. The MfcEmbedApp creates BrowserFrames + +2. BrowserFrame creates the toolbar, statusbar, URLbar + BrowserView etc. + BrowserFrames implement the IBrowserFrameGlue interface + using which new BrowserFrames can be created, statusbar + updated etc. + +3. BrowserView creates the embeddable browser instance and + manages user interaction such as URL navigation etc. + BrowserView connects the BrowserImpl with the BrowserFrame + via the IBrowserFrameGlue interface + +4. BrowserImpl implements the set of required/optional Gecko + embedding interfaces + + +Start by first looking at MfcEmbed.cpp + +Files: + +StdAfx.h + - Includes the required Mozilla header files + +MfcEmbed.cpp + - CWinApp derived class + - Creates the browser's main frame window etc + using the CreateNewBrowserFrame() and loads + the HomePage + - Makes the required NS_InitEmbedding() and the + NS_TermEmbedding() calls in the app's InitInstance() + and ExitInstance() functions + - Keeps track of the list of new BrowserFrames created + which it cleans up properly in ExitInstance() + +BrowserFrm.cpp + - This is the browser's Frame window i.e. the one with the + "chrome" - with the toolbar, urlbar etc. + - Creates the toolbar, URLbar, statusbar, progressbar + also the browser's view window. + +BrowserFrameGlue.cpp + - Implements the IBrowserFrameGlue interface. This interface + contains platform specific implementations of functions to + update the statusbar, creating new browser frames etc. Embedded + browser's callbacks use this interface when needed + +BrowserView.cpp + - Creates the embedded browser object and handles most aspects + of the embedded browser interactions - like URL navigation, + clipboard interactions etc + - Also has code to keep the menu/toolbar/statusbar UI items up + to date + - It's the view which conntects the BrowserFrame to the BrowserImpl + (see below) by passing it the pointer to IBrowserFrameGlue + +BrowserImpl*.cpp + - Implements the required and/or optional embedded browser + interfaces + (BrowserImpl.cpp implements the set of interfaces which + are required by Gecko of all embedding apps. The other + interfaces implemented in the BrowserImpl*.cpp files are + optional) + + - Calls on the statusbar/progressbar update functions exposed + via the IBrowserFrameGlue in response to the nsIProgressListener + interface callbacks + +Dialogs.cpp + - Contains dialog box code for displaying Prompts, getting + passwords, getting username/passwords etc + - Contains the CFindDialog class - used for searching text + in a web page + +winEmbedFileLocProvider.cpp, ProfilesDlg.cpp, ProfileMgr.cpp + - Profile management related code (by Conrad Carlen) + +MfcEmbed.htm + - This is a simple test harness for excercising some of the + implemented interfaces . For ex, the nsIWebBrowserChrome. + - Open the file in mfcemed by typing the following in it's + location bar. For ex: + + file:///c:/tmp/mfcembed.htm + - Read/Click on the links on that page more info + - This test page is just a start and will add more test + case to it over time + + +makefile.win + - We define "_AFXDLL" and for the compiler and specify + "-SUBSYSTEM:windows" for the linker using LCFLAGS and + LLFLAGS, respectively + - We also define "USE_SINGLE_SIGN_ON" to enable the + single sign-on support + +mfcembed.dsp and mfcembed.dsw + - These VisualStudio workspace/project files can be used + to open/build this sample inside of the VC++ IDE diff --git a/mozilla/embedding/qa/testembed/StdAfx.cpp b/mozilla/embedding/qa/testembed/StdAfx.cpp new file mode 100644 index 00000000000..23ef8983bb1 --- /dev/null +++ b/mozilla/embedding/qa/testembed/StdAfx.cpp @@ -0,0 +1,31 @@ +/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- + * + * The contents of this file are subject to the Netscape Public + * License Version 1.1 (the "License"); you may not use this file + * except in compliance with the License. You may obtain a copy of + * the License at http://www.mozilla.org/NPL/ + * + * Software distributed under the License is distributed on an "AS + * IS" basis, WITHOUT WARRANTY OF ANY KIND, either express or + * implied. See the License for the specific language governing + * rights and limitations under the License. + * + * The Original Code is mozilla.org code. + * + * The Initial Developer of the Original Code is Netscape + * Communications Corporation. Portions created by Netscape are + * Copyright (C) 1998 Netscape Communications Corporation. All + * Rights Reserved. + * + * Contributor(s): + * Chak Nanga + */ + +// stdafx.cpp : source file that includes just the standard includes +// mozembed.pch will be the pre-compiled header +// stdafx.obj will contain the pre-compiled type information + +#include "stdafx.h" + + + diff --git a/mozilla/embedding/qa/testembed/StdAfx.h b/mozilla/embedding/qa/testembed/StdAfx.h new file mode 100644 index 00000000000..4240b01fd56 --- /dev/null +++ b/mozilla/embedding/qa/testembed/StdAfx.h @@ -0,0 +1,105 @@ +/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- + * + * The contents of this file are subject to the Netscape Public + * License Version 1.1 (the "License"); you may not use this file + * except in compliance with the License. You may obtain a copy of + * the License at http://www.mozilla.org/NPL/ + * + * Software distributed under the License is distributed on an "AS + * IS" basis, WITHOUT WARRANTY OF ANY KIND, either express or + * implied. See the License for the specific language governing + * rights and limitations under the License. + * + * The Original Code is mozilla.org code. + * + * The Initial Developer of the Original Code is Netscape + * Communications Corporation. Portions created by Netscape are + * Copyright (C) 1998 Netscape Communications Corporation. All + * Rights Reserved. + * + * Contributor(s): + * Chak Nanga + */ + +// stdafx.h : include file for standard system include files, +// or project specific include files that are used frequently, but +// are changed infrequently +// + +#ifndef _STDAFX_H +#define _STDAFX_H + +#if _MSC_VER > 1000 +#pragma once +#endif // _MSC_VER > 1000 + +#define VC_EXTRALEAN // Exclude rarely-used stuff from Windows headers + +#include // MFC core and standard components +#include // MFC extensions +#include // MFC support for Internet Explorer 4 Common Controls +#include // Needed for MFC MBCS/Unicode Conversion Macros +#ifndef _AFX_NO_AFXCMN_SUPPORT +#include // MFC support for Windows Common Controls +#endif // _AFX_NO_AFXCMN_SUPPORT + +#include "nsCOMPtr.h" +#include "nsNetUtil.h" +#include "nsString.h" +#include "nsVoidArray.h" +#include "nsCWebBrowser.h" +#include "nsXPIDLString.h" +#include "nsWidgetsCID.h" +#include "nsIDocShell.h" +#include "nsIWebBrowser.h" +#include "nsIBaseWindow.h" +#include "nsIWebNavigation.h" +#include "nsIWebBrowserChrome.h" +#include "nsIWebProgressListener.h" +#include "nsIWebProgress.h" +#include "nsIWindowCreator.h" +#include "nsIInterfaceRequestor.h" +#include "nsIDocShellTreeOwner.h" +#include "nsIDocShellTreeItem.h" +#include "nsIClipboardCommands.h" +#include "nsIWebBrowserPersist.h" +#include "nsIContextMenuListener.h" +#include "nsIDOMNode.h" +#include "nsIDOMHTMLAnchorElement.h" +#include "nsIDOMHTMLImageElement.h" +#include "nsReadableUtils.h" +#include "nsIPrompt.h" +#include "nsEmbedAPI.h" +#include "nsISHistory.h" +#include "nsISHEntry.h" +#include "nsIPref.h" +#include "nsAppDirectoryServiceDefs.h" +#include "nsIProfileChangeStatus.h" +#include "nsIObserverService.h" +#ifdef MOZ_OLD_CACHE +#include "nsINetDataCacheManager.h" +#endif +#include "nsError.h" +#include "nsIObserver.h" +#include "nsWeakReference.h" +#include "nsIEmbeddingSiteWindow.h" +#include "nsIWebBrowserFind.h" +#include "nsIWebBrowserFocus.h" + +// Printer Includes +#include "nsIPrintOptions.h" +#include "nsIWebBrowserPrint.h" +#include "nsIDOMWindow.h" + +// qa additions +#include "nsIGlobalHistory.h" +#include "nsIBrowserHistory.h" +#include "nsILocalFile.h" + +#include "nsIProfile.h" +#include "nsIDOMDocument.h" + +//{{AFX_INSERT_LOCATION}} +// Microsoft Visual C++ will insert additional declarations immediately before the previous line. + +#endif //_STDAFX_H diff --git a/mozilla/embedding/qa/testembed/TestEmbed.cpp b/mozilla/embedding/qa/testembed/TestEmbed.cpp new file mode 100644 index 00000000000..c19fb38f2bb --- /dev/null +++ b/mozilla/embedding/qa/testembed/TestEmbed.cpp @@ -0,0 +1,661 @@ +/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- + * + * The contents of this file are subject to the Netscape Public + * License Version 1.1 (the "License"); you may not use this file + * except in compliance with the License. You may obtain a copy of + * the License at http://www.mozilla.org/NPL/ + * + * Software distributed under the License is distributed on an "AS + * IS" basis, WITHOUT WARRANTY OF ANY KIND, either express or + * implied. See the License for the specific language governing + * rights and limitations under the License. + * + * The Original Code is mozilla.org code. + * + * The Initial Developer of the Original Code is Netscape + * Communications Corporation. Portions created by Netscape are + * Copyright (C) 1998 Netscape Communications Corporation. All + * Rights Reserved. + * + * Contributor(s): + * Chak Nanga + * Conrad Carlen + */ + +// File Overview.... +// +// The typical MFC app, frame creation code + AboutDlg handling +// +// NS_InitEmbedding() is called in InitInstance() +// +// NS_TermEmbedding() is called in ExitInstance() +// ExitInstance() also takes care of cleaning up of +// multiple browser frame windows on app exit +// +// NS_DoIdleEmbeddingStuff(); is called in the overridden +// OnIdle() method +// +// Code to handle the creation of a new browser window + +// Next suggested file to look at : BrowserFrm.cpp + +// Local Includes +#include "stdafx.h" +#include "TestEmbed.h" +#include "BrowserFrm.h" +#include "winEmbedFileLocProvider.h" +#include "ProfileMgr.h" +#include "BrowserImpl.h" +#include "BrowserView.h" +#include "nsIWindowWatcher.h" +#include "plstr.h" +#include "Preferences.h" +#include +#include + +#include "QAUtils.h" + +#ifdef _DEBUG +#define new DEBUG_NEW +#undef THIS_FILE +static char THIS_FILE[] = __FILE__; +#endif + +// this is for overriding the Mozilla default PromptService component +#include "PromptService.h" +#define kComponentsLibname "mfcEmbedComponents.dll" +#define NS_PROMPTSERVICE_CID \ + {0xa2112d6a, 0x0e28, 0x421f, {0xb4, 0x6a, 0x25, 0xc0, 0xb3, 0x8, 0xcb, 0xd0}} +static NS_DEFINE_CID(kPromptServiceCID, NS_PROMPTSERVICE_CID); + +BEGIN_MESSAGE_MAP(CTestEmbedApp, CWinApp) + //{{AFX_MSG_MAP(CTestEmbedApp) + ON_COMMAND(ID_NEW_BROWSER, OnNewBrowser) + ON_COMMAND(ID_MANAGE_PROFILES, OnManageProfiles) + ON_COMMAND(ID_APP_ABOUT, OnAppAbout) + ON_COMMAND(ID_EDIT_PREFERENCES, OnEditPreferences) + // NOTE - the ClassWizard will add and remove mapping macros here. + // DO NOT EDIT what you see in these blocks of generated code! + //}}AFX_MSG_MAP +END_MESSAGE_MAP() + +CTestEmbedApp::CTestEmbedApp() : + m_ProfileMgr(NULL) +{ + mRefCnt = 1; // Start at one - nothing is going to addref this object + + m_strHomePage = ""; + + m_iStartupPage = 0; + +} + +CTestEmbedApp theApp; + +BOOL CTestEmbedApp::IsCmdLineSwitch(const char *pSwitch, BOOL bRemove) +{ + // 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); +} + +void CTestEmbedApp::ParseCmdLine() +{ + // Show Debug Console? + if(IsCmdLineSwitch("-console")) + ShowDebugConsole(); +} + +/* Some Gecko interfaces are implemented as components, automatically + registered at application initialization. nsIPrompt is an example: + the default implementation uses XUL, not native windows. Embedding + apps can override the default implementation by implementing the + nsIPromptService interface and registering a factory for it with + the same CID and Contract ID as the default's. + + Note that this example implements the service in a separate DLL, + replacing the default if the override DLL is present. This could + also have been done in the same module, without a separate DLL. + See the PowerPlant example for, well, an example. +*/ +nsresult CTestEmbedApp::OverrideComponents() +{ + 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(::GetProcAddress(overlib, kPromptServiceInitFuncName)); + MakeFactory = reinterpret_cast(::GetProcAddress(overlib, kPromptServiceFactoryFuncName)); + + if (InitLib && MakeFactory) { + InitLib(overlib); + + nsCOMPtr promptFactory; + rv = MakeFactory(getter_AddRefs(promptFactory)); + if (NS_SUCCEEDED(rv)) + nsComponentManager::RegisterFactory(kPromptServiceCID, + "Prompt Service", + "@mozilla.org/embedcomp/prompt-service;1", + promptFactory, + PR_TRUE); // replace existing + } else + ::FreeLibrary(overlib); + } + + return rv; +} + +void CTestEmbedApp::ShowDebugConsole() +{ +#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 +} + +// Initialize our MFC application and also init +// the Gecko embedding APIs +// Note that we're also init'ng the profile switching +// code here +// Then, create a new BrowserFrame and load our +// default homepage +// +BOOL CTestEmbedApp::InitInstance() +{ + CQaUtils *myUtils = new CQaUtils(); + + myUtils->QAOutput("****************************************************\r\n"); + + ParseCmdLine(); + + Enable3dControls(); + + // 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; + } + + nsresult rv; + rv = NS_InitEmbedding(nsnull, provider); + if(NS_FAILED(rv)) + { + myUtils->QAOutput("TestEmbed didn't start up."); + ASSERT(FALSE); + return FALSE; + } + else + myUtils->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(); + myUtils->RvTestResult(rv, "TestEmbed shutdown"); + return FALSE; + } + + + if(!CreateHiddenWindow()) + { + ASSERT(FALSE); + rv = NS_TermEmbedding(); + myUtils->RvTestResult(rv, "TestEmbed shutdown"); + return FALSE; + } + + // Create the first browser frame window + OnNewBrowser(); + + return TRUE; +} + +CBrowserFrame* CTestEmbedApp::CreateNewBrowserFrame(PRUint32 chromeMask, + PRInt32 x, PRInt32 y, + PRInt32 cx, PRInt32 cy, + PRBool bShowWindow) +{ + // 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; +} + +void CTestEmbedApp::OnNewBrowser() +{ + CBrowserFrame *pBrowserFrame = CreateNewBrowserFrame(); + + //Load the HomePage into the browser view + if(pBrowserFrame && (GetStartupPageMode() == 1)) + pBrowserFrame->m_wndBrowserView.LoadHomePage(); +} + +// This gets called anytime a BrowserFrameWindow is +// closed i.e. by choosing the "close" menu item from +// a window's system menu or by dbl clicking on the +// system menu box +// +// Sends a WM_QUIT to the hidden window which results +// in ExitInstance() being called and the app is +// properly cleaned up and shutdown +// +void CTestEmbedApp::RemoveFrameFromList(CBrowserFrame* pFrm, BOOL bCloseAppOnLastFrame/*= TRUE*/) +{ + 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); +} + +int CTestEmbedApp::ExitInstance() +{ + // 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)) + CQaUtils::QAOutput("TestEmbed didn't shut down."); + else + CQaUtils::QAOutput("TestEmbed shut down."); + + return 1; +} + +BOOL CTestEmbedApp::OnIdle(LONG lCount) +{ + CWinApp::OnIdle(lCount); + + NS_DoIdleEmbeddingStuff(); + + return FALSE; +} + +void CTestEmbedApp::OnManageProfiles() +{ + m_ProfileMgr->DoManageProfilesDialog(PR_FALSE); +} + +void CTestEmbedApp::OnEditPreferences() +{ + 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; + NS_WITH_SERVICE(nsIPref, prefs, 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"); + } +} + +BOOL CTestEmbedApp::InitializeProfiles() +{ + m_ProfileMgr = new CProfileMgr; + if (!m_ProfileMgr) + return FALSE; + + nsresult rv; + NS_WITH_SERVICE(nsIObserverService, observerService, NS_OBSERVERSERVICE_CONTRACTID, &rv); + observerService->AddObserver(this, NS_LITERAL_STRING("profile-approve-change").get()); + observerService->AddObserver(this, NS_LITERAL_STRING("profile-change-teardown").get()); + observerService->AddObserver(this, NS_LITERAL_STRING("profile-after-change").get()); + + m_ProfileMgr->StartUp(); + + return TRUE; +} + +// When the profile switch happens, all open browser windows need to be +// closed. +// In order for that not to kill off the app, we just make the MFC app's +// mainframe be an invisible window which doesn't get closed on profile +// switches +BOOL CTestEmbedApp::CreateHiddenWindow() +{ + 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; +} + +nsresult CTestEmbedApp::InitializePrefs() +{ + nsresult rv; + NS_WITH_SERVICE(nsIPref, prefs, 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; +} + + +/* InitializeWindowCreator creates and hands off an object with a callback + to a window creation function. This will be used by Gecko C++ code + (never JS) to create new windows when no previous window is handy + to begin with. This is done in a few exceptional cases, like PSM code. + Failure to set this callback will only disable the ability to create + new windows under these circumstances. */ +nsresult CTestEmbedApp::InitializeWindowCreator() +{ + // give an nsIWindowCreator to the WindowWatcher service + nsCOMPtr windowCreator(NS_STATIC_CAST(nsIWindowCreator *, this)); + if (windowCreator) { + nsCOMPtr wwatch(do_GetService("@mozilla.org/embedcomp/window-watcher;1")); + if (wwatch) { + wwatch->SetWindowCreator(windowCreator); + return NS_OK; + } + } + return NS_ERROR_FAILURE; +} + +// --------------------------------------------------------------------------- +// CTestEmbedApp : nsISupports +// --------------------------------------------------------------------------- + +NS_IMPL_THREADSAFE_ISUPPORTS3(CTestEmbedApp, nsIObserver, nsIWindowCreator, nsISupportsWeakReference); + +// --------------------------------------------------------------------------- +// CTestEmbedApp : nsIObserver +// --------------------------------------------------------------------------- + +// Mainly needed to support "on the fly" profile switching + +NS_IMETHODIMP CTestEmbedApp::Observe(nsISupports *aSubject, const PRUnichar *aTopic, const PRUnichar *someData) +{ + nsresult rv = NS_OK; + + if (nsCRT::strcmp(aTopic, NS_LITERAL_STRING("profile-approve-change").get()) == 0) + { + // Ask the user if they want to + int result = MessageBox(NULL, "Do you want to close all windows in order to switch the profile?", "Confirm", MB_YESNO | MB_ICONQUESTION); + if (result != IDYES) + { + nsCOMPtr status = do_QueryInterface(aSubject); + NS_ENSURE_TRUE(status, NS_ERROR_FAILURE); + status->VetoChange(); + } + } + else if (nsCRT::strcmp(aTopic, NS_LITERAL_STRING("profile-change-teardown").get()) == 0) + { + // Close all open windows. Alternatively, we could just call CBrowserWindow::Stop() + // on each. Either way, we have to stop all network activity on this phase. + + POSITION pos = m_FrameWndLst.GetHeadPosition(); + while( pos != NULL ) + { + CBrowserFrame *pBrowserFrame = (CBrowserFrame *) m_FrameWndLst.GetNext(pos); + if(pBrowserFrame) + { + pBrowserFrame->ShowWindow(false); + + // Passing in FALSE below so that we do not + // kill the main app during a profile switch + RemoveFrameFromList(pBrowserFrame, FALSE); + + pBrowserFrame->DestroyWindow(); + } + } + } + else if (nsCRT::strcmp(aTopic, NS_LITERAL_STRING("profile-after-change").get()) == 0) + { + InitializePrefs(); // In case we have just switched to a newly created profile. + + // Only make a new browser window on a switch. This also gets + // called at start up and we already make a window then. + if (!nsCRT::strcmp(someData, NS_LITERAL_STRING("switch").get())) + OnNewBrowser(); + } + return rv; +} + +// --------------------------------------------------------------------------- +// CTestEmbedApp : nsIWindowCreator +// --------------------------------------------------------------------------- +NS_IMETHODIMP CTestEmbedApp::CreateChromeWindow(nsIWebBrowserChrome *parent, + PRUint32 chromeFlags, + nsIWebBrowserChrome **_retval) +{ + // XXX we're ignoring the "parent" parameter + NS_ENSURE_ARG_POINTER(_retval); + *_retval = 0; + + CBrowserFrame *pBrowserFrame = CreateNewBrowserFrame(chromeFlags); + if(pBrowserFrame) { + *_retval = NS_STATIC_CAST(nsIWebBrowserChrome *, pBrowserFrame->GetBrowserImpl()); + NS_ADDREF(*_retval); + } + return NS_OK; +} + +// AboutDlg Stuff + +class CAboutDlg : public CDialog +{ +public: + CAboutDlg(); + + enum { IDD = IDD_ABOUTBOX }; + +protected: + virtual void DoDataExchange(CDataExchange* pDX); // DDX/DDV support + +protected: + DECLARE_MESSAGE_MAP() +}; + +CAboutDlg::CAboutDlg() : CDialog(CAboutDlg::IDD) +{ +} + +void CAboutDlg::DoDataExchange(CDataExchange* pDX) +{ + CDialog::DoDataExchange(pDX); +} + +BEGIN_MESSAGE_MAP(CAboutDlg, CDialog) +END_MESSAGE_MAP() + +// Show the AboutDlg +void CTestEmbedApp::OnAppAbout() +{ + CAboutDlg aboutDlg; + aboutDlg.DoModal(); +} diff --git a/mozilla/embedding/qa/testembed/TestEmbed.h b/mozilla/embedding/qa/testembed/TestEmbed.h new file mode 100644 index 00000000000..a3000d00d1f --- /dev/null +++ b/mozilla/embedding/qa/testembed/TestEmbed.h @@ -0,0 +1,122 @@ +/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- + * + * The contents of this file are subject to the Netscape Public + * License Version 1.1 (the "License"); you may not use this file + * except in compliance with the License. You may obtain a copy of + * the License at http://www.mozilla.org/NPL/ + * + * Software distributed under the License is distributed on an "AS + * IS" basis, WITHOUT WARRANTY OF ANY KIND, either express or + * implied. See the License for the specific language governing + * rights and limitations under the License. + * + * The Original Code is mozilla.org code. + * + * The Initial Developer of the Original Code is Netscape + * Communications Corporation. Portions created by Netscape are + * Copyright (C) 1998 Netscape Communications Corporation. All + * Rights Reserved. + * + * Contributor(s): + * Chak Nanga + */ + +// mozembed.h : main header file for the MOZEMBED application +// + +#ifndef _TESTEMBED_H +#define _TESTEMBED_H + +#if _MSC_VER > 1000 +#pragma once +#endif // _MSC_VER > 1000 + +#ifndef __AFXWIN_H__ + #error include 'stdafx.h' before including this file for PCH +#endif + +#include "resource.h" // main symbols + +///////////////////////////////////////////////////////////////////////////// +// CTestEmbedApp: +// See mozembed.cpp for the implementation of this class +// + +class CBrowserFrame; +class CProfileMgr; + +class CTestEmbedApp : public CWinApp, + public nsIObserver, + public nsIWindowCreator, + public nsSupportsWeakReference +{ +public: + 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(); + + // Overrides + // ClassWizard generated virtual function overrides + //{{AFX_VIRTUAL(CTestEmbedApp) + public: + virtual BOOL InitInstance(); + virtual int ExitInstance(); + virtual BOOL OnIdle(LONG lCount); + //}}AFX_VIRTUAL + + CObList m_FrameWndLst; + + CString m_strHomePage; + inline BOOL GetHomePage(CString& strHomePage) { + strHomePage = m_strHomePage; + return TRUE; + } + + int m_iStartupPage; //0 = BlankPage, 1 = HomePage + inline int GetStartupPageMode() { + return m_iStartupPage; + } + +// Implementation + +public: + //{{AFX_MSG(CTestEmbedApp) + afx_msg void OnAppAbout(); + afx_msg void OnNewBrowser(); + afx_msg void OnManageProfiles(); + afx_msg void OnEditPreferences(); + // NOTE - the ClassWizard will add and remove member functions here. + // DO NOT EDIT what you see in these blocks of generated code ! + //}}AFX_MSG + DECLARE_MESSAGE_MAP() + +private: + BOOL InitializeProfiles(); + BOOL CreateHiddenWindow(); + nsresult InitializePrefs(); + nsresult InitializeWindowCreator(); + +private: + CProfileMgr *m_ProfileMgr; +}; + + +///////////////////////////////////////////////////////////////////////////// + +//{{AFX_INSERT_LOCATION}} +// Microsoft Visual C++ will insert additional declarations immediately before the previous line. + +#endif // _TESTEMBED_H diff --git a/mozilla/embedding/qa/testembed/Tests.cpp b/mozilla/embedding/qa/testembed/Tests.cpp new file mode 100644 index 00000000000..cbe43cc5e2c --- /dev/null +++ b/mozilla/embedding/qa/testembed/Tests.cpp @@ -0,0 +1,1080 @@ +/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- + * + * The contents of this file are subject to the Netscape Public + * License Version 1.1 (the "License"); you may not use this file + * except in compliance with the License. You may obtain a copy of + * the License at http://www.mozilla.org/NPL/ + * + * Software distributed under the License is distributed on an "AS + * IS" basis, WITHOUT WARRANTY OF ANY KIND, either express or + * implied. See the License for the specific language governing + * rights and limitations under the License. + * + * The Original Code is mozilla.org code. + * + * The Initial Developer of the Original Code is Netscape + * Communications Corporation. Portions created by Netscape are + * Copyright (C) 1998 Netscape Communications Corporation. All + * Rights Reserved. + * + * Contributor(s): + * David Epstein + */ + +// File Overview.... +// +// These are QA test case implementations +// + +#include "stdafx.h" +#include "TestEmbed.h" +#include "BrowserImpl.h" +#include "BrowserFrm.h" +#include "UrlDialog.h" +#include "ProfileMgr.h" +#include "ProfilesDlg.h" +#include "Tests.h" +#include "QaUtils.h" +#include + +#ifdef _DEBUG +#define new DEBUG_NEW +#undef THIS_FILE +static char THIS_FILE[] = __FILE__; +#endif + +// Register message for FindDialog communication +static UINT WM_FINDMSG = ::RegisterWindowMessage(FINDMSGSTRING); + +BEGIN_MESSAGE_MAP(CTests, CWnd) + //{{AFX_MSG_MAP(CTests) + + ON_COMMAND(ID_TESTS_CHANGEURL, OnTestsChangeUrl) + ON_COMMAND(ID_TESTS_GLOBALHISTORY, OnTestsGlobalHistory) + ON_COMMAND(ID_TESTS_CREATEFILE, OnTestsCreateFile) + ON_COMMAND(ID_TESTS_CREATEPROFILE, OnTestsCreateprofile) + ON_COMMAND(ID_TESTS_ADDWEBPROGLISTENER, OnTestsAddWebProgListener) + ON_COMMAND(ID_TESTS_ADDHISTORYLISTENER, OnTestsAddHistoryListener) + ON_COMMAND(ID_INTERFACES_NSIFILE, OnInterfacesNsifile) + ON_COMMAND(ID_INTERFACES_NSISHISTORY, OnInterfacesNsishistory) + ON_COMMAND(ID_INTERFACES_NSIWEBNAV, OnInterfacesNsiwebnav) + ON_COMMAND(ID_TOOLS_REMOVEGHPAGE, OnToolsRemoveGHPage) + ON_COMMAND(ID_TOOLS_REMOVEALLGH, OnToolsRemoveAllGH) + + // DHARMA + ON_COMMAND(ID_CLIPBOARDCMD_PASTE, OnPasteTest) + ON_COMMAND(ID_CLIPBOARDCMD_COPYSELECTION, OnCopyTest) + ON_COMMAND(ID_CLIPBOARDCMD_SELECTALL, OnSelectAllTest) + ON_COMMAND(ID_CLIPBOARDCMD_SELECTNONE, OnSelectNoneTest) + ON_COMMAND(ID_CLIPBOARDCMD_CUTSELECTION, OnCutSelectionTest) + ON_COMMAND(ID_CLIPBOARDCMD_COPYLINKLOCATION, copyLinkLocationTest) + ON_COMMAND(ID_CLIPBOARDCMD_CANCOPYSELECTION, canCopySelectionTest) + ON_COMMAND(ID_CLIPBOARDCMD_CANCUTSELECTION, canCutSelectionTest) + ON_COMMAND(ID_CLIPBOARDCMD_CANPASTE, canPasteTest) + // DHARMA + + //}}AFX_MSG_MAP +END_MESSAGE_MAP() + +CTests::CTests(nsIWebBrowser* mWebBrowser, + nsIBaseWindow* mBaseWindow, + nsIWebNavigation* mWebNav, + CBrowserImpl *mpBrowserImpl) +{ + qaWebBrowser = mWebBrowser; + qaBaseWindow = mBaseWindow; + qaWebNav = mWebNav; + + qaBrowserImpl = mpBrowserImpl; +} + +CTests::~CTests() +{ +} + + +// de: Start QA test cases here +// ********************************************************* +// ********************************************************* + +void CTests::OnTestsChangeUrl() +{ + char *theUrl = "http://www.aol.com/"; + CUrlDialog myDialog; + nsresult rv; + + if (!qaWebNav) + { + CQaUtils::QAOutput("Web navigation object not found. Change URL test not performed.", 2); + return; + } + + if (myDialog.DoModal() == IDOK) + { + CQaUtils::QAOutput("Begin Change URL test.", 1); + strcpy(theUrl, myDialog.m_urlfield); + rv = qaWebNav->LoadURI(NS_ConvertASCIItoUCS2(theUrl).GetUnicode(), + nsIWebNavigation::LOAD_FLAGS_BYPASS_HISTORY); + CQaUtils::RvTestResult(rv, "rv LoadURI() test", 1); + CQaUtils::FormatAndPrintOutput("The url = ", theUrl, 2); + +/* + char *uriSpec; + nsCOMPtr pURI; + // GetcurrentURI() declared in nsIP3PUI.idl + // used with webNav obj in nsP3PObserverHTML.cpp, line 239 + // this will be used as an indep routine to verify the URI load + rv = qaWebNav->GetCurrentURI( getter_AddRefs( pURI ) ); + if(NS_FAILED(rv) || !pURI) + AfxMessageBox("Bad result for GetCurrentURI()."); + + rv = pURI->GetSpec(&uriSpec); + if (NS_FAILED(rv)) + AfxMessageBox("Bad result for GetSpec()."); + + AfxMessageBox("Start URL validation test()."); + if (strcmp(uriSpec, theUrl) == 0) + { + CQaUtils::QAOutput("Url loaded successfully. Test Passed.", 2); + } + else + { + CQaUtils::QAOutput("Url didn't load successfully. Test Failed.", 2); + } +*/ + CQaUtils::QAOutput("End Change URL test.", 1); + } + else + CQaUtils::QAOutput("Change URL test not executed.", 1); + +} + +// ********************************************************* + +void CTests::OnTestsGlobalHistory() +{ + // create instance of myHistory object. Call's XPCOM + // service manager to pass the contract ID. + + char *theUrl = "http://www.bogussite.com/"; + CUrlDialog myDialog; + + PRBool theRetVal = PR_FALSE; + nsresult rv; + + nsCOMPtr myHistory(do_GetService(NS_GLOBALHISTORY_CONTRACTID)); + + if (!myHistory) + { + CQaUtils::QAOutput("Couldn't find history object. No GH tests performed.", 2); + return; + } + + if (myDialog.DoModal() == IDOK) + { + CQaUtils::QAOutput("Begin IsVisited() and AddPage() tests.", 2); + + strcpy(theUrl, myDialog.m_urlfield); + + CQaUtils::FormatAndPrintOutput("The history url = ", theUrl, 1); + + // see if url is already in the GH file (pre-AddPage() test) + rv = myHistory->IsVisited(theUrl, &theRetVal); + CQaUtils::RvTestResult(rv, "rv IsVisited() test", 1); + + strMsg.Format("The IsVisited() return value = %d", theRetVal); + AfxMessageBox(strMsg); + + if (theRetVal) + CQaUtils::QAOutput("URL has been visited. Won't execute AddPage().", 2); + else + { + CQaUtils::QAOutput("URL hasn't been visited. Will execute AddPage().", 2); + + // adds a url to the global history file + rv = myHistory->AddPage(theUrl); + + // prints addPage() results to output file + if (NS_FAILED(rv)) + { + CQaUtils::QAOutput("Invalid results for AddPage(). Url not added. Test failed.", 1); + return; + } + else + CQaUtils::QAOutput("Valid results for AddPage(). Url added. Test passed.", 1); + + // checks if url was visited (post-AddPage() test) + myHistory->IsVisited(theUrl, &theRetVal); + + if (theRetVal) + CQaUtils::QAOutput("URL is visited; post-AddPage() test. IsVisited() test passed.", 1); + else + CQaUtils::QAOutput("URL isn't visited; post-AddPage() test. IsVisited() test failed.", 1); + } + CQaUtils::QAOutput("End IsVisited() and AddPage() tests.", 2); + } + else + CQaUtils::QAOutput("IsVisited() and AddPage() tests not executed.", 1); +} + + + +// ********************************************************* + +void CTests::OnTestsCreateFile() +{ + nsresult rv; + PRBool exists; + nsCOMPtr theTestFile(do_GetService(NS_LOCAL_FILE_CONTRACTID)); + + if (!theTestFile) + { + CQaUtils::QAOutput("File object doesn't exist. No File tests performed.", 2); + return; + } + + + CQaUtils::QAOutput("Start Create File test.", 2); + + rv = theTestFile->InitWithPath("c:\\temp\\theFile.txt"); + rv = theTestFile->Exists(&exists); + + CQaUtils::QAOutput("File (theFile.txt) doesn't exist. We'll create it.\r\n", 1); + rv = theTestFile->Create(nsIFile::NORMAL_FILE_TYPE, 0777); + CQaUtils::RvTestResult(rv, "File Create() test", 2); +} + +// ********************************************************* + +void CTests::OnTestsCreateprofile() +{ + CProfilesDlg myDialog; + nsresult rv; + + if (myDialog.DoModal() == IDOK) + { +// NS_WITH_SERVICE(nsIProfile, profileService, NS_PROFILE_CONTRACTID, &rv); + nsCOMPtr theProfServ(do_GetService(NS_PROFILE_CONTRACTID)); + if (!theProfServ) + { + CQaUtils::QAOutput("Didn't get profile service. No profile tests performed.", 2); + return; + } + + CQaUtils::QAOutput("Start Profile switch test.", 2); + + CQaUtils::QAOutput("Retrieved profile service.", 2); + rv = theProfServ->SetCurrentProfile(myDialog.m_SelectedProfile.GetUnicode()); + CQaUtils::RvTestResult(rv, "SetCurrentProfile() (profile switching) test", 2); + + CQaUtils::QAOutput("End Profile switch test.", 2); + } + else + CQaUtils::QAOutput("Profile switch test not executed.", 2); + +} + +// ********************************************************* + +void CTests::OnTestsAddWebProgListener() +{ + nsWeakPtr weakling( + dont_AddRef(NS_GetWeakReference(NS_STATIC_CAST(nsIWebProgressListener*, qaBrowserImpl)))); + rv = qaWebBrowser->AddWebBrowserListener(weakling, NS_GET_IID(nsIWebProgressListener)); + + CQaUtils::RvTestResult(rv, "AddWebBrowserListener(). Add Web Prog Lstnr test", 2); +} + +// ********************************************************* + +void CTests::OnTestsAddHistoryListener() +{ + // addSHistoryListener test + nsWeakPtr weakling( + dont_AddRef(NS_GetWeakReference(NS_STATIC_CAST(nsISHistoryListener*, qaBrowserImpl)))); + rv = qaWebBrowser->AddWebBrowserListener(weakling, NS_GET_IID(nsISHistoryListener)); + CQaUtils::RvTestResult(rv, "AddWebBrowserListener(). Add History Lstnr test", 2); +} + +// ********************************************************* +// ********************************************************* +// TOOLS to help us + + +void CTests::OnToolsRemoveGHPage() +{ + char *theUrl = "http://www.bogussite.com/"; + CUrlDialog myDialog; + PRBool theRetVal = PR_FALSE; + nsresult rv; + nsCOMPtr myGHistory(do_GetService(NS_GLOBALHISTORY_CONTRACTID)); + if (!myGHistory) + { + CQaUtils::QAOutput("Could not get the global history object.", 2); + return; + } + nsCOMPtr myHistory = do_QueryInterface(myGHistory, &rv); + if(!NS_SUCCEEDED(rv)) { + CQaUtils::QAOutput("Could not get the history object.", 2); + return; + } +// nsCOMPtr myHistory(do_GetInterface(myGHistory)); + + + if (myDialog.DoModal() == IDOK) + { + CQaUtils::QAOutput("Begin URL removal from the GH file.", 2); + strcpy(theUrl, myDialog.m_urlfield); + + myGHistory->IsVisited(theUrl, &theRetVal); + if (theRetVal) + { + rv = myHistory->RemovePage(theUrl); + CQaUtils::RvTestResult(rv, "RemovePage() test (url removal from GH file)", 2); + } + else + { + CQaUtils::QAOutput("The URL wasn't in the GH file.\r\n", 1); + } + CQaUtils::QAOutput("End URL removal from the GH file.", 2); + } + else + CQaUtils::QAOutput("URL removal from the GH file not executed.", 2); +} + +void CTests::OnToolsRemoveAllGH() +{ + + nsresult rv; + nsCOMPtr myGHistory(do_GetService(NS_GLOBALHISTORY_CONTRACTID)); + if (!myGHistory) + { + CQaUtils::QAOutput("Could not get the global history object.", 2); + return; + } + nsCOMPtr myHistory = do_QueryInterface(myGHistory, &rv); + if(!NS_SUCCEEDED(rv)) { + CQaUtils::QAOutput("Could not get the history object.", 2); + return; + } + + CQaUtils::QAOutput("Begin removal of all pages from the GH file.", 2); + + rv = myHistory->RemoveAllPages(); + CQaUtils::RvTestResult(rv, "removeAllPages(). Test .", 2); + + CQaUtils::QAOutput("End removal of all pages from the GH file.", 2); + + // removeAllPages() + +} + +// *********************************************************************** +// ************************** Interface Tests **************************** +// *********************************************************************** + +// nsIFile: + +void CTests::OnInterfacesNsifile() +{ + nsCOMPtr theTestFile(do_CreateInstance(NS_LOCAL_FILE_CONTRACTID)); + nsCOMPtr theFileOpDir(do_CreateInstance(NS_LOCAL_FILE_CONTRACTID)); + + if (!theTestFile) + { + CQaUtils::QAOutput("File object doesn't exist. No File tests performed.", 2); + return; + } + if (!theFileOpDir) + { + CQaUtils::QAOutput("File object doesn't exist. No File tests performed.", 2); + return; + } + + CQaUtils::QAOutput("Begin nsIFile tests.", 2); + + InitWithPathTest(theTestFile); + AppendRelativePathTest(theTestFile); + FileCreateTest(theTestFile); + FileExistsTest(theTestFile); + + // FILE COPY test + + FileCopyTest(theTestFile, theFileOpDir); + + // FILE MOVE test + + FileMoveTest(theTestFile, theFileOpDir); + + CQaUtils::QAOutput("End nsIFile tests.", 2); +} + +// *********************************************************************** +// Individual nsIFile tests + +void CTests::InitWithPathTest(nsILocalFile *theTestFile) +{ + rv = theTestFile->InitWithPath("c:\\temp\\"); + CQaUtils::RvTestResult(rv, "InitWithPath() test (initializing file path)", 2); +} + +void CTests::AppendRelativePathTest(nsILocalFile *theTestFile) +{ + rv = theTestFile->AppendRelativePath("myFile.txt"); + CQaUtils::RvTestResult(rv, "AppendRelativePath() test (append file to the path)", 2); +} + +void CTests::FileCreateTest(nsILocalFile *theTestFile) +{ + rv = theTestFile->Exists(&exists); + if (!exists) + { + CQaUtils::QAOutput("File doesn't exist. We'll try creating it.", 2); + rv = theTestFile->Create(nsIFile::NORMAL_FILE_TYPE, 0777); + CQaUtils::RvTestResult(rv, " File Create() test ('myFile.txt')", 2); + } + else + CQaUtils::QAOutput("File already exists (myFile.txt). We won't create it.", 2); +} + +void CTests::FileExistsTest(nsILocalFile *theTestFile) +{ + rv = theTestFile->Exists(&exists); + if (!exists) + CQaUtils::QAOutput("Exists() test Failed. File (myFile.txt) doesn't exist.", 2); + else + CQaUtils::QAOutput("Exists() test Passed. File (myFile.txt) exists.", 2); + +} + +void CTests::FileCopyTest(nsILocalFile *theTestFile, nsILocalFile *theFileOpDir) +{ + CQaUtils::QAOutput("Start File Copy test.", 2); + + rv = theFileOpDir->InitWithPath("c:\\temp\\"); + if (NS_FAILED(rv)) + CQaUtils::QAOutput("The target dir wasn't found.", 2); + else + CQaUtils::QAOutput("The target dir was found.", 2); + + rv = theTestFile->InitWithPath("c:\\temp\\myFile.txt"); + if (NS_FAILED(rv)) + CQaUtils::QAOutput("The path wasn't found.", 2); + else + CQaUtils::QAOutput("The path was found.", 2); + + rv = theTestFile->CopyTo(theFileOpDir, "myFile2.txt"); + CQaUtils::RvTestResult(rv, "rv CopyTo() test", 2); + + rv = theTestFile->InitWithPath("c:\\temp\\myFile2.txt"); + rv = theTestFile->Exists(&exists); + if (!exists) + CQaUtils::QAOutput("File didn't copy. CopyTo() test Failed.", 2); + else + CQaUtils::QAOutput("File copied. CopyTo() test Passed.", 2); +} + +void CTests::FileMoveTest(nsILocalFile *theTestFile, nsILocalFile *theFileOpDir) +{ + CQaUtils::QAOutput("Start File Move test.", 2); + + rv = theFileOpDir->InitWithPath("c:\\Program Files\\"); + if (NS_FAILED(rv)) + CQaUtils::QAOutput("The target dir wasn't found.", 2); + + rv = theTestFile->InitWithPath("c:\\temp\\myFile2.txt"); + if (NS_FAILED(rv)) + CQaUtils::QAOutput("The path wasn't found.", 2); + + rv = theTestFile->MoveTo(theFileOpDir, "myFile2.txt"); + CQaUtils::RvTestResult(rv, "MoveTo() test", 2); + + rv = theTestFile->InitWithPath("c:\\Program Files\\myFile2.txt"); + rv = theTestFile->Exists(&exists); + if (!exists) + CQaUtils::QAOutput("File wasn't moved. MoveTo() test Failed.", 2); + else + CQaUtils::QAOutput("File was moved. MoveTo() test Passed.", 2); +} + +// *********************************************************************** +// *********************************************************************** +// nsISHistory & nsIHistoryEntry ifaces: + +void CTests::OnInterfacesNsishistory() +{ + nsresult rv; + PRInt32 numEntries = 5; + PRInt32 theIndex; + PRInt32 theMaxLength = 100; + + CString shString; + + nsCOMPtr theSessionHistory; + nsCOMPtr theHistoryEntry; + nsCOMPtr theUri; + // do_QueryInterface + // NS_HISTORYENTRY_CONTRACTID + // NS_SHISTORYLISTENER_CONTRACTID + + // get Session History through web nav iface + if (qaWebNav) + qaWebNav->GetSessionHistory( getter_AddRefs(theSessionHistory)); + + if (!theSessionHistory) + { + CQaUtils::QAOutput("theSessionHistory object wasn't created. No session history tests performed.", 2); + return; + } + else + CQaUtils::QAOutput("theSessionHistory object was created.", 2); + + + // test count attribute in nsISHistory.idl + GetCountTest(theSessionHistory, &numEntries); + + // test index attribute in nsISHistory.idl + GetIndexTest(theSessionHistory, &theIndex); + + // test maxLength attribute in nsISHistory.idl + GetMaxLength(theSessionHistory, theMaxLength); + SetMaxLength(theSessionHistory, &theMaxLength); + + CQaUtils::QAOutput("Start nsiHistoryEntry tests.", 2); + + strMsg.Format("numEntries = %d", numEntries); + AfxMessageBox(strMsg); + + // get theHistoryEntry object + theSessionHistory->GetEntryAtIndex(0, PR_FALSE, getter_AddRefs(theHistoryEntry)); + if (!theHistoryEntry) + CQaUtils::QAOutput("We didn't get the History Entry object.", 1); + else + { + CQaUtils::QAOutput("We have the History Entry object!", 1); + + // getEntryAtIndex() tests + for (theIndex = 0; theIndex < numEntries; theIndex++) + { + strMsg.Format("the index = %d", theIndex); + AfxMessageBox(strMsg); + +// GetEntryAtIndexTest(theSessionHistory, theHistoryEntry, theIndex); + theSessionHistory->GetEntryAtIndex(theIndex, PR_FALSE, getter_AddRefs(theHistoryEntry)); + // nsiHistoryEntry.idl tests + + // test URI attribute in nsIHistoryEntry.idl + GetURIHistTest(theHistoryEntry); + + // test title attribute in nsIHistoryEntry.idl + GetTitleHistTest(theHistoryEntry); + + // test isSubFrame attribute in nsIHistoryEntry.idl + GetIsSubFrameTest(theHistoryEntry); + + } // end for loop + } // end outer else + + + // test SHistoryEnumerator attribute in nsISHistory.idl + nsCOMPtr theSimpleEnum; + +// GetSHEnumTest(theSessionHistory, theSimpleEnum); + + rv = theSessionHistory->GetSHistoryEnumerator(getter_AddRefs(theSimpleEnum)); + if (!theSimpleEnum) + CQaUtils::QAOutput("theSimpleEnum for GetSHistoryEnumerator() invalid. Test failed.", 1); + else + CQaUtils::RvTestResult(rv, "GetSHistoryEnumerator() (SHistoryEnumerator attribute) test", 2); + + SimpleEnumTest(theSimpleEnum); + + // PurgeHistory() test + + PurgeHistoryTest(theSessionHistory, numEntries); +} + +// *********************************************************************** +// Individual nsISHistory tests + +void CTests::GetCountTest(nsISHistory *theSessionHistory, PRInt32 *numEntries) +{ + rv = theSessionHistory->GetCount(numEntries); + if (!(*numEntries)) + CQaUtils::QAOutput("numEntries for GetCount() invalid. Test failed.", 1); + else + CQaUtils::RvTestResult(rv, "GetCount() (count attribute) test", 2); +} + +void CTests::GetIndexTest(nsISHistory *theSessionHistory, PRInt32 *theIndex) +{ + rv = theSessionHistory->GetIndex(theIndex); + if (!(*theIndex)) + CQaUtils::QAOutput("theIndex for GetIndex() invalid. Test failed.", 1); + else + CQaUtils::RvTestResult(rv, "GetIndex() (index attribute) test", 2); +} + +void CTests::GetMaxLength(nsISHistory *theSessionHistory, PRInt32 theMaxLength) +{ + rv = theSessionHistory->SetMaxLength(theMaxLength); + CQaUtils::RvTestResult(rv, "SetMaxLength() (MaxLength attribute) test", 2); +} + +void CTests::SetMaxLength(nsISHistory *theSessionHistory, PRInt32 *theMaxLength) +{ + rv = theSessionHistory->GetMaxLength(theMaxLength); + if (!(*theMaxLength)) + CQaUtils::QAOutput("theMaxLength for GetMaxLength() invalid. Test failed.", 1); + else + CQaUtils::RvTestResult(rv, "GetMaxLength() (MaxLength attribute) test", 2); +} + +/* +void CTests::GetEntryAtIndexTest(nsISHistory *theSessionHistory, + nsIHistoryEntry *theHistoryEntry, + PRInt32 theIndex) +{ + theSessionHistory->GetEntryAtIndex(theIndex, PR_FALSE, getter_AddRefs(theHistoryEntry)); +} +*/ + +void CTests::GetURIHistTest(nsIHistoryEntry* theHistoryEntry) +{ + rv = theHistoryEntry->GetURI(getter_AddRefs(theUri)); + if (!theUri) + CQaUtils::QAOutput("theUri for GetURI() invalid. Test failed.", 1); + else + { + CQaUtils::RvTestResult(rv, "GetURI() (URI attribute) test", 1); + rv = theUri->GetSpec(&uriSpec); + if (NS_FAILED(rv)) + CQaUtils::QAOutput("We didn't get the uriSpec.", 1); + else + CQaUtils::FormatAndPrintOutput("The SH Url = ", uriSpec, 2); + } +} + +void CTests::GetTitleHistTest(nsIHistoryEntry* theHistoryEntry) +{ + nsXPIDLString theTitle; + const char * titleCString; + + rv = theHistoryEntry->GetTitle(getter_Copies(theTitle)); + if (!theTitle) + CQaUtils::QAOutput("theTitle for GetTitle() invalid. Test failed.", 1); + else + CQaUtils::RvTestResult(rv, "GetTitle() (title attribute) test", 1); + titleCString = NS_ConvertUCS2toUTF8(theTitle).get(); + CQaUtils::FormatAndPrintOutput("The title = ", (char *)titleCString, 2); + +} + +void CTests::GetIsSubFrameTest(nsIHistoryEntry* theHistoryEntry) +{ + PRBool isSubFrame; + + rv = theHistoryEntry->GetIsSubFrame(&isSubFrame); + if (!isSubFrame) + CQaUtils::QAOutput("isSubFrame for GetIsSubFrame() invalid. Test failed.", 1); + else + CQaUtils::RvTestResult(rv, "GetIsSubFrame() (isSubFrame attribute) test", 1); + strMsg.Format("The subFrame value = %d", isSubFrame); + AfxMessageBox(strMsg); +} + +/* +void CTests::GetSHEnumTest(nsISHistory *theSessionHistory, + nsISimpleEnumerator *theSimpleEnum) +{ + rv = theSessionHistory->GetSHistoryEnumerator(getter_AddRefs(theSimpleEnum)); + if (!theSimpleEnum) + CQaUtils::QAOutput("theSimpleEnum for GetSHistoryEnumerator() invalid. Test failed.", 1); + else + CQaUtils::RvTestResult(rv, "GetSHistoryEnumerator() (SHistoryEnumerator attribute) test", 2); +} +*/ + +void CTests::SimpleEnumTest(nsISimpleEnumerator *theSimpleEnum) +{ + PRBool bMore = PR_FALSE; + nsCOMPtr nextObj; + nsCOMPtr nextHistoryEntry; + + while (NS_SUCCEEDED(theSimpleEnum->HasMoreElements(&bMore)) && bMore) + { + theSimpleEnum->GetNext(getter_AddRefs(nextObj)); + if (!nextObj) + continue; + nextHistoryEntry = do_QueryInterface(nextObj); + if (!nextHistoryEntry) + continue; + rv = nextHistoryEntry->GetURI(getter_AddRefs(theUri)); + rv = theUri->GetSpec(&uriSpec); + if (!uriSpec) + CQaUtils::QAOutput("uriSpec for GetSpec() invalid. Test failed.", 1); + else + CQaUtils::FormatAndPrintOutput("The SimpleEnum URL = ", uriSpec, 2); + } +} + +void CTests::PurgeHistoryTest(nsISHistory* theSessionHistory, PRInt32 numEntries) +{ + rv = theSessionHistory->PurgeHistory(numEntries); + CQaUtils::RvTestResult(rv, "PurgeHistory() test", 2); +} + +// *********************************************************************** +// *********************************************************************** +// nsIWebNavigation iface + +void CTests::OnInterfacesNsiwebnav() +{ + if (qaWebNav) + CQaUtils::QAOutput("We have the web nav object.", 2); + else { + CQaUtils::QAOutput("We don't have the web nav object. No tests performed.", 2); + return; + } + + // canGoBack attribute test + CanGoBackTest(); + + // GoBack test + GoBackTest(); + + // canGoForward attribute test + CanGoForwardTest(); + + // GoForward test + GoForwardTest(); + + // GotoIndex test + GoToIndexTest(); + + // LoadURI() & reload tests + + CQaUtils::QAOutput("Run a few LoadURI() tests.", 2); + + LoadUriTest("http://www.yahoo.com/", nsIWebNavigation::LOAD_FLAGS_NONE); + ReloadTest(nsIWebNavigation::LOAD_FLAGS_NONE); + + LoadUriTest("http://www.cisco.com/", nsIWebNavigation::LOAD_FLAGS_MASK); +// ReloadTest(nsIWebNavigation::LOAD_FLAGS_MASK); + + LoadUriTest("http://www.netscape.com/", nsIWebNavigation::LOAD_FLAGS_IS_LINK); + LoadUriTest("http://www.aol.com/", nsIWebNavigation::LOAD_FLAGS_BYPASS_HISTORY); + + // Stop() test + StopUriTest("http://www.microsoft.com/"); + + // document test + GetDocumentTest(); + + // uri test + GetCurrentURITest(); + + // session history test + GetSHTest(); +} + +// *********************************************************************** +// Individual nsISHistory tests + +void CTests::CanGoBackTest() +{ + PRBool canGoBack = PR_FALSE; + rv = qaWebNav->GetCanGoBack(&canGoBack); + if (!canGoBack) + CQaUtils::QAOutput("canGoBack for GetCanGoBack() invalid. Test failed.", 1); + else + CQaUtils::RvTestResult(rv, "GetCanGoBack() attribute test", 2); + strMsg.Format("canGoBack value = %d", canGoBack); + AfxMessageBox(strMsg); +} + +void CTests::GoBackTest() +{ + rv = qaWebNav->GoBack(); + CQaUtils::RvTestResult(rv, "GoBack() test", 2); +} + +void CTests::CanGoForwardTest() +{ + PRBool canGoForward = PR_FALSE; + rv = qaWebNav->GetCanGoForward(&canGoForward); + if (!canGoForward) + CQaUtils::QAOutput("canGoForward for GetCanGoForward() invalid. Test failed.", 1); + else + CQaUtils::RvTestResult(rv, "GetCanGoForward() attribute test", 2); + strMsg.Format("canGoForward value = %d", canGoForward); + AfxMessageBox(strMsg); +} + +void CTests::GoForwardTest() +{ + rv = qaWebNav->GoForward(); + CQaUtils::RvTestResult(rv, "GoForward() test", 2); +} + +void CTests::GoToIndexTest() +{ + PRInt32 theIndex = 0; + + rv = qaWebNav->GotoIndex(theIndex); + CQaUtils::RvTestResult(rv, "GotoIndex() test", 2); +} + +void CTests::LoadUriTest(char *theUrl, const unsigned long theFlag) +{ + char theTotalString[500]; + char theFlagName[100]; + + switch(theFlag) + { + case nsIWebNavigation::LOAD_FLAGS_NONE: + strcpy(theFlagName, "LOAD_FLAGS_NONE"); + break; + case nsIWebNavigation::LOAD_FLAGS_MASK: + strcpy(theFlagName, "LOAD_FLAGS_MASK"); + break; + case nsIWebNavigation::LOAD_FLAGS_IS_REFRESH: + strcpy(theFlagName, "LOAD_FLAGS_IS_REFRESH"); + break; + case nsIWebNavigation::LOAD_FLAGS_IS_LINK: + strcpy(theFlagName, "LOAD_FLAGS_IS_LINK"); + break; + case nsIWebNavigation::LOAD_FLAGS_BYPASS_HISTORY: + strcpy(theFlagName, "LOAD_FLAGS_BYPASS_HISTORY"); + break; + case nsIWebNavigation::LOAD_FLAGS_REPLACE_HISTORY: + strcpy(theFlagName, "LOAD_FLAGS_REPLACE_HISTORY"); + break; + case nsIWebNavigation::LOAD_FLAGS_BYPASS_CACHE: + strcpy(theFlagName, "LOAD_FLAGS_BYPASS_CACHE"); + break; + case nsIWebNavigation::LOAD_FLAGS_BYPASS_PROXY: + strcpy(theFlagName, "LOAD_FLAGS_BYPASS_PROXY"); + break; + } + + rv = qaWebNav->LoadURI(NS_ConvertASCIItoUCS2(theUrl).GetUnicode(), + theFlag); + sprintf(theTotalString, "%s%s%s%s%s", "LoadURI(): ", theUrl, " w/ ", theFlagName, " test"); + CQaUtils::RvTestResult(rv, theTotalString, 2); +} + +void CTests::ReloadTest(const unsigned long theFlag) +{ + char theTotalString[500]; + char theFlagName[100]; + + switch(theFlag) + { + case nsIWebNavigation::LOAD_FLAGS_NONE: + strcpy(theFlagName, "LOAD_FLAGS_NONE"); + break; + case nsIWebNavigation::LOAD_FLAGS_MASK: + strcpy(theFlagName, "LOAD_FLAGS_MASK"); + break; + case nsIWebNavigation::LOAD_FLAGS_IS_REFRESH: + strcpy(theFlagName, "LOAD_FLAGS_IS_REFRESH"); + break; + case nsIWebNavigation::LOAD_FLAGS_IS_LINK: + strcpy(theFlagName, "LOAD_FLAGS_IS_LINK"); + break; + case nsIWebNavigation::LOAD_FLAGS_BYPASS_HISTORY: + strcpy(theFlagName, "LOAD_FLAGS_BYPASS_HISTORY"); + break; + case nsIWebNavigation::LOAD_FLAGS_REPLACE_HISTORY: + strcpy(theFlagName, "LOAD_FLAGS_REPLACE_HISTORY"); + break; + case nsIWebNavigation::LOAD_FLAGS_BYPASS_CACHE: + strcpy(theFlagName, "LOAD_FLAGS_BYPASS_CACHE"); + break; + case nsIWebNavigation::LOAD_FLAGS_BYPASS_PROXY: + strcpy(theFlagName, "LOAD_FLAGS_BYPASS_PROXY"); + break; + } + + rv = qaWebNav->Reload(theFlag); + sprintf(theTotalString, "%s%s%s%s", "Reload(): ", " w/ ", theFlagName, " test"); + CQaUtils::RvTestResult(rv, theTotalString, 2); +} + +void CTests::StopUriTest(char *theUrl) +{ + char theTotalString[200]; + + qaWebNav->LoadURI(NS_ConvertASCIItoUCS2(theUrl).GetUnicode(), + nsIWebNavigation::LOAD_FLAGS_NONE); + rv = qaWebNav->Stop(); + sprintf(theTotalString, "%s%s%s", "Stop(): ", theUrl, " test"); + CQaUtils::RvTestResult(rv, theTotalString, 2); +} + +void CTests::GetDocumentTest() +{ + nsCOMPtr theDocument; + rv = qaWebNav->GetDocument(getter_AddRefs(theDocument)); + if (!theDocument) + CQaUtils::QAOutput("We didn't get the document. Test failed.", 2); + else + CQaUtils::RvTestResult(rv, "GetDocument() test", 2); +} + +void CTests::GetCurrentURITest() +{ + nsCOMPtr theUri; + rv = qaWebNav->GetCurrentURI(getter_AddRefs(theUri)); + if (!theUri) + CQaUtils::QAOutput("We didn't get the URI. Test failed.", 2); + else + CQaUtils::RvTestResult(rv, "GetCurrentURI() test", 2); + + char *uriSpec; + rv = theUri->GetSpec(&uriSpec); + + CQaUtils::FormatAndPrintOutput("the uri = ", uriSpec, 2); +} + +void CTests::GetSHTest() +{ + nsCOMPtr theSessionHistory; + rv = qaWebNav->GetSessionHistory(getter_AddRefs(theSessionHistory)); + if (!theSessionHistory) + CQaUtils::QAOutput("We didn't get the session history. Test failed.", 2); + else + CQaUtils::RvTestResult(rv, "GetSessionHistory() test", 2); +} + +// *********************************************************************** +//DHARMA - nsIClipboardCommands +// Checking the paste() method. +void CTests::OnPasteTest() +{ + // AfxMessageBox("testing paste command"); + nsCOMPtr clipCmds = do_GetInterface(qaWebBrowser); + if (clipCmds) + clipCmds->Paste(); +} + +// Checking the copySelection() method. +void CTests::OnCopyTest() +{ +// AfxMessageBox("testing copyselection command"); + nsCOMPtr clipCmds = do_GetInterface(qaWebBrowser); + if (clipCmds) + clipCmds->CopySelection(); +} + +// Checking the selectAll() method. +void CTests::OnSelectAllTest() +{ + AfxMessageBox("testing selectall method"); + nsCOMPtr clipCmds = do_GetInterface(qaWebBrowser); + if (clipCmds) + clipCmds->SelectAll(); +} + +// Checking the selectNone() method. +void CTests::OnSelectNoneTest() +{ + AfxMessageBox("testing selectnone method"); + nsCOMPtr clipCmds = do_GetInterface(qaWebBrowser); + if (clipCmds) + clipCmds->SelectNone(); +} + +// Checking the cutSelection() method. +void CTests::OnCutSelectionTest() +{ +// AfxMessageBox("testing cutselection method"); + nsCOMPtr clipCmds = do_GetInterface(qaWebBrowser); + if (clipCmds) + clipCmds->CutSelection(); +} +// Checking the copyLinkLocation() method. +void CTests::copyLinkLocationTest() +{ +// AfxMessageBox("testing cutselection method"); + nsCOMPtr clipCmds = do_GetInterface(qaWebBrowser); + if (clipCmds) + clipCmds->CopyLinkLocation(); +} + +// Checking the canCopySelection() method. +void CTests::canCopySelectionTest() +{ + PRBool canCopySelection = PR_FALSE; + nsCOMPtr clipCmds = do_GetInterface(qaWebBrowser); + if (clipCmds) + clipCmds->CanCopySelection(&canCopySelection); + + if(canCopySelection) + AfxMessageBox("The selection you made Can be copied"); + else + AfxMessageBox("Either you didnot make a selection or The selection you made Cannot be copied"); +} + +// Checking the canCutSelection() method. +void CTests::canCutSelectionTest() +{ + PRBool canCutSelection = PR_FALSE; + nsCOMPtr clipCmds = do_GetInterface(qaWebBrowser); + if (clipCmds) + clipCmds->CanCutSelection(&canCutSelection); + + if(canCutSelection) + AfxMessageBox("The selection you made Can be cut"); + else + AfxMessageBox("Either you didnot make a selection or The selection you made Cannot be cut"); +} + +// Checking the canPaste() method. +void CTests::canPasteTest() +{ + PRBool canPaste = PR_FALSE; + nsCOMPtr clipCmds = do_GetInterface(qaWebBrowser); + if (clipCmds) + clipCmds->CanPaste(&canPaste); + + if(canPaste) + AfxMessageBox("The clipboard contents can be pasted here"); + else + AfxMessageBox("The clipboard contents cannot be pasted here"); +} + +//DHARMA + + +// *********************************************************************** +// ***************** Bug Verifications ****************** +// *********************************************************************** + +void CTests::OnVerifybugs70228() +{ + CQaUtils::QAOutput("Not implemented yet.", 0); +/* + nsCOMPtr + myHALD(do_GetService(NS_IHELPERAPPLAUNCHERDLG_CONTRACTID)); + if (!myHALD) + CQaUtils::QAOutput("Object not created. It's NOT a service!", 2); + else + CQaUtils::QAOutput("Object is created. But should it?! It's NOT a service!", 2); + + nsCOMPtr + myHALD(do_CreateInstance(NS_IHELPERAPPLAUNCHERDLG_CONTRACTID)); + if (!myHALD) + CQaUtils::QAOutput("Object not created. It should be. It's a component!", 2); + else + CQaUtils::QAOutput("Object is created. It's a component!", 2); +*/ +/* +nsCOMPtr + myHAL(do_CreateInstance(NS_IHELPERAPPLAUNCHERDLG_CONTRACTID)); + + rv = myHALD->show(myHal, mySupp); +*/ +} + diff --git a/mozilla/embedding/qa/testembed/Tests.h b/mozilla/embedding/qa/testembed/Tests.h new file mode 100644 index 00000000000..36e64012411 --- /dev/null +++ b/mozilla/embedding/qa/testembed/Tests.h @@ -0,0 +1,158 @@ +/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- + * + * The contents of this file are subject to the Netscape Public + * License Version 1.1 (the "License"); you may not use this file + * except in compliance with the License. You may obtain a copy of + * the License at http://www.mozilla.org/NPL/ + * + * Software distributed under the License is distributed on an "AS + * IS" basis, WITHOUT WARRANTY OF ANY KIND, either express or + * implied. See the License for the specific language governing + * rights and limitations under the License. + * + * The Original Code is mozilla.org code. + * + * The Initial Developer of the Original Code is Netscape + * Communications Corporation. Portions created by Netscape are + * Copyright (C) 1998 Netscape Communications Corporation. All + * Rights Reserved. + * + * Contributor(s): + * David Epstein + */ + +// Tests.h : header file for QA test cases +// +///////////////////////////////////////////////////////////////////////////// + +#ifndef _TESTS_H +#define _TESTS_H + +#if _MSC_VER > 1000 + #pragma once +#endif + +#include "BrowserView.h" +#include "BrowserImpl.h" + +///////////////////////////////////////////////////////////////////////////// +// CTESTS class + +class CBrowserImpl; +class CBrowserView; + +class CTests : public CWnd +{ +public: + CTests(nsIWebBrowser* mWebBrowser, + nsIBaseWindow* mBaseWindow, + nsIWebNavigation* mWebNav, + CBrowserImpl *mpBrowserImpl); + virtual ~CTests(); + + // Some helper methods + + // Mozilla interfaces + // + nsCOMPtr qaWebBrowser; + nsCOMPtr qaBaseWindow; + nsCOMPtr qaWebNav; + + CBrowserImpl *qaBrowserImpl; + + // local test methods + + // local test variables + nsresult rv; + CString strMsg; + char theUrl[200]; + char * uriSpec; + PRBool exists; + PRInt32 numEntries; + PRInt32 theIndex; + + nsCOMPtr theUri; + + // Overrides + // ClassWizard generated virtual function overrides + //{{AFX_VIRTUAL(CTests) + protected: + //}}AFX_VIRTUAL + + + // Generated message map functions +protected: + //{{AFX_MSG(CTests) + + afx_msg void OnUpdateNavBack(CCmdUI* pCmdUI); + afx_msg void OnUpdateNavForward(CCmdUI* pCmdUI); + afx_msg void OnUpdateNavStop(CCmdUI* pCmdUI); + afx_msg void OnUpdateCut(CCmdUI* pCmdUI); + afx_msg void OnUpdateCopy(CCmdUI* pCmdUI); + afx_msg void OnUpdatePaste(CCmdUI* pCmdUI); + + // qa tests + afx_msg void OnTestsChangeUrl(); + afx_msg void OnTestsGlobalHistory(); + afx_msg void OnTestsCreateFile(); + afx_msg void OnTestsCreateprofile(); + afx_msg void OnTestsAddWebProgListener(); + afx_msg void OnTestsAddHistoryListener(); + afx_msg void OnInterfacesNsifile(); + afx_msg void OnInterfacesNsishistory(); + afx_msg void OnInterfacesNsiwebnav(); + afx_msg void OnToolsRemoveGHPage(); + afx_msg void OnToolsRemoveAllGH(); + afx_msg void OnVerifybugs70228(); + + //DHARMA + afx_msg void OnPasteTest(); + afx_msg void OnCopyTest(); + afx_msg void OnSelectAllTest(); + afx_msg void OnSelectNoneTest(); + afx_msg void OnCutSelectionTest(); + afx_msg void copyLinkLocationTest(); + afx_msg void canCopySelectionTest(); + afx_msg void canCutSelectionTest(); + afx_msg void canPasteTest(); + //DHARMA + + //}}AFX_MSG + DECLARE_MESSAGE_MAP() + + // individual nsIFile tests + void InitWithPathTest(nsILocalFile *); + void AppendRelativePathTest(nsILocalFile *); + void FileCreateTest(nsILocalFile *); + void FileExistsTest(nsILocalFile *); + void FileCopyTest(nsILocalFile *, nsILocalFile *); + void FileMoveTest(nsILocalFile *, nsILocalFile *); + + // individual nsISHistory tests + void GetCountTest(nsISHistory *, PRInt32 *); + void GetIndexTest(nsISHistory *, PRInt32 *); + void GetMaxLength(nsISHistory *, PRInt32); + void SetMaxLength(nsISHistory *, PRInt32 *); + void GetEntryAtIndexTest(nsISHistory *, nsIHistoryEntry *, PRInt32 theIndex); + void GetURIHistTest(nsIHistoryEntry *); + void GetTitleHistTest(nsIHistoryEntry *); + void GetIsSubFrameTest(nsIHistoryEntry *); + void GetSHEnumTest(nsISHistory*, nsISimpleEnumerator *); + void SimpleEnumTest(nsISimpleEnumerator *); + void PurgeHistoryTest(nsISHistory *, PRInt32); + + // individual nsIWebNavigation tests + void CanGoBackTest(); + void GoBackTest(); + void CanGoForwardTest(); + void GoForwardTest(); + void GoToIndexTest(); + void LoadUriTest(char *, const unsigned long); + void ReloadTest(const unsigned long); + void StopUriTest(char *); + void GetDocumentTest(void); + void GetCurrentURITest(void); + void GetSHTest(void); +}; + +#endif //_TESTS_H diff --git a/mozilla/embedding/qa/testembed/UrlDialog.cpp b/mozilla/embedding/qa/testembed/UrlDialog.cpp new file mode 100644 index 00000000000..1fdf3443f2a --- /dev/null +++ b/mozilla/embedding/qa/testembed/UrlDialog.cpp @@ -0,0 +1,54 @@ +// UrlDialog.cpp : implementation file +// + +#include "stdafx.h" +#include "Testembed.h" +#include "UrlDialog.h" + +#ifdef _DEBUG +#define new DEBUG_NEW +#undef THIS_FILE +static char THIS_FILE[] = __FILE__; +#endif + +///////////////////////////////////////////////////////////////////////////// +// CUrlDialog dialog + + +CUrlDialog::CUrlDialog(CWnd* pParent /*=NULL*/) + : CDialog(CUrlDialog::IDD, pParent) +{ + //{{AFX_DATA_INIT(CUrlDialog) + m_urlfield = _T(""); + //}}AFX_DATA_INIT +} + + +void CUrlDialog::DoDataExchange(CDataExchange* pDX) +{ + CDialog::DoDataExchange(pDX); + //{{AFX_DATA_MAP(CUrlDialog) + DDX_Text(pDX, IDC_URLFIELD, m_urlfield); + //}}AFX_DATA_MAP +} + + +BEGIN_MESSAGE_MAP(CUrlDialog, CDialog) + //{{AFX_MSG_MAP(CUrlDialog) + ON_EN_CHANGE(IDC_URLFIELD, OnChangeUrlfield) + //}}AFX_MSG_MAP +END_MESSAGE_MAP() + +///////////////////////////////////////////////////////////////////////////// +// CUrlDialog message handlers + +void CUrlDialog::OnChangeUrlfield() +{ + // TODO: If this is a RICHEDIT control, the control will not + // send this notification unless you override the CDialog::OnInitDialog() + // function and call CRichEditCtrl().SetEventMask() + // with the ENM_CHANGE flag ORed into the mask. + + // TODO: Add your control notification handler code here + +} diff --git a/mozilla/embedding/qa/testembed/UrlDialog.h b/mozilla/embedding/qa/testembed/UrlDialog.h new file mode 100644 index 00000000000..ab65ae3cf3f --- /dev/null +++ b/mozilla/embedding/qa/testembed/UrlDialog.h @@ -0,0 +1,46 @@ +#if !defined(AFX_URLDIALOG_H__260C4EE1_2F8E_11D5_99F0_00C04FA02BE6__INCLUDED_) +#define AFX_URLDIALOG_H__260C4EE1_2F8E_11D5_99F0_00C04FA02BE6__INCLUDED_ + +#if _MSC_VER > 1000 +#pragma once +#endif // _MSC_VER > 1000 +// UrlDialog.h : header file +// + +///////////////////////////////////////////////////////////////////////////// +// CUrlDialog dialog + +class CUrlDialog : public CDialog +{ +// Construction +public: + CUrlDialog(CWnd* pParent = NULL); // standard constructor + +// Dialog Data + //{{AFX_DATA(CUrlDialog) + enum { IDD = IDD_URLDIALOG }; + CString m_urlfield; + //}}AFX_DATA + + +// Overrides + // ClassWizard generated virtual function overrides + //{{AFX_VIRTUAL(CUrlDialog) + protected: + virtual void DoDataExchange(CDataExchange* pDX); // DDX/DDV support + //}}AFX_VIRTUAL + +// Implementation +protected: + + // Generated message map functions + //{{AFX_MSG(CUrlDialog) + afx_msg void OnChangeUrlfield(); + //}}AFX_MSG + DECLARE_MESSAGE_MAP() +}; + +//{{AFX_INSERT_LOCATION}} +// Microsoft Visual C++ will insert additional declarations immediately before the previous line. + +#endif // !defined(AFX_URLDIALOG_H__260C4EE1_2F8E_11D5_99F0_00C04FA02BE6__INCLUDED_) diff --git a/mozilla/embedding/qa/testembed/makefile.win b/mozilla/embedding/qa/testembed/makefile.win new file mode 100644 index 00000000000..7ca264fa825 --- /dev/null +++ b/mozilla/embedding/qa/testembed/makefile.win @@ -0,0 +1,78 @@ +# +# The contents of this file are subject to the Netscape Public +# License Version 1.1 (the "License"); you may not use this file +# except in compliance with the License. You may obtain a copy of +# the License at http://www.mozilla.org/NPL/ +# +# Software distributed under the License is distributed on an "AS +# IS" basis, WITHOUT WARRANTY OF ANY KIND, either express or +# implied. See the License for the specific language governing +# rights and limitations under the License. +# +# The Original Code is Mozilla Communicator client code, +# released March 31, 1998. +# +# The Initial Developer of the Original Code is Netscape Communications +# Corporation. Portions created by Netscape are +# Copyright (C) 1999 Netscape Communications Corporation. All +# Rights Reserved. +# +# Contributor(s): + +DEPTH=..\..\.. + +DIRS=components \ + $(NULL) + +MAKE_OBJ_TYPE = EXE + +MODULE = testembed +PROGRAM = .\$(OBJDIR)\$(MODULE).exe +RESFILE = $(MODULE).res + +LINCS = -Icomponents \ + $(NULL) + +OBJS = \ + .\$(OBJDIR)\TestEmbed.obj \ + .\$(OBJDIR)\BrowserFrm.obj \ + .\$(OBJDIR)\BrowserFrameGlue.obj \ + .\$(OBJDIR)\BrowserView.obj \ + .\$(OBJDIR)\BrowserImpl.obj \ + .\$(OBJDIR)\BrowserImplWebPrgrsLstnr.obj \ + .\$(OBJDIR)\BrowserImplHistoryLstnr.obj \ + .\$(OBJDIR)\BrowserImplCtxMenuLstnr.obj \ + .\$(OBJDIR)\Dialogs.obj \ + .\$(OBJDIR)\ProfileMgr.obj \ + .\$(OBJDIR)\ProfilesDlg.obj \ + .\$(OBJDIR)\winEmbedFileLocProvider.obj \ + .\$(OBJDIR)\MostRecentUrls.obj \ + .\$(OBJDIR)\PrintProgressDialog.obj \ + .\$(OBJDIR)\Preferences.obj \ + .\$(OBJDIR)\StdAfx.obj \ + .\$(OBJDIR)\UrlDialog.obj \ + .\$(OBJDIR)\QaUtils.obj \ + .\$(OBJDIR)\Tests.obj \ + $(NULL) + +LLIBS= \ + $(DIST)\lib\baseembed_s.lib \ + $(DIST)\lib\gkgfxwin.lib \ + $(DIST)\lib\xpcom.lib \ + $(DIST)\lib\mfcEmbedComponents.lib \ + $(LIBNSPR) \ + $(NULL) + +LCFLAGS = /D "_AFXDLL" /D "USE_SINGLE_SIGN_ON" +LLFLAGS = -SUBSYSTEM:windows + +include <$(DEPTH)\config\rules.mak> + +install:: $(PROGRAM) + $(MAKE_INSTALL) $(PROGRAM) $(DIST)\bin + $(MAKE_INSTALL) testembed.htm $(DIST)\bin + +clobber_all:: + $(RM) $(DIST)\bin\$(MODULE).exe + $(RM) $(DIST)\bin\testembed.htm + diff --git a/mozilla/embedding/qa/testembed/res/Toolbar.bmp b/mozilla/embedding/qa/testembed/res/Toolbar.bmp new file mode 100644 index 0000000000000000000000000000000000000000..9a1ab9cb61124a6be1c05a1480c0fdb40564e79c GIT binary patch literal 838 zcmbtSJ5B>J5H+7-rF5Kvb08~rgO-AV10cZxtau6v7bAHjBIPP6k0l#3kcJPO zHpC)&S@yCa4-09y+`AYlf=ecev9AMJxboApsZ%H6V67#KwsmZ+-{VA-iry$-a^%+| z<3NF!LO6&lKx3N$MzI2qI7UmD3lmgvdl5ee4 z`H4l>dhqKp4)>Da`ns@5t40vnS^Ap2WbEMb7O%YQP6KP_B>EUpJ}7VJ?}`I-==#Bp v5~dtB5>UadZQdBwVvtjIc$QV;*Lq{mv#-xrE#Pn5jXM|d+is_?d@BC{I=p{= literal 0 HcmV?d00001 diff --git a/mozilla/embedding/qa/testembed/res/testembed.ico b/mozilla/embedding/qa/testembed/res/testembed.ico new file mode 100644 index 0000000000000000000000000000000000000000..7eef0bcbe6580a6f464d688906172c2d9de44262 GIT binary patch literal 1078 zcmc&zF>b>!3}jLb9s)T}@Kod(893@u8ajANzT`op9^o+)S?=nU(FD@%0s)Sg^oyC8{H z9myetc;MEP)59v(LMa~xK8Yu^jIR*H22uCFiq5%C{s7(PJi>o15i^bmX4(vPxWAio z9ryY#AU_jfnd047-@`)XzL?%iS$gQyFP{44kS9X)fN{{QoL~hO-&=q&20Zr*cxFAt PkaNE{wR~2C$NfnjhSXWT literal 0 HcmV?d00001 diff --git a/mozilla/embedding/qa/testembed/res/testembed.rc2 b/mozilla/embedding/qa/testembed/res/testembed.rc2 new file mode 100644 index 00000000000..339464a26a1 --- /dev/null +++ b/mozilla/embedding/qa/testembed/res/testembed.rc2 @@ -0,0 +1,13 @@ +// +// MFCEMBED.RC2 - resources Microsoft Visual C++ does not edit directly +// + +#ifdef APSTUDIO_INVOKED + #error this file is not editable by Microsoft Visual C++ +#endif //APSTUDIO_INVOKED + + +///////////////////////////////////////////////////////////////////////////// +// Add manually edited resources here... + +///////////////////////////////////////////////////////////////////////////// diff --git a/mozilla/embedding/qa/testembed/res/toolbar1.bmp b/mozilla/embedding/qa/testembed/res/toolbar1.bmp new file mode 100644 index 0000000000000000000000000000000000000000..7016676b81e5a605857b71bfa8ee7c22e38eef01 GIT binary patch literal 238 zcmZ?rea8R+Wk5;;hy{R{ABY(lSb!u0Lj{<`Ml>)m01-n&1B3#SKqkY10|$UKNa8;j tG5r4zVgWG_f`ouX0Ti&8qksZJe4yU%ARSP;VAZPiU_O+_$NvDb5&-BZ-uxf-pWCWrLA1IU*rhj&}h|U?Y3Ut|E#p zR`N(eSW1(B(GA6#?J!<{lI6SOXJMDVP?^;K{TBg}(?(f=G$L^?A z=|Q&F?H|>6y=7X}1vtf$ zORO&kG?U;lh9C1hO|XJx{eB;m4D@V>#F}8$FNx^;V92uC#bZ4%L*!8k%G*<-QpiXt zB4`0w8AaE`Br?lgYc@(W=N?&MkF-bXmx$!0R3n;A@@bEVonIyKJx}M6)LImwNhorW zRK1d@6sqT;8UYHK%rp$OJ<>A`!;lmn)rJR&P@L;tvRVwoq^C?620>_qMwGjPie-$z zFoIA7sT>$VV2Ds)#=G_?r(}WaF0e#bYSs)%h6n_9l4i;TLL~?y>e^!&m|!?`3`F%p%>xClimqVN9|7V#P5=s>@N`(HnL2XjF3N#B77{@vi=4ZwmsuLxGK z|Lq;9*P)&V%Uv;spF*6C=5wIH=8~{}>!JjvtM3u+cvmoy8{bV_F8IaB$p- z9Pxw<@ywCFaPI1zalfvzbzc_TLbpJ?#}aQXCW0)eVioDTMOh@}%DQy*|c_~$~ zZc$#iMXZ3-uUjfOj_aV8t}7jq?ZTftmLvZ4lB3N+j)cF+-tyiCuo3y-i4#TTq+f z$Wym_d3K=u;Hs@fO~wS@?b;X8h6YvBeB)jzkLFZ&*p@eGf2nPp`oI1Chp7~}+1YW+ N1iv4KYL{=-{{n~aqsIUM literal 0 HcmV?d00001 diff --git a/mozilla/embedding/qa/testembed/testembed.dsp b/mozilla/embedding/qa/testembed/testembed.dsp new file mode 100644 index 00000000000..ddebff7f902 --- /dev/null +++ b/mozilla/embedding/qa/testembed/testembed.dsp @@ -0,0 +1,261 @@ +# Microsoft Developer Studio Project File - Name="mfcembed" - Package Owner=<4> +# Microsoft Developer Studio Generated Build File, Format Version 6.00 +# ** DO NOT EDIT ** + +# TARGTYPE "Win32 (x86) External Target" 0x0106 + +CFG=mfcembed - Win32 Debug +!MESSAGE This is not a valid makefile. To build this project using NMAKE, +!MESSAGE use the Export Makefile command and run +!MESSAGE +!MESSAGE NMAKE /f "mfcembed.mak". +!MESSAGE +!MESSAGE You can specify a configuration when running NMAKE +!MESSAGE by defining the macro CFG on the command line. For example: +!MESSAGE +!MESSAGE NMAKE /f "mfcembed.mak" CFG="mfcembed - Win32 Debug" +!MESSAGE +!MESSAGE Possible choices for configuration are: +!MESSAGE +!MESSAGE "mfcembed - Win32 Release" (based on "Win32 (x86) External Target") +!MESSAGE "mfcembed - Win32 Debug" (based on "Win32 (x86) External Target") +!MESSAGE + +# Begin Project +# PROP AllowPerConfigDependencies 0 +# PROP Scc_ProjName "" +# PROP Scc_LocalPath "" + +!IF "$(CFG)" == "mfcembed - Win32 Release" + +# PROP BASE Use_MFC 0 +# PROP BASE Use_Debug_Libraries 0 +# PROP BASE Output_Dir "Release" +# PROP BASE Intermediate_Dir "Release" +# PROP BASE Cmd_Line "NMAKE /f mfcembed.mak" +# PROP BASE Rebuild_Opt "/a" +# PROP BASE Target_File "mfcembed.exe" +# PROP BASE Bsc_Name "mfcembed.bsc" +# PROP BASE Target_Dir "" +# PROP Use_MFC 0 +# PROP Use_Debug_Libraries 0 +# PROP Output_Dir "Release" +# PROP Intermediate_Dir "Release" +# PROP Cmd_Line "nmake /f "makfile.win"" +# PROP Rebuild_Opt "/a" +# PROP Target_File "WIN32_O.OBJ\mfcembed.exe" +# PROP Bsc_Name "" +# PROP Target_Dir "" + +!ELSEIF "$(CFG)" == "mfcembed - Win32 Debug" + +# PROP BASE Use_MFC 0 +# PROP BASE Use_Debug_Libraries 1 +# PROP BASE Output_Dir "Debug" +# PROP BASE Intermediate_Dir "Debug" +# PROP BASE Cmd_Line "NMAKE /f mfcembed.mak" +# PROP BASE Rebuild_Opt "/a" +# PROP BASE Target_File "mfcembed.exe" +# PROP BASE Bsc_Name "mfcembed.bsc" +# PROP BASE Target_Dir "" +# PROP Use_MFC 0 +# PROP Use_Debug_Libraries 1 +# PROP Output_Dir "Debug" +# PROP Intermediate_Dir "Debug" +# PROP Cmd_Line "nmake /f "makefile.win"" +# PROP Rebuild_Opt "/a" +# PROP Target_File "WIN32_D.OBJ\testembed.exe" +# PROP Bsc_Name "" +# PROP Target_Dir "" + +!ENDIF + +# Begin Target + +# Name "mfcembed - Win32 Release" +# Name "mfcembed - Win32 Debug" + +!IF "$(CFG)" == "mfcembed - Win32 Release" + +!ELSEIF "$(CFG)" == "mfcembed - Win32 Debug" + +!ENDIF + +# Begin Group "Source Files" + +# PROP Default_Filter "cpp;c;cxx;rc;def;r;odl;idl;hpj;bat" +# Begin Source File + +SOURCE=.\BrowserFrameGlue.cpp +# End Source File +# Begin Source File + +SOURCE=.\BrowserFrm.cpp +# End Source File +# Begin Source File + +SOURCE=.\BrowserImpl.cpp +# End Source File +# Begin Source File + +SOURCE=.\BrowserImplCtxMenuLstnr.cpp +# End Source File +# Begin Source File + +SOURCE=.\BrowserImplHistoryLstnr.cpp +# End Source File +# Begin Source File + +SOURCE=.\BrowserImplPrompt.cpp +# End Source File +# Begin Source File + +SOURCE=.\BrowserImplWebPrgrsLstnr.cpp +# End Source File +# Begin Source File + +SOURCE=.\BrowserView.cpp +# End Source File +# Begin Source File + +SOURCE=.\Dialogs.cpp +# End Source File +# Begin Source File + +SOURCE=.\MfcEmbed.cpp +# End Source File +# Begin Source File + +SOURCE=.\MfcEmbed.rc +# End Source File +# Begin Source File + +SOURCE=.\MostRecentUrls.cpp +# End Source File +# Begin Source File + +SOURCE=.\Preferences.cpp +# End Source File +# Begin Source File + +SOURCE=.\PrintProgressDialog.cpp +# End Source File +# Begin Source File + +SOURCE=.\ProfileMgr.cpp +# End Source File +# Begin Source File + +SOURCE=.\ProfilesDlg.cpp +# End Source File +# Begin Source File + +SOURCE=.\QaUtils.cpp +# End Source File +# Begin Source File + +SOURCE=.\StdAfx.cpp +# End Source File +# Begin Source File + +SOURCE=.\Tests.cpp +# End Source File +# Begin Source File + +SOURCE=.\UrlDialog.cpp +# End Source File +# Begin Source File + +SOURCE=.\winEmbedFileLocProvider.cpp +# End Source File +# End Group +# Begin Group "Header Files" + +# PROP Default_Filter "h;hpp;hxx;hm;inl" +# Begin Source File + +SOURCE=.\BrowserFrm.h +# End Source File +# Begin Source File + +SOURCE=.\BrowserImpl.h +# End Source File +# Begin Source File + +SOURCE=.\BrowserView.h +# End Source File +# Begin Source File + +SOURCE=.\Dialogs.h +# End Source File +# Begin Source File + +SOURCE=.\IBrowserFrameGlue.h +# End Source File +# Begin Source File + +SOURCE=.\MfcEmbed.h +# End Source File +# Begin Source File + +SOURCE=.\MostRecentUrls.h +# End Source File +# Begin Source File + +SOURCE=.\Preferences.h +# End Source File +# Begin Source File + +SOURCE=.\PrintProgressDialog.h +# End Source File +# Begin Source File + +SOURCE=.\ProfileMgr.h +# End Source File +# Begin Source File + +SOURCE=.\ProfilesDlg.h +# End Source File +# Begin Source File + +SOURCE=.\QaUtils.h +# End Source File +# Begin Source File + +SOURCE=.\resource.h +# End Source File +# Begin Source File + +SOURCE=.\StdAfx.h +# End Source File +# Begin Source File + +SOURCE=.\Tests.h +# End Source File +# Begin Source File + +SOURCE=.\UrlDialog.h +# End Source File +# Begin Source File + +SOURCE=.\winEmbedFileLocProvider.h +# End Source File +# End Group +# Begin Group "Resource Files" + +# PROP Default_Filter "ico;cur;bmp;dlg;rc2;rct;bin;rgs;gif;jpg;jpeg;jpe" +# Begin Source File + +SOURCE=.\res\mfcembed.ico +# End Source File +# Begin Source File + +SOURCE=.\res\testembed.ico +# End Source File +# Begin Source File + +SOURCE=.\res\Toolbar.bmp +# End Source File +# End Group +# End Target +# End Project diff --git a/mozilla/embedding/qa/testembed/testembed.dsw b/mozilla/embedding/qa/testembed/testembed.dsw new file mode 100644 index 00000000000..0660ff98912 --- /dev/null +++ b/mozilla/embedding/qa/testembed/testembed.dsw @@ -0,0 +1,29 @@ +Microsoft Developer Studio Workspace File, Format Version 6.00 +# WARNING: DO NOT EDIT OR DELETE THIS WORKSPACE FILE! + +############################################################################### + +Project: "mfcembed"=.\mfcembed.dsp - Package Owner=<4> + +Package=<5> +{{{ +}}} + +Package=<4> +{{{ +}}} + +############################################################################### + +Global: + +Package=<5> +{{{ +}}} + +Package=<3> +{{{ +}}} + +############################################################################### + diff --git a/mozilla/embedding/qa/testembed/testembed.htm b/mozilla/embedding/qa/testembed/testembed.htm new file mode 100644 index 00000000000..bba48eedd97 --- /dev/null +++ b/mozilla/embedding/qa/testembed/testembed.htm @@ -0,0 +1,58 @@ + + + + + + MfcEmbed JavaScript Tests + + + + +

+Excercising MfcEmbed's Interfaces

+This test page serves as a testbed to execercise some of the interfaces +MfcEmbed implements - such as nsIWebBrowserChrome, nsIPrompt etc. +

You can test these by loading mfcembed in the debugger and setting breakpoints +in the interface methods discussed below. Then clicking on these links +will break in the debugger at the specified locations for you to explore +these interface implementations further. +

Open a simple JavaScript window with +defaults for size etc: +

Invokes nsIWebBrowserChrome::CreateBrowserWindow() +to create the window
+Open a JavaScript window with +only its size specified (Not Resizable) +
Invokes nsIWebBrowserChrome::CreateBrowserWindow() +to create the window and also invokes nsIWebBrowserChrome::SizeBrowserTo() +to set the window size. This also shows how we handle the chromeMask to +make the window non-resizeable
+Open a window with +chrome and its size specified (Resizable) +
Invokes nsIWebBrowserChrome::CreateBrowserWindow() +to create the window and also invokes nsIWebBrowserChrome::SizeBrowserTo() +to set the window size +
All of the above tests also invoke nsIWebBrowserChrome::FindNamedBrowserItem() +to find the named target window in the JavaScript code.
+ + + diff --git a/mozilla/embedding/qa/testembed/testembed.rc b/mozilla/embedding/qa/testembed/testembed.rc new file mode 100644 index 00000000000..965ec8b13e6 --- /dev/null +++ b/mozilla/embedding/qa/testembed/testembed.rc @@ -0,0 +1,666 @@ +//Microsoft Developer Studio generated resource script. +// +#include "resource.h" + +#define APSTUDIO_READONLY_SYMBOLS +///////////////////////////////////////////////////////////////////////////// +// +// Generated from the TEXTINCLUDE 2 resource. +// +#include "afxres.h" + +///////////////////////////////////////////////////////////////////////////// +#undef APSTUDIO_READONLY_SYMBOLS + +///////////////////////////////////////////////////////////////////////////// +// English (U.S.) resources + +#if !defined(AFX_RESOURCE_DLL) || defined(AFX_TARG_ENU) +#ifdef _WIN32 +LANGUAGE LANG_ENGLISH, SUBLANG_ENGLISH_US +#pragma code_page(1252) +#endif //_WIN32 + +#ifdef APSTUDIO_INVOKED +///////////////////////////////////////////////////////////////////////////// +// +// TEXTINCLUDE +// + +1 TEXTINCLUDE DISCARDABLE +BEGIN + "resource.h\0" +END + +2 TEXTINCLUDE DISCARDABLE +BEGIN + "#include ""afxres.h""\r\n" + "\0" +END + +3 TEXTINCLUDE DISCARDABLE +BEGIN + "#define _AFX_NO_SPLITTER_RESOURCES\r\n" + "#define _AFX_NO_OLE_RESOURCES\r\n" + "#define _AFX_NO_TRACKER_RESOURCES\r\n" + "#define _AFX_NO_PROPERTY_RESOURCES\r\n" + "\r\n" + "#if !defined(AFX_RESOURCE_DLL) || defined(AFX_TARG_ENU)\r\n" + "#ifdef _WIN32\r\n" + "LANGUAGE 9, 1\r\n" + "#pragma code_page(1252)\r\n" + "#endif //_WIN32\r\n" + "#include ""res\\testembed.rc2"" // non-Microsoft Visual C++ edited resources\r\n" + "#include ""afxres.rc"" // Standard components\r\n" + "#endif\r\n" + "\0" +END + +#endif // APSTUDIO_INVOKED + + +///////////////////////////////////////////////////////////////////////////// +// +// Icon +// + +// Icon with lowest ID value placed first to ensure application icon +// remains consistent on all systems. +IDR_MAINFRAME ICON DISCARDABLE "res\\testembed.ico" + +///////////////////////////////////////////////////////////////////////////// +// +// Bitmap +// + +IDR_MAINFRAME BITMAP MOVEABLE PURE "res\\Toolbar.bmp" + +///////////////////////////////////////////////////////////////////////////// +// +// Toolbar +// + +IDR_MAINFRAME TOOLBAR DISCARDABLE 20, 18 +BEGIN + BUTTON ID_NAV_BACK + BUTTON ID_NAV_FORWARD + SEPARATOR + BUTTON ID_NAV_RELOAD + BUTTON ID_NAV_STOP + SEPARATOR + BUTTON ID_NAV_HOME + SEPARATOR + BUTTON ID_APP_ABOUT +END + + +///////////////////////////////////////////////////////////////////////////// +// +// Menu +// + +IDR_MAINFRAME MENU PRELOAD DISCARDABLE +BEGIN + POPUP "&File" + BEGIN + MENUITEM "&New Browser Window\tCtrl+N", ID_NEW_BROWSER + MENUITEM SEPARATOR + MENUITEM "&Open File...\tCtrl+O", ID_FILE_OPEN + MENUITEM "&Save Page As...\tCtrl+S", ID_FILE_SAVE_AS + MENUITEM SEPARATOR + MENUITEM "&Print...\tCtrl-P", ID_FILE_PRINT + MENUITEM SEPARATOR + MENUITEM "E&xit", ID_APP_EXIT + END + POPUP "&Edit" + BEGIN + MENUITEM "Cu&t\tCtrl+X", ID_EDIT_CUT + MENUITEM "&Copy\tCtrl+C", ID_EDIT_COPY + MENUITEM "&Paste\tCtrl+V", ID_EDIT_PASTE + MENUITEM SEPARATOR + MENUITEM "Select &All", ID_EDIT_SELECT_ALL + MENUITEM "Select &None", ID_EDIT_SELECT_NONE + MENUITEM SEPARATOR + MENUITEM "&Find in This Page...\tCtrl+F", ID_EDIT_FIND + MENUITEM SEPARATOR + MENUITEM "Profiles...", ID_MANAGE_PROFILES + MENUITEM SEPARATOR + MENUITEM "Preferences...", ID_EDIT_PREFERENCES + END + POPUP "&View" + BEGIN + MENUITEM "Page S&ource", ID_VIEW_SOURCE + MENUITEM "Page &Info", ID_VIEW_INFO + MENUITEM SEPARATOR + MENUITEM "&Toolbar", ID_VIEW_TOOLBAR + MENUITEM "&Status Bar", ID_VIEW_STATUS_BAR + END + POPUP "&Go" + BEGIN + MENUITEM "&Back", ID_NAV_BACK + MENUITEM "&Forward", ID_NAV_FORWARD + MENUITEM "&Home", ID_NAV_HOME + END + POPUP "&Help" + BEGIN + MENUITEM "&About TestEmbed...", ID_APP_ABOUT + END + POPUP "&Tests" + BEGIN + MENUITEM "&Change URL", ID_TESTS_CHANGEURL + MENUITEM "&Global &History", ID_TESTS_GLOBALHISTORY + MENUITEM "Create &File", ID_TESTS_CREATEFILE + MENUITEM "Create/Switch &Profile", ID_TESTS_CREATEPROFILE + MENUITEM "&Add Web Prog Listener", ID_TESTS_ADDWEBPROGLISTENER + MENUITEM "Add History &Listener", ID_TESTS_ADDHISTORYLISTENER + END + POPUP "&Interfaces" + BEGIN + MENUITEM "nsI&File", ID_INTERFACES_NSIFILE + MENUITEM "nsI&SHistory", ID_INTERFACES_NSISHISTORY + MENUITEM "nsI&WebNav", ID_INTERFACES_NSIWEBNAV + END + POPUP "T&ools" + BEGIN + MENUITEM "Remove &GH Page", ID_TOOLS_REMOVEGHPAGE + MENUITEM "Remove &All GH", ID_TOOLS_REMOVEALLGH + END + POPUP "Ve&rify Bugs" + BEGIN + MENUITEM "&70228", ID_VERIFYBUGS_70228 + END + + //DHARMA + POPUP "Clip&BoardTest" + + BEGIN + MENUITEM "&Copy Selection", ID_CLIPBOARDCMD_COPYSELECTION + MENUITEM "&Paste", ID_CLIPBOARDCMD_PASTE + MENUITEM "Select &All", ID_CLIPBOARDCMD_SELECTALL + MENUITEM "Select &None", ID_CLIPBOARDCMD_SELECTNONE + MENUITEM "Cu&t Selection", ID_CLIPBOARDCMD_CUTSELECTION + MENUITEM "Copy &Link Location", ID_CLIPBOARDCMD_COPYLINKLOCATION + MENUITEM "Can Copy &Selection", ID_CLIPBOARDCMD_CANCOPYSELECTION + MENUITEM "Can C&ut Selection", ID_CLIPBOARDCMD_CANCUTSELECTION + MENUITEM "Can Pas&Te", ID_CLIPBOARDCMD_CANPASTE + END + //DHARMA +END + +IDR_CTXMENU_DOCUMENT MENU DISCARDABLE +BEGIN + POPUP "Document Context Menu" + BEGIN + MENUITEM "&Back", ID_NAV_BACK + MENUITEM "&Forward", ID_NAV_FORWARD + MENUITEM "&Reload", ID_NAV_RELOAD + MENUITEM "&Stop", ID_NAV_STOP + MENUITEM SEPARATOR + MENUITEM "&View Page Source", ID_VIEW_SOURCE + MENUITEM "View Page &Info", ID_VIEW_INFO + MENUITEM SEPARATOR + MENUITEM "Save &Page As...", ID_FILE_SAVE_AS + MENUITEM SEPARATOR + MENUITEM "Select &All", ID_EDIT_SELECT_ALL + MENUITEM "Select &None", ID_EDIT_SELECT_NONE + MENUITEM "&Copy", ID_EDIT_COPY + END +END + +IDR_CTXMENU_IMAGE MENU DISCARDABLE +BEGIN + POPUP "Image Context Menu" + BEGIN + MENUITEM "&Back", ID_NAV_BACK + MENUITEM "&Forward", ID_NAV_FORWARD + MENUITEM "&Reload", ID_NAV_RELOAD + MENUITEM "&Stop", ID_NAV_STOP + MENUITEM SEPARATOR + MENUITEM "&View Page Source", ID_VIEW_SOURCE + MENUITEM "View &Image", ID_VIEW_IMAGE + MENUITEM SEPARATOR + MENUITEM "Save Image As...", ID_SAVE_IMAGE_AS + MENUITEM "Save &Page As...", ID_FILE_SAVE_AS + END +END + +IDR_CTXMENU_LINK MENU DISCARDABLE +BEGIN + POPUP "Link Context Menu" + BEGIN + MENUITEM "Open Link In New Window", ID_OPEN_LINK_IN_NEW_WINDOW + MENUITEM SEPARATOR + MENUITEM "&Back", ID_NAV_BACK + MENUITEM "&Forward", ID_NAV_FORWARD + MENUITEM "&Reload", ID_NAV_RELOAD + MENUITEM "&Stop", ID_NAV_STOP + MENUITEM SEPARATOR + MENUITEM "&View Page Source", ID_VIEW_SOURCE + MENUITEM SEPARATOR + MENUITEM "Save &Page As...", ID_FILE_SAVE_AS + MENUITEM "Save &Link As...", ID_SAVE_LINK_AS + MENUITEM "&Copy Link Location", ID_COPY_LINK_LOCATION + END +END + +IDR_CTXMENU_TEXT MENU DISCARDABLE +BEGIN + POPUP "Selection Context Menu" + BEGIN + MENUITEM "Cu&t", ID_EDIT_CUT + MENUITEM "&Copy", ID_EDIT_COPY + MENUITEM "&Paste", ID_EDIT_PASTE + MENUITEM "Select &All", ID_EDIT_SELECT_ALL + END +END + + +///////////////////////////////////////////////////////////////////////////// +// +// Accelerator +// + +IDR_MAINFRAME ACCELERATORS PRELOAD MOVEABLE PURE +BEGIN + "C", ID_EDIT_COPY, VIRTKEY, CONTROL, NOINVERT + "F", ID_EDIT_FIND, VIRTKEY, CONTROL, NOINVERT + "N", ID_NEW_BROWSER, VIRTKEY, CONTROL, NOINVERT + "O", ID_FILE_OPEN, VIRTKEY, CONTROL, NOINVERT + "S", ID_FILE_SAVE_AS, VIRTKEY, CONTROL, NOINVERT + "V", ID_EDIT_PASTE, VIRTKEY, CONTROL, NOINVERT + VK_BACK, ID_EDIT_UNDO, VIRTKEY, ALT, NOINVERT + VK_DELETE, ID_EDIT_CUT, VIRTKEY, SHIFT, NOINVERT + VK_F6, ID_NEXT_PANE, VIRTKEY, NOINVERT + VK_F6, ID_PREV_PANE, VIRTKEY, SHIFT, NOINVERT + VK_INSERT, ID_EDIT_COPY, VIRTKEY, CONTROL, NOINVERT + VK_INSERT, ID_EDIT_PASTE, VIRTKEY, SHIFT, NOINVERT + "X", ID_EDIT_CUT, VIRTKEY, CONTROL, NOINVERT + "Z", ID_EDIT_UNDO, VIRTKEY, CONTROL, NOINVERT + VK_ESCAPE, ID_NAV_STOP, VIRTKEY +END + + +///////////////////////////////////////////////////////////////////////////// +// +// Dialog +// + +IDD_ABOUTBOX DIALOG DISCARDABLE 0, 0, 235, 55 +STYLE DS_MODALFRAME | WS_POPUP | WS_CAPTION | WS_SYSMENU +CAPTION "About TestEmbed" +FONT 8, "MS Sans Serif" +BEGIN + ICON IDR_MAINFRAME,IDC_STATIC,11,17,20,20 + LTEXT "Mozilla TestEmbed Version 1.0",IDC_STATIC,40,10,119,8, + SS_NOPREFIX + LTEXT "Copyright (C) 2001",IDC_STATIC,40,25,119,8 + DEFPUSHBUTTON "OK",IDOK,178,7,50,14,WS_GROUP +END + +IDD_PROMPT_DIALOG DIALOG DISCARDABLE 0, 0, 249, 92 +STYLE DS_MODALFRAME | WS_POPUP | WS_VISIBLE | WS_CAPTION | WS_SYSMENU +CAPTION "Prompt Dialog" +FONT 8, "MS Sans Serif" +BEGIN + DEFPUSHBUTTON "OK",IDOK,130,69,50,14 + PUSHBUTTON "Cancel",IDCANCEL,189,69,50,14 + LTEXT "Please enter something....",IDC_PROMPT_TEXT,10,7,229,29 + EDITTEXT IDC_PROMPT_ANSWER,7,39,232,13,ES_AUTOHSCROLL + CONTROL "Save Answer",IDC_CHECK_SAVE_PASSWORD,"Button", + BS_AUTOCHECKBOX | WS_TABSTOP,7,57,229,10 +END + +IDD_PROMPT_PASSWORD_DIALOG DIALOG DISCARDABLE 0, 0, 248, 93 +STYLE DS_SYSMODAL | DS_MODALFRAME | WS_POPUP | WS_VISIBLE | WS_CAPTION | + WS_SYSMENU +CAPTION "Password Entry Dialog" +FONT 8, "MS Sans Serif" +BEGIN + LTEXT "Please enter your password:",IDC_PROMPT_TEXT,5,7,232,20 + DEFPUSHBUTTON "OK",IDOK,129,75,50,14 + PUSHBUTTON "Cancel",IDCANCEL,188,75,50,14 + EDITTEXT IDC_PASSWORD,5,37,233,12,ES_PASSWORD | ES_AUTOHSCROLL + CONTROL "Save Password",IDC_CHECK_SAVE_PASSWORD,"Button", + BS_AUTOCHECKBOX | WS_TABSTOP,7,57,229,10 +END + +IDD_PROMPT_USERPASS_DIALOG DIALOG DISCARDABLE 0, 0, 214, 123 +STYLE DS_MODALFRAME | WS_POPUP | WS_VISIBLE | WS_CAPTION | WS_SYSMENU +CAPTION "Username and Password Required" +FONT 8, "MS Sans Serif" +BEGIN + LTEXT "This operation requires authentication. Please enter your user name and password:", + IDC_PROMPT_TEXT,6,9,171,25 + LTEXT "User Name:",IDC_USERNAME_LABEL,6,39,39,9 + EDITTEXT IDC_USERNAME,49,39,153,12,ES_AUTOHSCROLL + LTEXT "Password:",IDC_PASSWORD_LABEL,6,58,36,8 + EDITTEXT IDC_PASSWORD,49,56,153,12,ES_PASSWORD | ES_AUTOHSCROLL + CONTROL "Save User Name and Password",IDC_CHECK_SAVE_PASSWORD, + "Button",BS_AUTOCHECKBOX | WS_TABSTOP,6,78,201,10 + DEFPUSHBUTTON "OK",IDOK,40,101,50,14 + PUSHBUTTON "Cancel",IDCANCEL,95,101,50,14 +END + +IDD_PROFILES DIALOG DISCARDABLE 0, 0, 196, 95 +STYLE DS_MODALFRAME | WS_POPUP | WS_CAPTION | WS_SYSMENU +CAPTION "Manage Profiles" +FONT 8, "MS Sans Serif" +BEGIN + LISTBOX IDC_LIST1,79,17,110,44,LBS_NOINTEGRALHEIGHT | WS_VSCROLL | + WS_TABSTOP + PUSHBUTTON "Rename...",IDC_PROF_RENAME,7,7,50,14 + PUSHBUTTON "Delete",IDC_PROF_DELETE,7,27,50,14 + PUSHBUTTON "New...",IDC_PROF_NEW,7,48,50,14 + DEFPUSHBUTTON "OK",IDOK,139,74,50,14 + PUSHBUTTON "Cancel",IDCANCEL,80,74,50,14 + CONTROL "Ask At Startup",IDC_CHECK_ASK_AT_START,"Button", + BS_AUTOCHECKBOX | WS_TABSTOP,7,75,61,10 +END + +IDD_PROFILE_NEW DIALOG DISCARDABLE 0, 0, 177, 79 +STYLE DS_MODALFRAME | WS_POPUP | WS_CAPTION | WS_SYSMENU +CAPTION "New Profile" +FONT 8, "MS Sans Serif" +BEGIN + EDITTEXT IDC_NEW_PROF_NAME,39,16,122,14,ES_AUTOHSCROLL + COMBOBOX IDC_LOCALE_COMBO,39,35,67,30,CBS_DROPDOWNLIST | CBS_SORT | + WS_DISABLED | WS_VSCROLL | WS_TABSTOP + DEFPUSHBUTTON "OK",IDOK,120,58,50,14 + PUSHBUTTON "Cancel",IDCANCEL,63,58,50,14 + RTEXT "Name:",IDC_STATIC,13,18,22,8 + RTEXT "Locale:",IDC_STATIC,11,37,24,8 +END + +IDD_PROFILE_RENAME DIALOG DISCARDABLE 0, 0, 177, 76 +STYLE DS_MODALFRAME | WS_POPUP | WS_CAPTION | WS_SYSMENU +CAPTION "Rename Profile" +FONT 8, "MS Sans Serif" +BEGIN + EDITTEXT IDC_NEW_NAME,50,16,113,14,ES_AUTOHSCROLL + DEFPUSHBUTTON "OK",IDOK,120,55,50,14 + PUSHBUTTON "Cancel",IDCANCEL,63,55,50,14 + RTEXT "New Name:",IDC_STATIC,7,18,38,8 +END + +IDD_FINDDLG DIALOG DISCARDABLE 30, 73, 236, 62 +STYLE DS_MODALFRAME | DS_3DLOOK | DS_CONTEXTHELP | WS_POPUP | WS_CAPTION | + WS_SYSMENU +CAPTION "Find" +FONT 8, "MS Shell Dlg" +BEGIN + LTEXT "Fi&nd what:",-1,4,8,42,8 + EDITTEXT IDC_FIND_EDIT,47,7,128,12,ES_AUTOHSCROLL | WS_GROUP + CONTROL "Match &whole word only",IDC_MATCH_WHOLE_WORD,"Button", + BS_AUTOCHECKBOX | WS_GROUP | WS_TABSTOP,4,26,90,12 + CONTROL "Wra&p around",IDC_WRAP_AROUND,"Button",BS_AUTOCHECKBOX | + WS_GROUP | WS_TABSTOP,101,26,65,12 + CONTROL "Match &case",IDC_MATCH_CASE,"Button",BS_AUTOCHECKBOX | + WS_TABSTOP,4,42,64,12 + CONTROL "Search &backwards",IDC_SEARCH_BACKWARDS,"Button", + BS_AUTOCHECKBOX | WS_TABSTOP,101,42,67,12 + DEFPUSHBUTTON "&Find Next",IDOK,182,5,50,14,WS_GROUP + PUSHBUTTON "Cancel",IDCANCEL,182,23,50,14 +END + +IDD_PRINT_PROGRESS_DIALOG DIALOG DISCARDABLE 0, 0, 294, 55 +STYLE DS_SYSMODAL | DS_MODALFRAME | DS_CENTER | WS_POPUP | WS_VISIBLE | + WS_CAPTION +CAPTION "Printing..." +FONT 8, "MS Sans Serif" +BEGIN + PUSHBUTTON "Cancel",IDCANCEL,122,34,50,14 + LTEXT "Document:",IDC_PPD_DOC_TITLE_STATIC,7,7,36,8 + LTEXT "",IDC_PPD_DOC_TXT,43,7,244,8 +END + +IDD_PREFS_START_PAGE DIALOG DISCARDABLE 0, 0, 284, 150 +STYLE WS_CHILD | WS_DISABLED | WS_CAPTION +CAPTION "Startup" +FONT 8, "MS Sans Serif" +BEGIN + GROUPBOX "TestEmbed starts with",IDC_STATIC,6,10,271,49 + CONTROL "Bla&nk Page",IDC_RADIO_BLANK_PAGE,"Button", + BS_AUTORADIOBUTTON | WS_GROUP,16,24,53,10 + CONTROL "&Home Page",IDC_RADIO_HOME_PAGE,"Button", + BS_AUTORADIOBUTTON,16,40,53,10 + GROUPBOX "Home Page",IDC_STATIC,6,67,271,51 + LTEXT "Clicking the Home button will take you to this page", + IDC_STATIC,17,80,234,8 + LTEXT "Loc&ation:",IDC_STATIC,17,98,31,8 + EDITTEXT IDC_EDIT_HOMEPAGE,53,95,211,14,ES_AUTOHSCROLL +END + +IDD_URLDIALOG DIALOG DISCARDABLE 0, 0, 186, 95 +STYLE DS_MODALFRAME | WS_POPUP | WS_CAPTION | WS_SYSMENU +CAPTION "URL Dialog" +FONT 8, "MS Sans Serif" +BEGIN + DEFPUSHBUTTON "OK",IDOK,129,7,50,14 + PUSHBUTTON "Cancel",IDCANCEL,129,24,50,14 + LTEXT "Enter URL here:",IDC_ENTER_URLTEXT,65,48,69,8 + EDITTEXT IDC_URLFIELD,30,66,132,14,ES_AUTOHSCROLL +END + +IDD_DIALOG1 DIALOG DISCARDABLE 0, 0, 186, 95 +STYLE DS_MODALFRAME | WS_POPUP | WS_CAPTION | WS_SYSMENU +CAPTION "Dialog" +FONT 8, "MS Sans Serif" +BEGIN + DEFPUSHBUTTON "OK",IDOK,129,7,50,14 + PUSHBUTTON "Cancel",IDCANCEL,129,24,50,14 +END + + +#ifndef _MAC +///////////////////////////////////////////////////////////////////////////// +// +// Version +// + +VS_VERSION_INFO VERSIONINFO + FILEVERSION 1,0,0,1 + PRODUCTVERSION 1,0,0,1 + FILEFLAGSMASK 0x3fL +#ifdef _DEBUG + FILEFLAGS 0x1L +#else + FILEFLAGS 0x0L +#endif + FILEOS 0x4L + FILETYPE 0x1L + FILESUBTYPE 0x0L +BEGIN + BLOCK "StringFileInfo" + BEGIN + BLOCK "040904B0" + BEGIN + VALUE "CompanyName", "\0" + VALUE "FileDescription", "TestEmbed MFC Application\0" + VALUE "FileVersion", "1, 0, 0, 1\0" + VALUE "InternalName", "TestEmbed\0" + VALUE "LegalCopyright", "Copyright (C) 2001\0" + VALUE "LegalTrademarks", "\0" + VALUE "OriginalFilename", "TestEmbed.EXE\0" + VALUE "ProductName", "TestEmbed Application\0" + VALUE "ProductVersion", "1, 0, 0, 1\0" + END + END + BLOCK "VarFileInfo" + BEGIN + VALUE "Translation", 0x409, 1200 + END +END + +#endif // !_MAC + + +///////////////////////////////////////////////////////////////////////////// +// +// DESIGNINFO +// + +#ifdef APSTUDIO_INVOKED +GUIDELINES DESIGNINFO DISCARDABLE +BEGIN + IDD_ABOUTBOX, DIALOG + BEGIN + LEFTMARGIN, 7 + RIGHTMARGIN, 228 + TOPMARGIN, 7 + BOTTOMMARGIN, 48 + END + + IDD_PROFILES, DIALOG + BEGIN + LEFTMARGIN, 7 + RIGHTMARGIN, 189 + TOPMARGIN, 7 + BOTTOMMARGIN, 88 + END + + IDD_PROFILE_NEW, DIALOG + BEGIN + LEFTMARGIN, 7 + RIGHTMARGIN, 170 + TOPMARGIN, 7 + BOTTOMMARGIN, 72 + END + + IDD_PROFILE_RENAME, DIALOG + BEGIN + LEFTMARGIN, 7 + RIGHTMARGIN, 170 + TOPMARGIN, 7 + BOTTOMMARGIN, 69 + END + + IDD_PRINT_PROGRESS_DIALOG, DIALOG + BEGIN + LEFTMARGIN, 7 + RIGHTMARGIN, 287 + TOPMARGIN, 7 + BOTTOMMARGIN, 48 + END + + IDD_URLDIALOG, DIALOG + BEGIN + LEFTMARGIN, 7 + RIGHTMARGIN, 179 + TOPMARGIN, 7 + BOTTOMMARGIN, 88 + END + + IDD_DIALOG1, DIALOG + BEGIN + LEFTMARGIN, 7 + RIGHTMARGIN, 179 + TOPMARGIN, 7 + BOTTOMMARGIN, 88 + END +END +#endif // APSTUDIO_INVOKED + + +///////////////////////////////////////////////////////////////////////////// +// +// String Table +// + +STRINGTABLE PRELOAD DISCARDABLE +BEGIN + IDR_MAINFRAME "testembed" +END + +STRINGTABLE PRELOAD DISCARDABLE +BEGIN + AFX_IDS_APP_TITLE "testembed" + AFX_IDS_IDLEMESSAGE "Ready" +END + +STRINGTABLE DISCARDABLE +BEGIN + ID_APP_ABOUT "Display program information, version number and copyright\nAbout" + ID_APP_EXIT "Quit the application; prompts to save documents\nExit" +END + +STRINGTABLE DISCARDABLE +BEGIN + ID_NEXT_PANE "Switch to the next window pane\nNext Pane" + ID_PREV_PANE "Switch back to the previous window pane\nPrevious Pane" +END + +STRINGTABLE DISCARDABLE +BEGIN + ID_WINDOW_SPLIT "Split the active window into panes\nSplit" +END + +STRINGTABLE DISCARDABLE +BEGIN + ID_EDIT_CLEAR "Erase the selection\nErase" + ID_EDIT_CLEAR_ALL "Erase everything\nErase All" + ID_EDIT_COPY "Copy the selection and put it on the Clipboard\nCopy" + ID_EDIT_CUT "Cut the selection and put it on the Clipboard\nCut" + ID_EDIT_FIND "Find the specified text\nFind" + ID_EDIT_PASTE "Insert Clipboard contents\nPaste" + ID_EDIT_REPEAT "Repeat the last action\nRepeat" + ID_EDIT_REPLACE "Replace specific text with different text\nReplace" + ID_EDIT_SELECT_ALL "Select the entire document\nSelect All" + ID_EDIT_UNDO "Undo the last action\nUndo" + ID_EDIT_REDO "Redo the previously undone action\nRedo" +END + +STRINGTABLE DISCARDABLE +BEGIN + ID_VIEW_TOOLBAR "Show or hide the toolbar\nToggle ToolBar" + ID_VIEW_STATUS_BAR "Show or hide the status bar\nToggle StatusBar" +END + +STRINGTABLE DISCARDABLE +BEGIN + AFX_IDS_SCSIZE "Change the window size" + AFX_IDS_SCMOVE "Change the window position" + AFX_IDS_SCMINIMIZE "Reduce the window to an icon" + AFX_IDS_SCMAXIMIZE "Enlarge the window to full size" + AFX_IDS_SCNEXTWINDOW "Switch to the next document window" + AFX_IDS_SCPREVWINDOW "Switch to the previous document window" + AFX_IDS_SCCLOSE "Close the active window and prompts to save the documents" +END + +STRINGTABLE DISCARDABLE +BEGIN + AFX_IDS_SCRESTORE "Restore the window to normal size" + AFX_IDS_SCTASKLIST "Activate Task List" +END + +STRINGTABLE DISCARDABLE +BEGIN + ID_EDIT_SELECT_NONE "Select nothing in the document\nSelect None" +END + +#endif // English (U.S.) resources +///////////////////////////////////////////////////////////////////////////// + + + +#ifndef APSTUDIO_INVOKED +///////////////////////////////////////////////////////////////////////////// +// +// Generated from the TEXTINCLUDE 3 resource. +// +#define _AFX_NO_SPLITTER_RESOURCES +#define _AFX_NO_OLE_RESOURCES +#define _AFX_NO_TRACKER_RESOURCES +#define _AFX_NO_PROPERTY_RESOURCES + +#if !defined(AFX_RESOURCE_DLL) || defined(AFX_TARG_ENU) +#ifdef _WIN32 +LANGUAGE 9, 1 +#pragma code_page(1252) +#endif //_WIN32 +#include "res\testembed.rc2" // non-Microsoft Visual C++ edited resources +#include "afxres.rc" // Standard components +#endif + +///////////////////////////////////////////////////////////////////////////// +#endif // not APSTUDIO_INVOKED + diff --git a/mozilla/embedding/qa/testembed/winEmbedFileLocProvider.cpp b/mozilla/embedding/qa/testembed/winEmbedFileLocProvider.cpp new file mode 100644 index 00000000000..cf10580fe9e --- /dev/null +++ b/mozilla/embedding/qa/testembed/winEmbedFileLocProvider.cpp @@ -0,0 +1,265 @@ +/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */ +/* + * The contents of this file are subject to the Netscape Public + * License Version 1.1 (the "License"); you may not use this file + * except in compliance with the License. You may obtain a copy of + * the License at http://www.mozilla.org/NPL/ + * + * Software distributed under the License is distributed on an "AS + * IS" basis, WITHOUT WARRANTY OF ANY KIND, either express or + * implied. See the License for the specific language governing + * rights and limitations under the License. + * + * The Original Code is Mozilla Communicator client code, + * released March 31, 1998. + * + * The Initial Developer of the Original Code is Netscape Communications + * Corporation. Portions created by Netscape are + * Copyright (C) 2000 Netscape Communications Corporation. All + * Rights Reserved. + * + * Contributor(s): + * Conrad Carlen + */ + +#include "winEmbedFileLocProvider.h" +#include "nsAppDirectoryServiceDefs.h" +#include "nsDirectoryServiceDefs.h" +#include "nsILocalFile.h" +#include "nsString.h" +#include "nsXPIDLString.h" + + +#include +#include + + +// WARNING: These hard coded names need to go away. They need to +// come from localizable resources +#define APP_REGISTRY_NAME "registry.dat" + +#define PROFILE_ROOT_DIR_NAME "Profiles" +#define DEFAULTS_DIR_NAME "defaults" +#define DEFAULTS_PREF_DIR_NAME "pref" +#define DEFAULTS_PROFILE_DIR_NAME "profile" +#define RES_DIR_NAME "res" +#define CHROME_DIR_NAME "chrome" +#define PLUGINS_DIR_NAME "plugins" +#define SEARCH_DIR_NAME "searchplugins" + + +//***************************************************************************** +// winEmbedFileLocProvider::Constructor/Destructor +//***************************************************************************** + +winEmbedFileLocProvider::winEmbedFileLocProvider(const char* productDirName) +{ + NS_INIT_ISUPPORTS(); + + strncpy(mProductDirName, productDirName, sizeof(mProductDirName) - 1); + mProductDirName[sizeof(mProductDirName) - 1] = '\0'; +} + +winEmbedFileLocProvider::~winEmbedFileLocProvider() +{ +} + + +//***************************************************************************** +// winEmbedFileLocProvider::nsISupports +//***************************************************************************** + +NS_IMPL_ISUPPORTS1(winEmbedFileLocProvider, nsIDirectoryServiceProvider) + +//***************************************************************************** +// winEmbedFileLocProvider::nsIDirectoryServiceProvider +//***************************************************************************** + +NS_IMETHODIMP +winEmbedFileLocProvider::GetFile(const char *prop, PRBool *persistant, nsIFile **_retval) +{ + nsCOMPtr localFile; + nsresult rv = NS_ERROR_FAILURE; + + *_retval = nsnull; + *persistant = PR_TRUE; + + if (nsCRT::strcmp(prop, NS_APP_APPLICATION_REGISTRY_DIR) == 0) + { + rv = GetProductDirectory(getter_AddRefs(localFile)); + } + else if (nsCRT::strcmp(prop, NS_APP_APPLICATION_REGISTRY_FILE) == 0) + { + rv = GetProductDirectory(getter_AddRefs(localFile)); + if (NS_SUCCEEDED(rv)) + rv = localFile->Append(APP_REGISTRY_NAME); + } + else if (nsCRT::strcmp(prop, NS_APP_DEFAULTS_50_DIR) == 0) + { + rv = CloneMozBinDirectory(getter_AddRefs(localFile)); + if (NS_SUCCEEDED(rv)) + rv = localFile->AppendRelativePath(DEFAULTS_DIR_NAME); + } + else if (nsCRT::strcmp(prop, NS_APP_PREF_DEFAULTS_50_DIR) == 0) + { + rv = CloneMozBinDirectory(getter_AddRefs(localFile)); + if (NS_SUCCEEDED(rv)) { + rv = localFile->AppendRelativePath(DEFAULTS_DIR_NAME); + if (NS_SUCCEEDED(rv)) + rv = localFile->AppendRelativePath(DEFAULTS_PREF_DIR_NAME); + } + } + else if (nsCRT::strcmp(prop, NS_APP_PROFILE_DEFAULTS_NLOC_50_DIR) == 0 || + nsCRT::strcmp(prop, NS_APP_PROFILE_DEFAULTS_50_DIR) == 0) + { + rv = CloneMozBinDirectory(getter_AddRefs(localFile)); + if (NS_SUCCEEDED(rv)) { + rv = localFile->AppendRelativePath(DEFAULTS_DIR_NAME); + if (NS_SUCCEEDED(rv)) + rv = localFile->AppendRelativePath(DEFAULTS_PROFILE_DIR_NAME); + } + } + else if (nsCRT::strcmp(prop, NS_APP_USER_PROFILES_ROOT_DIR) == 0) + { + rv = GetDefaultUserProfileRoot(getter_AddRefs(localFile)); + } + else if (nsCRT::strcmp(prop, NS_APP_RES_DIR) == 0) + { + rv = CloneMozBinDirectory(getter_AddRefs(localFile)); + if (NS_SUCCEEDED(rv)) + rv = localFile->AppendRelativePath(RES_DIR_NAME); + } + else if (nsCRT::strcmp(prop, NS_APP_CHROME_DIR) == 0) + { + rv = CloneMozBinDirectory(getter_AddRefs(localFile)); + if (NS_SUCCEEDED(rv)) + rv = localFile->AppendRelativePath(CHROME_DIR_NAME); + } + else if (nsCRT::strcmp(prop, NS_APP_PLUGINS_DIR) == 0) + { + rv = CloneMozBinDirectory(getter_AddRefs(localFile)); + if (NS_SUCCEEDED(rv)) + rv = localFile->AppendRelativePath(PLUGINS_DIR_NAME); + } + else if (nsCRT::strcmp(prop, NS_APP_SEARCH_DIR) == 0) + { + rv = CloneMozBinDirectory(getter_AddRefs(localFile)); + if (NS_SUCCEEDED(rv)) + rv = localFile->AppendRelativePath(SEARCH_DIR_NAME); + } + + if (localFile && NS_SUCCEEDED(rv)) + return localFile->QueryInterface(NS_GET_IID(nsIFile), (void**)_retval); + + return rv; +} + + +NS_METHOD winEmbedFileLocProvider::CloneMozBinDirectory(nsILocalFile **aLocalFile) +{ + NS_ENSURE_ARG_POINTER(aLocalFile); + nsresult rv; + + if (!mMozBinDirectory) + { + // Get the mozilla bin directory + // 1. Check the directory service first for NS_XPCOM_CURRENT_PROCESS_DIR + // This will be set if a directory was passed to NS_InitXPCOM + // 2. If that doesn't work, set it to be the current process directory + + NS_WITH_SERVICE(nsIProperties, directoryService, NS_DIRECTORY_SERVICE_CONTRACTID, &rv); + if (NS_FAILED(rv)) + return rv; + + rv = directoryService->Get(NS_XPCOM_CURRENT_PROCESS_DIR, NS_GET_IID(nsIFile), getter_AddRefs(mMozBinDirectory)); + if (NS_FAILED(rv)) { + rv = directoryService->Get(NS_OS_CURRENT_PROCESS_DIR, NS_GET_IID(nsIFile), getter_AddRefs(mMozBinDirectory)); + if (NS_FAILED(rv)) + return rv; + } + } + + nsCOMPtr aFile; + rv = mMozBinDirectory->Clone(getter_AddRefs(aFile)); + if (NS_FAILED(rv)) + return rv; + + nsCOMPtr lfile = do_QueryInterface (aFile); + if (!lfile) + return NS_ERROR_FAILURE; + + NS_IF_ADDREF(*aLocalFile = lfile); + return NS_OK; +} + + +//---------------------------------------------------------------------------------------- +// GetProductDirectory - Gets the directory which contains the application data folder +// +// WIN : \Mozilla +//---------------------------------------------------------------------------------------- +NS_METHOD winEmbedFileLocProvider::GetProductDirectory(nsILocalFile **aLocalFile) +{ + NS_ENSURE_ARG_POINTER(aLocalFile); + + nsresult rv; + PRBool exists; + nsCOMPtr localDir; + + NS_WITH_SERVICE(nsIProperties, directoryService, NS_DIRECTORY_SERVICE_CONTRACTID, &rv); + if (NS_FAILED(rv)) return rv; + rv = directoryService->Get(NS_WIN_APPDATA_DIR, NS_GET_IID(nsILocalFile), getter_AddRefs(localDir)); + if (NS_SUCCEEDED(rv)) + rv = localDir->Exists(&exists); + if (NS_FAILED(rv) || !exists) + { + // On some Win95 machines, NS_WIN_APPDATA_DIR does not exist - revert to NS_WIN_WINDOWS_DIR + localDir = nsnull; + rv = directoryService->Get(NS_WIN_WINDOWS_DIR, NS_GET_IID(nsILocalFile), getter_AddRefs(localDir)); + } + if (NS_FAILED(rv)) return rv; + + rv = localDir->AppendRelativePath(mProductDirName); + if (NS_FAILED(rv)) return rv; + rv = localDir->Exists(&exists); + if (NS_SUCCEEDED(rv) && !exists) + rv = localDir->Create(nsIFile::DIRECTORY_TYPE, 0775); + if (NS_FAILED(rv)) return rv; + + *aLocalFile = localDir; + NS_ADDREF(*aLocalFile); + + return rv; +} + + +//---------------------------------------------------------------------------------------- +// GetDefaultUserProfileRoot - Gets the directory which contains each user profile dir +// +// WIN : \Mozilla\Users50 +//---------------------------------------------------------------------------------------- +NS_METHOD winEmbedFileLocProvider::GetDefaultUserProfileRoot(nsILocalFile **aLocalFile) +{ + NS_ENSURE_ARG_POINTER(aLocalFile); + + nsresult rv; + PRBool exists; + nsCOMPtr localDir; + + rv = GetProductDirectory(getter_AddRefs(localDir)); + if (NS_FAILED(rv)) return rv; + + // These 3 platforms share this part of the path - do them as one + rv = localDir->AppendRelativePath(PROFILE_ROOT_DIR_NAME); + if (NS_FAILED(rv)) return rv; + rv = localDir->Exists(&exists); + if (NS_SUCCEEDED(rv) && !exists) + rv = localDir->Create(nsIFile::DIRECTORY_TYPE, 0775); + if (NS_FAILED(rv)) return rv; + + *aLocalFile = localDir; + NS_ADDREF(*aLocalFile); + + return rv; +} + diff --git a/mozilla/embedding/qa/testembed/winEmbedFileLocProvider.h b/mozilla/embedding/qa/testembed/winEmbedFileLocProvider.h new file mode 100644 index 00000000000..2c66b8f8f19 --- /dev/null +++ b/mozilla/embedding/qa/testembed/winEmbedFileLocProvider.h @@ -0,0 +1,53 @@ +/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */ +/* + * The contents of this file are subject to the Netscape Public + * License Version 1.1 (the "License"); you may not use this file + * except in compliance with the License. You may obtain a copy of + * the License at http://www.mozilla.org/NPL/ + * + * Software distributed under the License is distributed on an "AS + * IS" basis, WITHOUT WARRANTY OF ANY KIND, either express or + * implied. See the License for the specific language governing + * rights and limitations under the License. + * + * The Original Code is Mozilla Communicator client code, + * released March 31, 1998. + * + * The Initial Developer of the Original Code is Netscape Communications + * Corporation. Portions created by Netscape are + * Copyright (C) 2000 Netscape Communications Corporation. All + * Rights Reserved. + * + * Contributor(s): + * Conrad Carlen + */ + +#include "nsIDirectoryService.h" +#include "nsILocalFile.h" + +class nsIFile; + +//***************************************************************************** +// class winEmbedFileLocProvider +//***************************************************************************** + +class winEmbedFileLocProvider : public nsIDirectoryServiceProvider +{ +public: + // productDirName is the name (not path) of the dir + // in which the application registry and profiles live. + winEmbedFileLocProvider(const char* productDirName); + + NS_DECL_ISUPPORTS + NS_DECL_NSIDIRECTORYSERVICEPROVIDER + +protected: + virtual ~winEmbedFileLocProvider(); + + NS_METHOD CloneMozBinDirectory(nsILocalFile **aLocalFile); + NS_METHOD GetProductDirectory(nsILocalFile **aLocalFile); + NS_METHOD GetDefaultUserProfileRoot(nsILocalFile **aLocalFile); + + char mProductDirName[256]; + nsCOMPtr mMozBinDirectory; +};