OLD | NEW |
---|---|
(Empty) | |
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. | |
4 | |
5 #import "ios/web/public/test/crw_test_js_injection_receiver.h" | |
6 | |
7 #import <UIKit/UIKit.h> | |
8 | |
9 #import "base/mac/scoped_nsobject.h" | |
10 #import "ios/web/public/web_state/js/crw_js_injection_evaluator.h" | |
11 | |
12 @interface CRWTestUIWebViewEvaluator : NSObject<CRWJSInjectionEvaluator> { | |
13 base::scoped_nsobject<UIWebView> _webView; | |
14 } | |
15 @end | |
16 | |
17 @implementation CRWTestUIWebViewEvaluator | |
18 | |
19 - (id) init { | |
20 if (self = [super init]) | |
21 _webView.reset([[UIWebView alloc] init]); | |
22 return self; | |
23 } | |
24 | |
25 #pragma mark - | |
26 #pragma mark CRWJSInjectionEvaluatorMethods | |
27 | |
28 - (void)evaluateJavaScript:(NSString*)script | |
29 stringResultHandler:(web::JavaScriptCompletion)handler { | |
30 dispatch_async(dispatch_get_main_queue(), ^{ | |
31 // TODO(shreyasv): Change to weaknsobject once weaknsobject is moved to | |
stuartmorgan
2014/12/11 23:59:38
This TODO can just become "Change to WeakNSObject
droger
2014/12/12 12:33:15
I'll do that as a follow up, because WeakNSObject
| |
32 // ios/base. | |
33 NSString* result = | |
34 [_webView stringByEvaluatingJavaScriptFromString:script]; | |
35 if (handler) | |
36 handler(result, nil); | |
37 }); | |
38 } | |
39 | |
40 - (BOOL)scriptHasBeenInjectedForClass:(Class)jsInjectionManagerClass | |
41 presenceBeacon:(NSString*)beacon { | |
42 NSString* result = [_webView stringByEvaluatingJavaScriptFromString: | |
43 [NSString stringWithFormat:@"typeof %@", beacon]]; | |
44 return [result isEqualToString:@"object"]; | |
45 } | |
46 | |
47 - (void)injectScript:(NSString*)script | |
48 forClass:(Class)jsInjectionManagerClass { | |
49 [_webView stringByEvaluatingJavaScriptFromString:script]; | |
50 } | |
51 | |
52 @end | |
53 | |
54 @interface CRWTestJSInjectionReceiver () { | |
55 base::scoped_nsobject<CRWTestUIWebViewEvaluator> evaluator_; | |
56 } | |
57 @end | |
58 | |
59 @implementation CRWTestJSInjectionReceiver | |
60 | |
61 - (id)init { | |
62 base::scoped_nsobject<CRWTestUIWebViewEvaluator> evaluator( | |
63 [[CRWTestUIWebViewEvaluator alloc] init]); | |
64 if (self = [super initWithEvaluator:evaluator]) | |
65 evaluator_.swap(evaluator); | |
66 return self; | |
67 } | |
68 | |
69 @end | |
OLD | NEW |