Commit 7605b9a7 authored by Nidhi Jaju's avatar Nidhi Jaju Committed by Commit Bot

Change from GURL to url::Origin in ServiceWorkerContextWrapper

The service worker codebase currently uses a lot of GURLs for origins.
However, url::Origin should be used for origins instead of GURL where
possible due to security decisions. Hence HasRegistrationForOrigin()
was changed to take url::Origin as a parameter, and the related fields
were also modified.

Bug: 1095896
Change-Id: I7843427d163bdf8d1bae6541da86885d29060fdf
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/2249260
Commit-Queue: Nidhi Jaju <nidhijaju@google.com>
Reviewed-by: default avatarMatt Falkenhagen <falken@chromium.org>
Cr-Commit-Position: refs/heads/master@{#779238}
parent f3385bdb
...@@ -2007,7 +2007,7 @@ void ServiceWorkerContextWrapper::DidSetUpLoaderFactoryForUpdateCheck( ...@@ -2007,7 +2007,7 @@ void ServiceWorkerContextWrapper::DidSetUpLoaderFactoryForUpdateCheck(
} }
bool ServiceWorkerContextWrapper::HasRegistrationForOrigin( bool ServiceWorkerContextWrapper::HasRegistrationForOrigin(
const GURL& origin) const { const url::Origin& origin) const {
DCHECK_CURRENTLY_ON(BrowserThread::UI); DCHECK_CURRENTLY_ON(BrowserThread::UI);
return !registrations_initialized_ || return !registrations_initialized_ ||
registrations_for_origin_.find(origin) != registrations_for_origin_.find(origin) !=
...@@ -2030,7 +2030,7 @@ void ServiceWorkerContextWrapper::OnRegistrationUpdated( ...@@ -2030,7 +2030,7 @@ void ServiceWorkerContextWrapper::OnRegistrationUpdated(
registrations_initialized_ = true; registrations_initialized_ = true;
for (const auto& registration : registrations) { for (const auto& registration : registrations) {
GURL origin = registration.scope.GetOrigin(); url::Origin origin = url::Origin::Create(registration.scope);
int64_t registration_id = registration.registration_id; int64_t registration_id = registration.registration_id;
if (registration.delete_flag == ServiceWorkerRegistrationInfo::IS_DELETED) { if (registration.delete_flag == ServiceWorkerRegistrationInfo::IS_DELETED) {
auto& registration_ids = registrations_for_origin_[origin]; auto& registration_ids = registrations_for_origin_[origin];
......
...@@ -331,7 +331,7 @@ class CONTENT_EXPORT ServiceWorkerContextWrapper ...@@ -331,7 +331,7 @@ class CONTENT_EXPORT ServiceWorkerContextWrapper
ServiceWorkerContextCore* context(); ServiceWorkerContextCore* context();
// Whether |origin| has any registrations. Must be called on UI thread. // Whether |origin| has any registrations. Must be called on UI thread.
bool HasRegistrationForOrigin(const GURL& origin) const; bool HasRegistrationForOrigin(const url::Origin& origin) const;
void WaitForRegistrationsInitializedForTest(); void WaitForRegistrationsInitializedForTest();
// This must be called on the core thread, and the |callback| also runs on // This must be called on the core thread, and the |callback| also runs on
...@@ -580,7 +580,8 @@ class CONTENT_EXPORT ServiceWorkerContextWrapper ...@@ -580,7 +580,8 @@ class CONTENT_EXPORT ServiceWorkerContextWrapper
// accessed on UI thread. // accessed on UI thread.
// TODO(http://crbug.com/824858): This can be removed when service workers are // TODO(http://crbug.com/824858): This can be removed when service workers are
// fully converted to running on the UI thread. // fully converted to running on the UI thread.
base::flat_map<GURL, base::flat_set<int64_t>> registrations_for_origin_; base::flat_map<url::Origin, base::flat_set<int64_t>>
registrations_for_origin_;
bool registrations_initialized_ = false; bool registrations_initialized_ = false;
base::OnceClosure on_registrations_initialized_; base::OnceClosure on_registrations_initialized_;
......
...@@ -102,8 +102,10 @@ TEST_F(ServiceWorkerContextWrapperTest, HasRegistration) { ...@@ -102,8 +102,10 @@ TEST_F(ServiceWorkerContextWrapperTest, HasRegistration) {
// Now test that registrations are recognized. // Now test that registrations are recognized.
wrapper_->WaitForRegistrationsInitializedForTest(); wrapper_->WaitForRegistrationsInitializedForTest();
EXPECT_TRUE(wrapper_->HasRegistrationForOrigin(GURL("https://example.com"))); EXPECT_TRUE(wrapper_->HasRegistrationForOrigin(
EXPECT_FALSE(wrapper_->HasRegistrationForOrigin(GURL("https://example.org"))); url::Origin::Create(GURL("https://example.com"))));
EXPECT_FALSE(wrapper_->HasRegistrationForOrigin(
url::Origin::Create(GURL("https://example.org"))));
} }
} // namespace content } // namespace content
...@@ -278,7 +278,7 @@ void ServiceWorkerMainResourceLoaderInterceptor::MaybeCreateLoader( ...@@ -278,7 +278,7 @@ void ServiceWorkerMainResourceLoaderInterceptor::MaybeCreateLoader(
LoaderCallback original_callback; LoaderCallback original_callback;
if (!ServiceWorkerContext::IsServiceWorkerOnUIEnabled() && if (!ServiceWorkerContext::IsServiceWorkerOnUIEnabled() &&
!handle_->context_wrapper()->HasRegistrationForOrigin( !handle_->context_wrapper()->HasRegistrationForOrigin(
tentative_resource_request.url.GetOrigin())) { url::Origin::Create(tentative_resource_request.url))) {
// We have no registrations, so it's safe to continue the request now // We have no registrations, so it's safe to continue the request now
// without blocking on the IO thread. Give a dummy callback to the // without blocking on the IO thread. Give a dummy callback to the
// IO thread interceptor, and we'll run the original callback immediately // IO thread interceptor, and we'll run the original callback immediately
......
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