Bug 1368102: Part 3 - Use MatchPattern and MatchGlob bindings for content script matching. r=mixedpuppy
authorKris Maglione <maglione.k@gmail.com>
Thu, 25 May 2017 15:42:18 -0700
changeset 410375 b9439245aa6bc591c4e138ea2f6978d7e3bab831
parent 410374 056e3d934eb26523b35fcdd4b1cdadca2c8bb190
child 410376 417fd0cf65a8bddc78c59156cb317cc4156f9392
push id7391
push usermtabara@mozilla.com
push dateMon, 12 Jun 2017 13:08:53 +0000
treeherdermozilla-beta@2191d7f87e2e [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersmixedpuppy
bugs1368102
milestone55.0a1
first release with
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
last release without
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
Bug 1368102: Part 3 - Use MatchPattern and MatchGlob bindings for content script matching. r=mixedpuppy MozReview-Commit-ID: AvNCU77I2Je
toolkit/components/extensions/ExtensionTabs.jsm
toolkit/components/extensions/extension-process-script.js
--- a/toolkit/components/extensions/ExtensionTabs.jsm
+++ b/toolkit/components/extensions/ExtensionTabs.jsm
@@ -543,19 +543,19 @@ class TabBase {
 
     if (details.frameId !== null && details.allFrames) {
       return Promise.reject({message: `'frameId' and 'allFrames' are mutually exclusive`});
     }
 
     if (this.hasActiveTabPermission) {
       // If we have the "activeTab" permission for this tab, ignore
       // the host whitelist.
-      options.matchesHost = ["<all_urls>"];
+      options.matches = ["<all_urls>"];
     } else {
-      options.matchesHost = this.extension.whiteListedHosts.patterns.map(host => host.pattern);
+      options.matches = this.extension.whiteListedHosts.patterns.map(host => host.pattern);
     }
 
     if (details.code !== null) {
       options[`${kind}Code`] = details.code;
     }
     if (details.file !== null) {
       let url = context.uri.resolve(details.file);
       if (!this.extension.isExtensionURL(url)) {
--- a/toolkit/components/extensions/extension-process-script.js
+++ b/toolkit/components/extensions/extension-process-script.js
@@ -12,20 +12,16 @@
 
 const {classes: Cc, interfaces: Ci, utils: Cu, results: Cr} = Components;
 
 Cu.import("resource://gre/modules/Services.jsm");
 Cu.import("resource://gre/modules/XPCOMUtils.jsm");
 
 XPCOMUtils.defineLazyModuleGetter(this, "ExtensionManagement",
                                   "resource://gre/modules/ExtensionManagement.jsm");
-XPCOMUtils.defineLazyModuleGetter(this, "MatchGlobs",
-                                  "resource://gre/modules/MatchPattern.jsm");
-XPCOMUtils.defineLazyModuleGetter(this, "MatchPattern",
-                                  "resource://gre/modules/MatchPattern.jsm");
 XPCOMUtils.defineLazyModuleGetter(this, "MessageChannel",
                                   "resource://gre/modules/MessageChannel.jsm");
 XPCOMUtils.defineLazyModuleGetter(this, "WebNavigationFrames",
                                   "resource://gre/modules/WebNavigationFrames.jsm");
 
 XPCOMUtils.defineLazyModuleGetter(this, "ExtensionChild",
                                   "resource://gre/modules/ExtensionChild.jsm");
 XPCOMUtils.defineLazyModuleGetter(this, "ExtensionContent",
@@ -51,23 +47,20 @@ class ScriptMatcher {
 
     this._script = null;
 
     this.allFrames = options.all_frames;
     this.matchAboutBlank = options.match_about_blank;
     this.frameId = options.frame_id;
     this.runAt = options.run_at;
 
-    this.matches = new MatchPattern(options.matches);
-    this.excludeMatches = new MatchPattern(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.matchesHost = new MatchPattern(options.matchesHost || null);
-    this.includeGlobs = options.include_globs && new MatchGlobs(options.include_globs);
-    this.excludeGlobs = new MatchGlobs(options.exclude_globs);
+    this.matches = new MatchPatternSet(options.matches);
+    this.excludeMatches = new MatchPatternSet(options.exclude_matches || []);
+    this.includeGlobs = options.include_globs && options.include_globs.map(glob => new MatchGlob(glob));
+    this.excludeGlobs = options.include_globs && options.exclude_globs.map(glob => new MatchGlob(glob));
   }
 
   toString() {
     return `[Script {js: [${this.options.js}], matchAboutBlank: ${this.matchAboutBlank}, runAt: ${this.runAt}, matches: ${this.options.matches}}]`;
   }
 
   get script() {
     if (!this._script) {
@@ -92,29 +85,29 @@ class ScriptMatcher {
     if (!this.allFrames && !loadInfo.isTopLevelLoad) {
       return false;
     }
 
     return true;
   }
 
   matchesURI(uri) {
-    if (!(this.matches.matches(uri) || this.matchesHost.matchesIgnoringPath(uri))) {
+    if (!(this.matches.matches(uri))) {
       return false;
     }
 
     if (this.excludeMatches.matches(uri)) {
       return false;
     }
 
-    if (this.includeGlobs != null && !this.includeGlobs.matches(uri.spec)) {
+    if (this.includeGlobs && !this.includeGlobs.some(glob => glob.matches(uri.spec))) {
       return false;
     }
 
-    if (this.excludeGlobs.matches(uri.spec)) {
+    if (this.excludeGlobs && this.excludeGlobs.some(glob => glob.matches(uri.spec))) {
       return false;
     }
 
     return true;
   }
 
   matchesWindow(window) {
     if (!this.allFrames && this.frameId == null && window.parent !== window) {