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

Side by Side Diff: content/child/np_channel_base.cc

Issue 17208003: Track NPObject ownership by the originating plugins' NPP identifier. [4/6] (Chrome) (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Temporarily remove check for NULL owner when receiving objects. Created 7 years, 6 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 2013 The Chromium Authors. All rights reserved. 1 // Copyright 2013 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 "content/child/np_channel_base.h" 5 #include "content/child/np_channel_base.h"
6 6
7 #include <stack> 7 #include <stack>
8 8
9 #include "base/auto_reset.h" 9 #include "base/auto_reset.h"
10 #include "base/containers/hash_tables.h" 10 #include "base/containers/hash_tables.h"
(...skipping 54 matching lines...) Expand 10 before | Expand all | Expand 10 after
65 iter->second->Send(new IPC::Message(*message)); 65 iter->second->Send(new IPC::Message(*message));
66 } 66 }
67 delete message; 67 delete message;
68 } 68 }
69 69
70 NPChannelBase::NPChannelBase() 70 NPChannelBase::NPChannelBase()
71 : mode_(IPC::Channel::MODE_NONE), 71 : mode_(IPC::Channel::MODE_NONE),
72 non_npobject_count_(0), 72 non_npobject_count_(0),
73 peer_pid_(0), 73 peer_pid_(0),
74 in_remove_route_(false), 74 in_remove_route_(false),
75 default_owner_(NULL),
75 channel_valid_(false), 76 channel_valid_(false),
76 in_unblock_dispatch_(0), 77 in_unblock_dispatch_(0),
77 send_unblocking_only_during_unblock_dispatch_(false) { 78 send_unblocking_only_during_unblock_dispatch_(false) {
78 } 79 }
79 80
80 NPChannelBase::~NPChannelBase() { 81 NPChannelBase::~NPChannelBase() {
darin (slow to review) 2013/06/18 23:26:24 should we assert that these new maps are empty at
Wez 2013/06/19 05:17:54 Done.
81 } 82 }
82 83
83 NPChannelBase* NPChannelBase::GetCurrentChannel() { 84 NPChannelBase* NPChannelBase::GetCurrentChannel() {
84 return g_lazy_channel_stack.Pointer()->top().get(); 85 return g_lazy_channel_stack.Pointer()->top().get();
85 } 86 }
86 87
87 void NPChannelBase::CleanupChannels() { 88 void NPChannelBase::CleanupChannels() {
88 // Make a copy of the references as we can't iterate the map since items will 89 // Make a copy of the references as we can't iterate the map since items will
89 // be removed from it as we clean them up. 90 // be removed from it as we clean them up.
90 std::vector<scoped_refptr<NPChannelBase> > channels; 91 std::vector<scoped_refptr<NPChannelBase> > channels;
(...skipping 173 matching lines...) Expand 10 before | Expand all | Expand 10 after
264 iter != g_channels.Get().end(); ++iter) { 265 iter != g_channels.Get().end(); ++iter) {
265 if (iter->second.get() == this) { 266 if (iter->second.get() == this) {
266 // Insert new element before invalidating |iter|. 267 // Insert new element before invalidating |iter|.
267 g_channels.Get()[iter->first + "-error"] = iter->second; 268 g_channels.Get()[iter->first + "-error"] = iter->second;
268 g_channels.Get().erase(iter); 269 g_channels.Get().erase(iter);
269 break; 270 break;
270 } 271 }
271 } 272 }
272 } 273 }
273 274
274 NPObject* NPChannelBase::GetExistingNPObjectProxy(int route_id) {
275 ProxyMap::iterator iter = proxy_map_.find(route_id);
276 return iter != proxy_map_.end() ? iter->second : NULL;
277 }
278
279 int NPChannelBase::GetExistingRouteForNPObjectStub(NPObject* npobject) {
280 StubMap::iterator iter = stub_map_.find(npobject);
281 return iter != stub_map_.end() ? iter->second : MSG_ROUTING_NONE;
282 }
283
284 void NPChannelBase::AddMappingForNPObjectProxy(int route_id, 275 void NPChannelBase::AddMappingForNPObjectProxy(int route_id,
285 NPObject* object) { 276 NPObject* object) {
286 proxy_map_[route_id] = object; 277 proxy_map_[route_id] = object;
287 } 278 }
288 279
280 void NPChannelBase::RemoveMappingForNPObjectProxy(int route_id) {
281 proxy_map_.erase(route_id);
282 }
283
289 void NPChannelBase::AddMappingForNPObjectStub(int route_id, 284 void NPChannelBase::AddMappingForNPObjectStub(int route_id,
290 NPObject* object) { 285 NPObject* object) {
291 DCHECK(object != NULL); 286 DCHECK(object != NULL);
292 stub_map_[object] = route_id; 287 stub_map_[object] = route_id;
293 } 288 }
294 289
295 void NPChannelBase::RemoveMappingForNPObjectStub(int route_id, 290 void NPChannelBase::RemoveMappingForNPObjectStub(int route_id,
296 NPObject* object) { 291 NPObject* object) {
297 DCHECK(object != NULL); 292 DCHECK(object != NULL);
298 stub_map_.erase(object); 293 stub_map_.erase(object);
299 } 294 }
300 295
301 void NPChannelBase::RemoveMappingForNPObjectProxy(int route_id) { 296 void NPChannelBase::AddMappingForNPObjectOwner(int route_id,
302 proxy_map_.erase(route_id); 297 struct _NPP* owner) {
298 DCHECK(owner != NULL);
299 route_to_owner_[route_id] = owner;
300 owner_to_route_[owner] = route_id;
301 }
302
303 void NPChannelBase::AddDefaultNPObjectOwner(struct _NPP* owner) {
darin (slow to review) 2013/06/18 23:26:24 nit: Since this method only supports retaining a s
Wez 2013/06/19 05:17:54 Done.
304 DCHECK(owner != NULL);
305 default_owner_ = owner;
306 }
307
308 void NPChannelBase::RemoveMappingForNPObjectOwner(int route_id) {
309 DCHECK(route_to_owner_.find(route_id) != route_to_owner_.end());
310 owner_to_route_.erase(route_to_owner_[route_id]);
311 route_to_owner_.erase(route_id);
312 }
313
314 NPObject* NPChannelBase::GetExistingNPObjectProxy(int route_id) {
315 ProxyMap::iterator iter = proxy_map_.find(route_id);
316 return iter != proxy_map_.end() ? iter->second : NULL;
317 }
318
319 int NPChannelBase::GetExistingRouteForNPObjectStub(NPObject* npobject) {
320 StubMap::iterator iter = stub_map_.find(npobject);
321 return iter != stub_map_.end() ? iter->second : MSG_ROUTING_NONE;
322 }
323
324 NPP NPChannelBase::GetExistingNPObjectOwner(int route_id) {
325 RouteToOwnerMap::iterator iter = route_to_owner_.find(route_id);
326 return iter != route_to_owner_.end() ? iter->second : default_owner_;
327 }
328
329 int NPChannelBase::GetExistingRouteForNPObjectOwner(NPP owner) {
330 OwnerToRouteMap::iterator iter = owner_to_route_.find(owner);
331 return iter != owner_to_route_.end() ? iter->second : MSG_ROUTING_NONE;
303 } 332 }
304 333
305 } // namespace content 334 } // namespace content
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698