Commit 10a65146 authored by Valeriya Sinevich's avatar Valeriya Sinevich Committed by Commit Bot

[Signin] Force using XMLHttpRequest for Multilogin even after io11.

Set listAccounts result stale to true on Multilogin finished.

iOS fully working.

Cq-Include-Trybots: luci.chromium.try:ios-simulator-cronet;luci.chromium.try:ios-simulator-full-configs
Change-Id: Id24213b3c2ab8000bbcc6170140de50bcd84986c
Reviewed-on: https://chromium-review.googlesource.com/1245707
Commit-Queue: Valeriya Sinevich <valeriyas@google.com>
Reviewed-by: default avatarDavid Roger <droger@chromium.org>
Cr-Commit-Position: refs/heads/master@{#595119}
parent 82637b85
......@@ -422,8 +422,9 @@ void AccountReconcilor::FinishReconcileWithMultiloginEndpoint(
OnSetAccountsInCookieCompleted(GoogleServiceAuthError::AuthErrorNone());
}
// TODO(valeriyas): Log operation here.
// TODO (valeriyas): Write correct first gaia account to cache for desktop.
if (!is_reconcile_started_)
delegate_->OnReconcileFinished(gaia_accounts[0].id, reconcile_is_noop_);
delegate_->OnReconcileFinished(primary_account, reconcile_is_noop_);
first_execution_ = false;
ScheduleStartReconcileIfChromeAccountsChanged();
}
......
......@@ -1005,6 +1005,9 @@ void GaiaCookieManagerService::StartFetchingListAccounts() {
void GaiaCookieManagerService::OnSetAccountsFinished(
const GoogleServiceAuthError& error) {
// Set ListAccounts result to stale manually because on iOS
// GaiaCookieManagerService is not notified about changes in cookie storage.
list_accounts_stale_ = true;
access_tokens_.clear();
token_requests_.clear();
cookies_to_set_.clear();
......
......@@ -227,6 +227,11 @@ void GaiaAuthFetcher::CancelRequest() {
fetch_pending_ = false;
}
bool GaiaAuthFetcher::IsMultiloginUrl(const GURL& url) {
return base::StartsWith(url.spec(), oauth_multilogin_gurl_.spec(),
base::CompareCase::SENSITIVE);
}
void GaiaAuthFetcher::CreateAndStartGaiaFetcher(
const std::string& body,
const std::string& headers,
......@@ -1116,8 +1121,7 @@ void GaiaAuthFetcher::DispatchFetchedRequest(
OnUberAuthTokenFetch(data, net_error, response_code);
} else if (url == oauth_login_gurl_) {
OnOAuthLoginFetched(data, net_error, response_code);
} else if (base::StartsWith(url.spec(), oauth_multilogin_gurl_.spec(),
base::CompareCase::SENSITIVE)) {
} else if (IsMultiloginUrl(url)) {
OnOAuthMultiloginFetched(data, net_error, response_code);
} else if (url == oauth2_revoke_gurl_) {
OnOAuth2RevokeTokenFetched(data, net_error, response_code);
......
......@@ -196,6 +196,13 @@ class GaiaAuthFetcher {
void SetPendingFetch(bool pending_fetch);
// Needed to use XmlHTTPRequest for Multilogin requeston iOS even after
// iOS11 because WKWebView cannot read response body if content-disposition
// header is set.
// TODO(https://crbug.com/889471) Remove this once requests are done using
// NSUrlSession in iOS.
bool IsMultiloginUrl(const GURL& url);
private:
// The format of the POST body for IssueAuthToken.
static const char kIssueAuthTokenFormat[];
......
......@@ -113,16 +113,16 @@ NSString* EscapeAndQuoteToNSString(const std::string& value) {
// Simulates a POST request on |web_view| using a XMLHttpRequest in
// JavaScript.
// This is needed because WKWebView ignores the HTTPBody in a POST request.
// See
// This is needed because WKWebView ignores the HTTPBody in a POST request
// before iOS11 and because WKWebView cannot read response body if
// content-disposition header is set. See
// https://bugs.webkit.org/show_bug.cgi?id=145410
// TODO(crbug.com/740987): Remove this function workaround once iOS 10 is
// dropped.
// TODO(crbug.com/889471) Remove this once requests are done using
// NSUrlSession in iOS.
void DoPostRequest(WKWebView* web_view,
const std::string& body,
const std::string& headers,
const GURL& url) {
DCHECK(!base::ios::IsRunningOnIOS11OrLater());
NSMutableString* header_data = [NSMutableString string];
net::HttpRequestHeaders request_headers;
request_headers.AddHeadersFromString(headers);
......@@ -200,15 +200,21 @@ void DoPostRequest(WKWebView* web_view,
#pragma mark - GaiaAuthFetcherIOSBridge::Request
GaiaAuthFetcherIOSBridge::Request::Request()
: pending(false), url(), headers(), body() {}
: pending(false),
url(),
headers(),
body(),
shouldUseXmlHTTPRequest(false) {}
GaiaAuthFetcherIOSBridge::Request::Request(const GURL& request_url,
const std::string& request_headers,
const std::string& request_body)
const std::string& request_body,
bool shouldUseXmlHTTPRequest)
: pending(true),
url(request_url),
headers(request_headers),
body(request_body) {}
body(request_body),
shouldUseXmlHTTPRequest(shouldUseXmlHTTPRequest) {}
#pragma mark - GaiaAuthFetcherIOSBridge
......@@ -226,8 +232,9 @@ GaiaAuthFetcherIOSBridge::~GaiaAuthFetcherIOSBridge() {
void GaiaAuthFetcherIOSBridge::Fetch(const GURL& url,
const std::string& headers,
const std::string& body) {
request_ = Request(url, headers, body);
const std::string& body,
bool shouldUseXmlHTTPRequest) {
request_ = Request(url, headers, body, shouldUseXmlHTTPRequest);
FetchPendingRequest();
}
......@@ -265,7 +272,7 @@ void GaiaAuthFetcherIOSBridge::URLFetchFailure(bool is_cancelled) {
void GaiaAuthFetcherIOSBridge::FetchPendingRequest() {
if (!request_.pending)
return;
if (!request_.body.empty() && !base::ios::IsRunningOnIOS11OrLater()) {
if (!request_.body.empty() && request_.shouldUseXmlHTTPRequest) {
DoPostRequest(GetWKWebView(), request_.body, request_.headers,
request_.url);
} else {
......@@ -355,7 +362,9 @@ void GaiaAuthFetcherIOS::CreateAndStartGaiaFetcher(
// a network request with cookies sent and saved is by making it through a
// WKWebView.
SetPendingFetch(true);
bridge_->Fetch(gaia_gurl, headers, body);
bool shouldUseXmlHTTPRequest =
IsMultiloginUrl(gaia_gurl) || !base::ios::IsRunningOnIOS11OrLater();
bridge_->Fetch(gaia_gurl, headers, body, shouldUseXmlHTTPRequest);
}
void GaiaAuthFetcherIOS::CancelRequest() {
......
......@@ -36,7 +36,8 @@ class GaiaAuthFetcherIOSBridge : ActiveStateManager::Observer {
// will be a POST request.
void Fetch(const GURL& url,
const std::string& headers,
const std::string& body);
const std::string& body,
bool shouldUseXmlHTTPRequest);
// Cancels the current fetch.
void Cancel();
......@@ -61,7 +62,8 @@ class GaiaAuthFetcherIOSBridge : ActiveStateManager::Observer {
Request();
Request(const GURL& url,
const std::string& headers,
const std::string& body);
const std::string& body,
bool shouldUseXmlHTTPRequest);
// Whether the request is pending (i.e. awaiting to be processed or
// currently being processed).
bool pending;
......@@ -71,6 +73,9 @@ class GaiaAuthFetcherIOSBridge : ActiveStateManager::Observer {
std::string headers;
// HTTP body to add to the request.
std::string body;
// Whether XmlHTTPRequest should be injected in JS instead of using
// WKWebView directly.
bool shouldUseXmlHTTPRequest;
};
// Fetches the pending request if it exists.
......
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