Chromium Code Reviews
Help | Chromium Project | Sign in
(526)

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

Issue 3026016: New pyauto hook for the translate feature. (Closed) Base URL: http://src.chromium.org/git/chromium.git
Patch Set: Small changes Created 3 years, 9 months ago
Use n/p to move between diff chunks; N/P to move between comments. Please Sign in to add in-line comments.
Jump to:
View unified diff | Download patch
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_observers.h" 5 #include "chrome/browser/automation/automation_provider_observers.h"
6 6
7 #include "base/basictypes.h" 7 #include "base/basictypes.h"
8 #include "base/json/json_writer.h" 8 #include "base/json/json_writer.h"
9 #include "base/string_util.h" 9 #include "base/string_util.h"
10 #include "chrome/app/chrome_dll_resource.h" 10 #include "chrome/app/chrome_dll_resource.h"
11 #include "chrome/browser/automation/automation_provider.h" 11 #include "chrome/browser/automation/automation_provider.h"
12 #include "chrome/browser/automation/automation_provider_json.h" 12 #include "chrome/browser/automation/automation_provider_json.h"
13 #include "chrome/browser/bookmarks/bookmark_model.h" 13 #include "chrome/browser/bookmarks/bookmark_model.h"
14 #include "chrome/browser/dom_operation_notification_details.h" 14 #include "chrome/browser/dom_operation_notification_details.h"
15 #include "chrome/browser/download/download_item.h" 15 #include "chrome/browser/download/download_item.h"
16 #include "chrome/browser/download/save_package.h" 16 #include "chrome/browser/download/save_package.h"
17 #include "chrome/browser/extensions/extension_host.h" 17 #include "chrome/browser/extensions/extension_host.h"
18 #include "chrome/browser/extensions/extension_process_manager.h" 18 #include "chrome/browser/extensions/extension_process_manager.h"
19 #include "chrome/browser/extensions/extension_updater.h" 19 #include "chrome/browser/extensions/extension_updater.h"
20 #include "chrome/browser/login_prompt.h" 20 #include "chrome/browser/login_prompt.h"
21 #include "chrome/browser/metrics/metric_event_duration_details.h" 21 #include "chrome/browser/metrics/metric_event_duration_details.h"
22 #include "chrome/browser/printing/print_job.h" 22 #include "chrome/browser/printing/print_job.h"
23 #include "chrome/browser/profile.h" 23 #include "chrome/browser/profile.h"
24 #include "chrome/browser/tab_contents/navigation_controller.h" 24 #include "chrome/browser/tab_contents/navigation_controller.h"
25 #include "chrome/browser/tab_contents/tab_contents.h" 25 #include "chrome/browser/tab_contents/tab_contents.h"
26 #include "chrome/browser/translate/page_translated_details.h"
27 #include "chrome/browser/translate/translate_infobar_delegate.h"
26 #include "chrome/common/extensions/extension.h" 28 #include "chrome/common/extensions/extension.h"
27 #include "chrome/common/notification_service.h" 29 #include "chrome/common/notification_service.h"
28 #include "chrome/test/automation/automation_constants.h" 30 #include "chrome/test/automation/automation_constants.h"
29 31
30 #if defined(OS_CHROMEOS) 32 #if defined(OS_CHROMEOS)
31 #include "chrome/browser/chromeos/login/authentication_notification_details.h" 33 #include "chrome/browser/chromeos/login/authentication_notification_details.h"
32 #endif 34 #endif
33 35
34 // Holds onto start and stop timestamps for a particular tab 36 // Holds onto start and stop timestamps for a particular tab
35 class InitialLoadObserver::TabTime { 37 class InitialLoadObserver::TabTime {
(...skipping 886 matching lines...) Expand 10 before | Expand all | Expand 10 after
922 if (type != NotificationType::METRIC_EVENT_DURATION) { 924 if (type != NotificationType::METRIC_EVENT_DURATION) {
923 NOTREACHED(); 925 NOTREACHED();
924 return; 926 return;
925 } 927 }
926 MetricEventDurationDetails* metric_event_duration = 928 MetricEventDurationDetails* metric_event_duration =
927 Details<MetricEventDurationDetails>(details).ptr(); 929 Details<MetricEventDurationDetails>(details).ptr();
928 durations_[metric_event_duration->event_name] = 930 durations_[metric_event_duration->event_name] =
929 metric_event_duration->duration_ms; 931 metric_event_duration->duration_ms;
930 } 932 }
931 933
934 PageTranslatedObserver::PageTranslatedObserver(AutomationProvider* automation,
935 IPC::Message* reply_message,
936 TabContents* tab_contents)
937 : automation_(automation),
938 reply_message_(reply_message) {
939 registrar_.Add(this, NotificationType::PAGE_TRANSLATED,
940 Source<TabContents>(tab_contents));
941 }
942
943 void PageTranslatedObserver::Observe(NotificationType type,
944 const NotificationSource& source,
945 const NotificationDetails& details) {
946 DCHECK(type == NotificationType::PAGE_TRANSLATED);
947 AutomationJSONReply reply(automation_, reply_message_);
948
949 PageTranslatedDetails* translated_details =
950 Details<PageTranslatedDetails>(details).ptr();
951 scoped_ptr<DictionaryValue> return_value(new DictionaryValue);
952 return_value->SetBoolean(
953 L"translation_success",
954 translated_details->error_type == TranslateErrors::NONE);
955 reply.SendSuccess(return_value.get());
956 delete this;
957 }
958
959 TabLanguageDeterminedObserver::TabLanguageDeterminedObserver(
960 AutomationProvider* automation, IPC::Message* reply_message,
961 TabContents* tab_contents, TranslateInfoBarDelegate* translate_bar)
962 : automation_(automation),
963 reply_message_(reply_message),
964 tab_contents_(tab_contents),
965 translate_bar_(translate_bar) {
966 registrar_.Add(this, NotificationType::TAB_LANGUAGE_DETERMINED,
967 Source<TabContents>(tab_contents));
968 }
969
970 void TabLanguageDeterminedObserver::Observe(
971 NotificationType type, const NotificationSource& source,
972 const NotificationDetails& details) {
973 DCHECK(type == NotificationType::TAB_LANGUAGE_DETERMINED);
974
975 scoped_ptr<DictionaryValue> return_value(new DictionaryValue);
976 return_value->SetBoolean(L"page_translated",
977 tab_contents_->language_state().IsPageTranslated());
978 return_value->SetBoolean(
979 L"can_translate_page", TranslatePrefs::CanTranslate(
980 automation_->profile()->GetPrefs(),
981 tab_contents_->language_state().original_language(),
982 tab_contents_->GetURL()));
983 return_value->SetString(
984 L"original_language",
985 tab_contents_->language_state().original_language());
986 if (translate_bar_) {
987 DictionaryValue* bar_info = new DictionaryValue;
988 std::map<TranslateInfoBarDelegate::Type, std::string> type_to_string;
989 type_to_string[TranslateInfoBarDelegate::BEFORE_TRANSLATE] =
990 "BEFORE_TRANSLATE";
991 type_to_string[TranslateInfoBarDelegate::TRANSLATING] =
992 "TRANSLATING";
993 type_to_string[TranslateInfoBarDelegate::AFTER_TRANSLATE] =
994 "AFTER_TRANSLATE";
995 type_to_string[TranslateInfoBarDelegate::TRANSLATION_ERROR] =
996 "TRANSLATION_ERROR";
997
998 bar_info->SetString(L"bar_state", type_to_string[translate_bar_->type()]);
999 bar_info->SetString(L"target_lang_code",
1000 translate_bar_->GetTargetLanguageCode());
1001 bar_info->SetString(L"original_lang_code",
1002 translate_bar_->GetOriginalLanguageCode());
1003 return_value->Set(L"translate_bar", bar_info);
1004 }
1005 AutomationJSONReply(automation_, reply_message_)
1006 .SendSuccess(return_value.get());
1007 delete this;
1008 }
1009
932 #if defined(OS_CHROMEOS) 1010 #if defined(OS_CHROMEOS)
933 LoginManagerObserver::LoginManagerObserver( 1011 LoginManagerObserver::LoginManagerObserver(
934 AutomationProvider* automation, 1012 AutomationProvider* automation,
935 IPC::Message* reply_message) 1013 IPC::Message* reply_message)
936 : automation_(automation), 1014 : automation_(automation),
937 reply_message_(reply_message) { 1015 reply_message_(reply_message) {
938 1016
939 registrar_.Add(this, NotificationType::LOGIN_AUTHENTICATION, 1017 registrar_.Add(this, NotificationType::LOGIN_AUTHENTICATION,
940 NotificationService::AllSources()); 1018 NotificationService::AllSources());
941 } 1019 }
(...skipping 184 matching lines...) Expand 10 before | Expand all | Expand 10 after
1126 if (tab_contents_->infobar_delegate_count() == count_) { 1204 if (tab_contents_->infobar_delegate_count() == count_) {
1127 ConditionMet(); 1205 ConditionMet();
1128 } 1206 }
1129 } 1207 }
1130 1208
1131 void WaitForInfobarCountObserver::ConditionMet() { 1209 void WaitForInfobarCountObserver::ConditionMet() {
1132 registrar_.RemoveAll(); 1210 registrar_.RemoveAll();
1133 AutomationJSONReply(automation_, reply_message_).SendSuccess(NULL); 1211 AutomationJSONReply(automation_, reply_message_).SendSuccess(NULL);
1134 delete this; 1212 delete this;
1135 } 1213 }
OLDNEW
« no previous file with comments | « chrome/browser/automation/automation_provider_observers.h ('k') | chrome/test/functional/PYAUTO_TESTS » ('j') | no next file with comments »

Powered by Google App Engine
RSS Feeds Recent Issues | This issue
This is Rietveld 1280:2d3e6564b7b6