OLD | NEW |
(Empty) | |
| 1 // Copyright (c) 2011 The Native Client 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 #ifndef TESTS_PPAPI_GETURL_MODULE_H_ |
| 5 #define TESTS_PPAPI_GETURL_MODULE_H_ |
| 6 |
| 7 #include <string> |
| 8 |
| 9 #include "ppapi/c/pp_module.h" |
| 10 #include "ppapi/c/pp_resource.h" |
| 11 #include "ppapi/c/ppb.h" |
| 12 #include "ppapi/c/ppb_core.h" |
| 13 #include "ppapi/c/ppb_messaging.h" |
| 14 #include "ppapi/c/ppb_var.h" |
| 15 #include "ppapi/c/ppp.h" |
| 16 |
| 17 // ppapi_geturl example is deliberately using C PPAPI interface. |
| 18 // C++ PPAPI layer has pp::Module wrapper class. |
| 19 class Module { |
| 20 public: |
| 21 static Module* Create(PP_Module module_id, |
| 22 PPB_GetInterface get_browser_interface); |
| 23 static Module* Get(); |
| 24 static void Free(); |
| 25 |
| 26 const void* GetPluginInterface(const char* interface_name); |
| 27 const void* GetBrowserInterface(const char* interface_name); |
| 28 PP_Module module_id() { return module_id_; } |
| 29 const PPB_Core* ppb_core_interface() const { return ppb_core_interface_; } |
| 30 const PPB_Messaging* ppb_messaging_interface() const { |
| 31 return ppb_messaging_interface_; |
| 32 } |
| 33 const PPB_Var* ppb_var_interface() const { return ppb_var_interface_; } |
| 34 |
| 35 static char* VarToCStr(const PP_Var& var); |
| 36 static std::string VarToStr(const PP_Var& var); |
| 37 static PP_Var StrToVar(const char* str); |
| 38 static PP_Var StrToVar(const std::string& str); |
| 39 static std::string ErrorCodeToStr(int32_t error_code); |
| 40 |
| 41 // Constructs a parameterized message string then uses messaging.PostMessage |
| 42 // to send this message back to the browser. The receiving message handler |
| 43 // is defined in ppapi_geturl.html |
| 44 void ReportResult(PP_Instance pp_instance, |
| 45 const char* url, |
| 46 bool as_file, |
| 47 const char* text, |
| 48 bool success); |
| 49 private: |
| 50 PP_Module module_id_; |
| 51 PPB_GetInterface get_browser_interface_; |
| 52 const PPB_Core* ppb_core_interface_; |
| 53 const PPB_Messaging* ppb_messaging_interface_; |
| 54 const PPB_Var* ppb_var_interface_; |
| 55 |
| 56 Module(PP_Module module_id, PPB_GetInterface get_browser_interface); |
| 57 ~Module() { } |
| 58 Module(const Module&); |
| 59 void operator=(const Module&); |
| 60 }; |
| 61 |
| 62 #endif // TESTS_PPAPI_GETURL_MODULE_H_ |
OLD | NEW |