Commit dddb38e6 authored by Johannes Henkel's avatar Johannes Henkel Committed by Commit Bot

Migrate emulation agent to InspectorSessionState fields...

... except for the virtual time properties. I'll do these
separately so it's possible to review them.

Bug:851762

Change-Id: I49333c7e0265cfc855cdb550e6f3338f74d1ebb1
Reviewed-on: https://chromium-review.googlesource.com/1157696
Commit-Queue: Johannes Henkel <johannes@chromium.org>
Reviewed-by: default avatarAndrey Kosyakov <caseq@chromium.org>
Cr-Commit-Position: refs/heads/master@{#580335}
parent dfc96205
...@@ -28,13 +28,6 @@ using protocol::Maybe; ...@@ -28,13 +28,6 @@ using protocol::Maybe;
using protocol::Response; using protocol::Response;
namespace EmulationAgentState { namespace EmulationAgentState {
static const char kScriptExecutionDisabled[] = "scriptExecutionDisabled";
static const char kScrollbarsHidden[] = "scrollbarsHidden";
static const char kDocumentCookieDisabled[] = "documentCookieDisabled";
static const char kTouchEventEmulationEnabled[] = "touchEventEmulationEnabled";
static const char kMaxTouchPoints[] = "maxTouchPoints";
static const char kEmulatedMedia[] = "emulatedMedia";
static const char kNavigatorPlatform[] = "navigatorPlatform";
static const char kVirtualTimeBudget[] = "virtualTimeBudget"; static const char kVirtualTimeBudget[] = "virtualTimeBudget";
static const char kVirtualTimeBudgetInitalOffset[] = static const char kVirtualTimeBudgetInitalOffset[] =
"virtualTimeBudgetInitalOffset"; "virtualTimeBudgetInitalOffset";
...@@ -44,15 +37,24 @@ static const char kVirtualTimePolicy[] = "virtualTimePolicy"; ...@@ -44,15 +37,24 @@ static const char kVirtualTimePolicy[] = "virtualTimePolicy";
static const char kVirtualTimeTaskStarvationCount[] = static const char kVirtualTimeTaskStarvationCount[] =
"virtualTimeTaskStarvationCount"; "virtualTimeTaskStarvationCount";
static const char kWaitForNavigation[] = "waitForNavigation"; static const char kWaitForNavigation[] = "waitForNavigation";
static const char kUserAgentOverride[] = "userAgentOverride";
static const char kAcceptLanguageOverride[] = "acceptLanguage";
} // namespace EmulationAgentState } // namespace EmulationAgentState
InspectorEmulationAgent::InspectorEmulationAgent( 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_( default_background_color_override_rgba_(&agent_state_,
&agent_state_, /*default_value=*/ WTF::String()) {} /*default_value=*/WTF::String()),
script_execution_disabled_(&agent_state_, /*default_value=*/false),
scrollbars_hidden_(&agent_state_, /*default_value=*/false),
document_cookie_disabled_(&agent_state_, /*default_value=*/false),
touch_event_emulation_enabled_(&agent_state_, /*default_value=*/false),
max_touch_points_(&agent_state_, /*default_value=*/1),
emulated_media_(&agent_state_, /*default_value=*/WTF::String()),
navigator_platform_override_(&agent_state_,
/*default_value=*/WTF::String()),
user_agent_override_(&agent_state_, /*default_value=*/WTF::String()),
accept_language_override_(&agent_state_,
/*default_value=*/WTF::String()) {}
InspectorEmulationAgent::~InspectorEmulationAgent() = default; InspectorEmulationAgent::~InspectorEmulationAgent() = default;
...@@ -61,36 +63,22 @@ WebViewImpl* InspectorEmulationAgent::GetWebViewImpl() { ...@@ -61,36 +63,22 @@ WebViewImpl* InspectorEmulationAgent::GetWebViewImpl() {
} }
void InspectorEmulationAgent::Restore() { void InspectorEmulationAgent::Restore() {
String user_agent; setUserAgentOverride(user_agent_override_.Get(),
state_->getString(EmulationAgentState::kUserAgentOverride, &user_agent); accept_language_override_.Get(),
String accept_language; navigator_platform_override_.Get());
state_->getString(EmulationAgentState::kAcceptLanguageOverride,
&accept_language);
String navigator_platform;
state_->getString(EmulationAgentState::kNavigatorPlatform,
&navigator_platform);
setUserAgentOverride(user_agent, accept_language, navigator_platform);
if (!web_local_frame_) if (!web_local_frame_)
return; return;
// Following code only runs for pages. // Following code only runs for pages.
if (state_->booleanProperty(EmulationAgentState::kScriptExecutionDisabled, if (script_execution_disabled_.Get())
false)) {
GetWebViewImpl()->GetDevToolsEmulator()->SetScriptExecutionDisabled(true); GetWebViewImpl()->GetDevToolsEmulator()->SetScriptExecutionDisabled(true);
} if (scrollbars_hidden_.Get())
if (state_->booleanProperty(EmulationAgentState::kScrollbarsHidden, false))
GetWebViewImpl()->GetDevToolsEmulator()->SetScrollbarsHidden(true); GetWebViewImpl()->GetDevToolsEmulator()->SetScrollbarsHidden(true);
if (state_->booleanProperty(EmulationAgentState::kDocumentCookieDisabled, if (document_cookie_disabled_.Get())
false)) {
GetWebViewImpl()->GetDevToolsEmulator()->SetDocumentCookieDisabled(true); GetWebViewImpl()->GetDevToolsEmulator()->SetDocumentCookieDisabled(true);
} setTouchEmulationEnabled(touch_event_emulation_enabled_.Get(),
setTouchEmulationEnabled( max_touch_points_.Get());
state_->booleanProperty(EmulationAgentState::kTouchEventEmulationEnabled, setEmulatedMedia(emulated_media_.Get());
false),
state_->integerProperty(EmulationAgentState::kMaxTouchPoints, 1));
String emulated_media;
state_->getString(EmulationAgentState::kEmulatedMedia, &emulated_media);
setEmulatedMedia(emulated_media);
if (!default_background_color_override_rgba_.Get().IsNull()) { if (!default_background_color_override_rgba_.Get().IsNull()) {
std::unique_ptr<protocol::Value> parsed = protocol::StringUtil::parseJSON( std::unique_ptr<protocol::Value> parsed = protocol::StringUtil::parseJSON(
default_background_color_override_rgba_.Get()); default_background_color_override_rgba_.Get());
...@@ -200,11 +188,9 @@ Response InspectorEmulationAgent::setScriptExecutionDisabled(bool value) { ...@@ -200,11 +188,9 @@ Response InspectorEmulationAgent::setScriptExecutionDisabled(bool value) {
Response response = AssertPage(); Response response = AssertPage();
if (!response.isSuccess()) if (!response.isSuccess())
return response; return response;
if (state_->booleanProperty(EmulationAgentState::kScriptExecutionDisabled, if (script_execution_disabled_.Get() == value)
false) == value) {
return response; return response;
} script_execution_disabled_.Set(value);
state_->setBoolean(EmulationAgentState::kScriptExecutionDisabled, value);
GetWebViewImpl()->GetDevToolsEmulator()->SetScriptExecutionDisabled(value); GetWebViewImpl()->GetDevToolsEmulator()->SetScriptExecutionDisabled(value);
return response; return response;
} }
...@@ -213,11 +199,9 @@ Response InspectorEmulationAgent::setScrollbarsHidden(bool hidden) { ...@@ -213,11 +199,9 @@ Response InspectorEmulationAgent::setScrollbarsHidden(bool hidden) {
Response response = AssertPage(); Response response = AssertPage();
if (!response.isSuccess()) if (!response.isSuccess())
return response; return response;
if (state_->booleanProperty(EmulationAgentState::kScrollbarsHidden, false) == if (scrollbars_hidden_.Get() == hidden)
hidden) {
return response; return response;
} scrollbars_hidden_.Set(hidden);
state_->setBoolean(EmulationAgentState::kScrollbarsHidden, hidden);
GetWebViewImpl()->GetDevToolsEmulator()->SetScrollbarsHidden(hidden); GetWebViewImpl()->GetDevToolsEmulator()->SetScrollbarsHidden(hidden);
return response; return response;
} }
...@@ -226,11 +210,9 @@ Response InspectorEmulationAgent::setDocumentCookieDisabled(bool disabled) { ...@@ -226,11 +210,9 @@ Response InspectorEmulationAgent::setDocumentCookieDisabled(bool disabled) {
Response response = AssertPage(); Response response = AssertPage();
if (!response.isSuccess()) if (!response.isSuccess())
return response; return response;
if (state_->booleanProperty(EmulationAgentState::kDocumentCookieDisabled, if (document_cookie_disabled_.Get() == disabled)
false) == disabled) {
return response; return response;
} document_cookie_disabled_.Set(disabled);
state_->setBoolean(EmulationAgentState::kDocumentCookieDisabled, disabled);
GetWebViewImpl()->GetDevToolsEmulator()->SetDocumentCookieDisabled(disabled); GetWebViewImpl()->GetDevToolsEmulator()->SetDocumentCookieDisabled(disabled);
return response; return response;
} }
...@@ -247,8 +229,8 @@ Response InspectorEmulationAgent::setTouchEmulationEnabled( ...@@ -247,8 +229,8 @@ Response InspectorEmulationAgent::setTouchEmulationEnabled(
"Touch points must be between 1 and " + "Touch points must be between 1 and " +
String::Number(WebTouchEvent::kTouchesLengthCap)); String::Number(WebTouchEvent::kTouchesLengthCap));
} }
state_->setBoolean(EmulationAgentState::kTouchEventEmulationEnabled, enabled); touch_event_emulation_enabled_.Set(enabled);
state_->setInteger(EmulationAgentState::kMaxTouchPoints, max_points); max_touch_points_.Set(max_points);
GetWebViewImpl()->GetDevToolsEmulator()->SetTouchEventEmulationEnabled( GetWebViewImpl()->GetDevToolsEmulator()->SetTouchEventEmulationEnabled(
enabled, max_points); enabled, max_points);
return response; return response;
...@@ -258,7 +240,7 @@ Response InspectorEmulationAgent::setEmulatedMedia(const String& media) { ...@@ -258,7 +240,7 @@ Response InspectorEmulationAgent::setEmulatedMedia(const String& media) {
Response response = AssertPage(); Response response = AssertPage();
if (!response.isSuccess()) if (!response.isSuccess())
return response; return response;
state_->setString(EmulationAgentState::kEmulatedMedia, media); emulated_media_.Set(media);
GetWebViewImpl()->GetPage()->GetSettings().SetMediaTypeOverride(media); GetWebViewImpl()->GetPage()->GetSettings().SetMediaTypeOverride(media);
return response; return response;
} }
...@@ -398,15 +380,12 @@ void InspectorEmulationAgent::WillSendRequest( ...@@ -398,15 +380,12 @@ void InspectorEmulationAgent::WillSendRequest(
const ResourceResponse& redirect_response, const ResourceResponse& redirect_response,
const FetchInitiatorInfo& initiator_info, const FetchInitiatorInfo& initiator_info,
Resource::Type resource_type) { Resource::Type resource_type) {
String accept_lang_override; if (!accept_language_override_.Get().IsEmpty() &&
state_->getString(EmulationAgentState::kAcceptLanguageOverride,
&accept_lang_override);
if (!accept_lang_override.IsEmpty() &&
request.HttpHeaderField("Accept-Language").IsEmpty()) { request.HttpHeaderField("Accept-Language").IsEmpty()) {
request.SetHTTPHeaderField( request.SetHTTPHeaderField(
"Accept-Language", "Accept-Language",
AtomicString( AtomicString(NetworkUtils::GenerateAcceptLanguageHeader(
NetworkUtils::GenerateAcceptLanguageHeader(accept_lang_override))); accept_language_override_.Get())));
} }
} }
...@@ -415,7 +394,7 @@ Response InspectorEmulationAgent::setNavigatorOverrides( ...@@ -415,7 +394,7 @@ Response InspectorEmulationAgent::setNavigatorOverrides(
Response response = AssertPage(); Response response = AssertPage();
if (!response.isSuccess()) if (!response.isSuccess())
return response; return response;
state_->setString(EmulationAgentState::kNavigatorPlatform, platform); navigator_platform_override_.Set(platform);
GetWebViewImpl()->GetPage()->GetSettings().SetNavigatorPlatformOverride( GetWebViewImpl()->GetPage()->GetSettings().SetNavigatorPlatformOverride(
platform); platform);
return response; return response;
...@@ -499,32 +478,24 @@ Response InspectorEmulationAgent::setUserAgentOverride( ...@@ -499,32 +478,24 @@ Response InspectorEmulationAgent::setUserAgentOverride(
protocol::Maybe<String> platform) { protocol::Maybe<String> platform) {
if (!user_agent.IsEmpty() || accept_language.isJust() || platform.isJust()) if (!user_agent.IsEmpty() || accept_language.isJust() || platform.isJust())
InnerEnable(); InnerEnable();
state_->setString(EmulationAgentState::kUserAgentOverride, user_agent); user_agent_override_.Set(user_agent);
state_->setString(EmulationAgentState::kAcceptLanguageOverride, accept_language_override_.Set(accept_language.fromMaybe(String()));
accept_language.fromMaybe(String())); navigator_platform_override_.Set(platform.fromMaybe(String()));
state_->setString(EmulationAgentState::kNavigatorPlatform,
platform.fromMaybe(String()));
if (web_local_frame_) { if (web_local_frame_) {
GetWebViewImpl()->GetPage()->GetSettings().SetNavigatorPlatformOverride( GetWebViewImpl()->GetPage()->GetSettings().SetNavigatorPlatformOverride(
platform.fromMaybe(String())); navigator_platform_override_.Get());
} }
return Response::OK(); return Response::OK();
} }
void InspectorEmulationAgent::ApplyAcceptLanguageOverride(String* accept_lang) { void InspectorEmulationAgent::ApplyAcceptLanguageOverride(String* accept_lang) {
String accept_lang_override; if (!accept_language_override_.Get().IsEmpty())
state_->getString(EmulationAgentState::kAcceptLanguageOverride, *accept_lang = accept_language_override_.Get();
&accept_lang_override);
if (!accept_lang_override.IsEmpty())
*accept_lang = accept_lang_override;
} }
void InspectorEmulationAgent::ApplyUserAgentOverride(String* user_agent) { void InspectorEmulationAgent::ApplyUserAgentOverride(String* user_agent) {
String user_agent_override; if (!user_agent_override_.Get().IsEmpty())
state_->getString(EmulationAgentState::kUserAgentOverride, *user_agent = user_agent_override_.Get();
&user_agent_override);
if (!user_agent_override.IsEmpty())
*user_agent = user_agent_override;
} }
void InspectorEmulationAgent::InnerEnable() { void InspectorEmulationAgent::InnerEnable() {
......
...@@ -123,6 +123,15 @@ class CORE_EXPORT InspectorEmulationAgent final ...@@ -123,6 +123,15 @@ class CORE_EXPORT InspectorEmulationAgent final
bool enabled_ = false; bool enabled_ = false;
InspectorAgentState::String default_background_color_override_rgba_; InspectorAgentState::String default_background_color_override_rgba_;
InspectorAgentState::Boolean script_execution_disabled_;
InspectorAgentState::Boolean scrollbars_hidden_;
InspectorAgentState::Boolean document_cookie_disabled_;
InspectorAgentState::Boolean touch_event_emulation_enabled_;
InspectorAgentState::Integer max_touch_points_;
InspectorAgentState::String emulated_media_;
InspectorAgentState::String navigator_platform_override_;
InspectorAgentState::String user_agent_override_;
InspectorAgentState::String accept_language_override_;
DISALLOW_COPY_AND_ASSIGN(InspectorEmulationAgent); 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