2023-03-15 16:00:52 +00:00
|
|
|
/**
|
|
|
|
* Copyright (c) HashiCorp, Inc.
|
|
|
|
* SPDX-License-Identifier: MPL-2.0
|
|
|
|
*/
|
|
|
|
|
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';
|
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({
|
2021-12-17 03:44:29 +00:00
|
|
|
events: computed(function () {
|
2018-09-25 16:28:26 +00:00
|
|
|
return [];
|
|
|
|
}),
|
2021-12-17 03:44:29 +00:00
|
|
|
connectionViolations: computed('events.@each.violatedDirective', function () {
|
|
|
|
return this.events.filter((e) => e.violatedDirective.startsWith('connect-src'));
|
2019-06-20 13:37:27 +00:00
|
|
|
}),
|
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
|
|
|
|
2021-12-17 03:44:29 +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) {
|
2022-11-09 23:15:31 +00:00
|
|
|
const 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
|
|
|
});
|