Bug 611953 - Part 1: GNOME 3.0 readiness; r=roc,karlt

This commit is contained in:
Chris Coulson 2011-04-12 16:10:09 -04:00
parent 6147cfffcc
commit 05f6e02161
2 changed files with 46 additions and 3 deletions

View File

@ -120,6 +120,9 @@ nsGNOMEShellService::Init()
// the locale encoding. If it's not set, they use UTF-8.
mUseLocaleFilenames = PR_GetEnv("G_BROKEN_FILENAMES") != nsnull;
if (GetAppPathFromLauncher())
return NS_OK;
nsCOMPtr<nsIProperties> dirSvc
(do_GetService("@mozilla.org/file/directory_service;1"));
NS_ENSURE_TRUE(dirSvc, NS_ERROR_NOT_AVAILABLE);
@ -137,6 +140,34 @@ nsGNOMEShellService::Init()
NS_IMPL_ISUPPORTS1(nsGNOMEShellService, nsIShellService)
PRBool
nsGNOMEShellService::GetAppPathFromLauncher()
{
gchar *tmp;
const char *launcher = PR_GetEnv("MOZ_APP_LAUNCHER");
if (!launcher)
return PR_FALSE;
if (g_path_is_absolute(launcher)) {
mAppPath = launcher;
tmp = g_path_get_basename(launcher);
gchar *fullpath = g_find_program_in_path(tmp);
if (fullpath && mAppPath.Equals(fullpath))
mAppIsInPath = PR_TRUE;
g_free(fullpath);
} else {
tmp = g_find_program_in_path(launcher);
if (!tmp)
return PR_FALSE;
mAppPath = tmp;
mAppIsInPath = PR_TRUE;
}
g_free(tmp);
return PR_TRUE;
}
PRBool
nsGNOMEShellService::KeyMatchesAppName(const char *aKeyValue) const
{
@ -215,8 +246,18 @@ nsGNOMEShellService::SetDefaultBrowser(PRBool aClaimAllTypes,
nsCOMPtr<nsIGConfService> gconf = do_GetService(NS_GCONFSERVICE_CONTRACTID);
if (gconf) {
nsCAutoString appKeyValue(mAppPath);
appKeyValue.Append(" \"%s\"");
nsCAutoString appKeyValue;
if(mAppIsInPath) {
// mAppPath is in the users path, so use only the basename as the launcher
gchar *tmp = g_path_get_basename(mAppPath.get());
appKeyValue = tmp;
g_free(tmp);
} else {
appKeyValue = mAppPath;
}
appKeyValue.AppendLiteral(" %s");
for (unsigned int i = 0; i < NS_ARRAY_LENGTH(appProtocols); ++i) {
if (appProtocols[i].essential || aClaimAllTypes) {
gconf->SetAppForProtocol(nsDependentCString(appProtocols[i].name),

View File

@ -43,7 +43,7 @@
class nsGNOMEShellService : public nsIShellService
{
public:
nsGNOMEShellService() : mCheckedThisSession(PR_FALSE) { }
nsGNOMEShellService() : mCheckedThisSession(PR_FALSE), mAppIsInPath(PR_FALSE) { }
NS_DECL_ISUPPORTS
NS_DECL_NSISHELLSERVICE
@ -55,9 +55,11 @@ private:
NS_HIDDEN_(PRBool) KeyMatchesAppName(const char *aKeyValue) const;
NS_HIDDEN_(PRBool) GetAppPathFromLauncher();
PRPackedBool mCheckedThisSession;
PRPackedBool mUseLocaleFilenames;
nsCString mAppPath;
PRPackedBool mAppIsInPath;
};
#endif // nsgnomeshellservice_h____