| Index: ios/web/web_state/ui/crw_wk_script_message_router.mm
|
| diff --git a/ios/web/web_state/ui/crw_wk_script_message_router.mm b/ios/web/web_state/ui/crw_wk_script_message_router.mm
|
| index ed13ddb0b878def502fbd03555fc35f32ee2a154..295ab0bd891506a364eb49a2f71d2c97311648d7 100644
|
| --- a/ios/web/web_state/ui/crw_wk_script_message_router.mm
|
| +++ b/ios/web/web_state/ui/crw_wk_script_message_router.mm
|
| @@ -5,7 +5,10 @@
|
| #import "ios/web/web_state/ui/crw_wk_script_message_router.h"
|
|
|
| #include "base/logging.h"
|
| -#import "base/mac/scoped_nsobject.h"
|
| +
|
| +#if !defined(__has_feature) || !__has_feature(objc_arc)
|
| +#error "This file requires ARC support."
|
| +#endif
|
|
|
| @interface CRWWKScriptMessageRouter ()<WKScriptMessageHandler>
|
|
|
| @@ -13,23 +16,23 @@
|
| - (void)tryRemoveScriptMessageHandlerForName:(NSString*)messageName
|
| webView:(WKWebView*)webView;
|
|
|
| +@property(nonatomic, weak, readwrite)
|
| + WKUserContentController* userContentController;
|
| +
|
| @end
|
|
|
| @implementation CRWWKScriptMessageRouter {
|
| // Two level map of registed message handlers. Keys are message names and
|
| // values are more maps (where keys are web views and values are handlers).
|
| - base::scoped_nsobject<NSMutableDictionary> _handlers;
|
| - // Wrapped WKUserContentController.
|
| - base::scoped_nsobject<WKUserContentController> _userContentController;
|
| + NSMutableDictionary* _handlers;
|
| }
|
|
|
| +// Wrapped WKUserContentController.
|
| +@synthesize userContentController = _userContentController;
|
| +
|
| #pragma mark -
|
| #pragma mark Interface
|
|
|
| -- (WKUserContentController*)userContentController {
|
| - return _userContentController.get();
|
| -}
|
| -
|
| - (instancetype)init {
|
| NOTREACHED();
|
| return nil;
|
| @@ -39,8 +42,8 @@
|
| (WKUserContentController*)userContentController {
|
| DCHECK(userContentController);
|
| if ((self = [super init])) {
|
| - _handlers.reset([[NSMutableDictionary alloc] init]);
|
| - _userContentController.reset([userContentController retain]);
|
| + _handlers = [[NSMutableDictionary alloc] init];
|
| + _userContentController = userContentController;
|
| }
|
| return self;
|
| }
|
| @@ -100,12 +103,11 @@
|
| - (void)tryRemoveScriptMessageHandlerForName:(NSString*)messageName
|
| webView:(WKWebView*)webView {
|
| NSMapTable* webViewToHandlerMap = [_handlers objectForKey:messageName];
|
| - id handler = [webViewToHandlerMap objectForKey:webView];
|
| + NS_VALID_UNTIL_END_OF_SCOPE id handler =
|
| + [webViewToHandlerMap objectForKey:webView];
|
| if (!handler)
|
| return;
|
| - // Extend the lifetime of |handler| so removeScriptMessageHandlerForName: can
|
| - // be called from inside of |handler|.
|
| - [[handler retain] autorelease];
|
| +
|
| if (webViewToHandlerMap.count == 1) {
|
| [_handlers removeObjectForKey:messageName];
|
| [_userContentController removeScriptMessageHandlerForName:messageName];
|
|
|