Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(492)

Side by Side Diff: chrome/browser/safe_browsing/safe_browsing_navigation_observer.h

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

Powered by Google App Engine
This is Rietveld 408576698