зеркало из https://github.com/mozilla/gecko-dev.git
Bug 1348442: Part 2c - Refactor Script class into ES6 class. r=aswan
MozReview-Commit-ID: Dtci1mfQts0 --HG-- extra : rebase_source : f9f0907b1562c955f13c1a4cea470cf2a6c79155
This commit is contained in:
Родитель
0b494d5ba4
Коммит
506db0ec9c
|
@ -177,47 +177,47 @@ class CSSCache extends CacheMap {
|
||||||
}
|
}
|
||||||
|
|
||||||
// Represents a content script.
|
// Represents a content script.
|
||||||
function Script(extension, options, deferred = PromiseUtils.defer()) {
|
class Script {
|
||||||
this.extension = extension;
|
constructor(extension, options, deferred = PromiseUtils.defer()) {
|
||||||
this.options = options;
|
this.extension = extension;
|
||||||
this.run_at = this.options.run_at;
|
this.options = options;
|
||||||
this.js = this.options.js || [];
|
this.run_at = this.options.run_at;
|
||||||
this.css = this.options.css || [];
|
this.js = this.options.js || [];
|
||||||
this.remove_css = this.options.remove_css;
|
this.css = this.options.css || [];
|
||||||
this.match_about_blank = this.options.match_about_blank;
|
this.remove_css = this.options.remove_css;
|
||||||
this.css_origin = this.options.css_origin;
|
this.match_about_blank = this.options.match_about_blank;
|
||||||
|
this.css_origin = this.options.css_origin;
|
||||||
|
|
||||||
this.deferred = deferred;
|
this.deferred = deferred;
|
||||||
|
|
||||||
this.cssCache = extension[this.css_origin === "user" ? "userCSS"
|
this.cssCache = extension[this.css_origin === "user" ? "userCSS"
|
||||||
: "authorCSS"];
|
: "authorCSS"];
|
||||||
this.scriptCache = extension[options.wantReturnValue ? "dynamicScripts"
|
this.scriptCache = extension[options.wantReturnValue ? "dynamicScripts"
|
||||||
: "staticScripts"];
|
: "staticScripts"];
|
||||||
|
|
||||||
if (options.wantReturnValue) {
|
if (options.wantReturnValue) {
|
||||||
this.compileScripts();
|
this.compileScripts();
|
||||||
this.loadCSS();
|
this.loadCSS();
|
||||||
|
}
|
||||||
|
|
||||||
|
this.matches_ = new MatchPattern(this.options.matches);
|
||||||
|
this.exclude_matches_ = new MatchPattern(this.options.exclude_matches || null);
|
||||||
|
// TODO: MatchPattern should pre-mangle host-only patterns so that we
|
||||||
|
// don't need to call a separate match function.
|
||||||
|
this.matches_host_ = new MatchPattern(this.options.matchesHost || null);
|
||||||
|
this.include_globs_ = new MatchGlobs(this.options.include_globs);
|
||||||
|
this.exclude_globs_ = new MatchGlobs(this.options.exclude_globs);
|
||||||
|
|
||||||
|
this.requiresCleanup = !this.remove_css && (this.css.length > 0 || options.cssCode);
|
||||||
}
|
}
|
||||||
|
|
||||||
this.matches_ = new MatchPattern(this.options.matches);
|
|
||||||
this.exclude_matches_ = new MatchPattern(this.options.exclude_matches || null);
|
|
||||||
// TODO: MatchPattern should pre-mangle host-only patterns so that we
|
|
||||||
// don't need to call a separate match function.
|
|
||||||
this.matches_host_ = new MatchPattern(this.options.matchesHost || null);
|
|
||||||
this.include_globs_ = new MatchGlobs(this.options.include_globs);
|
|
||||||
this.exclude_globs_ = new MatchGlobs(this.options.exclude_globs);
|
|
||||||
|
|
||||||
this.requiresCleanup = !this.remove_css && (this.css.length > 0 || options.cssCode);
|
|
||||||
}
|
|
||||||
|
|
||||||
Script.prototype = {
|
|
||||||
compileScripts() {
|
compileScripts() {
|
||||||
return this.js.map(url => this.scriptCache.get(url));
|
return this.js.map(url => this.scriptCache.get(url));
|
||||||
},
|
}
|
||||||
|
|
||||||
loadCSS() {
|
loadCSS() {
|
||||||
return this.cssURLs.map(url => this.cssCache.get(url));
|
return this.cssURLs.map(url => this.cssCache.get(url));
|
||||||
},
|
}
|
||||||
|
|
||||||
matchesLoadInfo(uri, loadInfo) {
|
matchesLoadInfo(uri, loadInfo) {
|
||||||
if (!this.matchesURI(uri)) {
|
if (!this.matchesURI(uri)) {
|
||||||
|
@ -229,7 +229,7 @@ Script.prototype = {
|
||||||
}
|
}
|
||||||
|
|
||||||
return true;
|
return true;
|
||||||
},
|
}
|
||||||
|
|
||||||
matchesURI(uri) {
|
matchesURI(uri) {
|
||||||
if (!(this.matches_.matches(uri) || this.matches_host_.matchesIgnoringPath(uri))) {
|
if (!(this.matches_.matches(uri) || this.matches_host_.matchesIgnoringPath(uri))) {
|
||||||
|
@ -251,7 +251,7 @@ Script.prototype = {
|
||||||
}
|
}
|
||||||
|
|
||||||
return true;
|
return true;
|
||||||
},
|
}
|
||||||
|
|
||||||
matches(window) {
|
matches(window) {
|
||||||
let uri = window.document.documentURIObject;
|
let uri = window.document.documentURIObject;
|
||||||
|
@ -298,7 +298,7 @@ Script.prototype = {
|
||||||
}
|
}
|
||||||
|
|
||||||
return true;
|
return true;
|
||||||
},
|
}
|
||||||
|
|
||||||
cleanup(window) {
|
cleanup(window) {
|
||||||
if (!this.remove_css) {
|
if (!this.remove_css) {
|
||||||
|
@ -309,7 +309,7 @@ Script.prototype = {
|
||||||
runSafeSyncWithoutClone(winUtils.removeSheetUsingURIString, url, type);
|
runSafeSyncWithoutClone(winUtils.removeSheetUsingURIString, url, type);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
},
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Tries to inject this script into the given window and sandbox, if
|
* Tries to inject this script into the given window and sandbox, if
|
||||||
|
@ -391,8 +391,8 @@ Script.prototype = {
|
||||||
return result;
|
return result;
|
||||||
}));
|
}));
|
||||||
}
|
}
|
||||||
},
|
}
|
||||||
};
|
}
|
||||||
|
|
||||||
defineLazyGetter(Script.prototype, "cssURLs", function() {
|
defineLazyGetter(Script.prototype, "cssURLs", function() {
|
||||||
// We can handle CSS urls (css) and CSS code (cssCode).
|
// We can handle CSS urls (css) and CSS code (cssCode).
|
||||||
|
|
Загрузка…
Ссылка в новой задаче