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

Side by Side 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 unified diff | Download patch
« no previous file with comments | « no previous file | chrome/test/pyautolib/pyauto.py » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright (c) 2010 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2010 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 #include "chrome/browser/automation/automation_provider.h" 5 #include "chrome/browser/automation/automation_provider.h"
6 6
7 #include <set> 7 #include <set>
8 8
9 #include "app/message_box_flags.h" 9 #include "app/message_box_flags.h"
10 #include "base/callback.h" 10 #include "base/callback.h"
(...skipping 2812 matching lines...) Expand 10 before | Expand all | Expand 10 after
2823 if (!args->GetString("option", &option)) { 2823 if (!args->GetString("option", &option)) {
2824 AutomationJSONReply(this, reply_message).SendError("Must include option"); 2824 AutomationJSONReply(this, reply_message).SendError("Must include option");
2825 return; 2825 return;
2826 } 2826 }
2827 2827
2828 if (option == "translate_page") { 2828 if (option == "translate_page") {
2829 // Make a new notification observer which will send the reply. 2829 // Make a new notification observer which will send the reply.
2830 new PageTranslatedObserver(this, reply_message, tab_contents); 2830 new PageTranslatedObserver(this, reply_message, tab_contents);
2831 translate_bar->Translate(); 2831 translate_bar->Translate();
2832 return; 2832 return;
2833 } else if (option == "set_target_language") {
2834 string16 target_language;
2835 if (!args->GetString("target_language", &target_language)) {
2836 AutomationJSONReply(this, reply_message).
2837 SendError("Must include target_language string.");
2838 return;
2839 }
2840 // Get the target language index based off of the language name.
2841 int target_language_index = -1;
2842 for (int i = 0; i < translate_bar->GetLanguageCount(); i++) {
2843 if (translate_bar->GetLanguageDisplayableNameAt(i) == target_language) {
2844 target_language_index = i;
2845 break;
2846 }
2847 }
2848 if (target_language_index == -1) {
2849 AutomationJSONReply(this, reply_message)
2850 .SendError("Invalid target language string.");
2851 return;
2852 }
2853 // If the page has already been translated it will be translated again to
2854 // the new language. The observer will wait until the page has been
2855 // translated to reply.
2856 if (translate_bar->type() == TranslateInfoBarDelegate::AFTER_TRANSLATE) {
2857 new PageTranslatedObserver(this, reply_message, tab_contents);
2858 translate_bar->SetTargetLanguage(target_language_index);
2859 return;
2860 }
2861 // Otherwise just send the reply back immediately.
2862 translate_bar->SetTargetLanguage(target_language_index);
2863 scoped_ptr<DictionaryValue> return_value(new DictionaryValue);
2864 return_value->SetBoolean("translation_success", true);
2865 AutomationJSONReply(this, reply_message).SendSuccess(return_value.get());
2866 return;
2833 } 2867 }
2834 2868
2835 AutomationJSONReply reply(this, reply_message); 2869 AutomationJSONReply reply(this, reply_message);
2836 if (option == "never_translate_language") { 2870 if (option == "never_translate_language") {
2837 if (translate_bar->IsLanguageBlacklisted()) { 2871 if (translate_bar->IsLanguageBlacklisted()) {
2838 reply.SendError("The language was already blacklisted."); 2872 reply.SendError("The language was already blacklisted.");
2839 return; 2873 return;
2840 } 2874 }
2841 translate_bar->ToggleLanguageBlacklist(); 2875 translate_bar->ToggleLanguageBlacklist();
2842 reply.SendSuccess(NULL); 2876 reply.SendSuccess(NULL);
(...skipping 1638 matching lines...) Expand 10 before | Expand all | Expand 10 after
4481 } 4515 }
4482 4516
4483 void AutomationProvider::WaitForPopupMenuToOpen(IPC::Message* reply_message) { 4517 void AutomationProvider::WaitForPopupMenuToOpen(IPC::Message* reply_message) {
4484 NOTIMPLEMENTED(); 4518 NOTIMPLEMENTED();
4485 } 4519 }
4486 #endif // !defined(TOOLKIT_VIEWS) 4520 #endif // !defined(TOOLKIT_VIEWS)
4487 4521
4488 void AutomationProvider::ResetToDefaultTheme() { 4522 void AutomationProvider::ResetToDefaultTheme() {
4489 profile_->ClearTheme(); 4523 profile_->ClearTheme();
4490 } 4524 }
OLDNEW
« 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