| OLD | NEW |
| 1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2011 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/browser/renderer_host/render_widget_host.h" | 5 #include "content/browser/renderer_host/render_widget_host.h" |
| 6 | 6 |
| 7 #include "base/auto_reset.h" | 7 #include "base/auto_reset.h" |
| 8 #include "base/bind.h" | 8 #include "base/bind.h" |
| 9 #include "base/command_line.h" | 9 #include "base/command_line.h" |
| 10 #include "base/debug/trace_event.h" | 10 #include "base/debug/trace_event.h" |
| 11 #include "base/i18n/rtl.h" | 11 #include "base/i18n/rtl.h" |
| 12 #include "base/message_loop.h" | 12 #include "base/message_loop.h" |
| 13 #include "base/metrics/histogram.h" | 13 #include "base/metrics/histogram.h" |
| 14 #include "base/string_number_conversions.h" | 14 #include "base/string_number_conversions.h" |
| 15 #include "base/utf_string_conversions.h" | 15 #include "base/utf_string_conversions.h" |
| 16 #include "content/browser/accessibility/browser_accessibility_state.h" | 16 #include "content/browser/accessibility/browser_accessibility_state.h" |
| 17 #include "content/browser/gpu/gpu_process_host.h" | 17 #include "content/browser/gpu/gpu_process_host.h" |
| 18 #include "content/browser/gpu/gpu_process_host_ui_shim.h" | 18 #include "content/browser/gpu/gpu_process_host_ui_shim.h" |
| 19 #include "content/browser/renderer_host/backing_store.h" | 19 #include "content/browser/renderer_host/backing_store.h" |
| 20 #include "content/browser/renderer_host/backing_store_manager.h" | 20 #include "content/browser/renderer_host/backing_store_manager.h" |
| 21 #include "content/browser/renderer_host/render_process_host_impl.h" | 21 #include "content/browser/renderer_host/render_process_host_impl.h" |
| 22 #include "content/browser/renderer_host/render_widget_helper.h" | 22 #include "content/browser/renderer_host/render_widget_helper.h" |
| 23 #include "content/browser/renderer_host/render_widget_host_view.h" | 23 #include "content/browser/renderer_host/render_widget_host_view.h" |
| 24 #include "content/browser/user_metrics.h" | |
| 25 #include "content/common/gpu/gpu_messages.h" | 24 #include "content/common/gpu/gpu_messages.h" |
| 26 #include "content/public/browser/notification_service.h" | |
| 27 #include "content/common/view_messages.h" | 25 #include "content/common/view_messages.h" |
| 28 #include "content/public/browser/native_web_keyboard_event.h" | 26 #include "content/public/browser/native_web_keyboard_event.h" |
| 27 #include "content/public/browser/notification_service.h" |
| 29 #include "content/public/browser/notification_types.h" | 28 #include "content/public/browser/notification_types.h" |
| 29 #include "content/public/browser/user_metrics.h" |
| 30 #include "content/public/common/content_switches.h" | 30 #include "content/public/common/content_switches.h" |
| 31 #include "content/public/common/result_codes.h" | 31 #include "content/public/common/result_codes.h" |
| 32 #include "third_party/WebKit/Source/WebKit/chromium/public/WebCompositionUnderli
ne.h" | 32 #include "third_party/WebKit/Source/WebKit/chromium/public/WebCompositionUnderli
ne.h" |
| 33 #include "ui/base/keycodes/keyboard_codes.h" | 33 #include "ui/base/keycodes/keyboard_codes.h" |
| 34 #include "webkit/glue/webcursor.h" | 34 #include "webkit/glue/webcursor.h" |
| 35 #include "webkit/glue/webpreferences.h" | 35 #include "webkit/glue/webpreferences.h" |
| 36 #include "webkit/plugins/npapi/webplugin.h" | 36 #include "webkit/plugins/npapi/webplugin.h" |
| 37 | 37 |
| 38 using base::Time; | 38 using base::Time; |
| 39 using base::TimeDelta; | 39 using base::TimeDelta; |
| 40 using base::TimeTicks; | 40 using base::TimeTicks; |
| 41 | 41 using content::UserMetricsAction; |
| 42 using WebKit::WebGestureEvent; | 42 using WebKit::WebGestureEvent; |
| 43 using WebKit::WebInputEvent; | 43 using WebKit::WebInputEvent; |
| 44 using WebKit::WebKeyboardEvent; | 44 using WebKit::WebKeyboardEvent; |
| 45 using WebKit::WebMouseEvent; | 45 using WebKit::WebMouseEvent; |
| 46 using WebKit::WebMouseWheelEvent; | 46 using WebKit::WebMouseWheelEvent; |
| 47 using WebKit::WebTextDirection; | 47 using WebKit::WebTextDirection; |
| 48 | 48 |
| 49 // How long to (synchronously) wait for the renderer to respond with a | 49 // How long to (synchronously) wait for the renderer to respond with a |
| 50 // PaintRect message, when our backing-store is invalid, before giving up and | 50 // PaintRect message, when our backing-store is invalid, before giving up and |
| 51 // returning a null or incorrectly sized backing-store from GetBackingStore. | 51 // returning a null or incorrectly sized backing-store from GetBackingStore. |
| (...skipping 186 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 238 IPC_MESSAGE_HANDLER(ViewHostMsg_CreatePluginContainer, | 238 IPC_MESSAGE_HANDLER(ViewHostMsg_CreatePluginContainer, |
| 239 OnMsgCreatePluginContainer) | 239 OnMsgCreatePluginContainer) |
| 240 IPC_MESSAGE_HANDLER(ViewHostMsg_DestroyPluginContainer, | 240 IPC_MESSAGE_HANDLER(ViewHostMsg_DestroyPluginContainer, |
| 241 OnMsgDestroyPluginContainer) | 241 OnMsgDestroyPluginContainer) |
| 242 #endif | 242 #endif |
| 243 IPC_MESSAGE_UNHANDLED(handled = false) | 243 IPC_MESSAGE_UNHANDLED(handled = false) |
| 244 IPC_END_MESSAGE_MAP_EX() | 244 IPC_END_MESSAGE_MAP_EX() |
| 245 | 245 |
| 246 if (!msg_is_ok) { | 246 if (!msg_is_ok) { |
| 247 // The message de-serialization failed. Kill the renderer process. | 247 // The message de-serialization failed. Kill the renderer process. |
| 248 UserMetrics::RecordAction(UserMetricsAction("BadMessageTerminate_RWH")); | 248 content::RecordAction(UserMetricsAction("BadMessageTerminate_RWH")); |
| 249 process()->ReceivedBadMessage(); | 249 process()->ReceivedBadMessage(); |
| 250 } | 250 } |
| 251 return handled; | 251 return handled; |
| 252 } | 252 } |
| 253 | 253 |
| 254 bool RenderWidgetHost::Send(IPC::Message* msg) { | 254 bool RenderWidgetHost::Send(IPC::Message* msg) { |
| 255 return process_->Send(msg); | 255 return process_->Send(msg); |
| 256 } | 256 } |
| 257 | 257 |
| 258 void RenderWidgetHost::WasHidden() { | 258 void RenderWidgetHost::WasHidden() { |
| (...skipping 766 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1025 DCHECK(!params.bitmap_rect.IsEmpty()); | 1025 DCHECK(!params.bitmap_rect.IsEmpty()); |
| 1026 const size_t size = params.bitmap_rect.height() * | 1026 const size_t size = params.bitmap_rect.height() * |
| 1027 params.bitmap_rect.width() * 4; | 1027 params.bitmap_rect.width() * 4; |
| 1028 TransportDIB* dib = process_->GetTransportDIB(params.bitmap); | 1028 TransportDIB* dib = process_->GetTransportDIB(params.bitmap); |
| 1029 | 1029 |
| 1030 // If gpu process does painting, scroll_rect and copy_rects are always empty | 1030 // If gpu process does painting, scroll_rect and copy_rects are always empty |
| 1031 // and backing store is never used. | 1031 // and backing store is never used. |
| 1032 if (dib) { | 1032 if (dib) { |
| 1033 if (dib->size() < size) { | 1033 if (dib->size() < size) { |
| 1034 DLOG(WARNING) << "Transport DIB too small for given rectangle"; | 1034 DLOG(WARNING) << "Transport DIB too small for given rectangle"; |
| 1035 UserMetrics::RecordAction( | 1035 content::RecordAction( |
| 1036 UserMetricsAction("BadMessageTerminate_RWH1")); | 1036 UserMetricsAction("BadMessageTerminate_RWH1")); |
| 1037 process()->ReceivedBadMessage(); | 1037 process()->ReceivedBadMessage(); |
| 1038 } else { | 1038 } else { |
| 1039 // Scroll the backing store. | 1039 // Scroll the backing store. |
| 1040 if (!params.scroll_rect.IsEmpty()) { | 1040 if (!params.scroll_rect.IsEmpty()) { |
| 1041 ScrollBackingStoreRect(params.dx, params.dy, | 1041 ScrollBackingStoreRect(params.dx, params.dy, |
| 1042 params.scroll_rect, | 1042 params.scroll_rect, |
| 1043 params.view_size); | 1043 params.view_size); |
| 1044 } | 1044 } |
| 1045 | 1045 |
| (...skipping 102 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1148 | 1148 |
| 1149 // Log the time delta for processing an input event. | 1149 // Log the time delta for processing an input event. |
| 1150 TimeDelta delta = TimeTicks::Now() - input_event_start_time_; | 1150 TimeDelta delta = TimeTicks::Now() - input_event_start_time_; |
| 1151 UMA_HISTOGRAM_TIMES("MPArch.RWH_InputEventDelta", delta); | 1151 UMA_HISTOGRAM_TIMES("MPArch.RWH_InputEventDelta", delta); |
| 1152 | 1152 |
| 1153 // Cancel pending hung renderer checks since the renderer is responsive. | 1153 // Cancel pending hung renderer checks since the renderer is responsive. |
| 1154 StopHangMonitorTimeout(); | 1154 StopHangMonitorTimeout(); |
| 1155 | 1155 |
| 1156 int type = static_cast<int>(event_type); | 1156 int type = static_cast<int>(event_type); |
| 1157 if (type < WebInputEvent::Undefined) { | 1157 if (type < WebInputEvent::Undefined) { |
| 1158 UserMetrics::RecordAction(UserMetricsAction("BadMessageTerminate_RWH2")); | 1158 content::RecordAction(UserMetricsAction("BadMessageTerminate_RWH2")); |
| 1159 process()->ReceivedBadMessage(); | 1159 process()->ReceivedBadMessage(); |
| 1160 } else if (type == WebInputEvent::MouseMove) { | 1160 } else if (type == WebInputEvent::MouseMove) { |
| 1161 mouse_move_pending_ = false; | 1161 mouse_move_pending_ = false; |
| 1162 | 1162 |
| 1163 // now, we can send the next mouse move event | 1163 // now, we can send the next mouse move event |
| 1164 if (next_mouse_move_.get()) { | 1164 if (next_mouse_move_.get()) { |
| 1165 DCHECK(next_mouse_move_->type == WebInputEvent::MouseMove); | 1165 DCHECK(next_mouse_move_->type == WebInputEvent::MouseMove); |
| 1166 ForwardMouseEvent(*next_mouse_move_); | 1166 ForwardMouseEvent(*next_mouse_move_); |
| 1167 } | 1167 } |
| 1168 } else if (WebInputEvent::isKeyboardEventType(type)) { | 1168 } else if (WebInputEvent::isKeyboardEventType(type)) { |
| (...skipping 24 matching lines...) Expand all Loading... |
| 1193 coalesced_mouse_wheel_events_.pop_front(); | 1193 coalesced_mouse_wheel_events_.pop_front(); |
| 1194 ForwardWheelEvent(next_wheel_event); | 1194 ForwardWheelEvent(next_wheel_event); |
| 1195 } | 1195 } |
| 1196 | 1196 |
| 1197 if (!processed && !is_hidden_ && view_) | 1197 if (!processed && !is_hidden_ && view_) |
| 1198 view_->UnhandledWheelEvent(current_wheel_event_); | 1198 view_->UnhandledWheelEvent(current_wheel_event_); |
| 1199 } | 1199 } |
| 1200 | 1200 |
| 1201 void RenderWidgetHost::OnMsgFocus() { | 1201 void RenderWidgetHost::OnMsgFocus() { |
| 1202 // Only RenderViewHost can deal with that message. | 1202 // Only RenderViewHost can deal with that message. |
| 1203 UserMetrics::RecordAction(UserMetricsAction("BadMessageTerminate_RWH4")); | 1203 content::RecordAction(UserMetricsAction("BadMessageTerminate_RWH4")); |
| 1204 process()->ReceivedBadMessage(); | 1204 process()->ReceivedBadMessage(); |
| 1205 } | 1205 } |
| 1206 | 1206 |
| 1207 void RenderWidgetHost::OnMsgBlur() { | 1207 void RenderWidgetHost::OnMsgBlur() { |
| 1208 // Only RenderViewHost can deal with that message. | 1208 // Only RenderViewHost can deal with that message. |
| 1209 UserMetrics::RecordAction(UserMetricsAction("BadMessageTerminate_RWH5")); | 1209 content::RecordAction(UserMetricsAction("BadMessageTerminate_RWH5")); |
| 1210 process()->ReceivedBadMessage(); | 1210 process()->ReceivedBadMessage(); |
| 1211 } | 1211 } |
| 1212 | 1212 |
| 1213 void RenderWidgetHost::OnMsgSetCursor(const WebCursor& cursor) { | 1213 void RenderWidgetHost::OnMsgSetCursor(const WebCursor& cursor) { |
| 1214 if (!view_) { | 1214 if (!view_) { |
| 1215 return; | 1215 return; |
| 1216 } | 1216 } |
| 1217 view_->UpdateCursor(cursor); | 1217 view_->UpdateCursor(cursor); |
| 1218 } | 1218 } |
| 1219 | 1219 |
| (...skipping 230 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1450 Send(new ViewMsg_ScrollFocusedEditableNodeIntoRect(routing_id(), rect)); | 1450 Send(new ViewMsg_ScrollFocusedEditableNodeIntoRect(routing_id(), rect)); |
| 1451 } | 1451 } |
| 1452 | 1452 |
| 1453 void RenderWidgetHost::SelectRange(const gfx::Point& start, | 1453 void RenderWidgetHost::SelectRange(const gfx::Point& start, |
| 1454 const gfx::Point& end) { | 1454 const gfx::Point& end) { |
| 1455 Send(new ViewMsg_SelectRange(routing_id(), start, end)); | 1455 Send(new ViewMsg_SelectRange(routing_id(), start, end)); |
| 1456 } | 1456 } |
| 1457 | 1457 |
| 1458 void RenderWidgetHost::Undo() { | 1458 void RenderWidgetHost::Undo() { |
| 1459 Send(new ViewMsg_Undo(routing_id())); | 1459 Send(new ViewMsg_Undo(routing_id())); |
| 1460 UserMetrics::RecordAction(UserMetricsAction("Undo")); | 1460 content::RecordAction(UserMetricsAction("Undo")); |
| 1461 } | 1461 } |
| 1462 | 1462 |
| 1463 void RenderWidgetHost::Redo() { | 1463 void RenderWidgetHost::Redo() { |
| 1464 Send(new ViewMsg_Redo(routing_id())); | 1464 Send(new ViewMsg_Redo(routing_id())); |
| 1465 UserMetrics::RecordAction(UserMetricsAction("Redo")); | 1465 content::RecordAction(UserMetricsAction("Redo")); |
| 1466 } | 1466 } |
| 1467 | 1467 |
| 1468 void RenderWidgetHost::Cut() { | 1468 void RenderWidgetHost::Cut() { |
| 1469 Send(new ViewMsg_Cut(routing_id())); | 1469 Send(new ViewMsg_Cut(routing_id())); |
| 1470 UserMetrics::RecordAction(UserMetricsAction("Cut")); | 1470 content::RecordAction(UserMetricsAction("Cut")); |
| 1471 } | 1471 } |
| 1472 | 1472 |
| 1473 void RenderWidgetHost::Copy() { | 1473 void RenderWidgetHost::Copy() { |
| 1474 Send(new ViewMsg_Copy(routing_id())); | 1474 Send(new ViewMsg_Copy(routing_id())); |
| 1475 UserMetrics::RecordAction(UserMetricsAction("Copy")); | 1475 content::RecordAction(UserMetricsAction("Copy")); |
| 1476 } | 1476 } |
| 1477 | 1477 |
| 1478 void RenderWidgetHost::CopyToFindPboard() { | 1478 void RenderWidgetHost::CopyToFindPboard() { |
| 1479 #if defined(OS_MACOSX) | 1479 #if defined(OS_MACOSX) |
| 1480 // Windows/Linux don't have the concept of a find pasteboard. | 1480 // Windows/Linux don't have the concept of a find pasteboard. |
| 1481 Send(new ViewMsg_CopyToFindPboard(routing_id())); | 1481 Send(new ViewMsg_CopyToFindPboard(routing_id())); |
| 1482 UserMetrics::RecordAction(UserMetricsAction("CopyToFindPboard")); | 1482 content::RecordAction(UserMetricsAction("CopyToFindPboard")); |
| 1483 #endif | 1483 #endif |
| 1484 } | 1484 } |
| 1485 | 1485 |
| 1486 void RenderWidgetHost::Paste() { | 1486 void RenderWidgetHost::Paste() { |
| 1487 Send(new ViewMsg_Paste(routing_id())); | 1487 Send(new ViewMsg_Paste(routing_id())); |
| 1488 UserMetrics::RecordAction(UserMetricsAction("Paste")); | 1488 content::RecordAction(UserMetricsAction("Paste")); |
| 1489 } | 1489 } |
| 1490 | 1490 |
| 1491 void RenderWidgetHost::PasteAndMatchStyle() { | 1491 void RenderWidgetHost::PasteAndMatchStyle() { |
| 1492 Send(new ViewMsg_PasteAndMatchStyle(routing_id())); | 1492 Send(new ViewMsg_PasteAndMatchStyle(routing_id())); |
| 1493 UserMetrics::RecordAction(UserMetricsAction("PasteAndMatchStyle")); | 1493 content::RecordAction(UserMetricsAction("PasteAndMatchStyle")); |
| 1494 } | 1494 } |
| 1495 | 1495 |
| 1496 void RenderWidgetHost::Delete() { | 1496 void RenderWidgetHost::Delete() { |
| 1497 Send(new ViewMsg_Delete(routing_id())); | 1497 Send(new ViewMsg_Delete(routing_id())); |
| 1498 UserMetrics::RecordAction(UserMetricsAction("DeleteSelection")); | 1498 content::RecordAction(UserMetricsAction("DeleteSelection")); |
| 1499 } | 1499 } |
| 1500 | 1500 |
| 1501 void RenderWidgetHost::SelectAll() { | 1501 void RenderWidgetHost::SelectAll() { |
| 1502 Send(new ViewMsg_SelectAll(routing_id())); | 1502 Send(new ViewMsg_SelectAll(routing_id())); |
| 1503 UserMetrics::RecordAction(UserMetricsAction("SelectAll")); | 1503 content::RecordAction(UserMetricsAction("SelectAll")); |
| 1504 } | 1504 } |
| 1505 bool RenderWidgetHost::GotResponseToLockMouseRequest(bool allowed) { | 1505 bool RenderWidgetHost::GotResponseToLockMouseRequest(bool allowed) { |
| 1506 if (!allowed) { | 1506 if (!allowed) { |
| 1507 RejectMouseLockOrUnlockIfNecessary(); | 1507 RejectMouseLockOrUnlockIfNecessary(); |
| 1508 return false; | 1508 return false; |
| 1509 } else { | 1509 } else { |
| 1510 if (!pending_mouse_lock_request_) { | 1510 if (!pending_mouse_lock_request_) { |
| 1511 // This is possible, e.g., the plugin sends us an unlock request before | 1511 // This is possible, e.g., the plugin sends us an unlock request before |
| 1512 // the user allows to lock to mouse. | 1512 // the user allows to lock to mouse. |
| 1513 return false; | 1513 return false; |
| (...skipping 17 matching lines...) Expand all Loading... |
| 1531 ui_shim->Send(new AcceleratedSurfaceMsg_BuffersSwappedACK(route_id)); | 1531 ui_shim->Send(new AcceleratedSurfaceMsg_BuffersSwappedACK(route_id)); |
| 1532 } | 1532 } |
| 1533 | 1533 |
| 1534 // static | 1534 // static |
| 1535 void RenderWidgetHost::AcknowledgePostSubBuffer(int32 route_id, | 1535 void RenderWidgetHost::AcknowledgePostSubBuffer(int32 route_id, |
| 1536 int gpu_host_id) { | 1536 int gpu_host_id) { |
| 1537 GpuProcessHostUIShim* ui_shim = GpuProcessHostUIShim::FromID(gpu_host_id); | 1537 GpuProcessHostUIShim* ui_shim = GpuProcessHostUIShim::FromID(gpu_host_id); |
| 1538 if (ui_shim) | 1538 if (ui_shim) |
| 1539 ui_shim->Send(new AcceleratedSurfaceMsg_PostSubBufferACK(route_id)); | 1539 ui_shim->Send(new AcceleratedSurfaceMsg_PostSubBufferACK(route_id)); |
| 1540 } | 1540 } |
| OLD | NEW |