| OLD | NEW |
| (Empty) | |
| 1 // Copyright 2017 The Chromium Authors. All rights reserved. |
| 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. |
| 4 |
| 5 #include "content/renderer/input/frame_input_hit_test_impl.h" |
| 6 |
| 7 #include "base/bind.h" |
| 8 #include "base/debug/stack_trace.h" |
| 9 #include "base/logging.h" |
| 10 #include "content/renderer/render_widget.h" |
| 11 |
| 12 namespace content { |
| 13 |
| 14 FrameInputHitTestImpl::FrameInputHitTestImpl( |
| 15 base::WeakPtr<RenderFrameImpl> render_frame, |
| 16 viz::mojom::FrameInputHitTestRequest request) |
| 17 : binding_(this), |
| 18 render_frame_(render_frame), |
| 19 input_event_queue_(render_frame->GetRenderWidget()->GetInputEventQueue()), |
| 20 main_thread_task_runner_(base::ThreadTaskRunnerHandle::Get()), |
| 21 weak_ptr_factory_(this) |
| 22 |
| 23 { |
| 24 weak_this_ = weak_ptr_factory_.GetWeakPtr(); |
| 25 // If we have created an input event queue move the mojo request over to the |
| 26 // compositor thread. |
| 27 if (RenderThreadImpl::current()->compositor_task_runner() && |
| 28 input_event_queue_) { |
| 29 // Mojo channel bound on compositor thread. |
| 30 RenderThreadImpl::current()->compositor_task_runner()->PostTask( |
| 31 FROM_HERE, base::BindOnce(&FrameInputHitTestImpl::BindNow, |
| 32 base::Unretained(this), std::move(request))); |
| 33 } else { |
| 34 // Mojo channel bound on main thread. |
| 35 BindNow(std::move(request)); |
| 36 } |
| 37 } |
| 38 |
| 39 FrameInputHitTestImpl::~FrameInputHitTestImpl() {} |
| 40 |
| 41 // static |
| 42 void FrameInputHitTestImpl::CreateMojoService( |
| 43 base::WeakPtr<RenderFrameImpl> render_frame, |
| 44 viz::mojom::FrameInputHitTestRequest request) { |
| 45 DCHECK(render_frame); |
| 46 |
| 47 // Owns itself. Will be deleted when message pipe is destroyed. |
| 48 new FrameInputHitTestImpl(render_frame, std::move(request)); |
| 49 } |
| 50 |
| 51 void FrameInputHitTestImpl::RunOnMainThread(base::OnceClosure closure) { |
| 52 if (input_event_queue_) { |
| 53 input_event_queue_->QueueClosure(std::move(closure)); |
| 54 } else { |
| 55 std::move(closure).Run(); |
| 56 } |
| 57 } |
| 58 |
| 59 void FrameInputHitTestImpl::HitTestFrameAt(const gfx::Point& point, |
| 60 HitTestFrameAtCallback callback) { |
| 61 if (!main_thread_task_runner_->BelongsToCurrentThread()) { |
| 62 RunOnMainThread(base::BindOnce(&FrameInputHitTestImpl::HitTestOnMainThread, |
| 63 weak_this_, point, std::move(callback))); |
| 64 return; |
| 65 } |
| 66 if (!render_frame_) |
| 67 return; |
| 68 HitTestOnMainThread(point, std::move(callback)); |
| 69 } |
| 70 |
| 71 void FrameInputHitTestImpl::HitTestOnMainThread( |
| 72 const gfx::Point& point, |
| 73 HitTestFrameAtCallback callback) { |
| 74 std::move(callback).Run( |
| 75 render_frame_->GetRenderWidget()->HitTestFrameAt(point)); |
| 76 } |
| 77 |
| 78 void FrameInputHitTestImpl::Release() { |
| 79 if (!main_thread_task_runner_->BelongsToCurrentThread()) { |
| 80 // Close the binding on the compositor thread first before telling the main |
| 81 // thread to delete this object. |
| 82 binding_.Close(); |
| 83 main_thread_task_runner_->PostTask( |
| 84 FROM_HERE, base::Bind(&FrameInputHitTestImpl::Release, weak_this_)); |
| 85 return; |
| 86 } |
| 87 delete this; |
| 88 } |
| 89 |
| 90 void FrameInputHitTestImpl::BindNow( |
| 91 viz::mojom::FrameInputHitTestRequest request) { |
| 92 binding_.Bind(std::move(request)); |
| 93 binding_.set_connection_error_handler( |
| 94 base::Bind(&FrameInputHitTestImpl::Release, base::Unretained(this))); |
| 95 } |
| 96 |
| 97 } // namespace content |
| OLD | NEW |