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

Side by Side Diff: ios/web/web_state/js/crw_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 2012 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 #include "ios/web/public/web_state/js/crw_js_injection_receiver.h"
6
7 #include "base/logging.h"
8 #import "base/mac/scoped_nsobject.h"
9 #include "ios/web/public/web_state/js/crw_js_injection_evaluator.h"
sdefresne 2014/12/10 15:30:23 nit: those headers are Objective-C headers too, wh
10 #include "ios/web/public/web_state/js/crw_js_injection_manager.h"
11
12 @implementation CRWJSInjectionReceiver {
13 // Used to evaluate JavaScripts.
14 __weak id<CRWJSInjectionEvaluator> _evaluator;
sdefresne 2014/12/10 15:30:23 __weak has no meaning if not using ARC. Its presen
15
16 // Map from a CRWJSInjectionManager class to its instance created for this
17 // receiver.
18 base::scoped_nsobject<NSMutableDictionary> _managers;
19 }
20
21 - (id)init {
22 NOTREACHED();
23 return [super init];
24 }
25
26 - (id)initWithEvaluator:(id<CRWJSInjectionEvaluator>)evaluator {
27 DCHECK(evaluator);
28 self = [super init];
29 if (self) {
30 _evaluator = evaluator;
31 _managers.reset([[NSMutableDictionary alloc] init]);
32 }
33 return self;
34 }
35
36 #pragma mark -
37 #pragma mark CRWJSInjectionEvaluatorMethods
38
39 - (void)evaluateJavaScript:(NSString*)script
40 stringResultHandler:(web::JavaScriptCompletion)handler {
41 [_evaluator evaluateJavaScript:script stringResultHandler:handler];
42 }
43
44 - (BOOL)scriptHasBeenInjectedForClass:(Class)jsInjectionManagerClass
45 presenceBeacon:(NSString*)beacon {
46 return [_evaluator scriptHasBeenInjectedForClass:jsInjectionManagerClass
47 presenceBeacon:beacon];
48 }
49
50 - (void)injectScript:(NSString*)script forClass:(Class)jsInjectionManagerClass {
51 [_evaluator injectScript:script forClass:jsInjectionManagerClass];
52 }
53
54 - (CRWJSInjectionManager*)instanceOfClass:(Class)jsInjectionManagerClass {
55 DCHECK(_managers);
56 CRWJSInjectionManager* manager =
57 [_managers objectForKey:jsInjectionManagerClass];
58 if (!manager) {
59 base::scoped_nsobject<CRWJSInjectionManager> newManager(
60 [[jsInjectionManagerClass alloc] initWithReceiver:self]);
61 [_managers setObject:newManager forKey:jsInjectionManagerClass];
62 manager = newManager;
63 }
64 DCHECK(manager);
65 for (Class depedencyClass in [manager directDependencies]) {
66 [self instanceOfClass:depedencyClass];
67 }
68 return manager;
69 }
70
71 @end
72
73 @implementation CRWJSInjectionReceiver (Testing)
74 - (NSDictionary*)managers {
75 return _managers.get();
76 }
77 @end
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698