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 frame. | |
| 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 // TODO(jialiul): source_url may be incorrect when | |
| 31 // navigation involves frames targeting each other. | |
| 32 // http://crbug.com/651895. | |
| 33 GURL source_main_frame_url; // Main frame url of the source_url. Could be the | |
| 34 // same as source_url, if source_url was loaded | |
| 35 // in main frame. | |
| 36 GURL original_request_url; // The original request URL of this navigation. | |
| 37 GURL destination_url; // The actual destination url of this navigation | |
| 38 // event. If this navigation has server side | |
| 39 // redirect(s), actual_target_url will be different | |
| 40 // from initial_request_url. | |
|
Charlie Reis
2016/10/28 23:36:09
nit: Fix indent.
Jialiu Lin
2016/10/29 00:45:34
Done.
| |
| 41 int source_tab_id; // Which tab contains the frame with source_url. Tab ID is | |
| 42 // returned by SessionTabHelper::IdForTab. This ID is | |
| 43 // immutable for a given tab and unique across Chrome | |
| 44 // within the current session. | |
| 45 | |
|
Charlie Reis
2016/10/28 23:36:09
nit: Not sure why some of these have blank lines b
Jialiu Lin
2016/10/29 00:45:34
Done.
| |
| 46 int target_tab_id; // Which tab this request url is targeting to. | |
| 47 | |
| 48 int frame_id; // Frame tree node ID of the frame where this navigation takes | |
| 49 // place. | |
| 50 | |
| 51 base::Time last_updated; // When this NavigationEvent was last updated. | |
| 52 | |
| 53 bool is_user_initiated; // browser_initiated || has_user_gesture. | |
| 54 bool has_committed; | |
| 55 bool has_server_redirect; | |
| 56 }; | |
| 57 | |
| 58 // Structure to keep track of resolved IP address of a host. | |
| 59 struct ResolvedIPAddress { | |
| 60 ResolvedIPAddress() : timestamp(base::Time::Now()), ip() {} | |
| 61 ResolvedIPAddress(base::Time timestamp, const std::string& ip) | |
| 62 : timestamp(timestamp), ip(ip) {} | |
| 63 base::Time timestamp; // Timestamp of when we get the resolved IP. | |
| 64 std::string ip; // Resolved IP address | |
| 65 }; | |
| 66 | |
| 67 // Observes the navigation events for a single WebContents (both main-frame | |
| 68 // and sub-frame navigations) | |
|
Charlie Reis
2016/10/28 23:36:09
nit: End with period.
Jialiu Lin
2016/10/29 00:45:34
Done.
| |
| 69 class SafeBrowsingNavigationObserver : public base::SupportsUserData::Data, | |
| 70 public content::WebContentsObserver { | |
| 71 public: | |
| 72 static void MaybeCreateForWebContents(content::WebContents* web_contents); | |
| 73 static SafeBrowsingNavigationObserver* FromWebContents( | |
| 74 content::WebContents* web_contents); | |
| 75 | |
| 76 SafeBrowsingNavigationObserver( | |
| 77 content::WebContents* contents, | |
| 78 const scoped_refptr<SafeBrowsingNavigationObserverManager>& manager); | |
| 79 | |
| 80 ~SafeBrowsingNavigationObserver() override; | |
| 81 | |
| 82 private: | |
| 83 typedef std::unordered_map<content::NavigationHandle*, NavigationEvent> | |
| 84 NavigationHandleMap; | |
| 85 | |
| 86 // content::WebContentsObserver: | |
| 87 void DidStartNavigation( | |
| 88 content::NavigationHandle* navigation_handle) override; | |
| 89 void DidRedirectNavigation( | |
| 90 content::NavigationHandle* navigation_handle) override; | |
| 91 void DidFinishNavigation( | |
| 92 content::NavigationHandle* navigation_handle) override; | |
| 93 void DidGetResourceResponseStart( | |
| 94 const content::ResourceRequestDetails& details) override; | |
| 95 void DidGetUserInteraction(const blink::WebInputEvent::Type type) override; | |
| 96 void WebContentsDestroyed() override; | |
| 97 | |
| 98 // Map keyed on NavigationHandle* to keep track of all the ongoing navigation | |
| 99 // events. NavigationHandle pointers are owned by RenderFrameHost. Since a | |
| 100 // NavigationHandle object will be destructed after navigation is done, | |
| 101 // at the end of DidFinishNavigation(...) corresponding entries in this map | |
| 102 // will be removed from navigation_handle_map_ and added to | |
| 103 // SafeBrowsingNavigationObserverManager::navigation_map_. | |
| 104 NavigationHandleMap navigation_handle_map_; | |
| 105 | |
| 106 scoped_refptr<SafeBrowsingNavigationObserverManager> manager_; | |
| 107 | |
| 108 // If the observed WebContents just got an user gesture. | |
| 109 bool has_user_gesture_; | |
| 110 | |
| 111 base::Time last_user_gesture_timestamp_; | |
| 112 | |
| 113 DISALLOW_COPY_AND_ASSIGN(SafeBrowsingNavigationObserver); | |
| 114 }; | |
| 115 | |
| 116 } // namespace safe_browsing | |
| 117 | |
| 118 #endif // CHROME_BROWSER_SAFE_BROWSING_SAFE_BROWSING_NAVIGATION_OBSERVER_H_ | |
| OLD | NEW |