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

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

Issue 8525016: Move Java Bridge files to new java/ subdirectory (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Rebased Created 9 years, 1 month 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 #include "third_party/WebKit/Source/WebKit/chromium/public/WebBindings.h"
11
12 JavaBridgeDispatcherHostManager::JavaBridgeDispatcherHostManager(
13 TabContents* tab_contents)
14 : TabContentsObserver(tab_contents) {
15 }
16
17 JavaBridgeDispatcherHostManager::~JavaBridgeDispatcherHostManager() {
18 DCHECK_EQ(0U, instances_.size());
19 }
20
21 void JavaBridgeDispatcherHostManager::AddNamedObject(const string16& name,
22 NPObject* object) {
23 // Record this object in a map so that we can add it into RenderViewHosts
24 // created later. The JavaBridgeDispatcherHost instances will take a
25 // reference to the object, but we take one too, because this method can be
26 // called before there are any such instances.
27 WebKit::WebBindings::retainObject(object);
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 WebKit::WebBindings::releaseObject(iter->second);
43 objects_.erase(iter);
44
45 for (InstanceMap::iterator iter = instances_.begin();
46 iter != instances_.end(); ++iter) {
47 iter->second->RemoveNamedObject(name);
48 }
49 }
50
51 void JavaBridgeDispatcherHostManager::RenderViewCreated(
52 RenderViewHost* render_view_host) {
53 // Creates a JavaBridgeDispatcherHost for the specified RenderViewHost and
54 // adds all currently registered named objects to the new instance.
55 scoped_refptr<JavaBridgeDispatcherHost> instance =
56 new JavaBridgeDispatcherHost(render_view_host);
57
58 for (ObjectMap::const_iterator iter = objects_.begin();
59 iter != objects_.end(); ++iter) {
60 instance->AddNamedObject(iter->first, iter->second);
61 }
62
63 instances_[render_view_host] = instance;
64 }
65
66 void JavaBridgeDispatcherHostManager::RenderViewDeleted(
67 RenderViewHost* render_view_host) {
68 instances_.erase(render_view_host);
69 }
70
71 void JavaBridgeDispatcherHostManager::TabContentsDestroyed(
72 TabContents* tab_contents) {
73 // When the tab is shutting down, the TabContents clears its observers before
74 // it kills all of its RenderViewHosts, so we won't get a call to
75 // RenderViewDeleted() for all RenderViewHosts.
76 instances_.clear();
77 }
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