Chromium Code Reviews| OLD | NEW |
|---|---|
| (Empty) | |
| 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 | |
| 3 // found in the LICENSE file. | |
| 4 #ifndef CHROME_BROWSER_SAFE_BROWSING_SAFE_BROWSING_NAVIGATION_OBSERVER_H_ | |
| 5 #define CHROME_BROWSER_SAFE_BROWSING_SAFE_BROWSING_NAVIGATION_OBSERVER_H_ | |
| 6 | |
| 7 #include "content/public/browser/navigation_handle.h" | |
| 8 #include "content/public/browser/notification_observer.h" | |
| 9 #include "content/public/browser/notification_registrar.h" | |
| 10 #include "content/public/browser/web_contents_observer.h" | |
| 11 #include "url/gurl.h" | |
| 12 | |
| 13 struct RetargetingDetails; | |
|
Charlie Reis
2016/09/16 23:35:05
nit: This appears unused in the .h file.
Jialiu Lin
2016/09/22 21:30:28
Done.
| |
| 14 | |
| 15 namespace content { | |
| 16 class NavigationHandle; | |
| 17 class NotificationRegistrar; | |
| 18 class RenderFrameHost; | |
| 19 struct ResourceRedirectDetails; | |
| 20 } | |
| 21 | |
| 22 namespace safe_browsing { | |
| 23 | |
| 24 // Observes the navigation events that might lead to a download. | |
| 25 class SafeBrowsingNavigationObserver : public content::NotificationObserver, | |
|
Charlie Reis
2016/09/16 23:35:05
It looks like this is trying to have one instance
Jialiu Lin
2016/09/22 21:30:28
Change to one observer per WebContents instead. Th
| |
| 26 public content::WebContentsObserver { | |
| 27 public: | |
| 28 struct NavigationEvent { | |
|
Charlie Reis
2016/09/16 23:35:06
Please have a comment with some description of how
Jialiu Lin
2016/09/22 21:30:28
Done.
| |
| 29 NavigationEvent(); | |
| 30 NavigationEvent(NavigationEvent&& nav_event); | |
| 31 NavigationEvent& operator=(NavigationEvent&& nav_event); | |
| 32 ~NavigationEvent(); | |
| 33 GURL source_url; | |
| 34 int source_tab_id; | |
|
Charlie Reis
2016/09/16 23:35:05
Please document these fields. For example, WebCon
Jialiu Lin
2016/09/22 21:30:29
Done.
| |
| 35 | |
| 36 GURL target_url; | |
| 37 int target_tab_id; | |
| 38 | |
| 39 int frame_id; // Frame tree node id. | |
| 40 GURL main_frame_url; // Main frame url of the source. | |
| 41 | |
| 42 double timestamp; // Timestamp of last time this object is updated. | |
| 43 | |
| 44 bool is_user_initiated; | |
|
Charlie Reis
2016/09/16 23:35:05
Mention how you track this. Does it boil down to
Jialiu Lin
2016/09/22 21:30:28
Done.
| |
| 45 bool has_committed; | |
| 46 bool is_server_redirect; | |
| 47 bool is_finished; | |
|
Charlie Reis
2016/09/16 23:35:05
What event does this refer to? (There are many po
Jialiu Lin
2016/09/22 21:30:29
This field is no longer needed. Removed.
| |
| 48 GURL server_redirect_url; | |
|
Charlie Reis
2016/09/16 23:35:05
Normally we keep track of a "redirect chain" of UR
Jialiu Lin
2016/09/22 21:30:28
If there are more than one server redirect, this i
| |
| 49 }; | |
| 50 | |
| 51 struct GurlHash { | |
| 52 std::size_t operator()(const GURL& url) const { | |
| 53 return std::hash<std::string>()(url.spec()); | |
| 54 } | |
| 55 }; | |
| 56 | |
| 57 typedef std::unordered_map<GURL, std::vector<NavigationEvent>, GurlHash> | |
| 58 NavigationMap; | |
| 59 typedef std::unordered_map<content::NavigationHandle*, NavigationEvent> | |
| 60 NavigationHandleMap; | |
|
Charlie Reis
2016/09/16 23:35:05
nit: Switch order to be consistent with the declar
Jialiu Lin
2016/09/22 21:30:28
NavigationMap is used in both unit tests and brows
| |
| 61 | |
| 62 SafeBrowsingNavigationObserver(); | |
| 63 | |
| 64 ~SafeBrowsingNavigationObserver() override; | |
| 65 | |
| 66 void ClearNavigationMap(); | |
| 67 | |
| 68 // TODO(jialiul): more functions coming for managing navigation_map_. | |
| 69 | |
| 70 protected: | |
| 71 void RecordNavigationPendingEntry( | |
| 72 const content::NotificationSource& source, | |
| 73 const content::NotificationDetails& details); | |
| 74 | |
| 75 // Record navigation event when observes a chrome::NOTIFICATION_RETARGETING | |
|
Charlie Reis
2016/09/16 23:35:05
nit: s/observes/observing/
Jialiu Lin
2016/09/22 21:30:29
Done.
| |
| 76 // notification. Retargeting means navigation triggered by one webcontents | |
|
Charlie Reis
2016/09/16 23:35:05
nit: WebContents
Jialiu Lin
2016/09/22 21:30:29
Done.
| |
| 77 // finished in another. e.g. open link in a new tab/window either by user or | |
| 78 // by code. | |
| 79 void RecordRetargeting(const content::NotificationDetails& details); | |
|
Charlie Reis
2016/09/16 23:35:05
Huh. I wasn't familiar with NOTIFICATION_RETARGET
Jialiu Lin
2016/09/22 21:30:28
I tried WebContentsObserver::DidOpenRequestedURL a
| |
| 80 | |
| 81 // content::NotificationObserver: | |
| 82 void Observe(int type, | |
| 83 const content::NotificationSource& source, | |
| 84 const content::NotificationDetails& details) override; | |
| 85 | |
| 86 // content::WebContentsObserver: | |
| 87 void DidStartNavigation( | |
| 88 content::NavigationHandle* navigation_handle) override; | |
| 89 | |
|
Charlie Reis
2016/09/16 23:35:05
nit: No blank lines between method override declar
Jialiu Lin
2016/09/22 21:30:29
Done.
| |
| 90 void DidRedirectNavigation( | |
| 91 content::NavigationHandle* navigation_handle) override; | |
| 92 | |
| 93 void DidFinishNavigation( | |
| 94 content::NavigationHandle* navigation_handle) override; | |
| 95 | |
| 96 private: | |
| 97 friend class SBNavigationObserverBrowserTest; | |
| 98 friend class SBNavigationObserverTest; | |
| 99 | |
| 100 NavigationMap* navigation_map() { return &navigation_map_; } | |
| 101 | |
| 102 // Map keyed on NavigationHandle* to keep track of all the ongoing navigation | |
| 103 // events. NavigationHandle pointers are owned by Navigator class. Since a | |
|
Charlie Reis
2016/09/16 23:35:06
I think NavigationHandle is owned by RenderFrameHo
Jialiu Lin
2016/09/22 21:30:28
Done.
| |
| 104 // NavigationHandle object will be destructed after navigation is done, | |
| 105 // corresponding entry in this map will be removed from navigation_handle_map_ | |
| 106 // and added to navigation_map_ at the end of DidFinishNavigation(...). | |
| 107 NavigationHandleMap navigation_handle_map_; | |
| 108 | |
| 109 // navigation_map_ keeps track of all the observed navigations. This map is | |
| 110 // keyed on target url. Since the same url can be requested multiple times | |
| 111 // across different tabs and frames, the value of this map is a vector of | |
| 112 // NavigationEvent ordered by navigation finish time. Entries in | |
| 113 // navigation_map_ will be removed if they are older than t minutes since | |
|
Charlie Reis
2016/09/16 23:35:05
Please say what t is.
I still have to wonder if w
Jialiu Lin
2016/09/22 21:30:29
Ah, sorry, I should mention that t is a place hold
| |
| 114 // their corresponding navigations finish. | |
| 115 NavigationMap navigation_map_; | |
| 116 content::NotificationRegistrar registrar_; | |
| 117 | |
| 118 DISALLOW_COPY_AND_ASSIGN(SafeBrowsingNavigationObserver); | |
| 119 }; | |
| 120 | |
| 121 } // namespace safe_browsing | |
| 122 | |
| 123 #endif // CHROME_BROWSER_SAFE_BROWSING_SAFE_BROWSING_NAVIGATION_OBSERVER_H_ | |
| OLD | NEW |