Commit 506db0ec authored by Kris Maglione's avatar Kris Maglione
Browse files

Bug 1348442: Part 2c - Refactor Script class into ES6 class. r=aswan

MozReview-Commit-ID: Dtci1mfQts0

--HG--
extra : rebase_source : f9f0907b1562c955f13c1a4cea470cf2a6c79155
parent 0b494d5b
Loading
Loading
Loading
Loading
+39 −39
Original line number Diff line number Diff line
@@ -177,7 +177,8 @@ class CSSCache extends CacheMap {
}

// Represents a content script.
function Script(extension, options, deferred = PromiseUtils.defer()) {
class Script {
  constructor(extension, options, deferred = PromiseUtils.defer()) {
    this.extension = extension;
    this.options = options;
    this.run_at = this.options.run_at;
@@ -210,14 +211,13 @@ function Script(extension, options, deferred = PromiseUtils.defer()) {
    this.requiresCleanup = !this.remove_css && (this.css.length > 0 || options.cssCode);
  }

Script.prototype = {
  compileScripts() {
    return this.js.map(url => this.scriptCache.get(url));
  },
  }

  loadCSS() {
    return this.cssURLs.map(url => this.cssCache.get(url));
  },
  }

  matchesLoadInfo(uri, loadInfo) {
    if (!this.matchesURI(uri)) {
@@ -229,7 +229,7 @@ Script.prototype = {
    }

    return true;
  },
  }

  matchesURI(uri) {
    if (!(this.matches_.matches(uri) || this.matches_host_.matchesIgnoringPath(uri))) {
@@ -251,7 +251,7 @@ Script.prototype = {
    }

    return true;
  },
  }

  matches(window) {
    let uri = window.document.documentURIObject;
@@ -298,7 +298,7 @@ Script.prototype = {
    }

    return true;
  },
  }

  cleanup(window) {
    if (!this.remove_css) {
@@ -309,7 +309,7 @@ Script.prototype = {
        runSafeSyncWithoutClone(winUtils.removeSheetUsingURIString, url, type);
      }
    }
  },
  }

  /**
   * Tries to inject this script into the given window and sandbox, if
@@ -391,8 +391,8 @@ Script.prototype = {
        return result;
      }));
    }
  },
};
  }
}

defineLazyGetter(Script.prototype, "cssURLs", function() {
  // We can handle CSS urls (css) and CSS code (cssCode).