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

Catch EvalError thrown by element.js in translate.

CSP can prevent eval and will cause this error:
"refused to evaluate a string as javascript because 'unsafe-eval'"

This fails silently on iOS so we need to catch it.

Bug: 686364
Change-Id: I5de275576670846dffc29f9f2c3916259196e70f
Reviewed-on: https://chromium-review.googlesource.com/1183944Reviewed-by: default avatarDavid Roger <droger@chromium.org>
Commit-Queue: John Wu <jzw@chromium.org>
Cr-Commit-Position: refs/heads/master@{#586055}
parent 4bad1cdf
......@@ -301,6 +301,16 @@ cr.googleTranslate = (function() {
lib.restore();
},
/**
* Called when an error is caught while executing script fetched in
* translate_script.cc.
*/
onTranslateElementError: function(error) {
errorCode = ERROR['UNEXPECTED_SCRIPT_ERROR'];
// Delayed so |readyCallback| has time to be defined.
setTimeout(invokeReadyCallback, 100);
},
/**
* Entry point called by the Translate Element once it has been injected in
* the page.
......
......@@ -161,7 +161,14 @@ void TranslateScript::OnScriptFetchComplete(bool success,
ui::ResourceBundle::GetSharedInstance().GetRawDataResource(
IDR_TRANSLATE_JS);
str.AppendToString(&data_);
data_ += data;
// Wrap |data| in try/catch block to handle unexpected script errors.
const char* format =
"try {"
" %s;"
"} catch (error) {"
" cr.googleTranslate.onTranslateElementError(error);"
"};";
base::StringAppendF(&data_, format, data.c_str());
// We'll expire the cached script after some time, to make sure long
// running browsers still get fixes that might get pushed with newer
......
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