OLD | NEW |
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 "content/renderer/browser_plugin/browser_plugin_manager.h" | 5 #include "content/renderer/browser_plugin/browser_plugin_manager.h" |
6 | 6 |
7 #include "base/memory/scoped_ptr.h" | 7 #include "base/memory/scoped_ptr.h" |
8 #include "content/common/browser_plugin/browser_plugin_constants.h" | 8 #include "content/common/browser_plugin/browser_plugin_constants.h" |
9 #include "content/common/browser_plugin/browser_plugin_messages.h" | 9 #include "content/common/browser_plugin/browser_plugin_messages.h" |
10 #include "content/common/frame_messages.h" | 10 #include "content/common/frame_messages.h" |
11 #include "content/public/renderer/browser_plugin_delegate.h" | 11 #include "content/public/renderer/browser_plugin_delegate.h" |
12 #include "content/public/renderer/render_thread.h" | 12 #include "content/public/renderer/content_renderer_client.h" |
13 #include "content/renderer/browser_plugin/browser_plugin.h" | 13 #include "content/renderer/browser_plugin/browser_plugin.h" |
| 14 #include "content/renderer/render_thread_impl.h" |
14 #include "ipc/ipc_message_macros.h" | 15 #include "ipc/ipc_message_macros.h" |
15 | 16 |
16 namespace content { | 17 namespace content { |
17 | 18 |
18 // static | 19 // static |
19 BrowserPluginManager* BrowserPluginManager::Create( | 20 BrowserPluginManager* BrowserPluginManager::Get() { |
20 RenderViewImpl* render_view) { | 21 return RenderThreadImpl::current()->browser_plugin_manager(); |
21 return new BrowserPluginManager(render_view); | |
22 } | 22 } |
23 | 23 |
24 BrowserPluginManager::BrowserPluginManager(RenderViewImpl* render_view) | 24 BrowserPluginManager::BrowserPluginManager() { |
25 : RenderViewObserver(render_view), | |
26 render_view_(render_view->AsWeakPtr()) { | |
27 } | 25 } |
28 | 26 |
29 BrowserPluginManager::~BrowserPluginManager() { | 27 BrowserPluginManager::~BrowserPluginManager() { |
30 } | 28 } |
31 | 29 |
32 void BrowserPluginManager::AddBrowserPlugin( | 30 void BrowserPluginManager::AddBrowserPlugin( |
33 int browser_plugin_instance_id, | 31 int browser_plugin_instance_id, |
34 BrowserPlugin* browser_plugin) { | 32 BrowserPlugin* browser_plugin) { |
35 instances_.AddWithID(browser_plugin, browser_plugin_instance_id); | 33 instances_.AddWithID(browser_plugin, browser_plugin_instance_id); |
36 } | 34 } |
37 | 35 |
38 void BrowserPluginManager::RemoveBrowserPlugin(int browser_plugin_instance_id) { | 36 void BrowserPluginManager::RemoveBrowserPlugin(int browser_plugin_instance_id) { |
39 instances_.Remove(browser_plugin_instance_id); | 37 instances_.Remove(browser_plugin_instance_id); |
40 } | 38 } |
41 | 39 |
42 BrowserPlugin* BrowserPluginManager::GetBrowserPlugin( | 40 BrowserPlugin* BrowserPluginManager::GetBrowserPlugin( |
43 int browser_plugin_instance_id) const { | 41 int browser_plugin_instance_id) const { |
44 return instances_.Lookup(browser_plugin_instance_id); | 42 return instances_.Lookup(browser_plugin_instance_id); |
45 } | 43 } |
46 | 44 |
47 int BrowserPluginManager::GetNextInstanceID() { | 45 int BrowserPluginManager::GetNextInstanceID() { |
48 return RenderThread::Get()->GenerateRoutingID(); | 46 return RenderThreadImpl::current()->GenerateRoutingID(); |
49 } | 47 } |
50 | 48 |
51 void BrowserPluginManager::UpdateDeviceScaleFactor() { | 49 void BrowserPluginManager::UpdateDeviceScaleFactor() { |
52 IDMap<BrowserPlugin>::iterator iter(&instances_); | 50 IDMap<BrowserPlugin>::iterator iter(&instances_); |
53 while (!iter.IsAtEnd()) { | 51 while (!iter.IsAtEnd()) { |
54 iter.GetCurrentValue()->UpdateDeviceScaleFactor(); | 52 iter.GetCurrentValue()->UpdateDeviceScaleFactor(); |
55 iter.Advance(); | 53 iter.Advance(); |
56 } | 54 } |
57 } | 55 } |
58 | 56 |
(...skipping 25 matching lines...) Expand all Loading... |
84 } | 82 } |
85 | 83 |
86 void BrowserPluginManager::DidCommitCompositorFrame() { | 84 void BrowserPluginManager::DidCommitCompositorFrame() { |
87 IDMap<BrowserPlugin>::iterator iter(&instances_); | 85 IDMap<BrowserPlugin>::iterator iter(&instances_); |
88 while (!iter.IsAtEnd()) { | 86 while (!iter.IsAtEnd()) { |
89 iter.GetCurrentValue()->DidCommitCompositorFrame(); | 87 iter.GetCurrentValue()->DidCommitCompositorFrame(); |
90 iter.Advance(); | 88 iter.Advance(); |
91 } | 89 } |
92 } | 90 } |
93 | 91 |
94 bool BrowserPluginManager::OnMessageReceived( | 92 bool BrowserPluginManager::OnControlMessageReceived( |
95 const IPC::Message& message) { | 93 const IPC::Message& message) { |
96 if (!BrowserPlugin::ShouldForwardToBrowserPlugin(message)) | 94 if (!BrowserPlugin::ShouldForwardToBrowserPlugin(message) && |
| 95 !content::GetContentClient()->renderer()-> |
| 96 ShouldForwardToGuestContainer(message)) { |
97 return false; | 97 return false; |
| 98 } |
98 | 99 |
99 int browser_plugin_instance_id = browser_plugin::kInstanceIDNone; | 100 int browser_plugin_instance_id = browser_plugin::kInstanceIDNone; |
100 // All allowed messages must have |browser_plugin_instance_id| as their | 101 // All allowed messages must have |browser_plugin_instance_id| as their |
101 // first parameter. | 102 // first parameter. |
102 PickleIterator iter(message); | 103 PickleIterator iter(message); |
103 bool success = iter.ReadInt(&browser_plugin_instance_id); | 104 bool success = iter.ReadInt(&browser_plugin_instance_id); |
104 DCHECK(success); | 105 DCHECK(success); |
105 BrowserPlugin* plugin = GetBrowserPlugin(browser_plugin_instance_id); | 106 BrowserPlugin* plugin = GetBrowserPlugin(browser_plugin_instance_id); |
106 if (plugin && plugin->OnMessageReceived(message)) | 107 if (plugin && plugin->OnMessageReceived(message)) |
107 return true; | 108 return true; |
108 | 109 |
109 // TODO(fsamuel): This is probably forcing the compositor to continue working | 110 // TODO(fsamuel): This is probably forcing the compositor to continue working |
110 // even on display:none. We should optimize this. | 111 // even on display:none. We should optimize this. |
111 if (message.type() == BrowserPluginMsg_CompositorFrameSwapped::ID) { | 112 if (message.type() == BrowserPluginMsg_CompositorFrameSwapped::ID) { |
112 OnCompositorFrameSwappedPluginUnavailable(message); | 113 OnCompositorFrameSwappedPluginUnavailable(message); |
113 return true; | 114 return true; |
114 } | 115 } |
115 | 116 |
116 return false; | 117 return false; |
117 } | 118 } |
118 | 119 |
119 bool BrowserPluginManager::Send(IPC::Message* msg) { | 120 bool BrowserPluginManager::Send(IPC::Message* msg) { |
120 return RenderThread::Get()->Send(msg); | 121 return RenderThreadImpl::current()->Send(msg); |
121 } | 122 } |
122 | 123 |
123 void BrowserPluginManager::OnCompositorFrameSwappedPluginUnavailable( | 124 void BrowserPluginManager::OnCompositorFrameSwappedPluginUnavailable( |
124 const IPC::Message& message) { | 125 const IPC::Message& message) { |
125 BrowserPluginMsg_CompositorFrameSwapped::Param param; | 126 BrowserPluginMsg_CompositorFrameSwapped::Param param; |
126 if (!BrowserPluginMsg_CompositorFrameSwapped::Read(&message, ¶m)) | 127 if (!BrowserPluginMsg_CompositorFrameSwapped::Read(&message, ¶m)) |
127 return; | 128 return; |
128 | 129 |
129 FrameHostMsg_CompositorFrameSwappedACK_Params params; | 130 FrameHostMsg_CompositorFrameSwappedACK_Params params; |
130 params.producing_host_id = param.b.producing_host_id; | 131 params.producing_host_id = param.b.producing_host_id; |
131 params.producing_route_id = param.b.producing_route_id; | 132 params.producing_route_id = param.b.producing_route_id; |
132 params.output_surface_id = param.b.output_surface_id; | 133 params.output_surface_id = param.b.output_surface_id; |
133 Send(new BrowserPluginHostMsg_CompositorFrameSwappedACK( | 134 Send(new BrowserPluginHostMsg_CompositorFrameSwappedACK( |
134 routing_id(), param.a, params)); | 135 message.routing_id(), param.a, params)); |
135 } | 136 } |
136 | 137 |
137 } // namespace content | 138 } // namespace content |
OLD | NEW |