Roll src/third_party/skia 99c7c07:4af6580
[chromium-blink-merge.git] / components / nacl / common / nacl_types.h
blob6107dcaed3450035da7f031d7612bc3721f0d398
1 // Copyright 2013 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.
5 #ifndef COMPONENTS_NACL_COMMON_NACL_TYPES_H_
6 #define COMPONENTS_NACL_COMMON_NACL_TYPES_H_
8 #include <string>
9 #include <utility>
10 #include <vector>
12 #include "base/basictypes.h"
13 #include "base/memory/shared_memory.h"
14 #include "base/process/process_handle.h"
15 #include "build/build_config.h"
16 #include "ipc/ipc_channel.h"
17 #include "ipc/ipc_platform_file.h"
19 #if defined(OS_POSIX)
20 #include "base/file_descriptor_posix.h"
21 #endif
23 #if defined(OS_WIN)
24 #include <windows.h> // for HANDLE
25 #endif
27 // TODO(gregoryd): add a Windows definition for base::FileDescriptor
28 namespace nacl {
30 #if defined(OS_WIN)
31 typedef HANDLE FileDescriptor;
32 inline HANDLE ToNativeHandle(const FileDescriptor& desc) {
33 return desc;
35 #elif defined(OS_POSIX)
36 typedef base::FileDescriptor FileDescriptor;
37 inline int ToNativeHandle(const FileDescriptor& desc) {
38 return desc.fd;
40 #endif
42 // We allocate a page of shared memory for sharing crash information from
43 // trusted code in the NaCl process to the renderer.
44 static const int kNaClCrashInfoShmemSize = 4096;
45 static const int kNaClCrashInfoMaxLogSize = 1024;
47 // Types of untrusted NaCl processes.
48 enum NaClAppProcessType {
49 kUnknownNaClProcessType,
50 // Runs user-provided *native* code. Enabled for Chrome Web Store apps.
51 kNativeNaClProcessType,
52 // Runs user-provided code that is translated from *bitcode* by an
53 // in-browser PNaCl translator.
54 kPNaClProcessType,
55 // Runs pnacl-llc/linker *native* code. These nexes are browser-provided
56 // (not user-provided).
57 kPNaClTranslatorProcessType,
58 kNumNaClProcessTypes
61 // Represents a request to prefetch a file that's listed in the "files" section
62 // of a NaCl manifest file.
63 struct NaClResourcePrefetchRequest {
64 NaClResourcePrefetchRequest();
65 NaClResourcePrefetchRequest(const std::string& file_key,
66 const std::string& resource_url);
67 ~NaClResourcePrefetchRequest();
69 std::string file_key; // a key for open_resource.
70 std::string resource_url;
73 // Represents a single prefetched file that's listed in the "files" section of
74 // a NaCl manifest file.
75 struct NaClResourcePrefetchResult {
76 NaClResourcePrefetchResult();
77 NaClResourcePrefetchResult(IPC::PlatformFileForTransit file,
78 const base::FilePath& file_path,
79 const std::string& file_key);
80 ~NaClResourcePrefetchResult();
82 IPC::PlatformFileForTransit file;
83 base::FilePath file_path_metadata; // a key for validation caching
84 std::string file_key; // a key for open_resource
87 // Parameters sent to the NaCl process when we start it.
88 struct NaClStartParams {
89 NaClStartParams();
90 ~NaClStartParams();
92 IPC::PlatformFileForTransit nexe_file;
93 // Used only as a key for validation caching.
94 base::FilePath nexe_file_path_metadata;
96 std::vector<NaClResourcePrefetchResult> prefetched_resource_files;
97 IPC::PlatformFileForTransit imc_bootstrap_handle;
98 IPC::PlatformFileForTransit irt_handle;
99 #if defined(OS_MACOSX)
100 IPC::PlatformFileForTransit mac_shm_fd;
101 #endif
102 #if defined(OS_POSIX)
103 IPC::PlatformFileForTransit debug_stub_server_bound_socket;
104 #endif
106 bool validation_cache_enabled;
107 std::string validation_cache_key;
108 // Chrome version string. Sending the version string over IPC avoids linkage
109 // issues in cases where NaCl is not compiled into the main Chromium
110 // executable or DLL.
111 std::string version;
113 bool enable_debug_stub;
114 bool enable_ipc_proxy;
116 NaClAppProcessType process_type;
118 // For NaCl <-> renderer crash information reporting.
119 base::SharedMemoryHandle crash_info_shmem_handle;
121 // NOTE: Any new fields added here must also be added to the IPC
122 // serialization in nacl_messages.h and (for POD fields) the constructor
123 // in nacl_types.cc.
126 // Parameters sent to the browser process to have it launch a NaCl process.
128 // If you change this, you will also need to update the IPC serialization in
129 // nacl_host_messages.h.
130 struct NaClLaunchParams {
131 NaClLaunchParams();
132 NaClLaunchParams(
133 const std::string& manifest_url,
134 const IPC::PlatformFileForTransit& nexe_file,
135 uint64_t nexe_token_lo,
136 uint64_t nexe_token_hi,
137 const std::vector<
138 NaClResourcePrefetchRequest>& resource_prefetch_request_list,
139 int render_view_id,
140 uint32 permission_bits,
141 bool uses_nonsfi_mode,
142 NaClAppProcessType process_type);
143 ~NaClLaunchParams();
145 std::string manifest_url;
146 // On Windows, the HANDLE passed here is valid in the renderer's context.
147 // It's the responsibility of the browser to duplicate this handle properly
148 // for passing it to the plugin.
149 IPC::PlatformFileForTransit nexe_file;
150 uint64_t nexe_token_lo;
151 uint64_t nexe_token_hi;
152 std::vector<NaClResourcePrefetchRequest> resource_prefetch_request_list;
154 int render_view_id;
155 uint32 permission_bits;
156 bool uses_nonsfi_mode;
158 NaClAppProcessType process_type;
161 struct NaClLaunchResult {
162 NaClLaunchResult();
163 NaClLaunchResult(
164 FileDescriptor imc_channel_handle,
165 const IPC::ChannelHandle& ppapi_ipc_channel_handle,
166 const IPC::ChannelHandle& trusted_ipc_channel_handle,
167 const IPC::ChannelHandle& manifest_service_ipc_channel_handle,
168 base::ProcessId plugin_pid,
169 int plugin_child_id,
170 base::SharedMemoryHandle crash_info_shmem_handle);
171 ~NaClLaunchResult();
173 // For plugin loader <-> renderer IMC communication.
174 FileDescriptor imc_channel_handle;
176 // For plugin <-> renderer PPAPI communication.
177 IPC::ChannelHandle ppapi_ipc_channel_handle;
179 // For plugin loader <-> renderer control communication (loading and
180 // starting nexe).
181 IPC::ChannelHandle trusted_ipc_channel_handle;
183 // For plugin <-> renderer ManifestService communication.
184 IPC::ChannelHandle manifest_service_ipc_channel_handle;
186 base::ProcessId plugin_pid;
187 int plugin_child_id;
189 // For NaCl <-> renderer crash information reporting.
190 base::SharedMemoryHandle crash_info_shmem_handle;
193 } // namespace nacl
195 #endif // COMPONENTS_NACL_COMMON_NACL_TYPES_H_