Add ICU message format support
[chromium-blink-merge.git] / ios / web / public / web_state / js / crw_js_injection_manager.h
blob916970ba778463db8095c0c96b1d0930ab9ed944
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.
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_
8 #import <Foundation/Foundation.h>
10 #import "ios/web/public/web_state/js/crw_js_injection_evaluator.h"
12 @class CRWJSInjectionReceiver;
14 // This class defines the abstract interface for managing JavaScript
15 // Injection into a UIWebView.
16 @interface CRWJSInjectionManager : NSObject
18 // Designated initializer. Initializes the object with the |receiver|.
19 - (id)initWithReceiver:(CRWJSInjectionReceiver*)receiver;
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;
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;
32 // Returns whether JavaScript has already been injected into the receiver.
33 - (BOOL)hasBeenInjected;
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;
39 // Evaluates the provided JavaScript expression, slightly deferred. Designed for
40 // scripts where the chance of crwebinvoke:// being triggered indirectly is
41 // high, and that aren't required to return a value.
42 - (void)deferredEvaluate:(NSString*)script;
44 // Evaluate the provided JavaScript asynchronously calling completionHandler
45 // after execution. The |completionHandler| can be nil.
46 - (void)evaluate:(NSString*)script
47 stringResultHandler:(web::JavaScriptCompletion)completionHandler;
49 @end
51 @interface CRWJSInjectionManager (ProtectedMethods)
53 // The injection receiver used to evaluate JavaScript.
54 - (CRWJSInjectionReceiver*)receiver;
56 // Path for the resource in the application bundle of type "js" that needs to
57 // injected for this manager.
58 // Subclasses must override this method to return the path to the JavaScript
59 // that needs to be injected.
60 - (NSString*)scriptPath;
62 // The JavaScript function that returns the JavaScript constant of undefined
63 // if the JavaScript has not been injected. Default to be nil. Subclasses
64 // should override this if their script should only be injected into a page
65 // once.
66 - (NSString*)presenceBeacon;
68 // Returns the content that should be injected. This is called every time
69 // injection content is needed; by default is uses a cached copy of
70 // staticInjectionContent.
71 // Subclasses should override this only if the content needs to be dynamic
72 // rather than cached, otherwise they should override staticInjectionContent.
73 - (NSString*)injectionContent;
75 // Returns an autoreleased string that is the JavaScript to be injected into
76 // the receiver object. By default this returns the contents of the script file;
77 // subclasses can override this if they need to get a static script from some
78 // other source.
79 // The return value from this method will be cached; if dynamic script content
80 // is necessary, override injectionContent instead.
81 - (NSString*)staticInjectionContent;
83 // Injects dependencies if they are missing.
84 - (void)injectDependenciesIfMissing;
86 @end
88 #endif // IOS_WEB_PUBLIC_WEB_STATE_JS_CRW_JS_INJECTION_MANAGER_H_