Back to index

lightning-sunbird  0.9+nobinonly
Classes | Functions | Variables
nsDebugRobot.cpp File Reference
#include "nsIRobotSink.h"
#include "nsIRobotSinkObserver.h"
#include "nsIParser.h"
#include "nsIDocShell.h"
#include "nsIWebNavigation.h"
#include "nsIWebProgress.h"
#include "nsIWebProgressListener.h"
#include "nsWeakReference.h"
#include "nsVoidArray.h"
#include "nsString.h"
#include "nsReadableUtils.h"
#include "nsIURL.h"
#include "nsIServiceManager.h"
#include "nsIIOService.h"
#include "nsNetCID.h"
#include "nsIComponentManager.h"
#include "nsParserCIID.h"
#include "nsIInterfaceRequestor.h"
#include "nsIInterfaceRequestorUtils.h"

Go to the source code of this file.

Classes

class  RobotSinkObserver
class  CStreamListener

Functions

static NS_DEFINE_CID (kIOServiceCID, NS_IOSERVICE_CID)
NS_EXPORT void SetVerificationDirectory (char *verify_dir)
 NS_IMPL_ISUPPORTS2 (CStreamListener, nsIWebProgressListener, nsISupportsWeakReference) extern"C"NS_EXPORT void DumpVectorRecord(void)
NS_EXPORT int DebugRobot (nsVoidArray *workList, nsIDocShell *docShell, int iMaxLoads, char *verify_dir, void(*yieldProc)(const char *))

Variables

static nsVoidArrayg_workList
static nsVoidArrayg_duplicateList
static int g_iProcessed
static int g_iMaxProcess = 5000
static PRBool g_bHitTop
static PRBool g_bReadyForNextUrl

Function Documentation

NS_EXPORT int DebugRobot ( nsVoidArray workList,
nsIDocShell docShell,
int  iMaxLoads,
char *  verify_dir,
void(*)(const char *)  yieldProc 
)

Definition at line 223 of file nsDebugRobot.cpp.

{
  int iCount = 1;
  CStreamListener * pl = new CStreamListener; 
  NS_ADDREF(pl);

  if (nsnull==workList)
     return -1;
  g_iMaxProcess = iMaxLoads;
  g_iProcessed = 0;
  g_bHitTop = PR_FALSE;
  g_duplicateList = new nsVoidArray();
  RobotSinkObserver* myObserver = new RobotSinkObserver();
  NS_ADDREF(myObserver);
  g_workList = workList;

  for (;;) {
    PRInt32 n = g_workList->Count();
    if (0 == n) {
      break;
    }
    nsString* urlName = (nsString*) g_workList->ElementAt(n - 1);
    g_workList->RemoveElementAt(n - 1);

    // Create url
    nsIURI* url;
    nsresult rv;
    nsCOMPtr<nsIIOService> service(do_GetService(kIOServiceCID, &rv));
    if (NS_FAILED(rv)) return rv;

    nsIURI *uri = nsnull;
    NS_ConvertUCS2toUTF8 uriStr(*urlName);
    rv = service->NewURI(uriStr, nsnull, nsnull, &uri);
    if (NS_FAILED(rv)) return rv;

    rv = uri->QueryInterface(NS_GET_IID(nsIURI), (void**)&url);
    NS_RELEASE(uri);
    if (NS_OK != rv) {
      printf("invalid URL: '");
      fputs(uriStr.get(), stdout);
      printf("'\n");
      NS_RELEASE(myObserver);
      return -1;
    }

    char str_num[25];
    sprintf (str_num,"%d",iCount++);
    fputs ("Robot: parsing(",stdout);
    fputs (str_num,stdout);
    fputs (") ",stdout);
    fputs (NS_LossyConvertUCS2toASCII(*urlName).get(),stdout);
    fputs ("...",stdout);

    delete urlName;

    nsIParser* parser;

    static NS_DEFINE_IID(kCParserIID, NS_IPARSER_IID);
    static NS_DEFINE_CID(kCParserCID, NS_PARSER_CID);

    rv = CallCreateInstance(kCParserCID, &parser);
    if (NS_FAILED(rv)) {
      printf("can't make parser\n");
      NS_RELEASE(myObserver);
      return -1;
    }

    nsIRobotSink* sink;
    rv = NS_NewRobotSink(&sink);
    if (NS_OK != rv) {
      printf("can't make parser\n");
      NS_RELEASE(myObserver);
      return -1;
    }
    sink->Init(url);
    sink->AddObserver(myObserver);

    parser->SetContentSink(sink);
    g_bReadyForNextUrl = PR_FALSE;  

    parser->Parse(url, nsnull,PR_TRUE);/* XXX hook up stream listener here! */
    while (!g_bReadyForNextUrl) {
      if (yieldProc != NULL) {
        nsCAutoString spec;
        (void)url->GetSpec(spec);
        (*yieldProc)(spec.get());
      }
    }
    g_bReadyForNextUrl = PR_FALSE;
    if (docShell) {
      nsCOMPtr<nsIWebProgress> progress(do_GetInterface(docShell, &rv));
      if (NS_FAILED(rv)) return rv;

      (void) progress->AddProgressListener(pl, nsIWebProgress::NOTIFY_STATE_DOCUMENT);

      nsCAutoString spec;
      (void)url->GetSpec(spec);
      NS_ConvertUTF8toUCS2 theSpec(spec);
      nsCOMPtr<nsIWebNavigation> webNav(do_QueryInterface(docShell));
      webNav->LoadURI(theSpec.get(),
                      nsIWebNavigation::LOAD_FLAGS_NONE,
                      nsnull,
                      nsnull,
                      nsnull);/* XXX hook up stream listener here! */
      while (!g_bReadyForNextUrl) {
        if (yieldProc != NULL) {
          (void)url->GetSpec(spec);
          (*yieldProc)(spec.get());
        }
      }
    }  

    NS_RELEASE(sink);
    NS_RELEASE(parser);
    NS_RELEASE(url);
  }

  fputs ("Robot completed.\n", stdout);

  NS_RELEASE(pl);
  NS_RELEASE(myObserver);

  return 0;
}

Here is the call graph for this function:

Here is the caller graph for this function:

static NS_DEFINE_CID ( kIOServiceCID  ,
NS_IOSERVICE_CID   
) [static]
NS_EXPORT void SetVerificationDirectory ( char *  verify_dir)

Variable Documentation

PRBool g_bHitTop [static]

Definition at line 80 of file nsDebugRobot.cpp.

Definition at line 81 of file nsDebugRobot.cpp.

Definition at line 77 of file nsDebugRobot.cpp.

int g_iMaxProcess = 5000 [static]

Definition at line 79 of file nsDebugRobot.cpp.

int g_iProcessed [static]

Definition at line 78 of file nsDebugRobot.cpp.

Definition at line 76 of file nsDebugRobot.cpp.