Commit 747f4c8f authored by Johannes Henkel's avatar Johannes Henkel Committed by Commit Bot

[DevTools] Switch the InspectorEmulationAgent's RBGA field to CBOR.

Change-Id: Ic99de0b23ec2b1c4d1c4f6477eb727f2b87c23c4
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/1677240
Commit-Queue: Johannes Henkel <johannes@chromium.org>
Reviewed-by: default avatarAndrey Kosyakov <caseq@chromium.org>
Cr-Commit-Position: refs/heads/master@{#672659}
parent 2fdefded
...@@ -32,7 +32,7 @@ InspectorEmulationAgent::InspectorEmulationAgent( ...@@ -32,7 +32,7 @@ InspectorEmulationAgent::InspectorEmulationAgent(
WebLocalFrameImpl* web_local_frame_impl) 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_background_color_override_rgba_(&agent_state_,
/*default_value=*/WTF::String()), /*default_value=*/{}),
script_execution_disabled_(&agent_state_, /*default_value=*/false), script_execution_disabled_(&agent_state_, /*default_value=*/false),
scrollbars_hidden_(&agent_state_, /*default_value=*/false), scrollbars_hidden_(&agent_state_, /*default_value=*/false),
document_cookie_disabled_(&agent_state_, /*default_value=*/false), document_cookie_disabled_(&agent_state_, /*default_value=*/false),
...@@ -60,6 +60,20 @@ WebViewImpl* InspectorEmulationAgent::GetWebViewImpl() { ...@@ -60,6 +60,20 @@ WebViewImpl* InspectorEmulationAgent::GetWebViewImpl() {
return web_local_frame_ ? web_local_frame_->ViewImpl() : nullptr; return web_local_frame_ ? web_local_frame_->ViewImpl() : nullptr;
} }
namespace {
std::unique_ptr<protocol::DOM::RGBA> ParseRGBA(
const std::vector<uint8_t>& cbor) {
auto parsed = protocol::Value::parseBinary(cbor.data(), cbor.size());
if (!parsed)
return nullptr;
blink::protocol::ErrorSupport errors;
auto rgba = protocol::DOM::RGBA::fromValue(parsed.get(), &errors);
if (errors.hasErrors())
return nullptr;
return rgba;
}
} // namespace
void InspectorEmulationAgent::Restore() { void InspectorEmulationAgent::Restore() {
setUserAgentOverride(user_agent_override_.Get(), setUserAgentOverride(user_agent_override_.Get(),
accept_language_override_.Get(), accept_language_override_.Get(),
...@@ -77,18 +91,9 @@ void InspectorEmulationAgent::Restore() { ...@@ -77,18 +91,9 @@ void InspectorEmulationAgent::Restore() {
setTouchEmulationEnabled(touch_event_emulation_enabled_.Get(), setTouchEmulationEnabled(touch_event_emulation_enabled_.Get(),
max_touch_points_.Get()); max_touch_points_.Get());
setEmulatedMedia(emulated_media_.Get()); setEmulatedMedia(emulated_media_.Get());
if (!default_background_color_override_rgba_.Get().IsNull()) { auto rgba = ParseRGBA(default_background_color_override_rgba_.Get());
std::unique_ptr<protocol::Value> parsed = protocol::StringUtil::parseJSON( if (rgba)
default_background_color_override_rgba_.Get()); setDefaultBackgroundColorOverride(std::move(rgba));
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)));
}
}
}
setFocusEmulationEnabled(emulate_focus_.Get()); setFocusEmulationEnabled(emulate_focus_.Get());
if (!timezone_id_override_.Get().IsNull()) if (!timezone_id_override_.Get().IsNull())
...@@ -404,7 +409,7 @@ Response InspectorEmulationAgent::setDefaultBackgroundColorOverride( ...@@ -404,7 +409,7 @@ Response InspectorEmulationAgent::setDefaultBackgroundColorOverride(
} }
blink::protocol::DOM::RGBA* rgba = color.fromJust(); blink::protocol::DOM::RGBA* rgba = color.fromJust();
default_background_color_override_rgba_.Set(rgba->toJSON()); default_background_color_override_rgba_.Set(rgba->serializeToBinary());
// Clamping of values is done by Color() constructor. // Clamping of values is done by Color() constructor.
int alpha = static_cast<int>(lroundf(255.0f * rgba->getA(1.0f))); int alpha = static_cast<int>(lroundf(255.0f * rgba->getA(1.0f)));
GetWebViewImpl()->SetBaseBackgroundColorOverride( GetWebViewImpl()->SetBaseBackgroundColorOverride(
......
...@@ -116,7 +116,7 @@ class CORE_EXPORT InspectorEmulationAgent final ...@@ -116,7 +116,7 @@ class CORE_EXPORT InspectorEmulationAgent final
base::Optional<PendingVirtualTimePolicy> pending_virtual_time_policy_; base::Optional<PendingVirtualTimePolicy> pending_virtual_time_policy_;
bool enabled_ = false; bool enabled_ = false;
InspectorAgentState::String default_background_color_override_rgba_; InspectorAgentState::Bytes default_background_color_override_rgba_;
InspectorAgentState::Boolean script_execution_disabled_; InspectorAgentState::Boolean script_execution_disabled_;
InspectorAgentState::Boolean scrollbars_hidden_; InspectorAgentState::Boolean scrollbars_hidden_;
InspectorAgentState::Boolean document_cookie_disabled_; InspectorAgentState::Boolean document_cookie_disabled_;
......
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