[Extensions] Split launch utils file.
The original file has a majority of functions that have no dependencies on chrome/browser/extensions, so these are moved to a new file in extensions/browser. This will help break some cyclical dependencies. Bug: 40593486 Change-Id: I254390151fac2e1961bf83c48594aa03dddf7169 Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/6333988 Reviewed-by: Solomon Kinard <solomonkinard@chromium.org> Reviewed-by: Theresa Sullivan <twellington@chromium.org> Commit-Queue: David Bertoni <dbertoni@chromium.org> Cr-Commit-Position: refs/heads/main@{#1430536}
This commit is contained in:

committed by
Chromium LUCI CQ

parent
cd8483cb38
commit
290539a8c3
chrome/browser
apps
app_service
publishers
browser_instance
platform_apps
ash
app_list
extensions
sync
test
ui
ash
shelf
extensions
views
apps
app_info_dialog
extensions/browser
@ -84,6 +84,7 @@
|
||||
#include "extensions/browser/app_window/app_window.h"
|
||||
#include "extensions/browser/extension_system.h"
|
||||
#include "extensions/browser/extension_util.h"
|
||||
#include "extensions/browser/launch_util.h"
|
||||
#include "extensions/browser/management_policy.h"
|
||||
#include "extensions/browser/path_util.h"
|
||||
#include "extensions/browser/ui_util.h"
|
||||
|
@ -5,7 +5,6 @@
|
||||
#include "chrome/browser/apps/browser_instance/web_contents_instance_id_utils.h"
|
||||
|
||||
#include "chrome/browser/extensions/extension_service.h"
|
||||
#include "chrome/browser/extensions/launch_util.h"
|
||||
#include "chrome/browser/profiles/profile.h"
|
||||
#include "chrome/browser/ui/browser.h"
|
||||
#include "chrome/browser/ui/browser_finder.h"
|
||||
@ -23,6 +22,7 @@
|
||||
#include "content/public/browser/web_contents.h"
|
||||
#include "extensions/browser/extension_registry.h"
|
||||
#include "extensions/browser/extension_system.h"
|
||||
#include "extensions/browser/launch_util.h"
|
||||
#include "extensions/common/extension.h"
|
||||
|
||||
namespace apps {
|
||||
|
@ -20,7 +20,6 @@
|
||||
#include "chrome/browser/apps/platform_apps/app_window_registry_util.h"
|
||||
#include "chrome/browser/apps/platform_apps/platform_app_launch.h"
|
||||
#include "chrome/browser/browser_process.h"
|
||||
#include "chrome/browser/extensions/launch_util.h"
|
||||
#include "chrome/browser/profiles/profiles_state.h"
|
||||
#include "chrome/browser/ui/browser_window.h"
|
||||
#include "chrome/browser/ui/extensions/app_launch_params.h"
|
||||
@ -36,6 +35,7 @@
|
||||
#include "extensions/browser/extension_host.h"
|
||||
#include "extensions/browser/extension_prefs.h"
|
||||
#include "extensions/browser/extension_registry.h"
|
||||
#include "extensions/browser/launch_util.h"
|
||||
#include "extensions/common/constants.h"
|
||||
#include "extensions/common/extension_id.h"
|
||||
|
||||
|
@ -21,6 +21,7 @@
|
||||
#include "extensions/browser/extension_prefs.h"
|
||||
#include "extensions/browser/extension_registry.h"
|
||||
#include "extensions/browser/extension_system.h"
|
||||
#include "extensions/browser/launch_util.h"
|
||||
#include "extensions/browser/management_policy.h"
|
||||
#include "extensions/common/extension.h"
|
||||
#include "extensions/common/extension_set.h"
|
||||
|
@ -67,6 +67,7 @@
|
||||
#include "extensions/browser/extension_registrar.h"
|
||||
#include "extensions/browser/extension_registry.h"
|
||||
#include "extensions/browser/extension_system.h"
|
||||
#include "extensions/browser/launch_util.h"
|
||||
#include "extensions/browser/supervised_user_extensions_delegate.h"
|
||||
#include "extensions/common/api/management.h"
|
||||
#include "extensions/common/extension.h"
|
||||
|
@ -34,6 +34,7 @@
|
||||
#include "extensions/browser/extension_registrar.h"
|
||||
#include "extensions/browser/extension_system.h"
|
||||
#include "extensions/browser/extension_util.h"
|
||||
#include "extensions/browser/launch_util.h"
|
||||
#include "extensions/browser/uninstall_reason.h"
|
||||
#include "extensions/common/extension.h"
|
||||
#include "extensions/common/extension_set.h"
|
||||
|
@ -4,68 +4,23 @@
|
||||
|
||||
#include "chrome/browser/extensions/launch_util.h"
|
||||
|
||||
#include <memory>
|
||||
#include <optional>
|
||||
|
||||
#include "base/values.h"
|
||||
#include "build/build_config.h"
|
||||
#include "build/chromeos_buildflags.h"
|
||||
#include "chrome/browser/extensions/extension_sync_service.h"
|
||||
#include "chrome/common/extensions/extension_constants.h"
|
||||
#include "chrome/common/extensions/manifest_handlers/app_launch_info.h"
|
||||
#include "components/pref_registry/pref_registry_syncable.h"
|
||||
#include "extensions/browser/bookmark_app_util.h"
|
||||
#include "extensions/browser/extension_prefs.h"
|
||||
#include "extensions/browser/extension_registry.h"
|
||||
#include "extensions/browser/pref_names.h"
|
||||
#include "extensions/browser/launch_util.h"
|
||||
#include "extensions/common/extension.h"
|
||||
|
||||
namespace extensions {
|
||||
namespace {
|
||||
|
||||
// A preference set by the the NTP to persist the desired launch container type
|
||||
// used for apps.
|
||||
const char kPrefLaunchType[] = "launchType";
|
||||
|
||||
} // namespace
|
||||
|
||||
LaunchType GetLaunchType(const ExtensionPrefs* prefs,
|
||||
const Extension* extension) {
|
||||
if (!extension) {
|
||||
return LAUNCH_TYPE_INVALID;
|
||||
}
|
||||
LaunchType result = LAUNCH_TYPE_DEFAULT;
|
||||
|
||||
int value = GetLaunchTypePrefValue(prefs, extension->id());
|
||||
if (value >= LAUNCH_TYPE_FIRST && value < NUM_LAUNCH_TYPES)
|
||||
result = static_cast<LaunchType>(value);
|
||||
|
||||
// Force hosted apps that are not locally installed to open in tabs.
|
||||
if (extension->is_hosted_app() &&
|
||||
!BookmarkAppIsLocallyInstalled(prefs, extension)) {
|
||||
result = LAUNCH_TYPE_REGULAR;
|
||||
} else if (result == LAUNCH_TYPE_PINNED) {
|
||||
result = LAUNCH_TYPE_REGULAR;
|
||||
} else if (result == LAUNCH_TYPE_FULLSCREEN) {
|
||||
result = LAUNCH_TYPE_WINDOW;
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
LaunchType GetLaunchTypePrefValue(const ExtensionPrefs* prefs,
|
||||
const std::string& extension_id) {
|
||||
int value = LAUNCH_TYPE_INVALID;
|
||||
return prefs->ReadPrefAsInteger(extension_id, kPrefLaunchType, &value)
|
||||
? static_cast<LaunchType>(value) : LAUNCH_TYPE_INVALID;
|
||||
}
|
||||
|
||||
void SetLaunchType(content::BrowserContext* context,
|
||||
const std::string& extension_id,
|
||||
LaunchType launch_type) {
|
||||
DCHECK(launch_type >= LAUNCH_TYPE_FIRST && launch_type < NUM_LAUNCH_TYPES);
|
||||
|
||||
ExtensionPrefs::Get(context)->UpdateExtensionPref(
|
||||
extension_id, kPrefLaunchType,
|
||||
base::Value(static_cast<int>(launch_type)));
|
||||
SetLaunchTypePrefValue(context, extension_id, launch_type);
|
||||
|
||||
// Sync the launch type.
|
||||
const Extension* extension =
|
||||
@ -126,18 +81,11 @@ apps::LaunchContainer GetLaunchContainer(const ExtensionPrefs* prefs,
|
||||
|
||||
bool HasPreferredLaunchContainer(const ExtensionPrefs* prefs,
|
||||
const Extension* extension) {
|
||||
int value = -1;
|
||||
apps::LaunchContainer manifest_launch_container =
|
||||
AppLaunchInfo::GetLaunchContainer(extension);
|
||||
return manifest_launch_container ==
|
||||
apps::LaunchContainer::kLaunchContainerTab &&
|
||||
prefs->ReadPrefAsInteger(extension->id(), kPrefLaunchType, &value);
|
||||
}
|
||||
|
||||
bool LaunchesInWindow(content::BrowserContext* context,
|
||||
const Extension* extension) {
|
||||
return GetLaunchType(ExtensionPrefs::Get(context), extension) ==
|
||||
LAUNCH_TYPE_WINDOW;
|
||||
GetLaunchTypePrefValue(prefs, extension->id()) != LAUNCH_TYPE_INVALID;
|
||||
}
|
||||
|
||||
} // namespace extensions
|
||||
|
@ -19,18 +19,6 @@ namespace extensions {
|
||||
class Extension;
|
||||
class ExtensionPrefs;
|
||||
|
||||
// Gets the launch type preference. If no preference is set, returns
|
||||
// LAUNCH_TYPE_DEFAULT.
|
||||
// Returns LAUNCH_TYPE_WINDOW if there's no preference and
|
||||
// bookmark apps are enabled.
|
||||
LaunchType GetLaunchType(const ExtensionPrefs* prefs,
|
||||
const Extension* extension);
|
||||
|
||||
// Returns the LaunchType that is set in the prefs. Returns LAUNCH_TYPE_INVALID
|
||||
// if no value is set in prefs.
|
||||
LaunchType GetLaunchTypePrefValue(const ExtensionPrefs* prefs,
|
||||
const std::string& extension_id);
|
||||
|
||||
// Sets an extension's launch type preference and syncs the value if necessary.
|
||||
void SetLaunchType(content::BrowserContext* context,
|
||||
const std::string& extension_id,
|
||||
@ -48,10 +36,6 @@ apps::LaunchContainer GetLaunchContainer(const ExtensionPrefs* prefs,
|
||||
bool HasPreferredLaunchContainer(const ExtensionPrefs* prefs,
|
||||
const Extension* extension);
|
||||
|
||||
// Whether |extension| will launch in a window.
|
||||
bool LaunchesInWindow(content::BrowserContext* context,
|
||||
const Extension* extension);
|
||||
|
||||
} // namespace extensions
|
||||
|
||||
#endif // CHROME_BROWSER_EXTENSIONS_LAUNCH_UTIL_H_
|
||||
|
@ -11,7 +11,6 @@
|
||||
#include "chrome/browser/extensions/extension_service.h"
|
||||
#include "chrome/browser/extensions/extension_sync_util.h"
|
||||
#include "chrome/browser/extensions/extension_util.h"
|
||||
#include "chrome/browser/extensions/launch_util.h"
|
||||
#include "chrome/browser/extensions/pending_extension_manager.h"
|
||||
#include "chrome/browser/profiles/profile.h"
|
||||
#include "chrome/browser/sync/test/integration/extensions_helper.h"
|
||||
@ -25,6 +24,7 @@
|
||||
#include "extensions/browser/extension_prefs.h"
|
||||
#include "extensions/browser/extension_registry.h"
|
||||
#include "extensions/browser/extension_system.h"
|
||||
#include "extensions/browser/launch_util.h"
|
||||
#include "extensions/common/extension_set.h"
|
||||
|
||||
using extensions::AppSorting;
|
||||
|
@ -3,6 +3,7 @@
|
||||
// found in the LICENSE file.
|
||||
|
||||
#include <stddef.h>
|
||||
|
||||
#include <memory>
|
||||
#include <utility>
|
||||
|
||||
@ -33,6 +34,7 @@
|
||||
#include "extensions/browser/extension_prefs.h"
|
||||
#include "extensions/browser/extension_registry.h"
|
||||
#include "extensions/browser/extension_system.h"
|
||||
#include "extensions/browser/launch_util.h"
|
||||
#include "extensions/browser/test_extension_registry_observer.h"
|
||||
#include "extensions/common/constants.h"
|
||||
|
||||
|
@ -139,6 +139,7 @@ static_library("shelf") {
|
||||
"//components/prefs",
|
||||
"//components/sync_preferences",
|
||||
"//components/webapps/common",
|
||||
"//extensions/browser",
|
||||
"//extensions/common",
|
||||
"//ui/chromeos/styles:cros_tokens_color_mappings_generator",
|
||||
]
|
||||
|
@ -47,6 +47,7 @@
|
||||
#include "components/services/app_service/public/cpp/app_types.h"
|
||||
#include "content/public/browser/context_menu_params.h"
|
||||
#include "extensions/browser/extension_prefs.h"
|
||||
#include "extensions/browser/launch_util.h"
|
||||
#include "ui/base/l10n/l10n_util.h"
|
||||
#include "ui/display/scoped_display_for_new_windows.h"
|
||||
#include "ui/gfx/vector_icon_types.h"
|
||||
|
@ -17,7 +17,6 @@
|
||||
#include "base/memory/ptr_util.h"
|
||||
#include "base/memory/raw_ptr.h"
|
||||
#include "chrome/browser/ash/app_list/arc/arc_app_utils.h"
|
||||
#include "chrome/browser/extensions/launch_util.h"
|
||||
#include "chrome/browser/profiles/profile.h"
|
||||
#include "chrome/browser/ui/ash/multi_user/multi_user_util.h"
|
||||
#include "chrome/browser/ui/ash/multi_user/multi_user_window_manager_helper.h"
|
||||
@ -43,6 +42,7 @@
|
||||
#include "content/public/browser/web_contents.h"
|
||||
#include "extensions/browser/app_window/native_app_window.h"
|
||||
#include "extensions/browser/extension_registry.h"
|
||||
#include "extensions/browser/launch_util.h"
|
||||
#include "extensions/browser/process_manager.h"
|
||||
#include "ui/aura/window.h"
|
||||
#include "ui/events/event.h"
|
||||
|
@ -25,6 +25,7 @@
|
||||
#include "content/public/browser/context_menu_params.h"
|
||||
#include "extensions/browser/extension_prefs.h"
|
||||
#include "extensions/browser/extension_system.h"
|
||||
#include "extensions/browser/launch_util.h"
|
||||
#include "extensions/browser/management_policy.h"
|
||||
#include "ui/base/l10n/l10n_util.h"
|
||||
#include "ui/base/models/image_model.h"
|
||||
|
@ -24,7 +24,6 @@
|
||||
#include "chrome/browser/apps/platform_apps/platform_app_launch.h"
|
||||
#include "chrome/browser/extensions/extension_util.h"
|
||||
#include "chrome/browser/extensions/file_handlers/file_handling_launch_utils.h"
|
||||
#include "chrome/browser/extensions/launch_util.h"
|
||||
#include "chrome/browser/extensions/tab_helper.h"
|
||||
#include "chrome/browser/profiles/profile.h"
|
||||
#include "chrome/browser/ui/browser.h"
|
||||
@ -48,7 +47,7 @@
|
||||
#include "extensions/browser/extension_prefs.h"
|
||||
#include "extensions/browser/extension_registrar.h"
|
||||
#include "extensions/browser/extension_registry.h"
|
||||
#include "extensions/browser/extension_system.h"
|
||||
#include "extensions/browser/launch_util.h"
|
||||
#include "extensions/common/constants.h"
|
||||
#include "extensions/common/extension.h"
|
||||
#include "extensions/common/features/feature.h"
|
||||
|
@ -19,6 +19,7 @@
|
||||
#include "components/app_constants/constants.h"
|
||||
#include "extensions/browser/extension_prefs.h"
|
||||
#include "extensions/browser/extension_registry.h"
|
||||
#include "extensions/browser/launch_util.h"
|
||||
#include "extensions/browser/path_util.h"
|
||||
#include "extensions/common/extension.h"
|
||||
#include "extensions/common/manifest.h"
|
||||
|
@ -386,6 +386,8 @@ source_set("browser_sources") {
|
||||
"json_file_sanitizer.h",
|
||||
"l10n_file_util.cc",
|
||||
"l10n_file_util.h",
|
||||
"launch_util.cc",
|
||||
"launch_util.h",
|
||||
"lazy_background_task_queue.cc",
|
||||
"lazy_background_task_queue.h",
|
||||
"lazy_background_task_queue_factory.cc",
|
||||
|
69
extensions/browser/launch_util.cc
Normal file
69
extensions/browser/launch_util.cc
Normal file
@ -0,0 +1,69 @@
|
||||
// Copyright 2025 The Chromium Authors
|
||||
// Use of this source code is governed by a BSD-style license that can be
|
||||
// found in the LICENSE file.
|
||||
|
||||
#include "extensions/browser/launch_util.h"
|
||||
|
||||
#include "build/build_config.h"
|
||||
#include "extensions/browser/bookmark_app_util.h"
|
||||
#include "extensions/browser/extension_prefs.h"
|
||||
#include "extensions/common/extension.h"
|
||||
|
||||
namespace extensions {
|
||||
namespace {
|
||||
|
||||
// A preference set by the the NTP to persist the desired launch container type
|
||||
// used for apps.
|
||||
constexpr char kPrefLaunchType[] = "launchType";
|
||||
|
||||
} // namespace
|
||||
|
||||
LaunchType GetLaunchType(const ExtensionPrefs* prefs,
|
||||
const Extension* extension) {
|
||||
if (!extension) {
|
||||
return LAUNCH_TYPE_INVALID;
|
||||
}
|
||||
LaunchType result = LAUNCH_TYPE_DEFAULT;
|
||||
|
||||
int value = GetLaunchTypePrefValue(prefs, extension->id());
|
||||
if (value >= LAUNCH_TYPE_FIRST && value < NUM_LAUNCH_TYPES) {
|
||||
result = static_cast<LaunchType>(value);
|
||||
}
|
||||
|
||||
// Force hosted apps that are not locally installed to open in tabs.
|
||||
if (extension->is_hosted_app() &&
|
||||
!BookmarkAppIsLocallyInstalled(prefs, extension)) {
|
||||
result = LAUNCH_TYPE_REGULAR;
|
||||
} else if (result == LAUNCH_TYPE_PINNED) {
|
||||
result = LAUNCH_TYPE_REGULAR;
|
||||
} else if (result == LAUNCH_TYPE_FULLSCREEN) {
|
||||
result = LAUNCH_TYPE_WINDOW;
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
LaunchType GetLaunchTypePrefValue(const ExtensionPrefs* prefs,
|
||||
const std::string& extension_id) {
|
||||
int value = LAUNCH_TYPE_INVALID;
|
||||
return prefs->ReadPrefAsInteger(extension_id, kPrefLaunchType, &value)
|
||||
? static_cast<LaunchType>(value)
|
||||
: LAUNCH_TYPE_INVALID;
|
||||
}
|
||||
|
||||
void SetLaunchTypePrefValue(content::BrowserContext* context,
|
||||
const std::string& extension_id,
|
||||
LaunchType launch_type) {
|
||||
DCHECK(launch_type >= LAUNCH_TYPE_FIRST && launch_type < NUM_LAUNCH_TYPES);
|
||||
|
||||
ExtensionPrefs::Get(context)->UpdateExtensionPref(
|
||||
extension_id, kPrefLaunchType,
|
||||
base::Value(static_cast<int>(launch_type)));
|
||||
}
|
||||
|
||||
bool LaunchesInWindow(content::BrowserContext* context,
|
||||
const Extension* extension) {
|
||||
return GetLaunchType(ExtensionPrefs::Get(context), extension) ==
|
||||
LAUNCH_TYPE_WINDOW;
|
||||
}
|
||||
|
||||
} // namespace extensions
|
45
extensions/browser/launch_util.h
Normal file
45
extensions/browser/launch_util.h
Normal file
@ -0,0 +1,45 @@
|
||||
// Copyright 2025 The Chromium Authors
|
||||
// Use of this source code is governed by a BSD-style license that can be
|
||||
// found in the LICENSE file.
|
||||
|
||||
#ifndef EXTENSIONS_BROWSER_LAUNCH_UTIL_H_
|
||||
#define EXTENSIONS_BROWSER_LAUNCH_UTIL_H_
|
||||
|
||||
#include <string>
|
||||
|
||||
#include "components/services/app_service/public/cpp/app_launch_util.h"
|
||||
#include "extensions/common/constants.h"
|
||||
|
||||
namespace content {
|
||||
class BrowserContext;
|
||||
}
|
||||
|
||||
namespace extensions {
|
||||
|
||||
class Extension;
|
||||
class ExtensionPrefs;
|
||||
|
||||
// Gets the launch type preference. If no preference is set, returns
|
||||
// LAUNCH_TYPE_DEFAULT.
|
||||
// Returns LAUNCH_TYPE_WINDOW if there's no preference and
|
||||
// bookmark apps are enabled.
|
||||
LaunchType GetLaunchType(const ExtensionPrefs* prefs,
|
||||
const Extension* extension);
|
||||
|
||||
// Returns the LaunchType that is set in the prefs. Returns LAUNCH_TYPE_INVALID
|
||||
// if no value is set in prefs.
|
||||
LaunchType GetLaunchTypePrefValue(const ExtensionPrefs* prefs,
|
||||
const std::string& extension_id);
|
||||
|
||||
// Sets an extension's launch type preference.
|
||||
void SetLaunchTypePrefValue(content::BrowserContext* context,
|
||||
const std::string& extension_id,
|
||||
LaunchType launch_type);
|
||||
|
||||
// Whether `extension` will launch in a window.
|
||||
bool LaunchesInWindow(content::BrowserContext* context,
|
||||
const Extension* extension);
|
||||
|
||||
} // namespace extensions
|
||||
|
||||
#endif // EXTENSIONS_BROWSER_LAUNCH_UTIL_H_
|
Reference in New Issue
Block a user