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 #ifndef IOS_WEB_PUBLIC_WEB_STATE_JS_CRW_JS_INJECTION_EVALUATOR_H_ | 5 #ifndef IOS_WEB_PUBLIC_WEB_STATE_JS_CRW_JS_INJECTION_EVALUATOR_H_ |
6 #define IOS_WEB_PUBLIC_WEB_STATE_JS_CRW_JS_INJECTION_EVALUATOR_H_ | 6 #define IOS_WEB_PUBLIC_WEB_STATE_JS_CRW_JS_INJECTION_EVALUATOR_H_ |
7 | 7 |
8 #import <Foundation/Foundation.h> | 8 #import <Foundation/Foundation.h> |
9 | 9 |
10 #include "ios/web/public/web_view_type.h" | 10 #include "ios/web/public/web_view_type.h" |
11 | 11 |
12 // The type of the completion handler block that is called from | 12 // The type of the completion handler block that is called from |
13 // |evaluateJavaScript:completionHandler| | 13 // |evaluateJavaScript:completionHandler| |
14 namespace web { | 14 namespace web { |
15 typedef void (^JavaScriptCompletion)(NSString*, NSError*); | 15 typedef void (^JavaScriptCompletion)(NSString*, NSError*); |
16 } | 16 } |
17 | 17 |
18 @protocol CRWJSInjectionEvaluator | 18 @protocol CRWJSInjectionEvaluator |
19 | 19 |
20 // Evaluates the supplied JavaScript in the WebView. Calls |completionHandler| | 20 // Evaluates the supplied JavaScript in the WebView. Calls |completionHandler| |
21 // with results of the evaluation (which may be nil if the implementing object | 21 // with results of the evaluation (which may be nil if the implementing object |
22 // has no way to run the evaluation or the evaluation returns a nil value) | 22 // has no way to run the evaluation or the evaluation returns a nil value) |
23 // or an NSError if there is an error. The |completionHandler| can be nil. | 23 // or an NSError if there is an error. The |completionHandler| can be nil. |
| 24 // TODO(crbug.com/595761): Change this API to return |id| instead of string. |
24 - (void)evaluateJavaScript:(NSString*)script | 25 - (void)evaluateJavaScript:(NSString*)script |
25 stringResultHandler:(web::JavaScriptCompletion)handler; | 26 stringResultHandler:(web::JavaScriptCompletion)handler; |
26 | 27 |
27 // Checks to see if the script for a class has been injected into the | 28 // Checks to see if the script for a class has been injected into the |
28 // current page already, given the class and the script's presence | 29 // current page already, given the class and the script's presence |
29 // beacon (a JS object that should exist iff the script has been injected). | 30 // beacon (a JS object that should exist iff the script has been injected). |
30 - (BOOL)scriptHasBeenInjectedForClass:(Class)jsInjectionManagerClass | 31 - (BOOL)scriptHasBeenInjectedForClass:(Class)jsInjectionManagerClass |
31 presenceBeacon:(NSString*)beacon; | 32 presenceBeacon:(NSString*)beacon; |
32 | 33 |
33 // Injects the given script into the current page on behalf of | 34 // Injects the given script into the current page on behalf of |
34 // |jsInjectionManagerClass|. This should only be used for injecting | 35 // |jsInjectionManagerClass|. This should only be used for injecting |
35 // the manager's script, and not for evaluating arbitrary JavaScript. | 36 // the manager's script, and not for evaluating arbitrary JavaScript. |
36 - (void)injectScript:(NSString*)script forClass:(Class)jsInjectionManagerClass; | 37 - (void)injectScript:(NSString*)script forClass:(Class)jsInjectionManagerClass; |
37 | 38 |
38 // Returns type of web view used for evaluation. Must not change for the | 39 // Returns type of web view used for evaluation. Must not change for the |
39 // lifetime of the object. | 40 // lifetime of the object. |
40 - (web::WebViewType)webViewType; | 41 - (web::WebViewType)webViewType; |
41 | 42 |
42 @end | 43 @end |
43 | 44 |
44 #endif // IOS_WEB_PUBLIC_WEB_STATE_JS_CRW_JS_INJECTION_EVALUATOR_H_ | 45 #endif // IOS_WEB_PUBLIC_WEB_STATE_JS_CRW_JS_INJECTION_EVALUATOR_H_ |
OLD | NEW |