diff --git a/components/youtube_script_injector/browser/core/youtube_rule.cc b/components/youtube_script_injector/browser/core/youtube_rule.cc index 0a7de9d90fea..f2235c358622 100644 --- a/components/youtube_script_injector/browser/core/youtube_rule.cc +++ b/components/youtube_script_injector/browser/core/youtube_rule.cc @@ -22,24 +22,26 @@ namespace { // youtube.json keys -constexpr char kInclude[] = "include"; -constexpr char kExclude[] = "exclude"; +// constexpr char kInclude[] = "include"; +// constexpr char kExclude[] = "exclude"; constexpr char kVersion[] = "version"; constexpr char kPolicyScript[] = "policy_script"; -bool GetURLPatternSetFromValue(const base::Value* value, - extensions::URLPatternSet* result) { - if (!value->is_list()) { - return false; - } - std::string error; - bool valid = result->Populate(value->GetList(), URLPattern::SCHEME_HTTPS, - false, &error); - if (!valid) { - DVLOG(1) << error; - } - return valid; -} +constexpr char kYouTubeUrl[] = "https://youtube.com"; + +// bool GetURLPatternSetFromValue(const base::Value* value, +// extensions::URLPatternSet* result) { +// if (!value->is_list()) { +// return false; +// } +// std::string error; +// bool valid = result->Populate(value->GetList(), URLPattern::SCHEME_HTTPS, +// false, &error); +// if (!valid) { +// DVLOG(1) << error; +// } +// return valid; +// } bool GetFilePathFromValue(const base::Value* value, base::FilePath* result) { if (!value->is_string()) { @@ -57,8 +59,8 @@ namespace youtube_script_injector { YouTubeRule::YouTubeRule() = default; YouTubeRule::~YouTubeRule() = default; YouTubeRule::YouTubeRule(const YouTubeRule& other) { - include_pattern_set_ = other.include_pattern_set_.Clone(); - exclude_pattern_set_ = other.exclude_pattern_set_.Clone(); + // include_pattern_set_ = other.include_pattern_set_.Clone(); + // exclude_pattern_set_ = other.exclude_pattern_set_.Clone(); policy_script_path_ = other.policy_script_path_; version_ = other.version_; } @@ -66,10 +68,10 @@ YouTubeRule::YouTubeRule(const YouTubeRule& other) { // static void YouTubeRule::RegisterJSONConverter( base::JSONValueConverter* converter) { - converter->RegisterCustomValueField( - kInclude, &YouTubeRule::include_pattern_set_, GetURLPatternSetFromValue); - converter->RegisterCustomValueField( - kExclude, &YouTubeRule::exclude_pattern_set_, GetURLPatternSetFromValue); + // converter->RegisterCustomValueField( + // kInclude, &YouTubeRule::include_pattern_set_, GetURLPatternSetFromValue); + // converter->RegisterCustomValueField( + // kExclude, &YouTubeRule::exclude_pattern_set_, GetURLPatternSetFromValue); converter->RegisterCustomValueField( kPolicyScript, &YouTubeRule::policy_script_path_, GetFilePathFromValue); converter->RegisterIntField(kVersion, &YouTubeRule::version_); @@ -99,19 +101,29 @@ std::optional> YouTubeRule::ParseRules( return rules; } -bool YouTubeRule::ShouldInsertScript(const GURL& url) const { - // If URL matches an explicitly excluded pattern, this rule does not - // apply. - if (exclude_pattern_set_.MatchesURL(url)) { - return false; - } - // If URL does not match an explicitly included pattern, this rule does not - // apply. - if (!include_pattern_set_.MatchesURL(url)) { - return false; +bool YouTubeRule::IsYouTubeDomain(const GURL& url) const { + if (net::registry_controlled_domains::SameDomainOrHost( + url, GURL(kYouTubeUrl), + net::registry_controlled_domains::INCLUDE_PRIVATE_REGISTRIES)) { + return true; } - return true; + return false; } +// bool YouTubeRule::ShouldInsertScript(const GURL& url) const { +// // If URL matches an explicitly excluded pattern, this rule does not +// // apply. +// if (exclude_pattern_set_.MatchesURL(url)) { +// return false; +// } +// // If URL does not match an explicitly included pattern, this rule does not +// // apply. +// if (!include_pattern_set_.MatchesURL(url)) { +// return false; +// } + +// return true; +// } + } // namespace youtube_script_injector diff --git a/components/youtube_script_injector/browser/core/youtube_rule.h b/components/youtube_script_injector/browser/core/youtube_rule.h index bdd7451e8228..55816ad60fa6 100644 --- a/components/youtube_script_injector/browser/core/youtube_rule.h +++ b/components/youtube_script_injector/browser/core/youtube_rule.h @@ -58,15 +58,16 @@ class YouTubeRule { static std::optional> ParseRules( const std::string& contents); // Check if this rule matches the given URL. - bool ShouldInsertScript(const GURL& url) const; + // bool ShouldInsertScript(const GURL& url) const; + bool IsYouTubeDomain(const GURL& url) const; // Getters. const base::FilePath& GetPolicyScript() const { return policy_script_path_; } int GetVersion() const { return version_; } private: - extensions::URLPatternSet include_pattern_set_; - extensions::URLPatternSet exclude_pattern_set_; + // extensions::URLPatternSet include_pattern_set_; + // extensions::URLPatternSet exclude_pattern_set_; // This is a path (not content) relative to the component under scripts/. base::FilePath policy_script_path_; // Used for checking if the last inserted script is the latest version. diff --git a/components/youtube_script_injector/browser/core/youtube_rule_registry.cc b/components/youtube_script_injector/browser/core/youtube_rule_registry.cc index 12045cecb755..0d6624a7f79d 100644 --- a/components/youtube_script_injector/browser/core/youtube_rule_registry.cc +++ b/components/youtube_script_injector/browser/core/youtube_rule_registry.cc @@ -69,7 +69,7 @@ void YouTubeRuleRegistry::CheckIfMatch( const GURL& url, base::OnceCallback cb) const { for (const YouTubeRule& rule : rules_) { - if (rule.ShouldInsertScript(url)) { + if (rule.IsYouTubeDomain(url)) { base::ThreadPool::PostTaskAndReplyWithResult( FROM_HERE, {base::MayBlock()}, base::BindOnce(&CreateMatchedRule, component_path_,