OLD | NEW |
---|---|
1 // Copyright 2016 The Chromium Authors. All rights reserved. | 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 | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 | 4 |
5 #include "chrome/browser/safe_browsing/safe_browsing_navigation_observer.h" | 5 #include "chrome/browser/safe_browsing/safe_browsing_navigation_observer.h" |
6 | 6 |
7 #include "base/memory/ptr_util.h" | 7 #include "base/memory/ptr_util.h" |
8 #include "base/time/time.h" | 8 #include "base/time/time.h" |
9 #include "chrome/browser/safe_browsing/safe_browsing_navigation_observer_manager .h" | 9 #include "chrome/browser/safe_browsing/safe_browsing_navigation_observer_manager .h" |
10 #include "chrome/browser/sessions/session_tab_helper.h" | 10 #include "chrome/browser/sessions/session_tab_helper.h" |
(...skipping 52 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
63 has_committed = nav_event.has_committed; | 63 has_committed = nav_event.has_committed; |
64 has_server_redirect = nav_event.has_server_redirect; | 64 has_server_redirect = nav_event.has_server_redirect; |
65 return *this; | 65 return *this; |
66 } | 66 } |
67 | 67 |
68 NavigationEvent::~NavigationEvent() {} | 68 NavigationEvent::~NavigationEvent() {} |
69 | 69 |
70 // SafeBrowsingNavigationObserver -------------------------------------------- | 70 // SafeBrowsingNavigationObserver -------------------------------------------- |
71 | 71 |
72 // static | 72 // static |
73 void SafeBrowsingNavigationObserver::MaybeCreateForWebContents( | 73 void SafeBrowsingNavigationObserver::CreateForWebContents( |
74 content::WebContents* web_contents) { | 74 content::WebContents* web_contents, |
75 if (FromWebContents(web_contents)) | 75 const scoped_refptr<SafeBrowsingNavigationObserverManager>& manager) { |
76 return; | 76 if (!FromWebContents(web_contents)) { |
77 // TODO(jialiul): This method will be called by TabHelpers::AttachTabHelpers. | 77 web_contents->SetUserData( |
78 // Complete this method when the entire class is ready. | 78 kWebContentsUserDataKey, |
79 NOTIMPLEMENTED(); | 79 new SafeBrowsingNavigationObserver(web_contents, manager)); |
80 } | |
80 } | 81 } |
81 | 82 |
82 // static | 83 // static |
83 SafeBrowsingNavigationObserver* SafeBrowsingNavigationObserver::FromWebContents( | 84 SafeBrowsingNavigationObserver* SafeBrowsingNavigationObserver::FromWebContents( |
84 content::WebContents* web_contents) { | 85 content::WebContents* web_contents) { |
85 return static_cast<SafeBrowsingNavigationObserver*>( | 86 return static_cast<SafeBrowsingNavigationObserver*>( |
86 web_contents->GetUserData(kWebContentsUserDataKey)); | 87 web_contents->GetUserData(kWebContentsUserDataKey)); |
87 } | 88 } |
88 | 89 |
89 SafeBrowsingNavigationObserver::SafeBrowsingNavigationObserver( | 90 SafeBrowsingNavigationObserver::SafeBrowsingNavigationObserver( |
(...skipping 18 matching lines...) Expand all Loading... | |
108 // we need to copy the is_user_initiated field. | 109 // we need to copy the is_user_initiated field. |
109 if (it != navigation_handle_map_.end()) { | 110 if (it != navigation_handle_map_.end()) { |
110 nav_event.is_user_initiated = it->second.is_user_initiated; | 111 nav_event.is_user_initiated = it->second.is_user_initiated; |
111 } else { | 112 } else { |
112 // If this is the first time we see this navigation_handle, create a new | 113 // If this is the first time we see this navigation_handle, create a new |
113 // NavigationEvent, and decide if it is triggered by user. | 114 // NavigationEvent, and decide if it is triggered by user. |
114 if ((has_user_gesture_ && | 115 if ((has_user_gesture_ && |
115 !SafeBrowsingNavigationObserverManager::IsUserGestureExpired( | 116 !SafeBrowsingNavigationObserverManager::IsUserGestureExpired( |
116 last_user_gesture_timestamp_)) || | 117 last_user_gesture_timestamp_)) || |
117 !navigation_handle->IsRendererInitiated()) { | 118 !navigation_handle->IsRendererInitiated()) { |
118 nav_event.is_user_initiated = has_user_gesture_; | 119 nav_event.is_user_initiated = true; |
119 manager_->OnUserGestureConsumed(web_contents(), | 120 if (has_user_gesture_) { |
120 last_user_gesture_timestamp_); | 121 manager_->OnUserGestureConsumed(web_contents(), |
122 last_user_gesture_timestamp_); | |
123 has_user_gesture_ = false; | |
Nathan Parker
2016/12/20 01:01:33
So this consumes the user gesture only if there re
Jialiu Lin
2016/12/20 02:07:51
Yes. That's correct.
| |
124 } | |
121 } | 125 } |
122 has_user_gesture_ = false; | |
123 } | 126 } |
124 | 127 |
125 // All the other fields are reconstructed based on current content of | 128 // All the other fields are reconstructed based on current content of |
126 // navigation_handle. | 129 // navigation_handle. |
127 nav_event.frame_id = navigation_handle->GetFrameTreeNodeId(); | 130 nav_event.frame_id = navigation_handle->GetFrameTreeNodeId(); |
128 | 131 |
129 // If there was a URL previously committed in the current RenderFrameHost, | 132 // If there was a URL previously committed in the current RenderFrameHost, |
130 // set it as the source url of this navigation. Otherwise, this is the | 133 // set it as the source url of this navigation. Otherwise, this is the |
131 // first url going to commit in this frame. We set navigation_handle's URL as | 134 // first url going to commit in this frame. We set navigation_handle's URL as |
132 // the source url. | 135 // the source url. |
(...skipping 94 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
227 last_user_gesture_timestamp_); | 230 last_user_gesture_timestamp_); |
228 } | 231 } |
229 | 232 |
230 void SafeBrowsingNavigationObserver::WebContentsDestroyed() { | 233 void SafeBrowsingNavigationObserver::WebContentsDestroyed() { |
231 manager_->OnWebContentDestroyed(web_contents()); | 234 manager_->OnWebContentDestroyed(web_contents()); |
232 web_contents()->RemoveUserData(kWebContentsUserDataKey); | 235 web_contents()->RemoveUserData(kWebContentsUserDataKey); |
233 // web_contents is null after this function. | 236 // web_contents is null after this function. |
234 } | 237 } |
235 | 238 |
236 } // namespace safe_browsing | 239 } // namespace safe_browsing |
OLD | NEW |