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/renderer/render_widget.h" | 5 #include "content/renderer/render_widget.h" |
6 | 6 |
7 #include "base/command_line.h" | 7 #include "base/command_line.h" |
8 #include "base/logging.h" | 8 #include "base/logging.h" |
9 #include "base/memory/scoped_ptr.h" | 9 #include "base/memory/scoped_ptr.h" |
10 #include "base/message_loop.h" | 10 #include "base/message_loop.h" |
(...skipping 54 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
65 host_window_(0), | 65 host_window_(0), |
66 current_paint_buf_(NULL), | 66 current_paint_buf_(NULL), |
67 next_paint_flags_(0), | 67 next_paint_flags_(0), |
68 update_reply_pending_(false), | 68 update_reply_pending_(false), |
69 did_show_(false), | 69 did_show_(false), |
70 is_hidden_(false), | 70 is_hidden_(false), |
71 needs_repainting_on_restore_(false), | 71 needs_repainting_on_restore_(false), |
72 has_focus_(false), | 72 has_focus_(false), |
73 handling_input_event_(false), | 73 handling_input_event_(false), |
74 closing_(false), | 74 closing_(false), |
| 75 is_swapped_out_(false), |
75 input_method_is_active_(false), | 76 input_method_is_active_(false), |
76 text_input_type_(WebKit::WebTextInputTypeNone), | 77 text_input_type_(WebKit::WebTextInputTypeNone), |
77 popup_type_(popup_type), | 78 popup_type_(popup_type), |
78 pending_window_rect_count_(0), | 79 pending_window_rect_count_(0), |
79 suppress_next_char_events_(false), | 80 suppress_next_char_events_(false), |
80 is_accelerated_compositing_active_(false), | 81 is_accelerated_compositing_active_(false), |
81 animation_update_pending_(false), | 82 animation_update_pending_(false), |
82 animation_task_posted_(false) { | 83 animation_task_posted_(false) { |
83 RenderProcess::current()->AddRefProcess(); | 84 RenderProcess::current()->AddRefProcess(); |
84 DCHECK(render_thread_); | 85 DCHECK(render_thread_); |
85 } | 86 } |
86 | 87 |
87 RenderWidget::~RenderWidget() { | 88 RenderWidget::~RenderWidget() { |
88 DCHECK(!webwidget_) << "Leaking our WebWidget!"; | 89 DCHECK(!webwidget_) << "Leaking our WebWidget!"; |
89 if (current_paint_buf_) { | 90 if (current_paint_buf_) { |
90 RenderProcess::current()->ReleaseTransportDIB(current_paint_buf_); | 91 RenderProcess::current()->ReleaseTransportDIB(current_paint_buf_); |
91 current_paint_buf_ = NULL; | 92 current_paint_buf_ = NULL; |
92 } | 93 } |
93 RenderProcess::current()->ReleaseProcess(); | 94 // If we are swapped out, we have released already. |
| 95 if (!is_swapped_out_) |
| 96 RenderProcess::current()->ReleaseProcess(); |
94 } | 97 } |
95 | 98 |
96 // static | 99 // static |
97 RenderWidget* RenderWidget::Create(int32 opener_id, | 100 RenderWidget* RenderWidget::Create(int32 opener_id, |
98 RenderThreadBase* render_thread, | 101 RenderThreadBase* render_thread, |
99 WebKit::WebPopupType popup_type) { | 102 WebKit::WebPopupType popup_type) { |
100 DCHECK(opener_id != MSG_ROUTING_NONE); | 103 DCHECK(opener_id != MSG_ROUTING_NONE); |
101 scoped_refptr<RenderWidget> widget(new RenderWidget(render_thread, | 104 scoped_refptr<RenderWidget> widget(new RenderWidget(render_thread, |
102 popup_type)); | 105 popup_type)); |
103 widget->Init(opener_id); // adds reference | 106 widget->Init(opener_id); // adds reference |
(...skipping 47 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
151 void RenderWidget::CompleteInit(gfx::NativeViewId parent_hwnd, | 154 void RenderWidget::CompleteInit(gfx::NativeViewId parent_hwnd, |
152 gfx::PluginWindowHandle compositing_surface) { | 155 gfx::PluginWindowHandle compositing_surface) { |
153 DCHECK(routing_id_ != MSG_ROUTING_NONE); | 156 DCHECK(routing_id_ != MSG_ROUTING_NONE); |
154 | 157 |
155 host_window_ = parent_hwnd; | 158 host_window_ = parent_hwnd; |
156 compositing_surface_ = compositing_surface; | 159 compositing_surface_ = compositing_surface; |
157 | 160 |
158 Send(new ViewHostMsg_RenderViewReady(routing_id_)); | 161 Send(new ViewHostMsg_RenderViewReady(routing_id_)); |
159 } | 162 } |
160 | 163 |
| 164 void RenderWidget::SetSwappedOut(bool is_swapped_out) { |
| 165 // We should only toggle between states. |
| 166 DCHECK(is_swapped_out_ != is_swapped_out); |
| 167 is_swapped_out_ = is_swapped_out; |
| 168 |
| 169 // If we are swapping out, we will call ReleaseProcess, allowing the process |
| 170 // to exit if all of its RenderViews are swapped out. We wait until the |
| 171 // WasSwappedOut call to do this, to avoid showing the sad tab. |
| 172 // If we are swapping in, we call AddRefProcess to prevent the process from |
| 173 // exiting. |
| 174 if (!is_swapped_out) |
| 175 RenderProcess::current()->AddRefProcess(); |
| 176 } |
| 177 |
161 bool RenderWidget::OnMessageReceived(const IPC::Message& message) { | 178 bool RenderWidget::OnMessageReceived(const IPC::Message& message) { |
162 bool handled = true; | 179 bool handled = true; |
163 IPC_BEGIN_MESSAGE_MAP(RenderWidget, message) | 180 IPC_BEGIN_MESSAGE_MAP(RenderWidget, message) |
164 IPC_MESSAGE_HANDLER(ViewMsg_Close, OnClose) | 181 IPC_MESSAGE_HANDLER(ViewMsg_Close, OnClose) |
165 IPC_MESSAGE_HANDLER(ViewMsg_CreatingNew_ACK, OnCreatingNewAck) | 182 IPC_MESSAGE_HANDLER(ViewMsg_CreatingNew_ACK, OnCreatingNewAck) |
166 IPC_MESSAGE_HANDLER(ViewMsg_Resize, OnResize) | 183 IPC_MESSAGE_HANDLER(ViewMsg_Resize, OnResize) |
167 IPC_MESSAGE_HANDLER(ViewMsg_WasHidden, OnWasHidden) | 184 IPC_MESSAGE_HANDLER(ViewMsg_WasHidden, OnWasHidden) |
168 IPC_MESSAGE_HANDLER(ViewMsg_WasRestored, OnWasRestored) | 185 IPC_MESSAGE_HANDLER(ViewMsg_WasRestored, OnWasRestored) |
| 186 IPC_MESSAGE_HANDLER(ViewMsg_WasSwappedOut, OnWasSwappedOut) |
169 IPC_MESSAGE_HANDLER(ViewMsg_UpdateRect_ACK, OnUpdateRectAck) | 187 IPC_MESSAGE_HANDLER(ViewMsg_UpdateRect_ACK, OnUpdateRectAck) |
170 IPC_MESSAGE_HANDLER(ViewMsg_HandleInputEvent, OnHandleInputEvent) | 188 IPC_MESSAGE_HANDLER(ViewMsg_HandleInputEvent, OnHandleInputEvent) |
171 IPC_MESSAGE_HANDLER(ViewMsg_MouseCaptureLost, OnMouseCaptureLost) | 189 IPC_MESSAGE_HANDLER(ViewMsg_MouseCaptureLost, OnMouseCaptureLost) |
172 IPC_MESSAGE_HANDLER(ViewMsg_SetFocus, OnSetFocus) | 190 IPC_MESSAGE_HANDLER(ViewMsg_SetFocus, OnSetFocus) |
173 IPC_MESSAGE_HANDLER(ViewMsg_SetInputMethodActive, OnSetInputMethodActive) | 191 IPC_MESSAGE_HANDLER(ViewMsg_SetInputMethodActive, OnSetInputMethodActive) |
174 IPC_MESSAGE_HANDLER(ViewMsg_ImeSetComposition, OnImeSetComposition) | 192 IPC_MESSAGE_HANDLER(ViewMsg_ImeSetComposition, OnImeSetComposition) |
175 IPC_MESSAGE_HANDLER(ViewMsg_ImeConfirmComposition, OnImeConfirmComposition) | 193 IPC_MESSAGE_HANDLER(ViewMsg_ImeConfirmComposition, OnImeConfirmComposition) |
176 IPC_MESSAGE_HANDLER(ViewMsg_PaintAtSize, OnMsgPaintAtSize) | 194 IPC_MESSAGE_HANDLER(ViewMsg_PaintAtSize, OnMsgPaintAtSize) |
177 IPC_MESSAGE_HANDLER(ViewMsg_Repaint, OnMsgRepaint) | 195 IPC_MESSAGE_HANDLER(ViewMsg_Repaint, OnMsgRepaint) |
178 IPC_MESSAGE_HANDLER(ViewMsg_SetTextDirection, OnSetTextDirection) | 196 IPC_MESSAGE_HANDLER(ViewMsg_SetTextDirection, OnSetTextDirection) |
(...skipping 111 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
290 set_next_paint_is_restore_ack(); | 308 set_next_paint_is_restore_ack(); |
291 | 309 |
292 // Generate a full repaint. | 310 // Generate a full repaint. |
293 if (!is_accelerated_compositing_active_) { | 311 if (!is_accelerated_compositing_active_) { |
294 didInvalidateRect(gfx::Rect(size_.width(), size_.height())); | 312 didInvalidateRect(gfx::Rect(size_.width(), size_.height())); |
295 } else { | 313 } else { |
296 scheduleComposite(); | 314 scheduleComposite(); |
297 } | 315 } |
298 } | 316 } |
299 | 317 |
| 318 void RenderWidget::OnWasSwappedOut() { |
| 319 // If we have been swapped out and no one else is using this process, |
| 320 // it's safe to exit now. If we get swapped back in, we will call |
| 321 // AddRefProcess in SetSwappedOut. |
| 322 if (is_swapped_out_) |
| 323 RenderProcess::current()->ReleaseProcess(); |
| 324 } |
| 325 |
300 void RenderWidget::OnRequestMoveAck() { | 326 void RenderWidget::OnRequestMoveAck() { |
301 DCHECK(pending_window_rect_count_); | 327 DCHECK(pending_window_rect_count_); |
302 pending_window_rect_count_--; | 328 pending_window_rect_count_--; |
303 } | 329 } |
304 | 330 |
305 void RenderWidget::OnUpdateRectAck() { | 331 void RenderWidget::OnUpdateRectAck() { |
306 GPU_TRACE_EVENT0("renderer", "RenderWidget::OnUpdateRectAck"); | 332 GPU_TRACE_EVENT0("renderer", "RenderWidget::OnUpdateRectAck"); |
307 DCHECK(update_reply_pending()); | 333 DCHECK(update_reply_pending()); |
308 update_reply_pending_ = false; | 334 update_reply_pending_ = false; |
309 | 335 |
(...skipping 802 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1112 | 1138 |
1113 void RenderWidget::CleanupWindowInPluginMoves(gfx::PluginWindowHandle window) { | 1139 void RenderWidget::CleanupWindowInPluginMoves(gfx::PluginWindowHandle window) { |
1114 for (WebPluginGeometryVector::iterator i = plugin_window_moves_.begin(); | 1140 for (WebPluginGeometryVector::iterator i = plugin_window_moves_.begin(); |
1115 i != plugin_window_moves_.end(); ++i) { | 1141 i != plugin_window_moves_.end(); ++i) { |
1116 if (i->window == window) { | 1142 if (i->window == window) { |
1117 plugin_window_moves_.erase(i); | 1143 plugin_window_moves_.erase(i); |
1118 break; | 1144 break; |
1119 } | 1145 } |
1120 } | 1146 } |
1121 } | 1147 } |
OLD | NEW |