Chromium Code Reviews| OLD | NEW |
|---|---|
| (Empty) | |
| 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 | |
| 3 // found in the LICENSE file. | |
| 4 | |
| 5 #include "content/browser/android/date_time_chooser_android.h" | |
| 6 | |
| 7 #include "base/android/jni_string.h" | |
| 8 #include "content/common/view_messages.h" | |
| 9 #include "content/public/browser/android/content_view_core.h" | |
| 10 #include "content/public/browser/render_view_host_observer.h" | |
| 11 #include "jni/DateTimeChooserAndroid_jni.h" | |
| 12 | |
| 13 using base::android::AttachCurrentThread; | |
| 14 using base::android::ConvertJavaStringToUTF16; | |
| 15 using base::android::ConvertUTF8ToJavaString; | |
| 16 | |
| 17 | |
| 18 namespace content { | |
| 19 | |
| 20 // Updates date/time via IPC to the RenderView | |
| 21 class DateTimeChooserAndroid::DateTimeIPCSender : | |
| 22 public RenderViewHostObserver { | |
| 23 public: | |
| 24 explicit DateTimeIPCSender(RenderViewHost* sender); | |
| 25 virtual ~DateTimeIPCSender() {} | |
| 26 void ReplaceDateTime(string16 text); | |
| 27 void CancelDialog(); | |
| 28 | |
| 29 private: | |
| 30 DISALLOW_COPY_AND_ASSIGN(DateTimeIPCSender); | |
| 31 }; | |
| 32 | |
| 33 DateTimeChooserAndroid::DateTimeIPCSender::DateTimeIPCSender( | |
| 34 RenderViewHost* sender) | |
| 35 : RenderViewHostObserver(sender) { | |
| 36 } | |
| 37 | |
| 38 void DateTimeChooserAndroid::DateTimeIPCSender::ReplaceDateTime( | |
| 39 string16 text) { | |
| 40 Send(new ViewMsg_ReplaceDateTime(routing_id(), text)); | |
| 41 } | |
| 42 | |
| 43 void DateTimeChooserAndroid::DateTimeIPCSender::CancelDialog() { | |
| 44 Send(new ViewMsg_CancelDateTimeDialog(routing_id())); | |
| 45 } | |
| 46 | |
| 47 // DateTimeChooserAndroid implementation | |
| 48 DateTimeChooserAndroid::DateTimeChooserAndroid() { | |
| 49 } | |
| 50 | |
| 51 DateTimeChooserAndroid::~DateTimeChooserAndroid() { | |
| 52 } | |
| 53 | |
| 54 // static | |
| 55 void DateTimeChooserAndroid::InitializeDateInputTypes( | |
| 56 int text_input_type_date, int text_input_type_date_time, | |
| 57 int text_input_type_date_time_local, int text_input_type_month, | |
| 58 int text_input_type_time) { | |
| 59 JNIEnv* env = AttachCurrentThread(); | |
| 60 Java_DateTimeChooserAndroid_initializeDateInputTypes( | |
| 61 env, | |
| 62 text_input_type_date, text_input_type_date_time, | |
| 63 text_input_type_date_time_local, text_input_type_month, | |
| 64 text_input_type_time); | |
| 65 } | |
| 66 | |
| 67 void DateTimeChooserAndroid::ReplaceDateTime( | |
| 68 JNIEnv* env, jobject, jstring text) { | |
|
palmer
2013/01/14 23:53:35
My security and correctness instinct is to receive
| |
| 69 string16 text16 = ConvertJavaStringToUTF16(env, text); | |
| 70 communicator_->ReplaceDateTime(text16); | |
| 71 } | |
| 72 | |
| 73 void DateTimeChooserAndroid::CancelDialog(JNIEnv* env, jobject) { | |
| 74 communicator_->CancelDialog(); | |
| 75 } | |
| 76 | |
| 77 void DateTimeChooserAndroid::ShowDialog( | |
| 78 ContentViewCore* content, RenderViewHost* sender, | |
| 79 int type, const std::string& value) { | |
| 80 communicator_.reset(new DateTimeIPCSender(sender)); | |
| 81 JNIEnv* env = AttachCurrentThread(); | |
| 82 base::android::ScopedJavaLocalRef<jstring> java_value = | |
|
palmer
2013/01/14 23:53:35
NIT: Two spaces between type and identifier.
Miguel Garcia
2013/01/17 12:17:40
Done.
| |
| 83 ConvertUTF8ToJavaString(env, value); | |
| 84 j_date_time_chooser_.Reset(Java_DateTimeChooserAndroid_createDateTimeChooser( | |
| 85 env, content->GetJavaObject().obj(), | |
| 86 reinterpret_cast<intptr_t>(this), java_value.obj(), type)); | |
| 87 } | |
| 88 | |
| 89 // ---------------------------------------------------------------------------- | |
| 90 // Native JNI methods | |
| 91 // ---------------------------------------------------------------------------- | |
| 92 bool RegisterDateTimeChooserAndroid(JNIEnv* env) { | |
| 93 bool registered = RegisterNativesImpl(env); | |
| 94 if (registered) | |
| 95 DateTimeChooserAndroid::InitializeDateInputTypes( | |
| 96 ui::TEXT_INPUT_TYPE_DATE, | |
| 97 ui::TEXT_INPUT_TYPE_DATE_TIME, | |
| 98 ui::TEXT_INPUT_TYPE_DATE_TIME_LOCAL, | |
| 99 ui::TEXT_INPUT_TYPE_MONTH, | |
| 100 ui::TEXT_INPUT_TYPE_TIME); | |
| 101 return registered; | |
| 102 } | |
| 103 | |
| 104 } // namespace content | |
| OLD | NEW |