Commit 75a59538 authored by Michael Crouse's avatar Michael Crouse Committed by Commit Bot

[LiteVideo] Rework rebuffer blocklist key without navigation handle.

The rebuffer event will be observed based on a renderframe host rather
than navigation handle. The navigation handle will have expired so
we will need to support a GURL-based API rather than a navigation
handle one.

A future change will update the LiteVideoObserver to maintain a map
of GURL to renderframe host and plumb the stop throttling update
to the blocklist.

Bug: 1101563
Change-Id: Idec5588a6a948c19a0318f08e555cb857404d584
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/2316852
Auto-Submit: Michael Crouse <mcrouse@chromium.org>
Commit-Queue: rajendrant <rajendrant@chromium.org>
Reviewed-by: default avatarrajendrant <rajendrant@chromium.org>
Reviewed-by: default avatarSophie Chang <sophiechang@chromium.org>
Cr-Commit-Position: refs/heads/master@{#792396}
parent 36b99bd7
...@@ -12,38 +12,37 @@ ...@@ -12,38 +12,37 @@
namespace { namespace {
// Determine whether the provided navigation is valid and can be queried or // Determine whether the URL is valid and can be queried or
// added to the blocklist. // added to the blocklist.
bool IsNavigationValidForBlocklist( bool IsURLValidForBlocklist(const GURL& url) {
content::NavigationHandle* navigation_handle) { return url.SchemeIsHTTPOrHTTPS() && url.has_host();
GURL navigation_url = navigation_handle->GetURL();
return navigation_url.SchemeIsHTTPOrHTTPS() && navigation_url.has_host();
} }
} // namespace
namespace lite_video {
// Separator between hosts for the rebuffer blocklist type. // Separator between hosts for the rebuffer blocklist type.
constexpr char kLiteVideoBlocklistKeySeparator[] = "_"; constexpr char kLiteVideoBlocklistKeySeparator[] = "_";
// static // Returns the key for a navigation used for the rebuffer blocklist type.
base::Optional<std::string> LiteVideoUserBlocklist::GetRebufferBlocklistKey( // The key format is "mainframe.com_subframe.com", if the navigation is the
content::NavigationHandle* navigation_handle) { // mainframe navigation, the key omits subframe.com, e.g., "mainframe.com_"
if (!IsNavigationValidForBlocklist(navigation_handle)) base::Optional<std::string> GetRebufferBlocklistKey(
const GURL& mainframe_url,
base::Optional<GURL> subframe_url) {
if (!IsURLValidForBlocklist(mainframe_url))
return base::nullopt; return base::nullopt;
const GURL url = navigation_handle->GetURL(); if (!subframe_url)
if (navigation_handle->IsInMainFrame()) return mainframe_url.host() + kLiteVideoBlocklistKeySeparator;
return url.host() + kLiteVideoBlocklistKeySeparator;
const GURL mainframe_url = if (!IsURLValidForBlocklist(*subframe_url))
navigation_handle->GetWebContents()->GetLastCommittedURL();
if (!mainframe_url.SchemeIsHTTPOrHTTPS() || !mainframe_url.has_host())
return base::nullopt; return base::nullopt;
return mainframe_url.host() + kLiteVideoBlocklistKeySeparator + url.host(); return mainframe_url.host() + kLiteVideoBlocklistKeySeparator +
subframe_url->host();
} }
} // namespace
namespace lite_video {
LiteVideoUserBlocklist::LiteVideoUserBlocklist( LiteVideoUserBlocklist::LiteVideoUserBlocklist(
std::unique_ptr<blocklist::OptOutStore> opt_out_store, std::unique_ptr<blocklist::OptOutStore> opt_out_store,
base::Clock* clock, base::Clock* clock,
...@@ -57,19 +56,25 @@ LiteVideoUserBlocklist::~LiteVideoUserBlocklist() = default; ...@@ -57,19 +56,25 @@ LiteVideoUserBlocklist::~LiteVideoUserBlocklist() = default;
LiteVideoBlocklistReason LiteVideoUserBlocklist::IsLiteVideoAllowedOnNavigation( LiteVideoBlocklistReason LiteVideoUserBlocklist::IsLiteVideoAllowedOnNavigation(
content::NavigationHandle* navigation_handle) const { content::NavigationHandle* navigation_handle) const {
DCHECK_CALLED_ON_VALID_SEQUENCE(sequence_checker_); DCHECK_CALLED_ON_VALID_SEQUENCE(sequence_checker_);
if (!IsNavigationValidForBlocklist(navigation_handle)) GURL navigation_url = navigation_handle->GetURL();
if (!IsURLValidForBlocklist(navigation_url))
return LiteVideoBlocklistReason::kNavigationNotEligibile; return LiteVideoBlocklistReason::kNavigationNotEligibile;
std::vector<blocklist::BlocklistReason> passed_reasons; std::vector<blocklist::BlocklistReason> passed_reasons;
auto blocklist_reason = blocklist::OptOutBlocklist::IsLoadedAndAllowed( auto blocklist_reason = blocklist::OptOutBlocklist::IsLoadedAndAllowed(
navigation_handle->GetURL().host(), navigation_url.host(),
static_cast<int>(LiteVideoBlocklistType::kNavigationBlocklist), static_cast<int>(LiteVideoBlocklistType::kNavigationBlocklist),
/*opt_out=*/false, &passed_reasons); /*opt_out=*/false, &passed_reasons);
if (blocklist_reason != blocklist::BlocklistReason::kAllowed) if (blocklist_reason != blocklist::BlocklistReason::kAllowed)
return LiteVideoBlocklistReason::kNavigationBlocklisted; return LiteVideoBlocklistReason::kNavigationBlocklisted;
base::Optional<std::string> rebuffer_key = base::Optional<std::string> rebuffer_key =
GetRebufferBlocklistKey(navigation_handle); navigation_handle->IsInMainFrame()
? GetRebufferBlocklistKey(navigation_url, base::nullopt)
: GetRebufferBlocklistKey(
navigation_handle->GetWebContents()->GetLastCommittedURL(),
navigation_url);
if (!rebuffer_key) if (!rebuffer_key)
return LiteVideoBlocklistReason::kNavigationNotEligibile; return LiteVideoBlocklistReason::kNavigationNotEligibile;
...@@ -128,7 +133,7 @@ void LiteVideoUserBlocklist::AddNavigationToBlocklist( ...@@ -128,7 +133,7 @@ void LiteVideoUserBlocklist::AddNavigationToBlocklist(
content::NavigationHandle* navigation_handle, content::NavigationHandle* navigation_handle,
bool opt_out) { bool opt_out) {
DCHECK_CALLED_ON_VALID_SEQUENCE(sequence_checker_); DCHECK_CALLED_ON_VALID_SEQUENCE(sequence_checker_);
if (!IsNavigationValidForBlocklist(navigation_handle)) if (!IsURLValidForBlocklist(navigation_handle->GetURL()))
return; return;
AddEntry(navigation_handle->GetURL().host(), opt_out, AddEntry(navigation_handle->GetURL().host(), opt_out,
static_cast<int>(LiteVideoBlocklistType::kNavigationBlocklist)); static_cast<int>(LiteVideoBlocklistType::kNavigationBlocklist));
......
...@@ -105,11 +105,6 @@ class LiteVideoUserBlocklist : public blocklist::OptOutBlocklist { ...@@ -105,11 +105,6 @@ class LiteVideoUserBlocklist : public blocklist::OptOutBlocklist {
const override; const override;
private: private:
// Returns the key for a navigation used for the rebuffer blocklist type.
// The key format is "mainframe.com_subframe.com", if the navigation is the
// mainframe navigation, the key omits subframe.com, e.g., "mainframe.com_".
static base::Optional<std::string> GetRebufferBlocklistKey(
content::NavigationHandle* navigation_handle);
SEQUENCE_CHECKER(sequence_checker_); SEQUENCE_CHECKER(sequence_checker_);
}; };
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment