Back to index

lightning-sunbird  0.9+nobinonly
Public Member Functions | Protected Member Functions | Protected Attributes
nsNativeViewerApp Class Reference

#include <nsViewerApp.h>

Inheritance diagram for nsNativeViewerApp:
Inheritance graph
[legend]
Collaboration diagram for nsNativeViewerApp:
Collaboration graph
[legend]

List of all members.

Public Member Functions

 nsNativeViewerApp ()
 ~nsNativeViewerApp ()
virtual int Run ()
NS_DECL_ISUPPORTS NS_IMETHOD SetupRegistry ()
NS_IMETHOD Initialize (int argc, char **argv)
NS_IMETHOD ProcessArguments (int argc, char **argv)
NS_IMETHOD OpenWindow ()
NS_IMETHOD OpenWindow (PRUint32 aNewChromeMask, nsBrowserWindow *&aNewWindow)
NS_IMETHOD CloseWindow (nsBrowserWindow *aBrowserWindow)
NS_IMETHOD ViewSource (nsString &aURL)
NS_IMETHOD CreateRobot (nsBrowserWindow *aWindow)
NS_IMETHOD CreateSiteWalker (nsBrowserWindow *aWindow)
NS_IMETHOD CreateJSConsole (nsBrowserWindow *aWindow)
NS_IMETHOD Exit ()
NS_IMETHOD DoPrefs (nsBrowserWindow *aWindow)

Protected Member Functions

nsresult InitializeWindowCreator ()
void Destroy ()

Protected Attributes

nsIAppShellmAppShell
nsIPrefServicemPrefService
nsString mStartURL
PRBool mDoPurify
PRBool mLoadTestFromFile
PRBool mCrawl
nsString mInputFileName
PRInt32 mNumSamples
PRInt32 mDelay
PRInt32 mRepeatCount
nsWebCrawlermCrawler
PRBool mAllowPlugins
PRBool mIsInitialized
PRInt32 mWidth
PRInt32 mHeight
PRBool mShowLoadTimes
PRBool mJustShutdown

Detailed Description

Definition at line 101 of file nsViewerApp.h.


Constructor & Destructor Documentation

Definition at line 48 of file nsBeOSMain.cpp.

{
}

Definition at line 52 of file nsBeOSMain.cpp.

{
}

Member Function Documentation

NS_IMETHODIMP nsViewerApp::CloseWindow ( nsBrowserWindow aBrowserWindow) [inherited]

Definition at line 629 of file nsViewerApp.cpp.

{
  aBrowserWindow->Destroy();
  nsBrowserWindow* bw;
  mCrawler->GetBrowserWindow(&bw);
  if (bw == aBrowserWindow) {
    mCrawler->SetBrowserWindow(nsnull);
  }
  NS_IF_RELEASE(bw);
  NS_RELEASE(aBrowserWindow);

  return NS_OK;
}

Here is the call graph for this function:

Here is the caller graph for this function:

Definition at line 1519 of file nsViewerApp.cpp.

{
#ifdef XP_WIN
  if (nsnull == gConsole) {
    ShowConsole(aWindow);
  }
#endif
  return NS_OK;
}

Here is the caller graph for this function:

Definition at line 1021 of file nsViewerApp.cpp.

{
  if (CreateRobotDialog(aWindow->mWindow))
  {
    nsIPresShell* shell = aWindow->GetPresShell();
    if (nsnull != shell) {
      nsIDocument *doc = shell->GetDocument();
      if (doc) {
        nsCAutoString str;
        nsresult rv = doc->GetDocumentURI()->GetSpec(str);
        if (NS_FAILED(rv)) {
          return rv;
        }
        nsVoidArray * gWorkList = new nsVoidArray();

        {
          nsString* tempStr = new nsString;
          if ( tempStr )
            CopyUTF8toUTF16(str, *tempStr);
          gWorkList->AppendElement(tempStr);
        }
#if defined(XP_WIN) && defined(NS_DEBUG)
        DebugRobot( 
          gWorkList, 
          gVisualDebug ? aWindow->mDocShell : nsnull, 
          gDebugRobotLoads, 
          PL_strdup(gVerifyDir),
          yieldProc);
#endif
      }
    }
  }
  return NS_OK;
}

Here is the call graph for this function:

Definition at line 1464 of file nsViewerApp.cpp.

