blob: 58a2687bda81b5d0d7cb93558b5fd7e4df2d63ab [file] [log] [blame]
[email protected]5b6f0692012-06-12 05:00:051// Copyright (c) 2012 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/app/android/sandboxed_process_service.h"
6
[email protected]30935362012-06-28 21:26:237#include "base/android/jni_array.h"
[email protected]5b6f0692012-06-12 05:00:058#include "base/global_descriptors_posix.h"
9#include "base/logging.h"
10#include "content/common/android/surface_texture_peer.h"
[email protected]5b6f0692012-06-12 05:00:0511#include "content/public/app/android_library_loader_hooks.h"
[email protected]1602cde2012-06-26 15:09:1212#include "content/public/common/content_descriptors.h"
[email protected]5b6f0692012-06-12 05:00:0513#include "ipc/ipc_descriptors.h"
14#include "jni/sandboxed_process_service_jni.h"
15
16using base::android::AttachCurrentThread;
17using base::android::CheckException;
[email protected]30935362012-06-28 21:26:2318using base::android::JavaIntArrayToIntVector;
[email protected]5b6f0692012-06-12 05:00:0519
20namespace {
21
22class SurfaceTexturePeerSandboxedImpl : public content::SurfaceTexturePeer {
23 public:
24 // |service| is the instance of
25 // org.chromium.content.app.SandboxedProcessService.
26 SurfaceTexturePeerSandboxedImpl(jobject service)
27 : service_(service) {
28 }
29
30 virtual ~SurfaceTexturePeerSandboxedImpl() {
31 }
32
33 virtual void EstablishSurfaceTexturePeer(base::ProcessHandle pid,
34 SurfaceTextureTarget type,
35 jobject j_surface_texture,
36 int primary_id,
37 int secondary_id) {
38 JNIEnv* env = base::android::AttachCurrentThread();
[email protected]19630022012-06-25 18:58:0739 content::Java_SandboxedProcessService_establishSurfaceTexturePeer(
[email protected]30935362012-06-28 21:26:2340 env, service_, pid, type, j_surface_texture, primary_id, secondary_id);
[email protected]5b6f0692012-06-12 05:00:0541 CheckException(env);
42 }
43
44 private:
45 // The instance of org.chromium.content.app.SandboxedProcessService.
46 jobject service_;
47
48 DISALLOW_COPY_AND_ASSIGN(SurfaceTexturePeerSandboxedImpl);
49};
50
51// Chrome actually uses the renderer code path for all of its sandboxed
52// processes such as renderers, plugins, etc.
53void InternalInitSandboxedProcess(int ipc_fd,
[email protected]30935362012-06-28 21:26:2354 const std::vector<int>& extra_file_ids,
55 const std::vector<int>& extra_file_fds,
[email protected]5b6f0692012-06-12 05:00:0556 JNIEnv* env,
57 jclass clazz,
58 jobject context,
59 jobject service) {
60 // Set up the IPC file descriptor mapping.
61 base::GlobalDescriptors::GetInstance()->Set(kPrimaryIPCChannel, ipc_fd);
[email protected]30935362012-06-28 21:26:2362 // Register the extra file descriptors.
63 // This usually include the crash dump signals and resource related files.
64 DCHECK(extra_file_fds.size() == extra_file_ids.size());
65 for (size_t i = 0; i < extra_file_ids.size(); ++i) {
66 base::GlobalDescriptors::GetInstance()->Set(extra_file_ids[i],
67 extra_file_fds[i]);
[email protected]5b6f0692012-06-12 05:00:0568 }
[email protected]30935362012-06-28 21:26:2369
[email protected]5b6f0692012-06-12 05:00:0570 content::SurfaceTexturePeer::InitInstance(
71 new SurfaceTexturePeerSandboxedImpl(service));
72
73}
74
75} // namespace <anonymous>
76
[email protected]19630022012-06-25 18:58:0777namespace content {
78
79void InitSandboxedProcess(JNIEnv* env,
80 jclass clazz,
81 jobject context,
82 jobject service,
83 jint ipc_fd,
[email protected]30935362012-06-28 21:26:2384 jintArray j_extra_file_ids,
85 jintArray j_extra_file_fds) {
86 std::vector<int> extra_file_ids;
87 std::vector<int> extra_file_fds;
88 JavaIntArrayToIntVector(env, j_extra_file_ids, &extra_file_ids);
89 JavaIntArrayToIntVector(env, j_extra_file_fds, &extra_file_fds);
[email protected]5b6f0692012-06-12 05:00:0590
[email protected]30935362012-06-28 21:26:2391 InternalInitSandboxedProcess(static_cast<int>(ipc_fd),
92 extra_file_ids, extra_file_fds,
93 env, clazz, context, service);
[email protected]5b6f0692012-06-12 05:00:0594}
95
[email protected]19630022012-06-25 18:58:0796void ExitSandboxedProcess(JNIEnv* env, jclass clazz) {
[email protected]5b6f0692012-06-12 05:00:0597 LOG(INFO) << "SandboxedProcessService: Exiting sandboxed process.";
[email protected]19630022012-06-25 18:58:0798 LibraryLoaderExitHook();
[email protected]5b6f0692012-06-12 05:00:0599 _exit(0);
100}
101
[email protected]5b6f0692012-06-12 05:00:05102bool RegisterSandboxedProcessService(JNIEnv* env) {
103 return RegisterNativesImpl(env);
104}
105
106} // namespace content