| OLD | NEW |
| 1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. | 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 | 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 "native_client/src/shared/ppapi_proxy/browser_globals.h" | 5 #include "native_client/src/shared/ppapi_proxy/browser_globals.h" |
| 6 | 6 |
| 7 #include <stddef.h> | 7 #include <stddef.h> |
| 8 #include <stdio.h> | 8 #include <stdio.h> |
| 9 #include <stdlib.h> | 9 #include <stdlib.h> |
| 10 #include <string.h> | 10 #include <string.h> |
| (...skipping 38 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 49 // is requesting PPAPI Dev interfaces to be available. | 49 // is requesting PPAPI Dev interfaces to be available. |
| 50 // Set by SetPPBGetInterface(). | 50 // Set by SetPPBGetInterface(). |
| 51 PPB_GetInterface get_interface = NULL; | 51 PPB_GetInterface get_interface = NULL; |
| 52 bool enable_dev_interfaces = false; | 52 bool enable_dev_interfaces = false; |
| 53 | 53 |
| 54 // Whether Pepper 3D interfaces should be enabled. | 54 // Whether Pepper 3D interfaces should be enabled. |
| 55 bool enable_3d_interfaces = true; | 55 bool enable_3d_interfaces = true; |
| 56 | 56 |
| 57 } // namespace | 57 } // namespace |
| 58 | 58 |
| 59 // By default, disable developer (Dev) interfaces. To enable developer | |
| 60 // interfaces, set the environment variable NACL_ENABLE_PPAPI_DEV to 1. | |
| 61 // Also, the plugin can request whether or not to enable dev interfaces. | |
| 62 bool AreDevInterfacesEnabled() { | |
| 63 static bool first = true; | |
| 64 static bool env_dev_enabled = false; | |
| 65 if (first) { | |
| 66 const char *nacl_enable_ppapi_dev = getenv("NACL_ENABLE_PPAPI_DEV"); | |
| 67 if (NULL != nacl_enable_ppapi_dev) { | |
| 68 int v = strtol(nacl_enable_ppapi_dev, (char **) 0, 0); | |
| 69 if (v != 0) { | |
| 70 env_dev_enabled = true; | |
| 71 } | |
| 72 } | |
| 73 first = false; | |
| 74 } | |
| 75 return env_dev_enabled || enable_dev_interfaces; | |
| 76 } | |
| 77 | |
| 78 | |
| 79 void SetBrowserPppForInstance(PP_Instance instance, BrowserPpp* browser_ppp) { | 59 void SetBrowserPppForInstance(PP_Instance instance, BrowserPpp* browser_ppp) { |
| 80 // If there was no map, create one. | 60 // If there was no map, create one. |
| 81 if (instance_to_ppp_map == NULL) { | 61 if (instance_to_ppp_map == NULL) { |
| 82 instance_to_ppp_map = new std::map<PP_Instance, BrowserPpp*>; | 62 instance_to_ppp_map = new std::map<PP_Instance, BrowserPpp*>; |
| 83 } | 63 } |
| 84 // Add the instance to the map. | 64 // Add the instance to the map. |
| 85 (*instance_to_ppp_map)[instance] = browser_ppp; | 65 (*instance_to_ppp_map)[instance] = browser_ppp; |
| 86 } | 66 } |
| 87 | 67 |
| 88 void UnsetBrowserPppForInstance(PP_Instance instance) { | 68 void UnsetBrowserPppForInstance(PP_Instance instance) { |
| (...skipping 106 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 195 enable_3d_interfaces = allow_3d_interfaces; | 175 enable_3d_interfaces = allow_3d_interfaces; |
| 196 } | 176 } |
| 197 | 177 |
| 198 const void* GetBrowserInterface(const char* interface_name) { | 178 const void* GetBrowserInterface(const char* interface_name) { |
| 199 // Reject suspiciously long interface strings. | 179 // Reject suspiciously long interface strings. |
| 200 const size_t kMaxLength = 1024; | 180 const size_t kMaxLength = 1024; |
| 201 if (NULL == memchr(interface_name, '\0', kMaxLength)) { | 181 if (NULL == memchr(interface_name, '\0', kMaxLength)) { |
| 202 return NULL; | 182 return NULL; |
| 203 } | 183 } |
| 204 // If dev interface is not enabled, reject interfaces containing "(Dev)" | 184 // If dev interface is not enabled, reject interfaces containing "(Dev)" |
| 205 if (!AreDevInterfacesEnabled() && strstr(interface_name, "(Dev)") != NULL) { | 185 if (!enable_dev_interfaces && strstr(interface_name, "(Dev)") != NULL) { |
| 206 return NULL; | 186 return NULL; |
| 207 } | 187 } |
| 208 if (!enable_3d_interfaces) { | 188 if (!enable_3d_interfaces) { |
| 209 static const char* disabled_interface_names[] = { | 189 static const char* disabled_interface_names[] = { |
| 210 PPB_GRAPHICS_3D_INTERFACE, | 190 PPB_GRAPHICS_3D_INTERFACE, |
| 211 PPB_GRAPHICS_3D_TRUSTED_INTERFACE, | 191 PPB_GRAPHICS_3D_TRUSTED_INTERFACE, |
| 212 PPB_CONTEXT_3D_DEV_INTERFACE, | 192 PPB_CONTEXT_3D_DEV_INTERFACE, |
| 213 PPB_CONTEXT_3D_TRUSTED_DEV_INTERFACE, | 193 PPB_CONTEXT_3D_TRUSTED_DEV_INTERFACE, |
| 214 PPB_GLES_CHROMIUM_TEXTURE_MAPPING_DEV_INTERFACE, | 194 PPB_GLES_CHROMIUM_TEXTURE_MAPPING_DEV_INTERFACE, |
| 215 PPB_OPENGLES2_INTERFACE, | 195 PPB_OPENGLES2_INTERFACE, |
| (...skipping 214 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 430 | 410 |
| 431 // Private interfaces. | 411 // Private interfaces. |
| 432 const PPB_PDF* PPBPDFInterface() { | 412 const PPB_PDF* PPBPDFInterface() { |
| 433 static const PPB_PDF* ppb = | 413 static const PPB_PDF* ppb = |
| 434 static_cast<const PPB_PDF*>( | 414 static_cast<const PPB_PDF*>( |
| 435 GetBrowserInterfaceSafe(PPB_PDF_INTERFACE)); | 415 GetBrowserInterfaceSafe(PPB_PDF_INTERFACE)); |
| 436 return ppb; | 416 return ppb; |
| 437 } | 417 } |
| 438 | 418 |
| 439 } // namespace ppapi_proxy | 419 } // namespace ppapi_proxy |
| OLD | NEW |