{
  if (nsnull == gWinData) {
    gWinData = aWindow;
    NS_ADDREF(aWindow);
  }
  CreateSiteDialog(aWindow->mWindow);
  return NS_OK;
}

Here is the call graph for this function:

void nsViewerApp::Destroy ( void  ) [protected, inherited]

Definition at line 187 of file nsViewerApp.cpp.

{
  // Close all of our windows
  nsBrowserWindow::CloseAllWindows();

  // Release the crawler
  if (nsnull != mCrawler) {
    // break cycle between crawler and window.
    mCrawler->SetBrowserWindow(nsnull);
    NS_RELEASE(mCrawler);
  }

  NS_IF_RELEASE(mPrefService);
}

Here is the call graph for this function:

Here is the caller graph for this function:

Definition at line 1530 of file nsViewerApp.cpp.

{
#if defined(XP_WIN) && defined(NGPREFS)

  INGLayoutPrefs *pPrefs;
  CoInitialize(NULL);

  HRESULT res = CoCreateInstance(CLSID_NGLayoutPrefs, NULL, 
                                 CLSCTX_INPROC_SERVER,
                                 IID_INGLayoutPrefs, (void**)&pPrefs);

  if (SUCCEEDED(res)) {
      pPrefs->Show(NULL);
      pPrefs->Release();
  }
  CoUninitialize();
#endif
  return NS_OK;
}

Here is the caller graph for this function:

nsresult nsViewerApp::Exit ( ) [inherited]

Definition at line 293 of file nsViewerApp.cpp.

Here is the call graph for this function:

Here is the caller graph for this function:

nsresult nsViewerApp::Initialize ( int  argc,
char **  argv 
) [inherited]

Definition at line 239 of file nsViewerApp.cpp.

{
  nsresult rv;

  rv = SetupRegistry();
  if (NS_FAILED(rv)) {
    return rv;
  }

  InitializeWindowCreator();

  // Create widget application shell
  rv = CallCreateInstance(kAppShellCID, &mAppShell);
  if (NS_FAILED(rv)) {
    return rv;
  }
  mAppShell->Create(&argc, argv);

  // Load preferences
  rv = CallGetService(NS_PREFSERVICE_CONTRACTID, &mPrefService);
  if (NS_FAILED(rv)) {
    return rv;
  }
  mPrefService->ReadUserPrefs(nsnull);

  // Finally process our arguments
  rv = ProcessArguments(argc, argv);

  mIsInitialized = PR_TRUE;
  return rv;
}

Here is the call graph for this function:

Here is the caller graph for this function:

nsresult nsViewerApp::InitializeWindowCreator ( ) [protected, inherited]

Definition at line 275 of file nsViewerApp.cpp.

{
  // create an nsWindowCreator and give it to the WindowWatcher service
  nsWindowCreator *creatorCallback = new nsWindowCreator(this);
  if (creatorCallback) {
    nsCOMPtr<nsIWindowCreator> windowCreator(NS_STATIC_CAST(nsIWindowCreator *, creatorCallback));
    if (windowCreator) {
      nsCOMPtr<nsIWindowWatcher> wwatch(do_GetService(NS_WINDOWWATCHER_CONTRACTID));
      if (wwatch) {
        wwatch->SetWindowCreator(windowCreator);
        return NS_OK;
      }
    }
  }
  return NS_ERROR_FAILURE;
}

Here is the call graph for this function:

Here is the caller graph for this function:

Definition at line 577 of file nsViewerApp.cpp.

{
  // Create browser window
  // XXX Some piece of code needs to properly hold the reference to this
  // browser window. For the time being the reference is released by the
  // browser event handling code during processing of the NS_DESTROY event...
  nsBrowserWindow* bw = new nsNativeBrowserWindow();
  NS_ENSURE_TRUE(bw, NS_ERROR_FAILURE);
  NS_ADDREF(bw);

  bw->SetApp(this);
  bw->SetShowLoadTimes(mShowLoadTimes);
  bw->Init(mAppShell, nsRect(0, 0, mWidth, mHeight),
           (PRUint32(~0) & ~nsIWebBrowserChrome::CHROME_OPENAS_CHROME), mAllowPlugins);
  bw->SetVisibility(PR_TRUE);
  nsBrowserWindow*   bwCurrent;
  mCrawler->GetBrowserWindow(&bwCurrent);
  if (!bwCurrent) {
         mCrawler->SetBrowserWindow(bw);
    bw->SetWebCrawler(mCrawler);
  }
  NS_IF_RELEASE(bwCurrent);

  if (mDoPurify) {
    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);
        mCrawler->AddURL(NS_ConvertASCIItoUCS2(url));
      }
    }
    mCrawler->Start();
  }
  else if (mLoadTestFromFile) {
    for (PRInt32 i = 0; i < mRepeatCount; i++) {
      AddTestDocsFromFile(mCrawler, mInputFileName);
    }
    mCrawler->Start();
  }
  else if (mCrawl) {
    mCrawler->AddURL(mStartURL);
    mCrawler->Start();
  }
  else {
    bw->GoTo(mStartURL.get());
  }
  NS_RELEASE(bw);

  return NS_OK;
}

