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

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: resolve final nit 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 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
40 // different from initial_request_url.
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 int target_tab_id; // Which tab this request url is targeting to.
46 int frame_id; // Frame tree node ID of the frame where this navigation takes
47 // place.
48 base::Time last_updated; // When this NavigationEvent was last updated.
49 bool is_user_initiated; // browser_initiated || has_user_gesture.
50 bool has_committed;
51 bool has_server_redirect;
52 };
53
54 // Structure to keep track of resolved IP address of a host.
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 // at the end of DidFinishNavigation(...) corresponding entries in this map
98 // will be removed from navigation_handle_map_ and added to
99 // SafeBrowsingNavigationObserverManager::navigation_map_.
100 NavigationHandleMap navigation_handle_map_;
101
102 scoped_refptr<SafeBrowsingNavigationObserverManager> manager_;
103
104 // If the observed WebContents just got an user gesture.
105 bool has_user_gesture_;
106
107 base::Time last_user_gesture_timestamp_;
108
109 DISALLOW_COPY_AND_ASSIGN(SafeBrowsingNavigationObserver);
110 };
111
112 } // namespace safe_browsing
113
114 #endif // CHROME_BROWSER_SAFE_BROWSING_SAFE_BROWSING_NAVIGATION_OBSERVER_H_
OLDNEW
« no previous file with comments | « chrome/browser/BUILD.gn ('k') | chrome/browser/safe_browsing/safe_browsing_navigation_observer.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698