| 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 #import "components/translate/ios/browser/js_language_detection_manager.h" | 5 #import "components/translate/ios/browser/js_language_detection_manager.h" |
| 6 | 6 |
| 7 #include "base/callback.h" | 7 #include "base/callback.h" |
| 8 #include "base/mac/scoped_nsobject.h" | |
| 9 #include "base/strings/string_util.h" | 8 #include "base/strings/string_util.h" |
| 10 #include "base/strings/sys_string_conversions.h" | 9 #include "base/strings/sys_string_conversions.h" |
| 11 | 10 |
| 11 #if !defined(__has_feature) || !__has_feature(objc_arc) |
| 12 #error "This file requires ARC support." |
| 13 #endif |
| 14 |
| 12 namespace language_detection { | 15 namespace language_detection { |
| 13 // Note: This should stay in sync with the constant in language_detection.js. | 16 // Note: This should stay in sync with the constant in language_detection.js. |
| 14 const size_t kMaxIndexChars = 65535; | 17 const size_t kMaxIndexChars = 65535; |
| 15 } // namespace language_detection | 18 } // namespace language_detection |
| 16 | 19 |
| 17 @implementation JsLanguageDetectionManager | 20 @implementation JsLanguageDetectionManager |
| 18 | 21 |
| 19 #pragma mark - Protected methods | 22 #pragma mark - Protected methods |
| 20 | 23 |
| 21 - (NSString*)scriptPath { | 24 - (NSString*)scriptPath { |
| (...skipping 12 matching lines...) Expand all Loading... |
| 34 DCHECK(!callback.is_null()); | 37 DCHECK(!callback.is_null()); |
| 35 // Copy the completion handler so that the block does not capture a reference. | 38 // Copy the completion handler so that the block does not capture a reference. |
| 36 __block language_detection::BufferedTextCallback blockCallback = callback; | 39 __block language_detection::BufferedTextCallback blockCallback = callback; |
| 37 NSString* JS = @"__gCrWeb.languageDetection.retrieveBufferedTextContent()"; | 40 NSString* JS = @"__gCrWeb.languageDetection.retrieveBufferedTextContent()"; |
| 38 [self executeJavaScript:JS completionHandler:^(id result, NSError*) { | 41 [self executeJavaScript:JS completionHandler:^(id result, NSError*) { |
| 39 blockCallback.Run(base::SysNSStringToUTF16(result)); | 42 blockCallback.Run(base::SysNSStringToUTF16(result)); |
| 40 }]; | 43 }]; |
| 41 } | 44 } |
| 42 | 45 |
| 43 @end | 46 @end |
| OLD | NEW |