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 | |
| 5 #ifndef CHROME_BROWSER_SAFE_BROWSING_SAFE_BROWSING_NAVIGATION_OBSERVER_H_ | |
| 6 #define CHROME_BROWSER_SAFE_BROWSING_SAFE_BROWSING_NAVIGATION_OBSERVER_H_ | |
| 7 | |
| 8 #include "base/supports_user_data.h" | |
| 9 #include "content/public/browser/web_contents_observer.h" | |
| 10 #include "url/gurl.h" | |
| 11 | |
| 12 namespace content { | |
| 13 class NavigationHandle; | |
| 14 struct ResourceRedirectDetails; | |
| 15 } | |
| 16 | |
| 17 namespace safe_browsing { | |
| 18 class SafeBrowsingNavigationObserverManager; | |
| 19 | |
| 20 // Struct to record the details of a navigation event for any frames. | |
|
Charlie Reis
2016/10/17 23:54:03
nit: s/frames/frame/
Jialiu Lin
2016/10/18 19:06:05
Done.
| |
| 21 // This information will be used to fill |url_chain| field in safe browsing | |
| 22 // download pings. | |
| 23 struct NavigationEvent { | |
| 24 NavigationEvent(); | |
| 25 NavigationEvent(NavigationEvent&& nav_event); | |
| 26 NavigationEvent& operator=(NavigationEvent&& nav_event); | |
| 27 ~NavigationEvent(); | |
| 28 | |
| 29 GURL source_url; // URL that caused this navigation to occur. | |
| 30 int source_tab_id; // Which tab the above source_url is in. Tab ID is | |
|
Charlie Reis
2016/10/17 23:54:04
Assuming that source_url might be a subframe, I th
Jialiu Lin
2016/10/18 19:06:05
Ah, that's much clearer. Thanks!
| |
| 31 // returned by SessionTabHelper::IdForTab. This ID is | |
| 32 // immutable for a given tab and unique across Chrome | |
| 33 // within the current session. | |
| 34 | |
| 35 GURL target_url; // The original request URL of this navigation. | |
| 36 int target_tab_id; // Which tab this target url is in. | |
| 37 | |
| 38 int frame_id; // Frame tree node ID of the frame where this navigation takes | |
| 39 // place. | |
| 40 GURL main_frame_url; // Main frame url of the source_url. Can be the same | |
|
Charlie Reis
2016/10/17 23:54:04
This should probably be called source_main_frame_u
Jialiu Lin
2016/10/18 19:06:05
make sense.
| |
| 41 // as source url, if source_url was loaded in main | |
| 42 // frame. | |
| 43 | |
| 44 base::Time timestamp; // Timestamp of last time this object is updated. | |
|
Charlie Reis
2016/10/17 23:54:04
last_updated, perhaps?
Jialiu Lin
2016/10/18 19:06:05
Done.
| |
| 45 | |
| 46 bool is_user_initiated; // browser_initiated || has_user_gesture. | |
| 47 bool has_committed; | |
| 48 bool has_server_redirect; | |
| 49 GURL server_redirect_url; // Last server redirect url in server redirect | |
|
Charlie Reis
2016/10/17 23:54:04
This sounds a bit awkward to use. In most places
Jialiu Lin
2016/10/18 19:06:05
I agree. though for some cases (e.g. download urls
Charlie Reis
2016/10/19 17:10:45
Good point about downloads not committing. Maybe
Jialiu Lin
2016/10/21 02:38:38
SG. renamed to destination_url.
| |
| 50 // chain. In the absence of server redirect, this | |
| 51 // field will be empty. | |
| 52 }; | |
| 53 | |
| 54 // Structure to keep tracks of resolved IP address of a host. | |
|
Charlie Reis
2016/10/17 23:54:04
nit: track
Jialiu Lin
2016/10/18 19:06:05
Done.
| |
| 55 struct ResolvedIPAddress { | |
| 56 ResolvedIPAddress() : timestamp(base::Time::Now()), ip() {} | |
| 57 ResolvedIPAddress(base::Time timestamp, const std::string& ip) | |
| 58 : timestamp(timestamp), ip(ip) {} | |
| 59 base::Time timestamp; // Timestamp of when we get the resolved IP. | |
| 60 std::string ip; // Resolved IP address | |
| 61 }; | |
| 62 | |
| 63 // Observes the navigation events for a single WebContents (both main-frame | |
| 64 // and sub-frame navigations) | |
| 65 class SafeBrowsingNavigationObserver : public base::SupportsUserData::Data, | |
| 66 public content::WebContentsObserver { | |
| 67 public: | |
| 68 static void MaybeCreateForWebContents(content::WebContents* web_contents); | |
| 69 static SafeBrowsingNavigationObserver* FromWebContents( | |
| 70 content::WebContents* web_contents); | |
| 71 | |
| 72 SafeBrowsingNavigationObserver( | |
| 73 content::WebContents* contents, | |
| 74 const scoped_refptr<SafeBrowsingNavigationObserverManager>& manager); | |
| 75 | |
| 76 ~SafeBrowsingNavigationObserver() override; | |
| 77 | |
| 78 private: | |
| 79 typedef std::unordered_map<content::NavigationHandle*, NavigationEvent> | |
| 80 NavigationHandleMap; | |
| 81 | |
| 82 // content::WebContentsObserver: | |
| 83 void DidStartNavigation( | |
| 84 content::NavigationHandle* navigation_handle) override; | |
| 85 void DidRedirectNavigation( | |
| 86 content::NavigationHandle* navigation_handle) override; | |
| 87 void DidFinishNavigation( | |
| 88 content::NavigationHandle* navigation_handle) override; | |
| 89 void DidGetResourceResponseStart( | |
| 90 const content::ResourceRequestDetails& details) override; | |
| 91 void DidGetUserInteraction(const blink::WebInputEvent::Type type) override; | |
| 92 void WebContentsDestroyed() override; | |
| 93 | |
| 94 // Map keyed on NavigationHandle* to keep track of all the ongoing navigation | |
| 95 // events. NavigationHandle pointers are owned by RenderFrameHost. Since a | |
| 96 // NavigationHandle object will be destructed after navigation is done, | |
| 97 // corresponding entry in this map will be removed from navigation_handle_map_ | |
| 98 // and added to navigation_map_ at the end of DidFinishNavigation(...). | |
|
Charlie Reis
2016/10/17 23:54:04
Please clarify where navigation_map_ lives.
Jialiu Lin
2016/10/18 19:06:05
Done.
| |
| 99 NavigationHandleMap navigation_handle_map_; | |
| 100 scoped_refptr<SafeBrowsingNavigationObserverManager> manager_; | |
|
Charlie Reis
2016/10/17 23:54:04
nit: I'd find this section more readable with blan
Jialiu Lin
2016/10/18 19:06:05
Blank lines added.
| |
| 101 // If the observed WebContents just got an user gesture. | |
| 102 bool has_user_gesture_; | |
| 103 base::Time last_user_gesture_timestamp_; | |
| 104 DISALLOW_COPY_AND_ASSIGN(SafeBrowsingNavigationObserver); | |
| 105 }; | |
| 106 | |
| 107 } // namespace safe_browsing | |
| 108 | |
| 109 #endif // CHROME_BROWSER_SAFE_BROWSING_SAFE_BROWSING_NAVIGATION_OBSERVER_H_ | |
| OLD | NEW |