Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(670)

Side by Side Diff: ppapi/cpp/module.cc

Issue 4310002: Make PPAPI headers compile with C compilers (gcc on Linux & Mac and MSVS on W... (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src/
Patch Set: '' Created 10 years, 1 month ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
« no previous file with comments | « ppapi/cpp/module.h ('k') | ppapi/cpp/var.cc » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright (c) 2010 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2010 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 // Note that the single accessor, Module::Get(), is not actually implemented 5 // Note that the single accessor, Module::Get(), is not actually implemented
6 // in this file. This is an intentional hook that allows users of ppapi's 6 // in this file. This is an intentional hook that allows users of ppapi's
7 // C++ wrapper objects to provide difference semantics for how the singleton 7 // C++ wrapper objects to provide difference semantics for how the singleton
8 // object is accessed. 8 // object is accessed.
9 // 9 //
10 // In general, users of ppapi will also link in ppp_entrypoints.cc, which 10 // In general, users of ppapi will also link in ppp_entrypoints.cc, which
(...skipping 10 matching lines...) Expand all
21 // function. Leaving Module::Get() unimplemented provides a hook for 21 // function. Leaving Module::Get() unimplemented provides a hook for
22 // implementing such behavior. 22 // implementing such behavior.
23 23
24 #include "ppapi/cpp/module.h" 24 #include "ppapi/cpp/module.h"
25 25
26 #include <string.h> 26 #include <string.h>
27 27
28 #include "ppapi/c/pp_instance.h" 28 #include "ppapi/c/pp_instance.h"
29 #include "ppapi/c/pp_var.h" 29 #include "ppapi/c/pp_var.h"
30 #include "ppapi/c/ppp_instance.h" 30 #include "ppapi/c/ppp_instance.h"
31 #include "ppapi/cpp/common.h"
31 #include "ppapi/cpp/dev/url_loader_dev.h" 32 #include "ppapi/cpp/dev/url_loader_dev.h"
32 #include "ppapi/cpp/instance.h" 33 #include "ppapi/cpp/instance.h"
33 #include "ppapi/cpp/rect.h" 34 #include "ppapi/cpp/rect.h"
34 #include "ppapi/cpp/resource.h" 35 #include "ppapi/cpp/resource.h"
35 #include "ppapi/cpp/var.h" 36 #include "ppapi/cpp/var.h"
36 37
37 namespace pp { 38 namespace pp {
38 39
39 // PPP_Instance implementation ------------------------------------------------- 40 // PPP_Instance implementation -------------------------------------------------
40 41
41 bool Instance_DidCreate(PP_Instance pp_instance, 42 PP_Bool Instance_DidCreate(PP_Instance pp_instance,
42 uint32_t argc, 43 uint32_t argc,
43 const char* argn[], 44 const char* argn[],
44 const char* argv[]) { 45 const char* argv[]) {
45 Module* module_singleton = Module::Get(); 46 Module* module_singleton = Module::Get();
46 if (!module_singleton) 47 if (!module_singleton)
47 return false; 48 return PP_FALSE;
48 49
49 Instance* instance = module_singleton->CreateInstance(pp_instance); 50 Instance* instance = module_singleton->CreateInstance(pp_instance);
50 if (!instance) 51 if (!instance)
51 return false; 52 return PP_FALSE;
52 module_singleton->current_instances_[pp_instance] = instance; 53 module_singleton->current_instances_[pp_instance] = instance;
53 return instance->Init(argc, argn, argv); 54 return BoolToPPBool(instance->Init(argc, argn, argv));
54 } 55 }
55 56
56 void Instance_DidDestroy(PP_Instance instance) { 57 void Instance_DidDestroy(PP_Instance instance) {
57 Module* module_singleton = Module::Get(); 58 Module* module_singleton = Module::Get();
58 if (!module_singleton) 59 if (!module_singleton)
59 return; 60 return;
60 Module::InstanceMap::iterator found = 61 Module::InstanceMap::iterator found =
61 module_singleton->current_instances_.find(instance); 62 module_singleton->current_instances_.find(instance);
62 if (found == module_singleton->current_instances_.end()) 63 if (found == module_singleton->current_instances_.end())
63 return; 64 return;
64 65
65 // Remove it from the map before deleting to try to catch reentrancy. 66 // Remove it from the map before deleting to try to catch reentrancy.
66 Instance* obj = found->second; 67 Instance* obj = found->second;
67 module_singleton->current_instances_.erase(found); 68 module_singleton->current_instances_.erase(found);
68 delete obj; 69 delete obj;
69 } 70 }
70 71
71 void Instance_DidChangeView(PP_Instance pp_instance, 72 void Instance_DidChangeView(PP_Instance pp_instance,
72 const PP_Rect* position, 73 const PP_Rect* position,
73 const PP_Rect* clip) { 74 const PP_Rect* clip) {
74 Module* module_singleton = Module::Get(); 75 Module* module_singleton = Module::Get();
75 if (!module_singleton) 76 if (!module_singleton)
76 return; 77 return;
77 Instance* instance = module_singleton->InstanceForPPInstance(pp_instance); 78 Instance* instance = module_singleton->InstanceForPPInstance(pp_instance);
78 if (!instance) 79 if (!instance)
79 return; 80 return;
80 instance->DidChangeView(*position, *clip); 81 instance->DidChangeView(*position, *clip);
81 } 82 }
82 83
83 void Instance_DidChangeFocus(PP_Instance pp_instance, bool has_focus) { 84 void Instance_DidChangeFocus(PP_Instance pp_instance, PP_Bool has_focus) {
84 Module* module_singleton = Module::Get(); 85 Module* module_singleton = Module::Get();
85 if (!module_singleton) 86 if (!module_singleton)
86 return; 87 return;
87 Instance* instance = module_singleton->InstanceForPPInstance(pp_instance); 88 Instance* instance = module_singleton->InstanceForPPInstance(pp_instance);
88 if (!instance) 89 if (!instance)
89 return; 90 return;
90 instance->DidChangeFocus(has_focus); 91 instance->DidChangeFocus(PPBoolToBool(has_focus));
91 } 92 }
92 93
93 bool Instance_HandleInputEvent(PP_Instance pp_instance, 94 PP_Bool Instance_HandleInputEvent(PP_Instance pp_instance,
94 const PP_InputEvent* event) { 95 const PP_InputEvent* event) {
95 Module* module_singleton = Module::Get(); 96 Module* module_singleton = Module::Get();
96 if (!module_singleton) 97 if (!module_singleton)
97 return false; 98 return PP_FALSE;
98 Instance* instance = module_singleton->InstanceForPPInstance(pp_instance); 99 Instance* instance = module_singleton->InstanceForPPInstance(pp_instance);
99 if (!instance) 100 if (!instance)
100 return false; 101 return PP_FALSE;
101 return instance->HandleInputEvent(*event); 102 return BoolToPPBool(instance->HandleInputEvent(*event));
102 } 103 }
103 104
104 bool Instance_HandleDocumentLoad(PP_Instance pp_instance, 105 PP_Bool Instance_HandleDocumentLoad(PP_Instance pp_instance,
105 PP_Resource pp_url_loader) { 106 PP_Resource pp_url_loader) {
106 Module* module_singleton = Module::Get(); 107 Module* module_singleton = Module::Get();
107 if (!module_singleton) 108 if (!module_singleton)
108 return false; 109 return PP_FALSE;
109 Instance* instance = module_singleton->InstanceForPPInstance(pp_instance); 110 Instance* instance = module_singleton->InstanceForPPInstance(pp_instance);
110 if (!instance) 111 if (!instance)
111 return false; 112 return PP_FALSE;
112 return instance->HandleDocumentLoad(URLLoader_Dev(pp_url_loader)); 113 return BoolToPPBool(
114 instance->HandleDocumentLoad(URLLoader_Dev(pp_url_loader)));
113 } 115 }
114 116
115 PP_Var Instance_GetInstanceObject(PP_Instance pp_instance) { 117 PP_Var Instance_GetInstanceObject(PP_Instance pp_instance) {
116 Module* module_singleton = Module::Get(); 118 Module* module_singleton = Module::Get();
117 if (!module_singleton) 119 if (!module_singleton)
118 return Var().Detach(); 120 return Var().Detach();
119 Instance* instance = module_singleton->InstanceForPPInstance(pp_instance); 121 Instance* instance = module_singleton->InstanceForPPInstance(pp_instance);
120 if (!instance) 122 if (!instance)
121 return Var().Detach(); 123 return Var().Detach();
122 return instance->GetInstanceObject().Detach(); 124 return instance->GetInstanceObject().Detach();
(...skipping 66 matching lines...) Expand 10 before | Expand all | Expand 10 after
189 const PPB_Core* core = reinterpret_cast<const PPB_Core*>(GetBrowserInterface( 191 const PPB_Core* core = reinterpret_cast<const PPB_Core*>(GetBrowserInterface(
190 PPB_CORE_INTERFACE)); 192 PPB_CORE_INTERFACE));
191 if (!core) 193 if (!core)
192 return false; 194 return false;
193 core_ = new Core(core); 195 core_ = new Core(core);
194 196
195 return Init(); 197 return Init();
196 } 198 }
197 199
198 } // namespace pp 200 } // namespace pp
OLDNEW
« no previous file with comments | « ppapi/cpp/module.h ('k') | ppapi/cpp/var.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698