Commit c22bb097 authored by Gauthier Ambard's avatar Gauthier Ambard Committed by Commit Bot

[iOS] Automatic UA is restored when flag is enabled

This CL makes sure that the AUTOMATIC UserAgentType is restored in the
WebState when the flag to have the AUTOMATIC UserAgent is enabled.
In some cases (for example after updating the flag), the session is
restored with the AUTOMATIC UserAgent, leading to a DCHECK.

Bug: None
Change-Id: Iceb9e8b2af25db987e80f07e9fbb2911d0c4f0c6
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/2329709Reviewed-by: default avatarAli Juma <ajuma@chromium.org>
Reviewed-by: default avatarSebastien Lalancette <seblalancette@chromium.org>
Commit-Queue: Gauthier Ambard <gambard@chromium.org>
Auto-Submit: Gauthier Ambard <gambard@chromium.org>
Cr-Commit-Position: refs/heads/master@{#793604}
parent 476d8ad8
...@@ -8,6 +8,7 @@ ...@@ -8,6 +8,7 @@
#include "base/check_op.h" #include "base/check_op.h"
#include "base/mac/foundation_util.h" #include "base/mac/foundation_util.h"
#include "ios/web/common/features.h"
#import "ios/web/navigation/navigation_item_impl.h" #import "ios/web/navigation/navigation_item_impl.h"
#import "ios/web/navigation/navigation_item_storage_builder.h" #import "ios/web/navigation/navigation_item_storage_builder.h"
#include "ios/web/navigation/navigation_manager_impl.h" #include "ios/web/navigation/navigation_manager_impl.h"
...@@ -113,7 +114,12 @@ void SessionStorageBuilder::ExtractSessionState( ...@@ -113,7 +114,12 @@ void SessionStorageBuilder::ExtractSessionState(
web_state->certificate_policy_cache_ = std::move(cert_policy_cache); web_state->certificate_policy_cache_ = std::move(cert_policy_cache);
web::SerializableUserDataManager::FromWebState(web_state) web::SerializableUserDataManager::FromWebState(web_state)
->AddSerializableUserData(storage.userData); ->AddSerializableUserData(storage.userData);
web_state->SetUserAgent(storage.userAgentType); UserAgentType user_agent_type = storage.userAgentType;
if (user_agent_type == UserAgentType::AUTOMATIC &&
!features::UseWebClientDefaultUserAgent()) {
user_agent_type = UserAgentType::MOBILE;
}
web_state->SetUserAgent(user_agent_type);
} }
} // namespace web } // namespace web
...@@ -110,8 +110,13 @@ NSString* const kLastCommittedItemIndexDeprecatedKey = ...@@ -110,8 +110,13 @@ NSString* const kLastCommittedItemIndexDeprecatedKey =
forKey:kCertificatePolicyCacheStorageKey]; forKey:kCertificatePolicyCacheStorageKey];
if (_userData) if (_userData)
_userData->Encode(coder); _userData->Encode(coder);
web::UserAgentType userAgentType = _userAgentType;
if (userAgentType == web::UserAgentType::AUTOMATIC &&
!web::features::UseWebClientDefaultUserAgent()) {
userAgentType = web::UserAgentType::MOBILE;
}
web::nscoder_util::EncodeString( web::nscoder_util::EncodeString(
coder, kUserAgentKey, web::GetUserAgentTypeDescription(_userAgentType)); coder, kUserAgentKey, web::GetUserAgentTypeDescription(userAgentType));
} }
@end @end
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