# HG changeset patch # User Ian Neal # Date 1623162001 14400 # Parent bfe2b1171f92bfdbdc95e15d835e0b83c2840e23 Bug 1544739 - Part 4: Update GNOME shell service - Change to CheckHandlerMatchesAppName. r=frg a=frg diff --git a/suite/components/shell/nsGNOMEShellService.cpp b/suite/components/shell/nsGNOMEShellService.cpp --- a/suite/components/shell/nsGNOMEShellService.cpp +++ b/suite/components/shell/nsGNOMEShellService.cpp @@ -129,38 +129,49 @@ bool nsGNOMEShellService::GetAppPathFrom mAppIsInPath = true; } g_free(tmp); return true; } bool -nsGNOMEShellService::HandlerMatchesAppName(const char* aHandler) +nsGNOMEShellService::CheckHandlerMatchesAppName(const nsACString &handler) const { - bool matches = false; gint argc; gchar** argv; - if (g_shell_parse_argv(aHandler, &argc, &argv, nullptr) && argc > 0) { - gchar* command = nullptr; - if (!mUseLocaleFilenames) - command = g_find_program_in_path(argv[0]); - else { - gchar* nativeFile = g_filename_from_utf8(argv[0], -1, - nullptr, nullptr, nullptr); - if (nativeFile) { - command = g_find_program_in_path(nativeFile); - g_free(nativeFile); - } - } - matches = command && mAppPath.Equals(command); - g_free(command); + nsAutoCString command(handler); + + // The string will be something of the form: [/path/to/]application "%s" + // We want to remove all of the parameters and get just the binary name. + + if (g_shell_parse_argv(command.get(), &argc, &argv, nullptr) && argc > 0) { + command.Assign(argv[0]); g_strfreev(argv); } + gchar *commandPath; + if (mUseLocaleFilenames) { + gchar *nativePath = + g_filename_from_utf8(command.get(), -1, nullptr, nullptr, nullptr); + if (!nativePath) { + NS_ERROR("Error converting path to filesystem encoding"); + return false; + } + + commandPath = g_find_program_in_path(nativePath); + g_free(nativePath); + } else { + commandPath = g_find_program_in_path(command.get()); + } + + if (!commandPath) return false; + + bool matches = mAppPath.Equals(commandPath); + g_free(commandPath); return matches; } NS_IMETHODIMP nsGNOMEShellService::IsDefaultClient(bool aStartupCheck, uint16_t aApps, bool* aIsDefaultClient) { *aIsDefaultClient = false; @@ -173,17 +184,17 @@ nsGNOMEShellService::IsDefaultClient(boo if (aApps & gProtocols[i].app) { nsDependentCString protocol(gProtocols[i].protocol); if (giovfs) { giovfs->GetAppForURIScheme(protocol, getter_AddRefs(app)); if (!app) return NS_OK; if (NS_SUCCEEDED(app->GetCommand(handler)) && - !HandlerMatchesAppName(handler.get())) + !CheckHandlerMatchesAppName(handler)) return NS_OK; } } } *aIsDefaultClient = true; return NS_OK; } diff --git a/suite/components/shell/nsGNOMEShellService.h b/suite/components/shell/nsGNOMEShellService.h --- a/suite/components/shell/nsGNOMEShellService.h +++ b/suite/components/shell/nsGNOMEShellService.h @@ -22,17 +22,17 @@ public: NS_DECL_NSISHELLSERVICE NS_DECL_NSIGNOMESHELLSERVICE nsresult Init(); private: ~nsGNOMEShellService() {} - bool HandlerMatchesAppName(const char* aHandler); + bool CheckHandlerMatchesAppName(const nsACString& handler) const; bool GetAppPathFromLauncher(); bool mUseLocaleFilenames; nsCString mAppPath; bool mAppIsInPath; }; #endif // nsgnomeshellservice_h____