static int InstallXULApp(nsIFile* aXULRunnerDir, const char *aAppLocation, const char *aInstallTo, const char *aLeafName) { nsCOMPtr<nsILocalFile> appLocation; nsCOMPtr<nsILocalFile> installTo; nsString leafName; nsresult rv = XRE_GetFileFromPath(aAppLocation, getter_AddRefs(appLocation)); if (NS_FAILED(rv)) return 2; if (aInstallTo) { rv = XRE_GetFileFromPath(aInstallTo, getter_AddRefs(installTo)); if (NS_FAILED(rv)) return 2; } if (aLeafName) NS_CStringToUTF16(nsDependentCString(aLeafName), NS_CSTRING_ENCODING_NATIVE_FILESYSTEM, leafName); rv = NS_InitXPCOM2(nsnull, aXULRunnerDir, nsnull); if (NS_FAILED(rv)) return 3; { // Scope our COMPtr to avoid holding XPCOM refs beyond xpcom shutdown nsCOMPtr<nsIXULAppInstall> install (do_GetService("@mozilla.org/xulrunner/app-install-service;1")); if (!install) { rv = NS_ERROR_FAILURE; } else { rv = install->InstallApplication(appLocation, installTo, leafName); } } NS_ShutdownXPCOM(nsnull); if (NS_FAILED(rv)) return 3; return 0; }
void purpleDebug::ReportMessage(PurpleDebugLevel level, const char *category, const char *arg) { LOG(("pp-%s: %s", category, arg)); NS_ENSURE_TRUE(Enabled(level, category), ); nsCOMPtr<nsIConsoleService> consoleService = do_GetService(NS_CONSOLESERVICE_CONTRACTID); NS_ENSURE_TRUE(consoleService, ); nsCString message(category); message.Append(": "); message.Append(arg); nsString msg; NS_CStringToUTF16(message, NS_CSTRING_ENCODING_UTF8, msg); consoleService->LogStringMessage(msg.get()); }
HRESULT nsScriptablePeer::ConvertVariants(nsIVariant *aIn, VARIANT *aOut) { if (aIn == NULL || aOut == NULL) { return NS_ERROR_INVALID_ARG; } PRBool isWritable = PR_FALSE; nsCOMPtr<nsIWritableVariant> writable = do_QueryInterface(aIn); if (writable) { writable->GetWritable(&isWritable); } PRUint16 type; nsresult rv = aIn->GetDataType(&type); switch (type) { case nsIDataType::VTYPE_INT8: { PRUint8 value = 0; rv = aIn->GetAsInt8(&value); aOut->vt = VT_I1; aOut->cVal = value; } break; case nsIDataType::VTYPE_INT16: { PRInt16 value = 0; rv = aIn->GetAsInt16(&value); aOut->vt = VT_I2; aOut->iVal = value; } break; case nsIDataType::VTYPE_INT32: { PRInt32 value = 0; rv = aIn->GetAsInt32(&value); aOut->vt = VT_I4; aOut->lVal = value; } break; case nsIDataType::VTYPE_CHAR: case nsIDataType::VTYPE_UINT8: { PRUint8 value = 0; rv = aIn->GetAsInt8(&value); aOut->vt = VT_UI1; aOut->bVal = value; } break; case nsIDataType::VTYPE_WCHAR: case nsIDataType::VTYPE_UINT16: { PRUint16 value = 0; rv = aIn->GetAsUint16(&value); aOut->vt = VT_I2; aOut->uiVal = value; } break; case nsIDataType::VTYPE_UINT32: { PRUint32 value = 0; rv = aIn->GetAsUint32(&value); aOut->vt = VT_I4; aOut->ulVal = value; } break; case nsIDataType::VTYPE_FLOAT: { float value = 0; rv = aIn->GetAsFloat(&value); aOut->vt = VT_R4; aOut->fltVal = value; } break; case nsIDataType::VTYPE_DOUBLE: { double value = 0; rv = aIn->GetAsDouble(&value); aOut->vt = VT_R4; aOut->dblVal = value; } break; case nsIDataType::VTYPE_BOOL: { PRBool value = 0; rv = aIn->GetAsBool(&value); aOut->vt = VT_BOOL; aOut->dblVal = value ? VARIANT_TRUE : VARIANT_FALSE; } break; case nsIDataType::VTYPE_EMPTY: VariantClear(aOut); break; case nsIDataType::VTYPE_STRING_SIZE_IS: case nsIDataType::VTYPE_CHAR_STR: { nsCString value; aIn->GetAsString(getter_Copies(value)); nsString valueWide; NS_CStringToUTF16(value, NS_CSTRING_ENCODING_ASCII, valueWide); aOut->vt = VT_BSTR; aOut->bstrVal = SysAllocString(valueWide.get()); } break; case nsIDataType::VTYPE_WSTRING_SIZE_IS: case nsIDataType::VTYPE_WCHAR_STR: { nsString value; aIn->GetAsWString(getter_Copies(value)); aOut->vt = VT_BSTR; aOut->bstrVal = SysAllocString(value.get()); } break; case nsIDataType::VTYPE_ASTRING: { nsAutoString value; aIn->GetAsAString(value); aOut->vt = VT_BSTR; aOut->bstrVal = SysAllocString(value.get()); } break; case nsIDataType::VTYPE_DOMSTRING: { nsAutoString value; aIn->GetAsAString(value); aOut->vt = VT_BSTR; aOut->bstrVal = SysAllocString(value.get()); } break; case nsIDataType::VTYPE_CSTRING: { nsCAutoString value; aIn->GetAsACString(value); nsAutoString valueWide; NS_CStringToUTF16(value, NS_CSTRING_ENCODING_ASCII, valueWide); aOut->vt = VT_BSTR; aOut->bstrVal = SysAllocString(valueWide.get()); } break; case nsIDataType::VTYPE_UTF8STRING: { nsCAutoString value; aIn->GetAsAUTF8String(value); nsAutoString valueWide; CopyUTF8toUTF16(value, valueWide); aOut->vt = VT_BSTR; aOut->bstrVal = SysAllocString(valueWide.get()); } // Unsupported types default: case nsIDataType::VTYPE_INT64: case nsIDataType::VTYPE_UINT64: case nsIDataType::VTYPE_VOID: case nsIDataType::VTYPE_ID: case nsIDataType::VTYPE_INTERFACE: case nsIDataType::VTYPE_INTERFACE_IS: case nsIDataType::VTYPE_ARRAY: case nsIDataType::VTYPE_EMPTY_ARRAY: return E_INVALIDARG; } return S_OK; }
nsresult WebBrowserChrome::SendHistoryStatusMessage(nsIURI * aURI, char * operation, int32_t info1, uint32_t aReloadFlags) { nsCString uriSpec; if (aURI) { aURI->GetSpec(uriSpec); } nsCString status; if(!(strcmp(operation, "back"))) { status.Assign("Going back to url: "); status.Append(uriSpec); } else if (!(strcmp(operation, "forward"))) { // Going forward. XXX Get string from a resource file status.Assign("Going forward to url: "); status.Append(uriSpec); } else if (!(strcmp(operation, "reload"))) { // Reloading. XXX Get string from a resource file if (aReloadFlags & nsIWebNavigation::LOAD_FLAGS_BYPASS_PROXY && aReloadFlags & nsIWebNavigation::LOAD_FLAGS_BYPASS_CACHE) { status.Assign("Reloading url, (bypassing proxy and cache): "); } else if (aReloadFlags & nsIWebNavigation::LOAD_FLAGS_BYPASS_PROXY) { status.Assign("Reloading url, (bypassing proxy): "); } else if (aReloadFlags & nsIWebNavigation::LOAD_FLAGS_BYPASS_CACHE) { status.Assign("Reloading url, (bypassing cache): "); } else { status.Assign("Reloading url, (normal): "); } status.Append(uriSpec); } else if (!(strcmp(operation, "add"))) { status.Assign(uriSpec); status.Append(" added to session History"); } else if (!(strcmp(operation, "goto"))) { status.Assign("Going to HistoryIndex: "); AppendIntToCString(info1, status); status.Append(" Url: "); status.Append(uriSpec); } else if (!(strcmp(operation, "purge"))) { AppendIntToCString(info1, status); status.Append(" purged from Session History"); } else if (!(strcmp(operation, "replace"))) { status.Assign("Replacing HistoryIndex: "); AppendIntToCString(info1, status); } nsString wstatus; NS_CStringToUTF16(status, NS_CSTRING_ENCODING_UTF8, wstatus); WebBrowserChromeUI::UpdateStatusBarText(this, wstatus.get()); return NS_OK; }
/* static */ nsresult GeckoPrintService::TranslateSettings (GtkPrintSettings *aGtkSettings, GtkPageSetup *aPageSetup, GtkPrinter *aPrinter, const nsACString &aSourceFile, PRInt16 aPrintFrames, PRBool aIsForPrinting, nsIPrintSettings *aSettings) { NS_ENSURE_ARG (aGtkSettings); NS_ENSURE_ARG (aPageSetup); GtkPrintCapabilities capabilities = GtkPrintCapabilities (0); if (aIsForPrinting) { NS_ENSURE_TRUE (aPrinter, NS_ERROR_FAILURE); capabilities = gtk_printer_get_capabilities (aPrinter); } /* Initialisation */ aSettings->SetIsInitializedFromPrinter (PR_FALSE); /* FIXME: PR_TRUE? */ aSettings->SetIsInitializedFromPrefs (PR_FALSE); /* FIXME: PR_TRUE? */ aSettings->SetPrintSilent (PR_FALSE); aSettings->SetShowPrintProgress (PR_TRUE); /* We always print PS to a file and then hand that off to gtk-print */ aSettings->SetPrinterName (LITERAL ("PostScript/default")); if (aIsForPrinting) { aSettings->SetPrintToFile (PR_TRUE); nsString sourceFile; NS_CStringToUTF16 (aSourceFile, NS_CSTRING_ENCODING_NATIVE_FILESYSTEM, sourceFile); aSettings->SetToFileName (sourceFile.get ()); } else { /* Otherwise mozilla will create the file nevertheless and * fail since we haven't set a name! */ aSettings->SetPrintToFile (PR_FALSE); } /* This is the time between printing each page, in ms. * It 'gives the user more time to press cancel' ! * We don't want any of this nonsense, so set this to a low value, * just enough to update the print dialogue. */ aSettings->SetPrintPageDelay (50); if (aIsForPrinting) { #ifdef HAVE_NSIPRINTSETTINGS_SETOUTPUTFORMAT NS_ENSURE_TRUE (aPrinter, NS_ERROR_FAILURE); const char *format = gtk_print_settings_get (aGtkSettings, GTK_PRINT_SETTINGS_OUTPUT_FILE_FORMAT); if (!format) format = "ps"; if (strcmp (format, "pdf") == 0 && gtk_printer_accepts_pdf (aPrinter)) { aSettings->SetOutputFormat (nsIPrintSettings::kOutputFormatPDF); } else if (strcmp (format, "ps") == 0 && gtk_printer_accepts_ps (aPrinter)) { aSettings->SetOutputFormat (nsIPrintSettings::kOutputFormatPS); } else { g_warning ("Output format '%s' specified, but printer '%s' does not support it!", format, gtk_printer_get_name (aPrinter)); return NS_ERROR_FAILURE; } #endif int n_copies = gtk_print_settings_get_n_copies (aGtkSettings); if (n_copies <= 0) return NS_ERROR_FAILURE; if (capabilities & GTK_PRINT_CAPABILITY_COPIES) { aSettings->SetNumCopies (1); } else { /* We have to copy them ourself */ aSettings->SetNumCopies (n_copies); gtk_print_settings_set_n_copies (aGtkSettings, 1); } gboolean reverse = gtk_print_settings_get_reverse (aGtkSettings); if (capabilities & GTK_PRINT_CAPABILITY_REVERSE) { aSettings->SetPrintReversed (PR_FALSE); } else { aSettings->SetPrintReversed (reverse); gtk_print_settings_set_reverse (aGtkSettings, FALSE); } GtkPageSet pageSet = gtk_print_settings_get_page_set (aGtkSettings); aSettings->SetPrintOptions (nsIPrintSettings::kPrintEvenPages, pageSet != GTK_PAGE_SET_ODD); aSettings->SetPrintOptions (nsIPrintSettings::kPrintEvenPages, pageSet != GTK_PAGE_SET_EVEN); GtkPrintPages printPages = gtk_print_settings_get_print_pages (aGtkSettings); switch (printPages) { case GTK_PRINT_PAGES_RANGES: { int numRanges = 0; GtkPageRange *pageRanges = gtk_print_settings_get_page_ranges (aGtkSettings, &numRanges); if (numRanges > 0) { /* FIXME: We can only support one range, ignore more ranges or raise error? */ aSettings->SetPrintRange (nsIPrintSettings::kRangeSpecifiedPageRange); /* Gecko page numbers start at 1, while gtk page numbers start at 0 */ aSettings->SetStartPageRange (pageRanges[0].start + 1); aSettings->SetEndPageRange (pageRanges[0].end + 1); g_free (pageRanges); break; } /* Fall-through to PAGES_ALL */ } case GTK_PRINT_PAGES_CURRENT: /* not supported, fall through */ case GTK_PRINT_PAGES_ALL: aSettings->SetPrintRange (nsIPrintSettings::kRangeAllPages); break; /* FIXME: we need some custom ranges here, "Selection" and "Focused Frame" */ } } else { aSettings->SetPrintOptions (nsIPrintSettings::kPrintEvenPages, PR_TRUE); aSettings->SetPrintOptions (nsIPrintSettings::kPrintEvenPages, PR_TRUE); aSettings->SetPrintReversed (PR_FALSE); aSettings->SetPrintRange (nsIPrintSettings::kRangeAllPages); } /* And clear those in the settings, so the printer doesn't try to apply them too */ gtk_print_settings_set_print_pages (aGtkSettings, GTK_PRINT_PAGES_ALL); gtk_print_settings_set_page_ranges (aGtkSettings, NULL, 0); gtk_print_settings_set_page_set (aGtkSettings, GTK_PAGE_SET_ALL); /* We must use the page setup here instead of the print settings, see gtk bug #485685 */ switch (gtk_page_setup_get_orientation (aPageSetup)) { case GTK_PAGE_ORIENTATION_PORTRAIT: case GTK_PAGE_ORIENTATION_REVERSE_PORTRAIT: /* not supported */ aSettings->SetOrientation (nsIPrintSettings::kPortraitOrientation); break; case GTK_PAGE_ORIENTATION_LANDSCAPE: case GTK_PAGE_ORIENTATION_REVERSE_LANDSCAPE: /* not supported */ aSettings->SetOrientation (nsIPrintSettings::kLandscapeOrientation); break; } aSettings->SetPrintInColor (gtk_print_settings_get_use_color (aGtkSettings)); aSettings->SetPaperSizeUnit(nsIPrintSettings::kPaperSizeMillimeters); #ifdef HAVE_NSIPRINTSETTINGS_SETPAPERSIZE aSettings->SetPaperSize (nsIPrintSettings::kPaperSizeDefined); #endif GtkPaperSize *paperSize = gtk_page_setup_get_paper_size (aPageSetup); if (!paperSize) { return NS_ERROR_FAILURE; } aSettings->SetPaperSizeType (nsIPrintSettings::kPaperSizeDefined); aSettings->SetPaperWidth (gtk_paper_size_get_width (paperSize, GTK_UNIT_MM)); aSettings->SetPaperHeight (gtk_paper_size_get_height (paperSize, GTK_UNIT_MM)); #ifdef HAVE_NSIPRINTSETTINGS_SETPAPERNAME aSettings->SetPaperName (NS_ConvertUTF8toUTF16 (gtk_paper_size_get_name (paperSize)).get ()); #else { /* Mozilla bug https://bugzilla.mozilla.org/show_bug.cgi?id=307404 * means that we cannot actually use any paper sizes except mozilla's * builtin list, and we must refer to them *by name*! */ static const struct { const char gtkPaperName[13]; const char mozPaperName[10]; } paperTable [] = { { GTK_PAPER_NAME_A5, "A5" }, { GTK_PAPER_NAME_A4, "A4" }, { GTK_PAPER_NAME_A3, "A3" }, { GTK_PAPER_NAME_LETTER, "Letter" }, { GTK_PAPER_NAME_LEGAL, "Legal" }, { GTK_PAPER_NAME_EXECUTIVE, "Executive" }, }; const char *paperName = gtk_paper_size_get_name (paperSize); PRUint32 i; for (i = 0; i < G_N_ELEMENTS (paperTable); i++) { if (g_ascii_strcasecmp (paperTable[i].gtkPaperName, paperName) == 0) { paperName = paperTable[i].mozPaperName; break; } } if (i == G_N_ELEMENTS (paperTable)) { /* Not in table, fall back to A4 */ g_warning ("Unknown paper name '%s', falling back to A4", gtk_paper_size_get_name (paperSize)); paperName = paperTable[1].mozPaperName; } aSettings->SetPaperName (NS_ConvertUTF8toUTF16 (paperName).get ()); } #endif /* !HAVE_NSIPRINTSETTINGS_SETPAPERNAME */ /* Sucky mozilla wants margins in inch! */ aSettings->SetMarginTop (gtk_page_setup_get_top_margin (aPageSetup, GTK_UNIT_INCH)); aSettings->SetMarginBottom (gtk_page_setup_get_bottom_margin (aPageSetup, GTK_UNIT_INCH)); aSettings->SetMarginLeft (gtk_page_setup_get_left_margin (aPageSetup, GTK_UNIT_INCH)); aSettings->SetMarginRight (gtk_page_setup_get_right_margin (aPageSetup, GTK_UNIT_INCH)); aSettings->SetHeaderStrLeft (eel_gconf_get_boolean (CONF_PRINT_PAGE_TITLE) ? LITERAL ("&T") : LITERAL ("")); aSettings->SetHeaderStrCenter (LITERAL ("")); aSettings->SetHeaderStrRight (eel_gconf_get_boolean (CONF_PRINT_PAGE_URL) ? LITERAL ("&U") : LITERAL ("")); aSettings->SetFooterStrLeft (eel_gconf_get_boolean (CONF_PRINT_PAGE_NUMBERS) ? LITERAL ("&PT") : LITERAL ("")); aSettings->SetFooterStrCenter (LITERAL ("")); aSettings->SetFooterStrRight (eel_gconf_get_boolean (CONF_PRINT_DATE) ? LITERAL ("&D") : LITERAL ("")); aSettings->SetPrintFrameType (aPrintFrames); aSettings->SetPrintFrameTypeUsage (nsIPrintSettings::kUseSettingWhenPossible); /* FIXME: only if GTK_PRINT_CAPABILITY_SCALE is not set? */ aSettings->SetScaling (gtk_print_settings_get_scale (aGtkSettings) / 100.0); gtk_print_settings_set_scale (aGtkSettings, 1.0); aSettings->SetShrinkToFit (PR_FALSE); /* FIXME setting */ aSettings->SetPrintBGColors (eel_gconf_get_boolean (CONF_PRINT_BG_COLORS) != FALSE); aSettings->SetPrintBGImages (eel_gconf_get_boolean (CONF_PRINT_BG_IMAGES) != FALSE); /* aSettings->SetPlexName (LITERAL ("default")); */ /* aSettings->SetColorspace (LITERAL ("default")); */ /* aSettings->SetResolutionName (LITERAL ("default")); */ /* aSettings->SetDownloadFonts (PR_TRUE); */ /* Unset those setting that we can handle, so they don't get applied * again for the print job. */ /* gtk_print_settings_set_collate (aGtkSettings, FALSE); not yet */ /* FIXME: Unset the orientation for the print job? */ /* gtk_page_setup_set_orientation (aPageSetup, GTK_PAGE_ORIENTATION_PORTRAIT); */ /* FIXME: unset output format -> "ps" ? */ return NS_OK; }
// This utility method isn't in the string glue on the branch. inline void CopyASCIItoUCS2(const nsACString &src, nsAString &dest) { NS_CStringToUTF16(src, NS_CSTRING_ENCODING_ASCII, dest); }