Chromium Code Reviews| Index: content/browser/android/date_time_chooser_android.cc |
| diff --git a/content/browser/android/date_time_chooser_android.cc b/content/browser/android/date_time_chooser_android.cc |
| index be87a932e1c922814c0d18fd2eeb949eacb09912..1b57b79d3b0f5850594cee421d6a04bae34244a1 100644 |
| --- a/content/browser/android/date_time_chooser_android.cc |
| +++ b/content/browser/android/date_time_chooser_android.cc |
| @@ -4,17 +4,36 @@ |
| #include "content/browser/android/date_time_chooser_android.h" |
| +#include "base/android/jni_android.h" |
| #include "base/android/jni_string.h" |
| #include "content/common/view_messages.h" |
| #include "content/public/browser/android/content_view_core.h" |
| #include "content/public/browser/render_view_host.h" |
| +#include "content/public/common/date_time_suggestion.h" |
| #include "jni/DateTimeChooserAndroid_jni.h" |
| +#include "third_party/icu/source/common/unicode/uchar.h" |
| using base::android::AttachCurrentThread; |
| using base::android::ConvertJavaStringToUTF16; |
| using base::android::ConvertUTF8ToJavaString; |
| +using base::android::ConvertUTF16ToJavaString; |
| +namespace { |
| + |
| +bool IsNonPrintableChar(char16 c) { |
| + return !u_isprint(static_cast<UChar>(c)); |
| +} |
| + |
| +string16 SanitizeSuggestionString(string16 string) { |
| + string.erase( |
| + std::remove_if(string.begin(), string.end(), &IsNonPrintableChar), |
| + string.end()); |
| + return string.substr(0, 255); |
| +} |
| + |
| +} // namespace |
| + |
| namespace content { |
| // DateTimeChooserAndroid implementation |
| @@ -40,25 +59,7 @@ void DateTimeChooserAndroid::InitializeDateInputTypes( |
| void DateTimeChooserAndroid::ReplaceDateTime(JNIEnv* env, |
| jobject, |
| - int dialog_type, |
| - int year, |
| - int month, |
| - int day, |
| - int hour, |
| - int minute, |
| - int second, |
| - int milli, |
| - int week) { |
| - ViewHostMsg_DateTimeDialogValue_Params value; |
| - value.year = year; |
| - value.month = month; |
| - value.day = day; |
| - value.hour = hour; |
| - value.minute = minute; |
| - value.second = second; |
| - value.milli = milli; |
| - value.week = week; |
| - value.dialog_type = dialog_type; |
| + jdouble value) { |
| host_->Send(new ViewMsg_ReplaceDateTime(host_->GetRoutingID(), value)); |
| } |
| @@ -66,39 +67,54 @@ void DateTimeChooserAndroid::CancelDialog(JNIEnv* env, jobject) { |
| host_->Send(new ViewMsg_CancelDateTimeDialog(host_->GetRoutingID())); |
| } |
| -void DateTimeChooserAndroid::ShowDialog(ContentViewCore* content, |
| - RenderViewHost* host, |
| - int type, |
| - int year, |
| - int month, |
| - int day, |
| - int hour, |
| - int minute, |
| - int second, |
| - int milli, |
| - int week, |
| - double min, |
| - double max, |
| - double step) { |
| +void DateTimeChooserAndroid::ShowDialog( |
| + ContentViewCore* content, |
| + RenderViewHost* host, |
| + ui::TextInputType dialog_type, |
| + double dialog_value, |
| + double min, |
| + double max, |
| + double step, |
| + std::vector<DateTimeSuggestion> suggestions) { |
| host_ = host; |
| JNIEnv* env = AttachCurrentThread(); |
| + ScopedJavaLocalRef<jobjectArray> suggestions_array; |
| + |
| + if (suggestions.size() > 0) { |
| + ScopedJavaLocalRef<jclass> suggestion_class = base::android::GetClass( |
| + env, |
| + "org/chromium/content/browser/input/DateTimeSuggestion"); |
|
joth
2013/12/02 20:48:55
+bulach could you double check this? I know we nor
|
| + suggestions_array.Reset(env, env->NewObjectArray(suggestions.size(), |
| + suggestion_class.obj(), |
| + NULL)); |
| + for (size_t i = 0; i < suggestions.size(); ++i) { |
| + const content::DateTimeSuggestion& suggestion = suggestions[i]; |
| + ScopedJavaLocalRef<jstring> localizedValue = ConvertUTF16ToJavaString( |
| + env, SanitizeSuggestionString(suggestion.localizedValue)); |
| + ScopedJavaLocalRef<jstring> label = ConvertUTF16ToJavaString( |
| + env, SanitizeSuggestionString(suggestion.label)); |
| + env->SetObjectArrayElement( |
| + suggestions_array.obj(), |
| + i, |
| + Java_DateTimeChooserAndroid_createDateTimeSuggestion( |
| + env, |
| + suggestion.value, |
| + localizedValue.obj(), |
| + label.obj()).obj()); |
| + } |
| + } |
| + |
| j_date_time_chooser_.Reset(Java_DateTimeChooserAndroid_createDateTimeChooser( |
| env, |
| content->GetJavaObject().obj(), |
| reinterpret_cast<intptr_t>(this), |
| - type, |
| - year, |
| - month, |
| - day, |
| - hour, |
| - minute, |
| - second, |
| - milli, |
| - week, |
| + dialog_type, |
| + dialog_value, |
| min, |
| max, |
| - step)); |
| + step, |
| + suggestions_array.obj())); |
| } |
| // ---------------------------------------------------------------------------- |