(["resource", "chrome"].includes(uri.scheme)) { port = undefined; } else { port = Services.io.getDefaultPort(uri.scheme); } } // Return false if none of the ports (or port ranges) is verified const portMatch = filter.ports.some(filterPort => { if (Array.isArray(filterPort)) { let [lower, upper] = filterPort; return port >= lower && port <= upper; } return port === filterPort; }); if (!portMatch) { return false; } } // Filters on host, url, path, query: // hostContains, hostEquals, hostSuffix, hostPrefix, // urlContains, urlEquals, ... for (let urlComponent of ["host", "path", "query", "url"]) { if (!this.testMatchOnURLComponent({ urlComponent, data, filter })) { return false; } } // urlMatches is a regular expression string and it is tested for matches // on the "url without the ref". if (filter.urlMatches) { let urlWithoutRef = uri.specIgnoringRef; if (!urlWithoutRef.match(filter.urlMatches)) { return false; } } // originAndPathMatches is a regular expression string and it is tested for matches // on the "url without the query and the ref". if (filter.originAndPathMatches) { let urlWithoutQueryAndRef = uri.resolve(uriURL.filePath); // The above 'uri.resolve(...)' will be null for some URI schemes // (e.g. about). // TODO: handle schemes which will not be able to resolve the filePath // (e.g. for "about:blank", 'urlWithoutQueryAndRef' should be "about:blank" instead // of null) if ( !urlWithoutQueryAndRef || !urlWithoutQueryAndRef.match(filter.originAndPathMatches) ) { return false; } } return true; } testMatchOnURLComponent({ urlComponent: key, data, filter }) { // Test for equals. // NOTE: an empty string should not be considered a filter to skip. if (filter[`${key}Equals`] != null) { if (data[key] !== filter[`${key}Equals`]) { return false; } } // Test for contains. if (filter[`${key}Contains`]) { let value = (key == "host" ? "." : "") + data[key]; if (!data[key] || !value.includes(filter[`${key}Contains`])) { return false; } } // Test for prefix. if (filter[`${key}Prefix`]) { if (!data[key] || !data[key].startsWith(filter[`${key}Prefix`])) { return false; } } // Test for suffix. if (filter[`${key}Suffix`]) { if (!data[key] || !data[key].endsWith(filter[`${key}Suffix`])) { return false; } } return true; } serialize() { return this.filters; } } PK