OLD | NEW |
(Empty) | |
| 1 // Copyright 2015 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 #include "chrome/browser/engagement/site_engagement_helper.h" |
| 6 |
| 7 #include "chrome/browser/engagement/site_engagement_service.h" |
| 8 #include "chrome/browser/engagement/site_engagement_service_factory.h" |
| 9 #include "chrome/browser/prerender/prerender_contents.h" |
| 10 #include "chrome/browser/profiles/profile.h" |
| 11 #include "content/public/browser/navigation_entry.h" |
| 12 #include "content/public/browser/web_contents.h" |
| 13 |
| 14 DEFINE_WEB_CONTENTS_USER_DATA_KEY(SiteEngagementHelper); |
| 15 |
| 16 SiteEngagementHelper::~SiteEngagementHelper() { |
| 17 } |
| 18 |
| 19 SiteEngagementHelper::SiteEngagementHelper(content::WebContents* web_contents) |
| 20 : content::WebContentsObserver(web_contents) { |
| 21 } |
| 22 |
| 23 void SiteEngagementHelper::DidStartNavigationToPendingEntry( |
| 24 const GURL& url, |
| 25 content::NavigationController::ReloadType reload_type) { |
| 26 prerender::PrerenderContents* prerender_contents = |
| 27 prerender::PrerenderContents::FromWebContents(web_contents()); |
| 28 |
| 29 // Ignore pre-render loads. |
| 30 if (prerender_contents != NULL) |
| 31 return; |
| 32 |
| 33 // Ignore all schemes except HTTP and HTTPS. |
| 34 if (!url.SchemeIsHTTPOrHTTPS()) |
| 35 return; |
| 36 |
| 37 Profile* profile = |
| 38 Profile::FromBrowserContext(web_contents()->GetBrowserContext()); |
| 39 SiteEngagementService* service = |
| 40 SiteEngagementServiceFactory::GetForProfile(profile); |
| 41 DCHECK(service); |
| 42 |
| 43 service->HandleNavigation(url); |
| 44 } |
OLD | NEW |