| OLD | NEW |
| 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 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 | 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
| 4 | 4 |
| 5 #include "content/app/android/sandboxed_process_service.h" | 5 #include "content/app/android/sandboxed_process_service.h" |
| 6 | 6 |
| 7 #include <android/native_window_jni.h> |
| 7 #include <cpu-features.h> | 8 #include <cpu-features.h> |
| 8 | 9 |
| 9 #include "base/android/jni_array.h" | 10 #include "base/android/jni_array.h" |
| 10 #include "base/logging.h" | 11 #include "base/logging.h" |
| 11 #include "base/posix/global_descriptors.h" | 12 #include "base/posix/global_descriptors.h" |
| 13 #include "content/common/android/scoped_java_surface.h" |
| 12 #include "content/common/android/surface_texture_peer.h" | 14 #include "content/common/android/surface_texture_peer.h" |
| 13 #include "content/common/child_process.h" | 15 #include "content/common/child_process.h" |
| 14 #include "content/common/child_thread.h" | 16 #include "content/common/child_thread.h" |
| 17 #include "content/common/gpu/gpu_surface_lookup.h" |
| 15 #include "content/public/app/android_library_loader_hooks.h" | 18 #include "content/public/app/android_library_loader_hooks.h" |
| 16 #include "content/public/common/content_descriptors.h" | 19 #include "content/public/common/content_descriptors.h" |
| 17 #include "ipc/ipc_descriptors.h" | 20 #include "ipc/ipc_descriptors.h" |
| 18 #include "jni/SandboxedProcessService_jni.h" | 21 #include "jni/SandboxedProcessService_jni.h" |
| 19 | 22 |
| 20 using base::android::AttachCurrentThread; | 23 using base::android::AttachCurrentThread; |
| 21 using base::android::CheckException; | 24 using base::android::CheckException; |
| 22 using base::android::JavaIntArrayToIntVector; | 25 using base::android::JavaIntArrayToIntVector; |
| 23 | 26 |
| 27 namespace content { |
| 28 |
| 24 namespace { | 29 namespace { |
| 25 | 30 |
| 26 class SurfaceTexturePeerSandboxedImpl : public content::SurfaceTexturePeer { | 31 class SurfaceTexturePeerSandboxedImpl : public content::SurfaceTexturePeer, |
| 32 public content::GpuSurfaceLookup { |
| 27 public: | 33 public: |
| 28 // |service| is the instance of | 34 // |service| is the instance of |
| 29 // org.chromium.content.app.SandboxedProcessService. | 35 // org.chromium.content.app.SandboxedProcessService. |
| 30 SurfaceTexturePeerSandboxedImpl(jobject service) | 36 explicit SurfaceTexturePeerSandboxedImpl( |
| 37 const base::android::ScopedJavaLocalRef<jobject>& service) |
| 31 : service_(service) { | 38 : service_(service) { |
| 39 GpuSurfaceLookup::InitInstance(this); |
| 32 } | 40 } |
| 33 | 41 |
| 34 virtual ~SurfaceTexturePeerSandboxedImpl() { | 42 virtual ~SurfaceTexturePeerSandboxedImpl() { |
| 43 GpuSurfaceLookup::InitInstance(NULL); |
| 35 } | 44 } |
| 36 | 45 |
| 37 virtual void EstablishSurfaceTexturePeer( | 46 virtual void EstablishSurfaceTexturePeer( |
| 38 base::ProcessHandle pid, | 47 base::ProcessHandle pid, |
| 39 scoped_refptr<content::SurfaceTextureBridge> surface_texture_bridge, | 48 scoped_refptr<content::SurfaceTextureBridge> surface_texture_bridge, |
| 40 int primary_id, | 49 int primary_id, |
| 41 int secondary_id) { | 50 int secondary_id) { |
| 42 JNIEnv* env = base::android::AttachCurrentThread(); | 51 JNIEnv* env = base::android::AttachCurrentThread(); |
| 43 content::Java_SandboxedProcessService_establishSurfaceTexturePeer( | 52 content::Java_SandboxedProcessService_establishSurfaceTexturePeer( |
| 44 env, service_, pid, | 53 env, service_.obj(), pid, |
| 45 surface_texture_bridge->j_surface_texture().obj(), primary_id, | 54 surface_texture_bridge->j_surface_texture().obj(), primary_id, |
| 46 secondary_id); | 55 secondary_id); |
| 47 CheckException(env); | 56 CheckException(env); |
| 48 } | 57 } |
| 49 | 58 |
| 59 virtual gfx::AcceleratedWidget AcquireNativeWidget(int surface_id) OVERRIDE { |
| 60 JNIEnv* env = base::android::AttachCurrentThread(); |
| 61 ScopedJavaSurface surface( |
| 62 content::Java_SandboxedProcessService_getViewSurface( |
| 63 env, service_.obj(), surface_id)); |
| 64 |
| 65 if (surface.j_surface().is_null()) |
| 66 return NULL; |
| 67 |
| 68 ANativeWindow* native_window = ANativeWindow_fromSurface( |
| 69 env, surface.j_surface().obj()); |
| 70 |
| 71 return native_window; |
| 72 } |
| 73 |
| 50 private: | 74 private: |
| 51 // The instance of org.chromium.content.app.SandboxedProcessService. | 75 // The instance of org.chromium.content.app.SandboxedProcessService. |
| 52 jobject service_; | 76 base::android::ScopedJavaGlobalRef<jobject> service_; |
| 53 | 77 |
| 54 DISALLOW_COPY_AND_ASSIGN(SurfaceTexturePeerSandboxedImpl); | 78 DISALLOW_COPY_AND_ASSIGN(SurfaceTexturePeerSandboxedImpl); |
| 55 }; | 79 }; |
| 56 | 80 |
| 57 // Chrome actually uses the renderer code path for all of its sandboxed | 81 // Chrome actually uses the renderer code path for all of its sandboxed |
| 58 // processes such as renderers, plugins, etc. | 82 // processes such as renderers, plugins, etc. |
| 59 void InternalInitSandboxedProcess(const std::vector<int>& file_ids, | 83 void InternalInitSandboxedProcess(const std::vector<int>& file_ids, |
| 60 const std::vector<int>& file_fds, | 84 const std::vector<int>& file_fds, |
| 61 JNIEnv* env, | 85 JNIEnv* env, |
| 62 jclass clazz, | 86 jclass clazz, |
| 63 jobject context, | 87 jobject context, |
| 64 jobject service, | 88 jobject service_in, |
| 65 jint cpu_count, | 89 jint cpu_count, |
| 66 jlong cpu_features) { | 90 jlong cpu_features) { |
| 91 base::android::ScopedJavaLocalRef<jobject> service(env, service_in); |
| 92 |
| 67 // Set the CPU properties. | 93 // Set the CPU properties. |
| 68 android_setCpu(cpu_count, cpu_features); | 94 android_setCpu(cpu_count, cpu_features); |
| 69 // Register the file descriptors. | 95 // Register the file descriptors. |
| 70 // This includes the IPC channel, the crash dump signals and resource related | 96 // This includes the IPC channel, the crash dump signals and resource related |
| 71 // files. | 97 // files. |
| 72 DCHECK(file_fds.size() == file_ids.size()); | 98 DCHECK(file_fds.size() == file_ids.size()); |
| 73 for (size_t i = 0; i < file_ids.size(); ++i) | 99 for (size_t i = 0; i < file_ids.size(); ++i) |
| 74 base::GlobalDescriptors::GetInstance()->Set(file_ids[i], file_fds[i]); | 100 base::GlobalDescriptors::GetInstance()->Set(file_ids[i], file_fds[i]); |
| 75 | 101 |
| 76 content::SurfaceTexturePeer::InitInstance( | 102 content::SurfaceTexturePeer::InitInstance( |
| 77 new SurfaceTexturePeerSandboxedImpl(service)); | 103 new SurfaceTexturePeerSandboxedImpl(service)); |
| 78 | 104 |
| 79 } | 105 } |
| 80 | 106 |
| 81 void QuitSandboxMainThreadMessageLoop() { | 107 void QuitSandboxMainThreadMessageLoop() { |
| 82 MessageLoop::current()->Quit(); | 108 MessageLoop::current()->Quit(); |
| 83 } | 109 } |
| 84 | 110 |
| 85 } // namespace <anonymous> | 111 } // namespace <anonymous> |
| 86 | 112 |
| 87 namespace content { | |
| 88 | |
| 89 void InitSandboxedProcess(JNIEnv* env, | 113 void InitSandboxedProcess(JNIEnv* env, |
| 90 jclass clazz, | 114 jclass clazz, |
| 91 jobject context, | 115 jobject context, |
| 92 jobject service, | 116 jobject service, |
| 93 jintArray j_file_ids, | 117 jintArray j_file_ids, |
| 94 jintArray j_file_fds, | 118 jintArray j_file_fds, |
| 95 jint cpu_count, | 119 jint cpu_count, |
| 96 jlong cpu_features) { | 120 jlong cpu_features) { |
| 97 std::vector<int> file_ids; | 121 std::vector<int> file_ids; |
| 98 std::vector<int> file_fds; | 122 std::vector<int> file_fds; |
| (...skipping 19 matching lines...) Expand all Loading... |
| 118 ChildProcess* current_process = ChildProcess::current(); | 142 ChildProcess* current_process = ChildProcess::current(); |
| 119 if (!current_process) | 143 if (!current_process) |
| 120 return; | 144 return; |
| 121 ChildThread* main_child_thread = current_process->main_thread(); | 145 ChildThread* main_child_thread = current_process->main_thread(); |
| 122 if (main_child_thread && main_child_thread->message_loop()) | 146 if (main_child_thread && main_child_thread->message_loop()) |
| 123 main_child_thread->message_loop()->PostTask(FROM_HERE, | 147 main_child_thread->message_loop()->PostTask(FROM_HERE, |
| 124 base::Bind(&QuitSandboxMainThreadMessageLoop)); | 148 base::Bind(&QuitSandboxMainThreadMessageLoop)); |
| 125 } | 149 } |
| 126 | 150 |
| 127 } // namespace content | 151 } // namespace content |
| OLD | NEW |