| OLD | NEW |
| 1 // Copyright 2017 The Chromium Authors. All rights reserved. | 1 // Copyright 2017 The Chromium Authors. All rights reserved. |
| 2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
| 4 | 4 |
| 5 #include "chrome/browser/page_load_metrics/observers/ads_page_load_metrics_obser
ver.h" | 5 #include "chrome/browser/page_load_metrics/observers/ads_page_load_metrics_obser
ver.h" |
| 6 | 6 |
| 7 #include <string> | 7 #include <string> |
| 8 #include <utility> | 8 #include <utility> |
| 9 | 9 |
| 10 #include "base/feature_list.h" | 10 #include "base/feature_list.h" |
| 11 #include "base/logging.h" | 11 #include "base/logging.h" |
| 12 #include "base/memory/ptr_util.h" | 12 #include "base/memory/ptr_util.h" |
| 13 #include "base/strings/string_util.h" | 13 #include "base/strings/string_util.h" |
| 14 #include "chrome/browser/page_load_metrics/observers/ads_detection.h" |
| 14 #include "chrome/browser/page_load_metrics/page_load_metrics_util.h" | 15 #include "chrome/browser/page_load_metrics/page_load_metrics_util.h" |
| 15 #include "content/public/browser/navigation_handle.h" | 16 #include "content/public/browser/navigation_handle.h" |
| 16 #include "content/public/browser/render_frame_host.h" | 17 #include "content/public/browser/render_frame_host.h" |
| 17 #include "content/public/browser/web_contents.h" | 18 #include "content/public/browser/web_contents.h" |
| 18 #include "url/gurl.h" | 19 #include "url/gurl.h" |
| 19 | 20 |
| 20 namespace { | 21 namespace { |
| 21 | 22 |
| 22 const base::Feature kAdsFeature{"AdsMetrics", base::FEATURE_ENABLED_BY_DEFAULT}; | 23 const base::Feature kAdsFeature{"AdsMetrics", base::FEATURE_ENABLED_BY_DEFAULT}; |
| 23 | 24 |
| (...skipping 21 matching lines...) Expand all Loading... |
| 45 // In case the navigation aborted, look up the RFH by the Frame Tree Node | 46 // In case the navigation aborted, look up the RFH by the Frame Tree Node |
| 46 // ID. It returns the committed frame host or the initial frame host for the | 47 // ID. It returns the committed frame host or the initial frame host for the |
| 47 // frame if no committed host exists. Using a previous host is fine because | 48 // frame if no committed host exists. Using a previous host is fine because |
| 48 // once a frame has an ad we always consider it to have an ad. | 49 // once a frame has an ad we always consider it to have an ad. |
| 49 // We use the unsafe method of FindFrameByFrameTreeNodeId because we're not | 50 // We use the unsafe method of FindFrameByFrameTreeNodeId because we're not |
| 50 // concerned with which process the frame lives on (we're just measuring | 51 // concerned with which process the frame lives on (we're just measuring |
| 51 // bytes and not granting security priveleges). | 52 // bytes and not granting security priveleges). |
| 52 content::RenderFrameHost* current_frame_host = | 53 content::RenderFrameHost* current_frame_host = |
| 53 navigation_handle->GetWebContents()->UnsafeFindFrameByFrameTreeNodeId( | 54 navigation_handle->GetWebContents()->UnsafeFindFrameByFrameTreeNodeId( |
| 54 navigation_handle->GetFrameTreeNodeId()); | 55 navigation_handle->GetFrameTreeNodeId()); |
| 55 if (current_frame_host) { | |
| 56 const std::string& frame_name = current_frame_host->GetFrameName(); | |
| 57 if (base::StartsWith(frame_name, "google_ads_iframe", | |
| 58 base::CompareCase::SENSITIVE) || | |
| 59 base::StartsWith(frame_name, "google_ads_frame", | |
| 60 base::CompareCase::SENSITIVE)) { | |
| 61 return true; | |
| 62 } | |
| 63 } | |
| 64 | 56 |
| 65 const GURL& url = navigation_handle->GetURL(); | 57 return IsAdFrame(current_frame_host ? current_frame_host->GetFrameName() : "", |
| 66 return url.host_piece() == "tpc.googlesyndication.com" && | 58 navigation_handle->GetURL()); |
| 67 base::StartsWith(url.path_piece(), "/safeframe", | |
| 68 base::CompareCase::SENSITIVE); | |
| 69 } | 59 } |
| 70 | 60 |
| 71 void RecordParentExistsForSubFrame( | 61 void RecordParentExistsForSubFrame( |
| 72 bool parent_exists, | 62 bool parent_exists, |
| 73 const AdsPageLoadMetricsObserver::AdTypes& ad_types) { | 63 const AdsPageLoadMetricsObserver::AdTypes& ad_types) { |
| 74 ADS_HISTOGRAM("ParentExistsForSubFrame", UMA_HISTOGRAM_BOOLEAN, | 64 ADS_HISTOGRAM("ParentExistsForSubFrame", UMA_HISTOGRAM_BOOLEAN, |
| 75 AdsPageLoadMetricsObserver::AD_TYPE_ALL, parent_exists); | 65 AdsPageLoadMetricsObserver::AD_TYPE_ALL, parent_exists); |
| 76 } | 66 } |
| 77 | 67 |
| 78 } // namespace | 68 } // namespace |
| (...skipping 288 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 367 void AdsPageLoadMetricsObserver::ProcessOngoingNavigationResource( | 357 void AdsPageLoadMetricsObserver::ProcessOngoingNavigationResource( |
| 368 FrameTreeNodeId frame_tree_node_id) { | 358 FrameTreeNodeId frame_tree_node_id) { |
| 369 const auto& frame_id_and_request = | 359 const auto& frame_id_and_request = |
| 370 ongoing_navigation_resources_.find(frame_tree_node_id); | 360 ongoing_navigation_resources_.find(frame_tree_node_id); |
| 371 if (frame_id_and_request == ongoing_navigation_resources_.end()) | 361 if (frame_id_and_request == ongoing_navigation_resources_.end()) |
| 372 return; | 362 return; |
| 373 | 363 |
| 374 ProcessLoadedResource(frame_id_and_request->second); | 364 ProcessLoadedResource(frame_id_and_request->second); |
| 375 ongoing_navigation_resources_.erase(frame_id_and_request); | 365 ongoing_navigation_resources_.erase(frame_id_and_request); |
| 376 } | 366 } |
| OLD | NEW |