Commit df9af169 authored by John Z Wu's avatar John Z Wu Committed by Commit Bot

Fix translate retry logic by re-injecting the scripts.

Currently retry only re-checks the ready status of the scripts.
To properly retry, the scripts need to be reinjected so a new ready
status can be provided.

Bug: 879821
Change-Id: I3f188a3358435304006c907b7dd3799d907c6a80
Reviewed-on: https://chromium-review.googlesource.com/1200573
Commit-Queue: John Wu <jzw@chromium.org>
Reviewed-by: default avatarDavid Roger <droger@chromium.org>
Reviewed-by: default avatarEugene But <eugenebut@chromium.org>
Cr-Commit-Position: refs/heads/master@{#589320}
parent 92625bc1
...@@ -162,8 +162,6 @@ cr.googleTranslate = (function() { ...@@ -162,8 +162,6 @@ cr.googleTranslate = (function() {
function invokeReadyCallback() { function invokeReadyCallback() {
if (readyCallback) { if (readyCallback) {
readyCallback(); readyCallback();
// Don't notify ready if already notified.
readyCallback = null;
} }
} }
......
...@@ -57,6 +57,24 @@ ...@@ -57,6 +57,24 @@
#pragma mark - #pragma mark -
#pragma mark CRWJSInjectionManager methods #pragma mark CRWJSInjectionManager methods
- (void)inject {
NSString* script = [self injectionContent];
// Reset any state if previously injected.
if ([self hasBeenInjected]) {
NSString* resetScript =
@"try {"
" cr.googleTranslate.revert();"
"} catch (e) {"
"}";
script = [resetScript stringByAppendingString:script];
}
// The scripts need to be re-injected to ensure that the logic that
// initializes translate can be restarted properly.
[[self receiver] injectScript:script forClass:[self class]];
}
- (NSString*)injectionContent { - (NSString*)injectionContent {
DCHECK(_translationScript); DCHECK(_translationScript);
NSString* translationScript = _translationScript; NSString* translationScript = _translationScript;
......
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