Пример #1
0
  initializeSandbox: function(sandbox) {
    assert(sandbox.type !== 'html', "Inline adapter only supports type `js` sandboxes, but type `html` was requested.");

    sandbox.el = document.createElement('div');

    var oasis = sandbox.sandboxedOasis = new Oasis();
    sandbox.sandboxedOasis.sandbox = sandbox;

    return RSVP.resolve();
  },
Пример #2
0
  initializeSandbox: function(sandbox) {
    assert(sandbox.type !== 'html', "Webworker adapter only supports type `js` sandboxes, but type `html` was requested.");

    var oasisURL = this.oasisURL(sandbox);
    var worker = new Worker(oasisURL);
    worker.name = sandbox.options.url + '?uuid=' + UUID.generate();
    sandbox.worker = worker;

    // Error handling inside the worker
    worker.errorHandler = function(event) {
      if(!event.data.sandboxException) {return;}

      sandbox.onerror( event.data.sandboxException );
    };
    addEventListener(worker, 'message', worker.errorHandler);

    sandbox._waitForLoadDeferred().resolve(new RSVP.Promise( function(resolve, reject) {
      worker.initializationHandler = function (event) {
        sandbox.oasis.configuration.eventCallback(function () {
          if( event.data !== sandbox.adapter.sandboxInitializedMessage ) {return;}
          removeEventListener(worker, 'message', worker.initializationHandler);

          Logger.log("worker sandbox initialized");
          resolve(sandbox);
        });
      };
      addEventListener(worker, 'message', worker.initializationHandler);
    }));

    return new RSVP.Promise(function (resolve, reject) {
      worker.loadHandler = function (event) {
        sandbox.oasis.configuration.eventCallback(function () {
          if( event.data !== sandbox.adapter.oasisLoadedMessage ) {return;}
          removeEventListener(worker, 'message', worker.loadHandler);

          Logger.log("worker sandbox initialized");
          resolve(sandbox);
        });
      };
      addEventListener(worker, 'message', worker.loadHandler);
    });
  },
Пример #3
0
  register: function (options) {
    assert(options.capabilities, "You are trying to register a package without any capabilities. Please provide a list of requested capabilities, or an empty array ([]).");

    this.packages[options.url] = options;
  },
Пример #4
0
  initializeSandbox: function(sandbox) {
    var options = sandbox.options,
        iframe = document.createElement('iframe'),
        oasisURL = this.oasisURL(sandbox),
        sandboxAttributes = ['allow-scripts'];

    if( sandbox.oasis.configuration.allowSameOrigin ) {
      sandboxAttributes.push('allow-same-origin');
    }

    iframe.name = sandbox.options.url + '?uuid=' + UUID.generate();
    iframe.sandbox = sandboxAttributes.join(' ');
    iframe.seamless = true;

    // rendering-specific code
    if (options.width) {
      iframe.width = options.width;
    } else if (options.height) {
      iframe.height = options.height;
    }

    // Error handling inside the iFrame
    iframe.errorHandler = function(event) {
      if(!event.data.sandboxException) {return;}
      try {
        // verify this message came from the expected sandbox; try/catch
        // because ie8 will disallow reading contentWindow in the case of
        // another sandbox's message
        if( event.source !== iframe.contentWindow ) {return;}
      } catch(e) {
        return;
      }

      sandbox.onerror( event.data.sandboxException );
    };
    addEventListener(window, 'message', iframe.errorHandler);

    switch (sandbox.type) {
      case 'js':
        verifySandbox( sandbox.oasis, oasisURL );
        this._setupIFrameBootstrap(iframe, sandbox, oasisURL);
        break;
      case 'html':
        verifySandbox( sandbox.oasis, sandbox.options.url );
        iframe.src = sandbox.options.url;
        break;
      default:
        assert(false, "IFrame Adapter only supports sandbox types `js` and `html`, not `" + sandbox.type + "`");
    }

    Logger.log('Initializing sandbox ' + iframe.name);

    // Promise that sandbox is loaded and capabilities are connected
    sandbox._waitForLoadDeferred().resolve(new RSVP.Promise( function(resolve, reject) {
      iframe.initializationHandler = function (event) {
        if( event.data !== sandbox.adapter.sandboxInitializedMessage ) {return;}
        try {
          // verify this message came from the expected sandbox; try/catch
          // because ie8 will disallow reading contentWindow in the case of
          // another sandbox's message
          if( event.source !== iframe.contentWindow ) {return;}
        } catch(e) {
          return;
        }
        removeEventListener(window, 'message', iframe.initializationHandler);

        sandbox.oasis.configuration.eventCallback(function () {
          Logger.log("container: iframe sandbox has initialized (capabilities connected)");
          resolve(sandbox);
        });
      };
      addEventListener(window, 'message', iframe.initializationHandler);
    }));

    sandbox.el = iframe;

    // Promise that sandbox is loaded; capabilities not connected
    return new RSVP.Promise(function (resolve, reject) {
      iframe.oasisLoadHandler = function (event) {
        if( event.data !== sandbox.adapter.oasisLoadedMessage ) {return;}
        try {
          // verify this message came from the expected sandbox; try/catch
          // because ie8 will disallow reading contentWindow in the case of
          // another sandbox's message
          if( event.source !== iframe.contentWindow ) {return;}
        } catch(e) {
          return;
        }
        removeEventListener(window, 'message', iframe.oasisLoadHandler);

        sandbox.oasis.configuration.eventCallback(function () {
          Logger.log("container: iframe sandbox has loaded Oasis");
          resolve(sandbox);
        });
      };
      addEventListener(window, 'message', iframe.oasisLoadHandler);
    });
  },