#ifdef UNSAFE_BUFFERS_BUILD
#pragma allow_unsafe_buffers
#endif
#include "chrome/browser/web_applications/os_integration/web_app_shortcut.h"
#include <functional>
#include <memory>
#include <optional>
#include <string>
#include <vector>
#include "base/files/file_path.h"
#include "base/files/file_util.h"
#include "base/functional/bind.h"
#include "base/functional/callback.h"
#include "base/functional/callback_helpers.h"
#include "base/logging.h"
#include "base/memory/raw_ptr.h"
#include "base/memory/scoped_refptr.h"
#include "base/run_loop.h"
#include "base/stl_util.h"
#include "base/strings/string_util.h"
#include "base/strings/utf_string_conversions.h"
#include "base/synchronization/waitable_event.h"
#include "base/task/bind_post_task.h"
#include "base/task/lazy_thread_pool_task_runner.h"
#include "base/task/sequenced_task_runner.h"
#include "base/task/task_traits.h"
#include "base/task/thread_pool.h"
#include "base/thread_annotations.h"
#include "base/threading/thread_restrictions.h"
#include "build/build_config.h"
#include "chrome/browser/web_applications/os_integration/file_handling_sub_manager.h"
#include "chrome/browser/web_applications/proto/web_app_os_integration_state.pb.h"
#include "chrome/browser/web_applications/web_app.h"
#include "chrome/browser/web_applications/web_app_constants.h"
#include "chrome/browser/web_applications/web_app_helpers.h"
#include "chrome/browser/web_applications/web_app_icon_manager.h"
#include "chrome/browser/web_applications/web_app_install_info.h"
#include "chrome/common/chrome_constants.h"
#include "content/public/browser/browser_task_traits.h"
#include "content/public/browser/browser_thread.h"
#include "extensions/grit/extensions_browser_resources.h"
#include "skia/ext/image_operations.h"
#include "third_party/protobuf/src/google/protobuf/repeated_field.h"
#include "third_party/re2/src/re2/re2.h"
#include "third_party/skia/include/core/SkBitmap.h"
#include "ui/base/resource/resource_bundle.h"
#include "ui/gfx/image/image_skia.h"
#include "ui/gfx/image/image_skia_rep_default.h"
#if BUILDFLAG(IS_WIN)
#include "ui/gfx/icon_util.h"
#endif
#if BUILDFLAG(IS_MAC)
#include "chrome/browser/web_applications/os_integration/mac/app_shim_registry.h"
#endif
BrowserThread;
namespace web_app {
namespace …
ShortcutInfo::ShortcutInfo() = default;
ShortcutInfo::~ShortcutInfo() { … }
std::unique_ptr<ShortcutInfo> BuildShortcutInfoWithoutFavicon(
const webapps::AppId& app_id,
const GURL& start_url,
const base::FilePath& profile_path,
const std::string& profile_name,
const proto::WebAppOsIntegrationState& state) { … }
void PopulateFaviconPurposeForShortcutInfo(
const WebApp* app,
WebAppIconManager& icon_manager,
IconPurpose purpose,
base::OnceCallback<void(std::unique_ptr<ShortcutInfo>)> callback,
std::unique_ptr<ShortcutInfo> shortcut_info_to_populate) { … }
void PopulateFaviconForShortcutInfo(
const WebApp* app,
WebAppIconManager& icon_manager,
std::unique_ptr<ShortcutInfo> shortcut_info_to_populate,
base::OnceCallback<void(std::unique_ptr<ShortcutInfo>)> callback) { … }
std::vector<WebAppShortcutsMenuItemInfo> CreateShortcutsMenuItemInfos(
const proto::ShortcutMenus& shortcut_menus) { … }
ShortcutLocations::ShortcutLocations() = default;
ShortcutLocations::~ShortcutLocations() = default;
base::Value ShortcutLocations::ToDebugValue() const { … }
ShortcutLocations MergeLocations(
const ShortcutLocations& user_specified_locations,
const ShortcutLocations& creation_locations) { … }
bool operator==(const ShortcutLocations& location1,
const ShortcutLocations& location2) { … }
bool operator!=(const ShortcutLocations& location1,
const ShortcutLocations& location2) { … }
std::string GenerateApplicationNameFromInfo(const ShortcutInfo& shortcut_info) { … }
base::FilePath GetOsIntegrationResourcesDirectoryForApp(
const base::FilePath& profile_path,
const std::string& app_id,
const GURL& url) { … }
base::span<const int> GetDesiredIconSizesForShortcut() { … }
gfx::ImageSkia CreateDefaultApplicationIcon(int size) { … }
namespace internals {
void PostShortcutIOTask(base::OnceCallback<void(const ShortcutInfo&)> task,
std::unique_ptr<ShortcutInfo> shortcut_info) { … }
void PostAsyncShortcutIOTask(
base::OnceCallback<void(std::unique_ptr<ShortcutInfo>)> task,
std::unique_ptr<ShortcutInfo> shortcut_info) { … }
void ScheduleCreatePlatformShortcuts(
const base::FilePath& shortcut_data_path,
const ShortcutLocations& creation_locations,
ShortcutCreationReason reason,
std::unique_ptr<ShortcutInfo> shortcut_info,
CreateShortcutsCallback callback) { … }
void ScheduleDeletePlatformShortcuts(
const base::FilePath& shortcut_data_path,
std::unique_ptr<ShortcutInfo> shortcut_info,
DeleteShortcutsCallback callback) { … }
void ScheduleDeleteMultiProfileShortcutsForApp(const std::string& app_id,
ResultCallback callback) { … }
void ScheduleUpdatePlatformShortcuts(
const base::FilePath& shortcut_data_dir,
const std::u16string& old_app_title,
std::optional<ShortcutLocations> locations,
base::OnceCallback<void(Result)> on_complete,
std::unique_ptr<ShortcutInfo> shortcut_info) { … }
void PostShortcutIOTaskAndReplyWithResult(
base::OnceCallback<Result(const ShortcutInfo&)> task,
std::unique_ptr<ShortcutInfo> shortcut_info,
ResultCallback reply) { … }
scoped_refptr<base::SequencedTaskRunner> GetShortcutIOTaskRunner() { … }
base::FilePath GetShortcutDataDir(const ShortcutInfo& shortcut_info) { … }
#if !BUILDFLAG(IS_MAC)
void DeleteMultiProfileShortcutsForApp(const std::string& app_id) { … }
#endif
}
}