Here is the call graph for this function:

Here is the caller graph for this function:

NS_IMETHODIMP nsViewerApp::OpenWindow ( PRUint32  aNewChromeMask,
nsBrowserWindow *&  aNewWindow 
) [inherited]

Definition at line 667 of file nsViewerApp.cpp.

{
  // Create browser window
  nsBrowserWindow* bw = new nsNativeBrowserWindow();
  NS_ENSURE_TRUE(bw, NS_ERROR_FAILURE);
  NS_ADDREF(bw);

  bw->SetApp(this);
  bw->Init(mAppShell, nsRect(0, 0, 620, 400), aNewChromeMask, mAllowPlugins);
  // Defer showing chrome windows until the chrome has loaded
  if (!(aNewChromeMask & nsIWebBrowserChrome::CHROME_OPENAS_CHROME))
    bw->SetVisibility(PR_TRUE);

  aNewWindow = bw;

  return NS_OK;
}

Here is the call graph for this function:

NS_IMETHODIMP nsViewerApp::ProcessArguments ( int  argc,
char **  argv 
) [inherited]

Definition at line 385 of file nsViewerApp.cpp.

{
  mCrawler = new nsWebCrawler(this);
  NS_ADDREF(mCrawler);

  int i;
  for (i = 1; i < argc; i++) {
    if (argv[i][0] == '-') {
      if (PL_strcmp(argv[i], "-x") == 0) {
        mJustShutdown = PR_TRUE;
      }
#if defined(NS_DEBUG) && defined(XP_WIN) && !defined(__MINGW32__)
      else if (PL_strcmp(argv[i], "-md") == 0) {
        int old = _CrtSetDbgFlag(0);
        old |= _CRTDBG_CHECK_ALWAYS_DF;
        _CrtSetDbgFlag(old);
      }
#endif
#if defined(XP_MACOSX)
      else if (PL_strncmp(argv[i], "-psn_", 5) == 0) {
        continue;
      }
#endif
      else if (PL_strncmp(argv[i], "-p", 2) == 0) {
        char *optionalSampleStopIndex = &(argv[i][2]);
        if ('\0' != *optionalSampleStopIndex)
        {
          if (1!=sscanf(optionalSampleStopIndex, "%d", &mNumSamples))
          {
            PrintHelpInfo(argv);
            exit(-1);
          }
        }
        mDoPurify = PR_TRUE;
        mCrawler->SetExitOnDone(PR_TRUE);
        mCrawl = PR_TRUE;
      }
      else if (PL_strcmp(argv[i], "-q") == 0) {
        mCrawler->EnableJiggleLayout();
        mCrawler->SetExitOnDone(PR_TRUE);
        mCrawl = 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.AssignWithConversion(argv[i]);
        mCrawler->SetExitOnDone(PR_TRUE);
        mCrawl = PR_TRUE;
      }
      else if (PL_strcmp(argv[i], "-rd") == 0) {
        i++;
        if (i>=argc || nsnull==argv[i] || nsnull==*(argv[i])) {
          PrintHelpInfo(argv);
          exit(-1);
        }
        mCrawler->SetEnableRegression(PR_TRUE);
        mCrawler->SetRegressionDir(NS_ConvertASCIItoUCS2(argv[i]));
      }
      else if (PL_strcmp(argv[i], "-o") == 0) {
        i++;
        if (i>=argc || nsnull==argv[i] || nsnull==*(argv[i]))
        {
          PrintHelpInfo(argv);
          exit(-1);
        }
        mCrawler->SetOutputDir(NS_ConvertASCIItoUCS2(argv[i]));
      }
      else if (PL_strcmp(argv[i], "-w") == 0) {
        int width;
        i++;
        if (i>=argc || 1!=sscanf(argv[i], "%d", &width))
        {
          PrintHelpInfo(argv);
          exit(-1);
        }
        mWidth = width > 0 ? width : DEFAULT_WIDTH;
      }
      else if (PL_strcmp(argv[i], "-h") == 0) {
        int height;
        i++;
        if (i>=argc || 1!=sscanf(argv[i], "%d", &height))
        {
          PrintHelpInfo(argv);
          exit(-1);
        }
        mHeight = height > 0 ? height : DEFAULT_HEIGHT;
      }
      else if (PL_strcmp(argv[i], "-r") == 0) {
        i++;
        if (i>=argc || 1!=sscanf(argv[i], "%d", &mRepeatCount))
        {
          PrintHelpInfo(argv);
          exit(-1);
        }
      }
      else if (PL_strcmp(argv[i], "-C") == 0) {
        mCrawler->EnableCrawler();
        mCrawler->SetExitOnDone(PR_TRUE);
        mCrawl = PR_TRUE;
      }
      else if (PL_strcmp(argv[i], "-R") == 0) {
        i++;
        if (i>=argc) {
          PrintHelpInfo(argv);
          exit(-1);
        }
        FILE* fp = fopen(argv[i], "w");
        if (nsnull == fp) {
          fprintf(stderr, "can't create '%s'\n", argv[i]);
          exit(-1);
        }
        mCrawler->SetRecordFile(fp);
      }
      else if (PL_strcmp(argv[i], "-S") == 0) {
        i++;
        if (i>=argc) {
          PrintHelpInfo(argv);
          exit(-1);
        }
        mCrawler->AddSafeDomain(NS_ConvertASCIItoUCS2(argv[i]));
      }
      else if (PL_strcmp(argv[i], "-A") == 0) {
        i++;
        if (i>=argc) {
          PrintHelpInfo(argv);
          exit(-1);
        }
        mCrawler->AddAvoidDomain(NS_ConvertASCIItoUCS2(argv[i]));
      }
      else if (PL_strcmp(argv[i], "-N") == 0) {
        int pages;
        i++;
        if (i>=argc || 1!=sscanf(argv[i], "%d", &pages)) {
          PrintHelpInfo(argv);
          exit(-1);
        }
        mCrawler->SetMaxPages(pages);
      }
      else if (PL_strcmp(argv[i], "-np") == 0) {
        mAllowPlugins = PR_FALSE;
      }
      else if (PL_strcmp(argv[i], "-v") == 0) {
        mCrawler->SetVerbose(PR_TRUE);
      }
      else if (PL_strcmp(argv[i], "-M") == 0) {
        mShowLoadTimes = PR_TRUE;
      }
      else if (PL_strcmp(argv[i], "-?") == 0) {
        PrintHelpInfo(argv);
      }
      else if (PL_strcmp(argv[i], "-B") == 0) {
        int regressionOutput;
        i++;
        if (i>=argc || 1!=sscanf(argv[i], "%d", &regressionOutput)){
          PrintHelpInfo(argv);
          exit(-1);
        }
        mCrawler->RegressionOutput(regressionOutput);
      }
      else if (PL_strcmp(argv[i], "-Prt") == 0) {
        int printTestType;
        i++;
        if (i>=argc || 1!=sscanf(argv[i], "%d", &printTestType)){
          PrintHelpInfo(argv);
          exit(-1);
        }
        mCrawler->SetPrintTest(printTestType);
      }
      else if(PL_strcmp(argv[i], "-regnostyle") == 0) {
        mCrawler->IncludeStyleData(PR_FALSE);
      }
    }
    else
      break;
  }
  if (i < argc) {
    mStartURL.AssignWithConversion(argv[i]);
#if defined(XP_UNIX) || defined(XP_BEOS)
    if (argv[i][0] == '/') {
      mStartURL.Assign(NS_LITERAL_STRING("file:") + mStartURL);
    }
#endif
  }
  return NS_OK;
}

