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

Side by Side Diff: webkit/plugins/ppapi/host_globals.cc

Issue 10168026: Delete FunctionGroupBase from Pepper. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Created 8 years, 8 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) 2012 The Chromium Authors. All rights reserved. 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 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 #include "webkit/plugins/ppapi/host_globals.h" 5 #include "webkit/plugins/ppapi/host_globals.h"
6 6
7 #include <limits> 7 #include <limits>
8 8
9 #include "base/command_line.h" 9 #include "base/command_line.h"
10 #include "base/logging.h" 10 #include "base/logging.h"
11 #include "base/rand_util.h" 11 #include "base/rand_util.h"
12 #include "base/utf_string_conversions.h" 12 #include "base/utf_string_conversions.h"
13 #include "ppapi/shared_impl/api_id.h" 13 #include "ppapi/shared_impl/api_id.h"
14 #include "ppapi/shared_impl/function_group_base.h"
15 #include "ppapi/shared_impl/id_assignment.h" 14 #include "ppapi/shared_impl/id_assignment.h"
16 #include "third_party/WebKit/Source/WebKit/chromium/public/platform/WebString.h" 15 #include "third_party/WebKit/Source/WebKit/chromium/public/platform/WebString.h"
17 #include "third_party/WebKit/Source/WebKit/chromium/public/WebConsoleMessage.h" 16 #include "third_party/WebKit/Source/WebKit/chromium/public/WebConsoleMessage.h"
18 #include "third_party/WebKit/Source/WebKit/chromium/public/WebDocument.h" 17 #include "third_party/WebKit/Source/WebKit/chromium/public/WebDocument.h"
19 #include "third_party/WebKit/Source/WebKit/chromium/public/WebElement.h" 18 #include "third_party/WebKit/Source/WebKit/chromium/public/WebElement.h"
20 #include "third_party/WebKit/Source/WebKit/chromium/public/WebFrame.h" 19 #include "third_party/WebKit/Source/WebKit/chromium/public/WebFrame.h"
21 #include "third_party/WebKit/Source/WebKit/chromium/public/WebPluginContainer.h" 20 #include "third_party/WebKit/Source/WebKit/chromium/public/WebPluginContainer.h"
22 #include "webkit/plugins/plugin_switches.h" 21 #include "webkit/plugins/plugin_switches.h"
23 #include "webkit/plugins/ppapi/plugin_module.h" 22 #include "webkit/plugins/ppapi/plugin_module.h"
24 #include "webkit/plugins/ppapi/ppapi_plugin_instance.h" 23 #include "webkit/plugins/ppapi/ppapi_plugin_instance.h"
25 #include "webkit/plugins/ppapi/resource_creation_impl.h"
26 24
27 using ppapi::CheckIdType; 25 using ppapi::CheckIdType;
28 using ppapi::MakeTypedId; 26 using ppapi::MakeTypedId;
29 using ppapi::PPIdType; 27 using ppapi::PPIdType;
30 using WebKit::WebConsoleMessage; 28 using WebKit::WebConsoleMessage;
31 using WebKit::WebString; 29 using WebKit::WebString;
32 30
33 namespace webkit { 31 namespace webkit {
34 namespace ppapi { 32 namespace ppapi {
35 33
(...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after
67 std::string result = source; 65 std::string result = source;
68 if (!result.empty()) 66 if (!result.empty())
69 result.append(": "); 67 result.append(": ");
70 result.append(message); 68 result.append(message);
71 return WebConsoleMessage(LogLevelToWebLogLevel(level), 69 return WebConsoleMessage(LogLevelToWebLogLevel(level),
72 WebString(UTF8ToUTF16(result))); 70 WebString(UTF8ToUTF16(result)));
73 } 71 }
74 72
75 } // namespace 73 } // namespace
76 74
77 struct HostGlobals::InstanceData {
brettw 2012/04/21 19:50:01 I deleted this since I deleted the function_proxie
78 InstanceData() : instance(0) {}
79
80 // Non-owning pointer to the instance object. When a PluginInstance is
81 // destroyed, it will notify us and we'll delete all associated data.
82 PluginInstance* instance;
83
84 // Lazily allocated function proxies for the different interfaces.
85 scoped_ptr< ::ppapi::FunctionGroupBase >
86 function_proxies[::ppapi::API_ID_COUNT];
87 };
88
89 HostGlobals* HostGlobals::host_globals_ = NULL; 75 HostGlobals* HostGlobals::host_globals_ = NULL;
90 76
91 HostGlobals::HostGlobals() : ::ppapi::PpapiGlobals() { 77 HostGlobals::HostGlobals() : ::ppapi::PpapiGlobals() {
92 DCHECK(!host_globals_); 78 DCHECK(!host_globals_);
93 host_globals_ = this; 79 host_globals_ = this;
94 } 80 }
95 81
96 HostGlobals::HostGlobals(::ppapi::PpapiGlobals::ForTest for_test) 82 HostGlobals::HostGlobals(::ppapi::PpapiGlobals::ForTest for_test)
97 : ::ppapi::PpapiGlobals(for_test) { 83 : ::ppapi::PpapiGlobals(for_test) {
98 DCHECK(!host_globals_); 84 DCHECK(!host_globals_);
99 } 85 }
100 86
101 HostGlobals::~HostGlobals() { 87 HostGlobals::~HostGlobals() {
102 DCHECK(host_globals_ == this || !host_globals_); 88 DCHECK(host_globals_ == this || !host_globals_);
103 host_globals_ = NULL; 89 host_globals_ = NULL;
104 } 90 }
105 91
106 ::ppapi::ResourceTracker* HostGlobals::GetResourceTracker() { 92 ::ppapi::ResourceTracker* HostGlobals::GetResourceTracker() {
107 return &resource_tracker_; 93 return &resource_tracker_;
108 } 94 }
109 95
110 ::ppapi::VarTracker* HostGlobals::GetVarTracker() { 96 ::ppapi::VarTracker* HostGlobals::GetVarTracker() {
111 return &host_var_tracker_; 97 return &host_var_tracker_;
112 } 98 }
113 99
114 ::ppapi::CallbackTracker* HostGlobals::GetCallbackTrackerForInstance( 100 ::ppapi::CallbackTracker* HostGlobals::GetCallbackTrackerForInstance(
115 PP_Instance instance) { 101 PP_Instance instance) {
116 std::map<PP_Instance, linked_ptr<InstanceData> >::iterator found = 102 InstanceMap::iterator found = instance_map_.find(instance);
117 instance_map_.find(instance);
118 if (found == instance_map_.end()) 103 if (found == instance_map_.end())
119 return NULL; 104 return NULL;
120 105 return found->second->module()->GetCallbackTracker();
121 return found->second->instance->module()->GetCallbackTracker();
122 } 106 }
123 107
124 ::ppapi::FunctionGroupBase* HostGlobals::GetFunctionAPI(PP_Instance pp_instance, 108 ::ppapi::thunk::PPB_Instance_API* HostGlobals::GetInstanceAPI(
125 ::ppapi::ApiID id) { 109 PP_Instance instance) {
126 // Get the instance object. This also ensures that the instance data is in 110 // The InstanceAPI is just implemented by the PluginInstance object.
127 // the map, since we need it below. 111 return GetInstance(instance);
112 }
113
114 ::ppapi::thunk::ResourceCreationAPI* HostGlobals::GetResourceCreationAPI(
115 PP_Instance pp_instance) {
128 PluginInstance* instance = GetInstance(pp_instance); 116 PluginInstance* instance = GetInstance(pp_instance);
129 if (!instance) 117 if (!instance)
130 return NULL; 118 return NULL;
131 119 return &instance->resource_creation();
132 // The instance one is special, since it's just implemented by the instance
133 // object.
134 if (id == ::ppapi::API_ID_PPB_INSTANCE)
135 return instance;
136
137 scoped_ptr< ::ppapi::FunctionGroupBase >& proxy =
138 instance_map_[pp_instance]->function_proxies[id];
139 if (proxy.get())
140 return proxy.get();
141
142 switch (id) {
143 case ::ppapi::API_ID_RESOURCE_CREATION:
144 proxy.reset(new ResourceCreationImpl(instance));
145 break;
146 default:
147 NOTREACHED();
148 }
149
150 return proxy.get();
151 } 120 }
152 121
153 PP_Module HostGlobals::GetModuleForInstance(PP_Instance instance) { 122 PP_Module HostGlobals::GetModuleForInstance(PP_Instance instance) {
154 PluginInstance* inst = GetInstance(instance); 123 PluginInstance* inst = GetInstance(instance);
155 if (!inst) 124 if (!inst)
156 return 0; 125 return 0;
157 return inst->module()->pp_module(); 126 return inst->module()->pp_module();
158 } 127 }
159 128
160 std::string HostGlobals::GetCommandLine() { 129 std::string HostGlobals::GetCommandLine() {
(...skipping 95 matching lines...) Expand 10 before | Expand all | Expand 10 after
256 // 225 //
257 // Need to make sure the random number isn't a duplicate or 0. 226 // Need to make sure the random number isn't a duplicate or 0.
258 PP_Instance new_instance; 227 PP_Instance new_instance;
259 do { 228 do {
260 new_instance = MakeTypedId(static_cast<PP_Instance>(base::RandUint64()), 229 new_instance = MakeTypedId(static_cast<PP_Instance>(base::RandUint64()),
261 ::ppapi::PP_ID_TYPE_INSTANCE); 230 ::ppapi::PP_ID_TYPE_INSTANCE);
262 } while (!new_instance || 231 } while (!new_instance ||
263 instance_map_.find(new_instance) != instance_map_.end() || 232 instance_map_.find(new_instance) != instance_map_.end() ||
264 !instance->module()->ReserveInstanceID(new_instance)); 233 !instance->module()->ReserveInstanceID(new_instance));
265 234
266 instance_map_[new_instance] = linked_ptr<InstanceData>(new InstanceData); 235 instance_map_[new_instance] = instance;
267 instance_map_[new_instance]->instance = instance;
268 236
269 resource_tracker_.DidCreateInstance(new_instance); 237 resource_tracker_.DidCreateInstance(new_instance);
270 return new_instance; 238 return new_instance;
271 } 239 }
272 240
273 void HostGlobals::InstanceDeleted(PP_Instance instance) { 241 void HostGlobals::InstanceDeleted(PP_Instance instance) {
274 resource_tracker_.DidDeleteInstance(instance); 242 resource_tracker_.DidDeleteInstance(instance);
275 host_var_tracker_.ForceFreeNPObjectsForInstance(instance); 243 host_var_tracker_.ForceFreeNPObjectsForInstance(instance);
276 instance_map_.erase(instance); 244 instance_map_.erase(instance);
277 } 245 }
278 246
279 void HostGlobals::InstanceCrashed(PP_Instance instance) { 247 void HostGlobals::InstanceCrashed(PP_Instance instance) {
280 resource_tracker_.DidDeleteInstance(instance); 248 resource_tracker_.DidDeleteInstance(instance);
281 host_var_tracker_.ForceFreeNPObjectsForInstance(instance); 249 host_var_tracker_.ForceFreeNPObjectsForInstance(instance);
282 } 250 }
283 251
284 PluginInstance* HostGlobals::GetInstance(PP_Instance instance) { 252 PluginInstance* HostGlobals::GetInstance(PP_Instance instance) {
285 DLOG_IF(ERROR, !CheckIdType(instance, ::ppapi::PP_ID_TYPE_INSTANCE)) 253 DLOG_IF(ERROR, !CheckIdType(instance, ::ppapi::PP_ID_TYPE_INSTANCE))
286 << instance << " is not a PP_Instance."; 254 << instance << " is not a PP_Instance.";
287 InstanceMap::iterator found = instance_map_.find(instance); 255 InstanceMap::iterator found = instance_map_.find(instance);
288 if (found == instance_map_.end()) 256 if (found == instance_map_.end())
289 return NULL; 257 return NULL;
290 return found->second->instance; 258 return found->second;
291 } 259 }
292 260
293 bool HostGlobals::IsHostGlobals() const { 261 bool HostGlobals::IsHostGlobals() const {
294 return true; 262 return true;
295 } 263 }
296 264
297 } // namespace ppapi 265 } // namespace ppapi
298 } // namespace webkit 266 } // namespace webkit
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698