Repo created

This commit is contained in:
Fr4nz D13trich 2025-11-22 14:04:28 +01:00
parent 81b91f4139
commit f8c34fa5ee
22732 changed files with 4815320 additions and 2 deletions

View file

@ -0,0 +1 @@
thomasanderson@chromium.org

View file

@ -0,0 +1,31 @@
// Copyright (c) 2012 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
#include "base/nix/mime_util_xdg.h"
#include "base/files/file_path.h"
#include "base/no_destructor.h"
#include "base/synchronization/lock.h"
#include "base/third_party/xdg_mime/xdgmime.h"
#include "base/threading/scoped_blocking_call.h"
namespace base {
namespace nix {
std::string GetFileMimeType(const FilePath& filepath) {
if (filepath.empty())
return std::string();
base::ScopedBlockingCall scoped_blocking_call(FROM_HERE,
base::BlockingType::MAY_BLOCK);
// None of the XDG stuff is thread-safe, so serialize all access under this
// lock.
static NoDestructor<Lock> mime_util_xdg_lock;
AutoLock scoped_lock(*mime_util_xdg_lock);
return xdg_mime_get_mime_type_from_file_name(filepath.value().c_str());
}
} // namespace nix
} // namespace base

View file

@ -0,0 +1,36 @@
// Copyright (c) 2011 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
#ifndef BASE_NIX_MIME_UTIL_XDG_H_
#define BASE_NIX_MIME_UTIL_XDG_H_
#include <string>
#include "base/base_export.h"
#include "build/build_config.h"
namespace base {
class FilePath;
namespace nix {
// Gets the mime type for a file at |filepath|.
//
// The mime type is calculated based only on the file name of |filepath|. In
// particular |filepath| will not be touched on disk and |filepath| doesn't even
// have to exist. This means that the function does not work for directories
// (i.e. |filepath| is assumed to be a path to a file).
//
// Note that this function might need to read from disk the mime-types data
// provided by the OS. Therefore this function should not be called from
// threads that disallow IO via base::ThreadRestrictions::SetIOAllowed(false).
//
// If the mime type is unknown, this will return application/octet-stream.
BASE_EXPORT std::string GetFileMimeType(const FilePath& filepath);
} // namespace nix
} // namespace base
#endif // BASE_NIX_MIME_UTIL_XDG_H_

View file

@ -0,0 +1,155 @@
// Copyright (c) 2012 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
#include "base/nix/xdg_util.h"
#include <string>
#include "base/base_paths.h"
#include "base/environment.h"
#include "base/files/file_path.h"
#include "base/files/file_util.h"
#include "base/path_service.h"
#include "base/strings/string_split.h"
#include "base/strings/string_util.h"
#include "base/third_party/xdg_user_dirs/xdg_user_dir_lookup.h"
namespace {
// The KDE session version environment variable introduced in KDE 4.
const char kKDESessionEnvVar[] = "KDE_SESSION_VERSION";
} // namespace
namespace base {
namespace nix {
const char kDotConfigDir[] = ".config";
const char kXdgConfigHomeEnvVar[] = "XDG_CONFIG_HOME";
FilePath GetXDGDirectory(Environment* env, const char* env_name,
const char* fallback_dir) {
FilePath path;
std::string env_value;
if (env->GetVar(env_name, &env_value) && !env_value.empty()) {
path = FilePath(env_value);
} else {
PathService::Get(DIR_HOME, &path);
path = path.Append(fallback_dir);
}
return path.StripTrailingSeparators();
}
FilePath GetXDGUserDirectory(const char* dir_name, const char* fallback_dir) {
FilePath path;
char* xdg_dir = xdg_user_dir_lookup(dir_name);
if (xdg_dir) {
path = FilePath(xdg_dir);
free(xdg_dir);
} else {
PathService::Get(DIR_HOME, &path);
path = path.Append(fallback_dir);
}
return path.StripTrailingSeparators();
}
DesktopEnvironment GetDesktopEnvironment(Environment* env) {
// XDG_CURRENT_DESKTOP is the newest standard circa 2012.
std::string xdg_current_desktop;
if (env->GetVar("XDG_CURRENT_DESKTOP", &xdg_current_desktop)) {
// It could have multiple values separated by colon in priority order.
for (const auto& value : SplitStringPiece(
xdg_current_desktop, ":", TRIM_WHITESPACE, SPLIT_WANT_NONEMPTY)) {
if (value == "Unity") {
// gnome-fallback sessions set XDG_CURRENT_DESKTOP to Unity
// DESKTOP_SESSION can be gnome-fallback or gnome-fallback-compiz
std::string desktop_session;
if (env->GetVar("DESKTOP_SESSION", &desktop_session) &&
desktop_session.find("gnome-fallback") != std::string::npos) {
return DESKTOP_ENVIRONMENT_GNOME;
}
return DESKTOP_ENVIRONMENT_UNITY;
}
if (value == "GNOME")
return DESKTOP_ENVIRONMENT_GNOME;
if (value == "X-Cinnamon")
return DESKTOP_ENVIRONMENT_CINNAMON;
if (value == "KDE") {
std::string kde_session;
if (env->GetVar(kKDESessionEnvVar, &kde_session)) {
if (kde_session == "5") {
return DESKTOP_ENVIRONMENT_KDE5;
}
}
return DESKTOP_ENVIRONMENT_KDE4;
}
if (value == "Pantheon")
return DESKTOP_ENVIRONMENT_PANTHEON;
if (value == "XFCE")
return DESKTOP_ENVIRONMENT_XFCE;
}
}
// DESKTOP_SESSION was what everyone used in 2010.
std::string desktop_session;
if (env->GetVar("DESKTOP_SESSION", &desktop_session)) {
if (desktop_session == "gnome" || desktop_session == "mate")
return DESKTOP_ENVIRONMENT_GNOME;
if (desktop_session == "kde4" || desktop_session == "kde-plasma")
return DESKTOP_ENVIRONMENT_KDE4;
if (desktop_session == "kde") {
// This may mean KDE4 on newer systems, so we have to check.
if (env->HasVar(kKDESessionEnvVar))
return DESKTOP_ENVIRONMENT_KDE4;
return DESKTOP_ENVIRONMENT_KDE3;
}
if (desktop_session.find("xfce") != std::string::npos ||
desktop_session == "xubuntu") {
return DESKTOP_ENVIRONMENT_XFCE;
}
}
// Fall back on some older environment variables.
// Useful particularly in the DESKTOP_SESSION=default case.
if (env->HasVar("GNOME_DESKTOP_SESSION_ID"))
return DESKTOP_ENVIRONMENT_GNOME;
if (env->HasVar("KDE_FULL_SESSION")) {
if (env->HasVar(kKDESessionEnvVar))
return DESKTOP_ENVIRONMENT_KDE4;
return DESKTOP_ENVIRONMENT_KDE3;
}
return DESKTOP_ENVIRONMENT_OTHER;
}
const char* GetDesktopEnvironmentName(DesktopEnvironment env) {
switch (env) {
case DESKTOP_ENVIRONMENT_OTHER:
return nullptr;
case DESKTOP_ENVIRONMENT_CINNAMON:
return "CINNAMON";
case DESKTOP_ENVIRONMENT_GNOME:
return "GNOME";
case DESKTOP_ENVIRONMENT_KDE3:
return "KDE3";
case DESKTOP_ENVIRONMENT_KDE4:
return "KDE4";
case DESKTOP_ENVIRONMENT_KDE5:
return "KDE5";
case DESKTOP_ENVIRONMENT_PANTHEON:
return "PANTHEON";
case DESKTOP_ENVIRONMENT_UNITY:
return "UNITY";
case DESKTOP_ENVIRONMENT_XFCE:
return "XFCE";
}
return nullptr;
}
const char* GetDesktopEnvironmentName(Environment* env) {
return GetDesktopEnvironmentName(GetDesktopEnvironment(env));
}
} // namespace nix
} // namespace base

