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 "chrome/renderer/chrome_ppapi_interfaces.h" | 5 #include "chrome/renderer/chrome_ppapi_interfaces.h" |
6 | 6 |
7 #include "base/command_line.h" | 7 #include "base/command_line.h" |
8 #include "base/lazy_instance.h" | 8 #include "base/lazy_instance.h" |
9 #include "base/logging.h" | 9 #include "base/logging.h" |
10 #include "base/rand_util_c.h" | 10 #include "base/rand_util_c.h" |
(...skipping 51 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
62 } | 62 } |
63 | 63 |
64 int UrandomFD(void) { | 64 int UrandomFD(void) { |
65 #if defined(OS_POSIX) | 65 #if defined(OS_POSIX) |
66 return GetUrandomFD(); | 66 return GetUrandomFD(); |
67 #else | 67 #else |
68 return 0; | 68 return 0; |
69 #endif | 69 #endif |
70 } | 70 } |
71 | 71 |
| 72 int GetReadonlyPnaclFD(const char* filename) { |
| 73 nacl::FileDescriptor out_fd; |
| 74 if (!RenderThread::Get()->Send( |
| 75 new ChromeViewHostMsg_GetReadonlyPnaclFD( |
| 76 std::string(filename), |
| 77 &out_fd))) { |
| 78 return -1; |
| 79 } |
| 80 |
| 81 // TODO(jvoung): Should nacl::FileDescriptor handle this? |
| 82 // Should we leave the HANDLE as a HANDLE for now? |
| 83 #if defined(OS_WIN) |
| 84 HANDLE handle = nacl::ToNativeHandle(out_fd); |
| 85 int posix_desc = _open_osfhandle(handle, _O_RDONLY | _O_BINARY); |
| 86 if (posix_desc == -1) { |
| 87 // Close the Windows HANDLE if it can't be converted. |
| 88 CloseHandle(handle); |
| 89 return -1; |
| 90 } |
| 91 return posix_desc; |
| 92 #elif defined(OS_POSIX) |
| 93 return nacl::ToNativeHandle(out_fd); |
| 94 #else |
| 95 #error "GetReadonlyPnaclFD: Don't know how to convert FileDescriptor to native." |
| 96 #endif |
| 97 } |
| 98 |
72 bool Are3DInterfacesDisabled() { | 99 bool Are3DInterfacesDisabled() { |
73 return CommandLine::ForCurrentProcess()->HasSwitch(switches::kDisable3DAPIs); | 100 return CommandLine::ForCurrentProcess()->HasSwitch(switches::kDisable3DAPIs); |
74 } | 101 } |
75 | 102 |
76 void EnableBackgroundSelLdrLaunch() { | 103 void EnableBackgroundSelLdrLaunch() { |
77 g_background_thread_sender.Get() = | 104 g_background_thread_sender.Get() = |
78 RenderThread::Get()->GetSyncMessageFilter(); | 105 RenderThread::Get()->GetSyncMessageFilter(); |
79 } | 106 } |
80 | 107 |
81 const PPB_NaCl_Private ppb_nacl = { | 108 const PPB_NaCl_Private ppb_nacl = { |
82 &LaunchSelLdr, | 109 &LaunchSelLdr, |
83 &UrandomFD, | 110 &UrandomFD, |
84 &Are3DInterfacesDisabled, | 111 &Are3DInterfacesDisabled, |
85 &EnableBackgroundSelLdrLaunch, | 112 &EnableBackgroundSelLdrLaunch, |
| 113 &GetReadonlyPnaclFD |
86 }; | 114 }; |
87 | 115 |
88 class PPB_NaCl_Impl { | 116 class PPB_NaCl_Impl { |
89 public: | 117 public: |
90 // Returns a pointer to the interface implementing PPB_NaCl_Private that is | 118 // Returns a pointer to the interface implementing PPB_NaCl_Private that is |
91 // exposed to the plugin. | 119 // exposed to the plugin. |
92 static const PPB_NaCl_Private* GetInterface() { | 120 static const PPB_NaCl_Private* GetInterface() { |
93 return &ppb_nacl; | 121 return &ppb_nacl; |
94 } | 122 } |
95 }; | 123 }; |
96 #endif // DISABLE_NACL | 124 #endif // DISABLE_NACL |
97 | 125 |
98 const void* ChromePPAPIInterfaceFactory(const std::string& interface_name) { | 126 const void* ChromePPAPIInterfaceFactory(const std::string& interface_name) { |
99 #if !defined(DISABLE_NACL) | 127 #if !defined(DISABLE_NACL) |
100 if (interface_name == PPB_NACL_PRIVATE_INTERFACE) | 128 if (interface_name == PPB_NACL_PRIVATE_INTERFACE) |
101 return chrome::PPB_NaCl_Impl::GetInterface(); | 129 return chrome::PPB_NaCl_Impl::GetInterface(); |
102 #endif // DISABLE_NACL | 130 #endif // DISABLE_NACL |
103 if (interface_name == PPB_PDF_INTERFACE) | 131 if (interface_name == PPB_PDF_INTERFACE) |
104 return chrome::PPB_PDF_Impl::GetInterface(); | 132 return chrome::PPB_PDF_Impl::GetInterface(); |
105 return NULL; | 133 return NULL; |
106 } | 134 } |
107 | 135 |
108 } // namespace chrome | 136 } // namespace chrome |
OLD | NEW |