OLD | NEW |
1 // Copyright 2016 The Chromium Authors. All rights reserved. | 1 // Copyright 2016 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 #ifndef CHROME_BROWSER_SAFE_BROWSING_SAFE_BROWSING_NAVIGATION_OBSERVER_MANAGER_H
_ | 5 #ifndef CHROME_BROWSER_SAFE_BROWSING_SAFE_BROWSING_NAVIGATION_OBSERVER_MANAGER_H
_ |
6 #define CHROME_BROWSER_SAFE_BROWSING_SAFE_BROWSING_NAVIGATION_OBSERVER_MANAGER_H
_ | 6 #define CHROME_BROWSER_SAFE_BROWSING_SAFE_BROWSING_NAVIGATION_OBSERVER_MANAGER_H
_ |
7 | 7 |
| 8 #include "base/feature_list.h" |
8 #include "chrome/common/safe_browsing/csd.pb.h" | 9 #include "chrome/common/safe_browsing/csd.pb.h" |
9 #include "content/public/browser/notification_observer.h" | 10 #include "content/public/browser/notification_observer.h" |
10 #include "content/public/browser/notification_registrar.h" | 11 #include "content/public/browser/notification_registrar.h" |
11 #include "content/public/browser/web_contents_observer.h" | 12 #include "content/public/browser/web_contents_observer.h" |
12 #include "url/gurl.h" | 13 #include "url/gurl.h" |
13 | 14 |
| 15 class Profile; |
| 16 |
14 namespace safe_browsing { | 17 namespace safe_browsing { |
15 | 18 |
16 class SafeBrowsingNavigationObserver; | 19 class SafeBrowsingNavigationObserver; |
17 struct NavigationEvent; | 20 struct NavigationEvent; |
18 struct ResolvedIPAddress; | 21 struct ResolvedIPAddress; |
19 | 22 |
20 // Manager class for SafeBrowsingNavigationObserver, which is in charge of | 23 // Manager class for SafeBrowsingNavigationObserver, which is in charge of |
21 // cleaning up stale navigation events, and identifying landing page/landing | 24 // cleaning up stale navigation events, and identifying landing page/landing |
22 // referrer for a specific download. | 25 // referrer for a specific download. |
23 // TODO(jialiul): For now, SafeBrowsingNavigationObserverManager also listens to | 26 // TODO(jialiul): For now, SafeBrowsingNavigationObserverManager also listens to |
24 // NOTIFICATION_RETARGETING as a way to detect cross frame/tab navigation. | 27 // NOTIFICATION_RETARGETING as a way to detect cross frame/tab navigation. |
25 // Remove base class content::NotificationObserver when | 28 // Remove base class content::NotificationObserver when |
26 // WebContentsObserver::DidOpenRequestedURL() covers all retargeting cases. | 29 // WebContentsObserver::DidOpenRequestedURL() covers all retargeting cases. |
27 class SafeBrowsingNavigationObserverManager | 30 class SafeBrowsingNavigationObserverManager |
28 : public content::NotificationObserver, | 31 : public content::NotificationObserver, |
29 public base::RefCountedThreadSafe<SafeBrowsingNavigationObserverManager> { | 32 public base::RefCountedThreadSafe<SafeBrowsingNavigationObserverManager> { |
30 public: | 33 public: |
| 34 static const base::Feature kDownloadAttribution; |
| 35 |
31 // For UMA histogram counting. Do NOT change order. | 36 // For UMA histogram counting. Do NOT change order. |
32 enum AttributionResult { | 37 enum AttributionResult { |
33 SUCCESS = 1, // Identified referrer chain is not empty. | 38 SUCCESS = 1, // Identified referrer chain is not empty. |
34 SUCCESS_LANDING_PAGE = 2, // Successfully identified landing page. | 39 SUCCESS_LANDING_PAGE = 2, // Successfully identified landing page. |
35 SUCCESS_LANDING_REFERRER = 3, // Successfully identified landing referrer. | 40 SUCCESS_LANDING_REFERRER = 3, // Successfully identified landing referrer. |
36 INVALID_URL = 4, | 41 INVALID_URL = 4, |
37 NAVIGATION_EVENT_NOT_FOUND = 5, | 42 NAVIGATION_EVENT_NOT_FOUND = 5, |
38 | 43 |
39 // Always at the end. | 44 // Always at the end. |
40 ATTRIBUTION_FAILURE_TYPE_MAX | 45 ATTRIBUTION_FAILURE_TYPE_MAX |
41 }; | 46 }; |
42 | 47 |
43 // Helper function to check if user gesture is older than | 48 // Helper function to check if user gesture is older than |
44 // kUserGestureTTLInSecond. | 49 // kUserGestureTTLInSecond. |
45 static bool IsUserGestureExpired(const base::Time& timestamp); | 50 static bool IsUserGestureExpired(const base::Time& timestamp); |
| 51 |
46 // Helper function to strip empty ref fragment from a URL. Many pages | 52 // Helper function to strip empty ref fragment from a URL. Many pages |
47 // end up with a "#" at the end of their URLs due to navigation triggered by | 53 // end up with a "#" at the end of their URLs due to navigation triggered by |
48 // href="#" and javascript onclick function. We don't want to have separate | 54 // href="#" and javascript onclick function. We don't want to have separate |
49 // entries for these cases in the maps. | 55 // entries for these cases in the maps. |
50 static GURL ClearEmptyRef(const GURL& url); | 56 static GURL ClearEmptyRef(const GURL& url); |
51 | 57 |
| 58 // Checks if we should enable observing navigations for safe browsing purpose. |
| 59 // Return true if the safe browsing service and the download attribution |
| 60 // feature are both enabled, and safe browsing service is initialized. |
| 61 static bool IsEnabledAndReady(Profile* profile); |
| 62 |
52 SafeBrowsingNavigationObserverManager(); | 63 SafeBrowsingNavigationObserverManager(); |
53 | 64 |
54 // Add |nav_event| to |navigation_map_| based on |nav_event_key|. Object | 65 // Add |nav_event| to |navigation_map_| based on |nav_event_key|. Object |
55 // pointed to by |nav_event| will be no longer accessible after this function. | 66 // pointed to by |nav_event| will be no longer accessible after this function. |
56 void RecordNavigationEvent(const GURL& nav_event_key, | 67 void RecordNavigationEvent(const GURL& nav_event_key, |
57 NavigationEvent* nav_event); | 68 NavigationEvent* nav_event); |
58 void RecordUserGestureForWebContents(content::WebContents* web_contents, | 69 void RecordUserGestureForWebContents(content::WebContents* web_contents, |
59 const base::Time& timestamp); | 70 const base::Time& timestamp); |
60 void OnUserGestureConsumed(content::WebContents* web_contents, | 71 void OnUserGestureConsumed(content::WebContents* web_contents, |
61 const base::Time& timestamp); | 72 const base::Time& timestamp); |
(...skipping 11 matching lines...) Expand all Loading... |
73 // leading to the target, with the coverage limited to | 84 // leading to the target, with the coverage limited to |
74 // |user_gesture_count_limit| number of user gestures. Then convert these | 85 // |user_gesture_count_limit| number of user gestures. Then convert these |
75 // identified NavigationEvents into ReferrerChainEntrys and append them to | 86 // identified NavigationEvents into ReferrerChainEntrys and append them to |
76 // |out_referrer_chain|. | 87 // |out_referrer_chain|. |
77 AttributionResult IdentifyReferrerChain( | 88 AttributionResult IdentifyReferrerChain( |
78 const GURL& target_url, | 89 const GURL& target_url, |
79 int target_tab_id, // -1 if tab id is not valid | 90 int target_tab_id, // -1 if tab id is not valid |
80 int user_gesture_count_limit, | 91 int user_gesture_count_limit, |
81 std::vector<ReferrerChainEntry>* out_referrer_chain); | 92 std::vector<ReferrerChainEntry>* out_referrer_chain); |
82 | 93 |
83 // Identify and add referrer chain info of a download to ClientDownloadRequest | |
84 // proto. This function also record UMA stats of download attribution result. | |
85 // TODO(jialiul): This function will be moved to DownloadProtectionService | |
86 // class shortly. | |
87 void AddReferrerChainToClientDownloadRequest( | |
88 const GURL& download_url, | |
89 content::WebContents* source_contents, | |
90 ClientDownloadRequest* out_request); | |
91 | |
92 private: | 94 private: |
93 friend class base::RefCountedThreadSafe< | 95 friend class base::RefCountedThreadSafe< |
94 SafeBrowsingNavigationObserverManager>; | 96 SafeBrowsingNavigationObserverManager>; |
95 friend class TestNavigationObserverManager; | 97 friend class TestNavigationObserverManager; |
96 friend class SBNavigationObserverBrowserTest; | 98 friend class SBNavigationObserverBrowserTest; |
97 friend class SBNavigationObserverTest; | 99 friend class SBNavigationObserverTest; |
98 | 100 |
99 struct GurlHash { | 101 struct GurlHash { |
100 std::size_t operator()(const GURL& url) const { | 102 std::size_t operator()(const GURL& url) const { |
101 return std::hash<std::string>()(url.spec()); | 103 return std::hash<std::string>()(url.spec()); |
(...skipping 82 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
184 | 186 |
185 content::NotificationRegistrar registrar_; | 187 content::NotificationRegistrar registrar_; |
186 | 188 |
187 base::OneShotTimer cleanup_timer_; | 189 base::OneShotTimer cleanup_timer_; |
188 | 190 |
189 DISALLOW_COPY_AND_ASSIGN(SafeBrowsingNavigationObserverManager); | 191 DISALLOW_COPY_AND_ASSIGN(SafeBrowsingNavigationObserverManager); |
190 }; | 192 }; |
191 } // namespace safe_browsing | 193 } // namespace safe_browsing |
192 | 194 |
193 #endif // CHROME_BROWSER_SAFE_BROWSING_SAFE_BROWSING_NAVIGATION_OBSERVER_MANAGE
R_H_ | 195 #endif // CHROME_BROWSER_SAFE_BROWSING_SAFE_BROWSING_NAVIGATION_OBSERVER_MANAGE
R_H_ |
OLD | NEW |