1515#include " mozilla/dom/PContent.h"
1616#include " mozilla/dom/WindowGlobalChild.h"
1717
18- #include " mozilla/extensions/MatchPattern.h"
1918#include " nsContentUtils.h"
2019#include " JSActorProtocolUtils.h"
2120
@@ -29,7 +28,7 @@ NS_INTERFACE_MAP_BEGIN_CYCLE_COLLECTION(JSWindowActorProtocol)
2928 NS_INTERFACE_MAP_ENTRY (nsIDOMEventListener)
3029NS_INTERFACE_MAP_END
3130
32- NS_IMPL_CYCLE_COLLECTION (JSWindowActorProtocol)
31+ NS_IMPL_CYCLE_COLLECTION (JSWindowActorProtocol, mURIMatcher )
3332
3433/* static */ already_AddRefed<JSWindowActorProtocol>
3534JSWindowActorProtocol::FromIPC (const JSWindowActorInfo& aInfo) {
@@ -294,18 +293,30 @@ void JSWindowActorProtocol::RemoveObservers() {
294293 }
295294}
296295
297- extensions::MatchPatternSetCore * JSWindowActorProtocol::GetURIMatcher () {
296+ extensions::MatchPatternSet * JSWindowActorProtocol::GetURIMatcher () {
298297 // If we've already created the pattern set, return it.
299298 if (mURIMatcher || mMatches .IsEmpty ()) {
300299 return mURIMatcher ;
301300 }
302301
303- nsTArray<RefPtr<extensions::MatchPatternCore>> patterns (mMatches .Length ());
304- for (const nsString& pattern : mMatches ) {
305- patterns.AppendElement (new extensions::MatchPatternCore (
306- pattern, false , false , IgnoreErrors ()));
302+ // Constructing the MatchPatternSet requires a JS environment to be run in.
303+ // We can construct it here in the JSM scope, as we will be keeping it around.
304+ AutoJSAPI jsapi;
305+ MOZ_ALWAYS_TRUE (jsapi.Init (xpc::PrivilegedJunkScope ()));
306+ GlobalObject global (jsapi.cx (), xpc::PrivilegedJunkScope ());
307+
308+ nsTArray<OwningStringOrMatchPattern> patterns;
309+ patterns.SetCapacity (mMatches .Length ());
310+ for (nsString& s : mMatches ) {
311+ auto entry = patterns.AppendElement ();
312+ entry->SetAsString () = s;
307313 }
308- mURIMatcher = new extensions::MatchPatternSetCore (std::move (patterns));
314+
315+ MatchPatternOptions matchPatternOptions;
316+ // Make MatchPattern's mSchemes create properly.
317+ matchPatternOptions.mRestrictSchemes = false ;
318+ mURIMatcher = extensions::MatchPatternSet::Constructor (
319+ global, patterns, matchPatternOptions, IgnoreErrors ());
309320 return mURIMatcher ;
310321}
311322
@@ -365,7 +376,7 @@ bool JSWindowActorProtocol::Matches(BrowsingContext* aBrowsingContext,
365376 return false ;
366377 }
367378
368- if (extensions::MatchPatternSetCore * uriMatcher = GetURIMatcher ()) {
379+ if (extensions::MatchPatternSet * uriMatcher = GetURIMatcher ()) {
369380 if (!uriMatcher->Matches (aURI)) {
370381 aRv.ThrowNotSupportedError (nsPrintfCString (
371382 " Window protocol '%s' doesn't match uri %s" , mName .get (),
0 commit comments