Index: chrome/browser/page_load_metrics/metrics_web_contents_observer.cc |
diff --git a/chrome/browser/page_load_metrics/metrics_web_contents_observer.cc b/chrome/browser/page_load_metrics/metrics_web_contents_observer.cc |
index 072f1b510545a10a919d715471a2208a1e9ab919..985c1544665ae29755dd2704cf26cd437747af83 100644 |
--- a/chrome/browser/page_load_metrics/metrics_web_contents_observer.cc |
+++ b/chrome/browser/page_load_metrics/metrics_web_contents_observer.cc |
@@ -18,6 +18,7 @@ |
#include "chrome/browser/page_load_metrics/page_load_metrics_update_dispatcher.h" |
#include "chrome/browser/page_load_metrics/page_load_metrics_util.h" |
#include "chrome/browser/page_load_metrics/page_load_tracker.h" |
+#include "chrome/browser/prerender/prerender_contents.h" |
#include "chrome/common/chrome_features.h" |
#include "chrome/common/page_load_metrics/page_load_metrics_messages.h" |
#include "chrome/common/page_load_metrics/page_load_timing.h" |
@@ -69,24 +70,33 @@ UserInitiatedInfo CreateUserInitiatedInfo( |
MetricsWebContentsObserver::MetricsWebContentsObserver( |
content::WebContents* web_contents, |
+ const base::Optional<content::WebContents::CreateParams>& create_params, |
std::unique_ptr<PageLoadMetricsEmbedderInterface> embedder_interface) |
: content::WebContentsObserver(web_contents), |
- in_foreground_(false), |
+ in_foreground_(create_params ? !create_params->initially_hidden : false), |
embedder_interface_(std::move(embedder_interface)), |
has_navigated_(false), |
page_load_metrics_binding_(web_contents, this) { |
+ // Prerender's CreateParams erroneously reports that it is not initially |
+ // hidden, so we manually override visibility state for prerender. |
+ const bool is_prerender = |
+ prerender::PrerenderContents::FromWebContents(web_contents) != nullptr; |
+ if (is_prerender) |
+ in_foreground_ = false; |
+ |
RegisterInputEventObserver(web_contents->GetRenderViewHost()); |
} |
// static |
MetricsWebContentsObserver* MetricsWebContentsObserver::CreateForWebContents( |
content::WebContents* web_contents, |
+ const base::Optional<content::WebContents::CreateParams>& create_params, |
std::unique_ptr<PageLoadMetricsEmbedderInterface> embedder_interface) { |
DCHECK(web_contents); |
MetricsWebContentsObserver* metrics = FromWebContents(web_contents); |
if (!metrics) { |
- metrics = new MetricsWebContentsObserver(web_contents, |
+ metrics = new MetricsWebContentsObserver(web_contents, create_params, |
std::move(embedder_interface)); |
web_contents->SetUserData(UserDataKey(), base::WrapUnique(metrics)); |
} |