- Imagelib backward compatibility enhancement: Allow namespace-key as

alternative to `namespace` so as not to break old SVG-Edit which fail
  at *presence* of `namespace` (fixes #274)
- Forward compatibility enhancement: Once IE9 support may be dropped,
  we may post messages as objects, so don't break if objects received
  (embedded API, xdomain, Imagelib)
This commit is contained in:
Brett Zamir
2018-09-25 03:06:22 +08:00
parent 7ff2721ba9
commit 704336c0f2
4 changed files with 19 additions and 7 deletions

View File

@@ -63,11 +63,11 @@ function addCallback (t, {result, error, id: cbid}) {
function messageListener (e) {
// We accept and post strings as opposed to objects for the sake of IE9 support; this
// will most likely be changed in the future
if (typeof e.data !== 'string') {
if (!e.data || !['string', 'object'].includes(typeof e.data)) {
return;
}
const {allowedOrigins} = this,
data = e.data && JSON.parse(e.data);
data = typeof e.data === 'object' ? e.data : JSON.parse(e.data);
if (!data || typeof data !== 'object' || data.namespace !== 'svg-edit' ||
e.source !== this.frame.contentWindow ||
(!allowedOrigins.includes('*') && !allowedOrigins.includes(e.origin))