OLD | NEW |
(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 #ifndef IOS_WEB_PUBLIC_WEB_STATE_JS_CRW_JS_INJECTION_MANAGER_H_ |
| 6 #define IOS_WEB_PUBLIC_WEB_STATE_JS_CRW_JS_INJECTION_MANAGER_H_ |
| 7 |
| 8 #import <Foundation/Foundation.h> |
| 9 |
| 10 #import "ios/web/public/web_state/js/crw_js_injection_evaluator.h" |
| 11 |
| 12 @class CRWJSInjectionReceiver; |
| 13 |
| 14 // This class defines the abstract interface for managing JavaScript |
| 15 // Injection into a UIWebView. |
| 16 @interface CRWJSInjectionManager : NSObject |
| 17 |
| 18 // Designated initializer. Initializes the object with the |receiver|. |
| 19 - (id)initWithReceiver:(CRWJSInjectionReceiver*)receiver; |
| 20 |
| 21 // The array of |CRWJSInjectionManager| this class depends on. Default to be |
| 22 // empty array. Note circular dependency is not allowed, which will cause stack |
| 23 // overflow in dependency related computation such as -allDependencies. |
| 24 - (NSArray*)directDependencies; |
| 25 |
| 26 // Returns a list of all the CRWJSInjectionManagers required by this manager, |
| 27 // that is, this manager and the managers it directly or indirectly depends on. |
| 28 // The list is ordered in such a way that any CRWJSInjectionManager in the list |
| 29 // only depends on those appear before it in the list. |
| 30 - (NSArray*)allDependencies; |
| 31 |
| 32 // Returns whether JavaScript has already been injected into the receiver. |
| 33 - (BOOL)hasBeenInjected; |
| 34 |
| 35 // Injects JavaScript at |self.scriptPath| into the receiver object if it is |
| 36 // missing. It also injects the dependencies' JavaScript if they are missing. |
| 37 - (void)inject; |
| 38 |
| 39 // Returns an autoreleased string that is the JavaScript to be injected into |
| 40 // the receiver object including any JavaScript for all specified dependencies. |
| 41 - (NSString*)injectionContentIncludingDependencies; |
| 42 |
| 43 // Evaluates the provided JavaScript expression, slightly deferred. Designed for |
| 44 // scripts where the chance of crwebinvoke:// being triggered indirectly is |
| 45 // high, and that aren't required to return a value. |
| 46 - (void)deferredEvaluate:(NSString*)script; |
| 47 |
| 48 // Evaluate the provided JavaScript asynchronously calling completionHandler |
| 49 // after execution. The |completionHandler| can be nil. |
| 50 - (void)evaluate:(NSString*)script |
| 51 stringResultHandler:(web::JavaScriptCompletion)completionHandler; |
| 52 |
| 53 @end |
| 54 |
| 55 @interface CRWJSInjectionManager (ProtectedMethods) |
| 56 |
| 57 // The injection receiver used to evaluate JavaScript. |
| 58 - (CRWJSInjectionReceiver*)receiver; |
| 59 |
| 60 // Path for the resource in the application bundle of type "js" that needs to |
| 61 // injected for this manager. |
| 62 // Subclasses must override this method to return the path to the JavaScript |
| 63 // that needs to be injected. |
| 64 - (NSString*)scriptPath; |
| 65 |
| 66 // The JavaScript function that returns the JavaScript constant of undefined |
| 67 // if the JavaScript has not been injected. Default to be nil. Subclasses |
| 68 // should override this if their script should only be injected into a page |
| 69 // once. |
| 70 - (NSString*)presenceBeacon; |
| 71 |
| 72 // Returns the content that should be injected. This is called every time |
| 73 // injection content is needed; by default is uses a cached copy of |
| 74 // staticInjectionContent. |
| 75 // Subclasses should override this only if the content needs to be dynamic |
| 76 // rather than cached, otherwise they should override staticInjectionContent. |
| 77 - (NSString*)injectionContent; |
| 78 |
| 79 // Returns an autoreleased string that is the JavaScript to be injected into |
| 80 // the receiver object. By default this returns the contents of the script file; |
| 81 // subclasses can override this if they need to get a static script from some |
| 82 // other source. |
| 83 // The return value from this method will be cached; if dynamic script content |
| 84 // is necessary, override injectionContent instead. |
| 85 - (NSString*)staticInjectionContent; |
| 86 |
| 87 // Injects dependencies if they are missing. |
| 88 - (void)injectDependenciesIfMissing; |
| 89 |
| 90 @end |
| 91 |
| 92 #endif // IOS_WEB_PUBLIC_WEB_STATE_JS_CRW_JS_INJECTION_MANAGER_H_ |
OLD | NEW |