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

Side by Side Diff: ios/web/public/test/crw_test_js_injection_receiver.mm

Issue 790803002: Upstream JavaScript injection for iOS (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 6 years 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 unified diff | Download patch
OLDNEW
(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 #include "base/mac/scoped_nsobject.h"
10 #import "ios/web/public/web_state/js/crw_js_injection_evaluator.h"
11
12 // TODO(shreyasv): Rename this to CRWTestUIWebViewEvaluator.
13 @interface CRWWebViewEvaluator : NSObject<CRWJSInjectionEvaluator> {
sdefresne 2014/12/10 15:30:23 nit: this class is only used in this file, why not
14 base::scoped_nsobject<UIWebView> _webView;
15 }
16 @end
17
18 @implementation CRWWebViewEvaluator
19
20 - (id) init {
21 if (self = [super init])
22 _webView.reset([[UIWebView alloc] init]);
23 return self;
24 }
25
26 #pragma mark -
27 #pragma mark CRWJSInjectionEvaluatorMethods
28
29 - (void)evaluateJavaScript:(NSString*)script
30 stringResultHandler:(web::JavaScriptCompletion)handler {
31 dispatch_async(dispatch_get_main_queue(), ^{
32 // TODO(shreyasv): Change to weaknsobject once weaknsobject is moved to
33 // ios/base.
34 NSString* result =
35 [_webView stringByEvaluatingJavaScriptFromString:script];
36 if (handler)
37 handler(result, nil);
38 });
39 }
40
41 - (BOOL)scriptHasBeenInjectedForClass:(Class)jsInjectionManagerClass
42 presenceBeacon:(NSString*)beacon {
43 NSString* result = [_webView stringByEvaluatingJavaScriptFromString:
44 [NSString stringWithFormat:@"typeof %@", beacon]];
45 return [result isEqualToString:@"object"];
46 }
47
48 - (void)injectScript:(NSString*)script
49 forClass:(Class)jsInjectionManagerClass {
50 [_webView stringByEvaluatingJavaScriptFromString:script];
51 }
52
53 @end
54
55 @interface CRWTestJSInjectionReceiver () {
56 base::scoped_nsobject<CRWWebViewEvaluator> evaluator_;
57 }
58 @end
59
60 @implementation CRWTestJSInjectionReceiver
61
62 - (id)init {
63 base::scoped_nsobject<CRWWebViewEvaluator> evaluator(
64 [[CRWWebViewEvaluator alloc] init]);
65 if (self = [super initWithEvaluator:evaluator])
66 evaluator_.swap(evaluator);
67 return self;
68 }
69
70 @end
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698