Esempio n. 1
0
  connectSandbox: function (receiver, oasis) {
    var adapter = this;

    Logger.log("Sandbox listening for initialization message");

    function initializeOasisSandbox(event) {
      if (!event.data.isOasisInitialization) { return; }

      removeEventListener(receiver, 'message', initializeOasisSandbox);

      oasis.configuration.eventCallback(function () {
        Logger.log("Sandbox received initialization message.");

        oasis.configuration.oasisURL = event.data.oasisURL;

        adapter.loadScripts(event.data.base, event.data.scriptURLs);

        oasis.connectCapabilities(event.data.capabilities, event.ports);

        adapter.didConnect();
      });
    }
    addEventListener(receiver, 'message', initializeOasisSandbox);

    adapter.oasisLoaded();
  },
Esempio n. 2
0
        sandbox.oasis.configuration.eventCallback(function () {
          if( event.data !== sandbox.adapter.oasisLoadedMessage ) {return;}
          removeEventListener(worker, 'message', worker.loadHandler);

          Logger.log("worker sandbox initialized");
          resolve(sandbox);
        });
Esempio n. 3
0
  terminateSandbox: function(sandbox) {
    var el = sandbox.el;

    if (el.parentNode) {
      Logger.log("Terminating sandbox ", sandbox.el.name);
      el.parentNode.removeChild(el);
    }

    sandbox.el = null;
  },
Esempio n. 4
0
      oasis.configuration.eventCallback(function () {
        Logger.log("Sandbox received initialization message.");

        oasis.configuration.oasisURL = event.data.oasisURL;

        adapter.loadScripts(event.data.base, event.data.scriptURLs);

        oasis.connectCapabilities(event.data.capabilities, event.ports);

        adapter.didConnect();
      });
Esempio n. 5
0
  connectSandbox: function (receiver, oasis) {
    var adapter = this;

    Logger.log("Sandbox listening for initialization message");

    function initializeOasisSandbox(event) {
      if (!event.data.isOasisInitialization) { return; }

      removeEventListener(receiver, 'message', initializeOasisSandbox);
      adapter.initializeOasisSandbox(event, oasis);
    }
    addEventListener(receiver, 'message', initializeOasisSandbox);

    adapter.oasisLoaded(oasis);
  },
Esempio n. 6
0
  terminateSandbox: function(sandbox) {
    var el = sandbox.el;

    sandbox.terminated = true;

    if (el.loadHandler) {
      // no load handler for HTML sandboxes
      removeEventListener(el, 'load', el.loadHandler);
    }
    removeEventListener(window, 'message', el.initializationHandler);
    removeEventListener(window, 'message', el.oasisLoadHandler);

    if (el.parentNode) {
      Logger.log("Terminating sandbox ", sandbox.el.name);
      el.parentNode.removeChild(el);
    }

    sandbox.el = null;
  },
Esempio n. 7
0
    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;
      }

      Logger.log("container: iframe sandbox has loaded Oasis");


      if (verifyCurrentSandboxOrigin(sandbox, event)) {
        sandbox.createAndTransferCapabilities();
      }

      if (sandbox.options.reconnect === "none") {
        removeEventListener(window, 'message', iframe.oasisLoadHandler);
      }
    };
Esempio n. 8
0
  initializeSandbox: function(sandbox) {
    var options = sandbox.options,
        iframe = document.createElement('iframe');

    if(sandbox.oasis.configuration.sandboxed !== false) {
      var sandboxAttributes = ['allow-scripts'];

      if( sandbox.oasis.configuration.allowSameOrigin ) {
        sandboxAttributes.push('allow-same-origin');
      }
      if( options && options.sandbox && options.sandbox.popups ) {
        sandboxAttributes.push('allow-popups');
      }
      iframe.sandbox = sandboxAttributes.join(' ');
    }
    iframe.name = sandbox.options.url + '?uuid=' + UUID.generate();
    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);

    verifySandbox( sandbox.oasis, sandbox.options.url );
    iframe.src = sandbox.options.url;

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

    // Promise that sandbox has loaded and capabilities connected at least once.
    // This does not mean that the sandbox will be loaded & connected in the
    // face of reconnects (eg pages that navigate)
    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;

    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;
      }

      Logger.log("container: iframe sandbox has loaded Oasis");


      if (verifyCurrentSandboxOrigin(sandbox, event)) {
        sandbox.createAndTransferCapabilities();
      }

      if (sandbox.options.reconnect === "none") {
        removeEventListener(window, 'message', iframe.oasisLoadHandler);
      }
    };
    addEventListener(window, 'message', iframe.oasisLoadHandler);
  },
Esempio n. 9
0
 sandbox.oasis.configuration.eventCallback(function () {
   Logger.log("container: iframe sandbox has initialized (capabilities connected)");
   resolve(sandbox);
 });
Esempio n. 10
0
 function applySandboxJS(sandboxFn) {
   Logger.log("sandbox: inline sandbox initialized");
   sandboxFn(oasis);
   return oasis.sandbox;
 }
Esempio n. 11
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);
    });
  },
Esempio n. 12
0
 sandbox.oasis.configuration.eventCallback(function () {
   Logger.log("iframe loading oasis");
   iframe.contentWindow.location.href = oasisURL;
 });
Esempio n. 13
0
 sandbox.oasis.configuration.eventCallback(function () {
   Logger.log("container: iframe sandbox has loaded Oasis");
   resolve(sandbox);
 });