OLD | NEW |
1 // Copyright 2014 The Chromium Authors. All rights reserved. | 1 // Copyright 2014 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_WEB_STATE_UI_CRW_WK_SCRIPT_MESSAGE_ROUTER_H_ | 5 #ifndef IOS_WEB_WEB_STATE_UI_CRW_WK_SCRIPT_MESSAGE_ROUTER_H_ |
6 #define IOS_WEB_WEB_STATE_UI_CRW_WK_SCRIPT_MESSAGE_ROUTER_H_ | 6 #define IOS_WEB_WEB_STATE_UI_CRW_WK_SCRIPT_MESSAGE_ROUTER_H_ |
7 | 7 |
8 #import <WebKit/WebKit.h> | 8 #import <WebKit/WebKit.h> |
9 | 9 |
10 // WKUserContentController wrapper that allows adding multiple message handlers | 10 // WKUserContentController wrapper that allows adding multiple message handlers |
11 // for the same message name. CRWWKScriptMessageRouter will route the messages | 11 // for the same message name. CRWWKScriptMessageRouter will route the messages |
12 // from the underlying user content controller to a designated receiver by | 12 // from the underlying user content controller to a designated receiver by |
13 // matching the message's name and webView. | 13 // matching the message's name and webView. |
14 @interface CRWWKScriptMessageRouter : NSObject | 14 @interface CRWWKScriptMessageRouter : NSObject |
15 | 15 |
16 // Underlying WKUserContentController. | 16 // Underlying WKUserContentController. |
17 @property(nonatomic, weak, readonly) | 17 @property(nonatomic, readonly) WKUserContentController* userContentController; |
18 WKUserContentController* userContentController; | |
19 | 18 |
20 // Designated initializer. |userContentController| must not be nil. | 19 // Designated initializer. |userContentController| must not be nil. |
21 - (instancetype)initWithUserContentController: | 20 - (instancetype)initWithUserContentController: |
22 (WKUserContentController*)userContentController NS_DESIGNATED_INITIALIZER; | 21 (WKUserContentController*)userContentController NS_DESIGNATED_INITIALIZER; |
23 | 22 |
24 - (instancetype)init NS_UNAVAILABLE; | 23 - (instancetype)init NS_UNAVAILABLE; |
25 | 24 |
26 // Sets a script message handler. Multiple message handlers can be added for | 25 // Sets a script message handler. Multiple message handlers can be added for |
27 // the same message name and long as |webView| are different. Setting |handler| | 26 // the same message name and long as |webView| are different. Setting |handler| |
28 // for the same |name| and |webView| pair is an error. |handler| will be called | 27 // for the same |name| and |webView| pair is an error. |handler| will be called |
29 // if WKScriptMessage sent by WKUserContentController will match both the |name| | 28 // if WKScriptMessage sent by WKUserContentController will match both the |name| |
30 // and the |webView|. | 29 // and the |webView|. |
31 - (void)setScriptMessageHandler:(void (^)(WKScriptMessage*))handler | 30 - (void)setScriptMessageHandler:(void (^)(WKScriptMessage*))handler |
32 name:(NSString*)messageName | 31 name:(NSString*)messageName |
33 webView:(WKWebView*)webView; | 32 webView:(WKWebView*)webView; |
34 | 33 |
35 // Removes a specific message handler. | 34 // Removes a specific message handler. |
36 - (void)removeScriptMessageHandlerForName:(NSString*)messageName | 35 - (void)removeScriptMessageHandlerForName:(NSString*)messageName |
37 webView:(WKWebView*)webView; | 36 webView:(WKWebView*)webView; |
38 | 37 |
39 // Removes all message handlers for the given |webView|. | 38 // Removes all message handlers for the given |webView|. |
40 - (void)removeAllScriptMessageHandlersForWebView:(WKWebView*)webView; | 39 - (void)removeAllScriptMessageHandlersForWebView:(WKWebView*)webView; |
41 | 40 |
42 @end | 41 @end |
43 | 42 |
44 #endif // IOS_WEB_WEB_STATE_UI_CRW_WK_SCRIPT_MESSAGE_ROUTER_H_ | 43 #endif // IOS_WEB_WEB_STATE_UI_CRW_WK_SCRIPT_MESSAGE_ROUTER_H_ |
OLD | NEW |