forked from CCBlueX/java-cef
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathcontext_menu_handler.cpp
More file actions
94 lines (78 loc) · 2.9 KB
/
context_menu_handler.cpp
File metadata and controls
94 lines (78 loc) · 2.9 KB
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
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
// Copyright (c) 2014 The Chromium Embedded Framework Authors. All rights
// reserved. Use of this source code is governed by a BSD-style license that
// can be found in the LICENSE file.
#include "context_menu_handler.h"
#include "jni_util.h"
namespace {
// JNI CefContextMenuParams object.
class ScopedJNIContextMenuParams
: public ScopedJNIObject<CefContextMenuParams> {
public:
ScopedJNIContextMenuParams(JNIEnv* env, CefRefPtr<CefContextMenuParams> obj)
: ScopedJNIObject<CefContextMenuParams>(
env,
obj,
"org/cef/callback/CefContextMenuParams_N",
"CefContextMenuParams") {}
};
} // namespace
ContextMenuHandler::ContextMenuHandler(JNIEnv* env, jobject handler)
: handle_(env, handler) {}
void ContextMenuHandler::OnBeforeContextMenu(
CefRefPtr<CefBrowser> browser,
CefRefPtr<CefFrame> frame,
CefRefPtr<CefContextMenuParams> params,
CefRefPtr<CefMenuModel> model) {
ScopedJNIEnv env;
if (!env)
return;
ScopedJNIBrowser jbrowser(env, browser);
ScopedJNIFrame jframe(env, frame);
jframe.SetTemporary();
ScopedJNIContextMenuParams jparams(env, params);
jparams.SetTemporary();
ScopedJNIMenuModel jmodel(env, model);
jmodel.SetTemporary();
JNI_CALL_VOID_METHOD(env, handle_, "onBeforeContextMenu",
"(Lorg/cef/browser/CefBrowser;Lorg/cef/browser/"
"CefFrame;Lorg/cef/callback/CefContextMenuParams;"
"Lorg/cef/callback/CefMenuModel;)V",
jbrowser.get(), jframe.get(), jparams.get(),
jmodel.get());
}
bool ContextMenuHandler::OnContextMenuCommand(
CefRefPtr<CefBrowser> browser,
CefRefPtr<CefFrame> frame,
CefRefPtr<CefContextMenuParams> params,
int command_id,
EventFlags event_flags) {
ScopedJNIEnv env;
if (!env)
return false;
ScopedJNIBrowser jbrowser(env, browser);
ScopedJNIFrame jframe(env, frame);
jframe.SetTemporary();
ScopedJNIContextMenuParams jparams(env, params);
jparams.SetTemporary();
jboolean result = JNI_FALSE;
JNI_CALL_METHOD(env, handle_, "onContextMenuCommand",
"(Lorg/cef/browser/CefBrowser;Lorg/cef/browser/CefFrame;Lorg/"
"cef/callback/"
"CefContextMenuParams;II)Z",
Boolean, result, jbrowser.get(), jframe.get(), jparams.get(),
(jint)command_id, (jint)event_flags);
return (result != JNI_FALSE);
}
void ContextMenuHandler::OnContextMenuDismissed(CefRefPtr<CefBrowser> browser,
CefRefPtr<CefFrame> frame) {
ScopedJNIEnv env;
if (!env)
return;
ScopedJNIBrowser jbrowser(env, browser);
ScopedJNIFrame jframe(env, frame);
jframe.SetTemporary();
JNI_CALL_VOID_METHOD(
env, handle_, "onContextMenuDismissed",
"(Lorg/cef/browser/CefBrowser;Lorg/cef/browser/CefFrame;)V",
jbrowser.get(), jframe.get());
}