OLD | NEW |
---|---|
1 // Copyright (c) 2010 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2010 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 // Web progress notifier implementation. | 5 // Web progress notifier implementation. |
6 #include "ceee/ie/plugin/bho/web_progress_notifier.h" | 6 #include "ceee/ie/plugin/bho/web_progress_notifier.h" |
7 | 7 |
8 #include "base/logging.h" | 8 #include "base/logging.h" |
9 #include "base/string_util.h" | 9 #include "base/string_util.h" |
10 #include "ceee/common/com_utils.h" | 10 #include "ceee/common/com_utils.h" |
11 #include "ceee/ie/plugin/bho/dom_utils.h" | 11 #include "ceee/ie/plugin/bho/dom_utils.h" |
12 #include "ceee/ie/plugin/bho/webnavigation_events_funnel.h" | |
12 | 13 |
13 namespace { | 14 namespace { |
14 | 15 |
15 // In milliseconds. It defines the "effective period" of user action. A user | 16 // In milliseconds. It defines the "effective period" of user action. A user |
16 // action is considered as a possible cause of the next navigation if the | 17 // action is considered as a possible cause of the next navigation if the |
17 // navigation happens in this period. | 18 // navigation happens in this period. |
18 // This is a number we feel confident of based on past experience. | 19 // This is a number we feel confident of based on past experience. |
19 const int kUserActionTimeThresholdMs = 500; | 20 const int kUserActionTimeThresholdMs = 500; |
20 | 21 |
21 // String constants for the values of TransitionQualifier. | 22 // String constants for the values of TransitionQualifier. |
(...skipping 92 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
114 return; | 115 return; |
115 | 116 |
116 if (FilterOutWebBrowserEvent(browser, FilteringInfo::BEFORE_NAVIGATE)) | 117 if (FilterOutWebBrowserEvent(browser, FilteringInfo::BEFORE_NAVIGATE)) |
117 return; | 118 return; |
118 | 119 |
119 FrameInfo* frame_info = NULL; | 120 FrameInfo* frame_info = NULL; |
120 if (!GetFrameInfo(browser, &frame_info)) | 121 if (!GetFrameInfo(browser, &frame_info)) |
121 return; | 122 return; |
122 | 123 |
123 // TODO(yzshen@google.com): add support for requestId. | 124 // TODO(yzshen@google.com): add support for requestId. |
124 HRESULT hr = webnavigation_events_funnel().OnBeforeNavigate( | 125 HRESULT hr = E_POINTER; |
125 tab_handle_, url, frame_info->frame_id, -1, base::Time::Now()); | 126 WebNavigationEventsFunnel* funel = webnavigation_events_funnel(); |
Sigurður Ásgeirsson
2010/11/19 20:53:20
nit: funel -> funnel
| |
127 DCHECK(funel != NULL); | |
128 if (funel) { | |
129 hr = funel->OnBeforeNavigate(tab_handle_, url, frame_info->frame_id, -1, | |
130 base::Time::Now()); | |
131 } | |
126 DCHECK(SUCCEEDED(hr)) | 132 DCHECK(SUCCEEDED(hr)) |
127 << "Failed to fire the webNavigation.onBeforeNavigate event " | 133 << "Failed to fire the webNavigation.onBeforeNavigate event " |
128 << com::LogHr(hr); | 134 << com::LogHr(hr); |
129 | 135 |
130 if (frame_info->IsMainFrame()) { | 136 if (frame_info->IsMainFrame()) { |
131 frame_info->ClearTransition(); | 137 frame_info->ClearTransition(); |
132 | 138 |
133 // The order in which we set these transitions is **very important.** | 139 // The order in which we set these transitions is **very important.** |
134 // If there was no DocumentComplete, then there are two likely options: | 140 // If there was no DocumentComplete, then there are two likely options: |
135 // the transition was a JavaScript redirect, or the user navigated to a | 141 // the transition was a JavaScript redirect, or the user navigated to a |
(...skipping 47 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
183 if (!GetFrameInfo(browser, &frame_info)) | 189 if (!GetFrameInfo(browser, &frame_info)) |
184 return; | 190 return; |
185 | 191 |
186 if (frame_info->IsMainFrame()) { | 192 if (frame_info->IsMainFrame()) { |
187 main_frame_document_complete_ = true; | 193 main_frame_document_complete_ = true; |
188 | 194 |
189 has_potential_javascript_redirect_ = | 195 has_potential_javascript_redirect_ = |
190 HasPotentialJavaScriptRedirect(browser); | 196 HasPotentialJavaScriptRedirect(browser); |
191 } | 197 } |
192 | 198 |
193 HRESULT hr = webnavigation_events_funnel().OnCompleted( | 199 HRESULT hr = E_POINTER; |
194 tab_handle_, url, frame_info->frame_id, base::Time::Now()); | 200 WebNavigationEventsFunnel* funel = webnavigation_events_funnel(); |
Sigurður Ásgeirsson
2010/11/19 20:53:20
ditto.
Vitaly Buka corp
2010/11/19 21:21:28
Done.
| |
201 DCHECK(funel != NULL); | |
202 if (funel) { | |
203 hr = funel->OnCompleted(tab_handle_, url, frame_info->frame_id, | |
204 base::Time::Now()); | |
205 } | |
195 DCHECK(SUCCEEDED(hr)) << "Failed to fire the webNavigation.onCompleted event " | 206 DCHECK(SUCCEEDED(hr)) << "Failed to fire the webNavigation.onCompleted event " |
196 << com::LogHr(hr); | 207 << com::LogHr(hr); |
197 } | 208 } |
198 | 209 |
199 void WebProgressNotifier::OnNavigateComplete(IWebBrowser2* browser, BSTR url) { | 210 void WebProgressNotifier::OnNavigateComplete(IWebBrowser2* browser, BSTR url) { |
200 if (browser == NULL || url == NULL) | 211 if (browser == NULL || url == NULL) |
201 return; | 212 return; |
202 | 213 |
203 if (FilterOutWebBrowserEvent(browser, FilteringInfo::NAVIGATE_COMPLETE)) { | 214 if (FilterOutWebBrowserEvent(browser, FilteringInfo::NAVIGATE_COMPLETE)) { |
204 filtering_info_.pending_navigate_complete_browser = browser; | 215 filtering_info_.pending_navigate_complete_browser = browser; |
(...skipping 18 matching lines...) Expand all Loading... | |
223 return; | 234 return; |
224 | 235 |
225 if (frame_info->IsMainFrame()) { | 236 if (frame_info->IsMainFrame()) { |
226 main_frame_document_complete_ = false; | 237 main_frame_document_complete_ = false; |
227 | 238 |
228 if (IsForwardBack(url)) { | 239 if (IsForwardBack(url)) { |
229 frame_info->SetTransition(PageTransition::AUTO_BOOKMARK, FORWARD_BACK); | 240 frame_info->SetTransition(PageTransition::AUTO_BOOKMARK, FORWARD_BACK); |
230 } | 241 } |
231 } | 242 } |
232 | 243 |
233 HRESULT hr = webnavigation_events_funnel().OnCommitted( | 244 HRESULT hr = E_POINTER; |
245 WebNavigationEventsFunnel* funel = webnavigation_events_funnel(); | |
246 DCHECK(funel != NULL); | |
247 if (funel) { | |
248 hr = funel->OnCommitted( | |
234 tab_handle_, url, frame_info->frame_id, | 249 tab_handle_, url, frame_info->frame_id, |
235 PageTransition::CoreTransitionString(frame_info->transition_type), | 250 PageTransition::CoreTransitionString(frame_info->transition_type), |
236 TransitionQualifiersString(frame_info->transition_qualifiers).c_str(), | 251 TransitionQualifiersString(frame_info->transition_qualifiers).c_str(), |
237 timestamp); | 252 timestamp); |
253 } | |
238 DCHECK(SUCCEEDED(hr)) << "Failed to fire the webNavigation.onCommitted event " | 254 DCHECK(SUCCEEDED(hr)) << "Failed to fire the webNavigation.onCommitted event " |
239 << com::LogHr(hr); | 255 << com::LogHr(hr); |
240 | 256 |
241 if (frame_info->IsMainFrame()) | 257 if (frame_info->IsMainFrame()) |
242 subframe_map_.clear(); | 258 subframe_map_.clear(); |
243 } | 259 } |
244 | 260 |
245 void WebProgressNotifier::OnNavigateError(IWebBrowser2* browser, BSTR url, | 261 void WebProgressNotifier::OnNavigateError(IWebBrowser2* browser, BSTR url, |
246 long status_code) { | 262 long status_code) { |
247 if (browser == NULL || url == NULL) | 263 if (browser == NULL || url == NULL) |
248 return; | 264 return; |
249 | 265 |
250 if (FilterOutWebBrowserEvent(browser, FilteringInfo::NAVIGATE_ERROR)) | 266 if (FilterOutWebBrowserEvent(browser, FilteringInfo::NAVIGATE_ERROR)) |
251 return; | 267 return; |
252 | 268 |
253 FrameInfo* frame_info = NULL; | 269 FrameInfo* frame_info = NULL; |
254 if (!GetFrameInfo(browser, &frame_info)) | 270 if (!GetFrameInfo(browser, &frame_info)) |
255 return; | 271 return; |
256 | 272 |
257 HRESULT hr = webnavigation_events_funnel().OnErrorOccurred( | 273 HRESULT hr = E_POINTER; |
258 tab_handle_, url, frame_info->frame_id, CComBSTR(L""), base::Time::Now()); | 274 WebNavigationEventsFunnel* funel = webnavigation_events_funnel(); |
Sigurður Ásgeirsson
2010/11/19 20:53:20
et al.
| |
275 DCHECK(funel != NULL); | |
276 if (funel) { | |
277 hr = funel->OnErrorOccurred(tab_handle_, url, | |
278 frame_info->frame_id, CComBSTR(L""), base::Time::Now()); | |
279 } | |
259 DCHECK(SUCCEEDED(hr)) | 280 DCHECK(SUCCEEDED(hr)) |
260 << "Failed to fire the webNavigation.onErrorOccurred event " | 281 << "Failed to fire the webNavigation.onErrorOccurred event " |
261 << com::LogHr(hr); | 282 << com::LogHr(hr); |
262 } | 283 } |
263 | 284 |
264 void WebProgressNotifier::OnNewWindow(BSTR url_context, BSTR url) { | 285 void WebProgressNotifier::OnNewWindow(BSTR url_context, BSTR url) { |
265 if (url_context == NULL || url == NULL) | 286 if (url_context == NULL || url == NULL) |
266 return; | 287 return; |
267 | 288 |
268 if (FilterOutWebBrowserEvent(NULL, FilteringInfo::NEW_WINDOW)) | 289 if (FilterOutWebBrowserEvent(NULL, FilteringInfo::NEW_WINDOW)) |
269 return; | 290 return; |
270 | 291 |
271 HRESULT hr = webnavigation_events_funnel().OnBeforeRetarget( | 292 HRESULT hr = E_POINTER; |
272 tab_handle_, url_context, url, base::Time::Now()); | 293 WebNavigationEventsFunnel* funel = webnavigation_events_funnel(); |
294 DCHECK(funel != NULL); | |
295 if (funel) { | |
296 hr = funel->OnBeforeRetarget(tab_handle_, url_context, url, | |
297 base::Time::Now()); | |
298 } | |
273 DCHECK(SUCCEEDED(hr)) | 299 DCHECK(SUCCEEDED(hr)) |
274 << "Failed to fire the webNavigation.onBeforeRetarget event " | 300 << "Failed to fire the webNavigation.onBeforeRetarget event " |
275 << com::LogHr(hr); | 301 << com::LogHr(hr); |
276 } | 302 } |
277 | 303 |
278 void WebProgressNotifier::OnHandleMessage( | 304 void WebProgressNotifier::OnHandleMessage( |
279 WindowMessageSource::MessageType type, | 305 WindowMessageSource::MessageType type, |
280 const MSG* message_info) { | 306 const MSG* message_info) { |
281 DCHECK(create_thread_id_ == ::GetCurrentThreadId()); | 307 DCHECK(create_thread_id_ == ::GetCurrentThreadId()); |
282 | 308 |
(...skipping 15 matching lines...) Expand all Loading... | |
298 } | 324 } |
299 break; | 325 break; |
300 } | 326 } |
301 default: { | 327 default: { |
302 NOTREACHED(); | 328 NOTREACHED(); |
303 break; | 329 break; |
304 } | 330 } |
305 } | 331 } |
306 } | 332 } |
307 | 333 |
334 WebNavigationEventsFunnel* WebProgressNotifier::webnavigation_events_funnel() { | |
335 if (!webnavigation_events_funnel_.get()) | |
336 webnavigation_events_funnel_.reset(new WebNavigationEventsFunnel()); | |
337 return webnavigation_events_funnel_.get(); | |
338 } | |
339 | |
340 WebRequestNotifier* WebProgressNotifier::webrequest_notifier() { | |
341 if (cached_webrequest_notifier_ == NULL) { | |
342 cached_webrequest_notifier_ = ProductionWebRequestNotifier::get(); | |
343 } | |
344 return cached_webrequest_notifier_; | |
345 } | |
346 | |
308 WindowMessageSource* WebProgressNotifier::CreateWindowMessageSource() { | 347 WindowMessageSource* WebProgressNotifier::CreateWindowMessageSource() { |
309 scoped_ptr<WindowMessageSource> source(new WindowMessageSource()); | 348 scoped_ptr<WindowMessageSource> source(new WindowMessageSource()); |
310 | 349 |
311 return source->Initialize() ? source.release() : NULL; | 350 return source->Initialize() ? source.release() : NULL; |
312 } | 351 } |
313 | 352 |
314 std::string WebProgressNotifier::TransitionQualifiersString( | 353 std::string WebProgressNotifier::TransitionQualifiersString( |
315 TransitionQualifiers qualifiers) { | 354 TransitionQualifiers qualifiers) { |
316 std::string result; | 355 std::string result; |
317 for (unsigned int current_qualifier = FIRST_TRANSITION_QUALIFIER; | 356 for (unsigned int current_qualifier = FIRST_TRANSITION_QUALIFIER; |
(...skipping 327 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
645 break; | 684 break; |
646 } | 685 } |
647 default: { | 686 default: { |
648 NOTREACHED() << "Unknown state type."; | 687 NOTREACHED() << "Unknown state type."; |
649 break; | 688 break; |
650 } | 689 } |
651 } | 690 } |
652 } | 691 } |
653 return false; | 692 return false; |
654 } | 693 } |
OLD | NEW |