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, readonly) WKUserContentController* userContentController; | 17 @property(weak, nonatomic, readonly) |
| 18 WKUserContentController* userContentController; |
18 | 19 |
19 // Designated initializer. |userContentController| must not be nil. | 20 // Designated initializer. |userContentController| must not be nil. |
20 - (instancetype)initWithUserContentController: | 21 - (instancetype)initWithUserContentController: |
21 (WKUserContentController*)userContentController NS_DESIGNATED_INITIALIZER; | 22 (WKUserContentController*)userContentController NS_DESIGNATED_INITIALIZER; |
22 | 23 |
23 - (instancetype)init NS_UNAVAILABLE; | 24 - (instancetype)init NS_UNAVAILABLE; |
24 | 25 |
25 // Sets a script message handler. Multiple message handlers can be added for | 26 // Sets a script message handler. Multiple message handlers can be added for |
26 // the same message name and long as |webView| are different. Setting |handler| | 27 // the same message name and long as |webView| are different. Setting |handler| |
27 // for the same |name| and |webView| pair is an error. |handler| will be called | 28 // for the same |name| and |webView| pair is an error. |handler| will be called |
28 // if WKScriptMessage sent by WKUserContentController will match both the |name| | 29 // if WKScriptMessage sent by WKUserContentController will match both the |name| |
29 // and the |webView|. | 30 // and the |webView|. |
30 - (void)setScriptMessageHandler:(void (^)(WKScriptMessage*))handler | 31 - (void)setScriptMessageHandler:(void (^)(WKScriptMessage*))handler |
31 name:(NSString*)messageName | 32 name:(NSString*)messageName |
32 webView:(WKWebView*)webView; | 33 webView:(WKWebView*)webView; |
33 | 34 |
34 // Removes a specific message handler. | 35 // Removes a specific message handler. |
35 - (void)removeScriptMessageHandlerForName:(NSString*)messageName | 36 - (void)removeScriptMessageHandlerForName:(NSString*)messageName |
36 webView:(WKWebView*)webView; | 37 webView:(WKWebView*)webView; |
37 | 38 |
38 // Removes all message handlers for the given |webView|. | 39 // Removes all message handlers for the given |webView|. |
39 - (void)removeAllScriptMessageHandlersForWebView:(WKWebView*)webView; | 40 - (void)removeAllScriptMessageHandlersForWebView:(WKWebView*)webView; |
40 | 41 |
41 @end | 42 @end |
42 | 43 |
43 #endif // IOS_WEB_WEB_STATE_UI_CRW_WK_SCRIPT_MESSAGE_ROUTER_H_ | 44 #endif // IOS_WEB_WEB_STATE_UI_CRW_WK_SCRIPT_MESSAGE_ROUTER_H_ |
OLD | NEW |