Spanked to get most of the menus working again

git-svn-id: svn://10.0.0.236/trunk@6030 18797224-902f-48f8-a5cc-f745e15eee43
This commit is contained in:
kipp%netscape.com 1998-07-21 00:48:35 +00:00
parent a5f64bdca9
commit c3fd39a44f
11 changed files with 803 additions and 117 deletions

View File

@ -31,13 +31,14 @@ MISCDEP= \
OBJS = \
.\$(OBJDIR)\nsWinMain.obj \
.\$(OBJDIR)\nsViewerApp.obj \
.\$(OBJDIR)\JSConsole.obj \
.\$(OBJDIR)\nsBrowserWindow.obj \
.\$(OBJDIR)\nsDocLoader.obj \
.\$(OBJDIR)\nsEditorInterfaces.obj \
.\$(OBJDIR)\nsEditorMode.obj \
.\$(OBJDIR)\nsSetupRegistry.obj \
.\$(OBJDIR)\nsViewerApp.obj \
.\$(OBJDIR)\nsWinMain.obj \
.\$(OBJDIR)\JSConsole.obj \
$(NULL)
LINCS= \

View File

@ -35,7 +35,6 @@
#include "nsViewerApp.h"
#include "resources.h"
#define SAMPLES_BASE_URL "resource:/res/samples"
// XXX greasy constants
#define THROBBER_WIDTH 32
@ -526,6 +525,13 @@ nsBrowserWindow::SizeTo(PRInt32 aWidth, PRInt32 aHeight)
return NS_OK;
}
NS_IMETHODIMP
nsBrowserWindow::GetBounds(nsRect& aBounds)
{
mWindow->GetBounds(aBounds);
return NS_OK;
}
NS_IMETHODIMP
nsBrowserWindow::Show()
{
@ -563,6 +569,14 @@ nsBrowserWindow::LoadURL(const nsString& aURL)
return mWebShell->LoadURL(aURL, this, nsnull);
}
NS_IMETHODIMP
nsBrowserWindow::GetWebShell(nsIWebShell*& aResult)
{
aResult = mWebShell;
NS_IF_ADDREF(mWebShell);
return NS_OK;
}
//----------------------------------------
NS_IMETHODIMP
@ -675,6 +689,12 @@ nsBrowserWindow::OnStopBinding(nsIURL* aURL,
// nsIScriptContextOwner
// XXX this code is moving into nsWebShell.cpp so beware!
#include "nsIPresShell.h"
#include "nsIDocument.h"
#include "nsIDOMDocument.h"
nsresult
nsBrowserWindow::GetScriptContext(nsIScriptContext** aContext)
{
@ -692,8 +712,7 @@ nsBrowserWindow::GetScriptContext(nsIScriptContext** aContext)
return res;
}
#if XXX_this_is_wrong
nsIPresShell* shell = GetPresShell(mWebShell);
nsIPresShell* shell = GetPresShell();
if (nsnull != shell) {
nsIDocument* doc = shell->GetDocument();
if (nsnull != doc) {
@ -707,7 +726,6 @@ nsBrowserWindow::GetScriptContext(nsIScriptContext** aContext)
}
NS_RELEASE(shell);
}
#endif
}
*aContext = mScriptContext;
@ -766,13 +784,13 @@ nsBrowserWindow::DestroyThrobberImages()
static NS_DEFINE_IID(kIDocumentViewerIID, NS_IDOCUMENT_VIEWER_IID);
static nsIPresShell*
GetPresShell(nsIWebShell* aWebShell)
nsIPresShell*
nsBrowserWindow::GetPresShell()
{
nsIPresShell* shell = nsnull;
if (nsnull != aWebShell) {
if (nsnull != mWebShell) {
nsIContentViewer* cv = nsnull;
aWebShell->GetContentViewer(cv);
mWebShell->GetContentViewer(cv);
if (nsnull != cv) {
nsIDocumentViewer* docv = nsnull;
cv->QueryInterface(kIDocumentViewerIID, (void**) &docv);
@ -794,7 +812,7 @@ GetPresShell(nsIWebShell* aWebShell)
void
nsBrowserWindow::DumpContent(FILE* out)
{
nsIPresShell* shell = GetPresShell(mWebShell);
nsIPresShell* shell = GetPresShell();
if (nsnull != shell) {
nsIDocument* doc = shell->GetDocument();
if (nsnull != doc) {
@ -815,7 +833,7 @@ nsBrowserWindow::DumpContent(FILE* out)
void
nsBrowserWindow::DumpFrames(FILE* out)
{
nsIPresShell* shell = GetPresShell(mWebShell);
nsIPresShell* shell = GetPresShell();
if (nsnull != shell) {
nsIFrame* root = shell->GetRootFrame();
if (nsnull != root) {
@ -831,7 +849,7 @@ nsBrowserWindow::DumpFrames(FILE* out)
void
nsBrowserWindow::DumpViews(FILE* out)
{
nsIPresShell* shell = GetPresShell(mWebShell);
nsIPresShell* shell = GetPresShell();
if (nsnull != shell) {
nsIViewManager* vm = shell->GetViewManager();
if (nsnull != vm) {
@ -887,7 +905,7 @@ nsBrowserWindow::DumpWebShells(FILE* out)
void
nsBrowserWindow::DumpStyleSheets(FILE* out)
{
nsIPresShell* shell = GetPresShell(mWebShell);
nsIPresShell* shell = GetPresShell();
if (nsnull != shell) {
nsIStyleSet* styleSet = shell->GetStyleSet();
if (nsnull == styleSet) {
@ -906,7 +924,7 @@ nsBrowserWindow::DumpStyleSheets(FILE* out)
void
nsBrowserWindow::DumpStyleContexts(FILE* out)
{
nsIPresShell* shell = GetPresShell(mWebShell);
nsIPresShell* shell = GetPresShell();
if (nsnull != shell) {
nsIPresContext* cx = shell->GetPresContext();
nsIStyleSet* styleSet = shell->GetStyleSet();
@ -947,7 +965,7 @@ nsBrowserWindow::ToggleFrameBorders()
void
nsBrowserWindow::ForceRefresh()
{
nsIPresShell* shell = GetPresShell(mWebShell);
nsIPresShell* shell = GetPresShell();
if (nsnull != shell) {
nsIViewManager* vm = shell->GetViewManager();
if (nsnull != vm) {
@ -970,7 +988,7 @@ nsBrowserWindow::ShowContentSize()
return;
}
nsIPresShell* shell = GetPresShell(mWebShell);
nsIPresShell* shell = GetPresShell();
if (nsnull != shell) {
nsIDocument* doc = shell->GetDocument();
if (nsnull != doc) {
@ -992,7 +1010,7 @@ nsBrowserWindow::ShowContentSize()
void
nsBrowserWindow::ShowFrameSize()
{
nsIPresShell* shell0 = GetPresShell(mWebShell);
nsIPresShell* shell0 = GetPresShell();
if (nsnull != shell0) {
nsIDocument* doc = shell0->GetDocument();
if (nsnull != doc) {
@ -1031,7 +1049,7 @@ nsBrowserWindow::ShowStyleSize()
void
nsBrowserWindow::DoDebugSave()
{
nsIPresShell* shell = GetPresShell(mWebShell);
nsIPresShell* shell = GetPresShell();
if (nsnull != shell) {
nsIDocument* doc = shell->GetDocument();
if (nsnull != doc) {
@ -1066,6 +1084,44 @@ nsBrowserWindow::DoDebugSave()
}
}
void
nsBrowserWindow::DoDebugRobot()
{
mApp->CreateRobot(this);
}
void
nsBrowserWindow::DoSiteWalker()
{
mApp->CreateSiteWalker(this);
}
void
nsBrowserWindow::DoJSConsole()
{
mApp->CreateJSConsole(this);
}
#include "nsEditorMode.h"
void
nsBrowserWindow::DoEditorMode()
{
nsIPresShell* shell = GetPresShell();
if (nsnull != shell) {
nsIDocument* doc = shell->GetDocument();
if (nsnull != doc) {
nsIDOMDocument *domdoc = nsnull;
doc->QueryInterface(kIDOMDocumentIID, (void**) &domdoc);
if (nsnull != domdoc) {
NS_InitEditorMode(domdoc);
NS_RELEASE(domdoc);
}
NS_RELEASE(doc);
}
NS_RELEASE(shell);
}
}
nsEventStatus
nsBrowserWindow::DispatchDebugMenu(PRInt32 aID)
{
@ -1138,6 +1194,22 @@ nsBrowserWindow::DispatchDebugMenu(PRInt32 aID)
case VIEWER_DEBUGSAVE:
DoDebugSave();
break;
case VIEWER_DEBUGROBOT:
DoDebugRobot();
break;
case VIEWER_TOP100:
DoSiteWalker();
break;
case JS_CONSOLE:
DoJSConsole();
break;
case EDITOR_MODE:
DoEditorMode();
break;
}
return(result);
}

View File

@ -32,6 +32,12 @@ class nsIButton;
class nsIThrobber;
class nsViewerApp;
#ifdef NS_DEBUG
class nsIPresShell;
#endif
#define SAMPLES_BASE_URL "resource:/res/samples"
/**
* Abstract base class for our test app's browser windows
*/
@ -56,6 +62,7 @@ public:
PRUint32 aChromeMask);
NS_IMETHOD MoveTo(PRInt32 aX, PRInt32 aY);
NS_IMETHOD SizeTo(PRInt32 aWidth, PRInt32 aHeight);
NS_IMETHOD GetBounds(nsRect& aBounds);
NS_IMETHOD Show();
NS_IMETHOD Hide();
NS_IMETHOD ChangeChrome(PRUint32 aNewChromeMask);
@ -63,6 +70,7 @@ public:
NS_IMETHOD LoadURL(const nsString& aURL);
NS_IMETHOD SetTitle(const nsString& aTitle);
NS_IMETHOD GetTitle(nsString& aResult);
NS_IMETHOD GetWebShell(nsIWebShell*& aResult);
// nsIStreamObserver
NS_IMETHOD OnStartBinding(nsIURL* aURL, const char *aContentType);
@ -107,7 +115,12 @@ public:
void ShowFrameSize();
void ShowStyleSize();
void DoDebugSave();
void DoDebugRobot();
void DoSiteWalker();
void DoJSConsole();
void DoEditorMode();
nsEventStatus DispatchDebugMenu(PRInt32 aID);
nsIPresShell* GetPresShell();
#endif
void SetApp(nsViewerApp* aApp) {

View File

@ -15,8 +15,8 @@
* Copyright (C) 1998 Netscape Communications Corporation. All Rights
* Reserved.
*/
#include "nsDocLoader.h"
#include "nsIBrowserWindow.h"
#include "nsITimer.h"
#include "nsITimerCallback.h"
#include "nsVoidArray.h"
@ -25,7 +25,7 @@
#include "nsIWebShell.h"
#include "resources.h"
#include "nsString.h"
#include "nsViewer.h"
#include "nsViewerApp.h"
/*
This class loads creates and loads URLs until finished.
@ -34,8 +34,8 @@
*/
nsDocLoader::nsDocLoader(nsIWebShell* aShell,
nsViewer* aViewer,
nsDocLoader::nsDocLoader(nsIBrowserWindow* aBrowser,
nsViewerApp* aViewer,
PRInt32 aSeconds,
PRBool aPostExit)
{
@ -45,7 +45,7 @@ nsDocLoader::nsDocLoader(nsIWebShell* aShell,
mDelay = aSeconds;
mPostExit = aPostExit;
mDocNum = 0;
mWebShell = aShell;
mBrowser = aBrowser;
mViewer = aViewer;
mTimers = new nsVoidArray();
mURLList = new nsVoidArray();
@ -71,7 +71,7 @@ nsDocLoader::~nsDocLoader()
mTimers = nsnull;
}
NS_RELEASE(mWebShell);
NS_RELEASE(mBrowser);
}
static NS_DEFINE_IID(kIStreamObserverIID, NS_ISTREAMOBSERVER_IID);
@ -86,7 +86,7 @@ void nsDocLoader::SetDelay(PRInt32 aSeconds)
// Add a URL to the doc loader
void nsDocLoader::AddURL(char* aURL)
void nsDocLoader::AddURL(const char* aURL)
{
if (aURL)
{
@ -104,19 +104,16 @@ void nsDocLoader::AddURL(char* aURL)
}
// Add a URL to the doc loader
void nsDocLoader::AddURL(nsString* aURL)
void nsDocLoader::AddURL(const nsString& aURL)
{
if (aURL)
if (mStart == PR_FALSE)
{
if (mStart == PR_FALSE)
{
nsString* url;
nsString* url;
if (mURLList == nsnull)
mURLList = new nsVoidArray();
url = new nsString(*aURL);
mURLList->AppendElement((void*)url);
}
if (mURLList == nsnull)
mURLList = new nsVoidArray();
url = new nsString(aURL);
mURLList->AppendElement((void*)url);
}
}
@ -155,9 +152,14 @@ nsDocLoader::LoadDoc(PRInt32 aDocNum, PRBool aObserveIt)
{
nsString* url = (nsString*)mURLList->ElementAt(aDocNum);
if (url) {
mWebShell->LoadURL(*url, // URL string
aObserveIt ? this : nsnull, // Observer
nsnull); // Post Data
nsIWebShell* shell = nsnull;
mBrowser->GetWebShell(shell);
if (nsnull != shell) {
shell->LoadURL(*url, // URL string
aObserveIt ? this : nsnull, // Observer
nsnull); // Post Data
NS_RELEASE(shell);
}
}
}
@ -254,7 +256,7 @@ void nsDocLoader::CallTest()
if (mPostExit)
{
printf("QUITTING APPLICATION \n");
mViewer->ExitViewer();
mViewer->Exit();
}
}
}

View File

@ -22,10 +22,10 @@
#include "nsIStreamListener.h"
#include "nsString.h"
class nsIWebShell;
class nsIBrowserWindow;
class nsITimer;
class nsVoidArray;
class nsViewer;
class nsViewerApp;
/*
This class loads creates and loads URLs until finished.
@ -36,7 +36,7 @@ class nsViewer;
class nsDocLoader : public nsIStreamObserver
{
public:
nsDocLoader(nsIWebShell* aWebWidget, nsViewer* aViewer,
nsDocLoader(nsIBrowserWindow* aBrowser, nsViewerApp* aViewer,
PRInt32 aSeconds=1, PRBool aPostExit=PR_TRUE);
// nsISupports
@ -49,8 +49,8 @@ public:
NS_IMETHOD OnStopBinding(nsIURL* aURL, PRInt32 status, const nsString& aMsg);
// Add a URL to the doc loader
void AddURL(char* aURL);
void AddURL(nsString* aURL);
void AddURL(const char* aURL);
void AddURL(const nsString& aURL);
// Get the timer and the url list
// needed to be available for the call back methods
@ -92,15 +92,15 @@ protected:
void LoadDoc(PRInt32 aDocNum, PRBool aObserveIt);
PRInt32 mDocNum;
PRBool mStart;
PRInt32 mDelay;
PRBool mPostExit;
nsIWebShell* mWebShell;
nsViewer* mViewer;
nsString mURL;
nsVoidArray* mURLList;
nsVoidArray* mTimers;
PRInt32 mDocNum;
PRBool mStart;
PRInt32 mDelay;
PRBool mPostExit;
nsIBrowserWindow* mBrowser;
nsViewerApp* mViewer;
nsString mURL;
nsVoidArray* mURLList;
nsVoidArray* mTimers;
};
#endif

View File

@ -29,7 +29,7 @@ static nsIDOMNode* kCurrentNode;
static NS_DEFINE_IID(kIDOMTextIID, NS_IDOMTEXT_IID);
static NS_DEFINE_IID(kIDOMElementIID, NS_IDOMELEMENT_IID);
nsresult nsInitEditorMode(nsIDOMDocument *aDOMDocument)
nsresult NS_InitEditorMode(nsIDOMDocument *aDOMDocument)
{
NS_IF_RELEASE(kCurrentNode);

View File

@ -21,7 +21,7 @@
#include "nsIDOMDocument.h"
extern nsresult nsInitEditorMode(nsIDOMDocument * aDOMDocument);
extern nsresult NS_InitEditorMode(nsIDOMDocument * aDOMDocument);
extern nsresult nsAppendText(nsString *aStr);
extern nsresult nsDeleteLast();
extern nsresult nsSetCurrentNode(nsIDOMNode *aNode);

View File

@ -31,6 +31,18 @@ nsNativeViewerApp::~nsNativeViewerApp()
{
}
int
nsNativeViewerApp::Run()
{
mAppShell->Run();
return 0;
}
void
nsNativeViewerApp::CreateRobot(nsBrowserWindow* aWindow)
{
}
//----------------------------------------------------------------------
nsNativeBrowserWindow::nsNativeBrowserWindow()
@ -67,7 +79,7 @@ nsNativeBrowserWindow::DispatchMenuItem(PRInt32 aID)
//----------------------------------------------------------------------
void main(int argc, char **argv)
int main(int argc, char **argv)
{
// Hack to get il_ss set so it doesn't fail in xpcompat.c
@ -76,6 +88,7 @@ void main(int argc, char **argv)
gTheApp = new nsNativeViewerApp();
gTheApp->Initialize(argc, argv);
gTheApp->OpenWindow();
gTheApp->Run();
return 0;
}

View File

@ -23,6 +23,9 @@
#include "nsIPref.h"
#include "nsINetService.h"
#include "nsRepository.h"
#include "nsDocLoader.h"
#include "prprf.h"
#include "plstr.h"
#ifdef VIEWER_PLUGINS
static nsIPluginManager *gPluginManager = nsnull;
@ -43,7 +46,11 @@ static NS_DEFINE_IID(kINetContainerApplicationIID,
static NS_DEFINE_IID(kISupportsIID, NS_ISUPPORTS_IID);
nsViewerApp::nsViewerApp()
: mStartURL("resource:/res/samples/test0.html")
{
mDelay = 1;
mRepeatCount = 1;
mNumSamples = 10;
}
nsViewerApp::~nsViewerApp()
@ -163,15 +170,126 @@ nsViewerApp::Exit()
return NS_OK;
}
static void
PrintHelpInfo(char **argv)
{
fprintf(stderr, "Usage: %s [-p][-q][-md #][-f filename][-d #] [starting url]\n", argv[0]);
fprintf(stderr, "\t-p[#] -- run purify, optionally with a # that says which sample to stop at. For example, -p2 says to run samples 0, 1, and 2.\n");
fprintf(stderr, "\t-q -- run quantify\n");
fprintf(stderr, "\t-md # -- set the crt debug flags to #\n");
fprintf(stderr, "\t-d # -- set the delay between URL loads to # (in milliseconds)\n");
fprintf(stderr, "\t-r # -- set the repeat count, which is the number of times the URLs will be loaded in batch mode.\n");
fprintf(stderr, "\t-f filename -- read a list of URLs from <filename>\n");
}
static void
AddTestDocsFromFile(nsDocLoader* aDocLoader, const nsString& aFileName)
{
char cfn[1000];
aFileName.ToCString(cfn, sizeof(cfn));
#ifdef XP_PC
FILE* fp = fopen(cfn, "rb");
#else
FILE* fp = fopen(cfn, "r");
#endif
for (;;) {
char linebuf[2000];
char* cp = fgets(linebuf, sizeof(linebuf), fp);
if (nsnull == cp) {
break;
}
if (linebuf[0] == '#') {
continue;
}
// strip crlf's from the line
int len = strlen(linebuf);
if (0 != len) {
if (('\n' == linebuf[len-1]) || ('\r' == linebuf[len-1])) {
linebuf[--len] = 0;
}
}
if (0 != len) {
if (('\n' == linebuf[len-1]) || ('\r' == linebuf[len-1])) {
linebuf[--len] = 0;
}
}
// Add non-empty lines to the test list
if (0 != len) {
aDocLoader->AddURL(linebuf);
}
}
fclose(fp);
}
NS_IMETHODIMP
nsViewerApp::ProcessArguments(int argc, char** argv)
{
int i;
for (i = 1; i < argc; i++) {
if (argv[i][0] == '-') {
if (PL_strncmp(argv[i], "-p", 2) == 0) {
mDoPurify = PR_TRUE;
char *optionalSampleStopIndex = &(argv[i][2]);
if ('\0' != *optionalSampleStopIndex)
{
if (1!=sscanf(optionalSampleStopIndex, "%d", &mNumSamples))
{
PrintHelpInfo(argv);
exit(-1);
}
}
}
else if (PL_strcmp(argv[i], "-q") == 0) {
mDoQuantify = PR_TRUE;
}
else if (PL_strcmp(argv[i], "-f") == 0) {
mLoadTestFromFile = PR_TRUE;
i++;
if (i>=argc || nsnull==argv[i] || nsnull==*(argv[i]))
{
PrintHelpInfo(argv);
exit(-1);
}
mInputFileName = argv[i];
}
else if (PL_strcmp(argv[i], "-d") == 0) {
i++;
if (i>=argc || 1!=sscanf(argv[i], "%d", &mDelay))
{
PrintHelpInfo(argv);
exit(-1);
}
}
else if (PL_strcmp(argv[i], "-r") == 0) {
i++;
if (i>=argc || 1!=sscanf(argv[i], "%d", &mRepeatCount))
{
PrintHelpInfo(argv);
exit(-1);
}
}
else {
PrintHelpInfo(argv);
exit(-1);
}
}
else
break;
}
if (i < argc) {
mStartURL = argv[i];
}
return NS_OK;
}
NS_IMETHODIMP
nsViewerApp::OpenWindow()
{
// Create browser window
nsBrowserWindow* bw = nsnull;
nsresult rv = NSRepository::CreateInstance(kBrowserWindowCID, nsnull,
kIBrowserWindowIID,
@ -179,13 +297,59 @@ nsViewerApp::OpenWindow()
bw->SetApp(this);
bw->Init(mAppShell, nsRect(0, 0, 620, 400), PRUint32(~0));
bw->Show();
{
bw->LoadURL("resource:/res/samples/test0.html");
if (mDoPurify) {
mDocLoader = new nsDocLoader(bw, this, mDelay);
mDocLoader->AddRef();
for (PRInt32 i = 0; i < mRepeatCount; i++) {
for (int docnum = 0; docnum < mNumSamples; docnum++) {
char url[500];
PR_snprintf(url, 500, "%s/test%d.html", SAMPLES_BASE_URL, docnum);
mDocLoader->AddURL(url);
}
}
mDocLoader->StartTimedLoading();
}
else if (mLoadTestFromFile) {
mDocLoader = new nsDocLoader(bw, this, mDelay);
mDocLoader->AddRef();
for (PRInt32 i = 0; i < mRepeatCount; i++) {
AddTestDocsFromFile(mDocLoader, mInputFileName);
}
if (0 == mDelay) {
mDocLoader->StartLoading();
}
else {
mDocLoader->StartTimedLoading();
}
}
else {
bw->LoadURL(mStartURL);
}
return NS_OK;
}
#if XXX_fix_me
if (mDoQuantify) {
// Synthesize 20 ResizeReflow commands (+/- 10 pixels) and then
// exit.
#define kNumReflows 20
for (PRIntn i = 0; i < kNumReflows; i++) {
nsRect r;
bw->GetBounds(r);
if (i & 1) {
r.width -= 10;
}
else {
r.width += 10;
}
bw->SizeTo(r.width, r.height);
}
}
mAppShell->Exit();
#endif
//----------------------------------------
// nsINetContainerApplication implementation
@ -234,3 +398,406 @@ nsViewerApp::AfterDispatch()
{
NET_PollSockets();
}
//----------------------------------------
#ifdef XP_PC
// XXX temporary robot code until it's made XP
#include "prenv.h"
#include "resources.h"
#include "nsIPresShell.h"
#include "nsIDocument.h"
#include "nsIURL.h"
#define DEBUG_EMPTY "(none)"
static int gDebugRobotLoads = 5000;
static char gVerifyDir[_MAX_PATH];
static BOOL gVisualDebug = TRUE;
extern HANDLE gInstance, gPrevInstance;
extern "C" NS_EXPORT int DebugRobot(
nsVoidArray * workList, nsIWebShell * ww,
int imax, char * verify_dir,
void (*yieldProc)(const char *));
void yieldProc(const char * str)
{
// Process messages
MSG msg;
while (PeekMessage(&msg, NULL, 0, 0, PM_NOREMOVE)) {
GetMessage(&msg, NULL, 0, 0);
if (
#if 0
!JSConsole::sAccelTable ||
!gConsole ||
!gConsole->GetMainWindow() ||
!TranslateAccelerator(gConsole->GetMainWindow(), JSConsole::sAccelTable, &msg)
#else
1
#endif
) {
TranslateMessage(&msg);
DispatchMessage(&msg);
/* Pump Netlib... */
NET_PollSockets();
}
}
}
/* Debug Robot Dialog options */
BOOL CALLBACK DlgProc(HWND hDlg, UINT msg, WPARAM wParam,LPARAM lParam)
{
BOOL translated = FALSE;
HWND hwnd;
switch (msg)
{
case WM_INITDIALOG:
{
SetDlgItemInt(hDlg,IDC_PAGE_LOADS,5000,FALSE);
char * text = PR_GetEnv("VERIFY_PARSER");
SetDlgItemText(hDlg,IDC_VERIFICATION_DIRECTORY,text ? text : DEBUG_EMPTY);
hwnd = GetDlgItem(hDlg,IDC_UPDATE_DISPLAY);
SendMessage(hwnd,BM_SETCHECK,TRUE,0);
}
return FALSE;
case WM_COMMAND:
switch (LOWORD(wParam))
{
case IDOK:
gDebugRobotLoads = GetDlgItemInt(hDlg,IDC_PAGE_LOADS,&translated,FALSE);
GetDlgItemText(hDlg, IDC_VERIFICATION_DIRECTORY, gVerifyDir, sizeof(gVerifyDir));
if (!strcmp(gVerifyDir,DEBUG_EMPTY))
gVerifyDir[0] = '\0';
hwnd = GetDlgItem(hDlg,IDC_UPDATE_DISPLAY);
gVisualDebug = (BOOL)SendMessage(hwnd,BM_GETCHECK,0,0);
EndDialog(hDlg,IDOK);
break;
case IDCANCEL:
EndDialog(hDlg,IDCANCEL);
break;
}
break;
default:
return FALSE;
}
return TRUE;
}
BOOL CreateRobotDialog(HWND hParent)
{
BOOL result = (DialogBox(gInstance,MAKEINTRESOURCE(IDD_DEBUGROBOT),hParent,(DLGPROC)DlgProc) == IDOK);
return result;
}
#endif
NS_IMETHODIMP
nsViewerApp::CreateRobot(nsBrowserWindow* aWindow)
{
#ifdef XP_PC
if (CreateRobotDialog(aWindow->mWindow->GetNativeData(NS_NATIVE_WIDGET)))
{
nsIPresShell* shell = aWindow->GetPresShell();
if (nsnull != shell) {
nsIDocument* doc = shell->GetDocument();
if (nsnull!=doc) {
const char * str = doc->GetDocumentURL()->GetSpec();
nsVoidArray * gWorkList = new nsVoidArray();
gWorkList->AppendElement(new nsString(str));
DebugRobot(
gWorkList,
gVisualDebug ? aWindow->mWebShell : nsnull,
gDebugRobotLoads,
PL_strdup(gVerifyDir),
yieldProc);
}
}
}
#endif
return NS_OK;
}
//----------------------------------------
#ifdef XP_PC
static nsBrowserWindow* gWinData;
static int gTop100Pointer = 0;
static char * gTop100List[] = {
"http://www.yahoo.com",
"http://www.netscape.com",
"http://www.microsoft.com",
"http://www.excite.com",
"http://www.mckinley.com",
"http://www.city.net",
"http://www.webcrawler.com",
"http://www.mirabilis.com",
"http://www.infoseek.com",
"http://www.pathfinder.com",
"http://www.warnerbros.com",
"http://www.cnn.com",
"http://www.altavista.digital.com",
"http://www.altavista.com",
"http://www.usatoday.com",
"http://www.disney.com",
"http://www.starwave.com",
"http://www.hotwired.com",
"http://www.hotbot.com",
"http://www.lycos.com",
"http://www.pointcom.com",
"http://www.cnet.com",
"http://www.search.com",
"http://www.news.com",
"http://www.download.com",
"http://www.geocities.com",
"http://www.aol.com",
"http://members.aol.com",
"http://www.imdb.com",
"http://uk.imdb.com",
"http://macromedia.com",
"http://www.infobeat.com",
"http://www.fxweb.com",
"http://www.whowhere.com",
"http://www.real.com",
"http://www.sportsline.com",
"http://www.dejanews.com",
"http://www.the-park.com",
"http://www.cmpnet.com",
"http://www.go2net.com",
"http://www.metacrawler.com",
"http://www.playsite.com",
"http://www.stocksite.com",
"http://www.sony.com",
"http://www.music.sony.com",
"http://www.station.sony.com",
"http://www.scea.sony.com",
"http://www.infospace.com",
"http://www.zdnet.com",
"http://www.hotfiles.com",
"http://www.chathouse.com",
"http://www.looksmart.com",
"http://www.iamginegames.com",
"http://www.macaddict.com",
"http://www.rsac.org",
"http://www.apple.com",
"http://www.beseen.com",
"http://www.dogpile.com",
"http://www.xoom.com",
"http://www.tucows.com",
"http://www.freethemes.com",
"http://www.winfiles.com",
"http://www.vservers.com",
"http://www.mtv.com",
"http://www.the-xfiles.com",
"http://www.datek.com",
"http://www.cyberthrill.com",
"http://www.surplusdirect.com",
"http://www.tomshardware.com",
"http://www.bigyellow.com",
"http://www.100hot.com",
"http://www.messagemates.com",
"http://www.onelist.com",
"http://www.bluemountain.com",
"http://www.ea.com",
"http://www.bullfrog.co.uk",
"http://www.travelocity.com",
"http://www.ibm.com",
"http://www.bigcharts.com",
"http://www.davesclassics.com",
"http://www.goto.com",
"http://www.weather.com",
"http://www.gamespot.com",
"http://www.bloomberg.com",
"http://www.winzip.com",
"http://www.filez.com",
"http://www.westwood.com",
"http://www.internet.com",
"http://www.cardmaster.com",
"http://www.creaf.com",
"http://netaddress.usa.net",
"http://www.occ.com",
"http://www.as.org",
"http://www.amazon.com",
"http://www.drudgereport.com",
"http://www.hardradio.com",
"http://www.intel.com",
"http://www.mp3.com",
"http://www.ebay.com",
"http://www.msn.com",
"http://www.fifa.com",
"http://www.attitude.com",
"http://www.happypuppy.com",
"http://www.gamesdomain.com",
"http://www.onsale.com",
"http://www.tm.com",
"http://www.xlnc1.com",
"http://www.greatsports.com",
"http://www.discovery.com",
"http://www.nai.com",
"http://www.nasa.gov",
"http://www.ogr.com",
"http://www.warzone.com",
"http://www.gamestats.com",
"http://www.winamp.com",
"http://java.sun.com",
"http://www.hp.com",
"http://www.cdnow.com",
"http://www.nytimes.com",
"http://www.majorleaguebaseball.com",
"http://www.washingtonpost.com",
"http://www.planetquake.com",
"http://www.wsj.com",
"http://www.slashdot.org",
"http://www.adobe.com",
"http://www.quicken.com",
"http://www.talkcity.com",
"http://www.developer.com",
"http://www.mapquest.com",
0
};
// XXX temporary site walker code until it's made XP
BOOL CALLBACK
SiteWalkerDlgProc(HWND hDlg, UINT msg, WPARAM wParam,LPARAM lParam)
{
BOOL translated = FALSE;
switch (msg)
{
case WM_INITDIALOG:
{
SetDlgItemText(hDlg,IDC_SITE_NAME, gTop100List[gTop100Pointer]);
EnableWindow(GetDlgItem(hDlg,ID_SITE_PREVIOUS),TRUE);
if (gWinData)
gWinData->LoadURL(gTop100List[gTop100Pointer]);
}
return FALSE;
case WM_COMMAND:
switch (LOWORD(wParam))
{
case ID_SITE_NEXT:
{
char * p = gTop100List[++gTop100Pointer];
if (p) {
EnableWindow(GetDlgItem(hDlg,ID_SITE_NEXT),TRUE);
SetDlgItemText(hDlg,IDC_SITE_NAME, p);
if (gWinData)
gWinData->LoadURL(gTop100List[gTop100Pointer]);
}
else {
EnableWindow(GetDlgItem(hDlg,ID_SITE_NEXT),FALSE);
EnableWindow(GetDlgItem(hDlg,ID_SITE_PREVIOUS),TRUE);
SetDlgItemText(hDlg,IDC_SITE_NAME, "[END OF LIST]");
}
}
break;
case ID_SITE_PREVIOUS:
{
if (gTop100Pointer > 0) {
EnableWindow(GetDlgItem(hDlg,ID_SITE_PREVIOUS),TRUE);
SetDlgItemText(hDlg,IDC_SITE_NAME, gTop100List[--gTop100Pointer]);
if (gWinData)
gWinData->LoadURL(gTop100List[gTop100Pointer]);
}
else {
EnableWindow(GetDlgItem(hDlg,ID_SITE_PREVIOUS),FALSE);
EnableWindow(GetDlgItem(hDlg,ID_SITE_NEXT),TRUE);
}
}
break;
case ID_EXIT:
EndDialog(hDlg,IDCANCEL);
NS_RELEASE(gWinData);
break;
}
break;
default:
return FALSE;
}
return TRUE;
}
BOOL CreateSiteWalkerDialog(HWND hParent)
{
BOOL result = (DialogBox(gInstance,MAKEINTRESOURCE(IDD_SITEWALKER),hParent,(DLGPROC)SiteWalkerDlgProc) == IDOK);
return result;
}
#endif
NS_IMETHODIMP
nsViewerApp::CreateSiteWalker(nsBrowserWindow* aWindow)
{
#ifdef XP_PC
if (nsnull == gWinData) {
gWinData = aWindow;
NS_ADDREF(aWindow);
CreateSiteWalkerDialog(aWindow->mWindow->GetNativeData(NS_NATIVE_WIDGET));
}
#endif
return NS_OK;
}
//----------------------------------------
#ifdef XP_PC
#include "jsconsres.h"
#include "JSConsole.h"
static NS_DEFINE_IID(kIScriptContextOwnerIID, NS_ISCRIPTCONTEXTOWNER_IID);
JSConsole *gConsole = NULL;
void DestroyConsole()
{
if (gConsole) {
gConsole->SetNotification(NULL);
delete gConsole;
gConsole = NULL;
}
}
void ShowConsole(nsBrowserWindow* aWindow)
{
HWND hWnd = aWindow->mWindow->GetNativeData(NS_NATIVE_WIDGET);
if (!gConsole) {
// load the accelerator table for the console
if (!JSConsole::sAccelTable) {
JSConsole::sAccelTable = LoadAccelerators(gInstance,
MAKEINTRESOURCE(ACCELERATOR_TABLE));
}
nsIScriptContextOwner *owner = nsnull;
nsIScriptContext *context = nsnull;
// XXX needs to change to aWindow->mWebShell
if (NS_OK == aWindow->QueryInterface(kIScriptContextOwnerIID, (void **)&owner)) {
if (NS_OK == owner->GetScriptContext(&context)) {
// create the console
gConsole = JSConsole::CreateConsole();
gConsole->SetContext(context);
// lifetime of the context is still unclear at this point.
// Anyway, as long as the web widget is alive the context is alive.
// Maybe the context shouldn't even be RefCounted
context->Release();
gConsole->SetNotification(DestroyConsole);
}
NS_RELEASE(owner);
}
else {
MessageBox(hWnd, "Unable to load JavaScript", "Viewer Error", MB_ICONSTOP);
}
}
}
#endif
NS_IMETHODIMP
nsViewerApp::CreateJSConsole(nsBrowserWindow* aWindow)
{
#ifdef XP_PC
if (nsnull == gConsole) {
ShowConsole(aWindow);
}
#endif
return NS_OK;
}

View File

@ -21,13 +21,24 @@
#include "nsINetContainerApplication.h"
#include "nsIAppShell.h"
#include "nsString.h"
#include "nsCRT.h"
#include "nsVoidArray.h"
class nsIPref;
class nsDocLoader;
class nsBrowserWindow;
class nsViewerApp : public nsINetContainerApplication,
public nsDispatchListener
{
public:
void* operator new(size_t sz) {
void* rv = new char[sz];
nsCRT::zero(rv, sz);
return rv;
}
virtual ~nsViewerApp();
// nsISupports
@ -48,24 +59,36 @@ public:
NS_IMETHOD Initialize(int argc, char** argv);
NS_IMETHOD ProcessArguments(int argc, char** argv);
NS_IMETHOD OpenWindow();
NS_IMETHOD CreateRobot(nsBrowserWindow* aWindow);
NS_IMETHOD CreateSiteWalker(nsBrowserWindow* aWindow);
NS_IMETHOD CreateJSConsole(nsBrowserWindow* aWindow);
NS_IMETHOD Exit();
void Run() {
mAppShell->Run();
}
virtual int Run() = 0;
protected:
nsViewerApp();
nsIAppShell* mAppShell;
nsIPref* mPrefs;
nsString mStartURL;
PRBool mDoPurify;
PRBool mDoQuantify;
PRBool mLoadTestFromFile;
nsString mInputFileName;
PRInt32 mNumSamples;
nsVoidArray mInputFiles;
PRInt32 mDelay;
PRInt32 mRepeatCount;
nsDocLoader* mDocLoader;
};
class nsNativeViewerApp : public nsViewerApp {
public:
nsNativeViewerApp();
~nsNativeViewerApp();
virtual int Run();
};
#endif /* nsViewerApp_h___ */

View File

@ -24,7 +24,7 @@
extern "C" int NET_PollSockets();
static HANDLE gInstance, gPrevInstance;
HANDLE gInstance, gPrevInstance;
static nsITimer* gNetTimer;
nsNativeViewerApp::nsNativeViewerApp()
@ -35,6 +35,44 @@ nsNativeViewerApp::~nsNativeViewerApp()
{
}
static void
PollNet(nsITimer *aTimer, void *aClosure)
{
NET_PollSockets();
NS_IF_RELEASE(gNetTimer);
if (NS_OK == NS_NewTimer(&gNetTimer)) {
gNetTimer->Init(PollNet, nsnull, 1000 / 50);
}
}
int
nsNativeViewerApp::Run()
{
OpenWindow();
// Process messages
MSG msg;
PollNet(0, 0);
while (::GetMessage(&msg, NULL, 0, 0)) {
if (
#if 0
!JSConsole::sAccelTable ||
!gConsole ||
!gConsole->GetMainWindow() ||
!TranslateAccelerator(gConsole->GetMainWindow(), JSConsole::sAccelTable, &msg)
#endif
1
) {
TranslateMessage(&msg);
DispatchMessage(&msg);
NET_PollSockets();
}
}
return msg.wParam;
}
//----------------------------------------------------------------------
//----------------------------------------------------------------------
nsNativeBrowserWindow::nsNativeBrowserWindow()
@ -66,69 +104,26 @@ nsNativeBrowserWindow::DispatchMenuItem(PRInt32 aID)
//----------------------------------------------------------------------
static void
PollNet(nsITimer *aTimer, void *aClosure)
{
NET_PollSockets();
NS_IF_RELEASE(gNetTimer);
if (NS_OK == NS_NewTimer(&gNetTimer)) {
gNetTimer->Init(PollNet, nsnull, 1000 / 50);
}
}
static int
RunViewer(HANDLE instance, HANDLE prevInstance, int nCmdShow,
nsViewerApp* app)
{
gInstance = instance;
gPrevInstance = prevInstance;
app->OpenWindow();
// SetViewer(aViewer);
// nsIWidget *mainWindow = nsnull;
// nsDocLoader* dl = aViewer->SetupViewer(&mainWindow, 0, 0);
// Process messages
MSG msg;
PollNet(0, 0);
while (::GetMessage(&msg, NULL, 0, 0)) {
if (
#if 0
!JSConsole::sAccelTable ||
!gConsole ||
!gConsole->GetMainWindow() ||
!TranslateAccelerator(gConsole->GetMainWindow(), JSConsole::sAccelTable, &msg)
#endif
1
) {
TranslateMessage(&msg);
DispatchMessage(&msg);
NET_PollSockets();
}
}
// aViewer->CleanupViewer(dl);
return msg.wParam;
}
void main(int argc, char **argv)
int main(int argc, char **argv)
{
PL_InitializeEventsLib("");
nsViewerApp* app = new nsNativeViewerApp();
app->Initialize(argc, argv);
RunViewer(GetModuleHandle(NULL), NULL, SW_SHOW, app);
app->Run();
delete app;
return 0;
}
int PASCAL
WinMain(HANDLE instance, HANDLE prevInstance, LPSTR cmdParam, int nCmdShow)
{
gInstance = instance;
gPrevInstance = prevInstance;
PL_InitializeEventsLib("");
nsViewerApp* app = new nsNativeViewerApp();
app->Initialize(0, nsnull);
int rv = RunViewer(instance, prevInstance, nCmdShow, app);
int result = app->Run();
delete app;
return rv;
return result;
}