Exemple #1
0
resourceLoader.load = function(element, href, callback) {
  const document      = element.ownerDocument;
  const window        = document.defaultView;
  const tagName       = element.tagName.toLowerCase();
  const loadResource  = document.implementation._hasFeature('FetchExternalResources', tagName);
  const url           = resourceLoader.resolveResourceUrl(document, href);

  if (loadResource) {
    // This guarantees that all scripts are executed in order, must add to the
    // JSDOM queue before we add to the Zombie event queue.
    const enqueued = this.enqueue(element, url, callback && callback.bind(element));
    const request = new Fetch.Request(url);
    window._eventQueue.http(request, (error, response)=> {
      // Since this is used by resourceLoader that doesn't check the response,
      // we're responsible to turn anything other than 2xx/3xx into an error
      if (error)
        enqueued(new Error('Network error'));
      else if (response.status >= 400)
        enqueued(new Error(`Server returned status code ${response.status} from ${url}`));
      else
        response._consume().then((buffer)=> {
          response.body = buffer;
          enqueued(null, buffer);
        });
    });
  }
};
Exemple #2
0
DOM.HTMLImageElement.prototype._attrModified = function(name, value, oldVal) {
  if (name === 'src' && value && value !== oldVal) {
    const src = resourceLoader.resolveResourceUrl(this._ownerDocument, value);
    if (this.src !== src)
      resourceLoader.load(this, value);
  }
};
Exemple #3
0
    value: function replace(url) {
      var _this2 = this;

      url = URL.format(url);
      var name = '';

      if (this.current) {
        url = resourceLoader.resolveResourceUrl(this.current.window.document, url);
        name = this.current.window.name;
      }

      if (hashChange(this.current, url)) {
        (function () {
          var window = _this2.current.window;

          _this2.replaceEntry(window, url); // Reuse window with new URL
          var event = window.document.createEvent('HTMLEvents');
          event.initEvent('hashchange', true, false);
          window._eventQueue.enqueue(function () {
            window.dispatchEvent(event);
          });
        })();
      } else {
        var args = {
          browser: this.browser,
          history: this,
          name: name,
          url: url,
          parent: parentFrom(this.current.window)
        };
        var _document2 = loadDocument(args);
        this.replaceEntry(_document2.defaultView, url);
      }
    }
Exemple #4
0
 window.WebSocket = function(url, protocol) {
   url = resourceLoader.resolveResourceUrl(document, url);
   const origin = `${window.location.protocol}//${window.location.host}`;
   const ws = new WebSocket(url, { origin, protocol });
   window._allWebSockets.push(ws);
   return ws;
 };
Exemple #5
0
  // This method is available from Location, used to navigate to a new page.
  replace(url) {
    url = URL.format(url);
    let name = '';

    if (this.current) {
      url = resourceLoader.resolveResourceUrl(this.current.window.document, url);
      name = this.current.window.name;
    }

    if (hashChange(this.current, url)) {
      const { window } = this.current;
      this.replaceEntry(window, url); // Reuse window with new URL
      const event = window.document.createEvent('HTMLEvents');
      event.initEvent('hashchange', true, false);
      window._eventQueue.enqueue(function() {
        window.dispatchEvent(event);
      });
    } else {
      const args = {
        browser:  this.browser,
        history:  this,
        name:     name,
        url:      url,
        parent:   parentFrom(this.current.window)
      };
      const document = loadDocument(args);
      this.replaceEntry(document.defaultView, url);
    }
  }
Exemple #6
0
  window.WebSocket = function (url, protocol) {
    url = resourceLoader.resolveResourceUrl(document, url);
    var origin = window.location.protocol + '//' + window.location.host;
    var ws = new WebSocket(url, { origin: origin, protocol: protocol });

    // The < 1.x implementations of ws used to allows 'buffer' to be defined
    // as the binary type in node environments. Now, the supported type is
    // 'nodebuffer'. Version of engine.io-client <= 1.6.12 use the 'buffer'
    // type and this is a shim to allow that to keep working unti that version
    // of engine.io-client does not need to be supported anymore
    var origProperty = _Object$getOwnPropertyDescriptor(WebSocket.prototype, 'binaryType');
    Object.defineProperty(ws, 'binaryType', {
      get: function get() {
        return origProperty.get.call(this);
      },
      set: function set(type) {
        if (type === 'buffer') {
          type = 'nodebuffer';
        }
        return origProperty.set.call(this, type);
      }
    });
    window._allWebSockets.push(ws);
    return ws;
  };
