[email protected] | 5b6f069 | 2012-06-12 05:00:05 | [diff] [blame] | 1 | // 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] | 3093536 | 2012-06-28 21:26:23 | [diff] [blame] | 7 | #include "base/android/jni_array.h" |
[email protected] | 5b6f069 | 2012-06-12 05:00:05 | [diff] [blame] | 8 | #include "base/global_descriptors_posix.h" |
| 9 | #include "base/logging.h" |
| 10 | #include "content/common/android/surface_texture_peer.h" |
[email protected] | 5b6f069 | 2012-06-12 05:00:05 | [diff] [blame] | 11 | #include "content/public/app/android_library_loader_hooks.h" |
[email protected] | 1602cde | 2012-06-26 15:09:12 | [diff] [blame] | 12 | #include "content/public/common/content_descriptors.h" |
[email protected] | 5b6f069 | 2012-06-12 05:00:05 | [diff] [blame] | 13 | #include "ipc/ipc_descriptors.h" |
[email protected] | e46f6615 | 2012-07-19 20:02:55 | [diff] [blame] | 14 | #include "jni/SandboxedProcessService_jni.h" |
[email protected] | 5b6f069 | 2012-06-12 05:00:05 | [diff] [blame] | 15 | |
| 16 | using base::android::AttachCurrentThread; |
| 17 | using base::android::CheckException; |
[email protected] | 3093536 | 2012-06-28 21:26:23 | [diff] [blame] | 18 | using base::android::JavaIntArrayToIntVector; |
[email protected] | 5b6f069 | 2012-06-12 05:00:05 | [diff] [blame] | 19 | |
| 20 | namespace { |
| 21 | |
| 22 | class 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] | 11387d28 | 2012-10-10 04:38:17 | [diff] [blame^] | 33 | 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] | 5b6f069 | 2012-06-12 05:00:05 | [diff] [blame] | 39 | JNIEnv* env = base::android::AttachCurrentThread(); |
[email protected] | 1963002 | 2012-06-25 18:58:07 | [diff] [blame] | 40 | content::Java_SandboxedProcessService_establishSurfaceTexturePeer( |
[email protected] | 11387d28 | 2012-10-10 04:38:17 | [diff] [blame^] | 41 | env, service_, pid, type, |
| 42 | surface_texture_bridge->j_surface_texture().obj(), primary_id, |
| 43 | secondary_id); |
[email protected] | 5b6f069 | 2012-06-12 05:00:05 | [diff] [blame] | 44 | 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] | c7abd42 | 2012-09-25 00:20:08 | [diff] [blame] | 56 | void InternalInitSandboxedProcess(const std::vector<int>& file_ids, |
| 57 | const std::vector<int>& file_fds, |
[email protected] | 5b6f069 | 2012-06-12 05:00:05 | [diff] [blame] | 58 | JNIEnv* env, |
| 59 | jclass clazz, |
| 60 | jobject context, |
| 61 | jobject service) { |
[email protected] | c7abd42 | 2012-09-25 00:20:08 | [diff] [blame] | 62 | // 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] | 3093536 | 2012-06-28 21:26:23 | [diff] [blame] | 68 | |
[email protected] | 5b6f069 | 2012-06-12 05:00:05 | [diff] [blame] | 69 | content::SurfaceTexturePeer::InitInstance( |
| 70 | new SurfaceTexturePeerSandboxedImpl(service)); |
| 71 | |
| 72 | } |
| 73 | |
| 74 | } // namespace <anonymous> |
| 75 | |
[email protected] | 1963002 | 2012-06-25 18:58:07 | [diff] [blame] | 76 | namespace content { |
| 77 | |
| 78 | void InitSandboxedProcess(JNIEnv* env, |
| 79 | jclass clazz, |
| 80 | jobject context, |
| 81 | jobject service, |
[email protected] | c7abd42 | 2012-09-25 00:20:08 | [diff] [blame] | 82 | 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] | 5b6f069 | 2012-06-12 05:00:05 | [diff] [blame] | 88 | |
[email protected] | c7abd42 | 2012-09-25 00:20:08 | [diff] [blame] | 89 | InternalInitSandboxedProcess( |
| 90 | file_ids, file_fds, env, clazz, context, service); |
[email protected] | 5b6f069 | 2012-06-12 05:00:05 | [diff] [blame] | 91 | } |
| 92 | |
[email protected] | 1963002 | 2012-06-25 18:58:07 | [diff] [blame] | 93 | void ExitSandboxedProcess(JNIEnv* env, jclass clazz) { |
[email protected] | 5b6f069 | 2012-06-12 05:00:05 | [diff] [blame] | 94 | LOG(INFO) << "SandboxedProcessService: Exiting sandboxed process."; |
[email protected] | 1963002 | 2012-06-25 18:58:07 | [diff] [blame] | 95 | LibraryLoaderExitHook(); |
[email protected] | 5b6f069 | 2012-06-12 05:00:05 | [diff] [blame] | 96 | _exit(0); |
| 97 | } |
| 98 | |
[email protected] | 5b6f069 | 2012-06-12 05:00:05 | [diff] [blame] | 99 | bool RegisterSandboxedProcessService(JNIEnv* env) { |
| 100 | return RegisterNativesImpl(env); |
| 101 | } |
| 102 | |
| 103 | } // namespace content |