summaryrefslogtreecommitdiffstats
path: root/ios/web
diff options
context:
space:
mode:
authoreugenebut <eugenebut@chromium.org>2015-11-10 14:06:48 -0800
committerCommit bot <commit-bot@chromium.org>2015-11-10 22:07:27 +0000
commit8a75e248a594471fbf75d84f404f9450e3fa3315 (patch)
tree35e80f19987f97343f619d5a85d9dd757d96bf70 /ios/web
parent558d9d52420895d6456ff80afae57544208a3557 (diff)
downloadchromium_src-8a75e248a594471fbf75d84f404f9450e3fa3315.zip
chromium_src-8a75e248a594471fbf75d84f404f9450e3fa3315.tar.gz
chromium_src-8a75e248a594471fbf75d84f404f9450e3fa3315.tar.bz2
[ios] Do not copy JS evaluation handlers before passing to WKWebView.
WKWebView used to crash on deallocation when flushing scripts that did not finish the execution but had a completion handler. This crash has been fixed in iOS9, so this CL removes a crash workaround. BUG=None Review URL: https://codereview.chromium.org/1416743008 Cr-Commit-Position: refs/heads/master@{#358924}
Diffstat (limited to 'ios/web')
-rw-r--r--ios/web/web_state/ui/web_view_js_utils.mm22
1 files changed, 8 insertions, 14 deletions
diff --git a/ios/web/web_state/ui/web_view_js_utils.mm b/ios/web/web_state/ui/web_view_js_utils.mm
index 8f7b202..bd5b943 100644
--- a/ios/web/web_state/ui/web_view_js_utils.mm
+++ b/ios/web/web_state/ui/web_view_js_utils.mm
@@ -56,22 +56,16 @@ void EvaluateJavaScript(WKWebView* web_view,
NSString* script,
JavaScriptCompletion completion_handler) {
DCHECK([script length]);
- // __block qualifier ensures that web_view_completion_handler is correctly
- // captured by itself.
- __block void (^web_view_completion_handler)(id, NSError*) = nil;
- // Do not create a web_view_completion_handler if no |handler| is passed to
- // this function. This results in no creation of an unnecessary block.
+ void (^web_view_completion_handler)(id, NSError*) = nil;
+ // Do not create a web_view_completion_handler if no |completion_handler| is
+ // passed to this function. WKWebView guarantees to call all completion
+ // handlers before deallocation. Passing nil as completion handler (when
+ // appropriate) may speed up web view deallocation, because there will be no
+ // need to call those completion handlers.
if (completion_handler) {
- // WKWebView crashes on deallocation when it flushes scripts that did not
- // finish the execution but have |completion_handler|. Passing
- // |completion_handler| ownership to the block itself and keeping it alive
- // until it's executed fixes the crash. No memory leak is expected since
- // |completion_handler| is always executed even if WKWebView is deallocated.
- // https://bugs.webkit.org/show_bug.cgi?id=140203
- web_view_completion_handler = [^(id result, NSError* error) {
+ web_view_completion_handler = ^(id result, NSError* error) {
completion_handler(UIResultFromWKResult(result), error);
- [web_view_completion_handler autorelease];
- } copy];
+ };
}
[web_view evaluateJavaScript:script
completionHandler:web_view_completion_handler];