Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(2)

Side by Side Diff: content/test/data/browsing_data/worker.js

Issue 2368923003: Support the Clear-Site-Data header on resource requests (Closed)
Patch Set: Addressed comments. Created 4 years, 2 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
(Empty)
1 // Copyright 2016 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file.
4
5 // Service worker used in ClearSiteDataThrottleBrowserTest.
6
7 // Handle all resource requests.
8 self.addEventListener('fetch', function(event) {
9 var url = new URL(event.request.url);
10
11 var other_origin_param_regex = /other_origin=([^&=?]+)/;
12 var other_origin = decodeURIComponent(
13 url.search.match(other_origin_param_regex)[1]);
14
15 // If this is a request for 'resource_from_sw', serve that resource
16 // with a Clear-Site-Data header.
17 var resource_request_regex = /resource_from_sw/;
18 var resource_request = !!url.search.match(resource_request_regex);
19
20 if (resource_request) {
21 event.respondWith(new Response(
22 'Response content is not important, only the header is.', {
23 'headers': { 'Clear-Site-Data': '{ "types" : [ "cookies" ] }' }
24 }));
mmenke 2016/10/13 17:16:31 Should we instead / additionally get a network res
msramek 2016/10/17 14:28:31 Done. Yes, that makes more sense actually. I rewr
25 return;
26 }
27
28 // Otherwise, serve the default response - a simple HTML page that embeds
29 // that resource two times.
30 var header = encodeURIComponent('{ "types": [ "cookies" ] }');
31 event.respondWith(new Response(
32 '<html><head></head><body>' +
33 '<img id="res1">' +
34 '<img id="res2">' +
35
36 '<script>' +
37 // When the loading of both resources finishes, we will inform the
38 // C++ side. There, we will verify that Clear-Site-Data was not called.
39 'function done() { window.location.hash = "service-worker-active"; };' +
40 'var res1 = document.getElementById("res1");' +
41 'var res2 = document.getElementById("res2");' +
42 'res1.onload = res2.onload = res1.onerror = res2.onerror = done();' +
43
44 // Load the resource once on this origin and once on a different origin.
45 // In both cases, the Clear-Site-Data header should be ignored.
46 'res1.src = "resource_from_sw&header=' + header + '";' +
47 'res2.src = "' +
48 other_origin + 'resource_from_sw&header=' + header + '";' +
49
50 '</script>' +
51 '</body></html>',
52 { 'headers': { 'Content-Type': 'text/html' } }
53 ));
54 });
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698