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/pepper/pepper_plugin_instance_impl.h" | 5 #include "content/renderer/pepper/pepper_plugin_instance_impl.h" |
6 | 6 |
7 #include <utility> | 7 #include <utility> |
8 | 8 |
9 #include "base/bind.h" | 9 #include "base/bind.h" |
10 #include "base/bit_cast.h" | 10 #include "base/bit_cast.h" |
(...skipping 1102 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1113 caret.Offset(view_data_.rect.point.x, view_data_.rect.point.y); | 1113 caret.Offset(view_data_.rect.point.x, view_data_.rect.point.y); |
1114 ConvertDIPToViewport(&caret); | 1114 ConvertDIPToViewport(&caret); |
1115 return caret; | 1115 return caret; |
1116 } | 1116 } |
1117 | 1117 |
1118 bool PepperPluginInstanceImpl::HandleInputEvent( | 1118 bool PepperPluginInstanceImpl::HandleInputEvent( |
1119 const blink::WebInputEvent& event, | 1119 const blink::WebInputEvent& event, |
1120 WebCursorInfo* cursor_info) { | 1120 WebCursorInfo* cursor_info) { |
1121 TRACE_EVENT0("ppapi", "PepperPluginInstanceImpl::HandleInputEvent"); | 1121 TRACE_EVENT0("ppapi", "PepperPluginInstanceImpl::HandleInputEvent"); |
1122 | 1122 |
| 1123 if (!render_frame_) |
| 1124 return false; |
| 1125 |
1123 if (!has_been_clicked_ && is_flash_plugin_ && | 1126 if (!has_been_clicked_ && is_flash_plugin_ && |
1124 event.GetType() == blink::WebInputEvent::kMouseDown && | 1127 event.GetType() == blink::WebInputEvent::kMouseDown && |
1125 (event.GetModifiers() & blink::WebInputEvent::kLeftButtonDown)) { | 1128 (event.GetModifiers() & blink::WebInputEvent::kLeftButtonDown)) { |
1126 has_been_clicked_ = true; | 1129 has_been_clicked_ = true; |
1127 blink::WebRect bounds = container()->GetElement().BoundsInViewport(); | 1130 blink::WebRect bounds = container()->GetElement().BoundsInViewport(); |
1128 render_frame()->GetRenderWidget()->ConvertViewportToWindow(&bounds); | 1131 render_frame()->GetRenderWidget()->ConvertViewportToWindow(&bounds); |
1129 RecordFlashClickSizeMetric(bounds.width, bounds.height); | 1132 RecordFlashClickSizeMetric(bounds.width, bounds.height); |
1130 } | 1133 } |
1131 | 1134 |
1132 if (throttler_ && throttler_->ConsumeInputEvent(event)) | 1135 if (throttler_ && throttler_->ConsumeInputEvent(event)) |
1133 return true; | 1136 return true; |
1134 | 1137 |
1135 if (!render_frame_) | |
1136 return false; | |
1137 if (WebInputEvent::IsMouseEventType(event.GetType())) { | 1138 if (WebInputEvent::IsMouseEventType(event.GetType())) { |
1138 render_frame_->PepperDidReceiveMouseEvent(this); | 1139 render_frame_->PepperDidReceiveMouseEvent(this); |
1139 } | 1140 } |
1140 | 1141 |
1141 // Don't dispatch input events to crashed plugins. | 1142 // Don't dispatch input events to crashed plugins. |
1142 if (module()->is_crashed()) | 1143 if (module()->is_crashed()) |
1143 return false; | 1144 return false; |
1144 | 1145 |
1145 // Don't send reserved system key events to plugins. | 1146 // Don't send reserved system key events to plugins. |
1146 if (IsReservedSystemInputEvent(event)) | 1147 if (IsReservedSystemInputEvent(event)) |
(...skipping 108 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1255 // instance object. | 1256 // instance object. |
1256 if (LoadPrivateInterface()) | 1257 if (LoadPrivateInterface()) |
1257 return plugin_private_interface_->GetInstanceObject(pp_instance()); | 1258 return plugin_private_interface_->GetInstanceObject(pp_instance()); |
1258 return PP_MakeUndefined(); | 1259 return PP_MakeUndefined(); |
1259 } | 1260 } |
1260 | 1261 |
1261 void PepperPluginInstanceImpl::ViewChanged( | 1262 void PepperPluginInstanceImpl::ViewChanged( |
1262 const gfx::Rect& window, | 1263 const gfx::Rect& window, |
1263 const gfx::Rect& clip, | 1264 const gfx::Rect& clip, |
1264 const gfx::Rect& unobscured) { | 1265 const gfx::Rect& unobscured) { |
| 1266 if (!render_frame_) |
| 1267 return; |
| 1268 |
1265 // WebKit can give weird (x,y) positions for empty clip rects (since the | 1269 // WebKit can give weird (x,y) positions for empty clip rects (since the |
1266 // position technically doesn't matter). But we want to make these | 1270 // position technically doesn't matter). But we want to make these |
1267 // consistent since this is given to the plugin, so force everything to 0 | 1271 // consistent since this is given to the plugin, so force everything to 0 |
1268 // in the "everything is clipped" case. | 1272 // in the "everything is clipped" case. |
1269 gfx::Rect new_clip; | 1273 gfx::Rect new_clip; |
1270 if (!clip.IsEmpty()) | 1274 if (!clip.IsEmpty()) |
1271 new_clip = clip; | 1275 new_clip = clip; |
1272 | 1276 |
1273 unobscured_rect_ = unobscured; | 1277 unobscured_rect_ = unobscured; |
1274 | 1278 |
(...skipping 98 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1373 if (bound_graphics_2d_platform_) | 1377 if (bound_graphics_2d_platform_) |
1374 bound_graphics_2d_platform_->ViewInitiatedPaint(); | 1378 bound_graphics_2d_platform_->ViewInitiatedPaint(); |
1375 else if (bound_graphics_3d_.get()) | 1379 else if (bound_graphics_3d_.get()) |
1376 bound_graphics_3d_->ViewInitiatedPaint(); | 1380 bound_graphics_3d_->ViewInitiatedPaint(); |
1377 else if (bound_compositor_) | 1381 else if (bound_compositor_) |
1378 bound_compositor_->ViewInitiatedPaint(); | 1382 bound_compositor_->ViewInitiatedPaint(); |
1379 } | 1383 } |
1380 | 1384 |
1381 void PepperPluginInstanceImpl::SetSelectedText( | 1385 void PepperPluginInstanceImpl::SetSelectedText( |
1382 const base::string16& selected_text) { | 1386 const base::string16& selected_text) { |
| 1387 if (!render_frame_) |
| 1388 return; |
| 1389 |
1383 selected_text_ = selected_text; | 1390 selected_text_ = selected_text; |
1384 gfx::Range range(0, selected_text.length()); | 1391 gfx::Range range(0, selected_text.length()); |
1385 render_frame_->SetSelectedText(selected_text, 0, range); | 1392 render_frame_->SetSelectedText(selected_text, 0, range); |
1386 } | 1393 } |
1387 | 1394 |
1388 void PepperPluginInstanceImpl::SetLinkUnderCursor(const std::string& url) { | 1395 void PepperPluginInstanceImpl::SetLinkUnderCursor(const std::string& url) { |
1389 link_under_cursor_ = base::UTF8ToUTF16(url); | 1396 link_under_cursor_ = base::UTF8ToUTF16(url); |
1390 } | 1397 } |
1391 | 1398 |
1392 void PepperPluginInstanceImpl::SetTextInputType(ui::TextInputType type) { | 1399 void PepperPluginInstanceImpl::SetTextInputType(ui::TextInputType type) { |
| 1400 if (!render_frame_) |
| 1401 return; |
| 1402 |
1393 text_input_type_ = type; | 1403 text_input_type_ = type; |
1394 render_frame_->PepperTextInputTypeChanged(this); | 1404 render_frame_->PepperTextInputTypeChanged(this); |
1395 } | 1405 } |
1396 | 1406 |
1397 void PepperPluginInstanceImpl::PostMessageToJavaScript(PP_Var message) { | 1407 void PepperPluginInstanceImpl::PostMessageToJavaScript(PP_Var message) { |
1398 if (message_channel_) | 1408 if (message_channel_) |
1399 message_channel_->PostMessageToJavaScript(message); | 1409 message_channel_->PostMessageToJavaScript(message); |
1400 } | 1410 } |
1401 | 1411 |
1402 int32_t PepperPluginInstanceImpl::RegisterMessageHandler( | 1412 int32_t PepperPluginInstanceImpl::RegisterMessageHandler( |
(...skipping 275 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1678 // The bound callback that owns the weak pointer is still valid until after | 1688 // The bound callback that owns the weak pointer is still valid until after |
1679 // this function returns. SendDidChangeView checks HasWeakPtrs, so we need to | 1689 // this function returns. SendDidChangeView checks HasWeakPtrs, so we need to |
1680 // invalidate them here. | 1690 // invalidate them here. |
1681 // NOTE: If we ever want to have more than one pending callback, it should | 1691 // NOTE: If we ever want to have more than one pending callback, it should |
1682 // use a different factory, or we should have a different strategy here. | 1692 // use a different factory, or we should have a different strategy here. |
1683 view_change_weak_ptr_factory_.InvalidateWeakPtrs(); | 1693 view_change_weak_ptr_factory_.InvalidateWeakPtrs(); |
1684 SendDidChangeView(); | 1694 SendDidChangeView(); |
1685 } | 1695 } |
1686 | 1696 |
1687 void PepperPluginInstanceImpl::SendDidChangeView() { | 1697 void PepperPluginInstanceImpl::SendDidChangeView() { |
| 1698 if (!render_frame_) |
| 1699 return; |
| 1700 |
1688 // An asynchronous view update is scheduled. Skip sending this update. | 1701 // An asynchronous view update is scheduled. Skip sending this update. |
1689 if (view_change_weak_ptr_factory_.HasWeakPtrs()) | 1702 if (view_change_weak_ptr_factory_.HasWeakPtrs()) |
1690 return; | 1703 return; |
1691 | 1704 |
1692 // Don't send DidChangeView to crashed plugins. | 1705 // Don't send DidChangeView to crashed plugins. |
1693 if (module()->is_crashed()) | 1706 if (module()->is_crashed()) |
1694 return; | 1707 return; |
1695 | 1708 |
1696 if (bound_compositor_) | 1709 if (bound_compositor_) |
1697 bound_compositor_->set_viewport_to_dip_scale(viewport_to_dip_scale_); | 1710 bound_compositor_->set_viewport_to_dip_scale(viewport_to_dip_scale_); |
(...skipping 450 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2148 bool PepperPluginInstanceImpl::PrepareTextureMailbox( | 2161 bool PepperPluginInstanceImpl::PrepareTextureMailbox( |
2149 cc::TextureMailbox* mailbox, | 2162 cc::TextureMailbox* mailbox, |
2150 std::unique_ptr<cc::SingleReleaseCallback>* release_callback) { | 2163 std::unique_ptr<cc::SingleReleaseCallback>* release_callback) { |
2151 if (!bound_graphics_2d_platform_) | 2164 if (!bound_graphics_2d_platform_) |
2152 return false; | 2165 return false; |
2153 return bound_graphics_2d_platform_->PrepareTextureMailbox(mailbox, | 2166 return bound_graphics_2d_platform_->PrepareTextureMailbox(mailbox, |
2154 release_callback); | 2167 release_callback); |
2155 } | 2168 } |
2156 | 2169 |
2157 void PepperPluginInstanceImpl::AccessibilityModeChanged() { | 2170 void PepperPluginInstanceImpl::AccessibilityModeChanged() { |
2158 if (render_frame_->render_accessibility() && LoadPdfInterface()) | 2171 if (render_frame_ && render_frame_->render_accessibility() && |
| 2172 LoadPdfInterface()) { |
2159 plugin_pdf_interface_->EnableAccessibility(pp_instance()); | 2173 plugin_pdf_interface_->EnableAccessibility(pp_instance()); |
| 2174 } |
2160 } | 2175 } |
2161 | 2176 |
2162 void PepperPluginInstanceImpl::OnDestruct() { | 2177 void PepperPluginInstanceImpl::OnDestruct() { |
2163 render_frame_ = nullptr; | 2178 render_frame_ = nullptr; |
2164 } | 2179 } |
2165 | 2180 |
2166 void PepperPluginInstanceImpl::OnThrottleStateChange() { | 2181 void PepperPluginInstanceImpl::OnThrottleStateChange() { |
| 2182 if (!render_frame_) |
| 2183 return; |
| 2184 |
2167 SendDidChangeView(); | 2185 SendDidChangeView(); |
2168 | 2186 |
2169 bool is_throttled = throttler_->IsThrottled(); | 2187 bool is_throttled = throttler_->IsThrottled(); |
2170 render_frame()->Send(new FrameHostMsg_PluginInstanceThrottleStateChange( | 2188 render_frame()->Send(new FrameHostMsg_PluginInstanceThrottleStateChange( |
2171 module_->GetPluginChildId(), pp_instance_, is_throttled)); | 2189 module_->GetPluginChildId(), pp_instance_, is_throttled)); |
2172 } | 2190 } |
2173 | 2191 |
2174 void PepperPluginInstanceImpl::OnHiddenForPlaceholder(bool hidden) { | 2192 void PepperPluginInstanceImpl::OnHiddenForPlaceholder(bool hidden) { |
2175 UpdateLayer(false /* device_changed */); | 2193 UpdateLayer(false /* device_changed */); |
2176 } | 2194 } |
(...skipping 1276 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
3453 const cc::TextureMailbox& mailbox) const { | 3471 const cc::TextureMailbox& mailbox) const { |
3454 auto it = | 3472 auto it = |
3455 std::find_if(texture_ref_counts_.begin(), texture_ref_counts_.end(), | 3473 std::find_if(texture_ref_counts_.begin(), texture_ref_counts_.end(), |
3456 [&mailbox](const TextureMailboxRefCount& ref_count) { | 3474 [&mailbox](const TextureMailboxRefCount& ref_count) { |
3457 return ref_count.first.mailbox() == mailbox.mailbox(); | 3475 return ref_count.first.mailbox() == mailbox.mailbox(); |
3458 }); | 3476 }); |
3459 return it != texture_ref_counts_.end(); | 3477 return it != texture_ref_counts_.end(); |
3460 } | 3478 } |
3461 | 3479 |
3462 } // namespace content | 3480 } // namespace content |
OLD | NEW |