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

Unified Diff: chrome/renderer/chrome_render_frame_observer.cc

Issue 1398823004: Switch the page-capturing machinery to use the new hooks. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 5 years, 2 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/renderer/chrome_render_frame_observer.cc
diff --git a/chrome/renderer/chrome_render_frame_observer.cc b/chrome/renderer/chrome_render_frame_observer.cc
index 6f71da98b5d9fbd79ad933b15c6c5ddf2c62cd8c..ac78d742afaf106dd5e959220eb58419e3072560 100644
--- a/chrome/renderer/chrome_render_frame_observer.cc
+++ b/chrome/renderer/chrome_render_frame_observer.cc
@@ -49,14 +49,14 @@ using blink::WebString;
using content::SSLStatus;
using content::RenderFrame;
-// Delay in milliseconds that we'll wait before capturing the page contents.
-static const int kDelayForCaptureMs = 500;
+// // Delay in milliseconds that we'll wait before capturing the page contents.
+// static const int kDelayForCaptureMs = 500;
// Typically, we capture the page data once the page is loaded.
// Sometimes, the page never finishes to load, preventing the page capture
// To workaround this problem, we always perform a capture after the following
// delay.
-static const int kDelayForForcedCaptureMs = 6000;
+// static const int kDelayForForcedCaptureMs = 6000;
// Maximum number of characters in the document to index.
// Any text beyond this point will be clipped.
@@ -110,15 +110,15 @@ PageInfo::PageInfo(PageInfoReceiver* context)
DCHECK(context_);
}
-// TODO(dglazkov): Refactor to remove the RenderFrame* argument.
-void PageInfo::CapturePageInfoLater(CaptureType capture_type,
- RenderFrame* render_frame,
- base::TimeDelta delay) {
- capture_timer_.Start(
- FROM_HERE, delay,
- base::Bind(&PageInfo::CapturePageInfo, base::Unretained(this),
- render_frame, capture_type));
-}
+// // TODO(dglazkov): Refactor to remove the RenderFrame* argument.
+// void PageInfo::CapturePageInfoLater(CaptureType capture_type,
+// RenderFrame* render_frame,
+// base::TimeDelta delay) {
+// capture_timer_.Start(
+// FROM_HERE, delay,
+// base::Bind(&PageInfo::CapturePageInfo, base::Unretained(this),
+// render_frame, capture_type));
+// }
bool PageInfo::IsErrorPage(WebLocalFrame* frame) {
WebDataSource* ds = frame->dataSource();
@@ -134,6 +134,10 @@ void PageInfo::CapturePageInfo(RenderFrame* render_frame,
if (!frame)
return;
+ // Don't capture pages that have pending redirect or location change.
+ if (frame->isNavigationScheduled())
+ return;
+
// Don't index/capture pages that are in view source mode.
if (frame->isViewSourceModeEnabled())
return;
@@ -373,16 +377,11 @@ void ChromeRenderFrameObserver::DidFinishLoad() {
search_provider::AUTODETECTED_PROVIDER));
}
- // Don't capture pages that have pending redirect or location change.
- if (frame->isNavigationScheduled())
- return;
-
- page_info_.CapturePageInfoLater(
- FINAL_CAPTURE, render_frame(),
- base::TimeDelta::FromMilliseconds(
- render_frame()->GetRenderView()->GetContentStateImmediately()
- ? 0
- : kDelayForCaptureMs));
+ // // TODO(dglazkov): This is only necessary for testing and indicates that
+ // // the tests that rely on this specific timing need to be rewritten to
+ // // avoid this kludge.
+ // if (render_frame()->GetRenderView()->GetContentStateImmediately()) {
+ // page_info_.CapturePageInfo(render_frame(), FINAL_CAPTURE);
}
void ChromeRenderFrameObserver::DidStartProvisionalLoad() {
@@ -403,31 +402,41 @@ void ChromeRenderFrameObserver::DidCommitProvisionalLoad(
if (frame->parent())
return;
- // Don't capture pages being not new, with pending redirect, or location
- // change.
- if (!is_new_navigation || frame->isNavigationScheduled())
- return;
+ // // Don't capture pages being not new, with pending redirect, or location
+ // // change.
+ // if (!is_new_navigation || frame->isNavigationScheduled())
+ // return;
base::debug::SetCrashKeyValue(
crash_keys::kViewCount,
base::SizeTToString(content::RenderView::GetRenderViewCount()));
+}
- page_info_.CapturePageInfoLater(
- PRELIMINARY_CAPTURE, render_frame(),
- base::TimeDelta::FromMilliseconds(kDelayForForcedCaptureMs));
+void ChromeRenderFrameObserver::DidMeaningfulLayout(
+ blink::WebMeaningfulLayout layout_type) {
+ switch (layout_type) {
+ case blink::WebMeaningfulLayout::FinishedParsing:
+ page_info_.CapturePageInfo(render_frame(), PRELIMINARY_CAPTURE);
+ break;
+ case blink::WebMeaningfulLayout::FinishedLoading:
+ page_info_.CapturePageInfo(render_frame(), FINAL_CAPTURE);
+ break;
+ default:
+ break;
+ }
}
void ChromeRenderFrameObserver::PageCaptured(base::string16* content,
CaptureType capture_type) {
- if (translate_helper_)
+ bool is_preliminary_capture = capture_type == PRELIMINARY_CAPTURE;
+ if (translate_helper_ && is_preliminary_capture)
translate_helper_->PageCaptured(*content);
- TRACE_EVENT0("renderer", "ChromeRenderViewObserver::CapturePageInfo");
+ TRACE_EVENT0("renderer", "ChromeRenderFrameObserver::CapturePageInfo");
#if defined(FULL_SAFE_BROWSING)
// Will swap out the string.
if (phishing_classifier_)
- phishing_classifier_->PageCaptured(content,
- capture_type == PRELIMINARY_CAPTURE);
+ phishing_classifier_->PageCaptured(content, is_preliminary_capture);
#endif
}

Powered by Google App Engine
This is Rietveld 408576698