| OLD | NEW |
| 1 // Copyright 2012 The Chromium Authors. All rights reserved. | 1 // Copyright 2012 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 "ios/chrome/browser/passwords/js_password_manager.h" | 5 #import "ios/chrome/browser/passwords/js_password_manager.h" |
| 6 | 6 |
| 7 #include "base/json/string_escape.h" | 7 #include "base/json/string_escape.h" |
| 8 #include "base/logging.h" | 8 #include "base/logging.h" |
| 9 #include "base/mac/foundation_util.h" | 9 #include "base/mac/foundation_util.h" |
| 10 #include "base/strings/sys_string_conversions.h" | 10 #include "base/strings/sys_string_conversions.h" |
| 11 | 11 |
| 12 #if !defined(__has_feature) || !__has_feature(objc_arc) |
| 13 #error "This file requires ARC support." |
| 14 #endif |
| 15 |
| 12 namespace { | 16 namespace { |
| 13 // Sanitizes |JSONString| and wraps it in quotes so it can be injected safely in | 17 // Sanitizes |JSONString| and wraps it in quotes so it can be injected safely in |
| 14 // JavaScript. | 18 // JavaScript. |
| 15 NSString* JSONEscape(NSString* JSONString) { | 19 NSString* JSONEscape(NSString* JSONString) { |
| 16 return base::SysUTF8ToNSString( | 20 return base::SysUTF8ToNSString( |
| 17 base::GetQuotedJSONString(base::SysNSStringToUTF8(JSONString))); | 21 base::GetQuotedJSONString(base::SysNSStringToUTF8(JSONString))); |
| 18 } | 22 } |
| 19 } // namespace | 23 } // namespace |
| 20 | 24 |
| 21 @interface JsPasswordManager () | 25 @interface JsPasswordManager () |
| (...skipping 72 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 94 - (void)evaluateExtraScript:(NSString*)script | 98 - (void)evaluateExtraScript:(NSString*)script |
| 95 completionHandler:(void (^)(NSString*))completionHandler { | 99 completionHandler:(void (^)(NSString*))completionHandler { |
| 96 DCHECK(completionHandler); | 100 DCHECK(completionHandler); |
| 97 NSString* JS = [[self injectionContent] stringByAppendingString:script]; | 101 NSString* JS = [[self injectionContent] stringByAppendingString:script]; |
| 98 [self executeJavaScript:JS completionHandler:^(id result, NSError*) { | 102 [self executeJavaScript:JS completionHandler:^(id result, NSError*) { |
| 99 completionHandler(base::mac::ObjCCastStrict<NSString>(result)); | 103 completionHandler(base::mac::ObjCCastStrict<NSString>(result)); |
| 100 }]; | 104 }]; |
| 101 } | 105 } |
| 102 | 106 |
| 103 @end | 107 @end |
| OLD | NEW |