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

Side by Side Diff: content/renderer/browser_plugin/browser_plugin_manager.cc

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

Powered by Google App Engine
This is Rietveld 408576698