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

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

Issue 6716005: A proposal and implementation for an initial postMessage interface. These in... (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src/
Patch Set: '' Created 9 years, 9 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) 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
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/dev/ppp_messaging_dev.h"
28 #include "ppapi/c/pp_instance.h" 29 #include "ppapi/c/pp_instance.h"
29 #include "ppapi/c/pp_var.h" 30 #include "ppapi/c/pp_var.h"
30 #include "ppapi/c/ppp_instance.h" 31 #include "ppapi/c/ppp_instance.h"
31 #include "ppapi/cpp/common.h" 32 #include "ppapi/cpp/common.h"
32 #include "ppapi/cpp/url_loader.h" 33 #include "ppapi/cpp/url_loader.h"
33 #include "ppapi/cpp/instance.h" 34 #include "ppapi/cpp/instance.h"
34 #include "ppapi/cpp/rect.h" 35 #include "ppapi/cpp/rect.h"
35 #include "ppapi/cpp/resource.h" 36 #include "ppapi/cpp/resource.h"
36 #include "ppapi/cpp/var.h" 37 #include "ppapi/cpp/var.h"
37 38
(...skipping 89 matching lines...) Expand 10 before | Expand all | Expand 10 after
127 static PPP_Instance instance_interface = { 128 static PPP_Instance instance_interface = {
128 &Instance_DidCreate, 129 &Instance_DidCreate,
129 &Instance_DidDestroy, 130 &Instance_DidDestroy,
130 &Instance_DidChangeView, 131 &Instance_DidChangeView,
131 &Instance_DidChangeFocus, 132 &Instance_DidChangeFocus,
132 &Instance_HandleInputEvent, 133 &Instance_HandleInputEvent,
133 &Instance_HandleDocumentLoad, 134 &Instance_HandleDocumentLoad,
134 &Instance_GetInstanceObject 135 &Instance_GetInstanceObject
135 }; 136 };
136 137
138 void Messaging_HandleMessage(PP_Instance pp_instance, PP_Var var) {
139 Module* module_singleton = Module::Get();
140 if (!module_singleton)
141 return;
142 Instance* instance = module_singleton->InstanceForPPInstance(pp_instance);
143 if (!instance)
144 return;
145 instance->HandleMessage(Var(Var::PassRef(), var));
146 }
147
148 static PPP_Messaging_Dev instance_messaging_interface = {
149 &Messaging_HandleMessage
150 };
151
137 // Module ---------------------------------------------------------------------- 152 // Module ----------------------------------------------------------------------
138 153
139 Module::Module() : pp_module_(0), get_browser_interface_(NULL), core_(NULL) { 154 Module::Module() : pp_module_(0), get_browser_interface_(NULL), core_(NULL) {
140 } 155 }
141 156
142 Module::~Module() { 157 Module::~Module() {
143 delete core_; 158 delete core_;
144 core_ = NULL; 159 core_ = NULL;
145 } 160 }
146 161
147 bool Module::Init() { 162 bool Module::Init() {
148 return true; 163 return true;
149 } 164 }
150 165
151 const void* Module::GetPluginInterface(const char* interface_name) { 166 const void* Module::GetPluginInterface(const char* interface_name) {
152 if (strcmp(interface_name, PPP_INSTANCE_INTERFACE) == 0) 167 if (strcmp(interface_name, PPP_INSTANCE_INTERFACE) == 0)
153 return &instance_interface; 168 return &instance_interface;
154 169
170 if (strcmp(interface_name, PPP_MESSAGING_DEV_INTERFACE) == 0)
171 return &instance_messaging_interface;
172
155 // Now see if anything was dynamically registered. 173 // Now see if anything was dynamically registered.
156 InterfaceMap::const_iterator found = additional_interfaces_.find( 174 InterfaceMap::const_iterator found = additional_interfaces_.find(
157 std::string(interface_name)); 175 std::string(interface_name));
158 if (found != additional_interfaces_.end()) 176 if (found != additional_interfaces_.end())
159 return found->second; 177 return found->second;
160 178
161 return NULL; 179 return NULL;
162 } 180 }
163 181
164 const void* Module::GetBrowserInterface(const char* interface_name) { 182 const void* Module::GetBrowserInterface(const char* interface_name) {
(...skipping 30 matching lines...) Expand all
195 const PPB_Core* core = reinterpret_cast<const PPB_Core*>(GetBrowserInterface( 213 const PPB_Core* core = reinterpret_cast<const PPB_Core*>(GetBrowserInterface(
196 PPB_CORE_INTERFACE)); 214 PPB_CORE_INTERFACE));
197 if (!core) 215 if (!core)
198 return false; 216 return false;
199 core_ = new Core(core); 217 core_ = new Core(core);
200 218
201 return Init(); 219 return Init();
202 } 220 }
203 221
204 } // namespace pp 222 } // namespace pp
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698