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

Unified Diff: ui/base/dialogs/select_file_dialog_android.cc

Issue 10916160: Upstreaming SelectFileDialog for Android (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Created 8 years, 3 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 side-by-side diff with in-line comments
Download patch
« no previous file with comments | « ui/base/dialogs/select_file_dialog_android.h ('k') | ui/gfx/android/window_android.h » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: ui/base/dialogs/select_file_dialog_android.cc
diff --git a/ui/base/dialogs/select_file_dialog_android.cc b/ui/base/dialogs/select_file_dialog_android.cc
new file mode 100644
index 0000000000000000000000000000000000000000..993eb58ff16185bb188c4864163d5e0dda4e1ee5
--- /dev/null
+++ b/ui/base/dialogs/select_file_dialog_android.cc
@@ -0,0 +1,113 @@
+// Copyright (c) 2012 The Chromium Authors. All rights reserved.
+// Use of this source code is governed by a BSD-style license that can be
+// found in the LICENSE file.
+
+#include "select_file_dialog_android.h"
+
+#include "base/android/jni_android.h"
+#include "base/android/jni_string.h"
+#include "base/android/jni_array.h"
+#include "base/android/scoped_java_ref.h"
+#include "base/logging.h"
+#include "base/string_split.h"
+#include "base/string_util.h"
+#include "base/utf_string_conversions.h"
+#include "jni/SelectFileDialog_jni.h"
+#include "ui/gfx/android/window_android.h"
+
+namespace ui {
+
+// static
+SelectFileDialogImpl* SelectFileDialogImpl::Create(Listener* listener,
+ ui::SelectFilePolicy* policy) {
+ return new SelectFileDialogImpl(listener, policy);
+}
+
+void SelectFileDialogImpl::OnFileSelected(JNIEnv* env,
+ jobject java_object,
+ jstring filepath) {
+ if (listener_) {
+ std::string path = base::android::ConvertJavaStringToUTF8(env, filepath);
+ listener_->FileSelected(FilePath(path), 0, NULL);
+ }
+
+ is_running_ = false;
+}
+
+void SelectFileDialogImpl::OnFileNotSelected(
+ JNIEnv* env,
+ jobject java_object) {
+ if (listener_)
+ listener_->FileSelectionCanceled(NULL);
+
+ is_running_ = false;
+}
+
+bool SelectFileDialogImpl::IsRunning(gfx::NativeWindow) const {
+ return is_running_;
+}
+
+void SelectFileDialogImpl::ListenerDestroyed() {
+ listener_ = NULL;
+}
+
+void SelectFileDialogImpl::SelectFileImpl(
+ ui::SelectFileDialog::Type type,
+ const string16& title,
+ const FilePath& default_path,
+ const SelectFileDialog::FileTypeInfo* file_types,
+ int file_type_index,
+ const std::string& default_extension,
+ gfx::NativeWindow owning_window,
+ void* params) {
+ JNIEnv* env = base::android::AttachCurrentThread();
+
+ std::vector<string16> accept_types =
+ *(reinterpret_cast<std::vector<string16>*>(params));
+
+ // The last string in params is expected to be the string with capture value.
+ ScopedJavaLocalRef<jstring> capture_value =
+ base::android::ConvertUTF16ToJavaString(env,
+ StringToLowerASCII(accept_types.back()));
+ base::android::CheckException(env);
+ accept_types.pop_back();
+
+ // The rest params elements are expected to be accept_types.
+ ScopedJavaLocalRef<jobjectArray> accept_types_java =
+ base::android::ToJavaArrayOfStrings(env, accept_types);
+
+ Java_SelectFileDialog_selectFile(env, java_object_.obj(),
+ accept_types_java.obj(),
+ capture_value.obj(),
+ owning_window->GetJavaObject().obj());
+ is_running_ = true;
+}
+
+bool SelectFileDialogImpl::RegisterSelectFileDialog(JNIEnv* env) {
+ return RegisterNativesImpl(env);
+}
+
+SelectFileDialogImpl::~SelectFileDialogImpl() {
+}
+
+SelectFileDialogImpl::SelectFileDialogImpl(Listener* listener,
+ ui::SelectFilePolicy* policy)
+ : ui::SelectFileDialog(listener, policy),
+ is_running_(false) {
+ JNIEnv* env = base::android::AttachCurrentThread();
+ java_object_.Reset(
+ Java_SelectFileDialog_create(env, reinterpret_cast<jint>(this)));
+}
+
+bool SelectFileDialogImpl::HasMultipleFileTypeChoicesImpl() {
+ NOTIMPLEMENTED();
+ return false;
+}
+
+SelectFileDialog* CreateAndroidSelectFileDialog(
+ SelectFileDialog::Listener* listener,
+ SelectFilePolicy* policy) {
+ return SelectFileDialogImpl::Create(listener, policy);
+}
+
+} // namespace ui
« no previous file with comments | « ui/base/dialogs/select_file_dialog_android.h ('k') | ui/gfx/android/window_android.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698