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 <stddef.h> | 7 #include <stddef.h> |
8 | 8 |
9 #include <limits> | 9 #include <limits> |
10 #include <string> | 10 #include <string> |
(...skipping 14 matching lines...) Expand all Loading... |
25 #include "content/public/renderer/render_frame.h" | 25 #include "content/public/renderer/render_frame.h" |
26 #include "content/public/renderer/render_view.h" | 26 #include "content/public/renderer/render_view.h" |
27 #include "extensions/common/constants.h" | 27 #include "extensions/common/constants.h" |
28 #include "net/base/net_util.h" | 28 #include "net/base/net_util.h" |
29 #include "skia/ext/image_operations.h" | 29 #include "skia/ext/image_operations.h" |
30 #include "third_party/WebKit/public/platform/WebImage.h" | 30 #include "third_party/WebKit/public/platform/WebImage.h" |
31 #include "third_party/WebKit/public/platform/modules/app_banner/WebAppBannerProm
ptReply.h" | 31 #include "third_party/WebKit/public/platform/modules/app_banner/WebAppBannerProm
ptReply.h" |
32 #include "third_party/WebKit/public/web/WebDataSource.h" | 32 #include "third_party/WebKit/public/web/WebDataSource.h" |
33 #include "third_party/WebKit/public/web/WebDocument.h" | 33 #include "third_party/WebKit/public/web/WebDocument.h" |
34 #include "third_party/WebKit/public/web/WebElement.h" | 34 #include "third_party/WebKit/public/web/WebElement.h" |
| 35 #include "third_party/WebKit/public/web/WebFrameContentDumper.h" |
35 #include "third_party/WebKit/public/web/WebLocalFrame.h" | 36 #include "third_party/WebKit/public/web/WebLocalFrame.h" |
36 #include "third_party/WebKit/public/web/WebNode.h" | 37 #include "third_party/WebKit/public/web/WebNode.h" |
37 #include "third_party/WebKit/public/web/WebSecurityPolicy.h" | 38 #include "third_party/WebKit/public/web/WebSecurityPolicy.h" |
38 #include "third_party/skia/include/core/SkBitmap.h" | 39 #include "third_party/skia/include/core/SkBitmap.h" |
39 #include "ui/gfx/codec/jpeg_codec.h" | 40 #include "ui/gfx/codec/jpeg_codec.h" |
40 #include "ui/gfx/geometry/size_f.h" | 41 #include "ui/gfx/geometry/size_f.h" |
41 #include "url/gurl.h" | 42 #include "url/gurl.h" |
42 | 43 |
43 #if defined(ENABLE_PRINTING) | 44 #if defined(ENABLE_PRINTING) |
44 #include "components/printing/common/print_messages.h" | 45 #include "components/printing/common/print_messages.h" |
45 #include "components/printing/renderer/print_web_view_helper.h" | 46 #include "components/printing/renderer/print_web_view_helper.h" |
46 #endif | 47 #endif |
47 | 48 |
48 using blink::WebDataSource; | 49 using blink::WebDataSource; |
49 using blink::WebElement; | 50 using blink::WebElement; |
| 51 using blink::WebFrameContentDumper; |
50 using blink::WebLocalFrame; | 52 using blink::WebLocalFrame; |
51 using blink::WebNode; | 53 using blink::WebNode; |
52 using blink::WebString; | 54 using blink::WebString; |
53 using content::SSLStatus; | 55 using content::SSLStatus; |
54 using content::RenderFrame; | 56 using content::RenderFrame; |
55 | 57 |
56 // Maximum number of characters in the document to index. | 58 // Maximum number of characters in the document to index. |
57 // Any text beyond this point will be clipped. | 59 // Any text beyond this point will be clipped. |
58 static const size_t kMaxIndexChars = 65535; | 60 static const size_t kMaxIndexChars = 65535; |
59 | 61 |
(...skipping 287 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
347 return; | 349 return; |
348 | 350 |
349 // Don't index/capture pages that are being prerendered. | 351 // Don't index/capture pages that are being prerendered. |
350 if (prerender::PrerenderHelper::IsPrerendering(render_frame())) | 352 if (prerender::PrerenderHelper::IsPrerendering(render_frame())) |
351 return; | 353 return; |
352 | 354 |
353 base::TimeTicks capture_begin_time = base::TimeTicks::Now(); | 355 base::TimeTicks capture_begin_time = base::TimeTicks::Now(); |
354 | 356 |
355 // Retrieve the frame's full text (up to kMaxIndexChars), and pass it to the | 357 // Retrieve the frame's full text (up to kMaxIndexChars), and pass it to the |
356 // translate helper for language detection and possible translation. | 358 // translate helper for language detection and possible translation. |
357 base::string16 contents = frame->contentAsText(kMaxIndexChars); | 359 // TODO(dglazkov): WebFrameContentDumper should only be used for |
| 360 // testing purposes. See http://crbug.com/585164. |
| 361 base::string16 contents = |
| 362 WebFrameContentDumper::dumpFrameTreeAsText(frame, kMaxIndexChars); |
358 | 363 |
359 UMA_HISTOGRAM_TIMES(kTranslateCaptureText, | 364 UMA_HISTOGRAM_TIMES(kTranslateCaptureText, |
360 base::TimeTicks::Now() - capture_begin_time); | 365 base::TimeTicks::Now() - capture_begin_time); |
361 | 366 |
362 // We should run language detection only once. Parsing finishes before | 367 // We should run language detection only once. Parsing finishes before |
363 // the page loads, so let's pick that timing. | 368 // the page loads, so let's pick that timing. |
364 if (translate_helper_ && capture_type == PRELIMINARY_CAPTURE) | 369 if (translate_helper_ && capture_type == PRELIMINARY_CAPTURE) |
365 translate_helper_->PageCaptured(contents); | 370 translate_helper_->PageCaptured(contents); |
366 | 371 |
367 TRACE_EVENT0("renderer", "ChromeRenderFrameObserver::CapturePageText"); | 372 TRACE_EVENT0("renderer", "ChromeRenderFrameObserver::CapturePageText"); |
(...skipping 12 matching lines...) Expand all Loading... |
380 case blink::WebMeaningfulLayout::FinishedParsing: | 385 case blink::WebMeaningfulLayout::FinishedParsing: |
381 CapturePageText(PRELIMINARY_CAPTURE); | 386 CapturePageText(PRELIMINARY_CAPTURE); |
382 break; | 387 break; |
383 case blink::WebMeaningfulLayout::FinishedLoading: | 388 case blink::WebMeaningfulLayout::FinishedLoading: |
384 CapturePageText(FINAL_CAPTURE); | 389 CapturePageText(FINAL_CAPTURE); |
385 break; | 390 break; |
386 default: | 391 default: |
387 break; | 392 break; |
388 } | 393 } |
389 } | 394 } |
OLD | NEW |