Commit fed7ae11 authored by Ryan Sturm's avatar Ryan Sturm Committed by Commit Bot

Adding subframe pausing for new frames in page load capping

This adds frame pausing when new frames are created.

This also changes the browsertests to use the infobar.

Bug: 835895
Change-Id: I79d92bd91ad0482f41a26b0f1ceaddd88d798abb
Reviewed-on: https://chromium-review.googlesource.com/1091496
Commit-Queue: Ryan Sturm <ryansturm@chromium.org>
Reviewed-by: default avatarTarun Bansal <tbansal@chromium.org>
Cr-Commit-Position: refs/heads/master@{#565656}
parent 92e72e36
......@@ -19,6 +19,7 @@
#include "components/data_reduction_proxy/core/browser/data_reduction_proxy_settings.h"
#include "content/public/browser/browser_context.h"
#include "content/public/browser/navigation_handle.h"
#include "content/public/browser/render_frame_host.h"
#include "content/public/browser/web_contents.h"
namespace {
......@@ -80,6 +81,7 @@ PageCappingPageLoadMetricsObserver::OnCommit(
web_contents_ = navigation_handle->GetWebContents();
page_cap_ = GetPageLoadCappingBytesThreshold(false /* media_page_load */);
url_host_ = navigation_handle->GetURL().host();
MaybeCreate();
// TODO(ryansturm) Check a blacklist of eligible pages.
// https://crbug.com/797981
return page_load_metrics::PageLoadMetricsObserver::CONTINUE_OBSERVING;
......@@ -122,15 +124,31 @@ void PageCappingPageLoadMetricsObserver::MediaStartedPlaying(
page_cap_ = GetPageLoadCappingBytesThreshold(true /* media_page_load */);
}
void PageCappingPageLoadMetricsObserver::OnDidFinishSubFrameNavigation(
content::NavigationHandle* navigation_handle) {
// If the page is not paused, we should not pause new frames.
if (!paused_)
return;
// If the navigation is to the same page, is to an error page, the load hasn't
// committed or render frame host is null, no need to pause the page.
if (navigation_handle->IsSameDocument() || navigation_handle->IsErrorPage() ||
!navigation_handle->HasCommitted() ||
!navigation_handle->GetRenderFrameHost()) {
return;
}
// Pause the new frame.
handles_.push_back(
navigation_handle->GetRenderFrameHost()->PauseSubresourceLoading());
}
void PageCappingPageLoadMetricsObserver::PauseSubresourceLoading(bool pause) {
DCHECK_NE(pause, paused_);
DCHECK(displayed_infobar_);
paused_ = pause;
if (pause) {
if (pause)
handles_ = web_contents_->PauseSubresourceLoading();
} else {
else
handles_.clear();
}
}
page_load_metrics::PageLoadMetricsObserver::ObservePolicy
......
......@@ -42,6 +42,8 @@ class PageCappingPageLoadMetricsObserver
extra_request_complete_info) override;
ObservePolicy OnCommit(content::NavigationHandle* navigation_handle,
ukm::SourceId source_id) override;
void OnDidFinishSubFrameNavigation(
content::NavigationHandle* navigation_handle) override;
void MediaStartedPlaying(
const content::WebContentsObserver::MediaPlayerInfo& video_type,
bool is_in_main_frame) override;
......
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