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

Unified 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: Review comments 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 side-by-side diff with in-line comments
Download patch
Index: ios/web/public/test/crw_test_js_injection_receiver.mm
diff --git a/ios/web/public/test/crw_test_js_injection_receiver.mm b/ios/web/public/test/crw_test_js_injection_receiver.mm
new file mode 100644
index 0000000000000000000000000000000000000000..3d6d55d8dd6de5017f0f8b9478b3ec3d2247f712
--- /dev/null
+++ b/ios/web/public/test/crw_test_js_injection_receiver.mm
@@ -0,0 +1,69 @@
+// Copyright 2013 The Chromium Authors. All rights reserved.
+// Use of this source code is governed by a BSD-style license that can be
+// found in the LICENSE file.
+
+#import "ios/web/public/test/crw_test_js_injection_receiver.h"
+
+#import <UIKit/UIKit.h>
+
+#import "base/mac/scoped_nsobject.h"
+#import "ios/web/public/web_state/js/crw_js_injection_evaluator.h"
+
+@interface CRWTestUIWebViewEvaluator : NSObject<CRWJSInjectionEvaluator> {
+ base::scoped_nsobject<UIWebView> _webView;
+}
+@end
+
+@implementation CRWTestUIWebViewEvaluator
+
+- (id) init {
+ if (self = [super init])
+ _webView.reset([[UIWebView alloc] init]);
+ return self;
+}
+
+#pragma mark -
+#pragma mark CRWJSInjectionEvaluatorMethods
+
+- (void)evaluateJavaScript:(NSString*)script
+ stringResultHandler:(web::JavaScriptCompletion)handler {
+ dispatch_async(dispatch_get_main_queue(), ^{
+ // TODO(shreyasv): Change to weaknsobject once weaknsobject is moved to
+ // ios/base.
+ NSString* result =
+ [_webView stringByEvaluatingJavaScriptFromString:script];
+ if (handler)
+ handler(result, nil);
+ });
+}
+
+- (BOOL)scriptHasBeenInjectedForClass:(Class)jsInjectionManagerClass
+ presenceBeacon:(NSString*)beacon {
+ NSString* result = [_webView stringByEvaluatingJavaScriptFromString:
+ [NSString stringWithFormat:@"typeof %@", beacon]];
+ return [result isEqualToString:@"object"];
+}
+
+- (void)injectScript:(NSString*)script
+ forClass:(Class)jsInjectionManagerClass {
+ [_webView stringByEvaluatingJavaScriptFromString:script];
+}
+
+@end
+
+@interface CRWTestJSInjectionReceiver () {
+ base::scoped_nsobject<CRWTestUIWebViewEvaluator> evaluator_;
+}
+@end
+
+@implementation CRWTestJSInjectionReceiver
+
+- (id)init {
+ base::scoped_nsobject<CRWTestUIWebViewEvaluator> evaluator(
+ [[CRWTestUIWebViewEvaluator alloc] init]);
+ if (self = [super initWithEvaluator:evaluator])
+ evaluator_.swap(evaluator);
+ return self;
+}
+
+@end
« no previous file with comments | « ios/web/public/test/crw_test_js_injection_receiver.h ('k') | ios/web/public/web_state/js/crw_js_base_manager.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698