1 // Copyright 2019 The Chromium Authors. All rights reserved. 2 // Use of this source code is governed by a BSD-style license that can be 3 // found in the LICENSE file. 4 5 // This file contains some useful utilities for the safe_browsing/triggers 6 // classes 7 8 #include "components/safe_browsing/content/triggers/trigger_util.h" 9 10 #include <string> 11 12 #include "content/public/browser/render_frame_host.h" 13 14 namespace safe_browsing { 15 DetectGoogleAd(content::RenderFrameHost * render_frame_host,const GURL & frame_url)16bool DetectGoogleAd(content::RenderFrameHost* render_frame_host, 17 const GURL& frame_url) { 18 // In case the navigation aborted, look up the RFH by the Frame Tree Node 19 // ID. It returns the committed frame host or the initial frame host for the 20 // frame if no committed host exists. Using a previous host is fine because 21 // once a frame has an ad we always consider it to have an ad. 22 // We use the unsafe method of FindFrameByFrameTreeNodeId because we're not 23 // concerned with which process the frame lives on (we only want to know if an 24 // ad could be present on the page right now). 25 if (render_frame_host) { 26 const std::string& frame_name = render_frame_host->GetFrameName(); 27 if (base::StartsWith(frame_name, "google_ads_iframe", 28 base::CompareCase::SENSITIVE) || 29 base::StartsWith(frame_name, "google_ads_frame", 30 base::CompareCase::SENSITIVE)) { 31 return true; 32 } 33 } 34 35 return frame_url.host_piece() == "tpc.googlesyndication.com" && 36 base::StartsWith(frame_url.path_piece(), "/safeframe", 37 base::CompareCase::SENSITIVE); 38 } 39 40 } // namespace safe_browsing 41