Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(135)

Side by Side Diff: content/renderer/render_widget.cc

Issue 2813683002: Allow MainThreadEventQueue to call the RenderWidget directly. (Closed)
Patch Set: Fix style nits Created 3 years, 8 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « content/renderer/render_widget.h ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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 35 matching lines...) Expand 10 before | Expand all | Expand 10 after
46 #include "content/public/renderer/content_renderer_client.h" 46 #include "content/public/renderer/content_renderer_client.h"
47 #include "content/renderer/cursor_utils.h" 47 #include "content/renderer/cursor_utils.h"
48 #include "content/renderer/devtools/render_widget_screen_metrics_emulator.h" 48 #include "content/renderer/devtools/render_widget_screen_metrics_emulator.h"
49 #include "content/renderer/drop_data_builder.h" 49 #include "content/renderer/drop_data_builder.h"
50 #include "content/renderer/external_popup_menu.h" 50 #include "content/renderer/external_popup_menu.h"
51 #include "content/renderer/gpu/frame_swap_message_queue.h" 51 #include "content/renderer/gpu/frame_swap_message_queue.h"
52 #include "content/renderer/gpu/queue_message_swap_promise.h" 52 #include "content/renderer/gpu/queue_message_swap_promise.h"
53 #include "content/renderer/gpu/render_widget_compositor.h" 53 #include "content/renderer/gpu/render_widget_compositor.h"
54 #include "content/renderer/ime_event_guard.h" 54 #include "content/renderer/ime_event_guard.h"
55 #include "content/renderer/input/input_handler_manager.h" 55 #include "content/renderer/input/input_handler_manager.h"
56 #include "content/renderer/input/main_thread_event_queue.h"
56 #include "content/renderer/pepper/pepper_plugin_instance_impl.h" 57 #include "content/renderer/pepper/pepper_plugin_instance_impl.h"
57 #include "content/renderer/render_frame_impl.h" 58 #include "content/renderer/render_frame_impl.h"
58 #include "content/renderer/render_frame_proxy.h" 59 #include "content/renderer/render_frame_proxy.h"
59 #include "content/renderer/render_process.h" 60 #include "content/renderer/render_process.h"
60 #include "content/renderer/render_thread_impl.h" 61 #include "content/renderer/render_thread_impl.h"
61 #include "content/renderer/render_view_impl.h" 62 #include "content/renderer/render_view_impl.h"
62 #include "content/renderer/render_widget_owner_delegate.h" 63 #include "content/renderer/render_widget_owner_delegate.h"
63 #include "content/renderer/renderer_blink_platform_impl.h" 64 #include "content/renderer/renderer_blink_platform_impl.h"
64 #include "content/renderer/resizing_mode_selector.h" 65 #include "content/renderer/resizing_mode_selector.h"
65 #include "ipc/ipc_message_start.h" 66 #include "ipc/ipc_message_start.h"
(...skipping 328 matching lines...) Expand 10 before | Expand all | Expand 10 after
394 render_widget_scheduling_state_->SetHidden(is_hidden_); 395 render_widget_scheduling_state_->SetHidden(is_hidden_);
395 } 396 }
396 #if defined(USE_AURA) 397 #if defined(USE_AURA)
397 RendererWindowTreeClient::CreateIfNecessary(routing_id_); 398 RendererWindowTreeClient::CreateIfNecessary(routing_id_);
398 #endif 399 #endif
399 } 400 }
400 401
401 RenderWidget::~RenderWidget() { 402 RenderWidget::~RenderWidget() {
402 DCHECK(!webwidget_internal_) << "Leaking our WebWidget!"; 403 DCHECK(!webwidget_internal_) << "Leaking our WebWidget!";
403 404
405 if (input_event_queue_)
406 input_event_queue_->ClearClient();
407
404 // If we are swapped out, we have released already. 408 // If we are swapped out, we have released already.
405 if (!is_swapped_out_ && RenderProcess::current()) 409 if (!is_swapped_out_ && RenderProcess::current())
406 RenderProcess::current()->ReleaseProcess(); 410 RenderProcess::current()->ReleaseProcess();
407 #if defined(USE_AURA) 411 #if defined(USE_AURA)
408 // It is possible for a RenderWidget to be destroyed before it was embedded 412 // It is possible for a RenderWidget to be destroyed before it was embedded
409 // in a mus window. The RendererWindowTreeClient will leak in such cases. So 413 // in a mus window. The RendererWindowTreeClient will leak in such cases. So
410 // explicitly delete it here. 414 // explicitly delete it here.
411 RendererWindowTreeClient::Destroy(routing_id_); 415 RendererWindowTreeClient::Destroy(routing_id_);
412 #endif 416 #endif
413 } 417 }
(...skipping 397 matching lines...) Expand 10 before | Expand all | Expand 10 after
811 const ui::LatencyInfo& latency_info, 815 const ui::LatencyInfo& latency_info,
812 InputEventDispatchType dispatch_type) { 816 InputEventDispatchType dispatch_type) {
813 if (!input_event) 817 if (!input_event)
814 return; 818 return;
815 819
816 input_handler_->HandleInputEvent( 820 input_handler_->HandleInputEvent(
817 blink::WebCoalescedInputEvent(*input_event, coalesced_events), 821 blink::WebCoalescedInputEvent(*input_event, coalesced_events),
818 latency_info, dispatch_type); 822 latency_info, dispatch_type);
819 } 823 }
820 824
825 InputEventAckState RenderWidget::HandleInputEvent(
826 const blink::WebCoalescedInputEvent& input_event,
827 const ui::LatencyInfo& latency_info,
828 InputEventDispatchType dispatch_type) {
829 return input_handler_->HandleInputEvent(input_event, latency_info,
830 dispatch_type);
831 }
832
833 void RenderWidget::SendInputEventAck(blink::WebInputEvent::Type type,
834 InputEventAckState ack_result,
835 uint32_t touch_event_id) {
836 InputEventAck ack(InputEventAckSource::MAIN_THREAD, type, ack_result,
837 touch_event_id);
838 Send(new InputHostMsg_HandleInputEvent_ACK(routing_id_, ack));
839 }
840
821 void RenderWidget::OnCursorVisibilityChange(bool is_visible) { 841 void RenderWidget::OnCursorVisibilityChange(bool is_visible) {
822 if (GetWebWidget()) 842 if (GetWebWidget())
823 GetWebWidget()->SetCursorVisibilityState(is_visible); 843 GetWebWidget()->SetCursorVisibilityState(is_visible);
824 } 844 }
825 845
826 void RenderWidget::OnMouseCaptureLost() { 846 void RenderWidget::OnMouseCaptureLost() {
827 if (GetWebWidget()) 847 if (GetWebWidget())
828 GetWebWidget()->MouseCaptureLost(); 848 GetWebWidget()->MouseCaptureLost();
829 } 849 }
830 850
(...skipping 34 matching lines...) Expand 10 before | Expand all | Expand 10 after
865 } 885 }
866 886
867 void RenderWidget::RecordWheelAndTouchScrollingCount( 887 void RenderWidget::RecordWheelAndTouchScrollingCount(
868 bool has_scrolled_by_wheel, 888 bool has_scrolled_by_wheel,
869 bool has_scrolled_by_touch) { 889 bool has_scrolled_by_touch) {
870 GetWebWidget()->RecordWheelAndTouchScrollingCount(has_scrolled_by_wheel, 890 GetWebWidget()->RecordWheelAndTouchScrollingCount(has_scrolled_by_wheel,
871 has_scrolled_by_touch); 891 has_scrolled_by_touch);
872 } 892 }
873 893
874 void RenderWidget::BeginMainFrame(double frame_time_sec) { 894 void RenderWidget::BeginMainFrame(double frame_time_sec) {
875 RenderThreadImpl* render_thread = RenderThreadImpl::current(); 895 if (input_event_queue_) {
876 // render_thread may be NULL in tests. 896 input_event_queue_->DispatchRafAlignedInput(
877 InputHandlerManager* input_handler_manager = 897 ui::EventTimeStampFromSeconds(frame_time_sec));
878 render_thread ? render_thread->input_handler_manager() : NULL; 898 }
879 if (input_handler_manager)
880 input_handler_manager->ProcessRafAlignedInputOnMainThread(
881 routing_id_, ui::EventTimeStampFromSeconds(frame_time_sec));
882 899
883 GetWebWidget()->BeginFrame(frame_time_sec); 900 GetWebWidget()->BeginFrame(frame_time_sec);
884 } 901 }
885 902
886 void RenderWidget::RequestNewCompositorFrameSink( 903 void RenderWidget::RequestNewCompositorFrameSink(
887 bool fallback, 904 bool fallback,
888 const CompositorFrameSinkCallback& callback) { 905 const CompositorFrameSinkCallback& callback) {
889 DCHECK(GetWebWidget()); 906 DCHECK(GetWebWidget());
890 // For widgets that are never visible, we don't start the compositor, so we 907 // For widgets that are never visible, we don't start the compositor, so we
891 // never get a request for a cc::CompositorFrameSink. 908 // never get a request for a cc::CompositorFrameSink.
(...skipping 146 matching lines...) Expand 10 before | Expand all | Expand 10 after
1038 void RenderWidget::OnDidOverscroll(const ui::DidOverscrollParams& params) { 1055 void RenderWidget::OnDidOverscroll(const ui::DidOverscrollParams& params) {
1039 Send(new InputHostMsg_DidOverscroll(routing_id_, params)); 1056 Send(new InputHostMsg_DidOverscroll(routing_id_, params));
1040 } 1057 }
1041 1058
1042 void RenderWidget::OnInputEventAck( 1059 void RenderWidget::OnInputEventAck(
1043 std::unique_ptr<InputEventAck> input_event_ack) { 1060 std::unique_ptr<InputEventAck> input_event_ack) {
1044 SendOrCrash( 1061 SendOrCrash(
1045 new InputHostMsg_HandleInputEvent_ACK(routing_id_, *input_event_ack)); 1062 new InputHostMsg_HandleInputEvent_ACK(routing_id_, *input_event_ack));
1046 } 1063 }
1047 1064
1048 void RenderWidget::NotifyInputEventHandled(
1049 blink::WebInputEvent::Type handled_type,
1050 blink::WebInputEventResult result,
1051 InputEventAckState ack_result) {
1052 RenderThreadImpl* render_thread = RenderThreadImpl::current();
1053 InputHandlerManager* input_handler_manager =
1054 render_thread ? render_thread->input_handler_manager() : NULL;
1055 if (input_handler_manager) {
1056 input_handler_manager->NotifyInputEventHandledOnMainThread(
1057 routing_id_, handled_type, result, ack_result);
1058 }
1059 }
1060
1061 void RenderWidget::SetInputHandler(RenderWidgetInputHandler* input_handler) { 1065 void RenderWidget::SetInputHandler(RenderWidgetInputHandler* input_handler) {
1062 // Nothing to do here. RenderWidget created the |input_handler| and will take 1066 // Nothing to do here. RenderWidget created the |input_handler| and will take
1063 // ownership of it. We just verify here that we don't already have an input 1067 // ownership of it. We just verify here that we don't already have an input
1064 // handler. 1068 // handler.
1065 DCHECK(!input_handler_); 1069 DCHECK(!input_handler_);
1066 } 1070 }
1067 1071
1068 void RenderWidget::ShowVirtualKeyboard() { 1072 void RenderWidget::ShowVirtualKeyboard() {
1069 UpdateTextInputStateInternal(true, false); 1073 UpdateTextInputStateInternal(true, false);
1070 } 1074 }
(...skipping 243 matching lines...) Expand 10 before | Expand all | Expand 10 after
1314 StartCompositor(); 1318 StartCompositor();
1315 DCHECK_NE(MSG_ROUTING_NONE, routing_id_); 1319 DCHECK_NE(MSG_ROUTING_NONE, routing_id_);
1316 compositor_->SetFrameSinkId( 1320 compositor_->SetFrameSinkId(
1317 cc::FrameSinkId(RenderThread::Get()->GetClientId(), routing_id_)); 1321 cc::FrameSinkId(RenderThread::Get()->GetClientId(), routing_id_));
1318 1322
1319 RenderThreadImpl* render_thread = RenderThreadImpl::current(); 1323 RenderThreadImpl* render_thread = RenderThreadImpl::current();
1320 // render_thread may be NULL in tests. 1324 // render_thread may be NULL in tests.
1321 InputHandlerManager* input_handler_manager = 1325 InputHandlerManager* input_handler_manager =
1322 render_thread ? render_thread->input_handler_manager() : NULL; 1326 render_thread ? render_thread->input_handler_manager() : NULL;
1323 if (input_handler_manager) { 1327 if (input_handler_manager) {
1328 input_event_queue_ = new MainThreadEventQueue(
1329 this, render_thread->GetRendererScheduler()->CompositorTaskRunner(),
1330 render_thread->GetRendererScheduler());
1324 input_handler_manager->AddInputHandler( 1331 input_handler_manager->AddInputHandler(
1325 routing_id_, compositor()->GetInputHandler(), 1332 routing_id_, compositor()->GetInputHandler(), input_event_queue_,
1326 weak_ptr_factory_.GetWeakPtr(), 1333 weak_ptr_factory_.GetWeakPtr(),
1327 compositor_deps_->IsScrollAnimatorEnabled()); 1334 compositor_deps_->IsScrollAnimatorEnabled());
1328 has_added_input_handler_ = true; 1335 has_added_input_handler_ = true;
1329 } 1336 }
1330 1337
1331 return compositor_.get(); 1338 return compositor_.get();
1332 } 1339 }
1333 1340
1334 void RenderWidget::WillCloseLayerTreeView() { 1341 void RenderWidget::WillCloseLayerTreeView() {
1335 if (host_closing_) 1342 if (host_closing_)
(...skipping 987 matching lines...) Expand 10 before | Expand all | Expand 10 after
2323 // browser side (https://crbug.com/669219). 2330 // browser side (https://crbug.com/669219).
2324 // If there is no WebFrameWidget, then there will be no 2331 // If there is no WebFrameWidget, then there will be no
2325 // InputMethodControllers for a WebLocalFrame. 2332 // InputMethodControllers for a WebLocalFrame.
2326 return nullptr; 2333 return nullptr;
2327 } 2334 }
2328 return static_cast<blink::WebFrameWidget*>(GetWebWidget()) 2335 return static_cast<blink::WebFrameWidget*>(GetWebWidget())
2329 ->GetActiveWebInputMethodController(); 2336 ->GetActiveWebInputMethodController();
2330 } 2337 }
2331 2338
2332 } // namespace content 2339 } // namespace content
OLDNEW
« no previous file with comments | « content/renderer/render_widget.h ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698