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

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

Issue 3033050: Rename DictionaryValue's SetStringFromUTF16() to SetString() (and overload). (Closed)
Patch Set: There shouldn't be wstrings in platform-ind. code. 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
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"
(...skipping 82 matching lines...) Expand 10 before | Expand all | Expand 10 after
93 } 93 }
94 94
95 DictionaryValue* InitialLoadObserver::GetTimingInformation() const { 95 DictionaryValue* InitialLoadObserver::GetTimingInformation() const {
96 ListValue* items = new ListValue; 96 ListValue* items = new ListValue;
97 for (TabTimeMap::const_iterator it = loading_tabs_.begin(); 97 for (TabTimeMap::const_iterator it = loading_tabs_.begin();
98 it != loading_tabs_.end(); 98 it != loading_tabs_.end();
99 ++it) { 99 ++it) {
100 DictionaryValue* item = new DictionaryValue; 100 DictionaryValue* item = new DictionaryValue;
101 base::TimeDelta delta_start = it->second.start_time() - init_time_; 101 base::TimeDelta delta_start = it->second.start_time() - init_time_;
102 102
103 item->SetReal(L"load_start_ms", delta_start.InMillisecondsF()); 103 item->SetReal("load_start_ms", delta_start.InMillisecondsF());
104 if (it->second.stop_time().is_null()) { 104 if (it->second.stop_time().is_null()) {
105 item->Set(L"load_stop_ms", Value::CreateNullValue()); 105 item->Set("load_stop_ms", Value::CreateNullValue());
106 } else { 106 } else {
107 base::TimeDelta delta_stop = it->second.stop_time() - init_time_; 107 base::TimeDelta delta_stop = it->second.stop_time() - init_time_;
108 item->SetReal(L"load_stop_ms", delta_stop.InMillisecondsF()); 108 item->SetReal("load_stop_ms", delta_stop.InMillisecondsF());
109 } 109 }
110 items->Append(item); 110 items->Append(item);
111 } 111 }
112 DictionaryValue* return_value = new DictionaryValue; 112 DictionaryValue* return_value = new DictionaryValue;
113 return_value->Set(L"tabs", items); 113 return_value->Set("tabs", items);
114 return return_value; 114 return return_value;
115 } 115 }
116 116
117 void InitialLoadObserver::ConditionMet() { 117 void InitialLoadObserver::ConditionMet() {
118 registrar_.RemoveAll(); 118 registrar_.RemoveAll();
119 automation_->Send(new AutomationMsg_InitialLoadsComplete(0)); 119 automation_->Send(new AutomationMsg_InitialLoadsComplete(0));
120 } 120 }
121 121
122 NewTabUILoadObserver::NewTabUILoadObserver(AutomationProvider* automation) 122 NewTabUILoadObserver::NewTabUILoadObserver(AutomationProvider* automation)
123 : automation_(automation) { 123 : automation_(automation) {
(...skipping 819 matching lines...) Expand 10 before | Expand all | Expand 10 after
943 void PageTranslatedObserver::Observe(NotificationType type, 943 void PageTranslatedObserver::Observe(NotificationType type,
944 const NotificationSource& source, 944 const NotificationSource& source,
945 const NotificationDetails& details) { 945 const NotificationDetails& details) {
946 DCHECK(type == NotificationType::PAGE_TRANSLATED); 946 DCHECK(type == NotificationType::PAGE_TRANSLATED);
947 AutomationJSONReply reply(automation_, reply_message_); 947 AutomationJSONReply reply(automation_, reply_message_);
948 948
949 PageTranslatedDetails* translated_details = 949 PageTranslatedDetails* translated_details =
950 Details<PageTranslatedDetails>(details).ptr(); 950 Details<PageTranslatedDetails>(details).ptr();
951 scoped_ptr<DictionaryValue> return_value(new DictionaryValue); 951 scoped_ptr<DictionaryValue> return_value(new DictionaryValue);
952 return_value->SetBoolean( 952 return_value->SetBoolean(
953 L"translation_success", 953 "translation_success",
954 translated_details->error_type == TranslateErrors::NONE); 954 translated_details->error_type == TranslateErrors::NONE);
955 reply.SendSuccess(return_value.get()); 955 reply.SendSuccess(return_value.get());
956 delete this; 956 delete this;
957 } 957 }
958 958
959 TabLanguageDeterminedObserver::TabLanguageDeterminedObserver( 959 TabLanguageDeterminedObserver::TabLanguageDeterminedObserver(
960 AutomationProvider* automation, IPC::Message* reply_message, 960 AutomationProvider* automation, IPC::Message* reply_message,
961 TabContents* tab_contents, TranslateInfoBarDelegate* translate_bar) 961 TabContents* tab_contents, TranslateInfoBarDelegate* translate_bar)
962 : automation_(automation), 962 : automation_(automation),
963 reply_message_(reply_message), 963 reply_message_(reply_message),
964 tab_contents_(tab_contents), 964 tab_contents_(tab_contents),
965 translate_bar_(translate_bar) { 965 translate_bar_(translate_bar) {
966 registrar_.Add(this, NotificationType::TAB_LANGUAGE_DETERMINED, 966 registrar_.Add(this, NotificationType::TAB_LANGUAGE_DETERMINED,
967 Source<TabContents>(tab_contents)); 967 Source<TabContents>(tab_contents));
968 } 968 }
969 969
970 void TabLanguageDeterminedObserver::Observe( 970 void TabLanguageDeterminedObserver::Observe(
971 NotificationType type, const NotificationSource& source, 971 NotificationType type, const NotificationSource& source,
972 const NotificationDetails& details) { 972 const NotificationDetails& details) {
973 DCHECK(type == NotificationType::TAB_LANGUAGE_DETERMINED); 973 DCHECK(type == NotificationType::TAB_LANGUAGE_DETERMINED);
974 974
975 scoped_ptr<DictionaryValue> return_value(new DictionaryValue); 975 scoped_ptr<DictionaryValue> return_value(new DictionaryValue);
976 return_value->SetBoolean(L"page_translated", 976 return_value->SetBoolean("page_translated",
977 tab_contents_->language_state().IsPageTranslated()); 977 tab_contents_->language_state().IsPageTranslated());
978 return_value->SetBoolean( 978 return_value->SetBoolean(
979 L"can_translate_page", TranslatePrefs::CanTranslate( 979 "can_translate_page", TranslatePrefs::CanTranslate(
980 automation_->profile()->GetPrefs(), 980 automation_->profile()->GetPrefs(),
981 tab_contents_->language_state().original_language(), 981 tab_contents_->language_state().original_language(),
982 tab_contents_->GetURL())); 982 tab_contents_->GetURL()));
983 return_value->SetString( 983 return_value->SetString(
984 L"original_language", 984 "original_language",
985 tab_contents_->language_state().original_language()); 985 tab_contents_->language_state().original_language());
986 if (translate_bar_) { 986 if (translate_bar_) {
987 DictionaryValue* bar_info = new DictionaryValue; 987 DictionaryValue* bar_info = new DictionaryValue;
988 std::map<TranslateInfoBarDelegate::Type, std::string> type_to_string; 988 std::map<TranslateInfoBarDelegate::Type, std::string> type_to_string;
989 type_to_string[TranslateInfoBarDelegate::BEFORE_TRANSLATE] = 989 type_to_string[TranslateInfoBarDelegate::BEFORE_TRANSLATE] =
990 "BEFORE_TRANSLATE"; 990 "BEFORE_TRANSLATE";
991 type_to_string[TranslateInfoBarDelegate::TRANSLATING] = 991 type_to_string[TranslateInfoBarDelegate::TRANSLATING] =
992 "TRANSLATING"; 992 "TRANSLATING";
993 type_to_string[TranslateInfoBarDelegate::AFTER_TRANSLATE] = 993 type_to_string[TranslateInfoBarDelegate::AFTER_TRANSLATE] =
994 "AFTER_TRANSLATE"; 994 "AFTER_TRANSLATE";
995 type_to_string[TranslateInfoBarDelegate::TRANSLATION_ERROR] = 995 type_to_string[TranslateInfoBarDelegate::TRANSLATION_ERROR] =
996 "TRANSLATION_ERROR"; 996 "TRANSLATION_ERROR";
997 997
998 bar_info->SetString(L"bar_state", type_to_string[translate_bar_->type()]); 998 bar_info->SetString("bar_state", type_to_string[translate_bar_->type()]);
999 bar_info->SetString(L"target_lang_code", 999 bar_info->SetString("target_lang_code",
1000 translate_bar_->GetTargetLanguageCode()); 1000 translate_bar_->GetTargetLanguageCode());
1001 bar_info->SetString(L"original_lang_code", 1001 bar_info->SetString("original_lang_code",
1002 translate_bar_->GetOriginalLanguageCode()); 1002 translate_bar_->GetOriginalLanguageCode());
1003 return_value->Set(L"translate_bar", bar_info); 1003 return_value->Set("translate_bar", bar_info);
1004 } 1004 }
1005 AutomationJSONReply(automation_, reply_message_) 1005 AutomationJSONReply(automation_, reply_message_)
1006 .SendSuccess(return_value.get()); 1006 .SendSuccess(return_value.get());
1007 delete this; 1007 delete this;
1008 } 1008 }
1009 1009
1010 #if defined(OS_CHROMEOS) 1010 #if defined(OS_CHROMEOS)
1011 LoginManagerObserver::LoginManagerObserver( 1011 LoginManagerObserver::LoginManagerObserver(
1012 AutomationProvider* automation, 1012 AutomationProvider* automation,
1013 IPC::Message* reply_message) 1013 IPC::Message* reply_message)
(...skipping 48 matching lines...) Expand 10 before | Expand all | Expand 10 after
1062 1062
1063 void AutomationProviderHistoryObserver::HistoryQueryComplete( 1063 void AutomationProviderHistoryObserver::HistoryQueryComplete(
1064 HistoryService::Handle request_handle, 1064 HistoryService::Handle request_handle,
1065 history::QueryResults* results) { 1065 history::QueryResults* results) {
1066 scoped_ptr<DictionaryValue> return_value(new DictionaryValue); 1066 scoped_ptr<DictionaryValue> return_value(new DictionaryValue);
1067 1067
1068 ListValue* history_list = new ListValue; 1068 ListValue* history_list = new ListValue;
1069 for (size_t i = 0; i < results->size(); ++i) { 1069 for (size_t i = 0; i < results->size(); ++i) {
1070 DictionaryValue* page_value = new DictionaryValue; 1070 DictionaryValue* page_value = new DictionaryValue;
1071 history::URLResult const &page = (*results)[i]; 1071 history::URLResult const &page = (*results)[i];
1072 page_value->SetStringFromUTF16(L"title", page.title()); 1072 page_value->SetString("title", page.title());
1073 page_value->SetString(L"url", page.url().spec()); 1073 page_value->SetString("url", page.url().spec());
1074 page_value->SetReal(L"time", 1074 page_value->SetReal("time",
1075 static_cast<double>(page.visit_time().ToDoubleT())); 1075 static_cast<double>(page.visit_time().ToDoubleT()));
1076 page_value->SetStringFromUTF16(L"snippet", page.snippet().text()); 1076 page_value->SetString("snippet", page.snippet().text());
1077 page_value->SetBoolean( 1077 page_value->SetBoolean(
1078 L"starred", 1078 "starred",
1079 provider_->profile()->GetBookmarkModel()->IsBookmarked(page.url())); 1079 provider_->profile()->GetBookmarkModel()->IsBookmarked(page.url()));
1080 history_list->Append(page_value); 1080 history_list->Append(page_value);
1081 } 1081 }
1082 1082
1083 return_value->Set(L"history", history_list); 1083 return_value->Set("history", history_list);
1084 // Return history info. 1084 // Return history info.
1085 AutomationJSONReply reply(provider_, reply_message_); 1085 AutomationJSONReply reply(provider_, reply_message_);
1086 reply.SendSuccess(return_value.get()); 1086 reply.SendSuccess(return_value.get());
1087 delete this; 1087 delete this;
1088 } 1088 }
1089 1089
1090 void AutomationProviderImportSettingsObserver::ImportEnded() { 1090 void AutomationProviderImportSettingsObserver::ImportEnded() {
1091 // Send back an empty success message. 1091 // Send back an empty success message.
1092 AutomationJSONReply(provider_, reply_message_).SendSuccess(NULL); 1092 AutomationJSONReply(provider_, reply_message_).SendSuccess(NULL);
1093 delete this; 1093 delete this;
1094 } 1094 }
1095 1095
1096 void AutomationProviderGetPasswordsObserver::OnPasswordStoreRequestDone( 1096 void AutomationProviderGetPasswordsObserver::OnPasswordStoreRequestDone(
1097 int handle, const std::vector<webkit_glue::PasswordForm*>& result) { 1097 int handle, const std::vector<webkit_glue::PasswordForm*>& result) {
1098 scoped_ptr<DictionaryValue> return_value(new DictionaryValue); 1098 scoped_ptr<DictionaryValue> return_value(new DictionaryValue);
1099 1099
1100 ListValue* passwords = new ListValue; 1100 ListValue* passwords = new ListValue;
1101 for (std::vector<webkit_glue::PasswordForm*>::const_iterator it = 1101 for (std::vector<webkit_glue::PasswordForm*>::const_iterator it =
1102 result.begin(); it != result.end(); ++it) { 1102 result.begin(); it != result.end(); ++it) {
1103 DictionaryValue* password_val = new DictionaryValue; 1103 DictionaryValue* password_val = new DictionaryValue;
1104 webkit_glue::PasswordForm* password_form = *it; 1104 webkit_glue::PasswordForm* password_form = *it;
1105 password_val->SetStringFromUTF16(L"username_value", 1105 password_val->SetString("username_value", password_form->username_value);
1106 password_form->username_value); 1106 password_val->SetString("password_value", password_form->password_value);
1107 password_val->SetStringFromUTF16(L"password_value", 1107 password_val->SetString("signon_realm", password_form->signon_realm);
1108 password_form->password_value);
1109 password_val->SetString(L"signon_realm", password_form->signon_realm);
1110 password_val->SetReal( 1108 password_val->SetReal(
1111 L"time", static_cast<double>( 1109 "time", static_cast<double>(password_form->date_created.ToDoubleT()));
1112 password_form->date_created.ToDoubleT())); 1110 password_val->SetString("origin_url", password_form->origin.spec());
1113 password_val->SetString(L"origin_url", password_form->origin.spec()); 1111 password_val->SetString("username_element",
1114 password_val->SetStringFromUTF16(L"username_element", 1112 password_form->username_element);
1115 password_form->username_element); 1113 password_val->SetString("password_element",
1116 password_val->SetStringFromUTF16(L"password_element", 1114 password_form->password_element);
1117 password_form->password_element); 1115 password_val->SetString("submit_element",
1118 password_val->SetStringFromUTF16(L"submit_element",
1119 password_form->submit_element); 1116 password_form->submit_element);
1120 password_val->SetString(L"action_target", password_form->action.spec()); 1117 password_val->SetString("action_target", password_form->action.spec());
1121 password_val->SetBoolean(L"blacklist", password_form->blacklisted_by_user); 1118 password_val->SetBoolean("blacklist", password_form->blacklisted_by_user);
1122 passwords->Append(password_val); 1119 passwords->Append(password_val);
1123 } 1120 }
1124 1121
1125 return_value->Set(L"passwords", passwords); 1122 return_value->Set("passwords", passwords);
1126 AutomationJSONReply(provider_, reply_message_).SendSuccess( 1123 AutomationJSONReply(provider_, reply_message_).SendSuccess(
1127 return_value.get()); 1124 return_value.get());
1128 delete this; 1125 delete this;
1129 } 1126 }
1130 1127
1131 void AutomationProviderBrowsingDataObserver::OnBrowsingDataRemoverDone() { 1128 void AutomationProviderBrowsingDataObserver::OnBrowsingDataRemoverDone() {
1132 // Send back an empty success message 1129 // Send back an empty success message
1133 AutomationJSONReply(provider_, reply_message_).SendSuccess(NULL); 1130 AutomationJSONReply(provider_, reply_message_).SendSuccess(NULL);
1134 delete this; 1131 delete this;
1135 } 1132 }
(...skipping 78 matching lines...) Expand 10 before | Expand all | Expand 10 after
1214 if (tab_contents_->infobar_delegate_count() == count_) { 1211 if (tab_contents_->infobar_delegate_count() == count_) {
1215 ConditionMet(); 1212 ConditionMet();
1216 } 1213 }
1217 } 1214 }
1218 1215
1219 void WaitForInfobarCountObserver::ConditionMet() { 1216 void WaitForInfobarCountObserver::ConditionMet() {
1220 registrar_.RemoveAll(); 1217 registrar_.RemoveAll();
1221 AutomationJSONReply(automation_, reply_message_).SendSuccess(NULL); 1218 AutomationJSONReply(automation_, reply_message_).SendSuccess(NULL);
1222 delete this; 1219 delete this;
1223 } 1220 }
OLDNEW
« no previous file with comments | « chrome/browser/automation/automation_provider.cc ('k') | chrome/browser/background_contents_service.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698