View file

@ -0,0 +1,77 @@
// Copyright (c) 2012 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
#ifndef BASE_NIX_XDG_UTIL_H_
#define BASE_NIX_XDG_UTIL_H_
// XDG refers to http://en.wikipedia.org/wiki/Freedesktop.org .
// This file contains utilities found across free desktop environments.
//
// TODO(brettw) this file should be in app/x11, but is currently used by
// net. We should have a net API to allow the embedder to specify the behavior
// that it uses XDG for, and then move this file.
#include "base/base_export.h"
#ifdef nix
#error asdf
#endif
namespace base {
class Environment;
class FilePath;
namespace nix {
// The default XDG config directory name.
BASE_EXPORT extern const char kDotConfigDir[];
// The XDG config directory environment variable.
BASE_EXPORT extern const char kXdgConfigHomeEnvVar[];
// Utility function for getting XDG directories.
// |env_name| is the name of an environment variable that we want to use to get
// a directory path. |fallback_dir| is the directory relative to $HOME that we
// use if |env_name| cannot be found or is empty. |fallback_dir| may be NULL.
// Examples of |env_name| are XDG_CONFIG_HOME and XDG_DATA_HOME.
BASE_EXPORT FilePath GetXDGDirectory(Environment* env, const char* env_name,
const char* fallback_dir);
// Wrapper around xdg_user_dir_lookup() from src/base/third_party/xdg-user-dirs
// This looks up "well known" user directories like the desktop and music
// folder. Examples of |dir_name| are DESKTOP and MUSIC.
BASE_EXPORT FilePath GetXDGUserDirectory(const char* dir_name,
const char* fallback_dir);
enum DesktopEnvironment {
DESKTOP_ENVIRONMENT_OTHER,
DESKTOP_ENVIRONMENT_CINNAMON,
DESKTOP_ENVIRONMENT_GNOME,
// KDE3, KDE4 and KDE5 are sufficiently different that we count
// them as different desktop environments here.
DESKTOP_ENVIRONMENT_KDE3,
DESKTOP_ENVIRONMENT_KDE4,
DESKTOP_ENVIRONMENT_KDE5,
DESKTOP_ENVIRONMENT_PANTHEON,
DESKTOP_ENVIRONMENT_UNITY,
DESKTOP_ENVIRONMENT_XFCE,
};
// Return an entry from the DesktopEnvironment enum with a best guess
// of which desktop environment we're using. We use this to know when
// to attempt to use preferences from the desktop environment --
// proxy settings, password manager, etc.
BASE_EXPORT DesktopEnvironment GetDesktopEnvironment(Environment* env);
// Return a string representation of the given desktop environment.
// May return NULL in the case of DESKTOP_ENVIRONMENT_OTHER.
BASE_EXPORT const char* GetDesktopEnvironmentName(DesktopEnvironment env);
// Convenience wrapper that calls GetDesktopEnvironment() first.
BASE_EXPORT const char* GetDesktopEnvironmentName(Environment* env);
} // namespace nix
} // namespace base
#endif // BASE_NIX_XDG_UTIL_H_