Commit 9184a0b4 authored by Julie Jeongeun Kim's avatar Julie Jeongeun Kim Committed by Chromium LUCI CQ

Deprecate blink::mojom::ResourceType in //chrome/browser/signin

This CL replaces blink::mojom::ResourceType with
network::mojom::RequestDestination in //chrome/browser/signin since
blink::mojom::ResourceType is deprecated[1].

It adds IsFetchLikeAPI() to ChromeRequestAdapter to check if
the request has |is_fetch_like_api|.

[1] https://crbug.com/960143

Bug: 1059639
Change-Id: Ic83985731cd724f42447a73521b17a56219d29c6
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/2636895
Commit-Queue: Julie Kim <jkim@igalia.com>
Reviewed-by: default avatarDavid Roger <droger@chromium.org>
Reviewed-by: default avatarKinuko Yasuda <kinuko@chromium.org>
Cr-Commit-Position: refs/heads/master@{#845024}
parent fa2bf3e7
......@@ -46,7 +46,6 @@
#include "content/public/browser/browser_thread.h"
#include "google_apis/gaia/gaia_auth_util.h"
#include "net/http/http_response_headers.h"
#include "third_party/blink/public/mojom/loader/resource_load_info.mojom-shared.h"
#if defined(OS_ANDROID)
#include "chrome/browser/android/signin/signin_bridge.h"
......@@ -136,12 +135,12 @@ class AccountReconcilorLockWrapper
// * Main frame requests.
// * XHR requests having Gaia URL as referrer.
bool ShouldBlockReconcilorForRequest(ChromeRequestAdapter* request) {
blink::mojom::ResourceType resource_type = request->GetResourceType();
if (resource_type == blink::mojom::ResourceType::kMainFrame)
if (request->GetRequestDestination() ==
network::mojom::RequestDestination::kDocument) {
return true;
}
return (resource_type == blink::mojom::ResourceType::kXhr) &&
return request->IsFetchLikeAPI() &&
gaia::IsGaiaSignonRealm(request->GetReferrerOrigin());
}
......
......@@ -14,7 +14,7 @@
#include "chrome/browser/prefs/incognito_mode_prefs.h"
#include "components/signin/core/browser/signin_header_helper.h"
#include "content/public/browser/web_contents.h"
#include "third_party/blink/public/mojom/loader/resource_load_info.mojom-shared.h"
#include "services/network/public/mojom/fetch_api.mojom-shared.h"
namespace content_settings {
class CookieSettings;
......@@ -49,7 +49,9 @@ class ChromeRequestAdapter : public RequestAdapter {
virtual content::WebContents::Getter GetWebContentsGetter() const = 0;
virtual blink::mojom::ResourceType GetResourceType() const = 0;
virtual network::mojom::RequestDestination GetRequestDestination() const = 0;
virtual bool IsFetchLikeAPI() const = 0;
virtual GURL GetReferrerOrigin() const = 0;
......
......@@ -22,6 +22,7 @@
#include "google_apis/gaia/gaia_auth_util.h"
#include "mojo/public/cpp/bindings/receiver.h"
#include "net/base/net_errors.h"
#include "services/network/public/mojom/fetch_api.mojom-shared.h"
#include "services/network/public/mojom/url_loader.mojom.h"
namespace signin {
......@@ -164,8 +165,9 @@ class ProxyingURLLoaderFactory::InProgressRequest
net::HttpRequestHeaders headers_;
net::HttpRequestHeaders cors_exempt_headers_;
net::RedirectInfo redirect_info_;
const blink::mojom::ResourceType resource_type_;
const network::mojom::RequestDestination request_destination_;
const bool is_main_frame_;
const bool is_fetch_like_api_;
base::OnceClosure destruction_callback_;
......@@ -203,8 +205,12 @@ class ProxyingURLLoaderFactory::InProgressRequest::ProxyRequestAdapter
return in_progress_request_->factory_->web_contents_getter_;
}
blink::mojom::ResourceType GetResourceType() const override {
return in_progress_request_->resource_type_;
network::mojom::RequestDestination GetRequestDestination() const override {
return in_progress_request_->request_destination_;
}
bool IsFetchLikeAPI() const override {
return in_progress_request_->is_fetch_like_api_;
}
GURL GetReferrerOrigin() const override {
......@@ -285,9 +291,9 @@ ProxyingURLLoaderFactory::InProgressRequest::InProgressRequest(
request_url_(request.url),
response_url_(request.url),
referrer_origin_(request.referrer.GetOrigin()),
resource_type_(
static_cast<blink::mojom::ResourceType>(request.resource_type)),
request_destination_(request.destination),
is_main_frame_(request.is_main_frame),
is_fetch_like_api_(request.is_fetch_like_api),
target_client_(std::move(client)),
loader_receiver_(this, std::move(loader_receiver)) {
mojo::PendingRemote<network::mojom::URLLoaderClient> proxy_client =
......
......@@ -18,6 +18,7 @@
#include "mojo/public/cpp/bindings/receiver.h"
#include "net/traffic_annotation/network_traffic_annotation_test_helper.h"
#include "services/network/public/cpp/simple_url_loader.h"
#include "services/network/public/mojom/fetch_api.mojom-shared.h"
#include "services/network/test/test_url_loader_factory.h"
#include "testing/gmock/include/gmock/gmock.h"
#include "testing/gtest/include/gtest/gtest.h"
......@@ -138,8 +139,7 @@ TEST_F(ChromeSigninProxyingURLLoaderFactoryTest, ModifyHeaders) {
auto request = std::make_unique<network::ResourceRequest>();
request->url = kTestURL;
request->referrer = kTestReferrer;
request->resource_type =
static_cast<int>(blink::mojom::ResourceType::kMainFrame);
request->destination = network::mojom::RequestDestination::kDocument;
request->is_main_frame = true;
request->headers.SetHeader("X-Request-1", "Foo");
......@@ -158,8 +158,8 @@ TEST_F(ChromeSigninProxyingURLLoaderFactoryTest, ModifyHeaders) {
.WillOnce(
Invoke([&](ChromeRequestAdapter* adapter, const GURL& redirect_url) {
EXPECT_EQ(kTestURL, adapter->GetUrl());
EXPECT_EQ(blink::mojom::ResourceType::kMainFrame,
adapter->GetResourceType());
EXPECT_EQ(network::mojom::RequestDestination::kDocument,
adapter->GetRequestDestination());
EXPECT_EQ(GURL("https://chrome.com"), adapter->GetReferrerOrigin());
EXPECT_TRUE(adapter->HasHeader("X-Request-1"));
......@@ -175,8 +175,8 @@ TEST_F(ChromeSigninProxyingURLLoaderFactoryTest, ModifyHeaders) {
}))
.WillOnce(
Invoke([&](ChromeRequestAdapter* adapter, const GURL& redirect_url) {
EXPECT_EQ(blink::mojom::ResourceType::kMainFrame,
adapter->GetResourceType());
EXPECT_EQ(network::mojom::RequestDestination::kDocument,
adapter->GetRequestDestination());
// Changes to the URL and referrer take effect after the redirect
// is followed.
......
......@@ -31,8 +31,12 @@ class URLLoaderThrottle::ThrottleRequestAdapter : public ChromeRequestAdapter {
return throttle_->web_contents_getter_;
}
blink::mojom::ResourceType GetResourceType() const override {
return throttle_->request_resource_type_;
network::mojom::RequestDestination GetRequestDestination() const override {
return throttle_->request_destination_;
}
bool IsFetchLikeAPI() const override {
return throttle_->request_is_fetch_like_api_;
}
GURL GetReferrerOrigin() const override {
......@@ -64,8 +68,8 @@ class URLLoaderThrottle::ThrottleResponseAdapter : public ResponseAdapter {
}
bool IsMainFrame() const override {
return throttle_->request_resource_type_ ==
blink::mojom::ResourceType::kMainFrame;
return throttle_->request_destination_ ==
network::mojom::RequestDestination::kDocument;
}
GURL GetOrigin() const override {
......@@ -117,8 +121,8 @@ void URLLoaderThrottle::WillStartRequest(network::ResourceRequest* request,
bool* defer) {
request_url_ = request->url;
request_referrer_ = request->referrer;
request_resource_type_ =
static_cast<blink::mojom::ResourceType>(request->resource_type);
request_destination_ = request->destination;
request_is_fetch_like_api_ = request->is_fetch_like_api;
net::HttpRequestHeaders modified_request_headers;
std::vector<std::string> to_be_removed_request_headers;
......
......@@ -8,8 +8,8 @@
#include "base/macros.h"
#include "base/supports_user_data.h"
#include "content/public/browser/web_contents.h"
#include "services/network/public/mojom/fetch_api.mojom-shared.h"
#include "third_party/blink/public/common/loader/url_loader_throttle.h"
#include "third_party/blink/public/mojom/loader/resource_load_info.mojom-shared.h"
namespace signin {
......@@ -57,7 +57,9 @@ class URLLoaderThrottle : public blink::URLLoaderThrottle,
GURL request_referrer_;
net::HttpRequestHeaders request_headers_;
net::HttpRequestHeaders request_cors_exempt_headers_;
blink::mojom::ResourceType request_resource_type_;
network::mojom::RequestDestination request_destination_ =
network::mojom::RequestDestination::kEmpty;
bool request_is_fetch_like_api_ = false;
base::OnceClosure destruction_callback_;
......
......@@ -70,8 +70,8 @@ TEST(ChromeSigninURLLoaderThrottleTest, Intercept) {
.WillOnce(
Invoke([&](ChromeRequestAdapter* adapter, const GURL& redirect_url) {
EXPECT_EQ(kTestURL, adapter->GetUrl());
EXPECT_EQ(blink::mojom::ResourceType::kMainFrame,
adapter->GetResourceType());
EXPECT_EQ(network::mojom::RequestDestination::kDocument,
adapter->GetRequestDestination());
EXPECT_EQ(GURL("https://chrome.com"), adapter->GetReferrerOrigin());
EXPECT_TRUE(adapter->HasHeader("X-Request-1"));
......@@ -89,8 +89,7 @@ TEST(ChromeSigninURLLoaderThrottleTest, Intercept) {
network::ResourceRequest request;
request.url = kTestURL;
request.referrer = kTestReferrer;
request.resource_type =
static_cast<int>(blink::mojom::ResourceType::kMainFrame);
request.destination = network::mojom::RequestDestination::kDocument;
request.headers.SetHeader("X-Request-1", "Foo");
bool defer = false;
throttle->WillStartRequest(&request, &defer);
......@@ -135,8 +134,8 @@ TEST(ChromeSigninURLLoaderThrottleTest, Intercept) {
EXPECT_CALL(*delegate, ProcessRequest(_, _))
.WillOnce(
Invoke([&](ChromeRequestAdapter* adapter, const GURL& redirect_url) {
EXPECT_EQ(blink::mojom::ResourceType::kMainFrame,
adapter->GetResourceType());
EXPECT_EQ(network::mojom::RequestDestination::kDocument,
adapter->GetRequestDestination());
// Changes to the URL and referrer take effect after the redirect
// is followed.
......@@ -240,14 +239,13 @@ TEST(ChromeSigninURLLoaderThrottleTest, InterceptSubFrame) {
.Times(2)
.WillRepeatedly(
[](ChromeRequestAdapter* adapter, const GURL& redirect_url) {
EXPECT_EQ(blink::mojom::ResourceType::kSubFrame,
adapter->GetResourceType());
EXPECT_EQ(network::mojom::RequestDestination::kIframe,
adapter->GetRequestDestination());
});
network::ResourceRequest request;
request.url = GURL("https://google.com");
request.resource_type =
static_cast<int>(blink::mojom::ResourceType::kSubFrame);
request.destination = network::mojom::RequestDestination::kIframe;
bool defer = false;
throttle->WillStartRequest(&request, &defer);
......
......@@ -4257,6 +4257,7 @@ test("unit_tests") {
"//services/device/public/cpp:test_support",
"//services/network:test_support",
"//services/network/public/cpp",
"//services/network/public/mojom",
"//skia",
"//testing/gmock",
"//testing/gtest",
......
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