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

Side by Side Diff: chrome/browser/automation/automation_provider.cc

Issue 3061054: New pyauto translate hooks: always and never translate button. (Closed)
Patch Set: Added max tries count 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/browser/automation/automation_provider_observers.cc » ('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 2846 matching lines...) Expand 10 before | Expand all | Expand 10 after
2857 new PageTranslatedObserver(this, reply_message, tab_contents); 2857 new PageTranslatedObserver(this, reply_message, tab_contents);
2858 translate_bar->SetTargetLanguage(target_language_index); 2858 translate_bar->SetTargetLanguage(target_language_index);
2859 return; 2859 return;
2860 } 2860 }
2861 // Otherwise just send the reply back immediately. 2861 // Otherwise just send the reply back immediately.
2862 translate_bar->SetTargetLanguage(target_language_index); 2862 translate_bar->SetTargetLanguage(target_language_index);
2863 scoped_ptr<DictionaryValue> return_value(new DictionaryValue); 2863 scoped_ptr<DictionaryValue> return_value(new DictionaryValue);
2864 return_value->SetBoolean("translation_success", true); 2864 return_value->SetBoolean("translation_success", true);
2865 AutomationJSONReply(this, reply_message).SendSuccess(return_value.get()); 2865 AutomationJSONReply(this, reply_message).SendSuccess(return_value.get());
2866 return; 2866 return;
2867 } else if (option == "click_always_translate_lang_button") {
2868 if (!translate_bar->ShouldShowAlwaysTranslateButton()) {
2869 AutomationJSONReply(this, reply_message)
2870 .SendError("Always translate button not showing.");
2871 return;
2872 }
2873 // Clicking 'Always Translate' triggers a translation. The observer will
2874 // wait until the translation is complete before sending the reply.
2875 new PageTranslatedObserver(this, reply_message, tab_contents);
2876 translate_bar->AlwaysTranslatePageLanguage();
2877 return;
2867 } 2878 }
2868 2879
2869 AutomationJSONReply reply(this, reply_message); 2880 AutomationJSONReply reply(this, reply_message);
2870 if (option == "never_translate_language") { 2881 if (option == "never_translate_language") {
2871 if (translate_bar->IsLanguageBlacklisted()) { 2882 if (translate_bar->IsLanguageBlacklisted()) {
2872 reply.SendError("The language was already blacklisted."); 2883 reply.SendError("The language was already blacklisted.");
2873 return; 2884 return;
2874 } 2885 }
2875 translate_bar->ToggleLanguageBlacklist(); 2886 translate_bar->ToggleLanguageBlacklist();
2876 reply.SendSuccess(NULL); 2887 reply.SendSuccess(NULL);
2877 } else if (option == "never_translate_site") { 2888 } else if (option == "never_translate_site") {
2878 if (translate_bar->IsSiteBlacklisted()) { 2889 if (translate_bar->IsSiteBlacklisted()) {
2879 reply.SendError("The site was already blacklisted."); 2890 reply.SendError("The site was already blacklisted.");
2880 return; 2891 return;
2881 } 2892 }
2882 translate_bar->ToggleSiteBlacklist(); 2893 translate_bar->ToggleSiteBlacklist();
2883 reply.SendSuccess(NULL); 2894 reply.SendSuccess(NULL);
2884 } else if (option == "toggle_always_translate") { 2895 } else if (option == "toggle_always_translate") {
2885 translate_bar->ToggleAlwaysTranslate(); 2896 translate_bar->ToggleAlwaysTranslate();
2886 reply.SendSuccess(NULL); 2897 reply.SendSuccess(NULL);
2887 } else if (option == "revert_translation") { 2898 } else if (option == "revert_translation") {
2888 translate_bar->RevertTranslation(); 2899 translate_bar->RevertTranslation();
2889 reply.SendSuccess(NULL); 2900 reply.SendSuccess(NULL);
2901 } else if (option == "click_never_translate_lang_button") {
2902 if (!translate_bar->ShouldShowNeverTranslateButton()) {
2903 reply.SendError("Always translate button not showing.");
2904 return;
2905 }
2906 translate_bar->NeverTranslatePageLanguage();
2907 reply.SendSuccess(NULL);
2908 } else if (option == "decline_translation") {
2909 // This is the function called when an infobar is dismissed or when the
2910 // user clicks the 'Nope' translate button.
2911 translate_bar->TranslationDeclined();
2912 reply.SendSuccess(NULL);
2890 } else { 2913 } else {
2891 reply.SendError("Invalid string found for option."); 2914 reply.SendError("Invalid string found for option.");
2892 } 2915 }
2893 } 2916 }
2894 2917
2895 // See WaitUntilTranslateComplete() in chrome/test/pyautolib/pyauto.py for 2918 // See WaitUntilTranslateComplete() in chrome/test/pyautolib/pyauto.py for
2896 // sample json input and output. 2919 // sample json input and output.
2897 void AutomationProvider::WaitUntilTranslateComplete( 2920 void AutomationProvider::WaitUntilTranslateComplete(
2898 Browser* browser, DictionaryValue* args, IPC::Message* reply_message) { 2921 Browser* browser, DictionaryValue* args, IPC::Message* reply_message) {
2899 std::string error_message; 2922 std::string error_message;
(...skipping 1617 matching lines...) Expand 10 before | Expand all | Expand 10 after
4517 } 4540 }
4518 4541
4519 void AutomationProvider::WaitForPopupMenuToOpen(IPC::Message* reply_message) { 4542 void AutomationProvider::WaitForPopupMenuToOpen(IPC::Message* reply_message) {
4520 NOTIMPLEMENTED(); 4543 NOTIMPLEMENTED();
4521 } 4544 }
4522 #endif // !defined(TOOLKIT_VIEWS) 4545 #endif // !defined(TOOLKIT_VIEWS)
4523 4546
4524 void AutomationProvider::ResetToDefaultTheme() { 4547 void AutomationProvider::ResetToDefaultTheme() {
4525 profile_->ClearTheme(); 4548 profile_->ClearTheme();
4526 } 4549 }
OLDNEW
« no previous file with comments | « no previous file | chrome/browser/automation/automation_provider_observers.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698