blob: 2b3b2006f10c77f242a041999496778a882c7280 [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"
[email protected]e46f66152012-07-19 20:02:5514#include "jni/SandboxedProcessService_jni.h"
[email protected]5b6f0692012-06-12 05:00:0515
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
[email protected]11387d282012-10-10 04:38:1733 virtual void EstablishSurfaceTexturePeer(
34 base::ProcessHandle pid,
35 SurfaceTextureTarget type,
36 scoped_refptr<content::SurfaceTextureBridge> surface_texture_bridge,
37 int primary_id,
38 int secondary_id) {
[email protected]5b6f0692012-06-12 05:00:0539 JNIEnv* env = base::android::AttachCurrentThread();
[email protected]19630022012-06-25 18:58:0740 content::Java_SandboxedProcessService_establishSurfaceTexturePeer(
[email protected]11387d282012-10-10 04:38:1741 env, service_, pid, type,
42 surface_texture_bridge->j_surface_texture().obj(), primary_id,
43 secondary_id);
[email protected]5b6f0692012-06-12 05:00:0544 CheckException(env);
45 }
46
47 private:
48 // The instance of org.chromium.content.app.SandboxedProcessService.
49 jobject service_;
50
51 DISALLOW_COPY_AND_ASSIGN(SurfaceTexturePeerSandboxedImpl);
52};
53
54// Chrome actually uses the renderer code path for all of its sandboxed
55// processes such as renderers, plugins, etc.
[email protected]c7abd422012-09-25 00:20:0856void InternalInitSandboxedProcess(const std::vector<int>& file_ids,
57 const std::vector<int>& file_fds,
[email protected]5b6f0692012-06-12 05:00:0558 JNIEnv* env,
59 jclass clazz,
60 jobject context,
61 jobject service) {
[email protected]c7abd422012-09-25 00:20:0862 // Register the file descriptors.
63 // This includes the IPC channel, the crash dump signals and resource related
64 // files.
65 DCHECK(file_fds.size() == file_ids.size());
66 for (size_t i = 0; i < file_ids.size(); ++i)
67 base::GlobalDescriptors::GetInstance()->Set(file_ids[i], file_fds[i]);
[email protected]30935362012-06-28 21:26:2368
[email protected]5b6f0692012-06-12 05:00:0569 content::SurfaceTexturePeer::InitInstance(
70 new SurfaceTexturePeerSandboxedImpl(service));
71
72}
73
74} // namespace <anonymous>
75
[email protected]19630022012-06-25 18:58:0776namespace content {
77
78void InitSandboxedProcess(JNIEnv* env,
79 jclass clazz,
80 jobject context,
81 jobject service,
[email protected]c7abd422012-09-25 00:20:0882 jintArray j_file_ids,
83 jintArray j_file_fds) {
84 std::vector<int> file_ids;
85 std::vector<int> file_fds;
86 JavaIntArrayToIntVector(env, j_file_ids, &file_ids);
87 JavaIntArrayToIntVector(env, j_file_fds, &file_fds);
[email protected]5b6f0692012-06-12 05:00:0588
[email protected]c7abd422012-09-25 00:20:0889 InternalInitSandboxedProcess(
90 file_ids, file_fds, env, clazz, context, service);
[email protected]5b6f0692012-06-12 05:00:0591}
92
[email protected]19630022012-06-25 18:58:0793void ExitSandboxedProcess(JNIEnv* env, jclass clazz) {
[email protected]5b6f0692012-06-12 05:00:0594 LOG(INFO) << "SandboxedProcessService: Exiting sandboxed process.";
[email protected]19630022012-06-25 18:58:0795 LibraryLoaderExitHook();
[email protected]5b6f0692012-06-12 05:00:0596 _exit(0);
97}
98
[email protected]5b6f0692012-06-12 05:00:0599bool RegisterSandboxedProcessService(JNIEnv* env) {
100 return RegisterNativesImpl(env);
101}
102
103} // namespace content