#ifdef UNSAFE_BUFFERS_BUILD
#pragma allow_unsafe_buffers
#endif
#include "chrome/browser/shell_integration_linux.h"
#include <fcntl.h>
#include <stddef.h>
#include <stdlib.h>
#include <sys/stat.h>
#include <sys/types.h>
#include <unistd.h>
#include <memory>
#include <optional>
#include <sstream>
#include <string>
#include <utility>
#include <vector>
#include "base/base_paths.h"
#include "base/command_line.h"
#include "base/environment.h"
#include "base/files/file_enumerator.h"
#include "base/files/file_path.h"
#include "base/files/file_util.h"
#include "base/files/safe_base_name.h"
#include "base/i18n/file_util_icu.h"
#include "base/logging.h"
#include "base/memory/ref_counted_memory.h"
#include "base/nix/xdg_util.h"
#include "base/path_service.h"
#include "base/posix/eintr_wrapper.h"
#include "base/process/kill.h"
#include "base/process/launch.h"
#include "base/strings/strcat.h"
#include "base/strings/string_number_conversions.h"
#include "base/strings/string_util.h"
#include "base/strings/stringprintf.h"
#include "base/strings/utf_string_conversions.h"
#include "base/threading/scoped_blocking_call.h"
#include "base/threading/thread.h"
#include "base/threading/thread_restrictions.h"
#include "build/branding_buildflags.h"
#include "build/build_config.h"
#include "build/chromeos_buildflags.h"
#include "chrome/browser/shell_integration.h"
#include "chrome/browser/web_applications/os_integration/web_app_shortcut.h"
#include "chrome/browser/web_applications/web_app_helpers.h"
#include "chrome/common/buildflags.h"
#include "chrome/common/channel_info.h"
#include "chrome/common/chrome_constants.h"
#include "chrome/common/chrome_switches.h"
#include "chrome/grit/branded_strings.h"
#include "chrome/grit/chrome_unscaled_resources.h"
#include "components/version_info/version_info.h"
#include "third_party/libxml/chromium/xml_writer.h"
#include "third_party/re2/src/re2/re2.h"
#include "ui/base/l10n/l10n_util.h"
#include "ui/base/resource/resource_bundle.h"
#include "ui/gfx/image/image_family.h"
#include "ui/ozone/public/ozone_platform.h"
#include "ui/ozone/public/platform_utils.h"
#include "url/gurl.h"
#if defined(USE_GLIB)
#include <glib.h>
#endif
namespace shell_integration_linux {
const char kXdgSettings[] = …;
const char kXdgSettingsDefaultBrowser[] = …;
const char kXdgSettingsDefaultSchemeHandler[] = …;
bool GetChromeVersionOfScript(const std::string& script,
std::string* chrome_version) { … }
const int EXIT_XDG_SETTINGS_SYNTAX_ERROR = …;
bool SetDefaultWebClient(const std::string& scheme) { … }
shell_integration::DefaultWebClientState GetIsDefaultWebClient(
const std::string& scheme) { … }
std::string GetDesktopBaseName(const std::string& desktop_file_name) { … }
namespace {
#if defined(USE_GLIB)
std::string QuoteArgForDesktopFileExec(const std::string& arg) { … }
std::string QuoteCommandLineForDesktopFileExec(
const base::CommandLine& command_line) { … }
#endif
#if defined(USE_GLIB)
const char kDesktopEntry[] = …;
const char kXdgOpenShebang[] = …;
void SetActionsForDesktopApplication(
const base::CommandLine& command_line,
GKeyFile* key_file,
std::set<web_app::DesktopActionInfo> action_info) { … }
#endif
base::FilePath GetDesktopFileForDefaultSchemeHandler(base::Environment* env,
const GURL& url) { … }
std::string GetDesktopEntryStringValueFromFromDesktopFile(
const std::string& key,
const std::string& shortcut_contents) { … }
}
class [[maybe_unused, nodiscard]] LaunchXdgUtilityScopedAllowBaseSyncPrimitives
: public base::ScopedAllowBaseSyncPrimitives{ … };
bool LaunchXdgUtility(const std::vector<std::string>& argv, int* exit_code) { … }
std::string GetWMClassFromAppName(std::string app_name) { … }
std::string GetXdgAppIdForWebApp(std::string app_name,
const base::FilePath& profile_path) { … }
namespace internal {
std::string GetDesktopEntryStringValueFromFromDesktopFileForTest(
const std::string& key,
const std::string& shortcut_contents) { … }
bool GetNoDisplayFromDesktopFile(const std::string& shortcut_contents) { … }
base::FilePath GetChromeExePath() { … }
std::string GetProgramClassName(const base::CommandLine& command_line,
const std::string& desktop_file_name) { … }
std::string GetProgramClassClass(const base::CommandLine& command_line,
const std::string& desktop_file_name) { … }
}
std::string GetProgramClassName() { … }
std::string GetProgramClassClass() { … }
std::string GetIconName() { … }
bool GetExistingShortcutContents(base::Environment* env,
const base::FilePath& desktop_filename,
std::string* output) { … }
std::optional<base::SafeBaseName> GetUniqueWebShortcutFilename(
const std::string& name) { … }
std::vector<base::FilePath> GetExistingProfileShortcutFilenames(
const base::FilePath& profile_path,
const base::FilePath& directory) { … }
std::string GetDesktopFileContents(
const base::FilePath& chrome_exe_path,
const std::string& app_name,
const GURL& url,
const std::string& extension_id,
const std::u16string& title,
const std::string& icon_name,
const base::FilePath& profile_path,
const std::string& categories,
const std::string& mime_type,
bool no_display,
const std::string& run_on_os_login_mode,
std::set<web_app::DesktopActionInfo> action_info) { … }
std::string GetDesktopFileContentsForCommand(
const base::CommandLine& command_line,
const std::string& app_name,
const GURL& url,
const std::u16string& title,
const std::string& icon_name,
const std::string& categories,
const std::string& mime_type,
bool no_display,
std::set<web_app::DesktopActionInfo> action_info) { … }
std::string GetDesktopFileContentsForUrlShortcut(
const std::string& title,
const GURL& url,
const base::FilePath& icon_path,
const base::FilePath& profile_path) { … }
std::string GetDirectoryFileContents(const std::u16string& title,
const std::string& icon_name) { … }
base::FilePath GetMimeTypesRegistrationFilename(
const base::FilePath& profile_path,
const webapps::AppId& app_id) { … }
std::string GetMimeTypesRegistrationFileContents(
const apps::FileHandlers& file_handlers) { … }
}
namespace shell_integration {
bool SetAsDefaultBrowser() { … }
bool SetAsDefaultClientForScheme(const std::string& scheme) { … }
std::u16string GetApplicationNameForScheme(const GURL& url) { … }
DefaultWebClientState GetDefaultBrowser() { … }
bool IsFirefoxDefaultBrowser() { … }
DefaultWebClientState IsDefaultClientForScheme(const std::string& scheme) { … }
namespace internal {
DefaultWebClientSetPermission GetPlatformSpecificDefaultWebClientSetPermission(
WebClientSetMethod method) { … }
}
}