OLD | NEW |
1 // Copyright (c) 2010 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2010 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 "chrome/browser/renderer_host/render_widget_host.h" | 5 #include "chrome/browser/renderer_host/render_widget_host.h" |
6 | 6 |
7 #include "app/keyboard_codes.h" | 7 #include "app/keyboard_codes.h" |
8 #include "base/auto_reset.h" | 8 #include "base/auto_reset.h" |
9 #include "base/command_line.h" | 9 #include "base/command_line.h" |
10 #include "base/message_loop.h" | 10 #include "base/message_loop.h" |
11 #include "base/metrics/histogram.h" | 11 #include "base/metrics/histogram.h" |
12 #include "chrome/browser/accessibility/browser_accessibility_state.h" | 12 #include "chrome/browser/accessibility/browser_accessibility_state.h" |
13 #include "chrome/browser/browser_thread.h" | 13 #include "chrome/browser/browser_thread.h" |
14 #include "chrome/browser/renderer_host/backing_store.h" | 14 #include "chrome/browser/renderer_host/backing_store.h" |
15 #include "chrome/browser/renderer_host/backing_store_manager.h" | 15 #include "chrome/browser/renderer_host/backing_store_manager.h" |
16 #include "chrome/browser/renderer_host/render_process_host.h" | 16 #include "chrome/browser/renderer_host/render_process_host.h" |
17 #include "chrome/browser/renderer_host/render_widget_helper.h" | 17 #include "chrome/browser/renderer_host/render_widget_helper.h" |
18 #include "chrome/browser/renderer_host/render_widget_host_painting_observer.h" | 18 #include "chrome/browser/renderer_host/render_widget_host_painting_observer.h" |
19 #include "chrome/browser/renderer_host/render_widget_host_view.h" | 19 #include "chrome/browser/renderer_host/render_widget_host_view.h" |
20 #include "chrome/browser/renderer_host/video_layer.h" | |
21 #include "chrome/common/chrome_switches.h" | 20 #include "chrome/common/chrome_switches.h" |
22 #include "chrome/common/native_web_keyboard_event.h" | 21 #include "chrome/common/native_web_keyboard_event.h" |
23 #include "chrome/common/notification_service.h" | 22 #include "chrome/common/notification_service.h" |
24 #include "chrome/common/render_messages.h" | 23 #include "chrome/common/render_messages.h" |
25 #include "chrome/common/render_messages_params.h" | 24 #include "chrome/common/render_messages_params.h" |
26 #include "third_party/WebKit/WebKit/chromium/public/WebCompositionUnderline.h" | 25 #include "third_party/WebKit/WebKit/chromium/public/WebCompositionUnderline.h" |
27 #include "webkit/glue/plugins/webplugin.h" | 26 #include "webkit/glue/plugins/webplugin.h" |
28 #include "webkit/glue/webcursor.h" | 27 #include "webkit/glue/webcursor.h" |
29 | 28 |
30 #if defined(TOOLKIT_VIEWS) | 29 #if defined(TOOLKIT_VIEWS) |
(...skipping 112 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
143 | 142 |
144 void RenderWidgetHost::OnMessageReceived(const IPC::Message &msg) { | 143 void RenderWidgetHost::OnMessageReceived(const IPC::Message &msg) { |
145 bool msg_is_ok = true; | 144 bool msg_is_ok = true; |
146 IPC_BEGIN_MESSAGE_MAP_EX(RenderWidgetHost, msg, msg_is_ok) | 145 IPC_BEGIN_MESSAGE_MAP_EX(RenderWidgetHost, msg, msg_is_ok) |
147 IPC_MESSAGE_HANDLER(ViewHostMsg_RenderViewReady, OnMsgRenderViewReady) | 146 IPC_MESSAGE_HANDLER(ViewHostMsg_RenderViewReady, OnMsgRenderViewReady) |
148 IPC_MESSAGE_HANDLER(ViewHostMsg_RenderViewGone, OnMsgRenderViewGone) | 147 IPC_MESSAGE_HANDLER(ViewHostMsg_RenderViewGone, OnMsgRenderViewGone) |
149 IPC_MESSAGE_HANDLER(ViewHostMsg_Close, OnMsgClose) | 148 IPC_MESSAGE_HANDLER(ViewHostMsg_Close, OnMsgClose) |
150 IPC_MESSAGE_HANDLER(ViewHostMsg_RequestMove, OnMsgRequestMove) | 149 IPC_MESSAGE_HANDLER(ViewHostMsg_RequestMove, OnMsgRequestMove) |
151 IPC_MESSAGE_HANDLER(ViewHostMsg_PaintAtSize_ACK, OnMsgPaintAtSizeAck) | 150 IPC_MESSAGE_HANDLER(ViewHostMsg_PaintAtSize_ACK, OnMsgPaintAtSizeAck) |
152 IPC_MESSAGE_HANDLER(ViewHostMsg_UpdateRect, OnMsgUpdateRect) | 151 IPC_MESSAGE_HANDLER(ViewHostMsg_UpdateRect, OnMsgUpdateRect) |
153 IPC_MESSAGE_HANDLER(ViewHostMsg_CreateVideo, OnMsgCreateVideo) | |
154 IPC_MESSAGE_HANDLER(ViewHostMsg_UpdateVideo, OnMsgUpdateVideo) | |
155 IPC_MESSAGE_HANDLER(ViewHostMsg_DestroyVideo, OnMsgDestroyVideo) | |
156 IPC_MESSAGE_HANDLER(ViewHostMsg_HandleInputEvent_ACK, OnMsgInputEventAck) | 152 IPC_MESSAGE_HANDLER(ViewHostMsg_HandleInputEvent_ACK, OnMsgInputEventAck) |
157 IPC_MESSAGE_HANDLER(ViewHostMsg_Focus, OnMsgFocus) | 153 IPC_MESSAGE_HANDLER(ViewHostMsg_Focus, OnMsgFocus) |
158 IPC_MESSAGE_HANDLER(ViewHostMsg_Blur, OnMsgBlur) | 154 IPC_MESSAGE_HANDLER(ViewHostMsg_Blur, OnMsgBlur) |
159 IPC_MESSAGE_HANDLER(ViewHostMsg_SetCursor, OnMsgSetCursor) | 155 IPC_MESSAGE_HANDLER(ViewHostMsg_SetCursor, OnMsgSetCursor) |
160 IPC_MESSAGE_HANDLER(ViewHostMsg_ImeUpdateTextInputState, | 156 IPC_MESSAGE_HANDLER(ViewHostMsg_ImeUpdateTextInputState, |
161 OnMsgImeUpdateTextInputState) | 157 OnMsgImeUpdateTextInputState) |
162 IPC_MESSAGE_HANDLER(ViewHostMsg_ImeCancelComposition, | 158 IPC_MESSAGE_HANDLER(ViewHostMsg_ImeCancelComposition, |
163 OnMsgImeCancelComposition) | 159 OnMsgImeCancelComposition) |
164 IPC_MESSAGE_HANDLER(ViewHostMsg_GpuRenderingActivated, | 160 IPC_MESSAGE_HANDLER(ViewHostMsg_GpuRenderingActivated, |
165 OnMsgGpuRenderingActivated) | 161 OnMsgGpuRenderingActivated) |
(...skipping 619 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
785 ViewHostMsg_UpdateRect_Flags::is_repaint_ack(params.flags); | 781 ViewHostMsg_UpdateRect_Flags::is_repaint_ack(params.flags); |
786 if (is_repaint_ack) { | 782 if (is_repaint_ack) { |
787 repaint_ack_pending_ = false; | 783 repaint_ack_pending_ = false; |
788 TimeDelta delta = TimeTicks::Now() - repaint_start_time_; | 784 TimeDelta delta = TimeTicks::Now() - repaint_start_time_; |
789 UMA_HISTOGRAM_TIMES("MPArch.RWH_RepaintDelta", delta); | 785 UMA_HISTOGRAM_TIMES("MPArch.RWH_RepaintDelta", delta); |
790 } | 786 } |
791 | 787 |
792 DCHECK(!params.bitmap_rect.IsEmpty()); | 788 DCHECK(!params.bitmap_rect.IsEmpty()); |
793 DCHECK(!params.view_size.IsEmpty()); | 789 DCHECK(!params.view_size.IsEmpty()); |
794 | 790 |
795 bool painted_synchronously = true; // Default to sending a paint ACK below. | |
796 if (!is_gpu_rendering_active_) { | 791 if (!is_gpu_rendering_active_) { |
797 const size_t size = params.bitmap_rect.height() * | 792 const size_t size = params.bitmap_rect.height() * |
798 params.bitmap_rect.width() * 4; | 793 params.bitmap_rect.width() * 4; |
799 TransportDIB* dib = process_->GetTransportDIB(params.bitmap); | 794 TransportDIB* dib = process_->GetTransportDIB(params.bitmap); |
800 | 795 |
801 // If gpu process does painting, scroll_rect and copy_rects are always empty | 796 // If gpu process does painting, scroll_rect and copy_rects are always empty |
802 // and backing store is never used. | 797 // and backing store is never used. |
803 if (dib) { | 798 if (dib) { |
804 if (dib->size() < size) { | 799 if (dib->size() < size) { |
805 DLOG(WARNING) << "Transport DIB too small for given rectangle"; | 800 DLOG(WARNING) << "Transport DIB too small for given rectangle"; |
806 process()->ReceivedBadMessage(ViewHostMsg_UpdateRect__ID); | 801 process()->ReceivedBadMessage(ViewHostMsg_UpdateRect__ID); |
807 } else { | 802 } else { |
808 // Scroll the backing store. | 803 // Scroll the backing store. |
809 if (!params.scroll_rect.IsEmpty()) { | 804 if (!params.scroll_rect.IsEmpty()) { |
810 ScrollBackingStoreRect(params.dx, params.dy, | 805 ScrollBackingStoreRect(params.dx, params.dy, |
811 params.scroll_rect, | 806 params.scroll_rect, |
812 params.view_size); | 807 params.view_size); |
813 } | 808 } |
814 | 809 |
815 // Paint the backing store. This will update it with the | 810 // Paint the backing store. This will update it with the |
816 // renderer-supplied bits. The view will read out of the backing store | 811 // renderer-supplied bits. The view will read out of the backing store |
817 // later to actually draw to the screen. | 812 // later to actually draw to the screen. |
818 PaintBackingStoreRect(params.bitmap, params.bitmap_rect, | 813 PaintBackingStoreRect(params.bitmap, params.bitmap_rect, |
819 params.copy_rects, params.view_size, | 814 params.copy_rects, params.view_size); |
820 &painted_synchronously); | |
821 } | 815 } |
822 } | 816 } |
823 } | 817 } |
824 | 818 |
825 // ACK early so we can prefetch the next PaintRect if there is a next one. | 819 // ACK early so we can prefetch the next PaintRect if there is a next one. |
826 // This must be done AFTER we're done painting with the bitmap supplied by the | 820 // This must be done AFTER we're done painting with the bitmap supplied by the |
827 // renderer. This ACK is a signal to the renderer that the backing store can | 821 // renderer. This ACK is a signal to the renderer that the backing store can |
828 // be re-used, so the bitmap may be invalid after this call. If the backing | 822 // be re-used, so the bitmap may be invalid after this call. |
829 // store is painting asynchronously, it will manage issuing this IPC. | 823 Send(new ViewMsg_UpdateRect_ACK(routing_id_)); |
830 if (painted_synchronously) | |
831 Send(new ViewMsg_UpdateRect_ACK(routing_id_)); | |
832 | 824 |
833 // We don't need to update the view if the view is hidden. We must do this | 825 // We don't need to update the view if the view is hidden. We must do this |
834 // early return after the ACK is sent, however, or the renderer will not send | 826 // early return after the ACK is sent, however, or the renderer will not send |
835 // us more data. | 827 // us more data. |
836 if (is_hidden_) | 828 if (is_hidden_) |
837 return; | 829 return; |
838 | 830 |
839 // Now paint the view. Watch out: it might be destroyed already. | 831 // Now paint the view. Watch out: it might be destroyed already. |
840 if (view_) { | 832 if (view_) { |
841 view_->MovePluginWindows(params.plugin_window_moves); | 833 view_->MovePluginWindows(params.plugin_window_moves); |
(...skipping 22 matching lines...) Expand all Loading... |
864 } | 856 } |
865 | 857 |
866 if (painting_observer_) | 858 if (painting_observer_) |
867 painting_observer_->WidgetDidUpdateBackingStore(this); | 859 painting_observer_->WidgetDidUpdateBackingStore(this); |
868 | 860 |
869 // Log the time delta for processing a paint message. | 861 // Log the time delta for processing a paint message. |
870 TimeDelta delta = TimeTicks::Now() - paint_start; | 862 TimeDelta delta = TimeTicks::Now() - paint_start; |
871 UMA_HISTOGRAM_TIMES("MPArch.RWH_OnMsgUpdateRect", delta); | 863 UMA_HISTOGRAM_TIMES("MPArch.RWH_OnMsgUpdateRect", delta); |
872 } | 864 } |
873 | 865 |
874 void RenderWidgetHost::OnMsgCreateVideo(const gfx::Size& size) { | |
875 DCHECK(!video_layer_.get()); | |
876 | |
877 video_layer_.reset(view_->AllocVideoLayer(size)); | |
878 | |
879 // TODO(scherkus): support actual video ids! | |
880 Send(new ViewMsg_CreateVideo_ACK(routing_id_, -1)); | |
881 } | |
882 | |
883 void RenderWidgetHost::OnMsgUpdateVideo(TransportDIB::Id bitmap, | |
884 const gfx::Rect& bitmap_rect) { | |
885 PaintVideoLayer(bitmap, bitmap_rect); | |
886 | |
887 // TODO(scherkus): support actual video ids! | |
888 Send(new ViewMsg_UpdateVideo_ACK(routing_id_, -1)); | |
889 } | |
890 | |
891 void RenderWidgetHost::OnMsgDestroyVideo() { | |
892 video_layer_.reset(); | |
893 } | |
894 | |
895 void RenderWidgetHost::OnMsgInputEventAck(const IPC::Message& message) { | 866 void RenderWidgetHost::OnMsgInputEventAck(const IPC::Message& message) { |
896 // Log the time delta for processing an input event. | 867 // Log the time delta for processing an input event. |
897 TimeDelta delta = TimeTicks::Now() - input_event_start_time_; | 868 TimeDelta delta = TimeTicks::Now() - input_event_start_time_; |
898 UMA_HISTOGRAM_TIMES("MPArch.RWH_InputEventDelta", delta); | 869 UMA_HISTOGRAM_TIMES("MPArch.RWH_InputEventDelta", delta); |
899 | 870 |
900 // Cancel pending hung renderer checks since the renderer is responsive. | 871 // Cancel pending hung renderer checks since the renderer is responsive. |
901 StopHangMonitorTimeout(); | 872 StopHangMonitorTimeout(); |
902 | 873 |
903 void* iter = NULL; | 874 void* iter = NULL; |
904 int type = 0; | 875 int type = 0; |
(...skipping 165 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1070 NOTIMPLEMENTED(); | 1041 NOTIMPLEMENTED(); |
1071 } | 1042 } |
1072 } | 1043 } |
1073 | 1044 |
1074 #endif | 1045 #endif |
1075 | 1046 |
1076 void RenderWidgetHost::PaintBackingStoreRect( | 1047 void RenderWidgetHost::PaintBackingStoreRect( |
1077 TransportDIB::Id bitmap, | 1048 TransportDIB::Id bitmap, |
1078 const gfx::Rect& bitmap_rect, | 1049 const gfx::Rect& bitmap_rect, |
1079 const std::vector<gfx::Rect>& copy_rects, | 1050 const std::vector<gfx::Rect>& copy_rects, |
1080 const gfx::Size& view_size, | 1051 const gfx::Size& view_size) { |
1081 bool* painted_synchronously) { | |
1082 // On failure, we need to be sure our caller knows we're done with the | |
1083 // backing store. | |
1084 *painted_synchronously = true; | |
1085 | |
1086 // The view may be destroyed already. | 1052 // The view may be destroyed already. |
1087 if (!view_) | 1053 if (!view_) |
1088 return; | 1054 return; |
1089 | 1055 |
1090 if (is_hidden_) { | 1056 if (is_hidden_) { |
1091 // Don't bother updating the backing store when we're hidden. Just mark it | 1057 // Don't bother updating the backing store when we're hidden. Just mark it |
1092 // as being totally invalid. This will cause a complete repaint when the | 1058 // as being totally invalid. This will cause a complete repaint when the |
1093 // view is restored. | 1059 // view is restored. |
1094 needs_repainting_on_restore_ = true; | 1060 needs_repainting_on_restore_ = true; |
1095 return; | 1061 return; |
1096 } | 1062 } |
1097 | 1063 |
1098 bool needs_full_paint = false; | 1064 bool needs_full_paint = false; |
1099 BackingStoreManager::PrepareBackingStore(this, view_size, bitmap, bitmap_rect, | 1065 BackingStoreManager::PrepareBackingStore(this, view_size, bitmap, bitmap_rect, |
1100 copy_rects, &needs_full_paint, | 1066 copy_rects, &needs_full_paint); |
1101 painted_synchronously); | |
1102 if (needs_full_paint) { | 1067 if (needs_full_paint) { |
1103 repaint_start_time_ = TimeTicks::Now(); | 1068 repaint_start_time_ = TimeTicks::Now(); |
1104 repaint_ack_pending_ = true; | 1069 repaint_ack_pending_ = true; |
1105 Send(new ViewMsg_Repaint(routing_id_, view_size)); | 1070 Send(new ViewMsg_Repaint(routing_id_, view_size)); |
1106 } | 1071 } |
1107 } | 1072 } |
1108 | 1073 |
1109 void RenderWidgetHost::ScrollBackingStoreRect(int dx, int dy, | 1074 void RenderWidgetHost::ScrollBackingStoreRect(int dx, int dy, |
1110 const gfx::Rect& clip_rect, | 1075 const gfx::Rect& clip_rect, |
1111 const gfx::Size& view_size) { | 1076 const gfx::Size& view_size) { |
1112 if (is_hidden_) { | 1077 if (is_hidden_) { |
1113 // Don't bother updating the backing store when we're hidden. Just mark it | 1078 // Don't bother updating the backing store when we're hidden. Just mark it |
1114 // as being totally invalid. This will cause a complete repaint when the | 1079 // as being totally invalid. This will cause a complete repaint when the |
1115 // view is restored. | 1080 // view is restored. |
1116 needs_repainting_on_restore_ = true; | 1081 needs_repainting_on_restore_ = true; |
1117 return; | 1082 return; |
1118 } | 1083 } |
1119 | 1084 |
1120 // TODO(darin): do we need to do something else if our backing store is not | 1085 // TODO(darin): do we need to do something else if our backing store is not |
1121 // the same size as the advertised view? maybe we just assume there is a | 1086 // the same size as the advertised view? maybe we just assume there is a |
1122 // full paint on its way? | 1087 // full paint on its way? |
1123 BackingStore* backing_store = BackingStoreManager::Lookup(this); | 1088 BackingStore* backing_store = BackingStoreManager::Lookup(this); |
1124 if (!backing_store || (backing_store->size() != view_size)) | 1089 if (!backing_store || (backing_store->size() != view_size)) |
1125 return; | 1090 return; |
1126 backing_store->ScrollBackingStore(dx, dy, clip_rect, view_size); | 1091 backing_store->ScrollBackingStore(dx, dy, clip_rect, view_size); |
1127 } | 1092 } |
1128 | 1093 |
1129 void RenderWidgetHost::PaintVideoLayer(TransportDIB::Id bitmap, | |
1130 const gfx::Rect& bitmap_rect) { | |
1131 if (is_hidden_ || !video_layer_.get()) | |
1132 return; | |
1133 | |
1134 video_layer_->CopyTransportDIB(process(), bitmap, bitmap_rect); | |
1135 | |
1136 // Don't update the view if we're hidden or if the view has been destroyed. | |
1137 if (is_hidden_ || !view_) | |
1138 return; | |
1139 | |
1140 // Trigger a paint for the updated video layer bitmap. | |
1141 std::vector<gfx::Rect> copy_rects; | |
1142 copy_rects.push_back(bitmap_rect); | |
1143 | |
1144 view_being_painted_ = true; | |
1145 view_->DidUpdateBackingStore(gfx::Rect(), 0, 0, copy_rects); | |
1146 view_being_painted_ = false; | |
1147 } | |
1148 | |
1149 void RenderWidgetHost::ToggleSpellPanel(bool is_currently_visible) { | 1094 void RenderWidgetHost::ToggleSpellPanel(bool is_currently_visible) { |
1150 Send(new ViewMsg_ToggleSpellPanel(routing_id(), is_currently_visible)); | 1095 Send(new ViewMsg_ToggleSpellPanel(routing_id(), is_currently_visible)); |
1151 } | 1096 } |
1152 | 1097 |
1153 void RenderWidgetHost::Replace(const string16& word) { | 1098 void RenderWidgetHost::Replace(const string16& word) { |
1154 Send(new ViewMsg_Replace(routing_id_, word)); | 1099 Send(new ViewMsg_Replace(routing_id_, word)); |
1155 } | 1100 } |
1156 | 1101 |
1157 void RenderWidgetHost::AdvanceToNextMisspelling() { | 1102 void RenderWidgetHost::AdvanceToNextMisspelling() { |
1158 Send(new ViewMsg_AdvanceToNextMisspelling(routing_id_)); | 1103 Send(new ViewMsg_AdvanceToNextMisspelling(routing_id_)); |
(...skipping 55 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1214 // of this key event. | 1159 // of this key event. |
1215 if (!processed && !is_hidden_ && !front_item.skip_in_browser) { | 1160 if (!processed && !is_hidden_ && !front_item.skip_in_browser) { |
1216 UnhandledKeyboardEvent(front_item); | 1161 UnhandledKeyboardEvent(front_item); |
1217 | 1162 |
1218 // WARNING: This RenderWidgetHost can be deallocated at this point | 1163 // WARNING: This RenderWidgetHost can be deallocated at this point |
1219 // (i.e. in the case of Ctrl+W, where the call to | 1164 // (i.e. in the case of Ctrl+W, where the call to |
1220 // UnhandledKeyboardEvent destroys this RenderWidgetHost). | 1165 // UnhandledKeyboardEvent destroys this RenderWidgetHost). |
1221 } | 1166 } |
1222 } | 1167 } |
1223 } | 1168 } |
OLD | NEW |