Skip to content

Commit

Permalink
[DIP] Plumb DIP reporter into ServiceWorker
Browse files Browse the repository at this point in the history
This CL ensures that CORP checks handled by ServiceWorkers and that
fails due to DocumentIsolationPolicy are properly reported to an
appropriate DocumentIsolationPolicyReporter. To do so, it creates a
DocumentIsolationPolicy reporter in the EmbeddedWorkerInstance based on
the DocumentIsolationPolicy passed to the worker.

The DocumentIsolationPolicy reporter and COEP reporter are then
connected to ReportingObservers in the renderer process that are bound
when the WorkerGlobalScope is initialized. This CL updates how this is
currently done for COEP reporter, so that it happens through the
GlobalScopeCreationParams instead of the specific
ServiceWorkerGlobalScope. This will allow to reuse it for COEP and
DocumentIsolationPolicy reporters in DedicatedWorkers and SharedWorkers.

This CL also fixes an issue where DocumentIsolationPolicy was not passed
to the ServiceWorker and was not taken into account for CORP checks
triggered by the ServiceWorker.

The exception for using a non-Blink version of DocumentIsolationPolicy
in the ServiceWorker's CrossOriginResourcePolicyChecker was approved in
https://groups.google.com/a/chromium.org/g/platform-architecture-dev/c/kB9rcdFdIUE/m/IirIrk2nCwAJ.

This CL is part of a chain of CLs implementing DocumentIsolationPolicy
reporting:
1) Add DocumentIsolationPolicyReporter
2) Implement DocumentIsolationPolicyReporter
3) Pass the reporter to URLloaderFactory
4) Plumb DIP reporter into ServiceWorkers <- you are here
5) Add a DIP reporter to DedicatedWorker
6) Add a DIP reporter to SharedWorker
7) Plumb DIP reporter in CacheStorage

Bug: 333029815
Change-Id: I9b3a873867f01c5200be31b50e02687aa30314e8
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/6088945
Reviewed-by: Mike West <[email protected]>
Commit-Queue: Camille Lamy <[email protected]>
Reviewed-by: Hiroki Nakagawa <[email protected]>
Cr-Commit-Position: refs/heads/main@{#1410232}
  • Loading branch information
Camille Lamy authored and chromium-wpt-export-bot committed Jan 23, 2025
1 parent ec1ec56 commit f9bfe8e
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -98,6 +98,20 @@
run: async (test, url, expected_count) => {
return await fetchInFrame(test, FRAME_URL, url, expected_count);
},
}, {
tag: 'between service worker and page',
contextUrl: REPORTING_FRAME_URL,
run: async (test, url, expected_count) => {
// Here we use a Service Worker without COEP.
const WORKER_URL = `${ORIGIN}${BASE}/sw.js`;
const reg = await service_worker_unregister_and_register(
test, WORKER_URL, REPORTING_FRAME_URL);
test.add_cleanup(() => reg.unregister());
const worker = reg.installing || reg.waiting || reg.active;
worker.addEventListener('error', test.unreached_func('Worker.onerror'));
return await fetchInFrame(
test, REPORTING_FRAME_URL, url, expected_count);
},
}];

const CASES = [{
Expand Down
12 changes: 12 additions & 0 deletions html/document-isolation-policy/resources/sw.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
self.addEventListener('activate', (e) => {
e.waitUntil(clients.claim());
});

self.addEventListener('fetch', (e) => {
const url = new URL(e.request.url);
if (url.searchParams.has('passthrough')) {
return;
}

e.respondWith(fetch(e.request));
});

0 comments on commit f9bfe8e

Please sign in to comment.