2018-04-09 21:50:36 +00:00
|
|
|
/*eslint-disable no-constant-condition*/
|
2018-09-25 16:28:26 +00:00
|
|
|
import { computed } from '@ember/object';
|
|
|
|
import { filterBy } from '@ember/object/computed';
|
2018-04-05 21:36:33 +00:00
|
|
|
|
2018-09-25 16:28:26 +00:00
|
|
|
import Service from '@ember/service';
|
|
|
|
import { task, waitForEvent } from 'ember-concurrency';
|
2018-04-05 21:36:33 +00:00
|
|
|
|
2018-04-09 21:50:36 +00:00
|
|
|
export default Service.extend({
|
2018-09-25 16:28:26 +00:00
|
|
|
events: computed(function() {
|
|
|
|
return [];
|
|
|
|
}),
|
|
|
|
connectionViolations: filterBy('events', 'violatedDirective', 'connect-src'),
|
2018-04-05 21:36:33 +00:00
|
|
|
|
|
|
|
attach() {
|
2018-10-06 02:58:54 +00:00
|
|
|
this.monitor.perform();
|
2018-04-05 21:36:33 +00:00
|
|
|
},
|
|
|
|
|
|
|
|
remove() {
|
2018-10-06 02:58:54 +00:00
|
|
|
this.monitor.cancelAll();
|
2018-04-05 21:36:33 +00:00
|
|
|
},
|
2018-04-09 21:50:36 +00:00
|
|
|
|
|
|
|
monitor: task(function*() {
|
2018-10-06 02:58:54 +00:00
|
|
|
this.events.clear();
|
2018-04-09 21:50:36 +00:00
|
|
|
|
|
|
|
while (true) {
|
|
|
|
let event = yield waitForEvent(window.document, 'securitypolicyviolation');
|
2018-10-06 02:58:54 +00:00
|
|
|
this.events.addObject(event);
|
2018-04-09 21:50:36 +00:00
|
|
|
}
|
|
|
|
}),
|
2018-04-05 21:36:33 +00:00
|
|
|
});
|