Commit e3651be7 authored by Marc Treib's avatar Marc Treib Committed by Commit Bot

Thumbnails: Capture just before navigating away

Hidden behind new feature CaptureThumbnailOnNavigatingAway.

This is very similar to what NavigationEntryScreenshotManager does.
Hopefully this is a better time for capturing screenshots than when a
page load finishes (see crbug.com/737396 and crbug.com/741856).

Bug: 718413
Change-Id: I0fbcc7964b9f89c7ce589a197ac85b85a41385ba
Reviewed-on: https://chromium-review.googlesource.com/570318Reviewed-by: default avatarFriedrich Horschig <fhorschig@chromium.org>
Commit-Queue: Marc Treib <treib@chromium.org>
Cr-Commit-Position: refs/heads/master@{#486729}
parent a9e5af6d
...@@ -3182,6 +3182,12 @@ const FeatureEntry kFeatureEntries[] = { ...@@ -3182,6 +3182,12 @@ const FeatureEntry kFeatureEntries[] = {
flag_descriptions::kAsyncImageDecodingDescription, kOsAll, flag_descriptions::kAsyncImageDecodingDescription, kOsAll,
MULTI_VALUE_TYPE(kAsyncImageDecodingChoices)}, MULTI_VALUE_TYPE(kAsyncImageDecodingChoices)},
{"capture-thumbnail-on-navigating-away",
flag_descriptions::kCaptureThumbnailOnNavigatingAwayName,
flag_descriptions::kCaptureThumbnailOnNavigatingAwayDescription,
kOsDesktop,
FEATURE_VALUE_TYPE(features::kCaptureThumbnailOnNavigatingAway)},
// NOTE: Adding new command-line switches requires adding corresponding // NOTE: Adding new command-line switches requires adding corresponding
// entries to enum "LoginCustomFlags" in histograms/enums.xml. See note in // entries to enum "LoginCustomFlags" in histograms/enums.xml. See note in
// enums.xml and don't forget to run AboutFlagsHistogramTest unit test. // enums.xml and don't forget to run AboutFlagsHistogramTest unit test.
......
...@@ -87,6 +87,13 @@ const char kCaptureThumbnailOnLoadFinishedDescription[] = ...@@ -87,6 +87,13 @@ const char kCaptureThumbnailOnLoadFinishedDescription[] =
"Capture a page thumbnail (for use on the New Tab page) when the page load " "Capture a page thumbnail (for use on the New Tab page) when the page load "
"finishes, in addition to other times a thumbnail may be captured."; "finishes, in addition to other times a thumbnail may be captured.";
const char kCaptureThumbnailOnNavigatingAwayName[] =
"Capture page thumbnail on navigating away";
const char kCaptureThumbnailOnNavigatingAwayDescription[] =
"Capture a page thumbnail (for use on the New Tab page) when navigating "
"away from the current page, in addition to other times a thumbnail may be "
"captured.";
const char kCastStreamingHwEncodingName[] = const char kCastStreamingHwEncodingName[] =
"Cast Streaming hardware video encoding"; "Cast Streaming hardware video encoding";
const char kCastStreamingHwEncodingDescription[] = const char kCastStreamingHwEncodingDescription[] =
......
...@@ -78,6 +78,9 @@ extern const char kBypassAppBannerEngagementChecksDescription[]; ...@@ -78,6 +78,9 @@ extern const char kBypassAppBannerEngagementChecksDescription[];
extern const char kCaptureThumbnailOnLoadFinishedName[]; extern const char kCaptureThumbnailOnLoadFinishedName[];
extern const char kCaptureThumbnailOnLoadFinishedDescription[]; extern const char kCaptureThumbnailOnLoadFinishedDescription[];
extern const char kCaptureThumbnailOnNavigatingAwayName[];
extern const char kCaptureThumbnailOnNavigatingAwayDescription[];
extern const char kCastStreamingHwEncodingName[]; extern const char kCastStreamingHwEncodingName[];
extern const char kCastStreamingHwEncodingDescription[]; extern const char kCastStreamingHwEncodingDescription[];
......
...@@ -54,24 +54,25 @@ DEFINE_WEB_CONTENTS_USER_DATA_KEY(ThumbnailTabHelper); ...@@ -54,24 +54,25 @@ DEFINE_WEB_CONTENTS_USER_DATA_KEY(ThumbnailTabHelper);
// Overview // Overview
// -------- // --------
// This class provides a service for updating thumbnails to be used in // This class provides a service for updating thumbnails to be used in the
// "Most visited" section of the new tab page. The service can be started // "Most visited" section of the New Tab page. The process is started by
// by UpdateThumbnailIfNecessary(). The current algorithm of the service is as // UpdateThumbnailIfNecessary(), which updates the thumbnail for the current
// simple as follows: // tab if needed. The heuristics to judge whether to update the thumbnail are
// // implemented in ThumbnailService::ShouldAcquirePageThumbnail().
// When a renderer is about to be hidden (this usually occurs when the // There are several triggers that can start the process:
// current tab is closed or another tab is clicked), update the // - When a renderer is about to be hidden (this usually occurs when the current
// thumbnail for the tab rendered by the renderer, if needed. The // tab is closed or another tab is clicked).
// heuristics to judge whether or not to update the thumbnail is // - If features::kCaptureThumbnailOnLoadFinished is enabled: When a page load
// implemented in ThumbnailService::ShouldAcquirePageThumbnail(). // finishes.
// If features::kCaptureThumbnailOnLoadFinished is enabled, then a thumbnail // - If features::kCaptureThumbnailOnNavigatingAway is enabled: Just before
// may also be captured when a page load finishes (subject to the same // navigating away from the current page.
// heuristics).
ThumbnailTabHelper::ThumbnailTabHelper(content::WebContents* contents) ThumbnailTabHelper::ThumbnailTabHelper(content::WebContents* contents)
: content::WebContentsObserver(contents), : content::WebContentsObserver(contents),
capture_on_load_finished_(base::FeatureList::IsEnabled( capture_on_load_finished_(base::FeatureList::IsEnabled(
features::kCaptureThumbnailOnLoadFinished)), features::kCaptureThumbnailOnLoadFinished)),
capture_on_navigating_away_(base::FeatureList::IsEnabled(
features::kCaptureThumbnailOnNavigatingAway)),
page_transition_(ui::PAGE_TRANSITION_LINK), page_transition_(ui::PAGE_TRANSITION_LINK),
load_interrupted_(false), load_interrupted_(false),
weak_factory_(this) { weak_factory_(this) {
...@@ -125,6 +126,12 @@ void ThumbnailTabHelper::DidStartNavigation( ...@@ -125,6 +126,12 @@ void ThumbnailTabHelper::DidStartNavigation(
navigation_handle->IsSameDocument()) { navigation_handle->IsSameDocument()) {
return; return;
} }
if (capture_on_navigating_away_) {
// At this point, the new navigation has just been started, but the
// WebContents still shows the previous page. Grab a thumbnail before it
// goes away.
UpdateThumbnailIfNecessary();
}
// Reset the page transition to some uninteresting type, since the actual // Reset the page transition to some uninteresting type, since the actual
// type isn't available at this point. We'll get it in DidFinishNavigation // type isn't available at this point. We'll get it in DidFinishNavigation
// (if that happens, which isn't guaranteed). // (if that happens, which isn't guaranteed).
...@@ -142,6 +149,8 @@ void ThumbnailTabHelper::DidFinishNavigation( ...@@ -142,6 +149,8 @@ void ThumbnailTabHelper::DidFinishNavigation(
} }
void ThumbnailTabHelper::DidStartLoading() { void ThumbnailTabHelper::DidStartLoading() {
// TODO(treib): We should probably track whether the load *finished* - as it
// is, an in-progress load will count as not interrupted.
load_interrupted_ = false; load_interrupted_ = false;
} }
...@@ -170,12 +179,14 @@ void ThumbnailTabHelper::UpdateThumbnailIfNecessary() { ...@@ -170,12 +179,14 @@ void ThumbnailTabHelper::UpdateThumbnailIfNecessary() {
if (!web_contents() || web_contents()->IsBeingDestroyed()) { if (!web_contents() || web_contents()->IsBeingDestroyed()) {
return; return;
} }
// Skip if a pending entry exists. WidgetHidden can be called while navigating
// pages and this is not a time when thumbnails should be generated. // Note: Do *not* use GetLastVisibleURL - it might already have been updated
if (web_contents()->GetController().GetPendingEntry()) { // for a new pending navigation. The committed URL is the one corresponding
// to the currently visible content.
const GURL& url = web_contents()->GetLastCommittedURL();
if (!url.is_valid()) {
return; return;
} }
const GURL& url = web_contents()->GetURL();
Profile* profile = Profile* profile =
Profile::FromBrowserContext(web_contents()->GetBrowserContext()); Profile::FromBrowserContext(web_contents()->GetBrowserContext());
...@@ -183,7 +194,7 @@ void ThumbnailTabHelper::UpdateThumbnailIfNecessary() { ...@@ -183,7 +194,7 @@ void ThumbnailTabHelper::UpdateThumbnailIfNecessary() {
ThumbnailServiceFactory::GetForProfile(profile); ThumbnailServiceFactory::GetForProfile(profile);
// Skip if we don't need to update the thumbnail. // Skip if we don't need to update the thumbnail.
if (!thumbnail_service.get() || if (!thumbnail_service ||
!thumbnail_service->ShouldAcquirePageThumbnail(url, page_transition_)) { !thumbnail_service->ShouldAcquirePageThumbnail(url, page_transition_)) {
return; return;
} }
...@@ -294,5 +305,10 @@ void ThumbnailTabHelper::RenderViewHostCreated( ...@@ -294,5 +305,10 @@ void ThumbnailTabHelper::RenderViewHostCreated(
} }
void ThumbnailTabHelper::WidgetHidden(content::RenderWidgetHost* widget) { void ThumbnailTabHelper::WidgetHidden(content::RenderWidgetHost* widget) {
// Skip if a pending entry exists. WidgetHidden can be called while navigating
// pages and this is not a time when thumbnails should be generated.
if (!web_contents() || web_contents()->GetController().GetPendingEntry()) {
return;
}
UpdateThumbnailIfNecessary(); UpdateThumbnailIfNecessary();
} }
...@@ -73,6 +73,7 @@ class ThumbnailTabHelper ...@@ -73,6 +73,7 @@ class ThumbnailTabHelper
void WidgetHidden(content::RenderWidgetHost* widget); void WidgetHidden(content::RenderWidgetHost* widget);
const bool capture_on_load_finished_; const bool capture_on_load_finished_;
const bool capture_on_navigating_away_;
content::NotificationRegistrar registrar_; content::NotificationRegistrar registrar_;
......
...@@ -117,6 +117,11 @@ const base::Feature kCaptureThumbnailDependingOnTransitionType{ ...@@ -117,6 +117,11 @@ const base::Feature kCaptureThumbnailDependingOnTransitionType{
const base::Feature kCaptureThumbnailOnLoadFinished{ const base::Feature kCaptureThumbnailOnLoadFinished{
"CaptureThumbnailOnLoadFinished", base::FEATURE_DISABLED_BY_DEFAULT}; "CaptureThumbnailOnLoadFinished", base::FEATURE_DISABLED_BY_DEFAULT};
// Whether to capture page thumbnails when navigating away from the current page
// (in addition to any other times this might happen).
const base::Feature kCaptureThumbnailOnNavigatingAway{
"CaptureThumbnailOnNavigatingAway", base::FEATURE_DISABLED_BY_DEFAULT};
// Whether to trigger app banner installability checks on page load. // Whether to trigger app banner installability checks on page load.
const base::Feature kCheckInstallabilityForBannerOnLoad{ const base::Feature kCheckInstallabilityForBannerOnLoad{
"CheckInstallabilityForBannerOnLoad", base::FEATURE_DISABLED_BY_DEFAULT}; "CheckInstallabilityForBannerOnLoad", base::FEATURE_DISABLED_BY_DEFAULT};
......
...@@ -65,6 +65,8 @@ extern const base::Feature kCaptureThumbnailDependingOnTransitionType; ...@@ -65,6 +65,8 @@ extern const base::Feature kCaptureThumbnailDependingOnTransitionType;
extern const base::Feature kCaptureThumbnailOnLoadFinished; extern const base::Feature kCaptureThumbnailOnLoadFinished;
extern const base::Feature kCaptureThumbnailOnNavigatingAway;
extern const base::Feature kCheckInstallabilityForBannerOnLoad; extern const base::Feature kCheckInstallabilityForBannerOnLoad;
extern const base::Feature kClickToOpenPDFPlaceholder; extern const base::Feature kClickToOpenPDFPlaceholder;
......
...@@ -23292,6 +23292,7 @@ from previous Chrome versions. ...@@ -23292,6 +23292,7 @@ from previous Chrome versions.
<int value="835018878" label="disable-quic"/> <int value="835018878" label="disable-quic"/>
<int value="838887742" label="manual-enhanced-bookmarks"/> <int value="838887742" label="manual-enhanced-bookmarks"/>
<int value="841343322" label="disable-new-korean-ime"/> <int value="841343322" label="disable-new-korean-ime"/>
<int value="842432903" label="CaptureThumbnailOnNavigatingAway:enabled"/>
<int value="846951416" label="CopylessPaste:enabled"/> <int value="846951416" label="CopylessPaste:enabled"/>
<int value="851085848" label="enable-settings-window"/> <int value="851085848" label="enable-settings-window"/>
<int value="854730848" label="disable-app-info-dialog-mac"/> <int value="854730848" label="disable-app-info-dialog-mac"/>
...@@ -23489,6 +23490,7 @@ from previous Chrome versions. ...@@ -23489,6 +23490,7 @@ from previous Chrome versions.
<int value="1441897340" label="AndroidSpellCheckerNonLowEnd:enabled"/> <int value="1441897340" label="AndroidSpellCheckerNonLowEnd:enabled"/>
<int value="1442798825" label="enable-quic"/> <int value="1442798825" label="enable-quic"/>
<int value="1442830837" label="MemoryAblation:disabled"/> <int value="1442830837" label="MemoryAblation:disabled"/>
<int value="1454143461" label="CaptureThumbnailOnNavigatingAway:disabled"/>
<int value="1454363479" label="disable-storage-manager"/> <int value="1454363479" label="disable-storage-manager"/>
<int value="1458583431" label="arc-use-auth-endpoint"/> <int value="1458583431" label="arc-use-auth-endpoint"/>
<int value="1459529277" label="disable-text-input-focus-manager"/> <int value="1459529277" label="disable-text-input-focus-manager"/>
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