feature: only try sending events if the origins match
This commit is contained in:
parent
e8caa02e1a
commit
90399c53a8
|
@ -7,24 +7,26 @@
|
||||||
'https://openusercss.com'
|
'https://openusercss.com'
|
||||||
];
|
];
|
||||||
|
|
||||||
|
const sendPostMessage = message => {
|
||||||
|
allowedOrigins.forEach(origin => {
|
||||||
|
if (origin === location.origin) {
|
||||||
|
window.postMessage(message, origin);
|
||||||
|
}
|
||||||
|
});
|
||||||
|
};
|
||||||
|
|
||||||
const askHandshake = () => {
|
const askHandshake = () => {
|
||||||
// Tell the page that we exist and that it should send the handshake
|
// Tell the page that we exist and that it should send the handshake
|
||||||
allowedOrigins.forEach(origin => {
|
sendPostMessage({
|
||||||
window.postMessage({
|
type: 'ouc-begin-handshake'
|
||||||
type: 'ouc-begin-handshake'
|
|
||||||
}, origin);
|
|
||||||
});
|
});
|
||||||
};
|
};
|
||||||
|
|
||||||
// Listen for queries by the site and respond with a callback object
|
// Listen for queries by the site and respond with a callback object
|
||||||
const sendInstalledCallback = styleData => {
|
const sendInstalledCallback = styleData => {
|
||||||
allowedOrigins.forEach(origin => {
|
sendPostMessage({
|
||||||
if (origin === location.origin) {
|
type: 'ouc-is-installed-response',
|
||||||
window.postMessage({
|
style: styleData
|
||||||
type: 'ouc-is-installed-response',
|
|
||||||
style: styleData
|
|
||||||
}, origin);
|
|
||||||
}
|
|
||||||
});
|
});
|
||||||
};
|
};
|
||||||
|
|
||||||
|
@ -90,15 +92,13 @@
|
||||||
|
|
||||||
// We send the handshake response, which includes the key we got, plus some
|
// We send the handshake response, which includes the key we got, plus some
|
||||||
// additional metadata
|
// additional metadata
|
||||||
allowedOrigins.forEach(origin => {
|
sendPostMessage({
|
||||||
window.postMessage({
|
type: 'ouc-handshake-response',
|
||||||
type: 'ouc-handshake-response',
|
key: event.data.key,
|
||||||
key: event.data.key,
|
extension: {
|
||||||
extension: {
|
name: manifest.name,
|
||||||
name: manifest.name,
|
capabilities: reportedFeatures
|
||||||
capabilities: reportedFeatures
|
}
|
||||||
}
|
|
||||||
}, origin);
|
|
||||||
});
|
});
|
||||||
};
|
};
|
||||||
|
|
||||||
|
@ -118,11 +118,9 @@
|
||||||
const sendInstallCallback = data => {
|
const sendInstallCallback = data => {
|
||||||
// Send an install callback to the site in order to let it know
|
// Send an install callback to the site in order to let it know
|
||||||
// we were able to install the theme and it may display a success message
|
// we were able to install the theme and it may display a success message
|
||||||
allowedOrigins.forEach(origin => {
|
sendPostMessage({
|
||||||
window.postMessage({
|
type: 'ouc-install-callback',
|
||||||
type: 'ouc-install-callback',
|
key: data.key
|
||||||
key: data.key
|
|
||||||
}, origin);
|
|
||||||
});
|
});
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue
Block a user