Here is the call graph for this function:

Here is the caller graph for this function:

int nsNativeViewerApp::Run ( void  ) [virtual]

Implements nsViewerApp.

Definition at line 57 of file nsBeOSMain.cpp.

{
       OpenWindow();

       if(mAppShell) {
              nsIAppShell *theAppShell = mAppShell;
              NS_ADDREF(theAppShell);
              mAppShell->Run();
              NS_RELEASE(theAppShell);
       }

       return 0;
}

Here is the call graph for this function:

Here is the caller graph for this function:

Definition at line 208 of file nsViewerApp.cpp.

{
  nsresult rv;

  nsCOMPtr<nsIServiceManager> servManager;
  rv = NS_InitXPCOM3(getter_AddRefs(servManager), nsnull, nsnull,
                     kPStaticModules, kStaticModuleCount);

  nsCOMPtr<nsIComponentRegistrar> registrar = do_QueryInterface(servManager);
  NS_ASSERTION(registrar, "No nsIComponentRegistrar from get service. see dougt");
  rv = registrar->AutoRegister(nsnull);

  // Register our browser window factory
  nsIFactory* bwf;
  NS_NewXPBaseWindowFactory(&bwf);
  registrar->RegisterFactory(kXPBaseWindowCID, 0, 0, bwf);
  NS_RELEASE(bwf);

  // register the cookie manager
  nsCOMPtr<nsICookieService> cookieService = 
           do_GetService(kCookieServiceCID, &rv);
  if (NS_FAILED(rv) || (nsnull == cookieService)) {
#ifdef DEBUG
    printf("Unable to instantiate Cookie Manager\n");
#endif
  }

  return NS_OK;
}

