1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
content / public / test / context_menu_interceptor.cc [blame]
// Copyright 2024 The Chromium Authors
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
#include "content/public/test/context_menu_interceptor.h"
#include "content/browser/renderer_host/render_frame_host_impl.h"
#include "content/public/browser/browser_thread.h"
#include "testing/gtest/include/gtest/gtest.h"
namespace content {
ContextMenuInterceptor::ContextMenuInterceptor(
content::RenderFrameHost* render_frame_host,
ShowBehavior behavior)
: swapped_impl_(RenderFrameHostImpl::From(render_frame_host)
->local_frame_host_receiver_for_testing(),
this),
run_loop_(std::make_unique<base::RunLoop>()),
quit_closure_(run_loop_->QuitClosure()),
show_behavior_(behavior) {}
ContextMenuInterceptor::~ContextMenuInterceptor() = default;
void ContextMenuInterceptor::Wait() {
DCHECK_CURRENTLY_ON(BrowserThread::UI);
run_loop_->Run();
run_loop_ = nullptr;
}
void ContextMenuInterceptor::Reset() {
ASSERT_EQ(run_loop_, nullptr);
run_loop_ = std::make_unique<base::RunLoop>();
quit_closure_ = run_loop_->QuitClosure();
}
blink::mojom::LocalFrameHost* ContextMenuInterceptor::GetForwardingInterface() {
return swapped_impl_.old_impl();
}
void ContextMenuInterceptor::ShowContextMenu(
mojo::PendingAssociatedRemote<blink::mojom::ContextMenuClient>
context_menu_client,
const blink::UntrustworthyContextMenuParams& params) {
DCHECK_CURRENTLY_ON(BrowserThread::UI);
last_params_ = params;
std::move(quit_closure_).Run();
if (show_behavior_ == ShowBehavior::kPreventShow) {
return;
}
GetForwardingInterface()->ShowContextMenu(std::move(context_menu_client),
params);
}
} // namespace content