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

Unified Diff: services/android/java_handler.cc

Issue 898853006: Java content handler for Android. (Closed) Base URL: git@github.com:domokit/mojo.git@master
Patch Set: Created 5 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 side-by-side diff with in-line comments
Download patch
« no previous file with comments | « services/android/java_handler.h ('k') | services/android/rules.gni » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: services/android/java_handler.cc
diff --git a/services/android/java_handler.cc b/services/android/java_handler.cc
new file mode 100644
index 0000000000000000000000000000000000000000..d26b376c891793bde21f9d50e8a91f3c33149da9
--- /dev/null
+++ b/services/android/java_handler.cc
@@ -0,0 +1,96 @@
+// Copyright 2014 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 "services/android/java_handler.h"
+
+#include "base/android/jni_android.h"
+#include "base/android/jni_string.h"
+#include "base/files/file_path.h"
+#include "base/logging.h"
+#include "base/scoped_native_library.h"
+#include "jni/JavaHandler_jni.h"
+#include "mojo/android/system/base_run_loop.h"
+#include "mojo/android/system/core_impl.h"
+#include "mojo/application/application_runner_chromium.h"
+#include "mojo/application/content_handler_factory.h"
+#include "mojo/common/data_pipe_utils.h"
+#include "mojo/public/c/system/main.h"
+#include "mojo/public/cpp/application/application_impl.h"
+
+using base::android::AttachCurrentThread;
+using base::android::ScopedJavaLocalRef;
+using base::android::ConvertJavaStringToUTF8;
+using base::android::ConvertUTF8ToJavaString;
+using base::android::GetApplicationContext;
+
+namespace services {
+namespace android {
+JavaHandler::JavaHandler() : content_handler_factory_(this) {
+}
+
+JavaHandler::~JavaHandler() {
+}
+
+void JavaHandler::RunApplication(
+ mojo::InterfaceRequest<mojo::Application> application_request,
+ mojo::URLResponsePtr response) {
+ JNIEnv* env = base::android::AttachCurrentThread();
+ ScopedJavaLocalRef<jstring> j_archive_path =
+ Java_JavaHandler_getNewTempLibraryPath(env, GetApplicationContext());
+ base::FilePath archive_path(
+ base::android::ConvertJavaStringToUTF8(env, j_archive_path.obj()));
+
+ mojo::common::BlockingCopyToFile(response->body.Pass(), archive_path);
+
+ jobject context = base::android::GetApplicationContext();
+ Java_JavaHandler_bootstrap(
+ env, context, j_archive_path.obj(),
+ application_request.PassMessagePipe().release().value());
+}
+
+void JavaHandler::Initialize(mojo::ApplicationImpl* app) {
+}
+
+bool JavaHandler::ConfigureIncomingConnection(
+ mojo::ApplicationConnection* connection) {
+ connection->AddService(&content_handler_factory_);
+ return true;
+}
+
+bool RegisterJavaHandlerJni(JNIEnv* env) {
+ return RegisterNativesImpl(env);
+}
+
+} // namespace android
+} // namespace services
+
+MojoResult MojoMain(MojoHandle shell_handle) {
+ mojo::ApplicationRunnerChromium runner(new services::android::JavaHandler());
+ return runner.Run(shell_handle);
+}
+
+JNI_EXPORT jint JNI_OnLoad(JavaVM* vm, void* reserved) {
+ base::android::InitVM(vm);
+ JNIEnv* env = base::android::AttachCurrentThread();
+
+ if (!services::android::RegisterJavaHandlerJni(env))
+ return -1;
+
+ if (!mojo::android::RegisterCoreImpl(env))
+ return -1;
+
+ if (!mojo::android::RegisterBaseRunLoop(env))
+ return -1;
+
+ return JNI_VERSION_1_4;
+}
+
+// This is needed because the application needs to access the application
+// context.
+extern "C" JNI_EXPORT void InitApplicationContext(
+ const base::android::JavaRef<jobject>& context) {
+ JNIEnv* env = base::android::AttachCurrentThread();
+ base::android::InitApplicationContext(env, context);
+}
+
« no previous file with comments | « services/android/java_handler.h ('k') | services/android/rules.gni » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698