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

Unified Diff: chrome/renderer/chrome_render_frame_observer.cc

Issue 1650303002: Move DOM-inspecting language detection logic to Blink. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Rebased. Created 4 years, 10 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
« no previous file with comments | « no previous file | components/translate/content/renderer/translate_helper.h » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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 9fd19893f6daa9b2a071ad61e512ce34570c44f0..1a210f5ce2b3c1f1a38914e7b4b158f4caf4f188 100644
--- a/chrome/renderer/chrome_render_frame_observer.cc
+++ b/chrome/renderer/chrome_render_frame_observer.cc
@@ -28,6 +28,7 @@
#include "net/base/net_util.h"
#include "skia/ext/image_operations.h"
#include "third_party/WebKit/public/platform/WebImage.h"
+#include "third_party/WebKit/public/platform/WebLanguageDetectionDetails.h"
#include "third_party/WebKit/public/platform/modules/app_banner/WebAppBannerPromptReply.h"
#include "third_party/WebKit/public/web/WebDataSource.h"
#include "third_party/WebKit/public/web/WebDocument.h"
@@ -47,16 +48,13 @@
using blink::WebDataSource;
using blink::WebElement;
+using blink::WebLanguageDetectionDetails;
using blink::WebLocalFrame;
using blink::WebNode;
using blink::WebString;
using content::SSLStatus;
using content::RenderFrame;
-// Maximum number of characters in the document to index.
-// Any text beyond this point will be clipped.
-static const size_t kMaxIndexChars = 65535;
-
// Constants for UMA statistic collection.
static const char kTranslateCaptureText[] = "Translate.CaptureText";
@@ -352,21 +350,28 @@ void ChromeRenderFrameObserver::CapturePageText(TextCaptureType capture_type) {
base::TimeTicks capture_begin_time = base::TimeTicks::Now();
- // Retrieve the frame's full text (up to kMaxIndexChars), and pass it to the
- // translate helper for language detection and possible translation.
- base::string16 contents = frame->contentAsText(kMaxIndexChars);
+ WebLanguageDetectionDetails incoming_details =
+ frame->document().languageDetectionDetails();
UMA_HISTOGRAM_TIMES(kTranslateCaptureText,
base::TimeTicks::Now() - capture_begin_time);
// We should run language detection only once. Parsing finishes before
// the page loads, so let's pick that timing.
- if (translate_helper_ && capture_type == PRELIMINARY_CAPTURE)
- translate_helper_->PageCaptured(contents);
+ if (translate_helper_ && capture_type == PRELIMINARY_CAPTURE) {
+ translate::LanguageDetectionDetails details;
+ details.url = incoming_details.url;
+ details.content_language = incoming_details.contentLanguage.utf8();
+ details.html_root_language = incoming_details.htmlLanguage.utf8();
+ details.has_notranslate = incoming_details.hasNoTranslateMeta;
+ details.contents = incoming_details.content;
+ translate_helper_->LanguageDetectionDetailsCaptured(details);
+ }
TRACE_EVENT0("renderer", "ChromeRenderFrameObserver::CapturePageText");
#if defined(SAFE_BROWSING_CSD)
+ base::string16 contents = incoming_details.content;
// Will swap out the string.
if (phishing_classifier_)
phishing_classifier_->PageCaptured(&contents,
« no previous file with comments | « no previous file | components/translate/content/renderer/translate_helper.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698