Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(85)

Side by Side Diff: chrome/renderer/pepper/ppb_nacl_private_impl.cc

Issue 10173029: Add a PPB_Flash_Print interface and implement in Chrome. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Created 8 years, 8 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
OLDNEW
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/pepper/ppb_nacl_private_impl.h"
6
7 #ifndef DISABLE_NACL
6 8
7 #include "base/command_line.h" 9 #include "base/command_line.h"
8 #include "base/lazy_instance.h" 10 #include "base/lazy_instance.h"
9 #include "base/logging.h" 11 #include "base/logging.h"
10 #include "base/rand_util_c.h" 12 #include "base/rand_util_c.h"
11 #include "base/utf_string_conversions.h"
12 #include "chrome/common/render_messages.h" 13 #include "chrome/common/render_messages.h"
13 #include "chrome/renderer/chrome_ppb_pdf_impl.h"
14 #include "content/public/common/content_switches.h" 14 #include "content/public/common/content_switches.h"
15 #include "content/public/renderer/render_thread.h" 15 #include "content/public/renderer/render_thread.h"
16 #include "ipc/ipc_sync_message_filter.h" 16 #include "ipc/ipc_sync_message_filter.h"
17 #include "native_client/src/shared/imc/nacl_imc.h"
17 #include "ppapi/c/private/ppb_nacl_private.h" 18 #include "ppapi/c/private/ppb_nacl_private.h"
18 #include "ppapi/c/private/ppb_pdf.h" 19 #include "ppapi/native_client/src/trusted/plugin/nacl_entry_points.h"
19 #include "webkit/plugins/ppapi/ppapi_interface_factory.h"
20 20
21 #if !defined(DISABLE_NACL) 21 namespace {
22 #include "native_client/src/shared/imc/nacl_imc.h"
23 #include "ppapi/native_client/src/trusted/plugin/nacl_entry_points.h"
24 #endif
25 22
26 #if defined(OS_WIN)
27 #include "content/public/common/sandbox_init.h"
28 #endif
29
30 using content::RenderThread;
31
32 namespace chrome {
33
34 #if !defined(DISABLE_NACL)
35 namespace {
36 base::LazyInstance<scoped_refptr<IPC::SyncMessageFilter> > 23 base::LazyInstance<scoped_refptr<IPC::SyncMessageFilter> >
37 g_background_thread_sender = LAZY_INSTANCE_INITIALIZER; 24 g_background_thread_sender = LAZY_INSTANCE_INITIALIZER;
38 } // namespace
39 25
40 // Launch NaCl's sel_ldr process. 26 // Launch NaCl's sel_ldr process.
41 bool LaunchSelLdr(const char* alleged_url, int socket_count, 27 bool LaunchSelLdr(const char* alleged_url, int socket_count,
42 void* imc_handles, void* nacl_process_handle, 28 void* imc_handles, void* nacl_process_handle,
43 int* nacl_process_id) { 29 int* nacl_process_id) {
44 std::vector<nacl::FileDescriptor> sockets; 30 std::vector<nacl::FileDescriptor> sockets;
45 IPC::Message::Sender* sender = RenderThread::Get(); 31 IPC::Message::Sender* sender = content::RenderThread::Get();
46 if (sender == NULL) { 32 if (sender == NULL)
47 sender = g_background_thread_sender.Pointer()->get(); 33 sender = g_background_thread_sender.Pointer()->get();
48 } 34
49 if (!sender->Send( 35 if (!sender->Send(new ChromeViewHostMsg_LaunchNaCl(
50 new ChromeViewHostMsg_LaunchNaCl( 36 GURL(alleged_url), socket_count, &sockets)))
51 GURL(alleged_url), socket_count, &sockets))) {
52 return false; 37 return false;
53 } 38
54 CHECK(static_cast<int>(sockets.size()) == socket_count); 39 CHECK(static_cast<int>(sockets.size()) == socket_count);
55 for (int i = 0; i < socket_count; i++) { 40 for (int i = 0; i < socket_count; i++) {
56 static_cast<nacl::Handle*>(imc_handles)[i] = 41 static_cast<nacl::Handle*>(imc_handles)[i] =
57 nacl::ToNativeHandle(sockets[i]); 42 nacl::ToNativeHandle(sockets[i]);
58 } 43 }
59 // TODO(mseaborn): Remove the arguments nacl_process_handle and 44 // TODO(mseaborn): Remove the arguments nacl_process_handle and
60 // nacl_process_id from the interface. 45 // nacl_process_id from the interface.
61 *reinterpret_cast<base::ProcessHandle*>(nacl_process_handle) = 46 *reinterpret_cast<base::ProcessHandle*>(nacl_process_handle) =
62 (base::ProcessHandle) -1; 47 (base::ProcessHandle) -1;
63 *nacl_process_id = 0; 48 *nacl_process_id = 0;
64 return true; 49 return true;
65 } 50 }
66 51
67 int UrandomFD(void) { 52 int UrandomFD(void) {
68 #if defined(OS_POSIX) 53 #if defined(OS_POSIX)
69 return GetUrandomFD(); 54 return GetUrandomFD();
70 #else 55 #else
71 return 0; 56 return 0;
72 #endif 57 #endif
73 } 58 }
74 59
75 bool Are3DInterfacesDisabled() { 60 bool Are3DInterfacesDisabled() {
76 return CommandLine::ForCurrentProcess()->HasSwitch(switches::kDisable3DAPIs); 61 return CommandLine::ForCurrentProcess()->HasSwitch(switches::kDisable3DAPIs);
77 } 62 }
78 63
79 void EnableBackgroundSelLdrLaunch() { 64 void EnableBackgroundSelLdrLaunch() {
80 g_background_thread_sender.Get() = 65 g_background_thread_sender.Get() =
81 RenderThread::Get()->GetSyncMessageFilter(); 66 content::RenderThread::Get()->GetSyncMessageFilter();
82 } 67 }
83 68
84 int BrokerDuplicateHandle(void* source_handle, 69 int BrokerDuplicateHandle(void* source_handle,
85 unsigned int process_id, 70 unsigned int process_id,
86 void** target_handle, 71 void** target_handle,
87 unsigned int desired_access, 72 unsigned int desired_access,
88 unsigned int options) { 73 unsigned int options) {
89 #if defined(OS_WIN) 74 #if defined(OS_WIN)
90 return content::BrokerDuplicateHandle(source_handle, process_id, 75 return content::BrokerDuplicateHandle(source_handle, process_id,
91 target_handle, desired_access, 76 target_handle, desired_access,
92 options); 77 options);
93 #else 78 #else
94 return 0; 79 return 0;
95 #endif 80 #endif
96 } 81 }
97 82
98 const PPB_NaCl_Private ppb_nacl = { 83 const PPB_NaCl_Private nacl_interface = {
99 &LaunchSelLdr, 84 &LaunchSelLdr,
100 &UrandomFD, 85 &UrandomFD,
101 &Are3DInterfacesDisabled, 86 &Are3DInterfacesDisabled,
102 &EnableBackgroundSelLdrLaunch, 87 &EnableBackgroundSelLdrLaunch,
103 &BrokerDuplicateHandle, 88 &BrokerDuplicateHandle,
104 }; 89 };
105 90
106 class PPB_NaCl_Impl { 91 } // namespace
107 public:
108 // Returns a pointer to the interface implementing PPB_NaCl_Private that is
109 // exposed to the plugin.
110 static const PPB_NaCl_Private* GetInterface() {
111 return &ppb_nacl;
112 }
113 };
114 #endif // DISABLE_NACL
115 92
116 const void* ChromePPAPIInterfaceFactory(const std::string& interface_name) { 93 const PPB_NaCl_Private* PPB_NaCl_Private_Impl::GetInterface() {
117 #if !defined(DISABLE_NACL) 94 return &nacl_interface;
118 if (interface_name == PPB_NACL_PRIVATE_INTERFACE)
119 return chrome::PPB_NaCl_Impl::GetInterface();
120 #endif // DISABLE_NACL
121 if (interface_name == PPB_PDF_INTERFACE)
122 return chrome::PPB_PDF_Impl::GetInterface();
123 return NULL;
124 } 95 }
125 96
126 } // namespace chrome 97 #endif // DISABLE_NACL
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698