diff --git a/webshell/tests/viewer/main.cpp b/webshell/tests/viewer/main.cpp index 3b9fc9d886d..30ba23dfd04 100644 --- a/webshell/tests/viewer/main.cpp +++ b/webshell/tests/viewer/main.cpp @@ -19,9 +19,13 @@ #include "nsViewer.h" #include "nsMotifMenu.h" #include "nsIImageManager.h" +#include + +#define FILE_BASE_URL "file:////home/kmcclusk/mozilla/dist/Linux2.0.31_x86_DBG.OBJ/bin/res/samples" class nsMotifViewer : public nsViewer { virtual void AddMenu(nsIWidget* aMainWindow); + virtual char* GetBaseURL(); }; //-------------------------------------------------------- @@ -64,4 +68,29 @@ void nsMotifViewer::AddMenu(nsIWidget* aMainWindow) CreateViewerMenus(XtParent(aMainWindow->GetNativeData(NS_NATIVE_WIDGET)), MenuProc); } +char* nsMotifViewer::GetBaseURL() +{ + static char* protocol = "file:///"; + static char url[MAXPATHLEN + sizeof(protocol)]; + FILE *pp; + + char location[MAXPATHLEN]; + + if (!(pp = popen("pwd", "r"))) { + printf("Error in nsMotifViewer::GetBaseURL 1\n"); + return(0); + } + else { + if (fgets(location, MAXPATHLEN, pp)) { + location[strlen(location)-1] = 0; + sprintf(url, "%s%s%s", protocol,location, "/res/samples"); + return(url); + } + else + printf("Error in nsMotifViewer::GetBaseURL 2\n"); + return(0); + } + +} + diff --git a/webshell/tests/viewer/nsViewer.cpp b/webshell/tests/viewer/nsViewer.cpp index ef7d692eac2..0825ffda910 100644 --- a/webshell/tests/viewer/nsViewer.cpp +++ b/webshell/tests/viewer/nsViewer.cpp @@ -81,8 +81,12 @@ static NS_DEFINE_IID(kCScrollingViewCID, NS_SCROLLING_VIEW_CID); static NS_DEFINE_IID(kCWebWidgetCID, NS_WEBWIDGET_CID); +//#define SAMPLES_BASE_URL "file:////home/kmcclusk/mozilla/dist/Linux2.0.31_x86_DBG.OBJ/bin/res/samples" +//#define START_URL SAMPLES_BASE_URL "/test0.html" + + #define SAMPLES_BASE_URL "resource:/res/samples" -#define START_URL SAMPLES_BASE_URL "/test0.html" +#define DEFAULT_DOC "/test0.html" nsViewer* gTheViewer = nsnull; WindowData * gMainWindowData = nsnull; @@ -654,7 +658,7 @@ void nsViewer::AddTestDocs(nsDocLoader* aDocLoader) char url[500]; for (int docnum = 0; docnum < gNumSamples; docnum++) { - PR_snprintf(url, 500, "%s/test%d.html", SAMPLES_BASE_URL, docnum); + PR_snprintf(url, 500, "%s/test%d.html", GetBaseURL(), docnum); aDocLoader->AddURL(url); } } @@ -950,7 +954,7 @@ nsEventStatus nsViewer::ProcessMenu(PRUint32 aId, WindowData* wd) if ((nsnull != wd) && (nsnull != wd->ww)) { PRIntn ix = aId - VIEWER_DEMO0; char* url = new char[500]; - PR_snprintf(url, 500, "%s/test%d.html", SAMPLES_BASE_URL, ix); + PR_snprintf(url, 500, "%s/test%d.html", GetBaseURL(), ix); wd->observer->LoadURL(url); delete url; } @@ -1117,7 +1121,7 @@ nsDocLoader* nsViewer::SetupViewer(nsIWidget **aMainWindow, int argc, char **arg } else { // Load the starting url if we have one - wd->observer->LoadURL(startURL ? startURL : START_URL); + wd->observer->LoadURL(startURL ? startURL : GetDefaultStartURL()); if (gDoQuantify) { // Synthesize 20 ResizeReflow commands (+/- 10 pixels) and then // exit. @@ -1144,6 +1148,19 @@ void nsViewer::AfterDispatch() NET_PollSockets(); } +char* nsViewer::GetBaseURL() +{ + return(SAMPLES_BASE_URL); +} + +char* nsViewer::GetDefaultStartURL() +{ +static char defaultURL[MAXPATHLEN]; + + sprintf(defaultURL, "%s%s", GetBaseURL(), DEFAULT_DOC); + return(defaultURL); +} + void nsViewer::AddMenu(nsIWidget* aMainWindow) { printf("Menu not implemented\n"); diff --git a/webshell/tests/viewer/nsViewer.h b/webshell/tests/viewer/nsViewer.h index f0f9eff08ef..ca6e88c64aa 100644 --- a/webshell/tests/viewer/nsViewer.h +++ b/webshell/tests/viewer/nsViewer.h @@ -133,6 +133,8 @@ struct WindowData { class nsViewer : public nsDispatchListener { public: + virtual char* GetBaseURL(); + virtual char* GetDefaultStartURL(); virtual void AddMenu(nsIWidget* aMainWindow); virtual void ShowConsole(WindowData* aWindata); virtual void CloseConsole();