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/render_widget.h" | 5 #include "content/renderer/render_widget.h" |
6 | 6 |
7 #include <memory> | 7 #include <memory> |
8 #include <utility> | 8 #include <utility> |
9 | 9 |
10 #include "base/auto_reset.h" | 10 #include "base/auto_reset.h" |
(...skipping 191 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
202 << "blink::WebTextInputMode and ui::TextInputMode not synchronized"; | 202 << "blink::WebTextInputMode and ui::TextInputMode not synchronized"; |
203 return static_cast<ui::TextInputMode>(mode); | 203 return static_cast<ui::TextInputMode>(mode); |
204 } | 204 } |
205 | 205 |
206 } // namespace | 206 } // namespace |
207 | 207 |
208 namespace content { | 208 namespace content { |
209 | 209 |
210 // RenderWidget --------------------------------------------------------------- | 210 // RenderWidget --------------------------------------------------------------- |
211 | 211 |
212 RenderWidget::RenderWidget(CompositorDependencies* compositor_deps, | 212 RenderWidget::RenderWidget(int32_t widget_routing_id, |
| 213 CompositorDependencies* compositor_deps, |
213 blink::WebPopupType popup_type, | 214 blink::WebPopupType popup_type, |
214 const ScreenInfo& screen_info, | 215 const ScreenInfo& screen_info, |
215 bool swapped_out, | 216 bool swapped_out, |
216 bool hidden, | 217 bool hidden, |
217 bool never_visible) | 218 bool never_visible) |
218 : routing_id_(MSG_ROUTING_NONE), | 219 : routing_id_(widget_routing_id), |
219 compositor_deps_(compositor_deps), | 220 compositor_deps_(compositor_deps), |
220 webwidget_internal_(nullptr), | 221 webwidget_internal_(nullptr), |
221 owner_delegate_(nullptr), | 222 owner_delegate_(nullptr), |
222 opener_id_(MSG_ROUTING_NONE), | 223 opener_id_(MSG_ROUTING_NONE), |
223 next_paint_flags_(0), | 224 next_paint_flags_(0), |
224 auto_resize_mode_(false), | 225 auto_resize_mode_(false), |
225 need_update_rect_for_auto_resize_(false), | 226 need_update_rect_for_auto_resize_(false), |
226 did_show_(false), | 227 did_show_(false), |
227 is_hidden_(hidden), | 228 is_hidden_(hidden), |
228 compositor_never_visible_(never_visible), | 229 compositor_never_visible_(never_visible), |
(...skipping 19 matching lines...) Expand all Loading... |
248 monitor_composition_info_(false), | 249 monitor_composition_info_(false), |
249 popup_origin_scale_for_emulation_(0.f), | 250 popup_origin_scale_for_emulation_(0.f), |
250 frame_swap_message_queue_(new FrameSwapMessageQueue()), | 251 frame_swap_message_queue_(new FrameSwapMessageQueue()), |
251 resizing_mode_selector_(new ResizingModeSelector()), | 252 resizing_mode_selector_(new ResizingModeSelector()), |
252 has_host_context_menu_location_(false), | 253 has_host_context_menu_location_(false), |
253 has_focus_(false), | 254 has_focus_(false), |
254 #if defined(OS_MACOSX) | 255 #if defined(OS_MACOSX) |
255 text_input_client_observer_(new TextInputClientObserver(this)), | 256 text_input_client_observer_(new TextInputClientObserver(this)), |
256 #endif | 257 #endif |
257 focused_pepper_plugin_(nullptr) { | 258 focused_pepper_plugin_(nullptr) { |
| 259 DCHECK_NE(routing_id_, MSG_ROUTING_NONE); |
258 if (!swapped_out) | 260 if (!swapped_out) |
259 RenderProcess::current()->AddRefProcess(); | 261 RenderProcess::current()->AddRefProcess(); |
260 DCHECK(RenderThread::Get()); | 262 DCHECK(RenderThread::Get()); |
261 device_color_profile_.push_back('0'); | 263 device_color_profile_.push_back('0'); |
262 #if defined(OS_ANDROID) | 264 #if defined(OS_ANDROID) |
263 text_input_info_history_.push_back(blink::WebTextInputInfo()); | 265 text_input_info_history_.push_back(blink::WebTextInputInfo()); |
264 #endif | 266 #endif |
265 | 267 |
266 // In tests there may not be a RenderThreadImpl. | 268 // In tests there may not be a RenderThreadImpl. |
267 if (RenderThreadImpl::current()) { | 269 if (RenderThreadImpl::current()) { |
(...skipping 28 matching lines...) Expand all Loading... |
296 const ScreenInfo& screen_info) { | 298 const ScreenInfo& screen_info) { |
297 DCHECK(opener_id != MSG_ROUTING_NONE); | 299 DCHECK(opener_id != MSG_ROUTING_NONE); |
298 | 300 |
299 // Do a synchronous IPC to obtain a routing ID. | 301 // Do a synchronous IPC to obtain a routing ID. |
300 int32_t routing_id = MSG_ROUTING_NONE; | 302 int32_t routing_id = MSG_ROUTING_NONE; |
301 if (!RenderThreadImpl::current_render_message_filter()->CreateNewWidget( | 303 if (!RenderThreadImpl::current_render_message_filter()->CreateNewWidget( |
302 opener_id, popup_type, &routing_id)) { | 304 opener_id, popup_type, &routing_id)) { |
303 return nullptr; | 305 return nullptr; |
304 } | 306 } |
305 | 307 |
306 scoped_refptr<RenderWidget> widget(new RenderWidget( | 308 scoped_refptr<RenderWidget> widget( |
307 compositor_deps, popup_type, screen_info, false, false, false)); | 309 new RenderWidget(routing_id, compositor_deps, popup_type, screen_info, |
308 widget->InitRoutingID(routing_id); | 310 false, false, false)); |
309 widget->Init(opener_id, RenderWidget::CreateWebWidget(widget.get())); | 311 widget->Init(opener_id, RenderWidget::CreateWebWidget(widget.get())); |
310 DCHECK(!widget->HasOneRef()); // RenderWidget::Init() adds a reference. | 312 DCHECK(!widget->HasOneRef()); // RenderWidget::Init() adds a reference. |
311 return widget.get(); | 313 return widget.get(); |
312 } | 314 } |
313 | 315 |
314 // static | 316 // static |
315 RenderWidget* RenderWidget::CreateForFrame( | 317 RenderWidget* RenderWidget::CreateForFrame( |
316 int widget_routing_id, | 318 int widget_routing_id, |
317 bool hidden, | 319 bool hidden, |
318 const ScreenInfo& screen_info, | 320 const ScreenInfo& screen_info, |
319 CompositorDependencies* compositor_deps, | 321 CompositorDependencies* compositor_deps, |
320 blink::WebLocalFrame* frame) { | 322 blink::WebLocalFrame* frame) { |
321 CHECK_NE(widget_routing_id, MSG_ROUTING_NONE); | 323 CHECK_NE(widget_routing_id, MSG_ROUTING_NONE); |
322 // TODO(avi): Before RenderViewImpl has-a RenderWidget, the browser passes the | 324 // TODO(avi): Before RenderViewImpl has-a RenderWidget, the browser passes the |
323 // same routing ID for both the view routing ID and the main frame widget | 325 // same routing ID for both the view routing ID and the main frame widget |
324 // routing ID. https://crbug.com/545684 | 326 // routing ID. https://crbug.com/545684 |
325 RenderViewImpl* view = RenderViewImpl::FromRoutingID(widget_routing_id); | 327 RenderViewImpl* view = RenderViewImpl::FromRoutingID(widget_routing_id); |
326 if (view) { | 328 if (view) { |
327 view->AttachWebFrameWidget( | 329 view->AttachWebFrameWidget( |
328 RenderWidget::CreateWebFrameWidget(view->GetWidget(), frame)); | 330 RenderWidget::CreateWebFrameWidget(view->GetWidget(), frame)); |
329 return view->GetWidget(); | 331 return view->GetWidget(); |
330 } | 332 } |
331 scoped_refptr<RenderWidget> widget( | 333 scoped_refptr<RenderWidget> widget( |
332 g_create_render_widget | 334 g_create_render_widget |
333 ? g_create_render_widget(compositor_deps, blink::WebPopupTypeNone, | 335 ? g_create_render_widget(widget_routing_id, compositor_deps, |
334 screen_info, false, hidden, false) | 336 blink::WebPopupTypeNone, screen_info, false, |
335 : new RenderWidget(compositor_deps, blink::WebPopupTypeNone, | 337 hidden, false) |
336 screen_info, false, hidden, false)); | 338 : new RenderWidget(widget_routing_id, compositor_deps, |
| 339 blink::WebPopupTypeNone, screen_info, false, |
| 340 hidden, false)); |
337 widget->for_oopif_ = true; | 341 widget->for_oopif_ = true; |
338 // Init increments the reference count on |widget|, keeping it alive after | 342 // Init increments the reference count on |widget|, keeping it alive after |
339 // this function returns. | 343 // this function returns. |
340 widget->InitRoutingID(widget_routing_id); | |
341 widget->Init(MSG_ROUTING_NONE, | 344 widget->Init(MSG_ROUTING_NONE, |
342 RenderWidget::CreateWebFrameWidget(widget.get(), frame)); | 345 RenderWidget::CreateWebFrameWidget(widget.get(), frame)); |
343 | 346 |
344 if (g_render_widget_initialized) | 347 if (g_render_widget_initialized) |
345 g_render_widget_initialized(widget.get()); | 348 g_render_widget_initialized(widget.get()); |
346 return widget.get(); | 349 return widget.get(); |
347 } | 350 } |
348 | 351 |
349 // static | 352 // static |
350 blink::WebFrameWidget* RenderWidget::CreateWebFrameWidget( | 353 blink::WebFrameWidget* RenderWidget::CreateWebFrameWidget( |
(...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
382 | 385 |
383 // If we are swapping out, we will call ReleaseProcess, allowing the process | 386 // If we are swapping out, we will call ReleaseProcess, allowing the process |
384 // to exit if all of its RenderViews are swapped out. We wait until the | 387 // to exit if all of its RenderViews are swapped out. We wait until the |
385 // WasSwappedOut call to do this, to allow the unload handler to finish. | 388 // WasSwappedOut call to do this, to allow the unload handler to finish. |
386 // If we are swapping in, we call AddRefProcess to prevent the process from | 389 // If we are swapping in, we call AddRefProcess to prevent the process from |
387 // exiting. | 390 // exiting. |
388 if (!is_swapped_out_) | 391 if (!is_swapped_out_) |
389 RenderProcess::current()->AddRefProcess(); | 392 RenderProcess::current()->AddRefProcess(); |
390 } | 393 } |
391 | 394 |
392 void RenderWidget::InitRoutingID(int32_t routing_id) { | |
393 DCHECK_EQ(routing_id_, MSG_ROUTING_NONE); | |
394 routing_id_ = routing_id; | |
395 input_handler_.reset(new RenderWidgetInputHandler( | |
396 GetRenderWidgetInputHandlerDelegate(this), this)); | |
397 } | |
398 | |
399 void RenderWidget::Init(int32_t opener_id, WebWidget* web_widget) { | 395 void RenderWidget::Init(int32_t opener_id, WebWidget* web_widget) { |
400 DCHECK(!webwidget_internal_); | 396 DCHECK(!webwidget_internal_); |
401 DCHECK_NE(routing_id_, MSG_ROUTING_NONE); | 397 DCHECK_NE(routing_id_, MSG_ROUTING_NONE); |
402 | 398 |
| 399 input_handler_.reset(new RenderWidgetInputHandler( |
| 400 GetRenderWidgetInputHandlerDelegate(this), this)); |
| 401 |
403 if (opener_id != MSG_ROUTING_NONE) | 402 if (opener_id != MSG_ROUTING_NONE) |
404 opener_id_ = opener_id; | 403 opener_id_ = opener_id; |
405 | 404 |
406 webwidget_internal_ = web_widget; | 405 webwidget_internal_ = web_widget; |
407 webwidget_mouse_lock_target_.reset( | 406 webwidget_mouse_lock_target_.reset( |
408 new WebWidgetLockTarget(webwidget_internal_)); | 407 new WebWidgetLockTarget(webwidget_internal_)); |
409 mouse_lock_dispatcher_.reset(new RenderWidgetMouseLockDispatcher(this)); | 408 mouse_lock_dispatcher_.reset(new RenderWidgetMouseLockDispatcher(this)); |
410 | 409 |
411 RenderThread::Get()->AddRoute(routing_id_, this); | 410 RenderThread::Get()->AddRoute(routing_id_, this); |
412 // Take a reference on behalf of the RenderThread. This will be balanced | 411 // Take a reference on behalf of the RenderThread. This will be balanced |
(...skipping 1673 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2086 blink::WebInputMethodController* RenderWidget::GetInputMethodController() | 2085 blink::WebInputMethodController* RenderWidget::GetInputMethodController() |
2087 const { | 2086 const { |
2088 // TODO(ekaramad): Remove this CHECK when GetWebWidget() is | 2087 // TODO(ekaramad): Remove this CHECK when GetWebWidget() is |
2089 // always a WebFrameWidget. | 2088 // always a WebFrameWidget. |
2090 CHECK(GetWebWidget()->isWebFrameWidget()); | 2089 CHECK(GetWebWidget()->isWebFrameWidget()); |
2091 return static_cast<blink::WebFrameWidget*>(GetWebWidget()) | 2090 return static_cast<blink::WebFrameWidget*>(GetWebWidget()) |
2092 ->getActiveWebInputMethodController(); | 2091 ->getActiveWebInputMethodController(); |
2093 } | 2092 } |
2094 | 2093 |
2095 } // namespace content | 2094 } // namespace content |
OLD | NEW |