Chromium Code Reviews| OLD | NEW |
|---|---|
| 1 // Copyright 2012 The Chromium Authors. All rights reserved. | 1 // Copyright 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.h" | 5 #include "content/renderer/browser_plugin/browser_plugin.h" |
| 6 | 6 |
| 7 #include <stddef.h> | 7 #include <stddef.h> |
| 8 #include <utility> | 8 #include <utility> |
| 9 | 9 |
| 10 #include "base/command_line.h" | 10 #include "base/command_line.h" |
| (...skipping 158 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 169 attached_ = true; | 169 attached_ = true; |
| 170 } | 170 } |
| 171 | 171 |
| 172 void BrowserPlugin::Detach() { | 172 void BrowserPlugin::Detach() { |
| 173 if (!attached()) | 173 if (!attached()) |
| 174 return; | 174 return; |
| 175 | 175 |
| 176 attached_ = false; | 176 attached_ = false; |
| 177 guest_crashed_ = false; | 177 guest_crashed_ = false; |
| 178 EnableCompositing(false); | 178 EnableCompositing(false); |
| 179 if (compositing_helper_.get()) { | 179 if (compositing_helper_.get()) { |
|
Fady Samuel
2016/03/10 19:54:07
nit: Is this block necessary?
lfg
2016/03/10 19:57:40
No. Removed.
| |
| 180 compositing_helper_->OnContainerDestroy(); | 180 compositing_helper_->OnContainerDestroy(); |
| 181 compositing_helper_ = nullptr; | 181 compositing_helper_ = nullptr; |
| 182 } | 182 } |
| 183 | 183 |
| 184 BrowserPluginManager::Get()->Send( | 184 BrowserPluginManager::Get()->Send( |
| 185 new BrowserPluginHostMsg_Detach(browser_plugin_instance_id_)); | 185 new BrowserPluginHostMsg_Detach(browser_plugin_instance_id_)); |
| 186 } | 186 } |
| 187 | 187 |
| 188 void BrowserPlugin::DidCommitCompositorFrame() { | 188 void BrowserPlugin::DidCommitCompositorFrame() { |
| 189 } | 189 } |
| 190 | 190 |
| 191 void BrowserPlugin::OnAdvanceFocus(int browser_plugin_instance_id, | 191 void BrowserPlugin::OnAdvanceFocus(int browser_plugin_instance_id, |
| 192 bool reverse) { | 192 bool reverse) { |
| 193 auto render_frame = RenderFrameImpl::FromRoutingID(render_frame_routing_id()); | 193 auto render_frame = RenderFrameImpl::FromRoutingID(render_frame_routing_id()); |
| 194 auto render_view = render_frame ? render_frame->GetRenderView() : nullptr; | 194 auto render_view = render_frame ? render_frame->GetRenderView() : nullptr; |
| 195 if (!render_view) | 195 if (!render_view) |
| 196 return; | 196 return; |
| 197 render_view->GetWebView()->advanceFocus(reverse); | 197 render_view->GetWebView()->advanceFocus(reverse); |
| 198 } | 198 } |
| 199 | 199 |
| 200 void BrowserPlugin::OnGuestGone(int browser_plugin_instance_id) { | 200 void BrowserPlugin::OnGuestGone(int browser_plugin_instance_id) { |
| 201 guest_crashed_ = true; | 201 guest_crashed_ = true; |
| 202 | 202 |
| 203 // Turn off compositing so we can display the sad graphic. Changes to | 203 compositing_helper_->ChildFrameGone(); |
| 204 // compositing state will show up at a later time after a layout and commit. | |
| 205 EnableCompositing(false); | |
| 206 | |
| 207 // Queue up showing the sad graphic to give content embedders an opportunity | |
| 208 // to fire their listeners and potentially overlay the webview with custom | |
| 209 // behavior. If the BrowserPlugin is destroyed in the meantime, then the | |
| 210 // task will not be executed. | |
| 211 base::ThreadTaskRunnerHandle::Get()->PostTask( | |
| 212 FROM_HERE, base::Bind(&BrowserPlugin::ShowSadGraphic, | |
| 213 weak_ptr_factory_.GetWeakPtr())); | |
| 214 } | 204 } |
| 215 | 205 |
| 216 void BrowserPlugin::OnSetCursor(int browser_plugin_instance_id, | 206 void BrowserPlugin::OnSetCursor(int browser_plugin_instance_id, |
| 217 const WebCursor& cursor) { | 207 const WebCursor& cursor) { |
| 218 cursor_ = cursor; | 208 cursor_ = cursor; |
| 219 } | 209 } |
| 220 | 210 |
| 221 void BrowserPlugin::OnSetMouseLock(int browser_plugin_instance_id, | 211 void BrowserPlugin::OnSetMouseLock(int browser_plugin_instance_id, |
| 222 bool enable) { | 212 bool enable) { |
| 223 auto render_frame = RenderFrameImpl::FromRoutingID(render_frame_routing_id()); | 213 auto render_frame = RenderFrameImpl::FromRoutingID(render_frame_routing_id()); |
| (...skipping 22 matching lines...) Expand all Loading... | |
| 246 | 236 |
| 247 void BrowserPlugin::OnShouldAcceptTouchEvents(int browser_plugin_instance_id, | 237 void BrowserPlugin::OnShouldAcceptTouchEvents(int browser_plugin_instance_id, |
| 248 bool accept) { | 238 bool accept) { |
| 249 if (container()) { | 239 if (container()) { |
| 250 container()->requestTouchEventType( | 240 container()->requestTouchEventType( |
| 251 accept ? WebPluginContainer::TouchEventRequestTypeRaw | 241 accept ? WebPluginContainer::TouchEventRequestTypeRaw |
| 252 : WebPluginContainer::TouchEventRequestTypeNone); | 242 : WebPluginContainer::TouchEventRequestTypeNone); |
| 253 } | 243 } |
| 254 } | 244 } |
| 255 | 245 |
| 256 void BrowserPlugin::ShowSadGraphic() { | |
| 257 // If the BrowserPlugin is scheduled to be deleted, then container_ will be | |
| 258 // nullptr so we shouldn't attempt to access it. | |
| 259 if (container_) | |
| 260 container_->invalidate(); | |
| 261 } | |
| 262 | |
| 263 void BrowserPlugin::UpdateInternalInstanceId() { | 246 void BrowserPlugin::UpdateInternalInstanceId() { |
| 264 // This is a way to notify observers of our attributes that this plugin is | 247 // This is a way to notify observers of our attributes that this plugin is |
| 265 // available in render tree. | 248 // available in render tree. |
| 266 // TODO(lazyboy): This should be done through the delegate instead. Perhaps | 249 // TODO(lazyboy): This should be done through the delegate instead. Perhaps |
| 267 // by firing an event from there. | 250 // by firing an event from there. |
| 268 UpdateDOMAttribute( | 251 UpdateDOMAttribute( |
| 269 "internalinstanceid", | 252 "internalinstanceid", |
| 270 base::UTF8ToUTF16(base::IntToString(browser_plugin_instance_id_))); | 253 base::UTF8ToUTF16(base::IntToString(browser_plugin_instance_id_))); |
| 271 } | 254 } |
| 272 | 255 |
| (...skipping 94 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 367 } | 350 } |
| 368 | 351 |
| 369 bool BrowserPlugin::supportsInputMethod() const { | 352 bool BrowserPlugin::supportsInputMethod() const { |
| 370 return true; | 353 return true; |
| 371 } | 354 } |
| 372 | 355 |
| 373 bool BrowserPlugin::canProcessDrag() const { | 356 bool BrowserPlugin::canProcessDrag() const { |
| 374 return true; | 357 return true; |
| 375 } | 358 } |
| 376 | 359 |
| 377 void BrowserPlugin::paint(WebCanvas* canvas, const WebRect& rect) { | |
| 378 if (guest_crashed_) { | |
| 379 if (!sad_guest_) // Lazily initialize bitmap. | |
| 380 sad_guest_ = GetContentClient()->renderer()->GetSadWebViewBitmap(); | |
| 381 // content_shell does not have the sad plugin bitmap, so we'll paint black | |
| 382 // instead to make it clear that something went wrong. | |
| 383 if (sad_guest_) { | |
| 384 PaintSadPlugin(canvas, view_rect_, *sad_guest_); | |
| 385 return; | |
| 386 } | |
| 387 } | |
| 388 SkAutoCanvasRestore auto_restore(canvas, true); | |
| 389 canvas->translate(view_rect_.x(), view_rect_.y()); | |
| 390 SkRect image_data_rect = SkRect::MakeXYWH( | |
| 391 SkIntToScalar(0), | |
| 392 SkIntToScalar(0), | |
| 393 SkIntToScalar(view_rect_.width()), | |
| 394 SkIntToScalar(view_rect_.height())); | |
| 395 canvas->clipRect(image_data_rect); | |
| 396 // Paint black or white in case we have nothing in our backing store or we | |
| 397 // need to show a gutter. | |
| 398 SkPaint paint; | |
| 399 paint.setStyle(SkPaint::kFill_Style); | |
| 400 paint.setColor(guest_crashed_ ? SK_ColorBLACK : SK_ColorWHITE); | |
| 401 canvas->drawRect(image_data_rect, paint); | |
| 402 } | |
| 403 | |
| 404 // static | 360 // static |
| 405 bool BrowserPlugin::ShouldForwardToBrowserPlugin( | 361 bool BrowserPlugin::ShouldForwardToBrowserPlugin( |
| 406 const IPC::Message& message) { | 362 const IPC::Message& message) { |
| 407 return IPC_MESSAGE_CLASS(message) == BrowserPluginMsgStart; | 363 return IPC_MESSAGE_CLASS(message) == BrowserPluginMsgStart; |
| 408 } | 364 } |
| 409 | 365 |
| 410 void BrowserPlugin::updateGeometry(const WebRect& plugin_rect_in_viewport, | 366 void BrowserPlugin::updateGeometry(const WebRect& plugin_rect_in_viewport, |
| 411 const WebRect& clip_rect, | 367 const WebRect& clip_rect, |
| 412 const WebRect& unobscured_rect, | 368 const WebRect& unobscured_rect, |
| 413 const WebVector<WebRect>& cut_outs_rects, | 369 const WebVector<WebRect>& cut_outs_rects, |
| (...skipping 206 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 620 | 576 |
| 621 bool BrowserPlugin::HandleMouseLockedInputEvent( | 577 bool BrowserPlugin::HandleMouseLockedInputEvent( |
| 622 const blink::WebMouseEvent& event) { | 578 const blink::WebMouseEvent& event) { |
| 623 BrowserPluginManager::Get()->Send( | 579 BrowserPluginManager::Get()->Send( |
| 624 new BrowserPluginHostMsg_HandleInputEvent(browser_plugin_instance_id_, | 580 new BrowserPluginHostMsg_HandleInputEvent(browser_plugin_instance_id_, |
| 625 &event)); | 581 &event)); |
| 626 return true; | 582 return true; |
| 627 } | 583 } |
| 628 | 584 |
| 629 } // namespace content | 585 } // namespace content |
| OLD | NEW |