OLD | NEW |
---|---|
(Empty) | |
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 | |
3 // found in the LICENSE file. | |
4 | |
5 #include "content/browser/renderer_host/java_bridge_dispatcher_host_manager.h" | |
6 | |
7 #include "base/utf_string_conversions.h" | |
8 #include "content/browser/renderer_host/java_bridge_dispatcher_host.h" | |
9 #include "content/browser/tab_contents/tab_contents.h" | |
10 | |
11 JavaBridgeDispatcherHostManager::JavaBridgeDispatcherHostManager( | |
12 TabContents* tab_contents) | |
13 : TabContentsObserver(tab_contents) { | |
14 } | |
15 | |
16 JavaBridgeDispatcherHostManager::~JavaBridgeDispatcherHostManager() { | |
17 DCHECK_EQ(0U, instances_.size()); | |
18 } | |
19 | |
20 void JavaBridgeDispatcherHostManager::AddNamedObject(const string16& name, | |
21 NPObject* object) { | |
22 // Record this object in a map so that we can add it into RenderViewHosts | |
23 // created later. We don't need to take a reference because each | |
24 // JavaBridgeDispatcherHost will do so. The object can't be deleted until | |
25 // after RemoveNamedObject() is called, at which time we remove the entry | |
26 // from the map. | |
27 DCHECK(!instances_.empty()) << "There must be at least one instance present"; | |
28 objects_[name] = object; | |
29 | |
30 for (InstanceMap::iterator iter = instances_.begin(); | |
31 iter != instances_.end(); ++iter) { | |
32 iter->second->AddNamedObject(name, object); | |
33 } | |
34 } | |
35 | |
36 void JavaBridgeDispatcherHostManager::RemoveNamedObject(const string16& name) { | |
37 ObjectMap::iterator iter = objects_.find(name); | |
38 if (iter == objects_.end()) { | |
39 return; | |
40 } | |
41 | |
42 objects_.erase(iter); | |
43 | |
44 for (InstanceMap::iterator iter = instances_.begin(); | |
45 iter != instances_.end(); ++iter) { | |
46 iter->second->RemoveNamedObject(name); | |
47 } | |
48 } | |
49 | |
50 void JavaBridgeDispatcherHostManager::RenderViewCreated( | |
51 RenderViewHost* render_view_host) { | |
52 // Creates a JavaBridgeDispatcherHost for the specified RenderViewHost and | |
53 // adds all currently registered named objects to the new instance. | |
54 DCHECK(render_view_host); | |
jam
2011/10/21 16:18:21
this isn't necessary
| |
55 | |
56 scoped_refptr<JavaBridgeDispatcherHost> instance = | |
57 new JavaBridgeDispatcherHost(render_view_host); | |
58 | |
59 for (ObjectMap::const_iterator iter = objects_.begin(); | |
60 iter != objects_.end(); ++iter) { | |
61 instance->AddNamedObject(iter->first, iter->second); | |
62 } | |
63 | |
64 instances_[render_view_host] = instance; | |
65 } | |
66 | |
67 void JavaBridgeDispatcherHostManager::RenderViewDeleted( | |
68 RenderViewHost* render_view_host) { | |
69 instances_.erase(render_view_host); | |
70 } | |
71 | |
72 void JavaBridgeDispatcherHostManager::TabContentsDestroyed( | |
73 TabContents* tab_contents) { | |
74 // When the tab is shutting down, the TabContents clears its observers before | |
75 // it kills all of its RenderViewHosts, so we won't get a call to | |
76 // RenderViewDeleted() for all RenderViewHosts. | |
77 instances_.clear(); | |
78 } | |
OLD | NEW |