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
3// found in the LICENSE file.
4
5#include "native_client/src/shared/platform/nacl_check.h"
6
7#include "ppapi/c/dev/ppb_font_dev.h"
8#include "ppapi/c/dev/ppb_memory_dev.h"
9#include "ppapi/c/dev/ppb_var_deprecated.h"
10#include "ppapi/c/ppb_audio.h"
11#include "ppapi/c/ppb_audio_config.h"
12#include "ppapi/c/ppb_core.h"
13#include "ppapi/c/ppb_file_io.h"
14#include "ppapi/c/ppb_file_ref.h"
15#include "ppapi/c/ppb_file_system.h"
16#include "ppapi/c/ppb_fullscreen.h"
17#include "ppapi/c/ppb_graphics_2d.h"
18#include "ppapi/c/ppb_graphics_3d.h"
19#include "ppapi/c/ppb_image_data.h"
20#include "ppapi/c/ppb_input_event.h"
21#include "ppapi/c/ppb_instance.h"
22#include "ppapi/c/ppb_messaging.h"
23#include "ppapi/c/ppb_mouse_cursor.h"
24#include "ppapi/c/ppb_opengles2.h"
25#include "ppapi/c/ppb_url_loader.h"
26#include "ppapi/c/ppb_url_request_info.h"
27#include "ppapi/c/ppb_url_response_info.h"
28#include "ppapi/c/ppb_var.h"
29#include "ppapi/c/ppb_view.h"
30#include "ppapi/c/private/ppb_testing_private.h"
31
32#include "ppapi/native_client/tests/ppapi_test_lib/get_browser_interface.h"
33#include "ppapi/native_client/tests/ppapi_test_lib/internal_utils.h"
34
35// Use for dev interfaces that might not be present.
36const void* GetBrowserInterface(const char* interface_name) {
37  return (*ppb_get_interface())(interface_name);
38}
39
40// Use for stable interfaces that must always be present.
41const void* GetBrowserInterfaceSafe(const char* interface_name) {
42  const void* ppb_interface = (*ppb_get_interface())(interface_name);
43  CHECK(ppb_interface != NULL);
44  return ppb_interface;
45}
46
47// Stable interfaces.
48
49const PPB_Audio* PPBAudio() {
50  return reinterpret_cast<const PPB_Audio*>(
51      GetBrowserInterfaceSafe(PPB_AUDIO_INTERFACE));
52}
53
54const PPB_AudioConfig* PPBAudioConfig() {
55  return reinterpret_cast<const PPB_AudioConfig*>(
56      GetBrowserInterfaceSafe(PPB_AUDIO_CONFIG_INTERFACE));
57}
58
59const PPB_Core* PPBCore() {
60  return reinterpret_cast<const PPB_Core*>(
61      GetBrowserInterfaceSafe(PPB_CORE_INTERFACE));
62}
63
64const PPB_FileIO* PPBFileIO() {
65  return reinterpret_cast<const PPB_FileIO*>(
66      GetBrowserInterfaceSafe(PPB_FILEIO_INTERFACE));
67}
68
69const PPB_FileRef* PPBFileRef() {
70  return reinterpret_cast<const PPB_FileRef*>(
71      GetBrowserInterfaceSafe(PPB_FILEREF_INTERFACE));
72}
73
74const PPB_FileSystem* PPBFileSystem() {
75  return reinterpret_cast<const PPB_FileSystem*>(
76      GetBrowserInterfaceSafe(PPB_FILESYSTEM_INTERFACE));
77}
78
79const PPB_Fullscreen* PPBFullscreen() {
80  return reinterpret_cast<const PPB_Fullscreen*>(
81      GetBrowserInterfaceSafe(PPB_FULLSCREEN_INTERFACE));
82}
83
84const PPB_Graphics2D* PPBGraphics2D() {
85  return reinterpret_cast<const PPB_Graphics2D*>(
86      GetBrowserInterfaceSafe(PPB_GRAPHICS_2D_INTERFACE));
87}
88
89const PPB_Graphics3D* PPBGraphics3D() {
90  return reinterpret_cast<const PPB_Graphics3D*>(
91      GetBrowserInterfaceSafe(PPB_GRAPHICS_3D_INTERFACE));
92}
93
94const PPB_ImageData* PPBImageData() {
95  return reinterpret_cast<const PPB_ImageData*>(
96      GetBrowserInterfaceSafe(PPB_IMAGEDATA_INTERFACE));
97}
98
99const PPB_InputEvent* PPBInputEvent() {
100  return reinterpret_cast<const PPB_InputEvent*>(
101      GetBrowserInterfaceSafe(PPB_INPUT_EVENT_INTERFACE));
102}
103
104const PPB_Instance* PPBInstance() {
105  return reinterpret_cast<const PPB_Instance*>(
106      GetBrowserInterfaceSafe(PPB_INSTANCE_INTERFACE));
107}
108
109const PPB_KeyboardInputEvent* PPBKeyboardInputEvent() {
110  return reinterpret_cast<const PPB_KeyboardInputEvent*>(
111      GetBrowserInterfaceSafe(PPB_KEYBOARD_INPUT_EVENT_INTERFACE));
112}
113
114const PPB_Messaging* PPBMessaging() {
115  return reinterpret_cast<const PPB_Messaging*>(
116      GetBrowserInterfaceSafe(PPB_MESSAGING_INTERFACE));
117}
118
119const PPB_MouseCursor_1_0* PPBMouseCursor() {
120  return reinterpret_cast<const PPB_MouseCursor_1_0*>(
121      GetBrowserInterfaceSafe(PPB_MOUSECURSOR_INTERFACE_1_0));
122}
123
124const PPB_MouseInputEvent* PPBMouseInputEvent() {
125  return reinterpret_cast<const PPB_MouseInputEvent*>(
126      GetBrowserInterfaceSafe(PPB_MOUSE_INPUT_EVENT_INTERFACE));
127}
128
129const PPB_OpenGLES2* PPBOpenGLES2() {
130  return reinterpret_cast<const PPB_OpenGLES2*>(
131      GetBrowserInterfaceSafe(PPB_OPENGLES2_INTERFACE));
132}
133
134const PPB_URLLoader* PPBURLLoader() {
135  return reinterpret_cast<const PPB_URLLoader*>(
136      GetBrowserInterfaceSafe(PPB_URLLOADER_INTERFACE));
137}
138
139const PPB_URLRequestInfo* PPBURLRequestInfo() {
140  return reinterpret_cast<const PPB_URLRequestInfo*>(
141      GetBrowserInterfaceSafe(PPB_URLREQUESTINFO_INTERFACE));
142}
143
144const PPB_URLResponseInfo* PPBURLResponseInfo() {
145  return reinterpret_cast<const PPB_URLResponseInfo*>(
146      GetBrowserInterfaceSafe(PPB_URLRESPONSEINFO_INTERFACE));
147}
148
149const PPB_Var* PPBVar() {
150  return reinterpret_cast<const PPB_Var*>(
151      GetBrowserInterfaceSafe(PPB_VAR_INTERFACE));
152}
153
154const PPB_WheelInputEvent* PPBWheelInputEvent() {
155  return reinterpret_cast<const PPB_WheelInputEvent*>(
156      GetBrowserInterfaceSafe(PPB_WHEEL_INPUT_EVENT_INTERFACE));
157}
158
159
160// Dev interfaces.
161
162const PPB_Font_Dev* PPBFontDev() {
163  return reinterpret_cast<const PPB_Font_Dev*>(
164      // Change to GetBrowserInterfaceSafe when moving out of dev.
165      GetBrowserInterface(PPB_FONT_DEV_INTERFACE));
166}
167
168const PPB_Memory_Dev* PPBMemoryDev() {
169  return reinterpret_cast<const PPB_Memory_Dev*>(
170      // Change to GetBrowserInterfaceSafe when moving out of dev.
171      GetBrowserInterface(PPB_MEMORY_DEV_INTERFACE));
172}
173
174const PPB_Testing_Private* PPBTestingPrivate() {
175  return reinterpret_cast<const PPB_Testing_Private*>(
176      GetBrowserInterface(PPB_TESTING_PRIVATE_INTERFACE));
177}
178
179const PPB_View* PPBView() {
180  return reinterpret_cast<const PPB_View*>(
181      GetBrowserInterface(PPB_VIEW_INTERFACE));
182}
183