Roll src/third_party/WebKit eac3800:0237a66 (svn 202606:202607)
[chromium-blink-merge.git] / components / translate / ios / browser / js_language_detection_manager.mm
blob0baf504720beecd7ab78cbc17cc6d1ddc502d6cb
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
3 // found in the LICENSE file.
5 #import "components/translate/ios/browser/js_language_detection_manager.h"
7 #include "base/callback.h"
8 #include "base/mac/scoped_nsobject.h"
9 #include "base/strings/string_util.h"
10 #include "base/strings/sys_string_conversions.h"
12 namespace language_detection {
13 // Note: This should stay in sync with the constant in language_detection.js.
14 const size_t kMaxIndexChars = 65535;
15 }  // namespace language_detection
17 @implementation JsLanguageDetectionManager
19 #pragma mark - Protected methods
21 - (NSString*)scriptPath {
22   return @"language_detection";
25 - (NSString*)presenceBeacon {
26   return @"__gCrWeb.languageDetection";
29 #pragma mark - Public methods
31 - (void)startLanguageDetection {
32   [self evaluate:@"__gCrWeb.languageDetection.detectLanguage()"
33       stringResultHandler:nil];
36 - (void)retrieveBufferedTextContent:
37         (const language_detection::BufferedTextCallback&)callback {
38   DCHECK(!callback.is_null());
39   // Copy the completion handler so that the block does not capture a reference.
40   __block language_detection::BufferedTextCallback blockCallback = callback;
41   [self evaluate:@"__gCrWeb.languageDetection.retrieveBufferedTextContent()"
42       stringResultHandler:^(NSString* result, NSError*) {
43         blockCallback.Run(base::SysNSStringToUTF16(result));
44       }];
47 @end