Commit 29e751fe authored by Johannes Henkel's avatar Johannes Henkel Committed by Commit Bot

Use JSON to save the default background color override.

Earlier, I presented an alternative to this, which I prefer, by
storing the values in separate fields. It's in thic PR:
https://chromium-review.googlesource.com/c/chromium/src/+/1157185

Change-Id: I52740475b18dfed26fb4753ba11aff7523bedc0c
Reviewed-on: https://chromium-review.googlesource.com/1157248
Commit-Queue: Johannes Henkel <johannes@chromium.org>
Reviewed-by: default avatarAndrey Kosyakov <caseq@chromium.org>
Cr-Commit-Position: refs/heads/master@{#579612}
parent c66279fc
......@@ -34,8 +34,6 @@ static const char kDocumentCookieDisabled[] = "documentCookieDisabled";
static const char kTouchEventEmulationEnabled[] = "touchEventEmulationEnabled";
static const char kMaxTouchPoints[] = "maxTouchPoints";
static const char kEmulatedMedia[] = "emulatedMedia";
static const char kDefaultBackgroundColorOverrideRGBA[] =
"defaultBackgroundColorOverrideRGBA";
static const char kNavigatorPlatform[] = "navigatorPlatform";
static const char kVirtualTimeBudget[] = "virtualTimeBudget";
static const char kVirtualTimeBudgetInitalOffset[] =
......@@ -52,7 +50,9 @@ static const char kAcceptLanguageOverride[] = "acceptLanguage";
InspectorEmulationAgent::InspectorEmulationAgent(
WebLocalFrameImpl* web_local_frame_impl)
: web_local_frame_(web_local_frame_impl) {}
: web_local_frame_(web_local_frame_impl),
default_background_color_override_rgba_(
&agent_state_, /*default_value=*/ WTF::String()) {}
InspectorEmulationAgent::~InspectorEmulationAgent() = default;
......@@ -91,14 +91,16 @@ void InspectorEmulationAgent::Restore() {
String emulated_media;
state_->getString(EmulationAgentState::kEmulatedMedia, &emulated_media);
setEmulatedMedia(emulated_media);
auto* rgba_value =
state_->get(EmulationAgentState::kDefaultBackgroundColorOverrideRGBA);
if (rgba_value) {
blink::protocol::ErrorSupport errors;
auto rgba = protocol::DOM::RGBA::fromValue(rgba_value, &errors);
if (!errors.hasErrors()) {
setDefaultBackgroundColorOverride(
Maybe<protocol::DOM::RGBA>(std::move(rgba)));
if (!default_background_color_override_rgba_.Get().IsNull()) {
std::unique_ptr<protocol::Value> parsed = protocol::StringUtil::parseJSON(
default_background_color_override_rgba_.Get());
if (parsed) {
blink::protocol::ErrorSupport errors;
auto rgba = protocol::DOM::RGBA::fromValue(parsed.get(), &errors);
if (!errors.hasErrors()) {
setDefaultBackgroundColorOverride(
Maybe<protocol::DOM::RGBA>(std::move(rgba)));
}
}
}
......@@ -451,13 +453,13 @@ Response InspectorEmulationAgent::setDefaultBackgroundColorOverride(
if (!color.isJust()) {
// Clear the override and state.
GetWebViewImpl()->ClearBaseBackgroundColorOverride();
state_->remove(EmulationAgentState::kDefaultBackgroundColorOverrideRGBA);
default_background_color_override_rgba_.Clear();
return Response::OK();
}
blink::protocol::DOM::RGBA* rgba = color.fromJust();
state_->setValue(EmulationAgentState::kDefaultBackgroundColorOverrideRGBA,
rgba->toValue());
default_background_color_override_rgba_.Set(
rgba->toValue()->serialize());
// Clamping of values is done by Color() constructor.
int alpha = lroundf(255.0f * rgba->getA(1.0f));
GetWebViewImpl()->SetBaseBackgroundColorOverride(
......
......@@ -122,6 +122,7 @@ class CORE_EXPORT InspectorEmulationAgent final
base::Optional<PendingVirtualTimePolicy> pending_virtual_time_policy_;
bool enabled_ = false;
InspectorAgentState::String default_background_color_override_rgba_;
DISALLOW_COPY_AND_ASSIGN(InspectorEmulationAgent);
};
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment