Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(322)

Unified Diff: chrome/browser/automation/automation_provider.cc

Issue 3078026: New translate pyauto hook: select translate target language (Closed) Base URL: http://src.chromium.org/git/chromium.git
Patch Set: Final Created 10 years, 4 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
« no previous file with comments | « no previous file | chrome/test/pyautolib/pyauto.py » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: chrome/browser/automation/automation_provider.cc
diff --git a/chrome/browser/automation/automation_provider.cc b/chrome/browser/automation/automation_provider.cc
index 8f3e136869a79919c08b4d98ebdd949016dda870..e59c07a2dcb8ac5f9d42e7ec7a514ee2321ef18c 100644
--- a/chrome/browser/automation/automation_provider.cc
+++ b/chrome/browser/automation/automation_provider.cc
@@ -2830,6 +2830,40 @@ void AutomationProvider::SelectTranslateOption(Browser* browser,
new PageTranslatedObserver(this, reply_message, tab_contents);
translate_bar->Translate();
return;
+ } else if (option == "set_target_language") {
+ string16 target_language;
+ if (!args->GetString("target_language", &target_language)) {
+ AutomationJSONReply(this, reply_message).
+ SendError("Must include target_language string.");
+ return;
+ }
+ // Get the target language index based off of the language name.
+ int target_language_index = -1;
+ for (int i = 0; i < translate_bar->GetLanguageCount(); i++) {
+ if (translate_bar->GetLanguageDisplayableNameAt(i) == target_language) {
+ target_language_index = i;
+ break;
+ }
+ }
+ if (target_language_index == -1) {
+ AutomationJSONReply(this, reply_message)
+ .SendError("Invalid target language string.");
+ return;
+ }
+ // If the page has already been translated it will be translated again to
+ // the new language. The observer will wait until the page has been
+ // translated to reply.
+ if (translate_bar->type() == TranslateInfoBarDelegate::AFTER_TRANSLATE) {
+ new PageTranslatedObserver(this, reply_message, tab_contents);
+ translate_bar->SetTargetLanguage(target_language_index);
+ return;
+ }
+ // Otherwise just send the reply back immediately.
+ translate_bar->SetTargetLanguage(target_language_index);
+ scoped_ptr<DictionaryValue> return_value(new DictionaryValue);
+ return_value->SetBoolean("translation_success", true);
+ AutomationJSONReply(this, reply_message).SendSuccess(return_value.get());
+ return;
}
AutomationJSONReply reply(this, reply_message);
« no previous file with comments | « no previous file | chrome/test/pyautolib/pyauto.py » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698