OLD | NEW |
1 // Copyright 2013 The Chromium Authors. All rights reserved. | 1 // Copyright 2013 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/renderer/chrome_render_frame_observer.h" | 5 #include "chrome/renderer/chrome_render_frame_observer.h" |
6 | 6 |
7 #include <limits> | 7 #include <limits> |
8 #include <string> | 8 #include <string> |
9 #include <vector> | 9 #include <vector> |
10 | 10 |
(...skipping 355 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
366 if (frame->parent()) | 366 if (frame->parent()) |
367 return; | 367 return; |
368 | 368 |
369 GURL osdd_url = frame->document().openSearchDescriptionURL(); | 369 GURL osdd_url = frame->document().openSearchDescriptionURL(); |
370 if (!osdd_url.is_empty()) { | 370 if (!osdd_url.is_empty()) { |
371 Send(new ChromeViewHostMsg_PageHasOSDD( | 371 Send(new ChromeViewHostMsg_PageHasOSDD( |
372 routing_id(), frame->document().url(), osdd_url, | 372 routing_id(), frame->document().url(), osdd_url, |
373 search_provider::AUTODETECTED_PROVIDER)); | 373 search_provider::AUTODETECTED_PROVIDER)); |
374 } | 374 } |
375 | 375 |
376 // Don't capture pages including refresh meta tag. | 376 // Don't capture pages that have pending redirect or location change. |
377 if (HasRefreshMetaTag(frame)) | 377 if (frame->isNavigationScheduled()) |
378 return; | 378 return; |
379 | 379 |
380 page_info_.CapturePageInfoLater( | 380 page_info_.CapturePageInfoLater( |
381 FINAL_CAPTURE, render_frame(), | 381 FINAL_CAPTURE, render_frame(), |
382 base::TimeDelta::FromMilliseconds( | 382 base::TimeDelta::FromMilliseconds( |
383 render_frame()->GetRenderView()->GetContentStateImmediately() | 383 render_frame()->GetRenderView()->GetContentStateImmediately() |
384 ? 0 | 384 ? 0 |
385 : kDelayForCaptureMs)); | 385 : kDelayForCaptureMs)); |
386 } | 386 } |
387 | 387 |
388 void ChromeRenderFrameObserver::DidStartProvisionalLoad() { | 388 void ChromeRenderFrameObserver::DidStartProvisionalLoad() { |
389 // Let translate_helper do any preparatory work for loading a URL. | 389 // Let translate_helper do any preparatory work for loading a URL. |
390 if (!translate_helper_) | 390 if (!translate_helper_) |
391 return; | 391 return; |
392 | 392 |
393 translate_helper_->PrepareForUrl( | 393 translate_helper_->PrepareForUrl( |
394 render_frame()->GetWebFrame()->document().url()); | 394 render_frame()->GetWebFrame()->document().url()); |
395 } | 395 } |
396 | 396 |
397 void ChromeRenderFrameObserver::DidCommitProvisionalLoad( | 397 void ChromeRenderFrameObserver::DidCommitProvisionalLoad( |
398 bool is_new_navigation, | 398 bool is_new_navigation, |
399 bool is_same_page_navigation) { | 399 bool is_same_page_navigation) { |
400 WebLocalFrame* frame = render_frame()->GetWebFrame(); | 400 WebLocalFrame* frame = render_frame()->GetWebFrame(); |
401 | 401 |
402 // Don't do anything for subframes. | 402 // Don't do anything for subframes. |
403 if (frame->parent()) | 403 if (frame->parent()) |
404 return; | 404 return; |
405 | 405 |
406 // Don't capture pages being not new, or including refresh meta tag. | 406 // Don't capture pages being not new, with pending redirect, or location |
407 if (!is_new_navigation || HasRefreshMetaTag(frame)) | 407 // change. |
| 408 if (!is_new_navigation || frame->isNavigationScheduled()) |
408 return; | 409 return; |
409 | 410 |
410 base::debug::SetCrashKeyValue( | 411 base::debug::SetCrashKeyValue( |
411 crash_keys::kViewCount, | 412 crash_keys::kViewCount, |
412 base::SizeTToString(content::RenderView::GetRenderViewCount())); | 413 base::SizeTToString(content::RenderView::GetRenderViewCount())); |
413 | 414 |
414 page_info_.CapturePageInfoLater( | 415 page_info_.CapturePageInfoLater( |
415 PRELIMINARY_CAPTURE, render_frame(), | 416 PRELIMINARY_CAPTURE, render_frame(), |
416 base::TimeDelta::FromMilliseconds(kDelayForForcedCaptureMs)); | 417 base::TimeDelta::FromMilliseconds(kDelayForForcedCaptureMs)); |
417 } | 418 } |
418 | 419 |
419 bool ChromeRenderFrameObserver::HasRefreshMetaTag(WebLocalFrame* frame) { | |
420 if (!frame) | |
421 return false; | |
422 WebElement head = frame->document().head(); | |
423 if (head.isNull() || !head.hasChildNodes()) | |
424 return false; | |
425 | |
426 const WebString tag_name(base::ASCIIToUTF16("meta")); | |
427 const WebString attribute_name(base::ASCIIToUTF16("http-equiv")); | |
428 | |
429 WebNodeList children = head.childNodes(); | |
430 for (size_t i = 0; i < children.length(); ++i) { | |
431 WebNode node = children.item(i); | |
432 if (!node.isElementNode()) | |
433 continue; | |
434 WebElement element = node.to<WebElement>(); | |
435 if (!element.hasHTMLTagName(tag_name)) | |
436 continue; | |
437 WebString value = element.getAttribute(attribute_name); | |
438 if (value.isNull() || | |
439 !base::LowerCaseEqualsASCII(base::StringPiece16(value), "refresh")) | |
440 continue; | |
441 return true; | |
442 } | |
443 return false; | |
444 } | |
445 | |
446 void ChromeRenderFrameObserver::PageCaptured(base::string16* content, | 420 void ChromeRenderFrameObserver::PageCaptured(base::string16* content, |
447 CaptureType capture_type) { | 421 CaptureType capture_type) { |
448 if (translate_helper_) | 422 if (translate_helper_) |
449 translate_helper_->PageCaptured(*content); | 423 translate_helper_->PageCaptured(*content); |
450 | 424 |
451 TRACE_EVENT0("renderer", "ChromeRenderViewObserver::CapturePageInfo"); | 425 TRACE_EVENT0("renderer", "ChromeRenderViewObserver::CapturePageInfo"); |
452 | 426 |
453 #if defined(FULL_SAFE_BROWSING) | 427 #if defined(FULL_SAFE_BROWSING) |
454 // Will swap out the string. | 428 // Will swap out the string. |
455 if (phishing_classifier_) | 429 if (phishing_classifier_) |
456 phishing_classifier_->PageCaptured(content, | 430 phishing_classifier_->PageCaptured(content, |
457 capture_type == PRELIMINARY_CAPTURE); | 431 capture_type == PRELIMINARY_CAPTURE); |
458 #endif | 432 #endif |
459 } | 433 } |
OLD | NEW |