Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
The table of contents is too big for display.
Diff view
Diff view
  •  
  •  
  •  
37 changes: 37 additions & 0 deletions dom/bindings/Bindings.conf
Original file line number Diff line number Diff line change
Expand Up @@ -568,6 +568,12 @@ DOMInterfaces = {
'notflattened': True
},

'Cookie': {
'nativeType': 'nsICookie2',
'headerFile': 'nsICookie2.h',
'notflattened': True,
},

'IntersectionObserver': {
'nativeType': 'mozilla::dom::DOMIntersectionObserver',
},
Expand Down Expand Up @@ -595,6 +601,21 @@ DOMInterfaces = {
'nativeType': 'mozilla::DOMLocalMediaStream'
},

'MatchGlob': {
'nativeType': 'mozilla::extensions::MatchGlob',
'headerFile': 'mozilla/extensions/MatchGlob.h',
},

'MatchPattern': {
'nativeType': 'mozilla::extensions::MatchPattern',
'headerFile': 'mozilla/extensions/MatchPattern.h',
},

'MatchPatternSet': {
'nativeType': 'mozilla::extensions::MatchPatternSet',
'headerFile': 'mozilla/extensions/MatchPattern.h',
},

'MediaList': {
'nativeType': 'nsMediaList',
'headerFile': 'nsIMediaList.h',
Expand Down Expand Up @@ -644,6 +665,12 @@ DOMInterfaces = {
'notflattened': True
},

'LoadInfo': {
'nativeType': 'nsILoadInfo',
'headerFile': 'nsILoadInfo.h',
'notflattened': True,
},

'MozSpeakerManager': {
'nativeType': 'mozilla::dom::SpeakerManager',
'headerFile': 'SpeakerManager.h'
Expand Down Expand Up @@ -1390,6 +1417,16 @@ DOMInterfaces = {
'concrete': False,
},

'WebExtensionContentScript': {
'nativeType': 'mozilla::extensions::WebExtensionContentScript',
'headerFile': 'mozilla/extensions/WebExtensionContentScript.h',
},

'WebExtensionPolicy': {
'nativeType': 'mozilla::extensions::WebExtensionPolicy',
'headerFile': 'mozilla/extensions/WebExtensionPolicy.h',
},

'Window': {
'nativeType': 'nsGlobalWindow',
'binaryNames': {
Expand Down
24 changes: 24 additions & 0 deletions dom/webidl/MatchGlob.webidl
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
/* This Source Code Form is subject to the terms of the Mozilla Public
* License, v. 2.0. If a copy of the MPL was not distributed with this
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */

/**
* Represents a simple glob pattern matcher. Any occurrence of "*" in the glob
* pattern matches any literal string of characters in the string being
* compared. Additionally, if created with `allowQuestion = true`, any
* occurrence of "?" in the glob matches any single literal character.
*/
[Constructor(DOMString glob, optional boolean allowQuestion = true),
ChromeOnly, Exposed=(Window,System)]
interface MatchGlob {
/**
* Returns true if the string matches the glob.
*/
boolean matches(DOMString string);

/**
* The glob string this MatchGlob represents.
*/
[Constant]
readonly attribute DOMString glob;
};
121 changes: 121 additions & 0 deletions dom/webidl/MatchPattern.webidl
Original file line number Diff line number Diff line change
@@ -0,0 +1,121 @@
/* This Source Code Form is subject to the terms of the Mozilla Public
* License, v. 2.0. If a copy of the MPL was not distributed with this
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */

interface Cookie;
interface URI;

/**
* A URL match pattern as used by the WebExtension and Chrome extension APIs.
*
* A match pattern is a string with one of the following formats:
*
* - "<all_urls>"
* The literal string "<all_urls>" matches any URL with a supported
* protocol.
*
* - <proto>://<host>/<path>
* A URL pattern with the following placeholders:
*
* - <proto>
* The protocol to match, or "*" to match either "http" or "https".
* - <host>
* The hostname to match. May be either a complete, literal hostname to
* match a specific host, the wildcard character "*", to match any host,
* or a subdomain pattern, with "*." followed by a domain name, to match
* that domain name or any subdomain thereof.
* - <path>
* A glob pattern for paths to match. A "*" may appear anywhere within
* the path, and will match any string of characters. If no "*" appears,
* the URL path must exactly match the pattern path.
*/
[Constructor(DOMString pattern, optional MatchPatternOptions options),
ChromeOnly, Exposed=(Window,System)]
interface MatchPattern {
/**
* Returns true if the given URI matches the pattern.
*
* If explicit is true, only explicit domain matches, without wildcards, are
* considered.
*/
boolean matches(URI uri, optional boolean explicit = false);

/**
* Returns true if a URL exists which a) would be able to access the given
* cookie, and b) would be matched by this match pattern.
*/
boolean matchesCookie(Cookie cookie);

/**
* Returns true if this pattern will match any host which would be matched
* by the given pattern.
*/
boolean subsumes(MatchPattern pattern);

/**
* Returns true if there is any host which would be matched by both this
* pattern and the given pattern.
*/
boolean overlaps(MatchPattern pattern);

/**
* The match pattern string represented by this pattern.
*/
[Constant]
readonly attribute DOMString pattern;
};

/**
* A set of MatchPattern objects, which implements the MatchPattern API and
* matches when any of its sub-patterns matches.
*/
[Constructor(sequence<(DOMString or MatchPattern)> patterns,
optional MatchPatternOptions options),
ChromeOnly, Exposed=(Window,System)]
interface MatchPatternSet {
/**
* Returns true if the given URI matches any sub-pattern.
*
* If explicit is true, only explicit domain matches, without wildcards, are
* considered.
*/
boolean matches(URI uri, optional boolean explicit = false);

/**
* Returns true if any sub-pattern matches the given cookie.
*/
boolean matchesCookie(Cookie cookie);

/**
* Returns true if any sub-pattern subsumes the given pattern.
*/
boolean subsumes(MatchPattern pattern);

/**
* Returns true if any sub-pattern overlaps the given pattern.
*/
boolean overlaps(MatchPattern pattern);

/**
* Returns true if any sub-pattern overlaps any sub-pattern the given
* pattern set.
*/
boolean overlaps(MatchPatternSet patternSet);

/**
* Returns true if any sub-pattern overlaps *every* sub-pattern in the given
* pattern set.
*/
boolean overlapsAll(MatchPatternSet patternSet);

[Cached, Constant, Frozen]
readonly attribute sequence<MatchPattern> patterns;
};

dictionary MatchPatternOptions {
/**
* If true, the path portion of the pattern is ignored, and replaced with a
* wildcard. The `pattern` property is updated to reflect this.
*/
boolean ignorePath = false;
};
161 changes: 161 additions & 0 deletions dom/webidl/WebExtensionContentScript.webidl
Original file line number Diff line number Diff line change
@@ -0,0 +1,161 @@
/* This Source Code Form is subject to the terms of the Mozilla Public
* License, v. 2.0. If a copy of the MPL was not distributed with this
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */

interface LoadInfo;
interface URI;
interface WindowProxy;

/**
* Describes the earliest point in the load cycle at which a script should
* run.
*/
enum ContentScriptRunAt {
/**
* The point in the load cycle just after the document element has been
* inserted, before any page scripts have been allowed to run.
*/
"document_start",
/**
* The point after which the page DOM has fully loaded, but before all page
* resources have necessarily been loaded. Corresponds approximately to the
* DOMContentLoaded event.
*/
"document_end",
/**
* The first point after the page and all of its resources has fully loaded
* when the event loop is idle, and can run scripts without delaying a paint
* event.
*/
"document_idle",
};

[Constructor(WebExtensionPolicy extension, WebExtensionContentScriptInit options), ChromeOnly, Exposed=System]
interface WebExtensionContentScript {
/**
* Returns true if the script's match and exclude patterns match the given
* URI, without reference to attributes such as `allFrames`.
*/
boolean matchesURI(URI uri);

/**
* Returns true if the script matches the given URI and LoadInfo objects.
* This should be used to determine whether to begin pre-loading a content
* script based on network events.
*/
boolean matchesLoadInfo(URI uri, LoadInfo loadInfo);

/**
* Returns true if the script matches the given window. This should be used
* to determine whether to run a script in a window at load time.
*/
boolean matchesWindow(WindowProxy window);

/**
* The policy object for the extension that this script belongs to.
*/
[Constant]
readonly attribute WebExtensionPolicy extension;

/**
* If true, this script runs in all frames. If false, it only runs in
* top-level frames.
*/
[Constant]
readonly attribute boolean allFrames;

/**
* If true, this (misleadingly-named, but inherited from Chrome) attribute
* causes the script to run in frames with URLs which inherit a principal
* that matches one of the match patterns, such as about:blank or
* about:srcdoc. If false, the script only runs in frames with an explicit
* matching URL.
*/
[Constant]
readonly attribute boolean matchAboutBlank;

/**
* The earliest point in the load cycle at which this script should run. For
* static content scripts, in extensions which were present at browser
* startup, the browser makes every effort to make sure that the script runs
* no later than this point in the load cycle. For dynamic content scripts,
* and scripts from extensions installed during this session, the scripts
* may run at a later point.
*/
[Constant]
readonly attribute ContentScriptRunAt runAt;

/**
* The outer window ID of the frame in which to run the script, or 0 if it
* should run in the top-level frame. Should only be used for
* dynamically-injected scripts.
*/
[Constant]
readonly attribute unsigned long long? frameID;

/**
* The set of match patterns for URIs of pages in which this script should
* run. This attribute is mandatory, and is a prerequisite for all other
* match patterns.
*/
[Constant]
readonly attribute MatchPatternSet matches;

/**
* A set of match patterns for URLs in which this script should not run,
* even if they match other include patterns or globs.
*/
[Constant]
readonly attribute MatchPatternSet? excludeMatches;

/**
* A set of glob matchers for URLs in which this script should run. If this
* list is present, the script will only run in URLs which match the
* `matches` pattern as well as one of these globs.
*/
[Cached, Constant, Frozen]
readonly attribute sequence<MatchGlob>? includeGlobs;

/**
* A set of glob matchers for URLs in which this script should not run, even
* if they match other include patterns or globs.
*/
[Cached, Constant, Frozen]
readonly attribute sequence<MatchGlob>? excludeGlobs;

/**
* A set of paths, relative to the extension root, of CSS sheets to inject
* into matching pages.
*/
[Cached, Constant, Frozen]
readonly attribute sequence<DOMString> cssPaths;

/**
* A set of paths, relative to the extension root, of JavaScript scripts to
* execute in matching pages.
*/
[Cached, Constant, Frozen]
readonly attribute sequence<DOMString> jsPaths;
};

dictionary WebExtensionContentScriptInit {
boolean allFrames = false;

boolean matchAboutBlank = false;

ContentScriptRunAt runAt = "document_idle";

unsigned long long? frameID = null;

required MatchPatternSet matches;

MatchPatternSet? excludeMatches = null;

sequence<MatchGlob>? includeGlobs = null;

sequence<MatchGlob>? excludeGlobs = null;

sequence<DOMString> cssPaths = [];

sequence<DOMString> jsPaths = [];
};
Loading
Loading