components/embedder_support: Trim dependencies

master
klzgrad 2026-04-30 21:40:50 +08:00
parent dd2af1083d
commit 7da17f8e8c
2 changed files with 53 additions and 124 deletions

View File

@ -2,8 +2,6 @@
# Use of this source code is governed by a BSD-style license that can be # Use of this source code is governed by a BSD-style license that can be
# found in the LICENSE file. # found in the LICENSE file.
import("//device/vr/buildflags/buildflags.gni")
static_library("embedder_support") { static_library("embedder_support") {
sources = [ sources = [
"pref_names.h", "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") { static_library("user_agent") {
sources = [ sources = [
"user_agent_utils.cc", "user_agent_utils.cc",
@ -58,63 +19,7 @@ static_library("user_agent") {
deps = [ deps = [
":embedder_support", ":embedder_support",
"//build:branding_buildflags", "//build:branding_buildflags",
"//components/policy/core/common",
"//components/prefs",
"//components/version_info", "//components/version_info",
"//net", "//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 "build/build_config.h"
#include "components/embedder_support/pref_names.h" #include "components/embedder_support/pref_names.h"
#include "components/embedder_support/switches.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 "components/version_info/version_info.h"
#include "net/http/http_util.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" #include "third_party/blink/public/common/user_agent/user_agent_metadata.h"
#if BUILDFLAG(IS_WIN) #if BUILDFLAG(IS_WIN)
@ -46,7 +43,7 @@
#include "base/mac/mac_util.h" #include "base/mac/mac_util.h"
#endif #endif
#if BUILDFLAG(IS_IOS) || BUILDFLAG(IS_ANDROID) #if BUILDFLAG(IS_IOS)
#include "ui/base/device_form_factor.h" #include "ui/base/device_form_factor.h"
#endif #endif
@ -54,6 +51,51 @@
#include <sys/utsname.h> #include <sys/utsname.h>
#endif #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 embedder_support {
namespace { namespace {
@ -195,8 +237,7 @@ const blink::UserAgentBrandList GetUserAgentBrandMajorVersionListInternal(
// It helps us avoid introducing individual enterprise policy controls for // It helps us avoid introducing individual enterprise policy controls for
// sending unified platform for the user agent string. // sending unified platform for the user agent string.
bool ShouldSendUserAgentUnifiedPlatform() { bool ShouldSendUserAgentUnifiedPlatform() {
return base::FeatureList::IsEnabled( return true;
blink::features::kReduceUserAgentMinorVersion);
} }
// Return UserAgentBrandList with the full version populated in the brand // Return UserAgentBrandList with the full version populated in the brand
@ -299,7 +340,7 @@ std::string GetUserAgentPlatform() {
} }
std::string GetUnifiedPlatform() { std::string GetUnifiedPlatform() {
#if BUILDFLAG(IS_ANDROID) || BUILDFLAG(IS_CHROMEOS) #if BUILDFLAG(IS_CHROMEOS)
// This constant is only used on Android (desktop) and Linux. // This constant is only used on Android (desktop) and Linux.
constexpr char kUnifiedPlatformChromeOSX64[] = "X11; CrOS x86_64 14541.0.0"; constexpr char kUnifiedPlatformChromeOSX64[] = "X11; CrOS x86_64 14541.0.0";
@ -309,10 +350,7 @@ std::string GetUnifiedPlatform() {
// form factor. // form factor.
if (base::android::device_info::is_desktop() || if (base::android::device_info::is_desktop() ||
base::android::device_info::is_xr()) { base::android::device_info::is_xr()) {
return base::FeatureList::IsEnabled( return "X11; Linux x86_64";
blink::features::kAndroidDesktopUASpoofAsChromeOS)
? kUnifiedPlatformChromeOSX64
: "X11; Linux x86_64";
} }
return "Linux; Android 10; K"; return "Linux; Android 10; K";
#elif BUILDFLAG(IS_CHROMEOS) #elif BUILDFLAG(IS_CHROMEOS)
@ -443,11 +481,7 @@ std::string BuildOSCpuInfo(
} // namespace } // namespace
std::string GetProductAndVersion() { std::string GetProductAndVersion() {
return base::FeatureList::IsEnabled( return version_info::GetProductNameAndVersionForReducedUserAgent();
blink::features::kReduceUserAgentMinorVersion)
? version_info::GetProductNameAndVersionForReducedUserAgent()
: std::string(
version_info::GetProductNameAndVersionForUserAgent());
} }
std::optional<std::string> GetUserAgentFromCommandLine() { std::optional<std::string> GetUserAgentFromCommandLine() {
@ -593,9 +627,7 @@ std::string GetPlatformVersion() {
// and the real OS version reported unconditionally. // and the real OS version reported unconditionally.
// Note: check the feature flag first since it is cheaper than the device // Note: check the feature flag first since it is cheaper than the device
// info checks. // info checks.
if (!base::FeatureList::IsEnabled( if ((base::android::device_info::is_desktop() ||
blink::features::kAndroidDesktopUAPlatform) &&
(base::android::device_info::is_desktop() ||
base::android::device_info::is_xr())) { base::android::device_info::is_xr())) {
return std::string(); return std::string();
} }
@ -617,13 +649,7 @@ std::string GetPlatformForUAMetadata() {
#if BUILDFLAG(IS_ANDROID) #if BUILDFLAG(IS_ANDROID)
if (base::android::device_info::is_desktop() || if (base::android::device_info::is_desktop() ||
base::android::device_info::is_xr()) { base::android::device_info::is_xr()) {
return base::FeatureList::IsEnabled( return "Linux";
blink::features::kAndroidDesktopUAPlatform)
? "Android"
: (base::FeatureList::IsEnabled(
blink::features::kAndroidDesktopUASpoofAsChromeOS)
? "Chrome OS"
: "Linux");
} }
#endif #endif
@ -662,9 +688,7 @@ blink::UserAgentMetadata GetUserAgentMetadata(bool only_low_entropy_ch) {
// blocked by web application firewall software, etc. // blocked by web application firewall software, etc.
std::optional<std::string> custom_ua = GetUserAgentFromCommandLine(); std::optional<std::string> custom_ua = GetUserAgentFromCommandLine();
if (custom_ua.has_value()) { if (custom_ua.has_value()) {
return base::FeatureList::IsEnabled(blink::features::kUACHOverrideBlank) return metadata;
? blink::UserAgentMetadata()
: metadata;
} }
if (only_low_entropy_ch) { if (only_low_entropy_ch) {