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

Side by Side Diff: chrome/renderer/chrome_render_frame_observer.cc

Issue 1774663002: Teach CRFO:CapturePageText to recognize page refreshes with long delays. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Addressed nits. Created 4 years, 9 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 unified diff | Download patch
OLDNEW
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 <stddef.h> 7 #include <stddef.h>
8 8
9 #include <limits> 9 #include <limits>
10 #include <string> 10 #include <string>
(...skipping 46 matching lines...) Expand 10 before | Expand all | Expand 10 after
57 using content::SSLStatus; 57 using content::SSLStatus;
58 using content::RenderFrame; 58 using content::RenderFrame;
59 59
60 // Maximum number of characters in the document to index. 60 // Maximum number of characters in the document to index.
61 // Any text beyond this point will be clipped. 61 // Any text beyond this point will be clipped.
62 static const size_t kMaxIndexChars = 65535; 62 static const size_t kMaxIndexChars = 65535;
63 63
64 // Constants for UMA statistic collection. 64 // Constants for UMA statistic collection.
65 static const char kTranslateCaptureText[] = "Translate.CaptureText"; 65 static const char kTranslateCaptureText[] = "Translate.CaptureText";
66 66
67 // For a page that auto-refreshes, we still show the bubble, if
68 // the refresh delay is less than this value (in seconds).
69 static const double kLocationChangeIntervalInSeconds = 10;
70
67 namespace { 71 namespace {
68 72
69 // If the source image is null or occupies less area than 73 // If the source image is null or occupies less area than
70 // |thumbnail_min_area_pixels|, we return the image unmodified. Otherwise, we 74 // |thumbnail_min_area_pixels|, we return the image unmodified. Otherwise, we
71 // scale down the image so that the width and height do not exceed 75 // scale down the image so that the width and height do not exceed
72 // |thumbnail_max_size_pixels|, preserving the original aspect ratio. 76 // |thumbnail_max_size_pixels|, preserving the original aspect ratio.
73 SkBitmap Downscale(const blink::WebImage& image, 77 SkBitmap Downscale(const blink::WebImage& image,
74 int thumbnail_min_area_pixels, 78 int thumbnail_min_area_pixels,
75 const gfx::Size& thumbnail_max_size_pixels) { 79 const gfx::Size& thumbnail_max_size_pixels) {
76 if (image.isNull()) 80 if (image.isNull())
(...skipping 254 matching lines...) Expand 10 before | Expand all | Expand 10 after
331 crash_keys::kViewCount, 335 crash_keys::kViewCount,
332 base::SizeTToString(content::RenderView::GetRenderViewCount())); 336 base::SizeTToString(content::RenderView::GetRenderViewCount()));
333 } 337 }
334 338
335 void ChromeRenderFrameObserver::CapturePageText(TextCaptureType capture_type) { 339 void ChromeRenderFrameObserver::CapturePageText(TextCaptureType capture_type) {
336 WebLocalFrame* frame = render_frame()->GetWebFrame(); 340 WebLocalFrame* frame = render_frame()->GetWebFrame();
337 if (!frame) 341 if (!frame)
338 return; 342 return;
339 343
340 // Don't capture pages that have pending redirect or location change. 344 // Don't capture pages that have pending redirect or location change.
341 if (frame->isNavigationScheduled()) 345 if (frame->isNavigationScheduledWithin(kLocationChangeIntervalInSeconds))
342 return; 346 return;
343 347
344 // Don't index/capture pages that are in view source mode. 348 // Don't index/capture pages that are in view source mode.
345 if (frame->isViewSourceModeEnabled()) 349 if (frame->isViewSourceModeEnabled())
346 return; 350 return;
347 351
348 // Don't capture text of the error pages. 352 // Don't capture text of the error pages.
349 WebDataSource* ds = frame->dataSource(); 353 WebDataSource* ds = frame->dataSource();
350 if (ds && ds->hasUnreachableURL()) 354 if (ds && ds->hasUnreachableURL())
351 return; 355 return;
(...skipping 35 matching lines...) Expand 10 before | Expand all | Expand 10 after
387 case blink::WebMeaningfulLayout::FinishedParsing: 391 case blink::WebMeaningfulLayout::FinishedParsing:
388 CapturePageText(PRELIMINARY_CAPTURE); 392 CapturePageText(PRELIMINARY_CAPTURE);
389 break; 393 break;
390 case blink::WebMeaningfulLayout::FinishedLoading: 394 case blink::WebMeaningfulLayout::FinishedLoading:
391 CapturePageText(FINAL_CAPTURE); 395 CapturePageText(FINAL_CAPTURE);
392 break; 396 break;
393 default: 397 default:
394 break; 398 break;
395 } 399 }
396 } 400 }
OLDNEW
« no previous file with comments | « chrome/browser/translate/translate_browsertest.cc ('k') | chrome/test/data/translate/refresh_meta_tag_long.html » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698