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