Commit 2a4ea729 authored by stkhapugin's avatar stkhapugin Committed by Commit bot

[ARC] Converts parts of ios/web/web_state to ARC.

Notable changes:
 * CRWWebViewProxyImpl now uses synthesized getter and ivar for
property contentView
 * CRWJSPOSTRequestLoader now does not create a retain cycle of
CRWWKScriptMessageRouter objects. The cycle seems to have been harmless,
but it definitely brings no value, and it's better to not have it.

BUG=651830

Review-Url: https://codereview.chromium.org/2380323002
Cr-Commit-Position: refs/heads/master@{#422776}
parent 38715910
...@@ -176,6 +176,21 @@ source_set("web_arc") { ...@@ -176,6 +176,21 @@ source_set("web_arc") {
"web_state/credential.cc", "web_state/credential.cc",
"web_state/crw_pass_kit_downloader.h", "web_state/crw_pass_kit_downloader.h",
"web_state/crw_pass_kit_downloader.mm", "web_state/crw_pass_kit_downloader.mm",
"web_state/crw_web_view_proxy_impl.h",
"web_state/crw_web_view_proxy_impl.mm",
"web_state/crw_web_view_scroll_view_proxy.mm",
"web_state/error_translation_util.h",
"web_state/error_translation_util.mm",
"web_state/global_web_state_event_tracker.h",
"web_state/global_web_state_event_tracker.mm",
"web_state/global_web_state_observer.cc",
"web_state/js/credential_util.mm",
"web_state/js/crw_js_injection_manager.mm",
"web_state/js/crw_js_injection_receiver.mm",
"web_state/js/crw_js_plugin_placeholder_manager.h",
"web_state/js/crw_js_plugin_placeholder_manager.mm",
"web_state/js/crw_js_post_request_loader.h",
"web_state/js/crw_js_post_request_loader.mm",
"web_thread_impl.cc", "web_thread_impl.cc",
"web_thread_impl.h", "web_thread_impl.h",
"web_view_creation_util.mm", "web_view_creation_util.mm",
...@@ -237,21 +252,6 @@ source_set("web") { ...@@ -237,21 +252,6 @@ source_set("web") {
] ]
sources = [ sources = [
"web_state/crw_web_view_proxy_impl.h",
"web_state/crw_web_view_proxy_impl.mm",
"web_state/crw_web_view_scroll_view_proxy.mm",
"web_state/error_translation_util.h",
"web_state/error_translation_util.mm",
"web_state/global_web_state_event_tracker.h",
"web_state/global_web_state_event_tracker.mm",
"web_state/global_web_state_observer.cc",
"web_state/js/credential_util.mm",
"web_state/js/crw_js_injection_manager.mm",
"web_state/js/crw_js_injection_receiver.mm",
"web_state/js/crw_js_plugin_placeholder_manager.h",
"web_state/js/crw_js_plugin_placeholder_manager.mm",
"web_state/js/crw_js_post_request_loader.h",
"web_state/js/crw_js_post_request_loader.mm",
"web_state/js/crw_js_window_id_manager.h", "web_state/js/crw_js_window_id_manager.h",
"web_state/js/crw_js_window_id_manager.mm", "web_state/js/crw_js_window_id_manager.mm",
"web_state/js/page_script_util.h", "web_state/js/page_script_util.h",
......
...@@ -31,9 +31,10 @@ ...@@ -31,9 +31,10 @@
@property(nonatomic, readonly) CGRect frame; @property(nonatomic, readonly) CGRect frame;
@property(nonatomic, getter=isScrollEnabled) BOOL scrollEnabled; @property(nonatomic, getter=isScrollEnabled) BOOL scrollEnabled;
@property(nonatomic, assign) BOOL bounces; @property(nonatomic, assign) BOOL bounces;
@property(nonatomic, readonly) UIPanGestureRecognizer* panGestureRecognizer; @property(weak, nonatomic, readonly)
UIPanGestureRecognizer* panGestureRecognizer;
// Returns the scrollview's gesture recognizers. // Returns the scrollview's gesture recognizers.
@property(nonatomic, readonly) NSArray* gestureRecognizers; @property(weak, nonatomic, readonly) NSArray* gestureRecognizers;
// Calls UIScrollView's implementation of setContentInset: directly. This // Calls UIScrollView's implementation of setContentInset: directly. This
// bypasses a very slow update path in UIWebView. // bypasses a very slow update path in UIWebView.
......
...@@ -5,12 +5,15 @@ ...@@ -5,12 +5,15 @@
#import "ios/web/web_state/crw_web_view_proxy_impl.h" #import "ios/web/web_state/crw_web_view_proxy_impl.h"
#include "base/ios/ios_util.h" #include "base/ios/ios_util.h"
#include "base/ios/weak_nsobject.h"
#include "base/mac/scoped_nsobject.h" #include "base/mac/scoped_nsobject.h"
#import "ios/web/public/web_state/crw_web_view_scroll_view_proxy.h" #import "ios/web/public/web_state/crw_web_view_scroll_view_proxy.h"
#import "ios/web/public/web_state/ui/crw_content_view.h" #import "ios/web/public/web_state/ui/crw_content_view.h"
#import "ios/web/web_state/ui/crw_web_controller.h" #import "ios/web/web_state/ui/crw_web_controller.h"
#if !defined(__has_feature) || !__has_feature(objc_arc)
#error "This file requires ARC support."
#endif
namespace { namespace {
// Returns the first responder in the subviews of |view|, or nil if no view in // Returns the first responder in the subviews of |view|, or nil if no view in
...@@ -66,20 +69,20 @@ UIView* GetFirstResponderSubview(UIView* view) { ...@@ -66,20 +69,20 @@ UIView* GetFirstResponderSubview(UIView* view) {
@end @end
@implementation CRWWebViewProxyImpl { @implementation CRWWebViewProxyImpl {
base::WeakNSObject<CRWContentView> _contentView; __weak CRWWebController* _webController;
base::WeakNSObject<CRWWebController> _webController;
base::scoped_nsobject<NSMutableDictionary> _registeredInsets; base::scoped_nsobject<NSMutableDictionary> _registeredInsets;
// The WebViewScrollViewProxy is a wrapper around the web view's // The WebViewScrollViewProxy is a wrapper around the web view's
// UIScrollView to give components access in a limited and controlled manner. // UIScrollView to give components access in a limited and controlled manner.
base::scoped_nsobject<CRWWebViewScrollViewProxy> _contentViewScrollViewProxy; base::scoped_nsobject<CRWWebViewScrollViewProxy> _contentViewScrollViewProxy;
} }
@synthesize contentView = _contentView;
- (instancetype)initWithWebController:(CRWWebController*)webController { - (instancetype)initWithWebController:(CRWWebController*)webController {
self = [super init]; self = [super init];
if (self) { if (self) {
DCHECK(webController); DCHECK(webController);
_registeredInsets.reset([[NSMutableDictionary alloc] init]); _registeredInsets.reset([[NSMutableDictionary alloc] init]);
_webController.reset(webController); _webController = webController;
_contentViewScrollViewProxy.reset([[CRWWebViewScrollViewProxy alloc] init]); _contentViewScrollViewProxy.reset([[CRWWebViewScrollViewProxy alloc] init]);
} }
return self; return self;
...@@ -146,12 +149,8 @@ UIView* GetFirstResponderSubview(UIView* view) { ...@@ -146,12 +149,8 @@ UIView* GetFirstResponderSubview(UIView* view) {
[_registeredInsets removeObjectForKey:callerValue]; [_registeredInsets removeObjectForKey:callerValue];
} }
- (CRWContentView*)contentView {
return _contentView.get();
}
- (void)setContentView:(CRWContentView*)contentView { - (void)setContentView:(CRWContentView*)contentView {
_contentView.reset(contentView); _contentView = contentView;
[_contentViewScrollViewProxy setScrollView:contentView.scrollView]; [_contentViewScrollViewProxy setScrollView:contentView.scrollView];
} }
......
...@@ -4,14 +4,19 @@ ...@@ -4,14 +4,19 @@
#import "ios/web/public/web_state/crw_web_view_scroll_view_proxy.h" #import "ios/web/public/web_state/crw_web_view_scroll_view_proxy.h"
#import <objc/runtime.h>
#include "base/auto_reset.h" #include "base/auto_reset.h"
#import "base/ios/crb_protocol_observers.h" #import "base/ios/crb_protocol_observers.h"
#import "base/ios/weak_nsobject.h"
#include "base/mac/foundation_util.h" #include "base/mac/foundation_util.h"
#import "base/mac/scoped_nsobject.h" #import "base/mac/scoped_nsobject.h"
#if !defined(__has_feature) || !__has_feature(objc_arc)
#error "This file requires ARC support."
#endif
@interface CRWWebViewScrollViewProxy () { @interface CRWWebViewScrollViewProxy () {
base::WeakNSObject<UIScrollView> _scrollView; __weak UIScrollView* _scrollView;
base::scoped_nsobject<id> _observers; base::scoped_nsobject<id> _observers;
// When |_ignoreScroll| is set to YES, do not pass on -scrollViewDidScroll // When |_ignoreScroll| is set to YES, do not pass on -scrollViewDidScroll
// calls to observers. This is used by -setContentInsetFast, which needs to // calls to observers. This is used by -setContentInsetFast, which needs to
...@@ -36,15 +41,13 @@ ...@@ -36,15 +41,13 @@
self = [super init]; self = [super init];
if (self) { if (self) {
Protocol* protocol = @protocol(CRWWebViewScrollViewProxyObserver); Protocol* protocol = @protocol(CRWWebViewScrollViewProxyObserver);
_observers.reset( _observers.reset([CRBProtocolObservers observersWithProtocol:protocol]);
[[CRBProtocolObservers observersWithProtocol:protocol] retain]);
} }
return self; return self;
} }
- (void)dealloc { - (void)dealloc {
[self stopObservingScrollView:_scrollView]; [self stopObservingScrollView:_scrollView];
[super dealloc];
} }
- (void)addGestureRecognizer:(UIGestureRecognizer*)gestureRecognizer { - (void)addGestureRecognizer:(UIGestureRecognizer*)gestureRecognizer {
...@@ -71,7 +74,7 @@ ...@@ -71,7 +74,7 @@
DCHECK(!scrollView.delegate); DCHECK(!scrollView.delegate);
scrollView.delegate = self; scrollView.delegate = self;
[self startObservingScrollView:scrollView]; [self startObservingScrollView:scrollView];
_scrollView.reset(scrollView); _scrollView = scrollView;
[_observers webViewScrollViewProxyDidSetScrollView:self]; [_observers webViewScrollViewProxyDidSetScrollView:self];
} }
...@@ -141,9 +144,8 @@ ...@@ -141,9 +144,8 @@
// position, we can ignore these calls. // position, we can ignore these calls.
base::AutoReset<BOOL> autoReset(&_ignoreScroll, YES); base::AutoReset<BOOL> autoReset(&_ignoreScroll, YES);
CGPoint contentOffset = [_scrollView contentOffset]; CGPoint contentOffset = [_scrollView contentOffset];
_scrollView.get().contentOffset = _scrollView.contentOffset = CGPointMake(contentOffset.x, contentOffset.y + 1);
CGPointMake(contentOffset.x, contentOffset.y + 1); _scrollView.contentOffset = contentOffset;
_scrollView.get().contentOffset = contentOffset;
} }
- (void)setContentInset:(UIEdgeInsets)contentInset { - (void)setContentInset:(UIEdgeInsets)contentInset {
...@@ -264,7 +266,7 @@ ...@@ -264,7 +266,7 @@
ofObject:(id)object ofObject:(id)object
change:(NSDictionary*)change change:(NSDictionary*)change
context:(void*)context { context:(void*)context {
DCHECK_EQ(object, _scrollView.get()); DCHECK_EQ(object, _scrollView);
if ([keyPath isEqualToString:@"contentSize"]) if ([keyPath isEqualToString:@"contentSize"])
[_observers webViewScrollViewDidResetContentSize:self]; [_observers webViewScrollViewDidResetContentSize:self];
} }
......
...@@ -10,6 +10,10 @@ ...@@ -10,6 +10,10 @@
#include "base/mac/scoped_nsobject.h" #include "base/mac/scoped_nsobject.h"
#include "net/base/net_errors.h" #include "net/base/net_errors.h"
#if !defined(__has_feature) || !__has_feature(objc_arc)
#error "This file requires ARC support."
#endif
namespace web { namespace web {
namespace { namespace {
......
...@@ -11,6 +11,10 @@ ...@@ -11,6 +11,10 @@
#include "ios/web/public/web_state/web_state_observer.h" #include "ios/web/public/web_state/web_state_observer.h"
#include "ios/web/public/web_state/web_state_user_data.h" #include "ios/web/public/web_state/web_state_user_data.h"
#if !defined(__has_feature) || !__has_feature(objc_arc)
#error "This file requires ARC support."
#endif
namespace web { namespace web {
class WebStateEventForwarder; class WebStateEventForwarder;
......
...@@ -12,6 +12,10 @@ ...@@ -12,6 +12,10 @@
#include "url/gurl.h" #include "url/gurl.h"
#include "url/origin.h" #include "url/origin.h"
#if !defined(__has_feature) || !__has_feature(objc_arc)
#error "This file requires ARC support."
#endif
namespace { namespace {
// "type" value for a DictionaryValue representation of PasswordCredential. // "type" value for a DictionaryValue representation of PasswordCredential.
......
...@@ -13,12 +13,16 @@ ...@@ -13,12 +13,16 @@
#import "ios/web/public/web_state/js/crw_js_injection_receiver.h" #import "ios/web/public/web_state/js/crw_js_injection_receiver.h"
#import "ios/web/web_state/js/page_script_util.h" #import "ios/web/web_state/js/page_script_util.h"
#if !defined(__has_feature) || !__has_feature(objc_arc)
#error "This file requires ARC support."
#endif
@implementation CRWJSInjectionManager { @implementation CRWJSInjectionManager {
// JS to inject into the page. This may be nil if it has been purged due to // JS to inject into the page. This may be nil if it has been purged due to
// low memory. // low memory.
base::scoped_nsobject<NSString> _injectObject; base::scoped_nsobject<NSString> _injectObject;
// An object the can receive JavaScript injection. // An object the can receive JavaScript injection.
CRWJSInjectionReceiver* _receiver; // Weak. __weak CRWJSInjectionReceiver* _receiver;
} }
- (id)initWithReceiver:(CRWJSInjectionReceiver*)receiver { - (id)initWithReceiver:(CRWJSInjectionReceiver*)receiver {
...@@ -38,7 +42,6 @@ ...@@ -38,7 +42,6 @@
- (void)dealloc { - (void)dealloc {
[[NSNotificationCenter defaultCenter] removeObserver:self]; [[NSNotificationCenter defaultCenter] removeObserver:self];
[super dealloc];
} }
- (BOOL)hasBeenInjected { - (BOOL)hasBeenInjected {
......
...@@ -9,9 +9,13 @@ ...@@ -9,9 +9,13 @@
#import "ios/web/public/web_state/js/crw_js_injection_evaluator.h" #import "ios/web/public/web_state/js/crw_js_injection_evaluator.h"
#import "ios/web/public/web_state/js/crw_js_injection_manager.h" #import "ios/web/public/web_state/js/crw_js_injection_manager.h"
#if !defined(__has_feature) || !__has_feature(objc_arc)
#error "This file requires ARC support."
#endif
@implementation CRWJSInjectionReceiver { @implementation CRWJSInjectionReceiver {
// Used to evaluate JavaScripts. // Used to evaluate JavaScripts.
id<CRWJSInjectionEvaluator> _evaluator; __weak id<CRWJSInjectionEvaluator> _evaluator;
// Map from a CRWJSInjectionManager class to its instance created for this // Map from a CRWJSInjectionManager class to its instance created for this
// receiver. // receiver.
......
...@@ -8,6 +8,10 @@ ...@@ -8,6 +8,10 @@
#include "base/strings/sys_string_conversions.h" #include "base/strings/sys_string_conversions.h"
#include "ios/web/public/web_client.h" #include "ios/web/public/web_client.h"
#if !defined(__has_feature) || !__has_feature(objc_arc)
#error "This file requires ARC support."
#endif
@implementation CRWJSPluginPlaceholderManager @implementation CRWJSPluginPlaceholderManager
namespace { namespace {
......
...@@ -10,6 +10,10 @@ ...@@ -10,6 +10,10 @@
#import "ios/web/web_state/js/page_script_util.h" #import "ios/web/web_state/js/page_script_util.h"
#import "ios/web/web_state/ui/crw_wk_script_message_router.h" #import "ios/web/web_state/ui/crw_wk_script_message_router.h"
#if !defined(__has_feature) || !__has_feature(objc_arc)
#error "This file requires ARC support."
#endif
namespace { namespace {
// Escapes characters and encloses given string in quotes for use in JavaScript. // Escapes characters and encloses given string in quotes for use in JavaScript.
...@@ -62,7 +66,6 @@ NSString* const kSuccessHandlerName = @"POSTSuccessHandler"; ...@@ -62,7 +66,6 @@ NSString* const kSuccessHandlerName = @"POSTSuccessHandler";
- (void)dealloc { - (void)dealloc {
[[NSNotificationCenter defaultCenter] removeObserver:self]; [[NSNotificationCenter defaultCenter] removeObserver:self];
[super dealloc];
} }
- (NSString*)requestScript { - (NSString*)requestScript {
...@@ -82,12 +85,13 @@ NSString* const kSuccessHandlerName = @"POSTSuccessHandler"; ...@@ -82,12 +85,13 @@ NSString* const kSuccessHandlerName = @"POSTSuccessHandler";
DCHECK(completionHandler); DCHECK(completionHandler);
// Install error handling and success routers. // Install error handling and success routers.
__weak CRWWKScriptMessageRouter* weakRouter = messageRouter;
[messageRouter setScriptMessageHandler:^(WKScriptMessage* message) { [messageRouter setScriptMessageHandler:^(WKScriptMessage* message) {
// Cleaning up script handlers. // Cleaning up script handlers.
[messageRouter removeScriptMessageHandlerForName:kErrorHandlerName [weakRouter removeScriptMessageHandlerForName:kErrorHandlerName
webView:webView]; webView:webView];
[messageRouter removeScriptMessageHandlerForName:kSuccessHandlerName [weakRouter removeScriptMessageHandlerForName:kSuccessHandlerName
webView:webView]; webView:webView];
completionHandler(nil); completionHandler(nil);
} }
name:kSuccessHandlerName name:kSuccessHandlerName
...@@ -98,10 +102,10 @@ NSString* const kSuccessHandlerName = @"POSTSuccessHandler"; ...@@ -98,10 +102,10 @@ NSString* const kSuccessHandlerName = @"POSTSuccessHandler";
NSError* error = [NSError errorWithDomain:NSURLErrorDomain NSError* error = [NSError errorWithDomain:NSURLErrorDomain
code:statusCode.integerValue code:statusCode.integerValue
userInfo:nil]; userInfo:nil];
[messageRouter removeScriptMessageHandlerForName:kErrorHandlerName [weakRouter removeScriptMessageHandlerForName:kErrorHandlerName
webView:webView]; webView:webView];
[messageRouter removeScriptMessageHandlerForName:kSuccessHandlerName [weakRouter removeScriptMessageHandlerForName:kSuccessHandlerName
webView:webView]; webView:webView];
completionHandler(error); completionHandler(error);
} }
name:kErrorHandlerName name:kErrorHandlerName
...@@ -146,8 +150,8 @@ NSString* const kSuccessHandlerName = @"POSTSuccessHandler"; ...@@ -146,8 +150,8 @@ NSString* const kSuccessHandlerName = @"POSTSuccessHandler";
// This string is properly escaped by NSJSONSerialization. It needs to // This string is properly escaped by NSJSONSerialization. It needs to
// have no quotes since JavaScripts takes this parameter as an // have no quotes since JavaScripts takes this parameter as an
// Object<string, string>. // Object<string, string>.
return [[[NSString alloc] initWithData:headerData return [[NSString alloc] initWithData:headerData
encoding:NSUTF8StringEncoding] autorelease]; encoding:NSUTF8StringEncoding];
} }
} }
return @"{}"; return @"{}";
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment