static bool LoadLibxul(const char *aXPCOMPath) { nsresult rv; XPCOMGlueEnablePreload(); rv = XPCOMGlueStartup(aXPCOMPath); NS_ENSURE_SUCCESS(rv, false); rv = XPCOMGlueLoadXULFunctions(kXULFuncs); NS_ENSURE_SUCCESS(rv, false); return true; }
static bool GeckoPreLoader(const char* execPath) { nsresult rv = XPCOMGlueStartup(execPath); if (NS_FAILED(rv)) { Output("Couldn't load XPCOM.\n"); return false; } rv = XPCOMGlueLoadXULFunctions(kXULFuncs); if (NS_FAILED(rv)) { Output("Couldn't load XRE functions.\n"); return false; } return true; }
bool GRELoadAndLaunch(const char* firefoxDir, bool silentFail) { char xpcomDllPath[MAXPATHLEN]; snprintf(xpcomDllPath, MAXPATHLEN, "%s/%s", firefoxDir, XPCOM_DLL); if (silentFail && access(xpcomDllPath, F_OK) != 0) return false; if (NS_FAILED(XPCOMGlueStartup(xpcomDllPath))) { ErrorDialog("Couldn't load the XPCOM library"); return false; } if (NS_FAILED(XPCOMGlueLoadXULFunctions(kXULFuncs))) { ErrorDialog("Couldn't load libxul"); return false; } // NOTE: The GRE has successfully loaded, so we can use XPCOM now { // Scope for any XPCOM stuff we create ScopedLogging log; // Get the path to the runtime char rtPath[MAXPATHLEN]; snprintf(rtPath, MAXPATHLEN, "%s/%s", firefoxDir, kWEBAPPRT_PATH); // Get the path to the runtime's INI file char rtIniPath[MAXPATHLEN]; snprintf(rtIniPath, MAXPATHLEN, "%s/%s", rtPath, kWEBAPPRT_INI); // Load the runtime's INI from its path nsCOMPtr<nsIFile> rtINI; if (NS_FAILED(XRE_GetFileFromPath(rtIniPath, getter_AddRefs(rtINI)))) { ErrorDialog("Couldn't load the runtime INI"); return false; } bool exists; nsresult rv = rtINI->Exists(&exists); if (NS_FAILED(rv) || !exists) { ErrorDialog("The runtime INI doesn't exist"); return false; } nsXREAppData *webShellAppData; if (NS_FAILED(XRE_CreateAppData(rtINI, &webShellAppData))) { ErrorDialog("Couldn't read WebappRT application.ini"); return false; } if (!isProfileOverridden) { SetAllocatedString(webShellAppData->profile, profile); // nsXREAppData::name is used for the class name part of the WM_CLASS // property. Set it so that the DE can match our window to the correct // launcher. char programClass[MAXPATHLEN]; snprintf(programClass, MAXPATHLEN, "owa-%s", profile); SetAllocatedString(webShellAppData->name, programClass); } nsCOMPtr<nsIFile> directory; if (NS_FAILED(XRE_GetFileFromPath(rtPath, getter_AddRefs(directory)))) { ErrorDialog("Couldn't open runtime directory"); return false; } nsCOMPtr<nsIFile> xreDir; if (NS_FAILED(XRE_GetFileFromPath(firefoxDir, getter_AddRefs(xreDir)))) { ErrorDialog("Couldn't open XRE directory"); return false; } xreDir.forget(&webShellAppData->xreDirectory); NS_IF_RELEASE(webShellAppData->directory); directory.forget(&webShellAppData->directory); XRE_main(*pargc, *pargv, webShellAppData, 0); XRE_FreeAppData(webShellAppData); } return true; }
int main(int argc, char* argv[]) { char exePath[MAXPATHLEN]; nsresult rv = mozilla::BinaryPath::Get(argv[0], exePath); if (NS_FAILED(rv)) { Output("Couldn't calculate the application directory.\n"); return 255; } char *lastSlash = strrchr(exePath, XPCOM_FILE_PATH_SEPARATOR[0]); if (!lastSlash || (lastSlash - exePath > MAXPATHLEN - sizeof(XPCOM_DLL) - 1)) return 255; strcpy(++lastSlash, XPCOM_DLL); int gotCounters; #if defined(XP_UNIX) struct rusage initialRUsage; gotCounters = !getrusage(RUSAGE_SELF, &initialRUsage); #elif defined(XP_WIN) // GetProcessIoCounters().ReadOperationCount seems to have little to // do with actual read operations. It reports 0 or 1 at this stage // in the program. Luckily 1 coincides with when prefetch is // enabled. If Windows prefetch didn't happen we can do our own // faster dll preloading. IO_COUNTERS ioCounters; gotCounters = GetProcessIoCounters(GetCurrentProcess(), &ioCounters); if (gotCounters && !ioCounters.ReadOperationCount) #endif { XPCOMGlueEnablePreload(); } rv = XPCOMGlueStartup(exePath); if (NS_FAILED(rv)) { Output("Couldn't load XPCOM.\n"); return 255; } // Reset exePath so that it is the directory name and not the xpcom dll name *lastSlash = 0; rv = XPCOMGlueLoadXULFunctions(kXULFuncs); if (NS_FAILED(rv)) { Output("Couldn't load XRE functions.\n"); return 255; } #ifdef XRE_HAS_DLL_BLOCKLIST XRE_SetupDllBlocklist(); #endif if (gotCounters) { #if defined(XP_WIN) XRE_TelemetryAccumulate(mozilla::Telemetry::EARLY_GLUESTARTUP_READ_OPS, int(ioCounters.ReadOperationCount)); XRE_TelemetryAccumulate(mozilla::Telemetry::EARLY_GLUESTARTUP_READ_TRANSFER, int(ioCounters.ReadTransferCount / 1024)); IO_COUNTERS newIoCounters; if (GetProcessIoCounters(GetCurrentProcess(), &newIoCounters)) { XRE_TelemetryAccumulate(mozilla::Telemetry::GLUESTARTUP_READ_OPS, int(newIoCounters.ReadOperationCount - ioCounters.ReadOperationCount)); XRE_TelemetryAccumulate(mozilla::Telemetry::GLUESTARTUP_READ_TRANSFER, int((newIoCounters.ReadTransferCount - ioCounters.ReadTransferCount) / 1024)); } #elif defined(XP_UNIX) XRE_TelemetryAccumulate(mozilla::Telemetry::EARLY_GLUESTARTUP_HARD_FAULTS, int(initialRUsage.ru_majflt)); struct rusage newRUsage; if (!getrusage(RUSAGE_SELF, &newRUsage)) { XRE_TelemetryAccumulate(mozilla::Telemetry::GLUESTARTUP_HARD_FAULTS, int(newRUsage.ru_majflt - initialRUsage.ru_majflt)); } #endif } int result; { ScopedLogging log; result = do_main(argc, argv); } XPCOMGlueShutdown(); return result; }
int main(int argc, char **argv) { nsresult rv; char *lastSlash; char iniPath[MAXPATHLEN]; char greDir[MAXPATHLEN]; bool greFound = false; CFBundleRef appBundle = CFBundleGetMainBundle(); if (!appBundle) return 1; CFURLRef resourcesURL = CFBundleCopyResourcesDirectoryURL(appBundle); if (!resourcesURL) return 1; CFURLRef absResourcesURL = CFURLCopyAbsoluteURL(resourcesURL); CFRelease(resourcesURL); if (!absResourcesURL) return 1; CFURLRef iniFileURL = CFURLCreateCopyAppendingPathComponent(kCFAllocatorDefault, absResourcesURL, CFSTR("application.ini"), false); CFRelease(absResourcesURL); if (!iniFileURL) return 1; CFStringRef iniPathStr = CFURLCopyFileSystemPath(iniFileURL, kCFURLPOSIXPathStyle); CFRelease(iniFileURL); if (!iniPathStr) return 1; CFStringGetCString(iniPathStr, iniPath, sizeof(iniPath), kCFStringEncodingUTF8); CFRelease(iniPathStr); printf("iniPath = %s\n", iniPath); //////////////////////////////////////// if (!getExePath(greDir)) { return 1; } /*if (!getFrameworkPath(greDir)) { return 1; }*/ /*if (realpath(tmpPath, greDir)) { greFound = true; }*/ printf("greDir = %s\n", greDir); if (access(greDir, R_OK | X_OK) == 0) greFound = true; if (!greFound) { printf("Could not find the Mozilla runtime.\n"); return 1; } rv = XPCOMGlueStartup(greDir); if (NS_FAILED(rv)) { printf("Couldn't load XPCOM.\n"); return 1; } printf("Glue startup OK.\n"); ///////////////////////////////////////////////////// static const nsDynamicFunctionLoad kXULFuncs[] = { { "XRE_CreateAppData", (NSFuncPtr*) &XRE_CreateAppData }, { "XRE_FreeAppData", (NSFuncPtr*) &XRE_FreeAppData }, { "XRE_main", (NSFuncPtr*) &XRE_main }, { nullptr, nullptr } }; rv = XPCOMGlueLoadXULFunctions(kXULFuncs); if (NS_FAILED(rv)) { printf("Couldn't load XRE functions.\n"); return 1; } NS_LogInit(); int retval; nsXREAppData *pAppData = NULL; { nsCOMPtr<nsIFile> iniFile; // nsIFile *pIniFile; rv = NS_NewNativeLocalFile(nsDependentCString(iniPath), PR_FALSE, getter_AddRefs(iniFile)); //&pIniFile); //NS_ADDREF(pIniFile); if (NS_FAILED(rv)) { printf("Couldn't find application.ini file.\n"); return 1; } rv = XRE_CreateAppData(iniFile, &pAppData); //rv = XRE_CreateAppData(pIniFile, &pAppData); if (NS_FAILED(rv)) { printf("Error: couldn't parse application.ini.\n"); return 1; } } NS_ASSERTION(pAppData->directory, "Failed to get app directory."); { nsAutoString path; pAppData->directory->GetPath(path); nsAutoCString nsstr; ::CopyUTF16toUTF8(path, nsstr); printf("appData.directory=%s\n", nsstr.get()); } if (!pAppData->xreDirectory) { char xreDir[MAXPATHLEN]; if (!getFrameworkPath(xreDir)) return 1; rv = NS_NewNativeLocalFile(nsDependentCString(xreDir), PR_FALSE, &pAppData->xreDirectory); } printf("### ENTERING XRE_MAIN ###\n"); retval = XRE_main(argc, argv, pAppData, 0); printf("### LEAVING XRE_MAIN ###\n"); NS_LogTerm(); return retval; }
int main(int argc, char* argv[]) { PRTime start = _PR_Now(); char exePath[MAXPATHLEN]; #ifdef XP_MACOSX TriggerQuirks(); #endif nsresult rv = mozilla::BinaryPath::Get(argv[0], exePath); if (NS_FAILED(rv)) { Output("Couldn't calculate the application directory.\n"); return 255; } char *lastSlash = strrchr(exePath, XPCOM_FILE_PATH_SEPARATOR[0]); if (!lastSlash || (size_t(lastSlash - exePath) > MAXPATHLEN - sizeof(XPCOM_DLL) - 1)) return 255; strcpy(++lastSlash, XPCOM_DLL); int gotCounters; #if defined(XP_UNIX) struct rusage initialRUsage; gotCounters = !getrusage(RUSAGE_SELF, &initialRUsage); #elif defined(XP_WIN) IO_COUNTERS ioCounters; gotCounters = GetProcessIoCounters(GetCurrentProcess(), &ioCounters); #endif // We do this because of data in bug 771745 XPCOMGlueEnablePreload(); rv = XPCOMGlueStartup(exePath); if (NS_FAILED(rv)) { Output("Couldn't load XPCOM.\n"); return 255; } // Reset exePath so that it is the directory name and not the xpcom dll name *lastSlash = 0; rv = XPCOMGlueLoadXULFunctions(kXULFuncs); if (NS_FAILED(rv)) { Output("Couldn't load XRE functions.\n"); return 255; } XRE_StartupTimelineRecord(mozilla::StartupTimeline::START, start); #ifdef XRE_HAS_DLL_BLOCKLIST XRE_SetupDllBlocklist(); #endif if (gotCounters) { #if defined(XP_WIN) XRE_TelemetryAccumulate(mozilla::Telemetry::EARLY_GLUESTARTUP_READ_OPS, int(ioCounters.ReadOperationCount)); XRE_TelemetryAccumulate(mozilla::Telemetry::EARLY_GLUESTARTUP_READ_TRANSFER, int(ioCounters.ReadTransferCount / 1024)); IO_COUNTERS newIoCounters; if (GetProcessIoCounters(GetCurrentProcess(), &newIoCounters)) { XRE_TelemetryAccumulate(mozilla::Telemetry::GLUESTARTUP_READ_OPS, int(newIoCounters.ReadOperationCount - ioCounters.ReadOperationCount)); XRE_TelemetryAccumulate(mozilla::Telemetry::GLUESTARTUP_READ_TRANSFER, int((newIoCounters.ReadTransferCount - ioCounters.ReadTransferCount) / 1024)); } #elif defined(XP_UNIX) XRE_TelemetryAccumulate(mozilla::Telemetry::EARLY_GLUESTARTUP_HARD_FAULTS, int(initialRUsage.ru_majflt)); struct rusage newRUsage; if (!getrusage(RUSAGE_SELF, &newRUsage)) { XRE_TelemetryAccumulate(mozilla::Telemetry::GLUESTARTUP_HARD_FAULTS, int(newRUsage.ru_majflt - initialRUsage.ru_majflt)); } #endif } int result; { ScopedLogging log; result = do_main(argc, argv); } XPCOMGlueShutdown(); return result; }
int main(int argc, char* argv[]) { char exePath[MAXPATHLEN]; #ifdef MOZ_WIDGET_GONK // The first call of ProcessState::self() (per process) will register into // binder driver by current thread info, so the main thread is a best one to // do registration because it never leaves. android::sp<android::ProcessState> proc(android::ProcessState::self()); #endif nsresult rv = mozilla::BinaryPath::Get(argv[0], exePath); if (NS_FAILED(rv)) { Output("Couldn't calculate the application directory.\n"); return 255; } char *lastSlash = strrchr(exePath, XPCOM_FILE_PATH_SEPARATOR[0]); if (!lastSlash || ((lastSlash - exePath) + sizeof(XPCOM_DLL) + 1 > MAXPATHLEN)) return 255; strcpy(++lastSlash, XPCOM_DLL); #if defined(XP_UNIX) // If the b2g app is launched from adb shell, then the shell will wind // up being the process group controller. This means that we can't send // signals to the process group (useful for profiling). // We ignore the return value since setsid() fails if we're already the // process group controller (the normal situation). (void)setsid(); #endif int gotCounters; #if defined(XP_UNIX) struct rusage initialRUsage; gotCounters = !getrusage(RUSAGE_SELF, &initialRUsage); #elif defined(XP_WIN) IO_COUNTERS ioCounters; gotCounters = GetProcessIoCounters(GetCurrentProcess(), &ioCounters); #endif // We do this because of data in bug 771745 XPCOMGlueEnablePreload(); rv = XPCOMGlueStartup(exePath); if (NS_FAILED(rv)) { Output("Couldn't load XPCOM.\n"); return 255; } // Reset exePath so that it is the directory name and not the xpcom dll name *lastSlash = 0; rv = XPCOMGlueLoadXULFunctions(kXULFuncs); if (NS_FAILED(rv)) { Output("Couldn't load XRE functions.\n"); return 255; } #ifdef XRE_HAS_DLL_BLOCKLIST XRE_SetupDllBlocklist(); #endif if (gotCounters) { #if defined(XP_WIN) XRE_TelemetryAccumulate(mozilla::Telemetry::EARLY_GLUESTARTUP_READ_OPS, int(ioCounters.ReadOperationCount)); XRE_TelemetryAccumulate(mozilla::Telemetry::EARLY_GLUESTARTUP_READ_TRANSFER, int(ioCounters.ReadTransferCount / 1024)); IO_COUNTERS newIoCounters; if (GetProcessIoCounters(GetCurrentProcess(), &newIoCounters)) { XRE_TelemetryAccumulate(mozilla::Telemetry::GLUESTARTUP_READ_OPS, int(newIoCounters.ReadOperationCount - ioCounters.ReadOperationCount)); XRE_TelemetryAccumulate(mozilla::Telemetry::GLUESTARTUP_READ_TRANSFER, int((newIoCounters.ReadTransferCount - ioCounters.ReadTransferCount) / 1024)); } #elif defined(XP_UNIX) XRE_TelemetryAccumulate(mozilla::Telemetry::EARLY_GLUESTARTUP_HARD_FAULTS, int(initialRUsage.ru_majflt)); struct rusage newRUsage; if (!getrusage(RUSAGE_SELF, &newRUsage)) { XRE_TelemetryAccumulate(mozilla::Telemetry::GLUESTARTUP_HARD_FAULTS, int(newRUsage.ru_majflt - initialRUsage.ru_majflt)); } #endif } int result; { ScopedLogging log; result = do_main(argc, argv); } XPCOMGlueShutdown(); return result; }
int main(int argc, _CONST char* argv[]) { #ifndef MOZ_B2G_LOADER char exePath[MAXPATHLEN]; #endif #ifdef MOZ_WIDGET_GONK // This creates a ThreadPool for binder ipc. A ThreadPool is necessary to // receive binder calls, though not necessary to send binder calls. // ProcessState::Self() also needs to be called once on the main thread to // register the main thread with the binder driver. android::ProcessState::self()->startThreadPool(); #endif nsresult rv; #ifndef MOZ_B2G_LOADER rv = mozilla::BinaryPath::Get(argv[0], exePath); if (NS_FAILED(rv)) { Output("Couldn't calculate the application directory.\n"); return 255; } char *lastSlash = strrchr(exePath, XPCOM_FILE_PATH_SEPARATOR[0]); if (!lastSlash || ((lastSlash - exePath) + sizeof(XPCOM_DLL) + 1 > MAXPATHLEN)) return 255; strcpy(++lastSlash, XPCOM_DLL); #endif // MOZ_B2G_LOADER #if defined(XP_UNIX) // If the b2g app is launched from adb shell, then the shell will wind // up being the process group controller. This means that we can't send // signals to the process group (useful for profiling). // We ignore the return value since setsid() fails if we're already the // process group controller (the normal situation). (void)setsid(); #endif int gotCounters; #if defined(XP_UNIX) struct rusage initialRUsage; gotCounters = !getrusage(RUSAGE_SELF, &initialRUsage); #elif defined(XP_WIN) IO_COUNTERS ioCounters; gotCounters = GetProcessIoCounters(GetCurrentProcess(), &ioCounters); #else #error "Unknown platform" // having this here keeps cppcheck happy #endif #ifdef HAS_DLL_BLOCKLIST DllBlocklist_Initialize(); #endif // B2G loader has already initialized Gecko so we can't initialize // it again here. #ifndef MOZ_B2G_LOADER // We do this because of data in bug 771745 XPCOMGlueEnablePreload(); rv = XPCOMGlueStartup(exePath); if (NS_FAILED(rv)) { Output("Couldn't load XPCOM.\n"); return 255; } // Reset exePath so that it is the directory name and not the xpcom dll name *lastSlash = 0; #endif // MOZ_B2G_LOADER rv = XPCOMGlueLoadXULFunctions(kXULFuncs); if (NS_FAILED(rv)) { Output("Couldn't load XRE functions.\n"); return 255; } if (gotCounters) { #if defined(XP_WIN) XRE_TelemetryAccumulate(mozilla::Telemetry::EARLY_GLUESTARTUP_READ_OPS, int(ioCounters.ReadOperationCount)); XRE_TelemetryAccumulate(mozilla::Telemetry::EARLY_GLUESTARTUP_READ_TRANSFER, int(ioCounters.ReadTransferCount / 1024)); IO_COUNTERS newIoCounters; if (GetProcessIoCounters(GetCurrentProcess(), &newIoCounters)) { XRE_TelemetryAccumulate(mozilla::Telemetry::GLUESTARTUP_READ_OPS, int(newIoCounters.ReadOperationCount - ioCounters.ReadOperationCount)); XRE_TelemetryAccumulate(mozilla::Telemetry::GLUESTARTUP_READ_TRANSFER, int((newIoCounters.ReadTransferCount - ioCounters.ReadTransferCount) / 1024)); } #elif defined(XP_UNIX) XRE_TelemetryAccumulate(mozilla::Telemetry::EARLY_GLUESTARTUP_HARD_FAULTS, int(initialRUsage.ru_majflt)); struct rusage newRUsage; if (!getrusage(RUSAGE_SELF, &newRUsage)) { XRE_TelemetryAccumulate(mozilla::Telemetry::GLUESTARTUP_HARD_FAULTS, int(newRUsage.ru_majflt - initialRUsage.ru_majflt)); } #else #error "Unknown platform" // having this here keeps cppcheck happy #endif } int result; { ScopedLogging log; char **_argv; /* * Duplicate argument vector to conform non-const argv of * do_main() since XRE_main() is very stupid with non-const argv. */ _argv = new char *[argc + 1]; for (int i = 0; i < argc; i++) { size_t len = strlen(argv[i]) + 1; _argv[i] = new char[len]; MOZ_ASSERT(_argv[i] != nullptr); memcpy(_argv[i], argv[i], len); } _argv[argc] = nullptr; result = do_main(argc, _argv); for (int i = 0; i < argc; i++) { delete[] _argv[i]; } delete[] _argv; } return result; }
int main(int argc, char** argv) { GtkWidget *window=NULL; GtkWidget *vbox=NULL; nsCOMPtr<nsIServiceManager> servMan; nsCOMPtr<nsILocalFile> libxul; nsIWebNavigation *webNavigation; int cid=0; std::string lstStr(""); int mozSet=0; std::string xulPath(XUL_PATH); std::string xulrunPath(XUL_BIN); std::string soapServer; int maxDoc=20; if(argc<2) { usage(); return 0; } bool isCraw=true; int opt; while((opt = getopt(argc, argv, "n:i:c:l:r:t:s:b:S:CG")) != -1) { switch(opt) { case 'C': isCraw=true; break; case 'G': isCraw=false; break; case 'c': cid=atoi(optarg); break; case 'n': maxDoc=atoi(optarg); break; case 'l': lstStr=std::string(optarg); break; case 'r': mozSet=atoi(optarg); break; case 's': xulPath=std::string(optarg); break; case 'S': soapServer=std::string(optarg); break; case 'b': xulrunPath=std::string(optarg); break; default: usage(); } } if(lstStr.length()==0||lstStr.length()==0) { usage(); } nsDynamicFunctionLoad nsFuncs[] = { {"XRE_InitEmbedding", (NSFuncPtr*)&XRE_InitEmbedding}, {"XRE_TermEmbedding", (NSFuncPtr*) &XRE_TermEmbedding}, {0, 0} }; nsresult rv; //create native window gtk_init (&argc, &argv); window = gtk_window_new(GTK_WINDOW_TOPLEVEL); GTKEmbedGlueStartup(); GTKEmbedGlueStartupInternal(); gtk_widget_set_usize(window, 1280,1024); vbox = gtk_vbox_new(TRUE, 0); gtk_container_add(GTK_CONTAINER(window), vbox); gtk_widget_show(window); gtk_widget_show(vbox); //init standalone env rv = XPCOMGlueStartup(xulPath.c_str()); if (NS_FAILED(rv)) { printf("XPCOMGlueStartup\n"); } rv = XPCOMGlueLoadXULFunctions(nsFuncs); if (NS_FAILED(rv)) { printf("XPCOMGlueLoadXULFunctions\n"); } rv = NS_NewNativeLocalFile(nsEmbedCString(xulrunPath.c_str()), PR_FALSE, getter_AddRefs(libxul)); if (NS_FAILED(rv)) { printf("NS_NewNativeLocalFile\n"); } rv = XRE_InitEmbedding(libxul, 0, 0, 0, 0); if (NS_FAILED(rv)) { printf("XRE_InitEmbedding\n"); } rv = NS_GetServiceManager(getter_AddRefs(servMan)); if (NS_FAILED(rv)) { std::cout<<"Get manager Error:"<<rv<<std::endl; } nsCOMPtr<nsIComponentRegistrar> registrar = do_QueryInterface(servMan); rv=registrar->AutoRegister(nsnull); if (NS_FAILED(rv)) { std::cout<<"Get manager Error:"<<rv<<std::endl; } mozilla_prefs_set_string (servMan,"general.useragent.override", "Mozilla/5.0 (X11; U; Linux x86_64; en-US; rv:1.9.0.8) Gecko/2009032600 SUSE/3.0.8-1.1 Firefox/3.0.8"); nsCOMPtr<nsIStatManager> sm=do_CreateInstance(lstStr.c_str(),&rv); if (NS_FAILED(rv)) { std::cout<<"Get stat manager Error:"<<std::hex<<rv<<std::endl; return 0; } nsCOMPtr<nsISoapInter> inter=do_CreateInstance("@nyapc.com/XPCOM/nsSoapInter;1",&rv); if (NS_FAILED(rv)) { std::cout<<"Init Soap Inter error\n"; return 0; } if(soapServer.length()>0) inter->SetAddress(nsCString(soapServer.c_str())); nsCOMPtr<nsISoapTask> task; if(isCraw) inter->GetTask(cid,maxDoc,getter_AddRefs(task)); else inter->GetWrapTask(cid,maxDoc,getter_AddRefs(task)); sm->SetInter(inter); std::list<gtkBrowser> bList; if(task!=nsnull) { sm->SetTask(task); PRInt32 len; task->GetUrlCount(&len); for(PRInt32 index=0;index<len;index++) { int Uid; nsCString aurl; task->GetUrlByIndex(index,&Uid,aurl); gtkBrowser gb(vbox,Uid); gb.SetListener(sm); gb.SetRunlevel(mozSet); gb.SetUrl(aurl); bList.push_back(gb); } for(std::list<gtkBrowser>::iterator it=bList.begin();it!=bList.end();++it) it->Start(); }else { sleep(60); exit(0); } gtk_widget_hide(vbox); gtk_widget_hide(window); /**********set listener***********/ std::cout<<"Crawler ID:"<<cid<<std::endl; gtk_main(); XRE_TermEmbedding(); XPCOMGlueShutdown(); return 0; }
int main(int argc, char* argv[]) { char exePath[MAXPATHLEN]; #ifdef MOZ_WIDGET_GONK // This creates a ThreadPool for binder ipc. A ThreadPool is necessary to // receive binder calls, though not necessary to send binder calls. // ProcessState::Self() also needs to be called once on the main thread to // register the main thread with the binder driver. android::ProcessState::self()->startThreadPool(); #endif nsresult rv = mozilla::BinaryPath::Get(argv[0], exePath); if (NS_FAILED(rv)) { Output("Couldn't calculate the application directory.\n"); return 255; } char *lastSlash = strrchr(exePath, XPCOM_FILE_PATH_SEPARATOR[0]); if (!lastSlash || ((lastSlash - exePath) + sizeof(XPCOM_DLL) + 1 > MAXPATHLEN)) return 255; strcpy(++lastSlash, XPCOM_DLL); #if defined(XP_UNIX) // If the b2g app is launched from adb shell, then the shell will wind // up being the process group controller. This means that we can't send // signals to the process group (useful for profiling). // We ignore the return value since setsid() fails if we're already the // process group controller (the normal situation). (void)setsid(); #endif int gotCounters; #if defined(XP_UNIX) struct rusage initialRUsage; gotCounters = !getrusage(RUSAGE_SELF, &initialRUsage); #elif defined(XP_WIN) IO_COUNTERS ioCounters; gotCounters = GetProcessIoCounters(GetCurrentProcess(), &ioCounters); #endif // We do this because of data in bug 771745 XPCOMGlueEnablePreload(); rv = XPCOMGlueStartup(exePath); if (NS_FAILED(rv)) { Output("Couldn't load XPCOM.\n"); return 255; } // Reset exePath so that it is the directory name and not the xpcom dll name *lastSlash = 0; rv = XPCOMGlueLoadXULFunctions(kXULFuncs); if (NS_FAILED(rv)) { Output("Couldn't load XRE functions.\n"); return 255; } #ifdef XRE_HAS_DLL_BLOCKLIST XRE_SetupDllBlocklist(); #endif int result; { ScopedLogging log; result = do_main(argc, argv); } return result; }
int main(int argc, char **argv) { nsresult rv; char *lastSlash; char iniPath[MAXPATHLEN]; char tmpPath[MAXPATHLEN]; char greDir[MAXPATHLEN]; PRBool greFound = PR_FALSE; #if defined(XP_MACOSX) CFBundleRef appBundle = CFBundleGetMainBundle(); if (!appBundle) return 1; CFURLRef resourcesURL = CFBundleCopyResourcesDirectoryURL(appBundle); if (!resourcesURL) return 1; CFURLRef absResourcesURL = CFURLCopyAbsoluteURL(resourcesURL); CFRelease(resourcesURL); if (!absResourcesURL) return 1; CFURLRef iniFileURL = CFURLCreateCopyAppendingPathComponent(kCFAllocatorDefault, absResourcesURL, CFSTR("application.ini"), false); CFRelease(absResourcesURL); if (!iniFileURL) return 1; CFStringRef iniPathStr = CFURLCopyFileSystemPath(iniFileURL, kCFURLPOSIXPathStyle); CFRelease(iniFileURL); if (!iniPathStr) return 1; CFStringGetCString(iniPathStr, iniPath, sizeof(iniPath), kCFStringEncodingUTF8); CFRelease(iniPathStr); #else #ifdef XP_WIN wchar_t wide_path[MAX_PATH]; if (!::GetModuleFileNameW(NULL, wide_path, MAX_PATH)) return 1; WideCharToMultiByte(CP_UTF8, 0, wide_path,-1, iniPath, MAX_PATH, NULL, NULL); #elif defined(XP_OS2) PPIB ppib; PTIB ptib; DosGetInfoBlocks(&ptib, &ppib); DosQueryModuleName(ppib->pib_hmte, sizeof(iniPath), iniPath); #elif defined(XP_BEOS) BEntry e((const char *)argv[0], true); // traverse symlink BPath p; status_t err; err = e.GetPath(&p); NS_ASSERTION(err == B_OK, "realpath failed"); if (err == B_OK) // p.Path returns a pointer, so use strcpy to store path in iniPath strcpy(iniPath, p.Path()); #else // on unix, there is no official way to get the path of the current binary. // instead of using the MOZILLA_FIVE_HOME hack, which doesn't scale to // multiple applications, we will try a series of techniques: // // 1) use realpath() on argv[0], which works unless we're loaded from the // PATH // 2) manually walk through the PATH and look for ourself // 3) give up struct stat fileStat; if (!realpath(argv[0], iniPath) || stat(iniPath, &fileStat)) { const char *path = getenv("PATH"); if (!path) return 1; char *pathdup = strdup(path); if (!pathdup) return 1; PRBool found = PR_FALSE; char *token = strtok(pathdup, ":"); while (token) { sprintf(tmpPath, "%s/%s", token, argv[0]); if (realpath(tmpPath, iniPath) && stat(iniPath, &fileStat) == 0) { found = PR_TRUE; break; } token = strtok(NULL, ":"); } free (pathdup); if (!found) return 1; } #endif lastSlash = strrchr(iniPath, PATH_SEPARATOR_CHAR); if (!lastSlash) return 1; *(++lastSlash) = '\0'; // On Linux/Win, look for XULRunner in appdir/xulrunner snprintf(greDir, sizeof(greDir), "%sxulrunner" XPCOM_FILE_PATH_SEPARATOR XPCOM_DLL, iniPath); greFound = FolderExists(greDir); strncpy(lastSlash, "application.ini", sizeof(iniPath) - (lastSlash - iniPath)); #endif // If -app parameter was passed in, it is now time to take it under // consideration. const char *appDataFile; appDataFile = getenv("XUL_APP_FILE"); if (!appDataFile || !*appDataFile) if (argc > 1 && IsArg(argv[1], "app")) { if (argc == 2) { Output(PR_FALSE, "specify APP-FILE (optional)\n"); return 1; } argv[1] = argv[0]; ++argv; --argc; appDataFile = argv[1]; argv[1] = argv[0]; ++argv; --argc; char kAppEnv[MAXPATHLEN]; snprintf(kAppEnv, MAXPATHLEN, "XUL_APP_FILE=%s", appDataFile); if (putenv(kAppEnv)) Output(PR_FALSE, "Couldn't set %s.\n", kAppEnv); char *result = (char*) calloc(sizeof(char), MAXPATHLEN); if (NS_FAILED(GetRealPath(appDataFile, &result))) { Output(PR_TRUE, "Invalid application.ini path.\n"); return 1; } // We have a valid application.ini path passed in to the -app parameter // but not yet a valid greDir, so lets look for it also on the same folder // as the stub. if (!greFound) { lastSlash = strrchr(iniPath, PATH_SEPARATOR_CHAR); if (!lastSlash) return 1; *(++lastSlash) = '\0'; snprintf(greDir, sizeof(greDir), "%s" XPCOM_DLL, iniPath); greFound = FolderExists(greDir); } // copy it back. strcpy(iniPath, result); } nsINIParser parser; rv = parser.Init(iniPath); if (NS_FAILED(rv)) { fprintf(stderr, "Could not read application.ini\n"); return 1; } #ifdef WINCE // On Windows Mobile and WinCE, we can save a lot of time by not // waiting for XUL and XPCOM to load up. Let's see if we can find // an existing app window to forward our command-line to now. // Shouldn't attempt this if the -no-remote parameter has been provided. bool noRemote = false; for (int i = 1; i < argc; i++) { if (IsArg(argv[i], "no-remote")) { noRemote = true; break; } } if (!noRemote) { char windowName[512]; // Is there a const for appname like VERSION_MAXLEN? rv = parser.GetString("App", "Name", windowName, sizeof(windowName)); if (NS_FAILED(rv)) { fprintf(stderr, "Couldn't figure out the application name\n"); return 1; } // Lookup the hidden message window created by nsNativeAppSupport strncat(windowName, "MessageWindow", sizeof(windowName) - strlen(windowName)); WCHAR wWindowName[512]; MultiByteToWideChar(CP_UTF8, 0, windowName, -1, wWindowName, sizeof(wWindowName)); HWND wnd = ::FindWindowW(wWindowName, NULL); if (wnd) { // Forward the command-line and bail out ForwardToWindow(wnd); return 0; } } #endif if (!greFound) { char minVersion[VERSION_MAXLEN]; // If a gecko maxVersion is not specified, we assume that the app uses only // frozen APIs, and is therefore compatible with any xulrunner 1.x. char maxVersion[VERSION_MAXLEN] = "1.*"; GREVersionRange range = { minVersion, PR_TRUE, maxVersion, PR_TRUE }; rv = parser.GetString("Gecko", "MinVersion", minVersion, sizeof(minVersion)); if (NS_FAILED(rv)) { fprintf(stderr, "The application.ini does not specify a [Gecko] MinVersion\n"); return 1; } rv = parser.GetString("Gecko", "MaxVersion", maxVersion, sizeof(maxVersion)); if (NS_SUCCEEDED(rv)) range.upperInclusive = PR_TRUE; static const GREProperty kProperties[] = { { "xulrunner", "true" } }; rv = GRE_GetGREPathWithProperties(&range, 1, kProperties, NS_ARRAY_LENGTH(kProperties), greDir, sizeof(greDir)); if (NS_FAILED(rv)) { // XXXbsmedberg: Do something much smarter here: notify the // user/offer to download/? Output(PR_FALSE, "Could not find compatible GRE between version %s and %s.\n", range.lower, range.upper); return 1; } #ifdef XP_UNIX // Using a symlinked greDir will fail during startup. Not sure why, but if // we resolve the symlink, everything works as expected. char resolved_greDir[MAXPATHLEN] = ""; if (realpath(greDir, resolved_greDir) && *resolved_greDir) { strncpy(greDir, resolved_greDir, MAXPATHLEN); } #endif } #ifdef XP_OS2 // On OS/2 we need to set BEGINLIBPATH to be able to find XULRunner DLLs strcpy(tmpPath, greDir); lastSlash = strrchr(tmpPath, PATH_SEPARATOR_CHAR); if (lastSlash) { *lastSlash = '\0'; } DosSetExtLIBPATH(tmpPath, BEGIN_LIBPATH); #endif rv = XPCOMGlueStartup(greDir); if (NS_FAILED(rv)) { if (rv == NS_ERROR_OUT_OF_MEMORY) { char applicationName[2000] = "this application"; parser.GetString("App", "Name", applicationName, sizeof(applicationName)); Output(PR_TRUE, "Not enough memory available to start %s.\n", applicationName); } else { Output(PR_TRUE, "Couldn't load XPCOM.\n"); } return 1; } static const nsDynamicFunctionLoad kXULFuncs[] = { { "XRE_CreateAppData", (NSFuncPtr*) &XRE_CreateAppData }, { "XRE_FreeAppData", (NSFuncPtr*) &XRE_FreeAppData }, { "XRE_main", (NSFuncPtr*) &XRE_main }, { nsnull, nsnull } }; rv = XPCOMGlueLoadXULFunctions(kXULFuncs); if (NS_FAILED(rv)) { Output(PR_TRUE, "Couldn't load XRE functions.\n"); return 1; } NS_LogInit(); int retval; { // Scope COMPtr and AutoAppData nsCOMPtr<nsILocalFile> iniFile; #ifdef XP_WIN // On Windows and Windows CE, iniPath is UTF-8 encoded, // so we need to convert it. rv = NS_NewLocalFile(NS_ConvertUTF8toUTF16(iniPath), PR_FALSE, getter_AddRefs(iniFile)); #else rv = NS_NewNativeLocalFile(nsDependentCString(iniPath), PR_FALSE, getter_AddRefs(iniFile)); #endif if (NS_FAILED(rv)) { Output(PR_TRUE, "Couldn't find application.ini file.\n"); return 1; } AutoAppData appData(iniFile); if (!appData) { Output(PR_TRUE, "Error: couldn't parse application.ini.\n"); return 1; } NS_ASSERTION(appData->directory, "Failed to get app directory."); if (!appData->xreDirectory) { // chop "libxul.so" off the GRE path lastSlash = strrchr(greDir, PATH_SEPARATOR_CHAR); if (lastSlash) { *lastSlash = '\0'; } #ifdef XP_WIN // same as iniPath. NS_NewLocalFile(NS_ConvertUTF8toUTF16(greDir), PR_FALSE, &appData->xreDirectory); #else NS_NewNativeLocalFile(nsDependentCString(greDir), PR_FALSE, &appData->xreDirectory); #endif } retval = XRE_main(argc, argv, appData); } NS_LogTerm(); XPCOMGlueShutdown(); return retval; }
int main(int argc, char* argv[]) { PRTime start = _PR_Now(); char exePath[MAXPATHLEN]; #ifdef XP_MACOSX TriggerQuirks(); #endif nsresult rv = mozilla::BinaryPath::Get(argv[0], exePath); if (NS_FAILED(rv)) { Output("Couldn't calculate the application directory.\n"); return 255; } char *lastSlash = strrchr(exePath, XPCOM_FILE_PATH_SEPARATOR[0]); if (!lastSlash || (size_t(lastSlash - exePath) > MAXPATHLEN - sizeof(XPCOM_DLL) - 1)) return 255; strcpy(++lastSlash, XPCOM_DLL); int gotCounters; #if defined(XP_UNIX) struct rusage initialRUsage; gotCounters = !getrusage(RUSAGE_SELF, &initialRUsage); #elif defined(XP_WIN) // Don't change the order of these enumeration constants, the order matters // for reporting telemetry data. If new values are added adjust the // STARTUP_USING_PRELOAD_TRIAL histogram. enum PreloadType{ PREFETCH_PRELOAD, PREFETCH_NO_PRELOAD, NO_PREFETCH_PRELOAD, NO_PREFETCH_NO_PRELOAD }; PreloadType preloadType; IO_COUNTERS ioCounters; gotCounters = GetProcessIoCounters(GetCurrentProcess(), &ioCounters); srand(time(NULL)); bool shouldUsePreload = rand() % 2 == 0; if (IsPrefetchDisabledViaService()) { if (shouldUsePreload) { preloadType = NO_PREFETCH_PRELOAD; } else { preloadType = NO_PREFETCH_NO_PRELOAD; } } else { if (shouldUsePreload) { preloadType = PREFETCH_PRELOAD; } else { preloadType = PREFETCH_NO_PRELOAD; } } if (shouldUsePreload) #endif { XPCOMGlueEnablePreload(); } rv = XPCOMGlueStartup(exePath); if (NS_FAILED(rv)) { Output("Couldn't load XPCOM.\n"); return 255; } // Reset exePath so that it is the directory name and not the xpcom dll name *lastSlash = 0; rv = XPCOMGlueLoadXULFunctions(kXULFuncs); if (NS_FAILED(rv)) { Output("Couldn't load XRE functions.\n"); return 255; } XRE_StartupTimelineRecord(mozilla::StartupTimeline::START, start); #ifdef XRE_HAS_DLL_BLOCKLIST XRE_SetupDllBlocklist(); #endif #if defined(XP_WIN) XRE_TelemetryAccumulate(mozilla::Telemetry::STARTUP_USING_PRELOAD_TRIAL, preloadType); #endif if (gotCounters) { #if defined(XP_WIN) XRE_TelemetryAccumulate(mozilla::Telemetry::EARLY_GLUESTARTUP_READ_OPS, int(ioCounters.ReadOperationCount)); XRE_TelemetryAccumulate(mozilla::Telemetry::EARLY_GLUESTARTUP_READ_TRANSFER, int(ioCounters.ReadTransferCount / 1024)); IO_COUNTERS newIoCounters; if (GetProcessIoCounters(GetCurrentProcess(), &newIoCounters)) { XRE_TelemetryAccumulate(mozilla::Telemetry::GLUESTARTUP_READ_OPS, int(newIoCounters.ReadOperationCount - ioCounters.ReadOperationCount)); XRE_TelemetryAccumulate(mozilla::Telemetry::GLUESTARTUP_READ_TRANSFER, int((newIoCounters.ReadTransferCount - ioCounters.ReadTransferCount) / 1024)); } #elif defined(XP_UNIX) XRE_TelemetryAccumulate(mozilla::Telemetry::EARLY_GLUESTARTUP_HARD_FAULTS, int(initialRUsage.ru_majflt)); struct rusage newRUsage; if (!getrusage(RUSAGE_SELF, &newRUsage)) { XRE_TelemetryAccumulate(mozilla::Telemetry::GLUESTARTUP_HARD_FAULTS, int(newRUsage.ru_majflt - initialRUsage.ru_majflt)); } #endif } int result; { ScopedLogging log; result = do_main(argc, argv); } XPCOMGlueShutdown(); return result; }
int main(int argc, char* argv[]) { char exePath[MAXPATHLEN]; #ifdef MOZ_WIDGET_GONK // This creates a ThreadPool for binder ipc. A ThreadPool is necessary to // receive binder calls, though not necessary to send binder calls. // ProcessState::Self() also needs to be called once on the main thread to // register the main thread with the binder driver. android::ProcessState::self()->startThreadPool(); #endif nsresult rv; rv = mozilla::BinaryPath::Get(argv[0], exePath); if (NS_FAILED(rv)) { Output("Couldn't calculate the application directory.\n"); return 255; } char *lastSlash = strrchr(exePath, XPCOM_FILE_PATH_SEPARATOR[0]); if (!lastSlash || ((lastSlash - exePath) + sizeof(XPCOM_DLL) + 1 > MAXPATHLEN)) return 255; strcpy(++lastSlash, XPCOM_DLL); #if defined(XP_UNIX) // If the b2g app is launched from adb shell, then the shell will wind // up being the process group controller. This means that we can't send // signals to the process group (useful for profiling). // We ignore the return value since setsid() fails if we're already the // process group controller (the normal situation). (void)setsid(); #endif #ifdef HAS_DLL_BLOCKLIST DllBlocklist_Initialize(); #endif // We do this because of data in bug 771745 XPCOMGlueEnablePreload(); rv = XPCOMGlueStartup(exePath); if (NS_FAILED(rv)) { Output("Couldn't load XPCOM.\n"); return 255; } // Reset exePath so that it is the directory name and not the xpcom dll name *lastSlash = 0; rv = XPCOMGlueLoadXULFunctions(kXULFuncs); if (NS_FAILED(rv)) { Output("Couldn't load XRE functions.\n"); return 255; } int result; { ScopedLogging log; char **_argv; /* * Duplicate argument vector to conform non-const argv of * do_main() since XRE_main() is very stupid with non-const argv. */ _argv = new char *[argc + 1]; for (int i = 0; i < argc; i++) { size_t len = strlen(argv[i]) + 1; _argv[i] = new char[len]; MOZ_ASSERT(_argv[i] != nullptr); memcpy(_argv[i], argv[i], len); } _argv[argc] = nullptr; result = do_main(argc, _argv); for (int i = 0; i < argc; i++) { delete[] _argv[i]; } delete[] _argv; } return result; }
int main(int argc, char **argv) { nsresult rv; char *lastSlash; char iniPath[MAXPATHLEN]; char tmpPath[MAXPATHLEN]; char greDir[MAXPATHLEN]; bool greFound = false; #if defined(XP_MACOSX) CFBundleRef appBundle = CFBundleGetMainBundle(); if (!appBundle) return 1; CFURLRef resourcesURL = CFBundleCopyResourcesDirectoryURL(appBundle); if (!resourcesURL) return 1; CFURLRef absResourcesURL = CFURLCopyAbsoluteURL(resourcesURL); CFRelease(resourcesURL); if (!absResourcesURL) return 1; CFURLRef iniFileURL = CFURLCreateCopyAppendingPathComponent(kCFAllocatorDefault, absResourcesURL, CFSTR("application.ini"), false); CFRelease(absResourcesURL); if (!iniFileURL) return 1; CFStringRef iniPathStr = CFURLCopyFileSystemPath(iniFileURL, kCFURLPOSIXPathStyle); CFRelease(iniFileURL); if (!iniPathStr) return 1; CFStringGetCString(iniPathStr, iniPath, sizeof(iniPath), kCFStringEncodingUTF8); CFRelease(iniPathStr); #else #ifdef XP_WIN wchar_t wide_path[MAX_PATH]; if (!::GetModuleFileNameW(NULL, wide_path, MAX_PATH)) return 1; WideCharToMultiByte(CP_UTF8, 0, wide_path,-1, iniPath, MAX_PATH, NULL, NULL); #elif defined(XP_OS2) PPIB ppib; PTIB ptib; DosGetInfoBlocks(&ptib, &ppib); DosQueryModuleName(ppib->pib_hmte, sizeof(iniPath), iniPath); #else // on unix, there is no official way to get the path of the current binary. // instead of using the MOZILLA_FIVE_HOME hack, which doesn't scale to // multiple applications, we will try a series of techniques: // // 1) use realpath() on argv[0], which works unless we're loaded from the // PATH // 2) manually walk through the PATH and look for ourself // 3) give up struct stat fileStat; strncpy(tmpPath, argv[0], sizeof(tmpPath)); lastSlash = strrchr(tmpPath, '/'); if (lastSlash) { *lastSlash = 0; realpath(tmpPath, iniPath); } else { const char *path = getenv("PATH"); if (!path) return 1; char *pathdup = strdup(path); if (!pathdup) return 1; bool found = false; char *token = strtok(pathdup, ":"); while (token) { sprintf(tmpPath, "%s/%s", token, argv[0]); if (stat(tmpPath, &fileStat) == 0) { found = true; lastSlash = strrchr(tmpPath, '/'); *lastSlash = 0; realpath(tmpPath, iniPath); break; } token = strtok(NULL, ":"); } free (pathdup); if (!found) return 1; } lastSlash = iniPath + strlen(iniPath); *lastSlash = '/'; #endif #ifndef XP_UNIX lastSlash = strrchr(iniPath, PATH_SEPARATOR_CHAR); if (!lastSlash) return 1; #endif *(++lastSlash) = '\0'; // On Linux/Win, look for XULRunner in appdir/xulrunner snprintf(greDir, sizeof(greDir), "%sxulrunner" XPCOM_FILE_PATH_SEPARATOR XPCOM_DLL, iniPath); greFound = FolderExists(greDir); #ifdef XP_UNIX if (greFound) { char resolved_greDir[MAXPATHLEN] = ""; if (realpath(greDir, resolved_greDir) && *resolved_greDir) { strncpy(greDir, resolved_greDir, MAXPATHLEN); } } #endif strncpy(lastSlash, "application.ini", sizeof(iniPath) - (lastSlash - iniPath)); #endif // If -app parameter was passed in, it is now time to take it under // consideration. const char *appDataFile; appDataFile = getenv("XUL_APP_FILE"); if (!appDataFile || !*appDataFile) if (argc > 1 && IsArg(argv[1], "app")) { if (argc == 2) { Output(false, "specify APP-FILE (optional)\n"); return 1; } argv[1] = argv[0]; ++argv; --argc; appDataFile = argv[1]; argv[1] = argv[0]; ++argv; --argc; char kAppEnv[MAXPATHLEN]; snprintf(kAppEnv, MAXPATHLEN, "XUL_APP_FILE=%s", appDataFile); if (putenv(kAppEnv)) Output(false, "Couldn't set %s.\n", kAppEnv); char *result = (char*) calloc(sizeof(char), MAXPATHLEN); if (NS_FAILED(GetRealPath(appDataFile, &result))) { Output(true, "Invalid application.ini path.\n"); return 1; } // We have a valid application.ini path passed in to the -app parameter // but not yet a valid greDir, so lets look for it also on the same folder // as the stub. if (!greFound) { lastSlash = strrchr(iniPath, PATH_SEPARATOR_CHAR); if (!lastSlash) return 1; *(++lastSlash) = '\0'; snprintf(greDir, sizeof(greDir), "%s" XPCOM_DLL, iniPath); greFound = FolderExists(greDir); } // copy it back. strcpy(iniPath, result); } nsINIParser parser; rv = parser.Init(iniPath); if (NS_FAILED(rv)) { fprintf(stderr, "Could not read application.ini\n"); return 1; } if (!greFound) { #ifdef XP_MACOSX // Check for <bundle>/Contents/Frameworks/XUL.framework/libxpcom.dylib CFURLRef fwurl = CFBundleCopyPrivateFrameworksURL(appBundle); CFURLRef absfwurl = nullptr; if (fwurl) { absfwurl = CFURLCopyAbsoluteURL(fwurl); CFRelease(fwurl); } if (absfwurl) { CFURLRef xulurl = CFURLCreateCopyAppendingPathComponent(NULL, absfwurl, CFSTR("XUL.framework"), true); if (xulurl) { CFURLRef xpcomurl = CFURLCreateCopyAppendingPathComponent(NULL, xulurl, CFSTR("libxpcom.dylib"), false); if (xpcomurl) { char tbuffer[MAXPATHLEN]; if (CFURLGetFileSystemRepresentation(xpcomurl, true, (UInt8*) tbuffer, sizeof(tbuffer)) && access(tbuffer, R_OK | X_OK) == 0) { if (realpath(tbuffer, greDir)) { greFound = true; } else { greDir[0] = '\0'; } } CFRelease(xpcomurl); } CFRelease(xulurl); } CFRelease(absfwurl); } #endif if (!greFound) { Output(false, "Could not find the Mozilla runtime.\n"); return 1; } } #ifdef XP_OS2 // On OS/2 we need to set BEGINLIBPATH to be able to find XULRunner DLLs strcpy(tmpPath, greDir); lastSlash = strrchr(tmpPath, PATH_SEPARATOR_CHAR); if (lastSlash) { *lastSlash = '\0'; } DosSetExtLIBPATH(tmpPath, BEGIN_LIBPATH); #endif rv = XPCOMGlueStartup(greDir); if (NS_FAILED(rv)) { if (rv == NS_ERROR_OUT_OF_MEMORY) { char applicationName[2000] = "this application"; parser.GetString("App", "Name", applicationName, sizeof(applicationName)); Output(true, "Not enough memory available to start %s.\n", applicationName); } else { Output(true, "Couldn't load XPCOM.\n"); } return 1; } static const nsDynamicFunctionLoad kXULFuncs[] = { { "XRE_CreateAppData", (NSFuncPtr*) &XRE_CreateAppData }, { "XRE_FreeAppData", (NSFuncPtr*) &XRE_FreeAppData }, { "XRE_main", (NSFuncPtr*) &XRE_main }, { nullptr, nullptr } }; rv = XPCOMGlueLoadXULFunctions(kXULFuncs); if (NS_FAILED(rv)) { Output(true, "Couldn't load XRE functions.\n"); return 1; } NS_LogInit(); int retval; { // Scope COMPtr and AutoAppData nsCOMPtr<nsIFile> iniFile; #ifdef XP_WIN // On Windows iniPath is UTF-8 encoded so we need to convert it. rv = NS_NewLocalFile(NS_ConvertUTF8toUTF16(iniPath), false, getter_AddRefs(iniFile)); #else rv = NS_NewNativeLocalFile(nsDependentCString(iniPath), false, getter_AddRefs(iniFile)); #endif if (NS_FAILED(rv)) { Output(true, "Couldn't find application.ini file.\n"); return 1; } AutoAppData appData(iniFile); if (!appData) { Output(true, "Error: couldn't parse application.ini.\n"); return 1; } NS_ASSERTION(appData->directory, "Failed to get app directory."); if (!appData->xreDirectory) { // chop "libxul.so" off the GRE path lastSlash = strrchr(greDir, PATH_SEPARATOR_CHAR); if (lastSlash) { *lastSlash = '\0'; } #ifdef XP_WIN // same as iniPath. NS_NewLocalFile(NS_ConvertUTF8toUTF16(greDir), false, &appData->xreDirectory); #else NS_NewNativeLocalFile(nsDependentCString(greDir), false, &appData->xreDirectory); #endif } retval = XRE_main(argc, argv, appData, 0); } NS_LogTerm(); return retval; }