Revision 3b627befed3cfdb16b26f648899f1f02743c6778 authored by Jan-Ivar Bruaroey on 30 July 2018, 03:24:46 UTC, committed by moz-wptsync-bot on 30 July 2018, 15:06:49 UTC
bugzilla-url: https://bugzilla.mozilla.org/show_bug.cgi?id=1478367
gecko-commit: 61261702f7ac3e0fea9f6903e328b4bf3a529255
gecko-integration-branch: autoland
gecko-reviewers: bwc
1 parent 390fa1b
Raw File
untrusted-event.js
let sender = null;

self.addEventListener('message', e => {
  sender = e.source;

  if (e.data == 'paymentrequest') {
    self.dispatchEvent(new PaymentRequestEvent('paymentrequest', {
      methodData: [{
        supportedMethods: 'basic-card'
      }],
      total: {
        currency: 'USD',
        value: '100'
      },
      modifiers: [{
        supportedMethods: 'basic-card'
      }]
    }));
  } else if (e.data == 'canmakepayment') {
    self.dispatchEvent(new CanMakePaymentEvent('canmakepayment', {
      methodData: [{
        supportedMethods: 'basic-card'
      }],
      modifiers: [{
        supportedMethods: 'basic-card'
      }]
    }));
  }
});

self.addEventListener('paymentrequest', async e => {
  const result = [];

  try {
    e.respondWith({});
  } catch (exception) {
    result.push(exception.name);
  }

  try {
    await e.openWindow('payment-app/payment.html');
  } catch (exception) {
    result.push(exception.name);
  }

  sender.postMessage(result);
});

self.addEventListener('canmakepayment', async e => {
  const result = [];

  try {
    e.respondWith({});
  } catch (exception) {
    result.push(exception.name);
  }

  sender.postMessage(result);
});
back to top