Commit 9108e9a2 authored by eugenebut's avatar eugenebut Committed by Commit bot

[ios] improved retry logic for windowID injection.

Make windowID script return boolean result to indicate if retry is
necessary instead of retrying on exception.

BUG=628832

Review-Url: https://codereview.chromium.org/2189553003
Cr-Commit-Position: refs/heads/master@{#408232}
parent 2f06c3d5
......@@ -48,15 +48,26 @@ const size_t kUniqueKeyLength = 16;
NSString* script = [web::GetPageScript(@"window_id")
stringByReplacingOccurrencesOfString:@"$(WINDOW_ID)"
withString:_windowID];
// WKUserScript may not be injected yet. Make windowID script return boolean
// indicating whether the injection was successfull.
NSString* scriptWithResult = [NSString
stringWithFormat:@"if (!window.__gCrWeb) {false; } else { %@; true; }",
script];
base::WeakNSObject<CRWJSWindowIDManager> weakSelf(self);
[_webView evaluateJavaScript:script
[_webView evaluateJavaScript:scriptWithResult
completionHandler:^(id result, NSError* error) {
// TODO(crbug.com/628832): Refactor retry logic.
if (error.code == WKErrorJavaScriptExceptionOccurred) {
// This can happen if WKUserScript has not been injected yet.
// Retry if that's the case, because windowID injection is
// critical for the system to function.
if (error) {
DCHECK(error.code == WKErrorWebViewInvalidated ||
error.code == WKErrorWebContentProcessTerminated);
return;
}
DCHECK_EQ(CFBooleanGetTypeID(), CFGetTypeID(result));
if (![result boolValue]) {
// WKUserScript has not been injected yet. Retry window id
// injection, because it is critical for the system to
// function.
[weakSelf inject];
}
}];
......
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