Commit ae7aa895 authored by stkhapugin's avatar stkhapugin Committed by Commit bot

Converts part of ios/web/ui to ARC.

Notable changes:
* ios/web/webui/crw_web_ui_page_builder.mm has a block that had a
   __block reference to itself. Before ARC __block means "do not retain
   when being captured in a block", but with ARC it is captured. So I
   added an additional variable of __weak __block type instead.

* One WeakNSObject in mojo_facade.h could not be removed because it is
  included from non-ARC code. WeakNSObject is functional in ARC but is
  not preferred. Filed crbug.com/639326 to track future removal of
  this.

BUG=639327
TEST=None

Review-Url: https://codereview.chromium.org/2340343002
Cr-Commit-Position: refs/heads/master@{#419458}
parent 97fbce44
...@@ -97,6 +97,21 @@ source_set("web_arc") { ...@@ -97,6 +97,21 @@ source_set("web_arc") {
"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",
"webui/crw_web_ui_manager.h",
"webui/crw_web_ui_manager.mm",
"webui/crw_web_ui_page_builder.h",
"webui/crw_web_ui_page_builder.mm",
"webui/mojo_facade.h",
"webui/mojo_facade.mm",
"webui/mojo_js_constants.cc",
"webui/mojo_js_constants.h",
"webui/shared_resources_data_source_ios.h",
"webui/shared_resources_data_source_ios.mm",
"webui/url_data_manager_ios.cc",
"webui/url_data_manager_ios.h",
"webui/url_data_manager_ios_backend.h",
"webui/url_data_manager_ios_backend.mm",
"webui/url_data_source_ios.mm",
] ]
libs = [ "WebKit.framework" ] libs = [ "WebKit.framework" ]
...@@ -267,21 +282,6 @@ source_set("web") { ...@@ -267,21 +282,6 @@ source_set("web") {
"web_state/web_view_internal_creation_util.mm", "web_state/web_view_internal_creation_util.mm",
"web_state/wk_web_view_security_util.h", "web_state/wk_web_view_security_util.h",
"web_state/wk_web_view_security_util.mm", "web_state/wk_web_view_security_util.mm",
"webui/crw_web_ui_manager.h",
"webui/crw_web_ui_manager.mm",
"webui/crw_web_ui_page_builder.h",
"webui/crw_web_ui_page_builder.mm",
"webui/mojo_facade.h",
"webui/mojo_facade.mm",
"webui/mojo_js_constants.cc",
"webui/mojo_js_constants.h",
"webui/shared_resources_data_source_ios.h",
"webui/shared_resources_data_source_ios.mm",
"webui/url_data_manager_ios.cc",
"webui/url_data_manager_ios.h",
"webui/url_data_manager_ios_backend.h",
"webui/url_data_manager_ios_backend.mm",
"webui/url_data_source_ios.mm",
"webui/url_data_source_ios_impl.cc", "webui/url_data_source_ios_impl.cc",
"webui/url_data_source_ios_impl.h", "webui/url_data_source_ios_impl.h",
"webui/url_fetcher_block_adapter.h", "webui/url_fetcher_block_adapter.h",
......
...@@ -25,6 +25,10 @@ ...@@ -25,6 +25,10 @@
#include "mojo/public/js/constants.h" #include "mojo/public/js/constants.h"
#import "net/base/mac/url_conversions.h" #import "net/base/mac/url_conversions.h"
#if !defined(__has_feature) || !__has_feature(objc_arc)
#error "This file requires ARC support."
#endif
namespace { namespace {
// Prefix for history.requestFavicon JavaScript message. // Prefix for history.requestFavicon JavaScript message.
const char kScriptCommandPrefix[] = "webui"; const char kScriptCommandPrefix[] = "webui";
...@@ -98,7 +102,6 @@ const char kScriptCommandPrefix[] = "webui"; ...@@ -98,7 +102,6 @@ const char kScriptCommandPrefix[] = "webui";
- (void)dealloc { - (void)dealloc {
[self resetWebState]; [self resetWebState];
[super dealloc];
} }
#pragma mark - CRWWebStateObserver Methods #pragma mark - CRWWebStateObserver Methods
...@@ -214,7 +217,7 @@ const char kScriptCommandPrefix[] = "webui"; ...@@ -214,7 +217,7 @@ const char kScriptCommandPrefix[] = "webui";
// Retrieve favicon resource and set favicon background image via JavaScript. // Retrieve favicon resource and set favicon background image via JavaScript.
base::WeakNSObject<CRWWebUIManager> weakSelf(self); base::WeakNSObject<CRWWebUIManager> weakSelf(self);
void (^faviconHandler)(NSData*) = ^void(NSData* data) { void (^faviconHandler)(NSData*) = ^void(NSData* data) {
base::scoped_nsobject<CRWWebUIManager> strongSelf([weakSelf retain]); base::scoped_nsobject<CRWWebUIManager> strongSelf(weakSelf);
if (!strongSelf) if (!strongSelf)
return; return;
NSString* base64EncodedResource = [data base64EncodedStringWithOptions:0]; NSString* base64EncodedResource = [data base64EncodedStringWithOptions:0];
......
...@@ -69,7 +69,7 @@ class MockURLFetcherBlockAdapter : public URLFetcherBlockAdapter { ...@@ -69,7 +69,7 @@ class MockURLFetcherBlockAdapter : public URLFetcherBlockAdapter {
URLFetcherBlockAdapterCompletion completion_handler) URLFetcherBlockAdapterCompletion completion_handler)
: URLFetcherBlockAdapter(url, request_context, completion_handler), : URLFetcherBlockAdapter(url, request_context, completion_handler),
url_(url), url_(url),
completion_handler_(completion_handler) {} completion_handler_([completion_handler copy]) {}
void Start() override { void Start() override {
if (url_.spec() == kFaviconUrl) { if (url_.spec() == kFaviconUrl) {
......
...@@ -8,12 +8,15 @@ ...@@ -8,12 +8,15 @@
#include <string> #include <string>
#include <vector> #include <vector>
#include "base/ios/weak_nsobject.h"
#include "base/logging.h" #include "base/logging.h"
#include "base/mac/bundle_locations.h" #include "base/mac/bundle_locations.h"
#include "base/mac/scoped_nsobject.h" #include "base/mac/scoped_nsobject.h"
#include "base/strings/sys_string_conversions.h" #include "base/strings/sys_string_conversions.h"
#if !defined(__has_feature) || !__has_feature(objc_arc)
#error "This file requires ARC support."
#endif
namespace { namespace {
// Prefix for script tags. Used to locate JavaScript subresources. // Prefix for script tags. Used to locate JavaScript subresources.
NSString* const kJSTagPrefix = @"<script src=\""; NSString* const kJSTagPrefix = @"<script src=\"";
...@@ -92,7 +95,7 @@ NSString* const kWebUIJSURL = @"chrome://resources/js/ios/web_ui.js"; ...@@ -92,7 +95,7 @@ NSString* const kWebUIJSURL = @"chrome://resources/js/ios/web_ui.js";
@implementation CRWWebUIPageBuilder { @implementation CRWWebUIPageBuilder {
// Delegate for requesting resources. // Delegate for requesting resources.
base::WeakNSProtocol<id<CRWWebUIPageBuilderDelegate>> _delegate; __weak id<CRWWebUIPageBuilderDelegate> _delegate;
} }
#pragma mark - Public Methods #pragma mark - Public Methods
...@@ -104,7 +107,7 @@ NSString* const kWebUIJSURL = @"chrome://resources/js/ios/web_ui.js"; ...@@ -104,7 +107,7 @@ NSString* const kWebUIJSURL = @"chrome://resources/js/ios/web_ui.js";
- (instancetype)initWithDelegate:(id<CRWWebUIPageBuilderDelegate>)delegate { - (instancetype)initWithDelegate:(id<CRWWebUIPageBuilderDelegate>)delegate {
if (self = [super init]) { if (self = [super init]) {
_delegate.reset(delegate); _delegate = delegate;
} }
return self; return self;
} }
...@@ -132,10 +135,11 @@ NSString* const kWebUIJSURL = @"chrome://resources/js/ios/web_ui.js"; ...@@ -132,10 +135,11 @@ NSString* const kWebUIJSURL = @"chrome://resources/js/ios/web_ui.js";
return; return;
} }
__block std::map<GURL, std::string> subresources; __block std::map<GURL, std::string> subresources;
base::WeakNSObject<CRWWebUIPageBuilder> weakSelf(self); __weak CRWWebUIPageBuilder* weakSelf = self;
// Completion handler for subresource loads. // Completion handler for subresource loads.
__block web::WebUIDelegateCompletion subresourceHandler = nil; __block __weak web::WebUIDelegateCompletion weakSubresourceHandler = nil;
subresourceHandler = [[^(NSString* subresource, const GURL& subresourceURL) { web::WebUIDelegateCompletion subresourceHandler = [^(
NSString* subresource, const GURL& subresourceURL) {
// Import statements in CSS resources are also loaded. // Import statements in CSS resources are also loaded.
if ([self isCSSSubresourceURL:subresourceURL]) { if ([self isCSSSubresourceURL:subresourceURL]) {
NSSet* URLStrings = [weakSelf URLStringsFromCSS:subresource]; NSSet* URLStrings = [weakSelf URLStringsFromCSS:subresource];
...@@ -146,7 +150,7 @@ NSString* const kWebUIJSURL = @"chrome://resources/js/ios/web_ui.js"; ...@@ -146,7 +150,7 @@ NSString* const kWebUIJSURL = @"chrome://resources/js/ios/web_ui.js";
sourceURL:subresourceURL]; sourceURL:subresourceURL];
++pendingSubresourceCount; ++pendingSubresourceCount;
[weakSelf fetchResourceWithURL:URL [weakSelf fetchResourceWithURL:URL
completionHandler:subresourceHandler]; completionHandler:weakSubresourceHandler];
} }
} }
subresources[subresourceURL] = base::SysNSStringToUTF8(subresource); subresources[subresourceURL] = base::SysNSStringToUTF8(subresource);
...@@ -157,7 +161,9 @@ NSString* const kWebUIJSURL = @"chrome://resources/js/ios/web_ui.js"; ...@@ -157,7 +161,9 @@ NSString* const kWebUIJSURL = @"chrome://resources/js/ios/web_ui.js";
[weakSelf flattenHTML:webUIHTML withSubresources:subresources]; [weakSelf flattenHTML:webUIHTML withSubresources:subresources];
completionHandler(webUIHTML); completionHandler(webUIHTML);
} }
} copy] autorelease]; } copy];
weakSubresourceHandler = subresourceHandler;
for (NSString* URLString in subresourceURLStrings) { for (NSString* URLString in subresourceURLStrings) {
// chrome://resources/js/ios/web_ui.js is skipped because it is // chrome://resources/js/ios/web_ui.js is skipped because it is
......
...@@ -17,6 +17,10 @@ ...@@ -17,6 +17,10 @@
#include "mojo/public/cpp/system/core.h" #include "mojo/public/cpp/system/core.h"
#include "services/shell/public/interfaces/interface_provider.mojom.h" #include "services/shell/public/interfaces/interface_provider.mojom.h"
#if !defined(__has_feature) || !__has_feature(objc_arc)
#error "This file requires ARC support."
#endif
namespace web { namespace web {
namespace { namespace {
......
...@@ -15,6 +15,10 @@ ...@@ -15,6 +15,10 @@
#include "ui/resources/grit/webui_resources.h" #include "ui/resources/grit/webui_resources.h"
#include "ui/resources/grit/webui_resources_map.h" #include "ui/resources/grit/webui_resources_map.h"
#if !defined(__has_feature) || !__has_feature(objc_arc)
#error "This file requires ARC support."
#endif
namespace web { namespace web {
namespace { namespace {
......
...@@ -36,6 +36,10 @@ ...@@ -36,6 +36,10 @@
#include "net/url_request/url_request_job_factory.h" #include "net/url_request/url_request_job_factory.h"
#include "url/url_util.h" #include "url/url_util.h"
#if !defined(__has_feature) || !__has_feature(objc_arc)
#error "This file requires ARC support."
#endif
using web::WebThread; using web::WebThread;
namespace web { namespace web {
......
...@@ -8,6 +8,10 @@ ...@@ -8,6 +8,10 @@
#include "ios/web/webui/url_data_manager_ios.h" #include "ios/web/webui/url_data_manager_ios.h"
#include "net/url_request/url_request.h" #include "net/url_request/url_request.h"
#if !defined(__has_feature) || !__has_feature(objc_arc)
#error "This file requires ARC support."
#endif
namespace web { namespace web {
void URLDataSourceIOS::Add(BrowserState* browser_state, void URLDataSourceIOS::Add(BrowserState* browser_state,
......
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