Index: ios/web/web_state/ui/wk_web_view_configuration_provider.mm |
diff --git a/ios/web/web_state/ui/wk_web_view_configuration_provider.mm b/ios/web/web_state/ui/wk_web_view_configuration_provider.mm |
index 7527133963eaf71a5d883e8b9da24a8d72e6df5a..209746341d51ce18344f1a7e7b68b8e944b77421 100644 |
--- a/ios/web/web_state/ui/wk_web_view_configuration_provider.mm |
+++ b/ios/web/web_state/ui/wk_web_view_configuration_provider.mm |
@@ -14,6 +14,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 web { |
namespace { |
@@ -23,10 +27,10 @@ const char kWKWebViewConfigProviderKeyName[] = "wk_web_view_config_provider"; |
// Returns an autoreleased instance of WKUserScript to be added to |
// configuration's userContentController. |
WKUserScript* InternalGetEarlyPageScript(BrowserState* browser_state) { |
- return [[[WKUserScript alloc] |
+ return [[WKUserScript alloc] |
initWithSource:GetEarlyPageScript(browser_state) |
injectionTime:WKUserScriptInjectionTimeAtDocumentStart |
- forMainFrameOnly:YES] autorelease]; |
+ forMainFrameOnly:YES]; |
} |
} // namespace |
@@ -70,7 +74,7 @@ WKWebViewConfigurationProvider::GetWebViewConfiguration() { |
addUserScript:InternalGetEarlyPageScript(browser_state_)]; |
} |
// Prevent callers from changing the internals of configuration. |
- return [[configuration_ copy] autorelease]; |
+ return [configuration_ copy]; |
} |
CRWWKScriptMessageRouter* |
@@ -88,9 +92,16 @@ WKWebViewConfigurationProvider::GetScriptMessageRouter() { |
void WKWebViewConfigurationProvider::Purge() { |
DCHECK([NSThread isMainThread]); |
#if DCHECK_IS_ON() |
- base::WeakNSObject<id> weak_configuration(configuration_); |
- base::WeakNSObject<id> weak_router(router_); |
- base::WeakNSObject<id> weak_process_pool([configuration_ processPool]); |
+ base::WeakNSObject<id> weak_configuration; |
+ base::WeakNSObject<id> weak_router; |
+ // It's expected that the weak objects auto-nil by the end of this method. |
+ // They should not be in any autoreleasepool that might keep them alive. |
+ @autoreleasepool { |
+ weak_configuration.reset(configuration_); |
+ weak_router.reset(router_); |
+ } |
+// TODO(crbug.com/522672): See commented out DCHECK below. |
+// __weak id weak_process_pool = [configuration_ processPool]; |
#endif // DCHECK_IS_ON() |
configuration_.reset(); |
router_.reset(); |