Here is the call graph for this function:

Here is the caller graph for this function:

Definition at line 644 of file nsViewerApp.cpp.

{
  // Create browser window
  // XXX Some piece of code needs to properly hold the reference to this
  // browser window. For the time being the reference is released by the
  // browser event handling code during processing of the NS_DESTROY event...
  nsBrowserWindow* bw = new nsNativeBrowserWindow();
  NS_ENSURE_TRUE(bw, NS_ERROR_FAILURE);
  NS_ADDREF(bw);

  bw->SetApp(this);
  bw->Init(mAppShell, nsRect(0, 0, 620, 400), PRUint32(~0), mAllowPlugins);
  bw->SetTitle(NS_LITERAL_STRING("View Source").get());
  bw->SetVisibility(PR_TRUE);

  bw->GoTo(PromiseFlatString(NS_LITERAL_STRING("view-source:") + aURL).get());

  NS_RELEASE(bw);

  return NS_OK;
}

Here is the call graph for this function:


Member Data Documentation

PRBool nsViewerApp::mAllowPlugins [protected, inherited]

Definition at line 94 of file nsViewerApp.h.

nsIAppShell* nsViewerApp::mAppShell [protected, inherited]

Definition at line 83 of file nsViewerApp.h.

PRBool nsViewerApp::mCrawl [protected, inherited]

Definition at line 88 of file nsViewerApp.h.

nsWebCrawler* nsViewerApp::mCrawler [protected, inherited]

Definition at line 93 of file nsViewerApp.h.

PRInt32 nsViewerApp::mDelay [protected, inherited]

Definition at line 91 of file nsViewerApp.h.

PRBool nsViewerApp::mDoPurify [protected, inherited]

Definition at line 86 of file nsViewerApp.h.

PRInt32 nsViewerApp::mHeight [protected, inherited]

Definition at line 96 of file nsViewerApp.h.

nsString nsViewerApp::mInputFileName [protected, inherited]

Definition at line 89 of file nsViewerApp.h.

PRBool nsViewerApp::mIsInitialized [protected, inherited]

Definition at line 95 of file nsViewerApp.h.

PRBool nsViewerApp::mJustShutdown [protected, inherited]

Definition at line 98 of file nsViewerApp.h.

PRBool nsViewerApp::mLoadTestFromFile [protected, inherited]

Definition at line 87 of file nsViewerApp.h.

PRInt32 nsViewerApp::mNumSamples [protected, inherited]

Definition at line 90 of file nsViewerApp.h.

nsIPrefService* nsViewerApp::mPrefService [protected, inherited]

Definition at line 84 of file nsViewerApp.h.

PRInt32 nsViewerApp::mRepeatCount [protected, inherited]

Definition at line 92 of file nsViewerApp.h.

PRBool nsViewerApp::mShowLoadTimes [protected, inherited]

Definition at line 97 of file nsViewerApp.h.

nsString nsViewerApp::mStartURL [protected, inherited]

Definition at line 85 of file nsViewerApp.h.

PRInt32 nsViewerApp::mWidth [protected, inherited]

Definition at line 96 of file nsViewerApp.h.


The documentation for this class was generated from the following files: