Back to index

lightning-sunbird  0.9+nobinonly
Classes | Defines | Functions | Variables
nsWebCrawler.cpp File Reference
#include "nscore.h"
#include "nsCOMPtr.h"
#include "nsWebCrawler.h"
#include "nsViewerApp.h"
#include "nsIContentViewer.h"
#include "nsIDocumentViewer.h"
#include "nsIDocument.h"
#include "nsIContent.h"
#include "nsIPresShell.h"
#include "nsPresContext.h"
#include "nsIViewManager.h"
#include "nsIFrame.h"
#include "nsIFrameDebug.h"
#include "nsIURL.h"
#include "nsNetUtil.h"
#include "nsITimer.h"
#include "nsIAtom.h"
#include "nsIFrameUtil.h"
#include "nsIComponentManager.h"
#include "nsLayoutCID.h"
#include "nsRect.h"
#include "plhash.h"
#include "nsINameSpaceManager.h"
#include "nsXPIDLString.h"
#include "nsReadableUtils.h"
#include "nsIServiceManager.h"
#include "nsIEventQueueService.h"
#include "nsIEventQueue.h"
#include "prprf.h"
#include "nsIContentViewerFile.h"
#include "nsIDocShell.h"
#include "nsIWebNavigation.h"
#include "nsIWebProgress.h"

Go to the source code of this file.

Classes

class  AtomHashTable
struct  ExitEvent
struct  LoadEvent

Defines

#define BUF_SIZE   1024

Functions

static NS_DEFINE_IID (kFrameUtilCID, NS_FRAME_UTIL_CID)
static PLHashNumber HashKey (nsIAtom *key)
static PRIntn CompareKeys (nsIAtom *key1, nsIAtom *key2)
static PRIntn PR_CALLBACK DestroyEntry (PLHashEntry *he, PRIntn i, void *arg)
static void FreeStrings (nsVoidArray &aArray)
 NS_IMPL_ISUPPORTS2 (nsWebCrawler, nsIWebProgressListener, nsISupportsWeakReference) void nsWebCrawler
static PRBool EndsWith (const nsString &aDomain, const char *aHost, PRInt32 aHostLen)
static PRBool StartsWith (const nsString &s1, const char *s2)
static FILEOpenRegressionFile (const nsString &aBaseName, const nsString &aOutputName)
static NS_DEFINE_IID (kEventQueueServiceCID, NS_EVENTQUEUESERVICE_CID)
static NS_DEFINE_IID (kIEventQueueServiceIID, NS_IEVENTQUEUESERVICE_IID)
static nsresult QueueEvent (PLEvent *aEvent)

Variables

static const unsigned char kLowerLookup [256]

Define Documentation

#define BUF_SIZE   1024

Definition at line 918 of file nsWebCrawler.cpp.


Function Documentation

static PRIntn CompareKeys ( nsIAtom key1,
nsIAtom key2 
) [static]

Definition at line 89 of file nsWebCrawler.cpp.

{
  return key1 == key2;
}

Here is the caller graph for this function:

static PRIntn PR_CALLBACK DestroyEntry ( PLHashEntry he,
PRIntn  i,
void arg 
) [static]

Definition at line 116 of file nsWebCrawler.cpp.

{
  ((nsIAtom*)he->key)->Release();
  return HT_ENUMERATE_NEXT;
}

Here is the caller graph for this function:

static PRBool EndsWith ( const nsString aDomain,
const char *  aHost,
PRInt32  aHostLen 
) [static]

Definition at line 653 of file nsWebCrawler.cpp.

{
  PRInt32 slen = aDomain.Length();
  if (slen < aHostLen) {
    return PR_FALSE;
  }
  const PRUnichar* uc = aDomain.get();
  uc += slen - aHostLen;
  const PRUnichar* end = uc + aHostLen;
  while (uc < end) {
    unsigned char uch = (unsigned char) ((*uc++) & 0xff);
    unsigned char ch = (unsigned char) ((*aHost++) & 0xff);
    if (kLowerLookup[uch] != kLowerLookup[ch]) {
      return PR_FALSE;
    }
  }
  return PR_TRUE;
}

Here is the call graph for this function:

Here is the caller graph for this function:

static void FreeStrings ( nsVoidArray aArray) [static]

Definition at line 211 of file nsWebCrawler.cpp.

{
  PRInt32 i, n = aArray.Count();
  for (i = 0; i < n; i++) {
    nsString* s = (nsString*) aArray.ElementAt(i);
    delete s;
  }
  aArray.Clear();
}

Here is the caller graph for this function:

static PLHashNumber HashKey ( nsIAtom key) [static]

Definition at line 83 of file nsWebCrawler.cpp.

{
  return NS_PTR_TO_INT32(key);
}

Here is the caller graph for this function:

static NS_DEFINE_IID ( kFrameUtilCID  ,
NS_FRAME_UTIL_CID   
) [static]
static NS_DEFINE_IID ( kIEventQueueServiceIID  ,
NS_IEVENTQUEUESERVICE_IID   
) [static]

Definition at line 229 of file nsWebCrawler.cpp.

{
#ifdef NS_DEBUG
  nsCOMPtr<nsIDocShell> docshell;
  mBrowser->GetDocShell(*getter_AddRefs(docshell));
  if (! docshell)
    return;

  if (mOutputDir.Length() > 0) {
    nsCOMPtr<nsIPresShell> shell = GetPresShell(docshell);
    if (!shell) return;
    if ( mPrinterTestType > 0 ) {
      nsCOMPtr <nsIContentViewer> viewer;
      docshell->GetContentViewer(getter_AddRefs(viewer));

      if (viewer){
        nsCOMPtr<nsIContentViewerFile> viewerFile = do_QueryInterface(viewer);
        if (viewerFile) {
          nsAutoString regressionFileName;
          FILE *fp = GetOutputFile(mLastURL, regressionFileName);

          switch (mPrinterTestType) {
          case 1:
            // dump print data to a file for regression testing
            viewerFile->Print(PR_TRUE, fp, nsnull);
            break;
          case 2:
            // visual printing tests, all go to the printer, no printer dialog
            viewerFile->Print(PR_TRUE, nsnull, nsnull);
            break;
          case 3:
            // visual printing tests, all go to the printer, with a printer dialog
            viewerFile->Print(PR_FALSE, nsnull, nsnull);
            break;
          default:
            break;
          }
          fclose(fp);
          if( mPrinterTestType == 1) {
            if (mRegressing) {
              PerformRegressionTest(regressionFileName);
            }
            else {
              fputs(NS_LossyConvertUCS2toASCII(regressionFileName).get(),
                    stdout);
              printf(" - being written\n");
            }
          }
        }
      }
    } 
    else {
      nsIFrame* root = shell->GetRootFrame();
      if (nsnull != root) {
        nsPresContext *presContext = shell->GetPresContext();
        
        if (mOutputDir.Length() > 0) {
          nsAutoString regressionFileName;
          FILE *fp = GetOutputFile(mLastURL, regressionFileName);
          if (fp) {
            nsIFrameDebug* fdbg;
            if (NS_SUCCEEDED(root->QueryInterface(NS_GET_IID(nsIFrameDebug), (void**) &fdbg))) {
              fdbg->DumpRegressionData(presContext, fp, 0, mIncludeStyleInfo);
            }
            fclose(fp);
            if (mRegressing) {
              PerformRegressionTest(regressionFileName);
            }
            else {
              fputs(NS_LossyConvertUCS2toASCII(regressionFileName).get(),
                    stdout);
              printf(" - being written\n");
            }
          }
          else {
            nsCAutoString file;
            (void)mLastURL->GetPath(file);
            printf("could not open output file for %s\n", file.get());
          }
        }
        else {
          nsIFrameDebug* fdbg;
          if (NS_SUCCEEDED(root->QueryInterface(NS_GET_IID(nsIFrameDebug), (void**) &fdbg))) {
            fdbg->DumpRegressionData(presContext, stdout, 0, mIncludeStyleInfo);
          }
        }
      }
    }
  }
#endif
}

Here is the call graph for this function:

static FILE* OpenRegressionFile ( const nsString aBaseName,
const nsString aOutputName 
) [static]

Definition at line 903 of file nsWebCrawler.cpp.

{
  nsAutoString a;
  a.Append(aBaseName);
  a.AppendLiteral("/");
  a.Append(aOutputName);
  char* fn = ToNewCString(a);
  FILE* fp = fopen(fn, "r");
  if (!fp) {
    printf("Unable to open regression data file %s\n", fn);
  }
  delete[] fn;
  return fp;
}

Here is the call graph for this function:

Here is the caller graph for this function:

static nsresult QueueEvent ( PLEvent aEvent) [static]

Definition at line 959 of file nsWebCrawler.cpp.

{
  nsresult rv;
  nsCOMPtr<nsIEventQueueService> eqs =
      do_GetService(kEventQueueServiceCID, &rv);
  if (NS_FAILED(rv)) {
    return rv;
  }

  if (eqs) {
    nsCOMPtr<nsIEventQueue> eq;
    rv = eqs->GetThreadEventQueue(NS_CURRENT_THREAD, getter_AddRefs(eq));
    if (eq) {
      eq->PostEvent(aEvent);
    }
  }

  return rv;
}

Here is the call graph for this function:

Here is the caller graph for this function:

static PRBool StartsWith ( const nsString s1,
const char *  s2 
) [static]

Definition at line 673 of file nsWebCrawler.cpp.

{
  PRInt32 s1len = s1.Length();
  PRInt32 s2len = strlen(s2);
  if (s1len < s2len) {
    return PR_FALSE;
  }
  const PRUnichar* uc = s1.get();
  const PRUnichar* end = uc + s2len;
  while (uc < end) {
    unsigned char uch = (unsigned char) ((*uc++) & 0xff);
    unsigned char ch = (unsigned char) ((*s2++) & 0xff);
    if (kLowerLookup[uch] != kLowerLookup[ch]) {
      return PR_FALSE;
    }
  }
  return PR_TRUE;
}

Here is the call graph for this function:

Here is the caller graph for this function:


Variable Documentation

const unsigned char kLowerLookup[256] [static]
Initial value:
 {
  0,1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,
  16,17,18,19,20,21,22,23,24,25,26,27,28,29,30,31,
  32,33,34,35,36,37,38,39,40,41,42,43,44,45,46,47,
  48,49,50,51,52,53,54,55,56,57,58,59,60,61,62,63,
  64,
    97,98,99,100,101,102,103,104,105,106,107,108,109,
    110,111,112,113,114,115,116,117,118,119,120,121,122,

   91, 92, 93, 94, 95, 96, 97, 98, 99,100,101,102,103,104,105,106,107,108,109,110,111,
  112,113,114,115,116,117,118,119,120,121,122,123,124,125,126,127,

  128,129,130,131,132,133,134,135,136,137,138,139,140,141,142,143,
  144,145,146,147,148,149,150,151,152,153,154,155,156,157,158,159,
  160,161,162,163,164,165,166,167,168,169,170,171,172,173,174,175,
  176,177,178,179,180,181,182,183,184,185,186,187,188,189,190,191,
  192,193,194,195,196,197,198,199,200,201,202,203,204,205,206,207,
  208,209,210,211,212,213,214,215,216,217,218,219,220,221,222,223,
  224,225,226,227,228,229,230,231,232,233,234,235,236,237,238,239,
  240,241,242,243,244,245,246,247,248,249,250,251,252,253,254,255
}

Definition at line 630 of file nsWebCrawler.cpp.