OLD | NEW |
---|---|
(Empty) | |
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 | |
3 // found in the LICENSE file. | |
4 | |
5 #include "content/browser/browser_plugin/browser_plugin_guest.h" | |
6 | |
7 #include "base/time.h" | |
8 #include "content/browser/browser_plugin/browser_plugin_guest_helper.h" | |
9 #include "content/browser/renderer_host/render_view_host_impl.h" | |
10 #include "content/browser/renderer_host/render_widget_host_impl.h" | |
11 #include "content/browser/web_contents/web_contents_impl.h" | |
12 #include "content/common/browser_plugin_messages.h" | |
13 #include "content/common/view_messages.h" | |
14 #include "content/public/browser/render_process_host.h" | |
15 #include "content/public/browser/render_view_host.h" | |
16 #include "content/public/browser/render_widget_host_view.h" | |
17 #include "content/public/browser/notification_details.h" | |
18 #include "content/public/browser/notification_service.h" | |
19 #include "content/public/browser/notification_source.h" | |
20 #include "content/public/browser/notification_types.h" | |
21 #include "content/public/browser/web_contents_observer.h" | |
22 #include "content/public/common/result_codes.h" | |
23 #include "ui/gfx/size.h" | |
24 | |
25 namespace content { | |
26 | |
27 namespace { | |
28 const int kGuestHangTimeout = 5000; | |
29 } | |
30 | |
31 BrowserPluginGuest::BrowserPluginGuest(int instance_id, | |
32 WebContentsImpl* web_contents, | |
33 RenderViewHost* render_view_host) | |
34 : WebContentsObserver(web_contents), | |
35 embedder_render_process_host_(NULL), | |
36 instance_id_(instance_id), | |
37 damage_buffer_(NULL), | |
38 pending_update_counter_(0) { | |
39 new BrowserPluginGuestHelper(this, render_view_host); | |
Fady Samuel
2012/08/25 05:28:32
The lifetime of the helper is not equal to the lif
lazyboy
2012/08/25 05:57:09
Ah, that's why it was like that, I see.
Now the pr
lazyboy
2012/08/27 15:42:51
So my assumption was:
embedder loads guest a.com,
Charlie Reis
2012/08/27 20:23:59
As I mentioned separately, we don't yet do any cro
lazyboy
2012/08/28 19:07:14
When we switch to new RVH (for embedder case), wou
Charlie Reis
2012/08/29 00:11:04
Sounds like you're talking about the embedder here
| |
40 } | |
41 | |
42 BrowserPluginGuest::~BrowserPluginGuest() { | |
43 if (damage_buffer_) | |
44 delete damage_buffer_; | |
45 } | |
46 | |
47 bool BrowserPluginGuest::TakeFocus(bool reverse) { | |
48 embedder_render_process_host()->Send( | |
49 new BrowserPluginMsg_AdvanceFocus(instance_id(), reverse)); | |
50 return true; | |
51 } | |
52 | |
53 void BrowserPluginGuest::RendererUnresponsive(WebContents* source) { | |
54 base::ProcessHandle process_handle = | |
55 web_contents()->GetRenderProcessHost()->GetHandle(); | |
56 base::KillProcess(process_handle, RESULT_CODE_HUNG, false); | |
Charlie Reis
2012/08/27 20:23:59
I don't think we've resolved this yet. I understa
lazyboy
2012/08/28 19:07:14
I talked to rjkroege@ abt this, it seems:
a. would
| |
57 } | |
58 | |
59 void BrowserPluginGuest::SetDamageBuffer( | |
60 TransportDIB* damage_buffer, const gfx::Size& size, float scale_factor) { | |
61 if (damage_buffer_) | |
62 delete damage_buffer_; | |
63 damage_buffer_ = damage_buffer; | |
64 damage_buffer_size_ = size; | |
65 damage_buffer_scale_factor_ = scale_factor; | |
66 } | |
67 | |
68 void BrowserPluginGuest::UpdateRect( | |
69 RenderViewHost* render_view_host, | |
70 const ViewHostMsg_UpdateRect_Params& params) { | |
71 // This handler is only of interest to us for the 2D software rendering path. | |
72 // needs_ack should always be true for the 2D path. | |
73 // TODO(fsamuel): Do we need to do something different in the 3D case? | |
74 if (!params.needs_ack) | |
75 return; | |
76 | |
77 // Only copy damage if the guest's view size is equal to the damage buffer's | |
78 // size and the guest's scale factor is equal to the damage buffer's scale | |
79 // factor. | |
80 if (params.view_size.width() == damage_buffer_size().width() && | |
81 params.view_size.height() == damage_buffer_size().height() && | |
82 params.scale_factor == damage_buffer_scale_factor()) { | |
83 TransportDIB* dib = render_view_host->GetProcess()-> | |
84 GetTransportDIB(params.bitmap); | |
85 if (dib) { | |
86 void* guest_memory = dib->memory(); | |
87 void* embedder_memory = damage_buffer_->memory(); | |
88 int size = std::min(dib->size(), damage_buffer_->size()); | |
89 memcpy(embedder_memory, guest_memory, size); | |
90 } | |
91 } | |
92 DCHECK(embedder_render_process_host()); | |
93 BrowserPluginMsg_UpdateRect_Params relay_params; | |
94 relay_params.bitmap_rect = params.bitmap_rect; | |
95 relay_params.dx = params.dx; | |
96 relay_params.dy = params.dy; | |
97 relay_params.scroll_rect = params.scroll_rect; | |
98 relay_params.copy_rects = params.copy_rects; | |
99 relay_params.view_size = params.view_size; | |
100 relay_params.scale_factor = params.scale_factor; | |
101 relay_params.is_resize_ack = ViewHostMsg_UpdateRect_Flags::is_resize_ack( | |
102 params.flags); | |
103 | |
104 // We need to send the ACK to the same render_view_host that issued | |
105 // the UpdateRect. We keep track of this correspondence via a message_id. | |
106 int message_id = pending_update_counter_++; | |
107 pending_updates_.AddWithID(render_view_host, message_id); | |
108 | |
109 gfx::Size param_size = gfx::Size(params.view_size.width(), | |
110 params.view_size.height()); | |
111 content::NotificationService::current()->Notify( | |
112 // TODO(lazyboy): Rename notification variable if this stays. | |
113 NOTIFICATION_BROWSER_PLUGIN_UPDATE_RECT, | |
114 content::Source<BrowserPluginGuest>(this), | |
115 content::Details<const gfx::Size>(¶m_size)); | |
116 | |
117 embedder_render_process_host()->Send( | |
118 new BrowserPluginMsg_UpdateRect(instance_id(), | |
119 message_id, | |
120 relay_params)); | |
121 } | |
122 | |
123 void BrowserPluginGuest::UpdateRectACK(int message_id, const gfx::Size& size) { | |
124 RenderViewHost* render_view_host = pending_updates_.Lookup(message_id); | |
125 // If the guest has crashed since it sent the initial ViewHostMsg_UpdateRect | |
126 // then the pending_updates_ map will have been cleared. | |
127 if (!render_view_host) | |
128 return; | |
129 pending_updates_.Remove(message_id); | |
130 render_view_host->Send( | |
131 new ViewMsg_UpdateRect_ACK(render_view_host->GetRoutingID())); | |
132 if (!size.IsEmpty()) | |
133 render_view_host->GetView()->SetSize(size); | |
134 } | |
135 | |
136 void BrowserPluginGuest::HandleInputEvent(RenderViewHost* render_view_host, | |
137 const gfx::Rect& guest_rect, | |
138 const WebKit::WebInputEvent& event, | |
139 IPC::Message* reply_message) { | |
140 guest_rect_ = guest_rect; | |
141 RenderViewHostImpl* guest_rvh = static_cast<RenderViewHostImpl*>( | |
142 web_contents()->GetRenderViewHost()); | |
143 IPC::Message* message = new ViewMsg_HandleInputEvent( | |
144 guest_rvh->GetRoutingID()); | |
145 | |
146 // Copy the WebInputEvent and modify the event type. The guest expects | |
147 // WebInputEvent::RawKeyDowns and not KeyDowns. | |
148 scoped_array<char> input_buffer(new char[event.size]); | |
149 memcpy(input_buffer.get(), &event, event.size); | |
150 WebKit::WebInputEvent* input_event = | |
151 reinterpret_cast<WebKit::WebInputEvent*>(input_buffer.get()); | |
152 if (event.type == WebKit::WebInputEvent::KeyDown) | |
153 input_event->type = WebKit::WebInputEvent::RawKeyDown; | |
154 | |
155 message->WriteData(input_buffer.get(), event.size); | |
156 // TODO(fsamuel): What do we need to do here? This is for keyboard shortcuts. | |
157 if (input_event->type == WebKit::WebInputEvent::RawKeyDown) | |
158 message->WriteBool(false); | |
159 guest_rvh->Send(message); | |
160 | |
161 DCHECK(!pending_input_event_reply_.get()); | |
162 pending_input_event_reply_.reset(reply_message); | |
163 guest_rvh->StartHangMonitorTimeout( | |
164 base::TimeDelta::FromMilliseconds(kGuestHangTimeout)); | |
165 } | |
166 | |
167 void BrowserPluginGuest::HandleInputEventAck(RenderViewHost* render_view_host, | |
168 bool handled) { | |
169 DCHECK(pending_input_event_reply_.get()); | |
170 IPC::Message* reply_message = pending_input_event_reply_.release(); | |
171 BrowserPluginHostMsg_HandleInputEvent::WriteReplyParams(reply_message, | |
172 handled, | |
173 cursor_); | |
174 embedder_render_process_host()->Send(reply_message); | |
175 RenderViewHostImpl* guest_rvh = | |
176 static_cast<RenderViewHostImpl*>(render_view_host); | |
177 guest_rvh->StopHangMonitorTimeout(); | |
178 } | |
179 | |
180 void BrowserPluginGuest::SetFocus(bool focused) { | |
181 RenderViewHost* render_view_host = web_contents()->GetRenderViewHost(); | |
182 render_view_host->Send( | |
183 new ViewMsg_SetFocus(render_view_host->GetRoutingID(), focused)); | |
184 } | |
185 | |
186 void BrowserPluginGuest::ShowWidget(RenderViewHost* render_view_host, | |
187 int route_id, | |
188 const gfx::Rect& initial_pos) { | |
189 gfx::Rect screen_pos(initial_pos); | |
190 screen_pos.Offset(guest_rect_.origin()); | |
191 static_cast<WebContentsImpl*>(web_contents())->ShowCreatedWidget(route_id, | |
192 screen_pos); | |
193 } | |
194 | |
195 void BrowserPluginGuest::SetCursor(const WebCursor& cursor) { | |
196 cursor_ = cursor; | |
197 } | |
198 | |
199 void BrowserPluginGuest::Destroy() { | |
200 WebContents* guest_web_contents = web_contents(); | |
201 DCHECK(guest_web_contents); | |
202 delete guest_web_contents; | |
203 } | |
204 | |
205 void BrowserPluginGuest::DidCommitProvisionalLoadForFrame( | |
206 int64 frame_id, | |
207 bool is_main_frame, | |
208 const GURL& url, | |
209 PageTransition transition_type, | |
210 RenderViewHost* render_view_host) { | |
211 // Inform its embedder of the updated URL. | |
212 // TODO(creis, fsamuel): Ensure this is safe/secure. | |
Charlie Reis
2012/08/27 20:23:59
What is this referring to?
lazyboy
2012/08/28 19:07:14
I have no context on this one, it's from Fady's CL
Fady Samuel
2012/08/29 08:16:20
At some point Charlie expressed a concern that pas
Charlie Reis
2012/08/29 18:08:12
I can't find the context for this. Now that we as
lazyboy
2012/08/29 21:24:44
Removed.
| |
213 DCHECK(embedder_render_process_host()); | |
214 if (is_main_frame) { | |
215 embedder_render_process_host()->Send( | |
216 new BrowserPluginMsg_DidNavigate(instance_id(), url)); | |
217 } | |
218 } | |
219 | |
220 void BrowserPluginGuest::RenderViewGone( | |
221 base::TerminationStatus status) { | |
222 DCHECK(embedder_render_process_host()); | |
223 if (pending_input_event_reply_.get()) { | |
224 IPC::Message* reply_message = pending_input_event_reply_.release(); | |
225 BrowserPluginHostMsg_HandleInputEvent::WriteReplyParams(reply_message, | |
226 false, | |
227 cursor_); | |
228 embedder_render_process_host()->Send(reply_message); | |
229 } | |
230 embedder_render_process_host()->Send( | |
231 new BrowserPluginMsg_GuestCrashed(instance_id())); | |
232 IDMap<RenderViewHost>::const_iterator iter(&pending_updates_); | |
233 while (!iter.IsAtEnd()) { | |
234 pending_updates_.Remove(iter.GetCurrentKey()); | |
235 iter.Advance(); | |
236 } | |
237 content::NotificationService::current()->Notify( | |
238 // TODO(lazyboy): Rename notification variable if this stays. | |
Charlie Reis
2012/08/27 20:23:59
nit: Wrong indent.
lazyboy
2012/08/28 19:07:14
Done.
| |
239 NOTIFICATION_BROWSER_PLUGIN_GUEST_CRASHED, | |
240 content::Source<BrowserPluginGuest>(this), | |
241 content::NotificationService::NoDetails()); | |
242 } | |
243 | |
244 } // namespace content | |
OLD | NEW |