1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
android_webview / browser / aw_feature_entries.cc [blame]
// Copyright 2021 The Chromium Authors
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
#include "android_webview/browser/aw_feature_entries.h"
#include <set>
#include "android_webview/common/aw_switches.h"
#include "base/command_line.h"
#include "base/metrics/field_trial.h"
#include "components/flags_ui/feature_entry.h"
#include "components/flags_ui/feature_entry_macros.h"
#include "components/flags_ui/flags_state.h"
#include "components/variations/variations_associated_data.h"
#include "third_party/blink/public/common/features.h"
namespace android_webview {
namespace aw_feature_entries {
namespace {
constexpr flags_ui::FeatureEntry::FeatureParam
kForceDark_SelectiveImageInversion[] = {
{"inversion_method", "cielab_based"},
{"image_behavior", "selective"},
{"foreground_lightness_threshold", "150"},
{"background_lightness_threshold", "205"}};
// Not like Chrome, WebView only provides a switch in dev ui and uses the
// preferred variation if it is turned on.
constexpr flags_ui::FeatureEntry::FeatureVariation kForceDarkVariations[] = {
{"with selective image inversion", kForceDark_SelectiveImageInversion,
std::size(kForceDark_SelectiveImageInversion), nullptr}};
// Not for display, set the descriptions to empty.
constexpr flags_ui::FeatureEntry kForceDark = {
"enable-force-dark", "", "", flags_ui::kOsWebView,
FEATURE_WITH_PARAMS_VALUE_TYPE(blink::features::kForceWebContentsDarkMode,
kForceDarkVariations,
"ForceDarkVariations")};
constexpr flags_ui::FeatureEntry kWebViewFeatureEntries[] = {
kForceDark,
};
} // namespace
namespace internal {
std::string ToEnabledEntry(const flags_ui::FeatureEntry& entry,
int enabled_variation_index) {
CHECK(entry.type == flags_ui::FeatureEntry::FEATURE_WITH_PARAMS_VALUE);
// Index 0 is "Default" and 1 is "Enabled" inside FeatureEntry.
return entry.NameForOption(enabled_variation_index + 2);
}
} // namespace internal
std::vector<std::string> RegisterEnabledFeatureEntries(
base::FeatureList* feature_list) {
std::set<std::string> enabled_entries;
if (base::CommandLine::ForCurrentProcess()->HasSwitch(
switches::kWebViewSelectiveImageInversionDarkening)) {
enabled_entries.insert(internal::ToEnabledEntry(kForceDark, 0));
}
return flags_ui::FlagsState::RegisterEnabledFeatureVariationParameters(
kWebViewFeatureEntries, enabled_entries, /*trial_name=*/"webview_dev_ui",
feature_list);
}
} // namespace aw_feature_entries
} // namespace android_webview