Skip to content

Commit e8e7b82

Browse files
committed
Convert plugin-related classes to use scoped helpers (see issue chromiumembedded#167)
- CefWebPluginManager does not need to implement CefNative.
1 parent b6f6993 commit e8e7b82

11 files changed

+103
-101
lines changed

java/org/cef/callback/CefWebPluginInfoVisitor.java

Lines changed: 10 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -7,15 +7,19 @@
77
import org.cef.network.CefWebPluginInfo;
88

99
/**
10-
* Interface to implement for visiting web plugin information. The methods of
11-
* this class will be called on the browser process UI thread.
10+
* Interface to implement for visiting web plugin information. The methods of this class will be
11+
* called on the browser process UI thread.
1212
*/
1313
public interface CefWebPluginInfoVisitor {
1414
/**
15-
* Method that will be called once for each plugin. |count| is the 0-based
16-
* index for the current plugin. |total| is the total number of plugins.
17-
* Return false to stop visiting plugins. This method may never be called if
18-
* no plugins are found.
15+
* Method that will be called once for each plugin. This method may never be called if no
16+
* plugins are found.
17+
*
18+
* @param info Information for the current plugin. Instance only valid within the scope of this
19+
* method.
20+
* @param count The 0-based index for the current plugin.
21+
* @param total The total number of plugins.
22+
* @return True to continue visiting plugins or false to stop.
1923
*/
2024
public boolean visit(CefWebPluginInfo info, int count, int total);
2125
}

java/org/cef/callback/CefWebPluginUnstableCallback.java

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -5,14 +5,16 @@
55
package org.cef.callback;
66

77
/**
8-
* Interface to implement for receiving unstable plugin information. The methods
9-
* of this class will be called on the browser process IO thread.
8+
* Interface to implement for receiving unstable plugin information. The methods of this class will
9+
* be called on the browser process IO thread.
1010
*/
1111
public interface CefWebPluginUnstableCallback {
1212
/**
13-
* Method that will be called for the requested plugin. |unstable| will be
14-
* true if the plugin has reached the crash count threshold of 3 times in 120
15-
* seconds.
13+
* Method that will be called for the requested plugin.
14+
*
15+
* @param path Plugin file path (DLL/bundle/library).
16+
* @param unstable True if the plugin has reached the crash count threshold of 3 times in 120
17+
* seconds.
1618
*/
1719
public void isUnstable(String path, boolean unstable);
1820
}

java/org/cef/network/CefWebPluginInfo_N.java

Lines changed: 10 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -7,10 +7,12 @@
77
import org.cef.callback.CefNativeAdapter;
88

99
class CefWebPluginInfo_N extends CefNativeAdapter implements CefWebPluginInfo {
10+
CefWebPluginInfo_N() {}
11+
1012
@Override
1113
public String getName() {
1214
try {
13-
return N_GetName();
15+
return N_GetName(getNativeRef(null));
1416
} catch (UnsatisfiedLinkError ule) {
1517
ule.printStackTrace();
1618
}
@@ -20,7 +22,7 @@ public String getName() {
2022
@Override
2123
public String getPath() {
2224
try {
23-
return N_GetPath();
25+
return N_GetPath(getNativeRef(null));
2426
} catch (UnsatisfiedLinkError ule) {
2527
ule.printStackTrace();
2628
}
@@ -30,7 +32,7 @@ public String getPath() {
3032
@Override
3133
public String getVersion() {
3234
try {
33-
return N_GetVersion();
35+
return N_GetVersion(getNativeRef(null));
3436
} catch (UnsatisfiedLinkError ule) {
3537
ule.printStackTrace();
3638
}
@@ -40,15 +42,15 @@ public String getVersion() {
4042
@Override
4143
public String getDescription() {
4244
try {
43-
return N_GetDescription();
45+
return N_GetDescription(getNativeRef(null));
4446
} catch (UnsatisfiedLinkError ule) {
4547
ule.printStackTrace();
4648
}
4749
return null;
4850
}
4951

50-
private final native String N_GetName();
51-
private final native String N_GetPath();
52-
private final native String N_GetVersion();
53-
private final native String N_GetDescription();
52+
private final native String N_GetName(long self);
53+
private final native String N_GetPath(long self);
54+
private final native String N_GetVersion(long self);
55+
private final native String N_GetDescription(long self);
5456
}

java/org/cef/network/CefWebPluginManager.java

Lines changed: 17 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@
1111
* Class used to manage web plugins.
1212
*/
1313
public abstract class CefWebPluginManager {
14-
// This CTOR can't be called directly. Call method create() instead.
14+
// This CTOR can't be called directly. Call method getGlobalManager() instead.
1515
CefWebPluginManager() {}
1616

1717
/**
@@ -22,35 +22,39 @@ public static final CefWebPluginManager getGlobalManager() {
2222
}
2323

2424
/**
25-
* Visit web plugin information. Can be called on any thread in the browser
26-
* process.
25+
* Visit web plugin information. Can be called on any thread in the browser process.
26+
*
2727
* @param visitor Called with plugin information when available.
2828
*/
2929
public abstract void visitPlugins(CefWebPluginInfoVisitor visitor);
3030

3131
/**
32-
* Cause the plugin list to refresh the next time it is accessed regardless
33-
* of whether it has already been loaded. Can be called on any thread in the
34-
* browser process.
32+
* Cause the plugin list to refresh the next time it is accessed regardless of whether it has
33+
* already been loaded. Can be called on any thread in the browser process.
3534
*/
3635
public abstract void refreshPlugins();
3736

3837
/**
39-
* Unregister an internal plugin. This may be undone the next time
40-
* CefRefreshWebPlugins() is called. Can be called on any thread in the browser
41-
* process.
38+
* Unregister an internal plugin. This may be undone the next time refreshPlugins() is called.
39+
* Can be called on any thread in the browser process.
40+
*
41+
* @param path Plugin file path (DLL/bundle/library).
4242
*/
4343
public abstract void unregisterInternalPlugin(String path);
4444

4545
/**
46-
* Register a plugin crash. Can be called on any thread in the browser process
47-
* but will be executed on the IO thread.
46+
* Register a plugin crash. Can be called on any thread in the browser process but will be
47+
* executed on the IO thread.
48+
*
49+
* @param path Plugin file path (DLL/bundle/library).
4850
*/
4951
public abstract void registerPluginCrash(String path);
5052

5153
/**
52-
* Query if a plugin is unstable. Can be called on any thread in the browser
53-
* process.
54+
* Query if a plugin is unstable. Can be called on any thread in the browser process.
55+
*
56+
* @param path Plugin file path (DLL/bundle/library).
57+
* @param callback Called when plugin information is available.
5458
*/
5559
public abstract void isWebPluginUnstable(String path, CefWebPluginUnstableCallback callback);
5660
}

java/org/cef/network/CefWebPluginManager_N.java

Lines changed: 1 addition & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -8,21 +8,9 @@
88
import org.cef.callback.CefWebPluginInfoVisitor;
99
import org.cef.callback.CefWebPluginUnstableCallback;
1010

11-
class CefWebPluginManager_N extends CefWebPluginManager implements CefNative {
12-
// Used internally to store a pointer to the CEF object.
13-
private long N_CefHandle = 0;
11+
class CefWebPluginManager_N extends CefWebPluginManager {
1412
private static CefWebPluginManager_N instance = null;
1513

16-
@Override
17-
public void setNativeRef(String identifer, long nativeRef) {
18-
N_CefHandle = nativeRef;
19-
}
20-
21-
@Override
22-
public long getNativeRef(String identifer) {
23-
return N_CefHandle;
24-
}
25-
2614
CefWebPluginManager_N() {
2715
super();
2816
}

native/CefWebPluginInfo_N.cpp

Lines changed: 26 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -7,40 +7,50 @@
77

88
#include "include/cef_web_plugin.h"
99

10+
namespace {
11+
12+
CefRefPtr<CefWebPluginInfo> GetSelf(jlong self) {
13+
return reinterpret_cast<CefWebPluginInfo*>(self);
14+
}
15+
16+
} // namespace
17+
1018
JNIEXPORT jstring JNICALL
11-
Java_org_cef_network_CefWebPluginInfo_1N_N_1GetName(JNIEnv* env, jobject obj) {
12-
CefRefPtr<CefWebPluginInfo> info =
13-
GetCefFromJNIObject<CefWebPluginInfo>(env, obj, "CefWebPluginInfo");
14-
if (!info.get())
19+
Java_org_cef_network_CefWebPluginInfo_1N_N_1GetName(JNIEnv* env,
20+
jobject obj,
21+
jlong self) {
22+
CefRefPtr<CefWebPluginInfo> info = GetSelf(self);
23+
if (!info)
1524
return NULL;
1625
return NewJNIString(env, info->GetName());
1726
}
1827

1928
JNIEXPORT jstring JNICALL
20-
Java_org_cef_network_CefWebPluginInfo_1N_N_1GetPath(JNIEnv* env, jobject obj) {
21-
CefRefPtr<CefWebPluginInfo> info =
22-
GetCefFromJNIObject<CefWebPluginInfo>(env, obj, "CefWebPluginInfo");
23-
if (!info.get())
29+
Java_org_cef_network_CefWebPluginInfo_1N_N_1GetPath(JNIEnv* env,
30+
jobject obj,
31+
jlong self) {
32+
CefRefPtr<CefWebPluginInfo> info = GetSelf(self);
33+
if (!info)
2434
return NULL;
2535
return NewJNIString(env, info->GetPath());
2636
}
2737

2838
JNIEXPORT jstring JNICALL
2939
Java_org_cef_network_CefWebPluginInfo_1N_N_1GetVersion(JNIEnv* env,
30-
jobject obj) {
31-
CefRefPtr<CefWebPluginInfo> info =
32-
GetCefFromJNIObject<CefWebPluginInfo>(env, obj, "CefWebPluginInfo");
33-
if (!info.get())
40+
jobject obj,
41+
jlong self) {
42+
CefRefPtr<CefWebPluginInfo> info = GetSelf(self);
43+
if (!info)
3444
return NULL;
3545
return NewJNIString(env, info->GetVersion());
3646
}
3747

3848
JNIEXPORT jstring JNICALL
3949
Java_org_cef_network_CefWebPluginInfo_1N_N_1GetDescription(JNIEnv* env,
40-
jobject obj) {
41-
CefRefPtr<CefWebPluginInfo> info =
42-
GetCefFromJNIObject<CefWebPluginInfo>(env, obj, "CefWebPluginInfo");
43-
if (!info.get())
50+
jobject obj,
51+
jlong self) {
52+
CefRefPtr<CefWebPluginInfo> info = GetSelf(self);
53+
if (!info)
4454
return NULL;
4555
return NewJNIString(env, info->GetDescription());
4656
}

native/CefWebPluginInfo_N.h

Lines changed: 10 additions & 8 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

native/web_plugin_unstable_callback.cpp

Lines changed: 7 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -8,22 +8,17 @@
88
#include "util.h"
99

1010
WebPluginUnstableCallback::WebPluginUnstableCallback(JNIEnv* env,
11-
jobject jcallback) {
12-
jcallback_ = env->NewGlobalRef(jcallback);
13-
}
14-
15-
WebPluginUnstableCallback::~WebPluginUnstableCallback() {
16-
JNIEnv* env = GetJNIEnv();
17-
env->DeleteGlobalRef(jcallback_);
18-
}
11+
jobject jcallback)
12+
: handle_(env, jcallback) {}
1913

2014
void WebPluginUnstableCallback::IsUnstable(const CefString& path,
2115
bool unstable) {
2216
JNIEnv* env = GetJNIEnv();
2317
if (!env)
2418
return;
25-
jstring jpath = NewJNIString(env, path);
26-
JNI_CALL_VOID_METHOD(env, jcallback_, "isUnstable", "(Ljava/lang/String;Z)V",
27-
jpath, (unstable ? JNI_TRUE : JNI_FALSE));
28-
env->DeleteLocalRef(jpath);
19+
20+
ScopedJNIString jpath(env, path);
21+
22+
JNI_CALL_VOID_METHOD(env, handle_, "isUnstable", "(Ljava/lang/String;Z)V",
23+
jpath.get(), (unstable ? JNI_TRUE : JNI_FALSE));
2924
}

native/web_plugin_unstable_callback.h

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,19 +7,21 @@
77
#pragma once
88

99
#include <jni.h>
10+
1011
#include "include/cef_web_plugin.h"
1112

13+
#include "jni_scoped_helpers.h"
14+
1215
// WebPluginUnstableCallback implementation.
1316
class WebPluginUnstableCallback : public CefWebPluginUnstableCallback {
1417
public:
1518
WebPluginUnstableCallback(JNIEnv* env, jobject jcallback);
16-
virtual ~WebPluginUnstableCallback();
1719

1820
// WebPluginUnstableCallback methods
1921
virtual void IsUnstable(const CefString& path, bool unstable) OVERRIDE;
2022

2123
protected:
22-
jobject jcallback_;
24+
ScopedJNIObjectGlobal handle_;
2325

2426
// Include the default reference counting implementation.
2527
IMPLEMENT_REFCOUNTING(WebPluginUnstableCallback);

native/web_plugin_visitor.cpp

Lines changed: 7 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -7,14 +7,8 @@
77
#include "jni_util.h"
88
#include "util.h"
99

10-
WebPluginInfoVisitor::WebPluginInfoVisitor(JNIEnv* env, jobject jvisitor) {
11-
jvisitor_ = env->NewGlobalRef(jvisitor);
12-
}
13-
14-
WebPluginInfoVisitor::~WebPluginInfoVisitor() {
15-
JNIEnv* env = GetJNIEnv();
16-
env->DeleteGlobalRef(jvisitor_);
17-
}
10+
WebPluginInfoVisitor::WebPluginInfoVisitor(JNIEnv* env, jobject jvisitor)
11+
: handle_(env, jvisitor) {}
1812

1913
bool WebPluginInfoVisitor::Visit(CefRefPtr<CefWebPluginInfo> info,
2014
int count,
@@ -23,17 +17,14 @@ bool WebPluginInfoVisitor::Visit(CefRefPtr<CefWebPluginInfo> info,
2317
if (!env)
2418
return false;
2519

26-
jobject jinfo = NewJNIObject(env, "org/cef/network/CefWebPluginInfo_N");
27-
if (!jinfo)
28-
return false;
29-
SetCefForJNIObject(env, jinfo, info.get(), "CefWebPluginInfo");
20+
ScopedJNIObject<CefWebPluginInfo> jinfo(
21+
env, info, "org/cef/network/CefWebPluginInfo_N", "CefWebPluginInfo");
22+
jinfo.SetTemporary();
3023

3124
jboolean jresult = JNI_FALSE;
32-
JNI_CALL_METHOD(env, jvisitor_, "visit",
25+
JNI_CALL_METHOD(env, handle_, "visit",
3326
"(Lorg/cef/network/CefWebPluginInfo;II)Z", Boolean, jresult,
34-
jinfo, (jint)count, (jint)total);
27+
jinfo.get(), (jint)count, (jint)total);
3528

36-
SetCefForJNIObject<CefWebPluginInfo>(env, jinfo, NULL, "CefWebPluginInfo");
37-
env->DeleteLocalRef(jinfo);
3829
return jresult != JNI_FALSE;
3930
}

0 commit comments

Comments
 (0)