Fixed service side implementation of glTexStorage2DEXT to only initialize the number of
[chromium-blink-merge.git] / chrome / renderer / chrome_ppapi_interfaces.cc
bloba01c1ee52a5cd5b4fe6b6a2171962d9a58fe91f1
1 // Copyright (c) 2011 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 #include "chrome/renderer/chrome_ppapi_interfaces.h"
7 #include "base/command_line.h"
8 #include "base/logging.h"
9 #include "base/rand_util_c.h"
10 #include "base/utf_string_conversions.h"
11 #include "chrome/common/render_messages.h"
12 #include "chrome/renderer/chrome_ppb_pdf_impl.h"
13 #include "content/public/common/content_switches.h"
14 #include "content/public/renderer/render_thread.h"
15 #include "ppapi/c/private/ppb_nacl_private.h"
16 #include "ppapi/c/private/ppb_pdf.h"
17 #include "webkit/plugins/ppapi/ppapi_interface_factory.h"
19 #if !defined(DISABLE_NACL)
20 #include "native_client/src/shared/imc/nacl_imc.h"
21 #include "ppapi/native_client/src/trusted/plugin/nacl_entry_points.h"
22 #endif
24 using content::RenderThread;
26 namespace chrome {
28 #if !defined(DISABLE_NACL)
29 // Launch NaCl's sel_ldr process.
30 bool LaunchSelLdr(const char* alleged_url, int socket_count,
31 void* imc_handles, void* nacl_process_handle,
32 int* nacl_process_id) {
33 std::vector<nacl::FileDescriptor> sockets;
34 base::ProcessHandle nacl_process;
35 if (!RenderThread::Get()->Send(
36 new ChromeViewHostMsg_LaunchNaCl(
37 ASCIIToWide(alleged_url),
38 socket_count,
39 &sockets,
40 &nacl_process,
41 reinterpret_cast<base::ProcessId*>(nacl_process_id)))) {
42 return false;
44 CHECK(static_cast<int>(sockets.size()) == socket_count);
45 for (int i = 0; i < socket_count; i++) {
46 static_cast<nacl::Handle*>(imc_handles)[i] =
47 nacl::ToNativeHandle(sockets[i]);
49 *static_cast<nacl::Handle*>(nacl_process_handle) = nacl_process;
50 return true;
53 int UrandomFD(void) {
54 #if defined(OS_POSIX)
55 return GetUrandomFD();
56 #else
57 return 0;
58 #endif
61 bool Are3DInterfacesDisabled() {
62 return CommandLine::ForCurrentProcess()->HasSwitch(switches::kDisable3DAPIs);
65 const PPB_NaCl_Private ppb_nacl = {
66 &LaunchSelLdr,
67 &UrandomFD,
68 &Are3DInterfacesDisabled,
71 class PPB_NaCl_Impl {
72 public:
73 // Returns a pointer to the interface implementing PPB_NaCl_Private that is
74 // exposed to the plugin.
75 static const PPB_NaCl_Private* GetInterface() {
76 return &ppb_nacl;
79 #endif // DISABLE_NACL
81 const void* ChromePPAPIInterfaceFactory(const std::string& interface_name) {
82 #if !defined(DISABLE_NACL)
83 if (interface_name == PPB_NACL_PRIVATE_INTERFACE)
84 return chrome::PPB_NaCl_Impl::GetInterface();
85 #endif // DISABLE_NACL
86 if (interface_name == PPB_PDF_INTERFACE)
87 return chrome::PPB_PDF_Impl::GetInterface();
88 return NULL;
91 } // namespace chrome