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