Commit c7a5668a authored by Richard Li's avatar Richard Li Committed by Commit Bot

[OnionSoup] Move data from RequestExtraData to WebURLRequest::ExtraData.

This CL is a preparation for building typemapping for
blink::ResourceRequest. In the current code, network.mojom.URLRequest
contains members like |render_frame_id|, |is_main_frame|, etc. In cpp
code, these data are saved in RequestExtraData, while blink::RR keeps
|sharable_extra_data_| as a base class point for RequestExtraData.

As a result, when converting blink::RR to URLRequest, the data saved in
RequestExtraData cannot be reached inside blink/ as RequestExtraData is
a data struct in content/.

This CL try to move data (and corresponding getter/setter), from
RequestExtraData to ExtraData. By doing this, we don't need to touch any
user of these two classes, as we are still keeping the original member
functions' prototype. Then moved data can be touched when making
conversion between blink::RR and network.mojom.URLRequest.

Change-Id: I6995b64ff9da6bef0d70b22b5ec1167bd1e8666f
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/1542727Reviewed-by: default avatarKinuko Yasuda <kinuko@chromium.org>
Commit-Queue: Richard Li <richard.li@intel.com>
Cr-Commit-Position: refs/heads/master@{#646616}
parent 39a7ba52
......@@ -26,6 +26,7 @@
#include "content/public/test/test_browser_thread_bundle.h"
#include "content/public/test/test_utils.h"
#include "testing/gtest/include/gtest/gtest.h"
#include "third_party/blink/public/common/service_worker/service_worker_types.h"
#include "third_party/blink/public/mojom/service_worker/service_worker_event_status.mojom.h"
#include "third_party/blink/public/mojom/service_worker/service_worker_registration.mojom.h"
......@@ -872,7 +873,7 @@ TEST_F(ServiceWorkerContextTest, ProviderHostIterator) {
kRenderProcessId2, true /* is_parent_frame_secure */, version.get(),
context()->AsWeakPtr(), &remote_endpoints.back());
const int host4_provider_id = host4->provider_id();
EXPECT_NE(host4_provider_id, kInvalidServiceWorkerProviderId);
EXPECT_NE(host4_provider_id, blink::kInvalidServiceWorkerProviderId);
ServiceWorkerProviderHost* host1_raw = host1.get();
ServiceWorkerProviderHost* host2_raw = host2.get();
......
......@@ -54,7 +54,6 @@ extern const char kServiceWorkerCopyScriptError[];
// Constants for invalid identifiers.
static const int kInvalidEmbeddedWorkerThreadId = -1;
static const int kInvalidServiceWorkerProviderId = -1;
static const int64_t kInvalidServiceWorkerResourceId = -1;
// The HTTP cache is bypassed for Service Worker scripts if the last network
......
......@@ -17,7 +17,6 @@
#include "content/renderer/loader/web_url_loader_impl.h"
#include "third_party/blink/public/platform/web_string.h"
#include "third_party/blink/public/platform/web_url_request.h"
#include "ui/base/page_transition_types.h"
namespace network {
struct ResourceRequest;
......@@ -33,34 +32,6 @@ class CONTENT_EXPORT RequestExtraData : public blink::WebURLRequest::ExtraData {
RequestExtraData();
~RequestExtraData() override;
void set_is_preprerendering(bool is_prerendering) {
is_prerendering_ = is_prerendering;
}
void set_render_frame_id(int render_frame_id) {
render_frame_id_ = render_frame_id;
}
void set_is_main_frame(bool is_main_frame) {
is_main_frame_ = is_main_frame;
}
void set_allow_download(bool allow_download) {
allow_download_ = allow_download;
}
ui::PageTransition transition_type() const { return transition_type_; }
void set_transition_type(ui::PageTransition transition_type) {
transition_type_ = transition_type;
}
int service_worker_provider_id() const {
return service_worker_provider_id_;
}
void set_service_worker_provider_id(
int service_worker_provider_id) {
service_worker_provider_id_ = service_worker_provider_id;
}
// true if the request originated from within a service worker e.g. due to
// a fetch() in the service worker script.
void set_originated_from_service_worker(bool originated_from_service_worker) {
originated_from_service_worker_ = originated_from_service_worker;
}
// |custom_user_agent| is used to communicate an overriding custom user agent
// to |RenderViewImpl::willSendRequest()|; set to a null string to indicate no
// override and an empty string to indicate that there should be no user
......@@ -84,10 +55,6 @@ class CONTENT_EXPORT RequestExtraData : public blink::WebURLRequest::ExtraData {
navigation_response_override_ = std::move(response_override);
}
void set_initiated_in_secure_context(bool secure) {
initiated_in_secure_context_ = secure;
}
// The request is for a prefetch-only client (i.e. running NoStatePrefetch)
// and should use LOAD_PREFETCH network flags.
bool is_for_no_state_prefetch() const { return is_for_no_state_prefetch_; }
......@@ -103,14 +70,6 @@ class CONTENT_EXPORT RequestExtraData : public blink::WebURLRequest::ExtraData {
void set_block_mixed_plugin_content(bool block_mixed_plugin_content) {
block_mixed_plugin_content_ = block_mixed_plugin_content;
}
// Determines whether SameSite cookies will be attached to the request
// even when the request looks cross-site.
bool attach_same_site_cookies() const { return attach_same_site_cookies_; }
void set_attach_same_site_cookies(bool attach) {
attach_same_site_cookies_ = attach;
}
std::vector<std::unique_ptr<URLLoaderThrottle>> TakeURLLoaderThrottles() {
return std::move(url_loader_throttles_);
}
......@@ -118,12 +77,10 @@ class CONTENT_EXPORT RequestExtraData : public blink::WebURLRequest::ExtraData {
std::vector<std::unique_ptr<URLLoaderThrottle>> throttles) {
url_loader_throttles_ = std::move(throttles);
}
void set_frame_request_blocker(
scoped_refptr<FrameRequestBlocker> frame_request_blocker) {
frame_request_blocker_ = frame_request_blocker;
}
scoped_refptr<FrameRequestBlocker> frame_request_blocker() {
return frame_request_blocker_;
}
......@@ -131,20 +88,11 @@ class CONTENT_EXPORT RequestExtraData : public blink::WebURLRequest::ExtraData {
void CopyToResourceRequest(network::ResourceRequest* request) const;
private:
bool is_prerendering_ = false;
int render_frame_id_ = MSG_ROUTING_NONE;
bool is_main_frame_ = false;
bool allow_download_ = true;
ui::PageTransition transition_type_ = ui::PAGE_TRANSITION_LINK;
int service_worker_provider_id_ = kInvalidServiceWorkerProviderId;
bool originated_from_service_worker_ = false;
blink::WebString custom_user_agent_;
std::unique_ptr<NavigationResponseOverrideParameters>
navigation_response_override_;
bool initiated_in_secure_context_ = false;
bool is_for_no_state_prefetch_ = false;
bool block_mixed_plugin_content_ = false;
bool attach_same_site_cookies_ = false;
std::vector<std::unique_ptr<URLLoaderThrottle>> url_loader_throttles_;
scoped_refptr<FrameRequestBlocker> frame_request_blocker_;
......
......@@ -34,6 +34,7 @@
#include "services/network/public/cpp/wrapper_shared_url_loader_factory.h"
#include "services/service_manager/public/cpp/connector.h"
#include "third_party/blink/public/common/features.h"
#include "third_party/blink/public/common/service_worker/service_worker_types.h"
#include "third_party/blink/public/mojom/service_worker/service_worker_object.mojom.h"
#include "third_party/blink/public/mojom/service_worker/service_worker_provider.mojom.h"
#include "third_party/blink/public/platform/web_security_origin.h"
......@@ -197,7 +198,7 @@ scoped_refptr<WebWorkerFetchContextImpl> WebWorkerFetchContextImpl::Create(
worker_fetch_context->set_client_id(provider_context->client_id());
} else {
worker_fetch_context->set_service_worker_provider_id(
kInvalidServiceWorkerProviderId);
blink::kInvalidServiceWorkerProviderId);
worker_fetch_context->set_is_controlled_by_service_worker(
blink::mojom::ControllerServiceWorkerMode::kNoController);
}
......
......@@ -16,6 +16,7 @@
#include "services/network/public/cpp/shared_url_loader_factory.h"
#include "services/network/public/mojom/url_loader_factory.mojom.h"
#include "services/service_manager/public/cpp/connector.h"
#include "third_party/blink/public/common/service_worker/service_worker_types.h"
#include "third_party/blink/public/mojom/appcache/appcache.mojom.h"
#include "third_party/blink/public/mojom/blob/blob_registry.mojom.h"
#include "third_party/blink/public/mojom/renderer_preference_watcher.mojom.h"
......@@ -200,7 +201,7 @@ class CONTENT_EXPORT WebWorkerFetchContextImpl
// Consumed on the worker thread to create |fallback_factory_|.
std::unique_ptr<network::SharedURLLoaderFactoryInfo> fallback_factory_info_;
int service_worker_provider_id_ = kInvalidServiceWorkerProviderId;
int service_worker_provider_id_ = blink::kInvalidServiceWorkerProviderId;
blink::mojom::ControllerServiceWorkerMode is_controlled_by_service_worker_ =
blink::mojom::ControllerServiceWorkerMode::kNoController;
......
......@@ -14,6 +14,7 @@
#include "content/renderer/render_thread_impl.h"
#include "content/renderer/service_worker/service_worker_provider_context.h"
#include "services/network/public/cpp/weak_wrapper_shared_url_loader_factory.h"
#include "third_party/blink/public/common/service_worker/service_worker_types.h"
#include "third_party/blink/public/common/service_worker/service_worker_utils.h"
#include "third_party/blink/public/web/web_local_frame.h"
......@@ -184,7 +185,7 @@ void ServiceWorkerNetworkProviderForFrame::DispatchNetworkQuiet() {
int ServiceWorkerNetworkProviderForFrame::provider_id() const {
if (!context_)
return kInvalidServiceWorkerProviderId;
return blink::kInvalidServiceWorkerProviderId;
return context_->provider_id();
}
......
......@@ -15,6 +15,7 @@
#include "content/renderer/service_worker/service_worker_provider_context.h"
#include "services/network/public/cpp/features.h"
#include "services/network/public/cpp/weak_wrapper_shared_url_loader_factory.h"
#include "third_party/blink/public/common/service_worker/service_worker_types.h"
#include "third_party/blink/public/common/service_worker/service_worker_utils.h"
#include "third_party/blink/public/mojom/service_worker/service_worker_object.mojom.h"
......@@ -114,7 +115,7 @@ void ServiceWorkerNetworkProviderForWorker::DispatchNetworkQuiet() {}
int ServiceWorkerNetworkProviderForWorker::provider_id() const {
if (!context_)
return kInvalidServiceWorkerProviderId;
return blink::kInvalidServiceWorkerProviderId;
return context_->provider_id();
}
......
......@@ -569,6 +569,7 @@ source_set("blink_headers") {
"//third_party/webrtc/rtc_base:rtc_base",
"//third_party/webrtc/rtc_base:rtc_task_queue",
"//third_party/webrtc_overrides:init_webrtc",
"//ui/base:base",
"//v8:v8_headers",
]
}
......
......@@ -95,6 +95,7 @@ source_set("headers") {
"screen_orientation/web_screen_orientation_type.h",
"service_worker/service_worker_status_code.h",
"service_worker/service_worker_type_converters.h",
"service_worker/service_worker_types.h",
"service_worker/service_worker_utils.h",
"user_agent/user_agent_metadata.h",
]
......
// Copyright 2019 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
#ifndef THIRD_PARTY_BLINK_PUBLIC_COMMON_SERVICE_WORKER_SERVICE_WORKER_TYPES_H_
#define THIRD_PARTY_BLINK_PUBLIC_COMMON_SERVICE_WORKER_SERVICE_WORKER_TYPES_H_
namespace blink {
// Constants for invalid identifiers.
static const int kInvalidServiceWorkerProviderId = -1;
} // namespace blink
#endif // THIRD_PARTY_BLINK_PUBLIC_COMMON_SERVICE_WORKER_SERVICE_WORKER_TYPES_H_
......@@ -45,6 +45,7 @@ include_rules = [
"-third_party/blink/public/web",
"-third_party/blink/renderer/bindings",
"+third_party/skia",
"+ui/base/page_transition_types.h",
"+ui/gfx",
"+url",
"-web",
......
......@@ -36,8 +36,10 @@
#include "base/time/time.h"
#include "base/unguessable_token.h"
#include "services/network/public/mojom/referrer_policy.mojom-shared.h"
#include "third_party/blink/public/common/service_worker/service_worker_types.h"
#include "third_party/blink/public/mojom/fetch/fetch_api_request.mojom-shared.h"
#include "third_party/blink/public/platform/web_common.h"
#include "ui/base/page_transition_types.h"
namespace network {
namespace mojom {
......@@ -114,7 +116,58 @@ class WebURLRequest {
class ExtraData {
public:
void set_is_preprerendering(bool is_prerendering) {
is_prerendering_ = is_prerendering;
}
void set_render_frame_id(int render_frame_id) {
render_frame_id_ = render_frame_id;
}
void set_is_main_frame(bool is_main_frame) {
is_main_frame_ = is_main_frame;
}
void set_allow_download(bool allow_download) {
allow_download_ = allow_download;
}
ui::PageTransition transition_type() const { return transition_type_; }
void set_transition_type(ui::PageTransition transition_type) {
transition_type_ = transition_type;
}
int service_worker_provider_id() const {
return service_worker_provider_id_;
}
void set_service_worker_provider_id(int service_worker_provider_id) {
service_worker_provider_id_ = service_worker_provider_id;
}
// true if the request originated from within a service worker e.g. due to
// a fetch() in the service worker script.
void set_originated_from_service_worker(
bool originated_from_service_worker) {
originated_from_service_worker_ = originated_from_service_worker;
}
void set_initiated_in_secure_context(bool secure) {
initiated_in_secure_context_ = secure;
}
// Determines whether SameSite cookies will be attached to the request
// even when the request looks cross-site.
bool attach_same_site_cookies() const { return attach_same_site_cookies_; }
void set_attach_same_site_cookies(bool attach) {
attach_same_site_cookies_ = attach;
}
virtual ~ExtraData() = default;
protected:
bool is_prerendering_ = false;
int render_frame_id_ = MSG_ROUTING_NONE;
bool is_main_frame_ = false;
bool allow_download_ = true;
ui::PageTransition transition_type_ = ui::PAGE_TRANSITION_LINK;
int service_worker_provider_id_ = blink::kInvalidServiceWorkerProviderId;
bool originated_from_service_worker_ = false;
bool initiated_in_secure_context_ = false;
bool attach_same_site_cookies_ = false;
};
BLINK_PLATFORM_EXPORT ~WebURLRequest();
......
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