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 "base/feature_list.h" |
9 #include "chrome/common/safe_browsing/csd.pb.h" | 9 #include "chrome/common/safe_browsing/csd.pb.h" |
10 #include "content/public/browser/notification_observer.h" | 10 #include "content/public/browser/notification_observer.h" |
(...skipping 14 matching lines...) Expand all Loading... |
25 // referrer for a specific download. | 25 // referrer for a specific download. |
26 // TODO(jialiul): For now, SafeBrowsingNavigationObserverManager also listens to | 26 // TODO(jialiul): For now, SafeBrowsingNavigationObserverManager also listens to |
27 // NOTIFICATION_RETARGETING as a way to detect cross frame/tab navigation. | 27 // NOTIFICATION_RETARGETING as a way to detect cross frame/tab navigation. |
28 // Remove base class content::NotificationObserver when | 28 // Remove base class content::NotificationObserver when |
29 // WebContentsObserver::DidOpenRequestedURL() covers all retargeting cases. | 29 // WebContentsObserver::DidOpenRequestedURL() covers all retargeting cases. |
30 class SafeBrowsingNavigationObserverManager | 30 class SafeBrowsingNavigationObserverManager |
31 : public content::NotificationObserver, | 31 : public content::NotificationObserver, |
32 public base::RefCountedThreadSafe<SafeBrowsingNavigationObserverManager> { | 32 public base::RefCountedThreadSafe<SafeBrowsingNavigationObserverManager> { |
33 public: | 33 public: |
34 static const base::Feature kDownloadAttribution; | 34 static const base::Feature kDownloadAttribution; |
| 35 typedef std::vector<std::unique_ptr<ReferrerChainEntry>> ReferrerChain; |
35 | 36 |
36 // For UMA histogram counting. Do NOT change order. | 37 // For UMA histogram counting. Do NOT change order. |
37 enum AttributionResult { | 38 enum AttributionResult { |
38 SUCCESS = 1, // Identified referrer chain is not empty. | 39 SUCCESS = 1, // Identified referrer chain is not empty. |
39 SUCCESS_LANDING_PAGE = 2, // Successfully identified landing page. | 40 SUCCESS_LANDING_PAGE = 2, // Successfully identified landing page. |
40 SUCCESS_LANDING_REFERRER = 3, // Successfully identified landing referrer. | 41 SUCCESS_LANDING_REFERRER = 3, // Successfully identified landing referrer. |
41 INVALID_URL = 4, | 42 INVALID_URL = 4, |
42 NAVIGATION_EVENT_NOT_FOUND = 5, | 43 NAVIGATION_EVENT_NOT_FOUND = 5, |
43 | 44 |
44 // Always at the end. | 45 // Always at the end. |
(...skipping 38 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
83 // Based on the |target_url| and |target_tab_id|, trace back the observed | 84 // Based on the |target_url| and |target_tab_id|, trace back the observed |
84 // NavigationEvents in navigation_map_ to identify the sequence of navigations | 85 // NavigationEvents in navigation_map_ to identify the sequence of navigations |
85 // leading to the target, with the coverage limited to | 86 // leading to the target, with the coverage limited to |
86 // |user_gesture_count_limit| number of user gestures. Then convert these | 87 // |user_gesture_count_limit| number of user gestures. Then convert these |
87 // identified NavigationEvents into ReferrerChainEntrys and append them to | 88 // identified NavigationEvents into ReferrerChainEntrys and append them to |
88 // |out_referrer_chain|. | 89 // |out_referrer_chain|. |
89 AttributionResult IdentifyReferrerChainForDownload( | 90 AttributionResult IdentifyReferrerChainForDownload( |
90 const GURL& target_url, | 91 const GURL& target_url, |
91 int target_tab_id, // -1 if tab id is not valid | 92 int target_tab_id, // -1 if tab id is not valid |
92 int user_gesture_count_limit, | 93 int user_gesture_count_limit, |
93 std::vector<ReferrerChainEntry>* out_referrer_chain); | 94 ReferrerChain* out_referrer_chain); |
94 | 95 |
95 // Based on the |initiating_frame_url| and its associated |tab_id|, trace back | 96 // Based on the |initiating_frame_url| and its associated |tab_id|, trace back |
96 // the observed NavigationEvents in navigation_map_ to identify the sequence | 97 // the observed NavigationEvents in navigation_map_ to identify the sequence |
97 // of navigations leading to this |initiating_frame_url|. If this initiating | 98 // of navigations leading to this |initiating_frame_url|. If this initiating |
98 // frame has a user gesture, we trace back with the coverage limited to | 99 // frame has a user gesture, we trace back with the coverage limited to |
99 // |user_gesture_count_limit|-1 number of user gestures, otherwise we trace | 100 // |user_gesture_count_limit|-1 number of user gestures, otherwise we trace |
100 // back |user_gesture_count_limit| number of user gestures. We then convert | 101 // back |user_gesture_count_limit| number of user gestures. We then convert |
101 // these identified NavigationEvents into ReferrerChainEntrys and append them | 102 // these identified NavigationEvents into ReferrerChainEntrys and append them |
102 // to |out_referrer_chain|. | 103 // to |out_referrer_chain|. |
103 AttributionResult IdentifyReferrerChainForPPAPIDownload( | 104 AttributionResult IdentifyReferrerChainForPPAPIDownload( |
104 const GURL& initiating_frame_url, | 105 const GURL& initiating_frame_url, |
105 int tab_id, | 106 int tab_id, |
106 bool has_user_gesture, | 107 bool has_user_gesture, |
107 int user_gesture_count_limit, | 108 int user_gesture_count_limit, |
108 std::vector<ReferrerChainEntry>* out_referrer_chain); | 109 ReferrerChain* out_referrer_chain); |
109 | 110 |
110 private: | 111 private: |
111 friend class base::RefCountedThreadSafe< | 112 friend class base::RefCountedThreadSafe< |
112 SafeBrowsingNavigationObserverManager>; | 113 SafeBrowsingNavigationObserverManager>; |
113 friend class TestNavigationObserverManager; | 114 friend class TestNavigationObserverManager; |
114 friend class SBNavigationObserverBrowserTest; | 115 friend class SBNavigationObserverBrowserTest; |
115 friend class SBNavigationObserverTest; | 116 friend class SBNavigationObserverTest; |
116 | 117 |
117 struct GurlHash { | 118 struct GurlHash { |
118 std::size_t operator()(const GURL& url) const { | 119 std::size_t operator()(const GURL& url) const { |
(...skipping 54 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
173 // \ / | 174 // \ / |
174 // B | 175 // B |
175 // In this case, FindNavigationEvent() will think url2 in Window B is the | 176 // In this case, FindNavigationEvent() will think url2 in Window B is the |
176 // referrer of about::blank in Window C since this navigation is more recent. | 177 // referrer of about::blank in Window C since this navigation is more recent. |
177 // However, it does not prevent us to attribute url1 in Window A as the cause | 178 // However, it does not prevent us to attribute url1 in Window A as the cause |
178 // of all these navigations. | 179 // of all these navigations. |
179 NavigationEvent* FindNavigationEvent(const GURL& target_url, | 180 NavigationEvent* FindNavigationEvent(const GURL& target_url, |
180 const GURL& target_main_frame_url, | 181 const GURL& target_main_frame_url, |
181 int target_tab_id); | 182 int target_tab_id); |
182 | 183 |
183 void AddToReferrerChain(std::vector<ReferrerChainEntry>* referrer_chain, | 184 void AddToReferrerChain(ReferrerChain* referrer_chain, |
184 NavigationEvent* nav_event, | 185 NavigationEvent* nav_event, |
185 ReferrerChainEntry::URLType type); | 186 ReferrerChainEntry::URLType type); |
186 | 187 |
187 // Helper function to get the remaining referrer chain when we've already | 188 // Helper function to get the remaining referrer chain when we've already |
188 // traced back |current_user_gesture_count| number of user gestures. | 189 // traced back |current_user_gesture_count| number of user gestures. |
189 // This function modifies the |out_referrer_chain| and |out_result|. | 190 // This function modifies the |out_referrer_chain| and |out_result|. |
190 void GetRemainingReferrerChain( | 191 void GetRemainingReferrerChain(NavigationEvent* last_nav_event_traced, |
191 NavigationEvent* last_nav_event_traced, | 192 int current_user_gesture_count, |
192 int current_user_gesture_count, | 193 int user_gesture_count_limit, |
193 int user_gesture_count_limit, | 194 ReferrerChain* out_referrer_chain, |
194 std::vector<ReferrerChainEntry>* out_referrer_chain, | 195 AttributionResult* out_result); |
195 AttributionResult* out_result); | |
196 | 196 |
197 // navigation_map_ keeps track of all the observed navigations. This map is | 197 // navigation_map_ keeps track of all the observed navigations. This map is |
198 // keyed on the resolved request url. In other words, in case of server | 198 // keyed on the resolved request url. In other words, in case of server |
199 // redirects, its key is the last server redirect url, otherwise, it is the | 199 // redirects, its key is the last server redirect url, otherwise, it is the |
200 // original target url. Since the same url can be requested multiple times | 200 // original target url. Since the same url can be requested multiple times |
201 // across different tabs and frames, the value of this map is a vector of | 201 // across different tabs and frames, the value of this map is a vector of |
202 // NavigationEvent ordered by navigation finish time. | 202 // NavigationEvent ordered by navigation finish time. |
203 // Entries in navigation_map_ will be removed if they are older than 2 minutes | 203 // Entries in navigation_map_ will be removed if they are older than 2 minutes |
204 // since their corresponding navigations finish. | 204 // since their corresponding navigations finish. |
205 NavigationMap navigation_map_; | 205 NavigationMap navigation_map_; |
(...skipping 12 matching lines...) Expand all Loading... |
218 | 218 |
219 content::NotificationRegistrar registrar_; | 219 content::NotificationRegistrar registrar_; |
220 | 220 |
221 base::OneShotTimer cleanup_timer_; | 221 base::OneShotTimer cleanup_timer_; |
222 | 222 |
223 DISALLOW_COPY_AND_ASSIGN(SafeBrowsingNavigationObserverManager); | 223 DISALLOW_COPY_AND_ASSIGN(SafeBrowsingNavigationObserverManager); |
224 }; | 224 }; |
225 } // namespace safe_browsing | 225 } // namespace safe_browsing |
226 | 226 |
227 #endif // CHROME_BROWSER_SAFE_BROWSING_SAFE_BROWSING_NAVIGATION_OBSERVER_MANAGE
R_H_ | 227 #endif // CHROME_BROWSER_SAFE_BROWSING_SAFE_BROWSING_NAVIGATION_OBSERVER_MANAGE
R_H_ |
OLD | NEW |