components/embedder_support: Trim dependencies

This commit is contained in:
klzgrad
2026-04-30 21:40:50 +08:00
parent 9e889e7110
commit dde552aafa
2 changed files with 52 additions and 121 deletions

View File

@@ -2,8 +2,6 @@
# Use of this source code is governed by a BSD-style license that can be
# found in the LICENSE file.
import("//device/vr/buildflags/buildflags.gni")
static_library("embedder_support") {
sources = [
"pref_names.h",
@@ -12,43 +10,6 @@ static_library("embedder_support") {
]
}
static_library("content_settings") {
sources = [
"content_settings_utils.cc",
"content_settings_utils.h",
]
deps = [
"//components/content_settings/browser",
"//components/content_settings/core/browser",
"//components/content_settings/core/browser:cookie_settings",
"//content/public/browser",
"//net",
"//third_party/blink/public/mojom:mojom_platform_headers",
"//url",
]
}
static_library("permissions") {
sources = [
"permission_context_utils.cc",
"permission_context_utils.h",
]
deps = [
"//components/background_sync",
"//components/content_settings/core/common",
"//components/permissions",
"//device/vr/buildflags",
"//services/device/public/cpp:device_features",
"//services/device/public/cpp/geolocation:buildflags",
]
if (enable_vr) {
deps += [ "//device/vr/public/cpp:features" ]
}
}
static_library("user_agent") {
sources = [
"user_agent_utils.cc",
@@ -58,63 +19,7 @@ static_library("user_agent") {
deps = [
":embedder_support",
"//build:branding_buildflags",
"//components/policy/core/common",
"//components/prefs",
"//components/version_info",
"//net",
"//third_party/blink/public/common:headers",
"//ui/base",
]
}
source_set("unit_tests") {
testonly = true
sources = [
"origin_trials/component_updater_utils_unittest.cc",
"origin_trials/origin_trial_policy_impl_unittest.cc",
"origin_trials/origin_trials_settings_storage_unittest.cc",
"user_agent_utils_unittest.cc",
]
deps = [
":user_agent",
"//base",
"//base/test:test_support",
"//build:branding_buildflags",
"//components/component_updater/installer_policies",
"//components/embedder_support",
"//components/embedder_support/origin_trials",
"//components/embedder_support/origin_trials:test_support",
"//components/prefs",
"//components/prefs:test_support",
"//components/version_info",
"//content/public/common",
"//mojo/core/embedder",
"//net",
"//net/traffic_annotation:test_support",
"//services/network:test_support",
"//testing/gtest",
"//third_party/blink/public/common:headers",
"//third_party/blink/public/mojom:mojom_platform_headers",
"//third_party/re2",
]
if (is_android) {
sources += [
"android/util/android_stream_reader_url_loader_unittest.cc",
"android/util/input_stream_reader_unittest.cc",
"android/util/input_stream_unittest.cc",
"android/util/web_resource_response_unittest.cc",
]
deps += [
"android:native_j_unittests_jni",
"android:native_java_unittests_java",
"android:util",
]
}
# TODO(crbug.com/40031409): Fix code that adds exit-time destructors and
# enable the diagnostic by removing this line.
configs += [ "//build/config/compiler:no_exit_time_destructors" ]
}

View File

@@ -28,11 +28,8 @@
#include "build/build_config.h"
#include "components/embedder_support/pref_names.h"
#include "components/embedder_support/switches.h"
#include "components/policy/core/common/policy_pref_names.h"
#include "components/prefs/pref_service.h"
#include "components/version_info/version_info.h"
#include "net/http/http_util.h"
#include "third_party/blink/public/common/features.h"
#include "third_party/blink/public/common/user_agent/user_agent_metadata.h"
#if BUILDFLAG(IS_WIN)
@@ -46,7 +43,7 @@
#include "base/mac/mac_util.h"
#endif
#if BUILDFLAG(IS_IOS) || BUILDFLAG(IS_ANDROID)
#if BUILDFLAG(IS_IOS)
#include "ui/base/device_form_factor.h"
#endif
@@ -54,6 +51,51 @@
#include <sys/utsname.h>
#endif
#include <algorithm>
#include "base/containers/span.h"
#include "base/pickle.h"
#include "net/http/structured_headers.h"
namespace blink {
UserAgentBrandVersion::UserAgentBrandVersion(const std::string& ua_brand,
const std::string& ua_version) {
brand = ua_brand;
version = ua_version;
}
const std::string UserAgentMetadata::SerializeBrandVersionList(
const blink::UserAgentBrandList& ua_brand_version_list) {
net::structured_headers::List brand_version_header =
net::structured_headers::List();
for (const UserAgentBrandVersion& brand_version : ua_brand_version_list) {
if (brand_version.version.empty()) {
brand_version_header.push_back(
net::structured_headers::ParameterizedMember(
net::structured_headers::Item(brand_version.brand), {}));
} else {
brand_version_header.push_back(
net::structured_headers::ParameterizedMember(
net::structured_headers::Item(brand_version.brand),
{std::make_pair(
"v", net::structured_headers::Item(brand_version.version))}));
}
}
return net::structured_headers::SerializeList(brand_version_header)
.value_or("");
}
const std::string UserAgentMetadata::SerializeBrandFullVersionList() {
return SerializeBrandVersionList(brand_full_version_list);
}
const std::string UserAgentMetadata::SerializeBrandMajorVersionList() {
return SerializeBrandVersionList(brand_version_list);
}
}
namespace embedder_support {
namespace {
@@ -195,8 +237,7 @@ const blink::UserAgentBrandList GetUserAgentBrandMajorVersionListInternal(
// It helps us avoid introducing individual enterprise policy controls for
// sending unified platform for the user agent string.
bool ShouldSendUserAgentUnifiedPlatform() {
return base::FeatureList::IsEnabled(
blink::features::kReduceUserAgentMinorVersion);
return true;
}
// Return UserAgentBrandList with the full version populated in the brand
@@ -299,7 +340,7 @@ std::string GetUserAgentPlatform() {
}
std::string GetUnifiedPlatform() {
#if BUILDFLAG(IS_ANDROID) || BUILDFLAG(IS_CHROMEOS)
#if BUILDFLAG(IS_CHROMEOS)
// This constant is only used on Android (desktop) and Linux.
constexpr char kUnifiedPlatformChromeOSX64[] = "X11; CrOS x86_64 14541.0.0";
@@ -309,10 +350,7 @@ std::string GetUnifiedPlatform() {
// form factor.
if (base::android::device_info::is_desktop() ||
base::android::device_info::is_xr()) {
return base::FeatureList::IsEnabled(
blink::features::kAndroidDesktopUASpoofAsChromeOS)
? kUnifiedPlatformChromeOSX64
: "X11; Linux x86_64";
return "X11; Linux x86_64";
}
return "Linux; Android 10; K";
#elif BUILDFLAG(IS_CHROMEOS)
@@ -443,11 +481,7 @@ std::string BuildOSCpuInfo(
} // namespace
std::string GetProductAndVersion() {
return base::FeatureList::IsEnabled(
blink::features::kReduceUserAgentMinorVersion)
? version_info::GetProductNameAndVersionForReducedUserAgent()
: std::string(
version_info::GetProductNameAndVersionForUserAgent());
return version_info::GetProductNameAndVersionForReducedUserAgent();
}
std::optional<std::string> GetUserAgentFromCommandLine() {
@@ -606,13 +640,7 @@ std::string GetPlatformForUAMetadata() {
#if BUILDFLAG(IS_ANDROID)
if (base::android::device_info::is_desktop() ||
base::android::device_info::is_xr()) {
return base::FeatureList::IsEnabled(
blink::features::kAndroidDesktopUAPlatform)
? "Android"
: (base::FeatureList::IsEnabled(
blink::features::kAndroidDesktopUASpoofAsChromeOS)
? "Chrome OS"
: "Linux");
return "Linux";
}
#endif
@@ -651,9 +679,7 @@ blink::UserAgentMetadata GetUserAgentMetadata(bool only_low_entropy_ch) {
// blocked by web application firewall software, etc.
std::optional<std::string> custom_ua = GetUserAgentFromCommandLine();
if (custom_ua.has_value()) {
return base::FeatureList::IsEnabled(blink::features::kUACHOverrideBlank)
? blink::UserAgentMetadata()
: metadata;
return metadata;
}
if (only_low_entropy_ch) {