| 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 16 matching lines...) Expand all Loading... |
| 27 #include "content/renderer/drop_data_builder.h" | 27 #include "content/renderer/drop_data_builder.h" |
| 28 #include "content/renderer/render_thread_impl.h" | 28 #include "content/renderer/render_thread_impl.h" |
| 29 #include "content/renderer/sad_plugin.h" | 29 #include "content/renderer/sad_plugin.h" |
| 30 #include "third_party/WebKit/public/platform/WebRect.h" | 30 #include "third_party/WebKit/public/platform/WebRect.h" |
| 31 #include "third_party/WebKit/public/web/WebDocument.h" | 31 #include "third_party/WebKit/public/web/WebDocument.h" |
| 32 #include "third_party/WebKit/public/web/WebElement.h" | 32 #include "third_party/WebKit/public/web/WebElement.h" |
| 33 #include "third_party/WebKit/public/web/WebInputEvent.h" | 33 #include "third_party/WebKit/public/web/WebInputEvent.h" |
| 34 #include "third_party/WebKit/public/web/WebLocalFrame.h" | 34 #include "third_party/WebKit/public/web/WebLocalFrame.h" |
| 35 #include "third_party/WebKit/public/web/WebPluginContainer.h" | 35 #include "third_party/WebKit/public/web/WebPluginContainer.h" |
| 36 #include "third_party/WebKit/public/web/WebView.h" | 36 #include "third_party/WebKit/public/web/WebView.h" |
| 37 #include "third_party/skia/include/core/SkCanvas.h" | |
| 38 #include "ui/events/keycodes/keyboard_codes.h" | 37 #include "ui/events/keycodes/keyboard_codes.h" |
| 39 | 38 |
| 40 using blink::WebCanvas; | |
| 41 using blink::WebPluginContainer; | 39 using blink::WebPluginContainer; |
| 42 using blink::WebPoint; | 40 using blink::WebPoint; |
| 43 using blink::WebRect; | 41 using blink::WebRect; |
| 44 using blink::WebURL; | 42 using blink::WebURL; |
| 45 using blink::WebVector; | 43 using blink::WebVector; |
| 46 | 44 |
| 47 namespace { | 45 namespace { |
| 48 using PluginContainerMap = | 46 using PluginContainerMap = |
| 49 std::map<blink::WebPluginContainer*, content::BrowserPlugin*>; | 47 std::map<blink::WebPluginContainer*, content::BrowserPlugin*>; |
| 50 static base::LazyInstance<PluginContainerMap> g_plugin_container_map = | 48 static base::LazyInstance<PluginContainerMap> g_plugin_container_map = |
| (...skipping 118 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 169 attached_ = true; | 167 attached_ = true; |
| 170 } | 168 } |
| 171 | 169 |
| 172 void BrowserPlugin::Detach() { | 170 void BrowserPlugin::Detach() { |
| 173 if (!attached()) | 171 if (!attached()) |
| 174 return; | 172 return; |
| 175 | 173 |
| 176 attached_ = false; | 174 attached_ = false; |
| 177 guest_crashed_ = false; | 175 guest_crashed_ = false; |
| 178 EnableCompositing(false); | 176 EnableCompositing(false); |
| 179 if (compositing_helper_.get()) { | |
| 180 compositing_helper_->OnContainerDestroy(); | |
| 181 compositing_helper_ = nullptr; | |
| 182 } | |
| 183 | 177 |
| 184 BrowserPluginManager::Get()->Send( | 178 BrowserPluginManager::Get()->Send( |
| 185 new BrowserPluginHostMsg_Detach(browser_plugin_instance_id_)); | 179 new BrowserPluginHostMsg_Detach(browser_plugin_instance_id_)); |
| 186 } | 180 } |
| 187 | 181 |
| 188 void BrowserPlugin::DidCommitCompositorFrame() { | 182 void BrowserPlugin::DidCommitCompositorFrame() { |
| 189 } | 183 } |
| 190 | 184 |
| 191 void BrowserPlugin::OnAdvanceFocus(int browser_plugin_instance_id, | 185 void BrowserPlugin::OnAdvanceFocus(int browser_plugin_instance_id, |
| 192 bool reverse) { | 186 bool reverse) { |
| 193 auto render_frame = RenderFrameImpl::FromRoutingID(render_frame_routing_id()); | 187 auto render_frame = RenderFrameImpl::FromRoutingID(render_frame_routing_id()); |
| 194 auto render_view = render_frame ? render_frame->GetRenderView() : nullptr; | 188 auto render_view = render_frame ? render_frame->GetRenderView() : nullptr; |
| 195 if (!render_view) | 189 if (!render_view) |
| 196 return; | 190 return; |
| 197 render_view->GetWebView()->advanceFocus(reverse); | 191 render_view->GetWebView()->advanceFocus(reverse); |
| 198 } | 192 } |
| 199 | 193 |
| 200 void BrowserPlugin::OnGuestGone(int browser_plugin_instance_id) { | 194 void BrowserPlugin::OnGuestGone(int browser_plugin_instance_id) { |
| 201 guest_crashed_ = true; | 195 guest_crashed_ = true; |
| 202 | 196 |
| 203 // Turn off compositing so we can display the sad graphic. Changes to | 197 EnableCompositing(true); |
| 204 // compositing state will show up at a later time after a layout and commit. | 198 compositing_helper_->ChildFrameGone(); |
| 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 } | 199 } |
| 215 | 200 |
| 216 void BrowserPlugin::OnSetCursor(int browser_plugin_instance_id, | 201 void BrowserPlugin::OnSetCursor(int browser_plugin_instance_id, |
| 217 const WebCursor& cursor) { | 202 const WebCursor& cursor) { |
| 218 cursor_ = cursor; | 203 cursor_ = cursor; |
| 219 } | 204 } |
| 220 | 205 |
| 221 void BrowserPlugin::OnSetMouseLock(int browser_plugin_instance_id, | 206 void BrowserPlugin::OnSetMouseLock(int browser_plugin_instance_id, |
| 222 bool enable) { | 207 bool enable) { |
| 223 auto render_frame = RenderFrameImpl::FromRoutingID(render_frame_routing_id()); | 208 auto render_frame = RenderFrameImpl::FromRoutingID(render_frame_routing_id()); |
| (...skipping 22 matching lines...) Expand all Loading... |
| 246 | 231 |
| 247 void BrowserPlugin::OnShouldAcceptTouchEvents(int browser_plugin_instance_id, | 232 void BrowserPlugin::OnShouldAcceptTouchEvents(int browser_plugin_instance_id, |
| 248 bool accept) { | 233 bool accept) { |
| 249 if (container()) { | 234 if (container()) { |
| 250 container()->requestTouchEventType( | 235 container()->requestTouchEventType( |
| 251 accept ? WebPluginContainer::TouchEventRequestTypeRaw | 236 accept ? WebPluginContainer::TouchEventRequestTypeRaw |
| 252 : WebPluginContainer::TouchEventRequestTypeNone); | 237 : WebPluginContainer::TouchEventRequestTypeNone); |
| 253 } | 238 } |
| 254 } | 239 } |
| 255 | 240 |
| 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() { | 241 void BrowserPlugin::UpdateInternalInstanceId() { |
| 264 // This is a way to notify observers of our attributes that this plugin is | 242 // This is a way to notify observers of our attributes that this plugin is |
| 265 // available in render tree. | 243 // available in render tree. |
| 266 // TODO(lazyboy): This should be done through the delegate instead. Perhaps | 244 // TODO(lazyboy): This should be done through the delegate instead. Perhaps |
| 267 // by firing an event from there. | 245 // by firing an event from there. |
| 268 UpdateDOMAttribute( | 246 UpdateDOMAttribute( |
| 269 "internalinstanceid", | 247 "internalinstanceid", |
| 270 base::UTF8ToUTF16(base::IntToString(browser_plugin_instance_id_))); | 248 base::UTF8ToUTF16(base::IntToString(browser_plugin_instance_id_))); |
| 271 } | 249 } |
| 272 | 250 |
| (...skipping 94 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 367 } | 345 } |
| 368 | 346 |
| 369 bool BrowserPlugin::supportsInputMethod() const { | 347 bool BrowserPlugin::supportsInputMethod() const { |
| 370 return true; | 348 return true; |
| 371 } | 349 } |
| 372 | 350 |
| 373 bool BrowserPlugin::canProcessDrag() const { | 351 bool BrowserPlugin::canProcessDrag() const { |
| 374 return true; | 352 return true; |
| 375 } | 353 } |
| 376 | 354 |
| 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 | 355 // static |
| 405 bool BrowserPlugin::ShouldForwardToBrowserPlugin( | 356 bool BrowserPlugin::ShouldForwardToBrowserPlugin( |
| 406 const IPC::Message& message) { | 357 const IPC::Message& message) { |
| 407 return IPC_MESSAGE_CLASS(message) == BrowserPluginMsgStart; | 358 return IPC_MESSAGE_CLASS(message) == BrowserPluginMsgStart; |
| 408 } | 359 } |
| 409 | 360 |
| 410 void BrowserPlugin::updateGeometry(const WebRect& plugin_rect_in_viewport, | 361 void BrowserPlugin::updateGeometry(const WebRect& plugin_rect_in_viewport, |
| 411 const WebRect& clip_rect, | 362 const WebRect& clip_rect, |
| 412 const WebRect& unobscured_rect, | 363 const WebRect& unobscured_rect, |
| 413 const WebVector<WebRect>& cut_outs_rects, | 364 const WebVector<WebRect>& cut_outs_rects, |
| (...skipping 207 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 621 | 572 |
| 622 bool BrowserPlugin::HandleMouseLockedInputEvent( | 573 bool BrowserPlugin::HandleMouseLockedInputEvent( |
| 623 const blink::WebMouseEvent& event) { | 574 const blink::WebMouseEvent& event) { |
| 624 BrowserPluginManager::Get()->Send( | 575 BrowserPluginManager::Get()->Send( |
| 625 new BrowserPluginHostMsg_HandleInputEvent(browser_plugin_instance_id_, | 576 new BrowserPluginHostMsg_HandleInputEvent(browser_plugin_instance_id_, |
| 626 &event)); | 577 &event)); |
| 627 return true; | 578 return true; |
| 628 } | 579 } |
| 629 | 580 |
| 630 } // namespace content | 581 } // namespace content |
| OLD | NEW |