Exemple #7
0
    value: function replaceState(state, title) {
      var url = arguments.length <= 2 || arguments[2] === undefined ? this.url : arguments[2];

      url = resourceLoader.resolveResourceUrl(this.current.window.document, url);
      // TODO: check same origin
      this.replaceEntry(this.current.window, url, state || {});
      this.updateLocation(this.current.window, url);
    }
 window._submit = function (formArgs) {
   var url = resourceLoader.resolveResourceUrl(document, formArgs.url);
   var target = formArgs.target || '_self';
   browser.emit('submit', url, target);
   // Figure out which history is going to handle this
   var targetWindow = target === '_self' ? window : target === '_parent' ? window.parent : target === '_top' ? window.top : browser.tabs.open({ name: target });
   var modified = _core.Object.assign({}, formArgs, { url: url, target: target });
   targetWindow._history.submit(modified);
 };
Exemple #9
0
    value: function assign(url) {
      var _this = this;

      var name = '';
      var parent = null;

      if (this.current) {
        url = resourceLoader.resolveResourceUrl(this.current.window.document, url);
        name = this.current.window.name;
        parent = parentFrom(this.current.window);
      }
      if (this.current && this.current.url === url) {
        this.replace(url);
        return;
      }

      if (hashChange(this.current, url)) {
        (function () {
          var window = _this.current.window;

          _this.updateLocation(window, url);
          _this.addEntry(window, url); // Reuse window with new URL
          var event = window.document.createEvent('HTMLEvents');
          event.initEvent('hashchange', true, false);
          window._eventQueue.enqueue(function () {
            window.dispatchEvent(event);
          });
        })();
      } else {
        var args = {
          browser: this.browser,
          history: this,
          name: name,
          url: url,
          parent: parent,
          referrer: this.current && this.current.window.document.referrer
        };
        var _document = loadDocument(args);
        this.addEntry(_document.defaultView, url);
      }
    }
DOM.HTMLFrameElement.prototype.__defineGetter__('contentWindow', function () {
  var _this = this;

  if (!this._contentWindow) {
    var createHistory = require('../history');
    var parentDocument = this._ownerDocument;
    var parentWindow = parentDocument.defaultView;

    // Need to bypass JSDOM's window/document creation and use ours
    var openWindow = createHistory(parentWindow.browser, function (active) {
      // Change the focus from window to active.
      _this._contentWindow = active;
    });

    var src = this.src.trim() === '' ? 'about:blank' : this.src;
    this._contentWindow = openWindow({
      name: this.name,
      url: resourceLoader.resolveResourceUrl(parentDocument, src),
      parent: parentWindow,
      referrer: parentWindow.location.href
    });
  }
  return this._contentWindow;
});
Exemple #11
0
 value: function normalizeURL(browser, request) {
   if (browser.document)
     // Resolve URL relative to document URL/base, or for new browser, using
     // Browser.site
     request.url = resourceLoader.resolveResourceUrl(browser.document, request.url);else request.url = Utils.resolveHref(browser.site || 'http://localhost', request.url);
 }
Exemple #12
0
 window.open = function(url, name) {
   url = url && resourceLoader.resolveResourceUrl(document, url);
   return browser.tabs.open({ name: name, url: url, opener: window });
 };
Exemple #13
0
 window.EventSource = function(url) {
   url = resourceLoader.resolveResourceUrl(document, url);
   const eventSource = new EventSource(url);
   eventQueue.addEventSource(eventSource);
   return eventSource;
 };
Exemple #14
0
 // This method is available from Location.
 replaceState(state, title, url = this.url) {
   url = resourceLoader.resolveResourceUrl(this.current.window.document, url);
   // TODO: check same origin
   this.replaceEntry(this.current.window, url, state || {});
   this.updateLocation(this.current.window, url);
 }
 window.WebSocket = function (url, protocol) {
   url = resourceLoader.resolveResourceUrl(document, url);
   var origin = '' + window.location.protocol + '//' + window.location.host;
   return new WebSocket(url, { origin: origin, protocol: protocol });
 };