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

Side by Side Diff: chrome/test/data/extensions/api_test/sandboxed_pages_csp/sandboxed.html

Issue 2563843002: Restrict app sandbox's CSP to disallow loading web content in them. (Closed)
Patch Set: more commetns Created 3 years, 12 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 This page should be sandboxed.
2
3 <script>
4 // We're not served with the extension default CSP, we can use inline script.
5
6 var loadFrameExpectResponse = function(iframe, url) {
7 var identifier = +new Date;
8 return new Promise(function(resolve, reject) {
9 window.addEventListener('message', function(e) {
10 var data = JSON.parse(e.data);
11 if (data[0] == 'pong' && data[1] == identifier) {
Devlin 2016/12/22 17:04:32 all these pings and pongs are getting hard to keep
lazyboy 2016/12/22 22:57:06 Changed to sandboxed frame msg <-> local/remote fr
12 resolve();
13 } else {
14 reject();
15 }
16 });
17 iframe.onerror = reject;
18 iframe.onload = function() {
19 iframe.contentWindow.postMessage(
20 JSON.stringify(['ping', identifier]), '*');
21 };
22 iframe.src = url;
23 });
24 };
25
26 var runTestAndRespond = function(localUrl, remoteUrl) {
27 var iframe = document.createElement('iframe');
28 var sendResponse = function(msg) {
29 var mainWindow = window.opener || window.top;
30 mainWindow.postMessage(msg, '*');
31 };
32
33 // First load local resource in |iframe|, expect the local frame to respond.
34 loadFrameExpectResponse(iframe, localUrl).then(function() {
35 // Then try to load remote resource on the same iframe element. Since the
36 // remote resource will fail to load, expect the local frame to respond
Devlin 2016/12/22 17:04:32 I don't quite follow. So in trying to commit an i
lazyboy 2016/12/22 22:57:06 We keep the current url and resource as is, but if
37 // again.
38 return loadFrameExpectResponse(iframe, remoteUrl);
39 }).then(function() {
40 sendResponse('succeeded');
41 }).catch(function(err) {
42 sendResponse('failed');
43 });
44 document.body.appendChild(iframe);
45 };
46
47 onmessage = function(e) {
48 var command = JSON.parse(e.data);
49 if (command[0] == 'load') {
50 var localUrl = command[1];
51 var remoteUrl = command[2];
52 runTestAndRespond(localUrl, remoteUrl);
53 }
54 };
55
56 </script>
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698