Commit bb3988a5 authored by Francois Doray's avatar Francois Doray Committed by Commit Bot

RC: Fix invalid access when getting site engagement score in chrome://discards.

There was an invalid access when the site engagement score of a
WebContents that was never navigated was obtained in chrome://discards.
With this CL, we return 0 as the engagement score of never-navigated
WebContents, instead of doing an invalid access.

Creating a new tab or opening a link in a new tab are actions that
create a WebContents a briefly keep it in a non-navigated state.

Bug: 854497
Change-Id: I204509b7c41445ac4b524f9a652f006189e4fcd9
Reviewed-on: https://chromium-review.googlesource.com/1111908Reviewed-by: default avatarSébastien Marchand <sebmarchand@chromium.org>
Commit-Queue: François Doray <fdoray@chromium.org>
Cr-Commit-Position: refs/heads/master@{#569700}
parent 348b6fa5
...@@ -67,8 +67,13 @@ resource_coordinator::LifecycleUnit* GetLifecycleUnitById(int32_t id) { ...@@ -67,8 +67,13 @@ resource_coordinator::LifecycleUnit* GetLifecycleUnitById(int32_t id) {
double GetSiteEngagementScore(content::WebContents* contents) { double GetSiteEngagementScore(content::WebContents* contents) {
// Get the active navigation entry. Restored tabs should always have one. // Get the active navigation entry. Restored tabs should always have one.
auto& controller = contents->GetController(); auto& controller = contents->GetController();
auto* nav_entry = const int current_entry_index = controller.GetCurrentEntryIndex();
controller.GetEntryAtIndex(controller.GetCurrentEntryIndex());
// A WebContents which hasn't navigated yet does not have a NavigationEntry.
if (current_entry_index == -1)
return 0;
auto* nav_entry = controller.GetEntryAtIndex(current_entry_index);
DCHECK(nav_entry); DCHECK(nav_entry);
auto* engagement_svc = SiteEngagementService::Get( auto* engagement_svc = SiteEngagementService::Get(
......
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