NS_IMETHODIMP nsGNOMEShellService::SetDefaultBrowser(PRBool aClaimAllTypes, PRBool aForAllUsers) { #ifdef DEBUG if (aForAllUsers) NS_WARNING("Setting the default browser for all users is not yet supported"); #endif nsCOMPtr<nsIGConfService> gconf = do_GetService(NS_GCONFSERVICE_CONTRACTID); if (gconf) { nsCAutoString appKeyValue(mAppPath); appKeyValue.Append(" \"%s\""); for (unsigned int i = 0; i < NS_ARRAY_LENGTH(appProtocols); ++i) { if (appProtocols[i].essential || aClaimAllTypes) { gconf->SetAppForProtocol(nsDependentCString(appProtocols[i].name), appKeyValue); } } } // set handler for .html and xhtml files and MIME types: if (aClaimAllTypes) { nsresult rv; nsCOMPtr<nsIGIOService> giovfs = do_GetService(NS_GIOSERVICE_CONTRACTID, &rv); NS_ENSURE_SUCCESS(rv, NS_OK); nsCOMPtr<nsIStringBundleService> bundleService = do_GetService(NS_STRINGBUNDLE_CONTRACTID, &rv); NS_ENSURE_SUCCESS(rv, rv); nsCOMPtr<nsIStringBundle> brandBundle; rv = bundleService->CreateBundle(BRAND_PROPERTIES, getter_AddRefs(brandBundle)); NS_ENSURE_SUCCESS(rv, rv); nsString brandShortName, brandFullName; brandBundle->GetStringFromName(NS_LITERAL_STRING("brandShortName").get(), getter_Copies(brandShortName)); brandBundle->GetStringFromName(NS_LITERAL_STRING("brandFullName").get(), getter_Copies(brandFullName)); // use brandShortName as the application id. NS_ConvertUTF16toUTF8 id(brandShortName); nsCOMPtr<nsIGIOMimeApp> appInfo; rv = giovfs->CreateAppFromCommand(mAppPath, id, getter_AddRefs(appInfo)); NS_ENSURE_SUCCESS(rv, rv); // Add mime types for html, xhtml extension and set app to just created appinfo. for (unsigned int i = 0; i < NS_ARRAY_LENGTH(appTypes); ++i) { appInfo->SetAsDefaultForMimeType(nsDependentCString(appTypes[i].mimeType)); appInfo->SetAsDefaultForFileExtensions(nsDependentCString(appTypes[i].extensions)); } } return NS_OK; }
NS_IMETHODIMP nsGNOMEShellService::SetDefaultBrowser(PRBool aClaimAllTypes, PRBool aForAllUsers) { #ifdef DEBUG if (aForAllUsers) NS_WARNING("Setting the default browser for all users is not yet supported"); #endif nsCOMPtr<nsIGConfService> gconf = do_GetService(NS_GCONFSERVICE_CONTRACTID); nsCAutoString schemeList; nsCAutoString appKeyValue(mAppPath + NS_LITERAL_CSTRING(" \"%s\"")); unsigned int i; for (i = 0; i < NS_ARRAY_LENGTH(appProtocols); ++i) { schemeList.Append(nsDependentCString(appProtocols[i].name) + NS_LITERAL_CSTRING(",")); if (appProtocols[i].essential || aClaimAllTypes) { gconf->SetAppForProtocol(nsDependentCString(appProtocols[i].name), appKeyValue); } } if (aClaimAllTypes) { nsCOMPtr<nsIGnomeVFSService> vfs = do_GetService(NS_GNOMEVFSSERVICE_CONTRACTID); nsCOMPtr<nsIStringBundleService> bundleService = do_GetService(NS_STRINGBUNDLE_CONTRACTID); NS_ENSURE_TRUE(bundleService, NS_ERROR_OUT_OF_MEMORY); nsCOMPtr<nsIStringBundle> brandBundle; bundleService->CreateBundle(BRAND_PROPERTIES, getter_AddRefs(brandBundle)); NS_ENSURE_TRUE(brandBundle, NS_ERROR_FAILURE); nsXPIDLString brandShortName, brandFullName; brandBundle->GetStringFromName(NS_LITERAL_STRING("brandShortName").get(), getter_Copies(brandShortName)); brandBundle->GetStringFromName(NS_LITERAL_STRING("brandFullName").get(), getter_Copies(brandFullName)); // use brandShortName as the application id. NS_ConvertUTF16toUTF8 id(brandShortName); vfs->SetAppStringKey(id, nsIGnomeVFSService::APP_KEY_COMMAND, mAppPath); vfs->SetAppStringKey(id, nsIGnomeVFSService::APP_KEY_NAME, NS_ConvertUTF16toUTF8(brandFullName)); // We don't want to be the default handler for "file:", but we do // want Nautilus to know that we support file: if the MIME type is // one that we can handle. schemeList.Append("file"); vfs->SetAppStringKey(id, nsIGnomeVFSService::APP_KEY_SUPPORTED_URI_SCHEMES, schemeList); vfs->SetAppStringKey(id, nsIGnomeVFSService::APP_KEY_EXPECTS_URIS, NS_LITERAL_CSTRING("true")); vfs->SetAppBoolKey(id, nsIGnomeVFSService::APP_KEY_CAN_OPEN_MULTIPLE, PR_FALSE); vfs->SetAppBoolKey(id, nsIGnomeVFSService::APP_KEY_REQUIRES_TERMINAL, PR_FALSE); // Copy icons/document.png to ~/.icons/firefox-document.png nsCAutoString iconFilePath(mAppPath); PRInt32 lastSlash = iconFilePath.RFindChar(PRUnichar('/')); if (lastSlash == -1) { NS_ERROR("no slash in executable path?"); } else { iconFilePath.Truncate(lastSlash); nsCOMPtr<nsILocalFile> iconFile; NS_NewNativeLocalFile(iconFilePath, PR_FALSE, getter_AddRefs(iconFile)); if (iconFile) { iconFile->AppendRelativeNativePath(NS_LITERAL_CSTRING("icons/document.png")); nsCOMPtr<nsILocalFile> userIconPath; NS_NewNativeLocalFile(nsDependentCString(PR_GetEnv("HOME")), PR_FALSE, getter_AddRefs(userIconPath)); if (userIconPath) { userIconPath->AppendNative(NS_LITERAL_CSTRING(".icons")); iconFile->CopyToNative(userIconPath, nsDependentCString(kDocumentIconPath)); } } } for (i = 0; i < NS_ARRAY_LENGTH(appTypes); ++i) { vfs->AddMimeType(id, nsDependentCString(appTypes[i].mimeType)); vfs->SetMimeExtensions(nsDependentCString(appTypes[i].mimeType), nsDependentCString(appTypes[i].extensions)); vfs->SetAppForMimeType(nsDependentCString(appTypes[i].mimeType), id); vfs->SetIconForMimeType(nsDependentCString(appTypes[i].mimeType), NS_LITERAL_CSTRING(kDocumentIconPath)); } vfs->SyncAppRegistry(); } return NS_OK; }