Bug 1431371 Only grant activeTab to urls that match <all_urls> r=kmag
authorAndrew Swan <aswan@mozilla.com>
Fri, 26 Jan 2018 19:54:34 -0800
changeset 403829 7fe5144564bcd624e42128f6545a790650620d6d
parent 403828 d60680f8627c01e89e4a6356b0aee1cd1e733bce
child 403830 8bb8cd8cd6917b8bb806ad6a5b6665099766908c
push id33445
push userapavel@mozilla.com
push dateThu, 15 Feb 2018 10:27:00 +0000
treeherdermozilla-central@9b69cc60e584 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewerskmag
bugs1431371
milestone60.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 1431371 Only grant activeTab to urls that match <all_urls> r=kmag MozReview-Commit-ID: ApnAwGsIOaG
toolkit/components/extensions/MatchPattern.cpp
toolkit/components/extensions/MatchPattern.h
toolkit/components/extensions/WebExtensionPolicy.cpp
--- a/toolkit/components/extensions/MatchPattern.cpp
+++ b/toolkit/components/extensions/MatchPattern.cpp
@@ -481,16 +481,22 @@ MatchPattern::Overlaps(const MatchPatter
 
 
 JSObject*
 MatchPattern::WrapObject(JSContext* aCx, JS::HandleObject aGivenProto)
 {
   return MatchPatternBinding::Wrap(aCx, this, aGivenProto);
 }
 
+/* static */ bool
+MatchPattern::MatchesAllURLs(const URLInfo& aURL)
+{
+  RefPtr<AtomSet> permittedSchemes = AtomSet::Get<PERMITTED_SCHEMES>();
+  return permittedSchemes->Contains(aURL.Scheme());
+}
 
 NS_IMPL_CYCLE_COLLECTION_WRAPPERCACHE(MatchPattern, mPath, mParent)
 
 NS_INTERFACE_MAP_BEGIN_CYCLE_COLLECTION(MatchPattern)
   NS_WRAPPERCACHE_INTERFACE_MAP_ENTRY
   NS_INTERFACE_MAP_ENTRY(nsISupports)
 NS_INTERFACE_MAP_END
 
--- a/toolkit/components/extensions/MatchPattern.h
+++ b/toolkit/components/extensions/MatchPattern.h
@@ -278,16 +278,21 @@ private:
   // While "foo.com" gives mDomain = "foo.com" and mMatchSubdomain = false,
   // and matches "foo.com" but not "bar.foo.com".
   nsCString mDomain;
   bool mMatchSubdomain = false;
 
   // The glob against which the URL path must match. If null, the path is
   // ignored entirely. If non-null, the path must match this glob.
   RefPtr<MatchGlob> mPath;
+
+ public:
+  // A quick way to check if a particular URL matches <all_urls> without
+  // actually instantiating a MatchPattern
+  static bool MatchesAllURLs(const URLInfo& aURL);
 };
 
 
 class MatchPatternSet final : public nsISupports
                             , public nsWrapperCache
 {
   NS_DECL_CYCLE_COLLECTING_ISUPPORTS
   NS_DECL_CYCLE_COLLECTION_SCRIPT_HOLDER_CLASS(MatchPatternSet)
--- a/toolkit/components/extensions/WebExtensionPolicy.cpp
+++ b/toolkit/components/extensions/WebExtensionPolicy.cpp
@@ -398,21 +398,23 @@ WebExtensionContentScript::Matches(const
   }
 
   // Content scripts are not allowed on pages that have elevated
   // privileges via mozAddonManager (see bug 1280234)
   if (AddonManagerWebAPI::IsValidSite(aDoc.PrincipalURL().URI())) {
     return false;
   }
 
-  if (mHasActiveTabPermission && aDoc.ShouldMatchActiveTabPermission()) {
+  URLInfo urlinfo(aDoc.PrincipalURL());
+  if (mHasActiveTabPermission && aDoc.ShouldMatchActiveTabPermission() &&
+      MatchPattern::MatchesAllURLs(urlinfo)) {
     return true;
   }
 
-  return MatchesURI(aDoc.PrincipalURL());
+  return MatchesURI(urlinfo);
 }
 
 bool
 WebExtensionContentScript::MatchesURI(const URLInfo& aURL) const
 {
   if (!mMatches->Matches(aURL)) {
     return false;
   }