Index: chrome/browser/page_load_metrics/observers/ads_page_load_metrics_observer.cc |
diff --git a/chrome/browser/page_load_metrics/observers/ads_page_load_metrics_observer.cc b/chrome/browser/page_load_metrics/observers/ads_page_load_metrics_observer.cc |
index 659f1fc8db2431233e50e2b035d890cd43710e1a..f52aad87430134eda65d5252cb02f6b9693cdcb1 100644 |
--- a/chrome/browser/page_load_metrics/observers/ads_page_load_metrics_observer.cc |
+++ b/chrome/browser/page_load_metrics/observers/ads_page_load_metrics_observer.cc |
@@ -11,6 +11,7 @@ |
#include "base/logging.h" |
#include "base/memory/ptr_util.h" |
#include "base/strings/string_util.h" |
+#include "chrome/browser/page_load_metrics/observers/ads_detection.h" |
#include "chrome/browser/page_load_metrics/page_load_metrics_util.h" |
#include "content/public/browser/navigation_handle.h" |
#include "content/public/browser/render_frame_host.h" |
@@ -21,14 +22,7 @@ namespace { |
const base::Feature kAdsFeature{"AdsMetrics", base::FEATURE_ENABLED_BY_DEFAULT}; |
-bool FrameIsAd(content::NavigationHandle* navigation_handle) { |
- // Because sub-resource filtering isn't always enabled, and doesn't work |
- // well in monitoring mode (no CSS enforcement), it's difficult to identify |
- // ads. Google ads are prevalent and easy to track, so we'll start by |
- // tracking those. Note that the frame name can be very large, so be careful |
- // to avoid full string searches if possible. |
- // TODO(jkarlin): Track other ad networks that are easy to identify. |
- |
+bool IsAdFrame(content::NavigationHandle* navigation_handle) { |
// In case the navigation aborted, look up the RFH by the Frame Tree Node |
// ID. It returns the committed frame host or the initial frame host for the |
// frame if no committed host exists. Using a previous host is fine because |
@@ -39,20 +33,9 @@ bool FrameIsAd(content::NavigationHandle* navigation_handle) { |
content::RenderFrameHost* current_frame_host = |
navigation_handle->GetWebContents()->UnsafeFindFrameByFrameTreeNodeId( |
navigation_handle->GetFrameTreeNodeId()); |
- if (current_frame_host) { |
- const std::string& frame_name = current_frame_host->GetFrameName(); |
- if (base::StartsWith(frame_name, "google_ads_iframe", |
- base::CompareCase::SENSITIVE) || |
- base::StartsWith(frame_name, "google_ads_frame", |
- base::CompareCase::SENSITIVE)) { |
- return true; |
- } |
- } |
- const GURL& url = navigation_handle->GetURL(); |
- return url.host_piece() == "tpc.googlesyndication.com" && |
- base::StartsWith(url.path_piece(), "/safeframe", |
- base::CompareCase::SENSITIVE); |
+ return IsAdFrame(current_frame_host ? current_frame_host->GetFrameName() : "", |
+ navigation_handle->GetURL()); |
} |
void RecordParentExistsForSubFrame(bool parent_exists) { |
@@ -114,7 +97,7 @@ void AdsPageLoadMetricsObserver::OnDidFinishSubFrameNavigation( |
// This is the top-most frame in the ad. |
UMA_HISTOGRAM_BOOLEAN( |
"PageLoad.Clients.Ads.Google.Navigations.AdFrameRenavigatedToAd", |
- FrameIsAd(navigation_handle)); |
+ IsAdFrame(navigation_handle)); |
} |
return; |
} |
@@ -122,7 +105,7 @@ void AdsPageLoadMetricsObserver::OnDidFinishSubFrameNavigation( |
// any child frames that were ads, those will still be recorded. |
UMA_HISTOGRAM_BOOLEAN( |
"PageLoad.Clients.Ads.Google.Navigations.NonAdFrameRenavigatedToAd", |
- FrameIsAd(navigation_handle)); |
+ IsAdFrame(navigation_handle)); |
} |
// Determine who the parent frame's ad ancestor is. |
@@ -139,7 +122,7 @@ void AdsPageLoadMetricsObserver::OnDidFinishSubFrameNavigation( |
AdFrameData* ad_data = parent_id_and_data->second; |
- if (!ad_data && FrameIsAd(navigation_handle)) { |
+ if (!ad_data && IsAdFrame(navigation_handle)) { |
// This frame is not nested within an ad frame but is itself an ad. |
ad_frames_data_storage_.emplace_back(frame_tree_node_id); |
ad_data = &ad_frames_data_storage_.back(); |