Commit 96d76ad2 authored by Nidhi Jaju's avatar Nidhi Jaju Committed by Commit Bot

Use url::Origin for CountExternalRequests

The service worker codebase currently uses a lot of GURLs for origins.
However, url::Origin should be used for origin instead of GURL where
possible due to security decisions.

This CL changes ServiceWorkerContextWrapper::CountExternalRequests
to use url::Origin instead of GURL. Some relevant callsites have also
been modified accordingly.

Bug: 1095896
Change-Id: I2d9463fc57409baab94fef7197c6229fcf7d0c1f
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/2401343
Commit-Queue: Nidhi Jaju <nidhijaju127@gmail.com>
Reviewed-by: default avatarMatt Falkenhagen <falken@chromium.org>
Reviewed-by: default avatarFrançois Doray <fdoray@chromium.org>
Reviewed-by: default avatarIstiaque Ahmed <lazyboy@chromium.org>
Cr-Commit-Position: refs/heads/master@{#806514}
parent 9d38d619
...@@ -198,7 +198,7 @@ class ServiceWorkerTest : public ExtensionApiTest { ...@@ -198,7 +198,7 @@ class ServiceWorkerTest : public ExtensionApiTest {
return ExtractInnerText(Navigate(url)); return ExtractInnerText(Navigate(url));
} }
size_t GetWorkerRefCount(const GURL& origin) { size_t GetWorkerRefCount(const url::Origin& origin) {
content::ServiceWorkerContext* sw_context = content::ServiceWorkerContext* sw_context =
content::BrowserContext::GetDefaultStoragePartition( content::BrowserContext::GetDefaultStoragePartition(
browser()->profile()) browser()->profile())
...@@ -2089,9 +2089,11 @@ IN_PROC_BROWSER_TEST_F(ServiceWorkerBasedBackgroundTest, WorkerRefCount) { ...@@ -2089,9 +2089,11 @@ IN_PROC_BROWSER_TEST_F(ServiceWorkerBasedBackgroundTest, WorkerRefCount) {
content::WebContents* web_contents = content::WebContents* web_contents =
browser()->tab_strip_model()->GetActiveWebContents(); browser()->tab_strip_model()->GetActiveWebContents();
url::Origin extension_origin = url::Origin::Create(extension->url());
// Service worker should have no pending requests because it hasn't performed // Service worker should have no pending requests because it hasn't performed
// any extension API request yet. // any extension API request yet.
EXPECT_EQ(0u, GetWorkerRefCount(extension->url())); EXPECT_EQ(0u, GetWorkerRefCount(extension_origin));
ExtensionTestMessageListener worker_listener("CHECK_REF_COUNT", true); ExtensionTestMessageListener worker_listener("CHECK_REF_COUNT", true);
worker_listener.set_failure_message("FAILURE"); worker_listener.set_failure_message("FAILURE");
...@@ -2100,7 +2102,7 @@ IN_PROC_BROWSER_TEST_F(ServiceWorkerBasedBackgroundTest, WorkerRefCount) { ...@@ -2100,7 +2102,7 @@ IN_PROC_BROWSER_TEST_F(ServiceWorkerBasedBackgroundTest, WorkerRefCount) {
// Service worker should have exactly one pending request because // Service worker should have exactly one pending request because
// chrome.test.sendMessage() API call is in-flight. // chrome.test.sendMessage() API call is in-flight.
EXPECT_EQ(1u, GetWorkerRefCount(extension->url())); EXPECT_EQ(1u, GetWorkerRefCount(extension_origin));
// Perform another extension API request while one is ongoing. // Perform another extension API request while one is ongoing.
{ {
...@@ -2111,7 +2113,7 @@ IN_PROC_BROWSER_TEST_F(ServiceWorkerBasedBackgroundTest, WorkerRefCount) { ...@@ -2111,7 +2113,7 @@ IN_PROC_BROWSER_TEST_F(ServiceWorkerBasedBackgroundTest, WorkerRefCount) {
ASSERT_TRUE(listener.WaitUntilSatisfied()); ASSERT_TRUE(listener.WaitUntilSatisfied());
// Service worker currently has two extension API requests in-flight. // Service worker currently has two extension API requests in-flight.
EXPECT_EQ(2u, GetWorkerRefCount(extension->url())); EXPECT_EQ(2u, GetWorkerRefCount(extension_origin));
// Finish executing the nested chrome.test.sendMessage() first. // Finish executing the nested chrome.test.sendMessage() first.
listener.Reply("Hello world"); listener.Reply("Hello world");
} }
...@@ -2138,7 +2140,7 @@ IN_PROC_BROWSER_TEST_F(ServiceWorkerBasedBackgroundTest, WorkerRefCount) { ...@@ -2138,7 +2140,7 @@ IN_PROC_BROWSER_TEST_F(ServiceWorkerBasedBackgroundTest, WorkerRefCount) {
} }
// The ref count should drop to 0. // The ref count should drop to 0.
EXPECT_EQ(0u, GetWorkerRefCount(extension->url())); EXPECT_EQ(0u, GetWorkerRefCount(extension_origin));
} }
const char* kEventsToStoppedExtensionId = "ogdbpbegnmindpdjfafpmpicikegejdj"; const char* kEventsToStoppedExtensionId = "ogdbpbegnmindpdjfafpmpicikegejdj";
......
...@@ -111,7 +111,7 @@ ServiceWorkerContextAdapter::FinishedExternalRequest( ...@@ -111,7 +111,7 @@ ServiceWorkerContextAdapter::FinishedExternalRequest(
} }
void ServiceWorkerContextAdapter::CountExternalRequestsForTest( void ServiceWorkerContextAdapter::CountExternalRequestsForTest(
const GURL& origin, const url::Origin& origin,
CountExternalRequestsCallback callback) { CountExternalRequestsCallback callback) {
NOTIMPLEMENTED(); NOTIMPLEMENTED();
} }
......
...@@ -59,7 +59,7 @@ class ServiceWorkerContextAdapter ...@@ -59,7 +59,7 @@ class ServiceWorkerContextAdapter
int64_t service_worker_version_id, int64_t service_worker_version_id,
const std::string& request_uuid) override; const std::string& request_uuid) override;
void CountExternalRequestsForTest( void CountExternalRequestsForTest(
const GURL& origin, const url::Origin& origin,
CountExternalRequestsCallback callback) override; CountExternalRequestsCallback callback) override;
bool MaybeHasRegistrationForOrigin(const url::Origin& origin) override; bool MaybeHasRegistrationForOrigin(const url::Origin& origin) override;
void GetInstalledRegistrationOrigins( void GetInstalledRegistrationOrigins(
......
...@@ -572,7 +572,7 @@ ServiceWorkerContextWrapper::FinishedExternalRequest( ...@@ -572,7 +572,7 @@ ServiceWorkerContextWrapper::FinishedExternalRequest(
} }
void ServiceWorkerContextWrapper::CountExternalRequestsForTest( void ServiceWorkerContextWrapper::CountExternalRequestsForTest(
const GURL& origin, const url::Origin& origin,
CountExternalRequestsCallback callback) { CountExternalRequestsCallback callback) {
DCHECK_CURRENTLY_ON(BrowserThread::UI); DCHECK_CURRENTLY_ON(BrowserThread::UI);
base::PostTask( base::PostTask(
...@@ -1833,7 +1833,7 @@ void ServiceWorkerContextWrapper::DidFindRegistrationForUpdate( ...@@ -1833,7 +1833,7 @@ void ServiceWorkerContextWrapper::DidFindRegistrationForUpdate(
} }
void ServiceWorkerContextWrapper::CountExternalRequests( void ServiceWorkerContextWrapper::CountExternalRequests(
const GURL& origin, const url::Origin& origin,
CountExternalRequestsCallback callback) { CountExternalRequestsCallback callback) {
DCHECK_CURRENTLY_ON(GetCoreThreadId()); DCHECK_CURRENTLY_ON(GetCoreThreadId());
...@@ -1842,7 +1842,7 @@ void ServiceWorkerContextWrapper::CountExternalRequests( ...@@ -1842,7 +1842,7 @@ void ServiceWorkerContextWrapper::CountExternalRequests(
size_t pending_external_request_count = 0; size_t pending_external_request_count = 0;
for (const ServiceWorkerVersionInfo& info : live_version_info) { for (const ServiceWorkerVersionInfo& info : live_version_info) {
ServiceWorkerVersion* version = GetLiveVersion(info.version_id); ServiceWorkerVersion* version = GetLiveVersion(info.version_id);
if (version && version->scope().GetOrigin() == origin) { if (version && version->origin() == origin) {
pending_external_request_count = pending_external_request_count =
version->GetExternalRequestCountForTest(); version->GetExternalRequestCountForTest();
break; break;
......
...@@ -171,7 +171,7 @@ class CONTENT_EXPORT ServiceWorkerContextWrapper ...@@ -171,7 +171,7 @@ class CONTENT_EXPORT ServiceWorkerContextWrapper
int64_t service_worker_version_id, int64_t service_worker_version_id,
const std::string& request_uuid) override; const std::string& request_uuid) override;
void CountExternalRequestsForTest( void CountExternalRequestsForTest(
const GURL& url, const url::Origin& origin,
CountExternalRequestsCallback callback) override; CountExternalRequestsCallback callback) override;
bool MaybeHasRegistrationForOrigin(const url::Origin& origin) override; bool MaybeHasRegistrationForOrigin(const url::Origin& origin) override;
void GetInstalledRegistrationOrigins( void GetInstalledRegistrationOrigins(
...@@ -436,7 +436,7 @@ class CONTENT_EXPORT ServiceWorkerContextWrapper ...@@ -436,7 +436,7 @@ class CONTENT_EXPORT ServiceWorkerContextWrapper
blink::ServiceWorkerStatusCode status, blink::ServiceWorkerStatusCode status,
scoped_refptr<content::ServiceWorkerRegistration> registration); scoped_refptr<content::ServiceWorkerRegistration> registration);
void CountExternalRequests(const GURL& url, void CountExternalRequests(const url::Origin& origin,
CountExternalRequestsCallback callback); CountExternalRequestsCallback callback);
void DidFindRegistrationForNavigationHint( void DidFindRegistrationForNavigationHint(
......
...@@ -157,7 +157,7 @@ class CONTENT_EXPORT ServiceWorkerContext { ...@@ -157,7 +157,7 @@ class CONTENT_EXPORT ServiceWorkerContext {
// specified |origin| via |callback|. Must be called from the UI thread. The // specified |origin| via |callback|. Must be called from the UI thread. The
// callback is called on the UI thread. // callback is called on the UI thread.
virtual void CountExternalRequestsForTest( virtual void CountExternalRequestsForTest(
const GURL& origin, const url::Origin& origin,
CountExternalRequestsCallback callback) = 0; CountExternalRequestsCallback callback) = 0;
// Whether |origin| has any registrations. Uninstalling and uninstalled // Whether |origin| has any registrations. Uninstalling and uninstalled
......
...@@ -51,7 +51,7 @@ FakeServiceWorkerContext::FinishedExternalRequest( ...@@ -51,7 +51,7 @@ FakeServiceWorkerContext::FinishedExternalRequest(
return ServiceWorkerExternalRequestResult::kWorkerNotFound; return ServiceWorkerExternalRequestResult::kWorkerNotFound;
} }
void FakeServiceWorkerContext::CountExternalRequestsForTest( void FakeServiceWorkerContext::CountExternalRequestsForTest(
const GURL& url, const url::Origin& origin,
CountExternalRequestsCallback callback) { CountExternalRequestsCallback callback) {
NOTREACHED(); NOTREACHED();
} }
......
...@@ -46,7 +46,7 @@ class FakeServiceWorkerContext : public ServiceWorkerContext { ...@@ -46,7 +46,7 @@ class FakeServiceWorkerContext : public ServiceWorkerContext {
int64_t service_worker_version_id, int64_t service_worker_version_id,
const std::string& request_uuid) override; const std::string& request_uuid) override;
void CountExternalRequestsForTest( void CountExternalRequestsForTest(
const GURL& url, const url::Origin& origin,
CountExternalRequestsCallback callback) override; CountExternalRequestsCallback callback) override;
bool MaybeHasRegistrationForOrigin(const url::Origin& origin) override; bool MaybeHasRegistrationForOrigin(const url::Origin& origin) override;
void GetInstalledRegistrationOrigins( void GetInstalledRegistrationOrigins(
......
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