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

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

Issue 7285010: Implement an input event resource. (Closed) Base URL: svn://chrome-svn/chrome/trunk/src/
Patch Set: '' Created 9 years, 5 months 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
OLDNEW
1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2011 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
11 // provides a simple default implementation of Module::Get(). 11 // provides a simple default implementation of Module::Get().
12 // 12 //
13 // A notable exception where the default ppp_entrypoints will not work is 13 // A notable exception where the default ppp_entrypoints will not work is
14 // when implementing "internal plugins" that are statically linked into the 14 // when implementing "internal plugins" that are statically linked into the
15 // browser. In this case, the process may actually have multiple Modules 15 // browser. In this case, the process may actually have multiple Modules
16 // loaded at once making a traditional "singleton" unworkable. To get around 16 // loaded at once making a traditional "singleton" unworkable. To get around
17 // this, the users of ppapi need to get creative about how to properly 17 // this, the users of ppapi need to get creative about how to properly
18 // implement the Module::Get() so that ppapi's C++ wrappers can find the 18 // implement the Module::Get() so that ppapi's C++ wrappers can find the
19 // right Module object. One example solution is to use thread local storage 19 // right Module object. One example solution is to use thread local storage
20 // to change the Module* returned based on which thread is invoking the 20 // to change the Module* returned based on which thread is invoking the
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_input_event.h"
30 #include "ppapi/c/ppp_instance.h" 31 #include "ppapi/c/ppp_instance.h"
31 #include "ppapi/c/ppp_messaging.h" 32 #include "ppapi/c/ppp_messaging.h"
32 #include "ppapi/cpp/common.h" 33 #include "ppapi/cpp/common.h"
33 #include "ppapi/cpp/url_loader.h" 34 #include "ppapi/cpp/input_event.h"
34 #include "ppapi/cpp/instance.h" 35 #include "ppapi/cpp/instance.h"
35 #include "ppapi/cpp/rect.h" 36 #include "ppapi/cpp/rect.h"
36 #include "ppapi/cpp/resource.h" 37 #include "ppapi/cpp/resource.h"
38 #include "ppapi/cpp/url_loader.h"
37 #include "ppapi/cpp/var.h" 39 #include "ppapi/cpp/var.h"
38 40
39 namespace pp { 41 namespace pp {
40 42
43 // PPP_InputEvent implementation -----------------------------------------------
44
45 PP_Bool InputEvent_HandleEvent(PP_Instance pp_instance, PP_Resource resource) {
46 Module* module_singleton = Module::Get();
47 if (!module_singleton)
48 return PP_FALSE;
49 Instance* instance = module_singleton->InstanceForPPInstance(pp_instance);
50 if (!instance)
51 return PP_FALSE;
52
53 return BoolToPPBool(instance->HandleInputEvent(InputEvent(resource)));
54 }
55
56 const PPP_InputEvent input_event_interface = {
57 &InputEvent_HandleEvent
58 };
59
41 // PPP_Instance implementation ------------------------------------------------- 60 // PPP_Instance implementation -------------------------------------------------
42 61
43 PP_Bool Instance_DidCreate(PP_Instance pp_instance, 62 PP_Bool Instance_DidCreate(PP_Instance pp_instance,
44 uint32_t argc, 63 uint32_t argc,
45 const char* argn[], 64 const char* argn[],
46 const char* argv[]) { 65 const char* argv[]) {
47 Module* module_singleton = Module::Get(); 66 Module* module_singleton = Module::Get();
48 if (!module_singleton) 67 if (!module_singleton)
49 return PP_FALSE; 68 return PP_FALSE;
50 69
(...skipping 81 matching lines...) Expand 10 before | Expand all | Expand 10 after
132 &Instance_DidDestroy, 151 &Instance_DidDestroy,
133 &Instance_DidChangeView, 152 &Instance_DidChangeView,
134 &Instance_DidChangeFocus, 153 &Instance_DidChangeFocus,
135 &Instance_HandleInputEvent, 154 &Instance_HandleInputEvent,
136 &Instance_HandleDocumentLoad, 155 &Instance_HandleDocumentLoad,
137 #ifndef PPAPI_INSTANCE_REMOVE_SCRIPTING 156 #ifndef PPAPI_INSTANCE_REMOVE_SCRIPTING
138 &Instance_GetInstanceObject 157 &Instance_GetInstanceObject
139 #endif 158 #endif
140 }; 159 };
141 160
161 // PPP_Messaging implementation ------------------------------------------------
162
142 void Messaging_HandleMessage(PP_Instance pp_instance, PP_Var var) { 163 void Messaging_HandleMessage(PP_Instance pp_instance, PP_Var var) {
143 Module* module_singleton = Module::Get(); 164 Module* module_singleton = Module::Get();
144 if (!module_singleton) 165 if (!module_singleton)
145 return; 166 return;
146 Instance* instance = module_singleton->InstanceForPPInstance(pp_instance); 167 Instance* instance = module_singleton->InstanceForPPInstance(pp_instance);
147 if (!instance) 168 if (!instance)
148 return; 169 return;
149 instance->HandleMessage(Var(Var::PassRef(), var)); 170 instance->HandleMessage(Var(Var::PassRef(), var));
150 } 171 }
151 172
152 static PPP_Messaging instance_messaging_interface = { 173 static PPP_Messaging instance_messaging_interface = {
153 &Messaging_HandleMessage 174 &Messaging_HandleMessage
154 }; 175 };
155 176
156 // Module ---------------------------------------------------------------------- 177 // Module ----------------------------------------------------------------------
157 178
158 Module::Module() : pp_module_(0), get_browser_interface_(NULL), core_(NULL) { 179 Module::Module() : pp_module_(0), get_browser_interface_(NULL), core_(NULL) {
159 } 180 }
160 181
161 Module::~Module() { 182 Module::~Module() {
162 delete core_; 183 delete core_;
163 core_ = NULL; 184 core_ = NULL;
164 } 185 }
165 186
166 bool Module::Init() { 187 bool Module::Init() {
167 return true; 188 return true;
168 } 189 }
169 190
170 const void* Module::GetPluginInterface(const char* interface_name) { 191 const void* Module::GetPluginInterface(const char* interface_name) {
192 if (strcmp(interface_name, PPP_INPUT_EVENT_INTERFACE) == 0)
193 return &input_event_interface;
171 if (strcmp(interface_name, PPP_INSTANCE_INTERFACE) == 0) 194 if (strcmp(interface_name, PPP_INSTANCE_INTERFACE) == 0)
172 return &instance_interface; 195 return &instance_interface;
173
174 if (strcmp(interface_name, PPP_MESSAGING_INTERFACE) == 0) 196 if (strcmp(interface_name, PPP_MESSAGING_INTERFACE) == 0)
175 return &instance_messaging_interface; 197 return &instance_messaging_interface;
176 198
177 // Now see if anything was dynamically registered. 199 // Now see if anything was dynamically registered.
178 InterfaceMap::const_iterator found = additional_interfaces_.find( 200 InterfaceMap::const_iterator found = additional_interfaces_.find(
179 std::string(interface_name)); 201 std::string(interface_name));
180 if (found != additional_interfaces_.end()) 202 if (found != additional_interfaces_.end())
181 return found->second; 203 return found->second;
182 204
183 return NULL; 205 return NULL;
(...skipping 33 matching lines...) Expand 10 before | Expand all | Expand 10 after
217 const PPB_Core* core = reinterpret_cast<const PPB_Core*>(GetBrowserInterface( 239 const PPB_Core* core = reinterpret_cast<const PPB_Core*>(GetBrowserInterface(
218 PPB_CORE_INTERFACE)); 240 PPB_CORE_INTERFACE));
219 if (!core) 241 if (!core)
220 return false; 242 return false;
221 core_ = new Core(core); 243 core_ = new Core(core);
222 244
223 return Init(); 245 return Init();
224 } 246 }
225 247
226 } // namespace pp 248 } // namespace pp
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698