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 "ppapi/c/pp_instance.h" 6#include "ppapi/c/pp_module.h" 7 8#include "ppapi/cpp/instance.h" 9#include "ppapi/cpp/module.h" 10 11#include "ppapi_simple/ps.h" 12 13static pp::Instance* s_Instance = NULL; 14 15PP_Instance PSGetInstanceId(void) { 16 if (s_Instance == NULL) 17 return 0; 18 return s_Instance->pp_instance(); 19} 20 21const void* PSGetInterface(const char *name) { 22 pp::Module* module = pp::Module::Get(); 23 if (module == NULL) 24 return NULL; 25 return module->GetBrowserInterface(name); 26} 27 28 29// The Module class. The browser calls the CreateInstance() method to create 30// an instance of your NaCl module on the web page. The browser creates a new 31// instance for each <embed> tag with type="application/x-nacl". 32class PSModule : public pp::Module { 33 public: 34 PSModule() : pp::Module() {} 35 virtual ~PSModule() {} 36 37 virtual pp::Instance* CreateInstance(PP_Instance instance) { 38 s_Instance = static_cast<pp::Instance*>(PSUserCreateInstance(instance)); 39 return s_Instance; 40 } 41}; 42 43namespace pp { 44 45// Factory function called by the browser when the module is first loaded. 46// The browser keeps a singleton of this module. It calls the 47// CreateInstance() method on the object you return to make instances. There 48// is one instance per <embed> tag on the page. This is the main binding 49// point for your NaCl module with the browser. 50Module* CreateModule() { 51 return new PSModule(); 52} 53 54} // namespace pp 55 56