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 202 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
213 CompositorDependencies* compositor_deps, | 213 CompositorDependencies* compositor_deps, |
214 blink::WebPopupType popup_type, | 214 blink::WebPopupType popup_type, |
215 const ScreenInfo& screen_info, | 215 const ScreenInfo& screen_info, |
216 bool swapped_out, | 216 bool swapped_out, |
217 bool hidden, | 217 bool hidden, |
218 bool never_visible) | 218 bool never_visible) |
219 : routing_id_(widget_routing_id), | 219 : routing_id_(widget_routing_id), |
220 compositor_deps_(compositor_deps), | 220 compositor_deps_(compositor_deps), |
221 webwidget_internal_(nullptr), | 221 webwidget_internal_(nullptr), |
222 owner_delegate_(nullptr), | 222 owner_delegate_(nullptr), |
223 opener_id_(MSG_ROUTING_NONE), | |
224 next_paint_flags_(0), | 223 next_paint_flags_(0), |
225 auto_resize_mode_(false), | 224 auto_resize_mode_(false), |
226 need_update_rect_for_auto_resize_(false), | 225 need_update_rect_for_auto_resize_(false), |
227 did_show_(false), | 226 did_show_(false), |
228 is_hidden_(hidden), | 227 is_hidden_(hidden), |
229 compositor_never_visible_(never_visible), | 228 compositor_never_visible_(never_visible), |
230 is_fullscreen_granted_(false), | 229 is_fullscreen_granted_(false), |
231 display_mode_(blink::WebDisplayModeUndefined), | 230 display_mode_(blink::WebDisplayModeUndefined), |
232 ime_event_guard_(nullptr), | 231 ime_event_guard_(nullptr), |
233 closing_(false), | 232 closing_(false), |
(...skipping 51 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
285 // static | 284 // static |
286 void RenderWidget::InstallCreateHook( | 285 void RenderWidget::InstallCreateHook( |
287 CreateRenderWidgetFunction create_render_widget, | 286 CreateRenderWidgetFunction create_render_widget, |
288 RenderWidgetInitializedCallback render_widget_initialized) { | 287 RenderWidgetInitializedCallback render_widget_initialized) { |
289 CHECK(!g_create_render_widget && !g_render_widget_initialized); | 288 CHECK(!g_create_render_widget && !g_render_widget_initialized); |
290 g_create_render_widget = create_render_widget; | 289 g_create_render_widget = create_render_widget; |
291 g_render_widget_initialized = render_widget_initialized; | 290 g_render_widget_initialized = render_widget_initialized; |
292 } | 291 } |
293 | 292 |
294 // static | 293 // static |
295 RenderWidget* RenderWidget::Create(int32_t opener_id, | 294 RenderWidget* RenderWidget::CreateForPopup( |
296 CompositorDependencies* compositor_deps, | 295 RenderViewImpl* opener, |
297 blink::WebPopupType popup_type, | 296 CompositorDependencies* compositor_deps, |
298 const ScreenInfo& screen_info) { | 297 blink::WebPopupType popup_type, |
299 DCHECK(opener_id != MSG_ROUTING_NONE); | 298 const ScreenInfo& screen_info) { |
300 | |
301 // Do a synchronous IPC to obtain a routing ID. | 299 // Do a synchronous IPC to obtain a routing ID. |
302 int32_t routing_id = MSG_ROUTING_NONE; | 300 int32_t routing_id = MSG_ROUTING_NONE; |
303 if (!RenderThreadImpl::current_render_message_filter()->CreateNewWidget( | 301 if (!RenderThreadImpl::current_render_message_filter()->CreateNewWidget( |
304 opener_id, popup_type, &routing_id)) { | 302 opener->GetRoutingID(), popup_type, &routing_id)) { |
305 return nullptr; | 303 return nullptr; |
306 } | 304 } |
307 | 305 |
308 scoped_refptr<RenderWidget> widget( | 306 scoped_refptr<RenderWidget> widget( |
309 new RenderWidget(routing_id, compositor_deps, popup_type, screen_info, | 307 new RenderWidget(routing_id, compositor_deps, popup_type, screen_info, |
310 false, false, false)); | 308 false, false, false)); |
311 widget->Init(opener_id, RenderWidget::CreateWebWidget(widget.get())); | 309 ShowCallback opener_callback = |
| 310 base::Bind(&RenderViewImpl::ShowCreatedPopupWidget, opener->AsWeakPtr()); |
| 311 widget->Init(opener_callback, RenderWidget::CreateWebWidget(widget.get())); |
312 DCHECK(!widget->HasOneRef()); // RenderWidget::Init() adds a reference. | 312 DCHECK(!widget->HasOneRef()); // RenderWidget::Init() adds a reference. |
313 return widget.get(); | 313 return widget.get(); |
314 } | 314 } |
315 | 315 |
316 // static | 316 // static |
317 RenderWidget* RenderWidget::CreateForFrame( | 317 RenderWidget* RenderWidget::CreateForFrame( |
318 int widget_routing_id, | 318 int widget_routing_id, |
319 bool hidden, | 319 bool hidden, |
320 const ScreenInfo& screen_info, | 320 const ScreenInfo& screen_info, |
321 CompositorDependencies* compositor_deps, | 321 CompositorDependencies* compositor_deps, |
(...skipping 12 matching lines...) Expand all Loading... |
334 g_create_render_widget | 334 g_create_render_widget |
335 ? g_create_render_widget(widget_routing_id, compositor_deps, | 335 ? g_create_render_widget(widget_routing_id, compositor_deps, |
336 blink::WebPopupTypeNone, screen_info, false, | 336 blink::WebPopupTypeNone, screen_info, false, |
337 hidden, false) | 337 hidden, false) |
338 : new RenderWidget(widget_routing_id, compositor_deps, | 338 : new RenderWidget(widget_routing_id, compositor_deps, |
339 blink::WebPopupTypeNone, screen_info, false, | 339 blink::WebPopupTypeNone, screen_info, false, |
340 hidden, false)); | 340 hidden, false)); |
341 widget->for_oopif_ = true; | 341 widget->for_oopif_ = true; |
342 // Init increments the reference count on |widget|, keeping it alive after | 342 // Init increments the reference count on |widget|, keeping it alive after |
343 // this function returns. | 343 // this function returns. |
344 widget->Init(MSG_ROUTING_NONE, | 344 widget->Init(RenderWidget::ShowCallback(), |
345 RenderWidget::CreateWebFrameWidget(widget.get(), frame)); | 345 RenderWidget::CreateWebFrameWidget(widget.get(), frame)); |
346 | 346 |
347 if (g_render_widget_initialized) | 347 if (g_render_widget_initialized) |
348 g_render_widget_initialized(widget.get()); | 348 g_render_widget_initialized(widget.get()); |
349 return widget.get(); | 349 return widget.get(); |
350 } | 350 } |
351 | 351 |
352 // static | 352 // static |
353 blink::WebFrameWidget* RenderWidget::CreateWebFrameWidget( | 353 blink::WebFrameWidget* RenderWidget::CreateWebFrameWidget( |
354 RenderWidget* render_widget, | 354 RenderWidget* render_widget, |
(...skipping 30 matching lines...) Expand all Loading... |
385 | 385 |
386 // 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 |
387 // 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 |
388 // 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. |
389 // 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 |
390 // exiting. | 390 // exiting. |
391 if (!is_swapped_out_) | 391 if (!is_swapped_out_) |
392 RenderProcess::current()->AddRefProcess(); | 392 RenderProcess::current()->AddRefProcess(); |
393 } | 393 } |
394 | 394 |
395 void RenderWidget::Init(int32_t opener_id, WebWidget* web_widget) { | 395 void RenderWidget::Init(const ShowCallback& show_callback, |
| 396 WebWidget* web_widget) { |
396 DCHECK(!webwidget_internal_); | 397 DCHECK(!webwidget_internal_); |
397 DCHECK_NE(routing_id_, MSG_ROUTING_NONE); | 398 DCHECK_NE(routing_id_, MSG_ROUTING_NONE); |
398 | 399 |
399 input_handler_.reset(new RenderWidgetInputHandler( | 400 input_handler_.reset(new RenderWidgetInputHandler( |
400 GetRenderWidgetInputHandlerDelegate(this), this)); | 401 GetRenderWidgetInputHandlerDelegate(this), this)); |
401 | 402 |
402 if (opener_id != MSG_ROUTING_NONE) | 403 show_callback_ = show_callback; |
403 opener_id_ = opener_id; | |
404 | 404 |
405 webwidget_internal_ = web_widget; | 405 webwidget_internal_ = web_widget; |
406 webwidget_mouse_lock_target_.reset( | 406 webwidget_mouse_lock_target_.reset( |
407 new WebWidgetLockTarget(webwidget_internal_)); | 407 new WebWidgetLockTarget(webwidget_internal_)); |
408 mouse_lock_dispatcher_.reset(new RenderWidgetMouseLockDispatcher(this)); | 408 mouse_lock_dispatcher_.reset(new RenderWidgetMouseLockDispatcher(this)); |
409 | 409 |
410 RenderThread::Get()->AddRoute(routing_id_, this); | 410 RenderThread::Get()->AddRoute(routing_id_, this); |
411 // 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 |
412 // when we receive ViewMsg_Close. | 412 // when we receive ViewMsg_Close. |
413 AddRef(); | 413 AddRef(); |
(...skipping 795 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1209 } | 1209 } |
1210 } | 1210 } |
1211 | 1211 |
1212 // We are supposed to get a single call to Show for a newly created RenderWidget | 1212 // We are supposed to get a single call to Show for a newly created RenderWidget |
1213 // that was created via RenderWidget::CreateWebView. So, we wait until this | 1213 // that was created via RenderWidget::CreateWebView. So, we wait until this |
1214 // point to dispatch the ShowWidget message. | 1214 // point to dispatch the ShowWidget message. |
1215 // | 1215 // |
1216 // This method provides us with the information about how to display the newly | 1216 // This method provides us with the information about how to display the newly |
1217 // created RenderWidget (i.e., as a blocked popup or as a new tab). | 1217 // created RenderWidget (i.e., as a blocked popup or as a new tab). |
1218 // | 1218 // |
1219 void RenderWidget::show(WebNavigationPolicy) { | 1219 void RenderWidget::show(WebNavigationPolicy policy) { |
1220 DCHECK(!did_show_) << "received extraneous Show call"; | 1220 DCHECK(!did_show_) << "received extraneous Show call"; |
1221 DCHECK(routing_id_ != MSG_ROUTING_NONE); | 1221 DCHECK(routing_id_ != MSG_ROUTING_NONE); |
1222 DCHECK(opener_id_ != MSG_ROUTING_NONE); | 1222 DCHECK(!show_callback_.is_null()); |
1223 | 1223 |
1224 if (did_show_) | 1224 if (did_show_) |
1225 return; | 1225 return; |
1226 | 1226 |
1227 did_show_ = true; | 1227 did_show_ = true; |
| 1228 |
| 1229 // The opener is responsible for actually showing this widget. |
| 1230 show_callback_.Run(this, policy, initial_rect_); |
| 1231 |
1228 // NOTE: initial_rect_ may still have its default values at this point, but | 1232 // NOTE: initial_rect_ may still have its default values at this point, but |
1229 // that's okay. It'll be ignored if as_popup is false, or the browser | 1233 // that's okay. It'll be ignored if as_popup is false, or the browser |
1230 // process will impose a default position otherwise. | 1234 // process will impose a default position otherwise. |
1231 Send(new ViewHostMsg_ShowWidget(opener_id_, routing_id_, initial_rect_)); | |
1232 SetPendingWindowRect(initial_rect_); | 1235 SetPendingWindowRect(initial_rect_); |
1233 } | 1236 } |
1234 | 1237 |
1235 void RenderWidget::DoDeferredClose() { | 1238 void RenderWidget::DoDeferredClose() { |
1236 WillCloseLayerTreeView(); | 1239 WillCloseLayerTreeView(); |
1237 Send(new ViewHostMsg_Close(routing_id_)); | 1240 Send(new ViewHostMsg_Close(routing_id_)); |
1238 } | 1241 } |
1239 | 1242 |
1240 void RenderWidget::NotifyOnClose() { | 1243 void RenderWidget::NotifyOnClose() { |
1241 for (auto& observer : render_frames_) | 1244 for (auto& observer : render_frames_) |
(...skipping 843 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2085 blink::WebInputMethodController* RenderWidget::GetInputMethodController() | 2088 blink::WebInputMethodController* RenderWidget::GetInputMethodController() |
2086 const { | 2089 const { |
2087 // TODO(ekaramad): Remove this CHECK when GetWebWidget() is | 2090 // TODO(ekaramad): Remove this CHECK when GetWebWidget() is |
2088 // always a WebFrameWidget. | 2091 // always a WebFrameWidget. |
2089 CHECK(GetWebWidget()->isWebFrameWidget()); | 2092 CHECK(GetWebWidget()->isWebFrameWidget()); |
2090 return static_cast<blink::WebFrameWidget*>(GetWebWidget()) | 2093 return static_cast<blink::WebFrameWidget*>(GetWebWidget()) |
2091 ->getActiveWebInputMethodController(); | 2094 ->getActiveWebInputMethodController(); |
2092 } | 2095 } |
2093 | 2096 |
2094 } // namespace content | 2097 } // namespace content |
OLD | NEW |