| 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. |
| 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 |
| 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 |
| 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. |
| 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 |
| 50 // chain. In the absence of server redirect, this |
| 51 // field will be empty. |
| 52 }; |
| 53 |
| 54 // Observes the navigation events for a single WebContents (both main-frame |
| 55 // and sub-frame navigations) |
| 56 class SafeBrowsingNavigationObserver : public base::SupportsUserData::Data, |
| 57 public content::WebContentsObserver { |
| 58 public: |
| 59 static void MaybeCreateForWebContents(content::WebContents* web_contents); |
| 60 static SafeBrowsingNavigationObserver* FromWebContents( |
| 61 content::WebContents* web_contents); |
| 62 |
| 63 SafeBrowsingNavigationObserver( |
| 64 content::WebContents* contents, |
| 65 const scoped_refptr<SafeBrowsingNavigationObserverManager>& manager); |
| 66 |
| 67 ~SafeBrowsingNavigationObserver() override; |
| 68 |
| 69 private: |
| 70 typedef std::unordered_map<content::NavigationHandle*, NavigationEvent> |
| 71 NavigationHandleMap; |
| 72 |
| 73 // content::WebContentsObserver: |
| 74 void DidStartNavigation( |
| 75 content::NavigationHandle* navigation_handle) override; |
| 76 void DidRedirectNavigation( |
| 77 content::NavigationHandle* navigation_handle) override; |
| 78 void DidFinishNavigation( |
| 79 content::NavigationHandle* navigation_handle) override; |
| 80 void DidGetUserInteraction(const blink::WebInputEvent::Type type) override; |
| 81 void WebContentsDestroyed() override; |
| 82 |
| 83 // Map keyed on NavigationHandle* to keep track of all the ongoing navigation |
| 84 // events. NavigationHandle pointers are owned by RenderFrameHost. Since a |
| 85 // NavigationHandle object will be destructed after navigation is done, |
| 86 // corresponding entry in this map will be removed from navigation_handle_map_ |
| 87 // and added to navigation_map_ at the end of DidFinishNavigation(...). |
| 88 NavigationHandleMap navigation_handle_map_; |
| 89 scoped_refptr<SafeBrowsingNavigationObserverManager> manager_; |
| 90 // If the observed WebContents just got an user gesture. |
| 91 bool has_user_gesture_; |
| 92 base::Time last_user_gesture_timestamp_; |
| 93 DISALLOW_COPY_AND_ASSIGN(SafeBrowsingNavigationObserver); |
| 94 }; |
| 95 |
| 96 } // namespace safe_browsing |
| 97 |
| 98 #endif // CHROME_BROWSER_SAFE_BROWSING_SAFE_BROWSING_NAVIGATION_OBSERVER_H_ |
| OLD | NEW |