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 #import "ios/web/web_state/ui/crw_wk_script_message_router.h" | 5 #import "ios/web/web_state/ui/crw_wk_script_message_router.h" |
6 | 6 |
7 #import "base/logging.h" | 7 #import "base/logging.h" |
8 #import "base/mac/scoped_nsobject.h" | 8 #import "base/mac/scoped_nsobject.h" |
9 | 9 |
10 @interface CRWWKScriptMessageRouter ()<WKScriptMessageHandler> | 10 @interface CRWWKScriptMessageRouter ()<WKScriptMessageHandler> |
(...skipping 82 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
93 ((void (^)(WKScriptMessage*))handler)(message); | 93 ((void (^)(WKScriptMessage*))handler)(message); |
94 } | 94 } |
95 } | 95 } |
96 | 96 |
97 #pragma mark - | 97 #pragma mark - |
98 #pragma mark Implementation | 98 #pragma mark Implementation |
99 | 99 |
100 - (void)tryRemoveScriptMessageHandlerForName:(NSString*)messageName | 100 - (void)tryRemoveScriptMessageHandlerForName:(NSString*)messageName |
101 webView:(WKWebView*)webView { | 101 webView:(WKWebView*)webView { |
102 NSMapTable* webViewToHandlerMap = [_handlers objectForKey:messageName]; | 102 NSMapTable* webViewToHandlerMap = [_handlers objectForKey:messageName]; |
103 if (![webViewToHandlerMap objectForKey:webView]) | 103 id handler = [webViewToHandlerMap objectForKey:webView]; |
| 104 if (!handler) |
104 return; | 105 return; |
| 106 // Extend the lifetime of |handler| so removeScriptMessageHandlerForName: can |
| 107 // be called from inside of |handler|. |
| 108 [[handler retain] autorelease]; |
105 if (webViewToHandlerMap.count == 1) { | 109 if (webViewToHandlerMap.count == 1) { |
106 [_handlers removeObjectForKey:messageName]; | 110 [_handlers removeObjectForKey:messageName]; |
107 [_userContentController removeScriptMessageHandlerForName:messageName]; | 111 [_userContentController removeScriptMessageHandlerForName:messageName]; |
108 } else { | 112 } else { |
109 [webViewToHandlerMap removeObjectForKey:webView]; | 113 [webViewToHandlerMap removeObjectForKey:webView]; |
110 } | 114 } |
111 } | 115 } |
112 | 116 |
113 @end | 117 @end |
OLD | NEW |