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

Side by Side Diff: content/browser/renderer_host/java_bridge_dispatcher_host_manager.cc

Issue 8366034: Adds browser-side component of Java Bridge for a TabContents (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Guards with ENABLE_JAVA_BRIDGE and addresses other comments Created 9 years, 2 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
(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 scoped_refptr<JavaBridgeDispatcherHost> instance =
55 new JavaBridgeDispatcherHost(render_view_host);
56
57 for (ObjectMap::const_iterator iter = objects_.begin();
58 iter != objects_.end(); ++iter) {
59 instance->AddNamedObject(iter->first, iter->second);
60 }
61
62 instances_[render_view_host] = instance;
63 }
64
65 void JavaBridgeDispatcherHostManager::RenderViewDeleted(
66 RenderViewHost* render_view_host) {
67 instances_.erase(render_view_host);
68 }
69
70 void JavaBridgeDispatcherHostManager::TabContentsDestroyed(
71 TabContents* tab_contents) {
72 // When the tab is shutting down, the TabContents clears its observers before
73 // it kills all of its RenderViewHosts, so we won't get a call to
74 // RenderViewDeleted() for all RenderViewHosts.
75 instances_.clear();
76 }
OLDNEW
« no previous file with comments | « content/browser/renderer_host/java_bridge_dispatcher_host_manager.h ('k') | content/browser/tab_contents/tab_contents.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698