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

Unified Diff: chrome/browser/safe_browsing/safe_browsing_navigation_observer.h

Issue 2302913003: Add SafeBrowsingNavigationObserver to listen to navigation events (Closed)
Patch Set: disable DownloadViaHTML5FileApi due to flackiness Created 4 years, 3 months 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 side-by-side diff with in-line comments
Download patch
Index: chrome/browser/safe_browsing/safe_browsing_navigation_observer.h
diff --git a/chrome/browser/safe_browsing/safe_browsing_navigation_observer.h b/chrome/browser/safe_browsing/safe_browsing_navigation_observer.h
new file mode 100644
index 0000000000000000000000000000000000000000..07a98b16e0e7bc440a3fb6c910c16e3d605f9cbf
--- /dev/null
+++ b/chrome/browser/safe_browsing/safe_browsing_navigation_observer.h
@@ -0,0 +1,104 @@
+// Copyright 2016 The Chromium Authors. All rights reserved.
+// Use of this source code is governed by a BSD-style license that can be
+// found in the LICENSE file.
+#ifndef CHROME_BROWSER_SAFE_BROWSING_SAFE_BROWSING_NAVIGATION_OBSERVER_H_
+#define CHROME_BROWSER_SAFE_BROWSING_SAFE_BROWSING_NAVIGATION_OBSERVER_H_
+
+#include "content/public/browser/navigation_handle.h"
+#include "content/public/browser/notification_observer.h"
+#include "content/public/browser/notification_registrar.h"
+#include "content/public/browser/web_contents_observer.h"
+#include "url/gurl.h"
+
+struct RetargetingDetails;
+
+namespace content {
+class NavigationHandle;
+class NotificationRegistrar;
+class RenderFrameHost;
+struct ResourceRedirectDetails;
+}
+
+namespace safe_browsing {
+
+// Observes the navigation events that might lead to a download.
+class SafeBrowsingNavigationObserver : public content::NotificationObserver,
+ public content::WebContentsObserver {
+ public:
+ struct NavigationEvent {
+ NavigationEvent();
+ NavigationEvent(const GURL& source_url,
Nathan Parker 2016/09/03 00:21:35 Is there away to avoid the many-args-of-similar-ty
Jialiu Lin 2016/09/07 00:42:41 Agree. Removed this constructor.
+ int source_tab_id,
+ const GURL& target_url,
+ int target_tab_id,
+ int frame_id,
+ const GURL& main_frame_url,
+ double timestamp,
+ bool has_user_gesture,
+ bool has_committed);
+ explicit NavigationEvent(const NavigationEvent& nav_event);
+ ~NavigationEvent();
+ GURL source_url;
+ int source_tab_id;
+
+ GURL target_url;
+ int target_tab_id;
+
+ int frame_id; // Frame tree node id.
+ GURL main_frame_url; // Main frame url of the source.
+
+ double timestamp; // Timestamp of last time this object is updated.
+
+ bool is_user_initiated;
+ bool has_committed;
+ bool is_server_redirect;
Nathan Parker 2016/09/03 00:21:35 It's is possible for is_user_initiated and is_serv
Jialiu Lin 2016/09/07 00:42:41 Yes, it's possible. User clicks on a link (url_a),
+ bool is_finished;
+ GURL server_redirect_url;
+ };
+
+ // NavigationMap keyed on target url.
+ typedef std::map<GURL, std::vector<NavigationEvent>> NavigationMap;
+ typedef std::map<content::NavigationHandle*, NavigationEvent>
Nathan Parker 2016/09/03 00:21:35 Who owns these pointers? Add a comment, or down be
Jialiu Lin 2016/09/07 00:42:41 done.
+ NavigationHandleMap;
+
+ SafeBrowsingNavigationObserver();
+
+ ~SafeBrowsingNavigationObserver() override;
+
+ NavigationMap* navigation_map();
+
+ void ClearNavigationMap();
+
+ // TODO(jialiul): more functions coming for managing navigation_map_.
+
+ protected:
+ void RecordNavigationPendingEntry(
+ const content::NotificationSource& source,
+ const content::NotificationDetails& details);
+
+ void RecordRetargeting(const content::NotificationDetails& details);
Nathan Parker 2016/09/03 00:21:35 What does retargeting mean?
Jialiu Lin 2016/09/07 00:42:41 Retargeting means navigation triggered in one tab
+
+ // content::NotificationObserver:
+ void Observe(int type,
+ const content::NotificationSource& source,
+ const content::NotificationDetails& details) override;
+
+ // content::WebContentsObserver:
+ void DidStartNavigation(
+ content::NavigationHandle* navigation_handle) override;
+
+ void DidRedirectNavigation(
+ content::NavigationHandle* navigation_handle) override;
+
+ void DidFinishNavigation(
+ content::NavigationHandle* navigation_handle) override;
+
+ NavigationHandleMap navigation_handle_map_;
Nathan Parker 2016/09/03 00:21:35 Add some comments on what these are used for, or h
Jialiu Lin 2016/09/07 00:42:41 done.
+ content::NotificationRegistrar registrar_;
+ NavigationMap navigation_map_;
+ DISALLOW_COPY_AND_ASSIGN(SafeBrowsingNavigationObserver);
+};
+
+} // namespace safe_browsing
+
+#endif // CHROME_BROWSER_SAFE_BROWSING_SAFE_BROWSING_NAVIGATION_OBSERVER_H_

Powered by Google App Engine
This is Rietveld 408576698