| 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..71a4d1529c8eaf027b2c939e49f47a4194714138 100644
|
| --- a/content/browser/android/date_time_chooser_android.cc
|
| +++ b/content/browser/android/date_time_chooser_android.cc
|
| @@ -4,17 +4,40 @@
|
|
|
| #include "content/browser/android/date_time_chooser_android.h"
|
|
|
| +#include "base/android/jni_android.h"
|
| #include "base/android/jni_string.h"
|
| +#include "base/i18n/char_iterator.h"
|
| +#include "content/common/date_time_suggestion.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 "jni/DateTimeChooserAndroid_jni.h"
|
| +#include "third_party/icu/source/common/unicode/uchar.h"
|
| +#include "third_party/icu/source/common/unicode/unistr.h"
|
|
|
| using base::android::AttachCurrentThread;
|
| using base::android::ConvertJavaStringToUTF16;
|
| using base::android::ConvertUTF8ToJavaString;
|
| +using base::android::ConvertUTF16ToJavaString;
|
|
|
|
|
| +namespace {
|
| +
|
| +string16 SanitizeSuggestionString(const string16& string) {
|
| + string16 trimmed = string.substr(0, 255);
|
| + icu::UnicodeString sanitized;
|
| + base::i18n::UTF16CharIterator sanitized_iterator(&trimmed);
|
| + do {
|
| + UChar c = sanitized_iterator.get();
|
| + if (u_isprint(c))
|
| + sanitized.append(c);
|
| + } while(sanitized_iterator.Advance());
|
| + return string16(sanitized.getBuffer(),
|
| + static_cast<size_t>(sanitized.length()));
|
| +}
|
| +
|
| +} // namespace
|
| +
|
| namespace content {
|
|
|
| // DateTimeChooserAndroid implementation
|
| @@ -40,25 +63,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 +71,46 @@ 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,
|
| + const std::vector<DateTimeSuggestion>& suggestions) {
|
| host_ = host;
|
|
|
| JNIEnv* env = AttachCurrentThread();
|
| + ScopedJavaLocalRef<jobjectArray> suggestions_array;
|
| +
|
| + if (suggestions.size() > 0) {
|
| + ScopedJavaLocalRef<jobjectArray> j_suggestions =
|
| + Java_DateTimeChooserAndroid_createSuggestionsArray(env,
|
| + suggestions.size());
|
| + for (size_t i = 0; i < suggestions.size(); ++i) {
|
| + const content::DateTimeSuggestion& suggestion = suggestions[i];
|
| + ScopedJavaLocalRef<jstring> localized_value = ConvertUTF16ToJavaString(
|
| + env, SanitizeSuggestionString(suggestion.localized_value));
|
| + ScopedJavaLocalRef<jstring> label = ConvertUTF16ToJavaString(
|
| + env, SanitizeSuggestionString(suggestion.label));
|
| + Java_DateTimeChooserAndroid_setDateTimeSuggestionAt(env,
|
| + j_suggestions.obj(), i,
|
| + suggestion.value, localized_value.obj(), label.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()));
|
| }
|
|
|
| // ----------------------------------------------------------------------------
|
|
|