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

Side by Side Diff: content/browser/android/date_time_chooser_android.cc

Issue 12191005: Move Android Date/Time parsing to the renderer (C++ and ICU) instead of the current parsing that ha… (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Rebased view_messages.h and fixed the link issue on the linux bot Created 7 years, 10 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) 2013 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2013 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 "content/browser/android/date_time_chooser_android.h" 5 #include "content/browser/android/date_time_chooser_android.h"
6 6
7 #include "base/android/jni_string.h" 7 #include "base/android/jni_string.h"
8 #include "content/common/view_messages.h" 8 #include "content/common/view_messages.h"
9 #include "content/public/browser/android/content_view_core.h" 9 #include "content/public/browser/android/content_view_core.h"
10 #include "content/public/browser/render_view_host_observer.h" 10 #include "content/public/browser/render_view_host_observer.h"
11 #include "jni/DateTimeChooserAndroid_jni.h" 11 #include "jni/DateTimeChooserAndroid_jni.h"
12 12
13 using base::android::AttachCurrentThread; 13 using base::android::AttachCurrentThread;
14 using base::android::ConvertJavaStringToUTF16; 14 using base::android::ConvertJavaStringToUTF16;
15 using base::android::ConvertUTF8ToJavaString; 15 using base::android::ConvertUTF8ToJavaString;
16 16
17 17
18 namespace content { 18 namespace content {
19 19
20 // Updates date/time via IPC to the RenderView 20 // Updates date/time via IPC to the RenderView
21 class DateTimeChooserAndroid::DateTimeIPCSender : 21 class DateTimeChooserAndroid::DateTimeIPCSender :
22 public RenderViewHostObserver { 22 public RenderViewHostObserver {
23 public: 23 public:
24 explicit DateTimeIPCSender(RenderViewHost* sender); 24 explicit DateTimeIPCSender(RenderViewHost* sender);
25 virtual ~DateTimeIPCSender() {} 25 virtual ~DateTimeIPCSender() {}
26 void ReplaceDateTime(string16 text); 26 void ReplaceDateTime(int dialog_type,
27 int year, int month, int day, int hour, int minute, int second);
27 void CancelDialog(); 28 void CancelDialog();
28 29
29 private: 30 private:
30 DISALLOW_COPY_AND_ASSIGN(DateTimeIPCSender); 31 DISALLOW_COPY_AND_ASSIGN(DateTimeIPCSender);
31 }; 32 };
32 33
33 DateTimeChooserAndroid::DateTimeIPCSender::DateTimeIPCSender( 34 DateTimeChooserAndroid::DateTimeIPCSender::DateTimeIPCSender(
34 RenderViewHost* sender) 35 RenderViewHost* sender)
35 : RenderViewHostObserver(sender) { 36 : RenderViewHostObserver(sender) {
36 } 37 }
37 38
38 void DateTimeChooserAndroid::DateTimeIPCSender::ReplaceDateTime( 39 void DateTimeChooserAndroid::DateTimeIPCSender::ReplaceDateTime(
39 string16 text) { 40 int dialog_type,
40 Send(new ViewMsg_ReplaceDateTime(routing_id(), text)); 41 int year, int month, int day, int hour, int minute, int second) {
42 ViewHostMsg_DateTimeDialogValue_Params value;
43 value.year = year;
44 value.month = month;
45 value.day = day;
46 value.hour = hour;
47 value.minute = minute;
48 value.second = second;
49 value.dialog_type = dialog_type;
50 Send(new ViewMsg_ReplaceDateTime(routing_id(), value));
41 } 51 }
42 52
43 void DateTimeChooserAndroid::DateTimeIPCSender::CancelDialog() { 53 void DateTimeChooserAndroid::DateTimeIPCSender::CancelDialog() {
44 Send(new ViewMsg_CancelDateTimeDialog(routing_id())); 54 Send(new ViewMsg_CancelDateTimeDialog(routing_id()));
45 } 55 }
46 56
47 // DateTimeChooserAndroid implementation 57 // DateTimeChooserAndroid implementation
48 DateTimeChooserAndroid::DateTimeChooserAndroid() { 58 DateTimeChooserAndroid::DateTimeChooserAndroid() {
49 } 59 }
50 60
51 DateTimeChooserAndroid::~DateTimeChooserAndroid() { 61 DateTimeChooserAndroid::~DateTimeChooserAndroid() {
52 } 62 }
53 63
54 // static 64 // static
55 void DateTimeChooserAndroid::InitializeDateInputTypes( 65 void DateTimeChooserAndroid::InitializeDateInputTypes(
56 int text_input_type_date, int text_input_type_date_time, 66 int text_input_type_date, int text_input_type_date_time,
57 int text_input_type_date_time_local, int text_input_type_month, 67 int text_input_type_date_time_local, int text_input_type_month,
58 int text_input_type_time) { 68 int text_input_type_time) {
59 JNIEnv* env = AttachCurrentThread(); 69 JNIEnv* env = AttachCurrentThread();
60 Java_DateTimeChooserAndroid_initializeDateInputTypes( 70 Java_DateTimeChooserAndroid_initializeDateInputTypes(
61 env, 71 env,
62 text_input_type_date, text_input_type_date_time, 72 text_input_type_date, text_input_type_date_time,
63 text_input_type_date_time_local, text_input_type_month, 73 text_input_type_date_time_local, text_input_type_month,
64 text_input_type_time); 74 text_input_type_time);
65 } 75 }
66 76
67 void DateTimeChooserAndroid::ReplaceDateTime( 77 void DateTimeChooserAndroid::ReplaceDateTime(
68 JNIEnv* env, jobject, jstring text) { 78 JNIEnv* env, jobject, int dialog_type,
69 string16 text16 = ConvertJavaStringToUTF16(env, text); 79 int year, int month, int day, int hour, int minute, int second) {
70 communicator_->ReplaceDateTime(text16); 80 sender_->ReplaceDateTime(
81 dialog_type, year, month, day, hour, minute, second);
71 } 82 }
72 83
73 void DateTimeChooserAndroid::CancelDialog(JNIEnv* env, jobject) { 84 void DateTimeChooserAndroid::CancelDialog(JNIEnv* env, jobject) {
74 communicator_->CancelDialog(); 85 sender_->CancelDialog();
75 } 86 }
76 87
77 void DateTimeChooserAndroid::ShowDialog( 88 void DateTimeChooserAndroid::ShowDialog(
78 ContentViewCore* content, RenderViewHost* sender, 89 ContentViewCore* content, RenderViewHost* sender,
79 int type, const std::string& value) { 90 int type, int year, int month, int day,
80 communicator_.reset(new DateTimeIPCSender(sender)); 91 int hour, int minute, int second) {
92 sender_.reset(new DateTimeIPCSender(sender));
81 JNIEnv* env = AttachCurrentThread(); 93 JNIEnv* env = AttachCurrentThread();
82 base::android::ScopedJavaLocalRef<jstring> java_value =
83 ConvertUTF8ToJavaString(env, value);
84 j_date_time_chooser_.Reset(Java_DateTimeChooserAndroid_createDateTimeChooser( 94 j_date_time_chooser_.Reset(Java_DateTimeChooserAndroid_createDateTimeChooser(
85 env, content->GetJavaObject().obj(), 95 env, content->GetJavaObject().obj(),
86 reinterpret_cast<intptr_t>(this), java_value.obj(), type)); 96 reinterpret_cast<intptr_t>(this),
97 type, year, month, day, hour, minute, second));
87 } 98 }
88 99
89 // ---------------------------------------------------------------------------- 100 // ----------------------------------------------------------------------------
90 // Native JNI methods 101 // Native JNI methods
91 // ---------------------------------------------------------------------------- 102 // ----------------------------------------------------------------------------
92 bool RegisterDateTimeChooserAndroid(JNIEnv* env) { 103 bool RegisterDateTimeChooserAndroid(JNIEnv* env) {
93 bool registered = RegisterNativesImpl(env); 104 bool registered = RegisterNativesImpl(env);
94 if (registered) 105 if (registered)
95 DateTimeChooserAndroid::InitializeDateInputTypes( 106 DateTimeChooserAndroid::InitializeDateInputTypes(
96 ui::TEXT_INPUT_TYPE_DATE, 107 ui::TEXT_INPUT_TYPE_DATE,
97 ui::TEXT_INPUT_TYPE_DATE_TIME, 108 ui::TEXT_INPUT_TYPE_DATE_TIME,
98 ui::TEXT_INPUT_TYPE_DATE_TIME_LOCAL, 109 ui::TEXT_INPUT_TYPE_DATE_TIME_LOCAL,
99 ui::TEXT_INPUT_TYPE_MONTH, 110 ui::TEXT_INPUT_TYPE_MONTH,
100 ui::TEXT_INPUT_TYPE_TIME); 111 ui::TEXT_INPUT_TYPE_TIME);
101 return registered; 112 return registered;
102 } 113 }
103 114
104 } // namespace content 115 } // namespace content
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698