Commit 7f05c35c authored by Eric Stevenson's avatar Eric Stevenson Committed by Commit Bot

JNI refactor: @NativeMethods conversion (rest of //chrome).

This CL was generated by
//base/android/jni_generator/jni_refactorer.py.

Tbr: agrieve@chromium.org
Bug: 929661
Change-Id: Iead2b36f9526ba122fe1bfdfb73eab5c1696abbd
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/1815048
Commit-Queue: Eric Stevenson <estevenson@chromium.org>
Auto-Submit: Eric Stevenson <estevenson@chromium.org>
Reviewed-by: default avatarAndrew Grieve <agrieve@chromium.org>
Cr-Commit-Position: refs/heads/master@{#698505}
parent d9649718
...@@ -9,9 +9,11 @@ import("//build/config/android/rules.gni") ...@@ -9,9 +9,11 @@ import("//build/config/android/rules.gni")
android_library("java") { android_library("java") {
deps = [ deps = [
"//base:base_java", "//base:base_java",
"//base:jni_java",
"//chrome/android/public/crypto:java", "//chrome/android/public/crypto:java",
"//content/public/android:content_java", "//content/public/android:content_java",
] ]
annotation_processor_deps = [ "//base/android/jni_generator:jni_processor" ]
java_files = [ java_files = [
"java/src/org/chromium/chrome/browser/cookies/CanonicalCookie.java", "java/src/org/chromium/chrome/browser/cookies/CanonicalCookie.java",
"java/src/org/chromium/chrome/browser/cookies/CookiesFetcher.java", "java/src/org/chromium/chrome/browser/cookies/CookiesFetcher.java",
......
...@@ -9,6 +9,7 @@ import org.chromium.base.ImportantFileWriterAndroid; ...@@ -9,6 +9,7 @@ import org.chromium.base.ImportantFileWriterAndroid;
import org.chromium.base.Log; import org.chromium.base.Log;
import org.chromium.base.ThreadUtils; import org.chromium.base.ThreadUtils;
import org.chromium.base.annotations.CalledByNative; import org.chromium.base.annotations.CalledByNative;
import org.chromium.base.annotations.NativeMethods;
import org.chromium.base.task.AsyncTask; import org.chromium.base.task.AsyncTask;
import org.chromium.base.task.BackgroundOnlyAsyncTask; import org.chromium.base.task.BackgroundOnlyAsyncTask;
import org.chromium.chrome.browser.crypto.CipherFactory; import org.chromium.chrome.browser.crypto.CipherFactory;
...@@ -57,7 +58,7 @@ public class CookiesFetcher { ...@@ -57,7 +58,7 @@ public class CookiesFetcher {
*/ */
public static void persistCookies() { public static void persistCookies() {
try { try {
nativePersistCookies(); CookiesFetcherJni.get().persistCookies();
} catch (RuntimeException e) { } catch (RuntimeException e) {
e.printStackTrace(); e.printStackTrace();
} }
...@@ -121,10 +122,11 @@ public class CookiesFetcher { ...@@ -121,10 +122,11 @@ public class CookiesFetcher {
protected void onPostExecute(List<CanonicalCookie> cookies) { protected void onPostExecute(List<CanonicalCookie> cookies) {
// We can only access cookies and profiles on the UI thread. // We can only access cookies and profiles on the UI thread.
for (CanonicalCookie cookie : cookies) { for (CanonicalCookie cookie : cookies) {
nativeRestoreCookies(cookie.getName(), cookie.getValue(), cookie.getDomain(), CookiesFetcherJni.get().restoreCookies(cookie.getName(), cookie.getValue(),
cookie.getPath(), cookie.getCreationDate(), cookie.getExpirationDate(), cookie.getDomain(), cookie.getPath(), cookie.getCreationDate(),
cookie.getLastAccessDate(), cookie.isSecure(), cookie.isHttpOnly(), cookie.getExpirationDate(), cookie.getLastAccessDate(),
cookie.getSameSite(), cookie.getPriority()); cookie.isSecure(), cookie.isHttpOnly(), cookie.getSameSite(),
cookie.getPriority());
} }
} }
}.executeOnExecutor(AsyncTask.SERIAL_EXECUTOR); }.executeOnExecutor(AsyncTask.SERIAL_EXECUTOR);
...@@ -220,8 +222,11 @@ public class CookiesFetcher { ...@@ -220,8 +222,11 @@ public class CookiesFetcher {
return new CanonicalCookie[size]; return new CanonicalCookie[size];
} }
private static native void nativePersistCookies(); @NativeMethods
private static native void nativeRestoreCookies(String name, String value, String domain, interface Natives {
String path, long creation, long expiration, long lastAccess, boolean secure, void persistCookies();
boolean httpOnly, int sameSite, int priority); void restoreCookies(String name, String value, String domain, String path, long creation,
long expiration, long lastAccess, boolean secure, boolean httpOnly, int sameSite,
int priority);
}
} }
...@@ -6,6 +6,7 @@ package org.chromium.chrome.browser.profiles; ...@@ -6,6 +6,7 @@ package org.chromium.chrome.browser.profiles;
import org.chromium.base.VisibleForTesting; import org.chromium.base.VisibleForTesting;
import org.chromium.base.annotations.CalledByNative; import org.chromium.base.annotations.CalledByNative;
import org.chromium.base.annotations.NativeMethods;
import org.chromium.base.library_loader.LibraryProcessType; import org.chromium.base.library_loader.LibraryProcessType;
import org.chromium.chrome.browser.cookies.CookiesFetcher; import org.chromium.chrome.browser.cookies.CookiesFetcher;
import org.chromium.content_public.browser.BrowserStartupController; import org.chromium.content_public.browser.BrowserStartupController;
...@@ -22,7 +23,7 @@ public class Profile { ...@@ -22,7 +23,7 @@ public class Profile {
private Profile(long nativeProfileAndroid) { private Profile(long nativeProfileAndroid) {
mNativeProfileAndroid = nativeProfileAndroid; mNativeProfileAndroid = nativeProfileAndroid;
mIsOffTheRecord = nativeIsOffTheRecord(mNativeProfileAndroid); mIsOffTheRecord = ProfileJni.get().isOffTheRecord(mNativeProfileAndroid, Profile.this);
} }
public static Profile getLastUsedProfile() { public static Profile getLastUsedProfile() {
...@@ -31,7 +32,7 @@ public class Profile { ...@@ -31,7 +32,7 @@ public class Profile {
.isFullBrowserStarted()) { .isFullBrowserStarted()) {
throw new IllegalStateException("Browser hasn't finished initialization yet!"); throw new IllegalStateException("Browser hasn't finished initialization yet!");
} }
return (Profile) nativeGetLastUsedProfile(); return (Profile) ProfileJni.get().getLastUsedProfile();
} }
/** /**
...@@ -40,23 +41,24 @@ public class Profile { ...@@ -40,23 +41,24 @@ public class Profile {
* this call. * this call.
*/ */
public void destroyWhenAppropriate() { public void destroyWhenAppropriate() {
nativeDestroyWhenAppropriate(mNativeProfileAndroid); ProfileJni.get().destroyWhenAppropriate(mNativeProfileAndroid, Profile.this);
} }
public Profile getOriginalProfile() { public Profile getOriginalProfile() {
return (Profile) nativeGetOriginalProfile(mNativeProfileAndroid); return (Profile) ProfileJni.get().getOriginalProfile(mNativeProfileAndroid, Profile.this);
} }
public Profile getOffTheRecordProfile() { public Profile getOffTheRecordProfile() {
return (Profile) nativeGetOffTheRecordProfile(mNativeProfileAndroid); return (Profile) ProfileJni.get().getOffTheRecordProfile(
mNativeProfileAndroid, Profile.this);
} }
public boolean hasOffTheRecordProfile() { public boolean hasOffTheRecordProfile() {
return nativeHasOffTheRecordProfile(mNativeProfileAndroid); return ProfileJni.get().hasOffTheRecordProfile(mNativeProfileAndroid, Profile.this);
} }
public ProfileKey getProfileKey() { public ProfileKey getProfileKey() {
return (ProfileKey) nativeGetProfileKey(mNativeProfileAndroid); return (ProfileKey) ProfileJni.get().getProfileKey(mNativeProfileAndroid, Profile.this);
} }
public boolean isOffTheRecord() { public boolean isOffTheRecord() {
...@@ -67,14 +69,14 @@ public class Profile { ...@@ -67,14 +69,14 @@ public class Profile {
* @return Whether the profile is signed in to a child account. * @return Whether the profile is signed in to a child account.
*/ */
public boolean isChild() { public boolean isChild() {
return nativeIsChild(mNativeProfileAndroid); return ProfileJni.get().isChild(mNativeProfileAndroid, Profile.this);
} }
/** /**
* Wipes all data for this profile. * Wipes all data for this profile.
*/ */
public void wipe() { public void wipe() {
nativeWipe(mNativeProfileAndroid); ProfileJni.get().wipe(mNativeProfileAndroid, Profile.this);
} }
/** /**
...@@ -104,13 +106,16 @@ public class Profile { ...@@ -104,13 +106,16 @@ public class Profile {
return mNativeProfileAndroid; return mNativeProfileAndroid;
} }
private static native Object nativeGetLastUsedProfile(); @NativeMethods
private native void nativeDestroyWhenAppropriate(long nativeProfileAndroid); interface Natives {
private native Object nativeGetOriginalProfile(long nativeProfileAndroid); Object getLastUsedProfile();
private native Object nativeGetOffTheRecordProfile(long nativeProfileAndroid); void destroyWhenAppropriate(long nativeProfileAndroid, Profile caller);
private native boolean nativeHasOffTheRecordProfile(long nativeProfileAndroid); Object getOriginalProfile(long nativeProfileAndroid, Profile caller);
private native boolean nativeIsOffTheRecord(long nativeProfileAndroid); Object getOffTheRecordProfile(long nativeProfileAndroid, Profile caller);
private native boolean nativeIsChild(long nativeProfileAndroid); boolean hasOffTheRecordProfile(long nativeProfileAndroid, Profile caller);
private native void nativeWipe(long nativeProfileAndroid); boolean isOffTheRecord(long nativeProfileAndroid, Profile caller);
private native Object nativeGetProfileKey(long nativeProfileAndroid); boolean isChild(long nativeProfileAndroid, Profile caller);
void wipe(long nativeProfileAndroid, Profile caller);
Object getProfileKey(long nativeProfileAndroid, Profile caller);
}
} }
...@@ -5,6 +5,7 @@ ...@@ -5,6 +5,7 @@
package org.chromium.chrome.browser.profiles; package org.chromium.chrome.browser.profiles;
import org.chromium.base.annotations.CalledByNative; import org.chromium.base.annotations.CalledByNative;
import org.chromium.base.annotations.NativeMethods;
/** /**
* Wrapper that allows passing a ProfileKey reference around in the Java layer. * Wrapper that allows passing a ProfileKey reference around in the Java layer.
...@@ -18,17 +19,19 @@ public class ProfileKey { ...@@ -18,17 +19,19 @@ public class ProfileKey {
private ProfileKey(long nativeProfileKeyAndroid) { private ProfileKey(long nativeProfileKeyAndroid) {
mNativeProfileKeyAndroid = nativeProfileKeyAndroid; mNativeProfileKeyAndroid = nativeProfileKeyAndroid;
mIsOffTheRecord = nativeIsOffTheRecord(mNativeProfileKeyAndroid); mIsOffTheRecord =
ProfileKeyJni.get().isOffTheRecord(mNativeProfileKeyAndroid, ProfileKey.this);
} }
public static ProfileKey getLastUsedProfileKey() { public static ProfileKey getLastUsedProfileKey() {
// TODO(mheikal): Assert at least reduced mode is started when https://crbug.com/973241 is // TODO(mheikal): Assert at least reduced mode is started when https://crbug.com/973241 is
// fixed. // fixed.
return (ProfileKey) nativeGetLastUsedProfileKey(); return (ProfileKey) ProfileKeyJni.get().getLastUsedProfileKey();
} }
public ProfileKey getOriginalKey() { public ProfileKey getOriginalKey() {
return (ProfileKey) nativeGetOriginalKey(mNativeProfileKeyAndroid); return (ProfileKey) ProfileKeyJni.get().getOriginalKey(
mNativeProfileKeyAndroid, ProfileKey.this);
} }
public boolean isOffTheRecord() { public boolean isOffTheRecord() {
...@@ -50,7 +53,10 @@ public class ProfileKey { ...@@ -50,7 +53,10 @@ public class ProfileKey {
return mNativeProfileKeyAndroid; return mNativeProfileKeyAndroid;
} }
private static native Object nativeGetLastUsedProfileKey(); @NativeMethods
private native Object nativeGetOriginalKey(long nativeProfileKeyAndroid); interface Natives {
private native boolean nativeIsOffTheRecord(long nativeProfileKeyAndroid); Object getLastUsedProfileKey();
Object getOriginalKey(long nativeProfileKeyAndroid, ProfileKey caller);
boolean isOffTheRecord(long nativeProfileKeyAndroid, ProfileKey caller);
}
} }
...@@ -9,6 +9,7 @@ import android.os.SystemClock; ...@@ -9,6 +9,7 @@ import android.os.SystemClock;
import org.chromium.base.ContextUtils; import org.chromium.base.ContextUtils;
import org.chromium.base.TraceEvent; import org.chromium.base.TraceEvent;
import org.chromium.base.annotations.NativeMethods;
/** /**
* A utility class for applying operations on all loaded profiles. * A utility class for applying operations on all loaded profiles.
...@@ -26,7 +27,7 @@ public class ProfileManagerUtils { ...@@ -26,7 +27,7 @@ public class ProfileManagerUtils {
public static void flushPersistentDataForAllProfiles() { public static void flushPersistentDataForAllProfiles() {
try { try {
TraceEvent.begin("ProfileManagerUtils.commitPendingWritesForAllProfiles"); TraceEvent.begin("ProfileManagerUtils.commitPendingWritesForAllProfiles");
nativeFlushPersistentDataForAllProfiles(); ProfileManagerUtilsJni.get().flushPersistentDataForAllProfiles();
} finally { } finally {
TraceEvent.end("ProfileManagerUtils.commitPendingWritesForAllProfiles"); TraceEvent.end("ProfileManagerUtils.commitPendingWritesForAllProfiles");
} }
...@@ -47,7 +48,7 @@ public class ProfileManagerUtils { ...@@ -47,7 +48,7 @@ public class ProfileManagerUtils {
// Allow some leeway to account for fractions of milliseconds. // Allow some leeway to account for fractions of milliseconds.
if (Math.abs(difference) > BOOT_TIMESTAMP_MARGIN_MS) { if (Math.abs(difference) > BOOT_TIMESTAMP_MARGIN_MS) {
nativeRemoveSessionCookiesForAllProfiles(); ProfileManagerUtilsJni.get().removeSessionCookiesForAllProfiles();
SharedPreferences prefs = ContextUtils.getAppSharedPreferences(); SharedPreferences prefs = ContextUtils.getAppSharedPreferences();
SharedPreferences.Editor editor = prefs.edit(); SharedPreferences.Editor editor = prefs.edit();
...@@ -56,6 +57,9 @@ public class ProfileManagerUtils { ...@@ -56,6 +57,9 @@ public class ProfileManagerUtils {
} }
} }
private static native void nativeFlushPersistentDataForAllProfiles(); @NativeMethods
private static native void nativeRemoveSessionCookiesForAllProfiles(); interface Natives {
void flushPersistentDataForAllProfiles();
void removeSessionCookiesForAllProfiles();
}
} }
...@@ -35,10 +35,12 @@ android_library("internal_java") { ...@@ -35,10 +35,12 @@ android_library("internal_java") {
deps = [ deps = [
"//base:base_java", "//base:base_java",
"//base:jni_java",
"//chrome/browser/android/thin_webview:java", "//chrome/browser/android/thin_webview:java",
"//content/public/android:content_java", "//content/public/android:content_java",
"//ui/android:ui_java", "//ui/android:ui_java",
] ]
annotation_processor_deps = [ "//base/android/jni_generator:jni_processor" ]
} }
generate_jni("jni_headers") { generate_jni("jni_headers") {
......
...@@ -16,6 +16,7 @@ import android.view.View; ...@@ -16,6 +16,7 @@ import android.view.View;
import org.chromium.base.annotations.CalledByNative; import org.chromium.base.annotations.CalledByNative;
import org.chromium.base.annotations.JNINamespace; import org.chromium.base.annotations.JNINamespace;
import org.chromium.base.annotations.NativeMethods;
import org.chromium.chrome.browser.thinwebview.CompositorView; import org.chromium.chrome.browser.thinwebview.CompositorView;
import org.chromium.ui.base.WindowAndroid; import org.chromium.ui.base.WindowAndroid;
...@@ -40,7 +41,8 @@ public class CompositorViewImpl implements CompositorView { ...@@ -40,7 +41,8 @@ public class CompositorViewImpl implements CompositorView {
public CompositorViewImpl(Context context, WindowAndroid windowAndroid) { public CompositorViewImpl(Context context, WindowAndroid windowAndroid) {
mContext = context; mContext = context;
mView = useSurfaceView() ? createSurfaceView() : createTextureView(); mView = useSurfaceView() ? createSurfaceView() : createTextureView();
mNativeCompositorViewImpl = nativeInit(windowAndroid); mNativeCompositorViewImpl =
CompositorViewImplJni.get().init(CompositorViewImpl.this, windowAndroid);
} }
@Override @Override
...@@ -50,12 +52,17 @@ public class CompositorViewImpl implements CompositorView { ...@@ -50,12 +52,17 @@ public class CompositorViewImpl implements CompositorView {
@Override @Override
public void destroy() { public void destroy() {
if (mNativeCompositorViewImpl != 0) nativeDestroy(mNativeCompositorViewImpl); if (mNativeCompositorViewImpl != 0) {
CompositorViewImplJni.get().destroy(mNativeCompositorViewImpl, CompositorViewImpl.this);
}
} }
@Override @Override
public void requestRender() { public void requestRender() {
if (mNativeCompositorViewImpl != 0) nativeSetNeedsComposite(mNativeCompositorViewImpl); if (mNativeCompositorViewImpl != 0) {
CompositorViewImplJni.get().setNeedsComposite(
mNativeCompositorViewImpl, CompositorViewImpl.this);
}
} }
private SurfaceView createSurfaceView() { private SurfaceView createSurfaceView() {
...@@ -64,21 +71,23 @@ public class CompositorViewImpl implements CompositorView { ...@@ -64,21 +71,23 @@ public class CompositorViewImpl implements CompositorView {
@Override @Override
public void surfaceCreated(SurfaceHolder surfaceHolder) { public void surfaceCreated(SurfaceHolder surfaceHolder) {
if (mNativeCompositorViewImpl == 0) return; if (mNativeCompositorViewImpl == 0) return;
nativeSurfaceCreated(mNativeCompositorViewImpl); CompositorViewImplJni.get().surfaceCreated(
mNativeCompositorViewImpl, CompositorViewImpl.this);
} }
@Override @Override
public void surfaceChanged( public void surfaceChanged(
SurfaceHolder surfaceHolder, int format, int width, int height) { SurfaceHolder surfaceHolder, int format, int width, int height) {
if (mNativeCompositorViewImpl == 0) return; if (mNativeCompositorViewImpl == 0) return;
nativeSurfaceChanged(mNativeCompositorViewImpl, format, width, height, CompositorViewImplJni.get().surfaceChanged(mNativeCompositorViewImpl,
surfaceHolder.getSurface()); CompositorViewImpl.this, format, width, height, surfaceHolder.getSurface());
} }
@Override @Override
public void surfaceDestroyed(SurfaceHolder surfaceHolder) { public void surfaceDestroyed(SurfaceHolder surfaceHolder) {
if (mNativeCompositorViewImpl == 0) return; if (mNativeCompositorViewImpl == 0) return;
nativeSurfaceDestroyed(mNativeCompositorViewImpl); CompositorViewImplJni.get().surfaceDestroyed(
mNativeCompositorViewImpl, CompositorViewImpl.this);
} }
}); });
...@@ -95,14 +104,16 @@ public class CompositorViewImpl implements CompositorView { ...@@ -95,14 +104,16 @@ public class CompositorViewImpl implements CompositorView {
public void onSurfaceTextureSizeChanged( public void onSurfaceTextureSizeChanged(
SurfaceTexture surfaceTexture, int width, int height) { SurfaceTexture surfaceTexture, int width, int height) {
if (mNativeCompositorViewImpl == 0) return; if (mNativeCompositorViewImpl == 0) return;
nativeSurfaceChanged(mNativeCompositorViewImpl, PixelFormat.OPAQUE, width, height, CompositorViewImplJni.get().surfaceChanged(mNativeCompositorViewImpl,
CompositorViewImpl.this, PixelFormat.OPAQUE, width, height,
new Surface(surfaceTexture)); new Surface(surfaceTexture));
} }
@Override @Override
public boolean onSurfaceTextureDestroyed(SurfaceTexture surfaceTexture) { public boolean onSurfaceTextureDestroyed(SurfaceTexture surfaceTexture) {
if (mNativeCompositorViewImpl == 0) return false; if (mNativeCompositorViewImpl == 0) return false;
nativeSurfaceDestroyed(mNativeCompositorViewImpl); CompositorViewImplJni.get().surfaceDestroyed(
mNativeCompositorViewImpl, CompositorViewImpl.this);
return false; return false;
} }
...@@ -110,8 +121,10 @@ public class CompositorViewImpl implements CompositorView { ...@@ -110,8 +121,10 @@ public class CompositorViewImpl implements CompositorView {
public void onSurfaceTextureAvailable( public void onSurfaceTextureAvailable(
SurfaceTexture surfaceTexture, int width, int height) { SurfaceTexture surfaceTexture, int width, int height) {
if (mNativeCompositorViewImpl == 0) return; if (mNativeCompositorViewImpl == 0) return;
nativeSurfaceCreated(mNativeCompositorViewImpl); CompositorViewImplJni.get().surfaceCreated(
nativeSurfaceChanged(mNativeCompositorViewImpl, PixelFormat.OPAQUE, width, height, mNativeCompositorViewImpl, CompositorViewImpl.this);
CompositorViewImplJni.get().surfaceChanged(mNativeCompositorViewImpl,
CompositorViewImpl.this, PixelFormat.OPAQUE, width, height,
new Surface(surfaceTexture)); new Surface(surfaceTexture));
} }
}); });
...@@ -136,11 +149,14 @@ public class CompositorViewImpl implements CompositorView { ...@@ -136,11 +149,14 @@ public class CompositorViewImpl implements CompositorView {
return Build.VERSION.SDK_INT >= Build.VERSION_CODES.N; return Build.VERSION.SDK_INT >= Build.VERSION_CODES.N;
} }
private native long nativeInit(WindowAndroid windowAndroid); @NativeMethods
private native void nativeDestroy(long nativeCompositorViewImpl); interface Natives {
private native void nativeSurfaceCreated(long nativeCompositorViewImpl); long init(CompositorViewImpl caller, WindowAndroid windowAndroid);
private native void nativeSurfaceDestroyed(long nativeCompositorViewImpl); void destroy(long nativeCompositorViewImpl, CompositorViewImpl caller);
private native void nativeSurfaceChanged( void surfaceCreated(long nativeCompositorViewImpl, CompositorViewImpl caller);
long nativeCompositorViewImpl, int format, int width, int height, Surface surface); void surfaceDestroyed(long nativeCompositorViewImpl, CompositorViewImpl caller);
private native void nativeSetNeedsComposite(long nativeCompositorViewImpl); void surfaceChanged(long nativeCompositorViewImpl, CompositorViewImpl caller, int format,
int width, int height, Surface surface);
void setNeedsComposite(long nativeCompositorViewImpl, CompositorViewImpl caller);
}
} }
...@@ -12,6 +12,7 @@ import android.widget.FrameLayout; ...@@ -12,6 +12,7 @@ import android.widget.FrameLayout;
import androidx.annotation.Nullable; import androidx.annotation.Nullable;
import org.chromium.base.annotations.JNINamespace; import org.chromium.base.annotations.JNINamespace;
import org.chromium.base.annotations.NativeMethods;
import org.chromium.chrome.browser.thinwebview.CompositorView; import org.chromium.chrome.browser.thinwebview.CompositorView;
import org.chromium.chrome.browser.thinwebview.ThinWebView; import org.chromium.chrome.browser.thinwebview.ThinWebView;
import org.chromium.content_public.browser.WebContents; import org.chromium.content_public.browser.WebContents;
...@@ -41,7 +42,8 @@ public class ThinWebViewImpl extends FrameLayout implements ThinWebView { ...@@ -41,7 +42,8 @@ public class ThinWebViewImpl extends FrameLayout implements ThinWebView {
ViewGroup.LayoutParams.MATCH_PARENT, ViewGroup.LayoutParams.MATCH_PARENT); ViewGroup.LayoutParams.MATCH_PARENT, ViewGroup.LayoutParams.MATCH_PARENT);
addView(mCompositorView.getView(), layoutParams); addView(mCompositorView.getView(), layoutParams);
mNativeThinWebViewImpl = nativeInit(mCompositorView, windowAndroid); mNativeThinWebViewImpl =
ThinWebViewImplJni.get().init(ThinWebViewImpl.this, mCompositorView, windowAndroid);
} }
@Override @Override
...@@ -54,20 +56,24 @@ public class ThinWebViewImpl extends FrameLayout implements ThinWebView { ...@@ -54,20 +56,24 @@ public class ThinWebViewImpl extends FrameLayout implements ThinWebView {
mWebContents = webContents; mWebContents = webContents;
setContentView(contentView); setContentView(contentView);
nativeSetWebContents(mNativeThinWebViewImpl, mWebContents); ThinWebViewImplJni.get().setWebContents(
mNativeThinWebViewImpl, ThinWebViewImpl.this, mWebContents);
mWebContents.onShow(); mWebContents.onShow();
} }
@Override @Override
public void destroy() { public void destroy() {
mCompositorView.destroy(); mCompositorView.destroy();
if (mNativeThinWebViewImpl != 0) nativeDestroy(mNativeThinWebViewImpl); if (mNativeThinWebViewImpl != 0) {
ThinWebViewImplJni.get().destroy(mNativeThinWebViewImpl, ThinWebViewImpl.this);
}
} }
@Override @Override
protected void onSizeChanged(int w, int h, int oldw, int oldh) { protected void onSizeChanged(int w, int h, int oldw, int oldh) {
if (w != oldw || h != oldh) { if (w != oldw || h != oldh) {
nativeSizeChanged(mNativeThinWebViewImpl, w, h); ThinWebViewImplJni.get().sizeChanged(
mNativeThinWebViewImpl, ThinWebViewImpl.this, w, h);
} }
} }
...@@ -83,8 +89,13 @@ public class ThinWebViewImpl extends FrameLayout implements ThinWebView { ...@@ -83,8 +89,13 @@ public class ThinWebViewImpl extends FrameLayout implements ThinWebView {
if (mContentView != null) addView(mContentView, 1); if (mContentView != null) addView(mContentView, 1);
} }
private native long nativeInit(CompositorView compositorView, WindowAndroid windowAndroid); @NativeMethods
private native void nativeDestroy(long nativeThinWebView); interface Natives {
private native void nativeSetWebContents(long nativeThinWebView, WebContents webContents); long init(
private native void nativeSizeChanged(long nativeThinWebView, int width, int height); ThinWebViewImpl caller, CompositorView compositorView, WindowAndroid windowAndroid);
void destroy(long nativeThinWebView, ThinWebViewImpl caller);
void setWebContents(
long nativeThinWebView, ThinWebViewImpl caller, WebContents webContents);
void sizeChanged(long nativeThinWebView, ThinWebViewImpl caller, int width, int height);
}
} }
...@@ -7,11 +7,13 @@ import("//build/config/android/rules.gni") ...@@ -7,11 +7,13 @@ import("//build/config/android/rules.gni")
android_library("java") { android_library("java") {
deps = [ deps = [
"//base:base_java", "//base:base_java",
"//base:jni_java",
"//chrome/android/public/profiles:java", "//chrome/android/public/profiles:java",
"//chrome/lib/util/public/android:java", "//chrome/lib/util/public/android:java",
"//content/public/android:content_java", "//content/public/android:content_java",
"//third_party/gif_player:gif_player_java", "//third_party/gif_player:gif_player_java",
] ]
annotation_processor_deps = [ "//base/android/jni_generator:jni_processor" ]
java_files = [ java_files = [
"android/java/src/org/chromium/chrome/browser/image_fetcher/CachedImageFetcher.java", "android/java/src/org/chromium/chrome/browser/image_fetcher/CachedImageFetcher.java",
"android/java/src/org/chromium/chrome/browser/image_fetcher/ImageFetcherBridge.java", "android/java/src/org/chromium/chrome/browser/image_fetcher/ImageFetcherBridge.java",
......
...@@ -8,6 +8,7 @@ import android.graphics.Bitmap; ...@@ -8,6 +8,7 @@ import android.graphics.Bitmap;
import org.chromium.base.Callback; import org.chromium.base.Callback;
import org.chromium.base.annotations.JNINamespace; import org.chromium.base.annotations.JNINamespace;
import org.chromium.base.annotations.NativeMethods;
import org.chromium.chrome.browser.profiles.Profile; import org.chromium.chrome.browser.profiles.Profile;
import jp.tomorrowkey.android.gifplayer.BaseGifImage; import jp.tomorrowkey.android.gifplayer.BaseGifImage;
...@@ -36,13 +37,13 @@ public class ImageFetcherBridge { ...@@ -36,13 +37,13 @@ public class ImageFetcherBridge {
* Creates a ImageFetcherBridge for accessing the native ImageFetcher implementation. * Creates a ImageFetcherBridge for accessing the native ImageFetcher implementation.
*/ */
public ImageFetcherBridge(Profile profile) { public ImageFetcherBridge(Profile profile) {
mNativeImageFetcherBridge = nativeInit(profile); mNativeImageFetcherBridge = ImageFetcherBridgeJni.get().init(profile);
} }
/** Cleans up native half of bridge. */ /** Cleans up native half of bridge. */
public void destroy() { public void destroy() {
assert mNativeImageFetcherBridge != 0; assert mNativeImageFetcherBridge != 0;
nativeDestroy(mNativeImageFetcherBridge); ImageFetcherBridgeJni.get().destroy(mNativeImageFetcherBridge, ImageFetcherBridge.this);
mNativeImageFetcherBridge = 0; mNativeImageFetcherBridge = 0;
} }
...@@ -54,7 +55,8 @@ public class ImageFetcherBridge { ...@@ -54,7 +55,8 @@ public class ImageFetcherBridge {
*/ */
public String getFilePath(String url) { public String getFilePath(String url) {
assert mNativeImageFetcherBridge != 0; assert mNativeImageFetcherBridge != 0;
return nativeGetFilePath(mNativeImageFetcherBridge, url); return ImageFetcherBridgeJni.get().getFilePath(
mNativeImageFetcherBridge, ImageFetcherBridge.this, url);
} }
/** /**
...@@ -68,13 +70,14 @@ public class ImageFetcherBridge { ...@@ -68,13 +70,14 @@ public class ImageFetcherBridge {
public void fetchGif(@ImageFetcherConfig int config, String url, String clientName, public void fetchGif(@ImageFetcherConfig int config, String url, String clientName,
Callback<BaseGifImage> callback) { Callback<BaseGifImage> callback) {
assert mNativeImageFetcherBridge != 0; assert mNativeImageFetcherBridge != 0;
nativeFetchImageData(mNativeImageFetcherBridge, config, url, clientName, (byte[] data) -> { ImageFetcherBridgeJni.get().fetchImageData(mNativeImageFetcherBridge,
if (data == null || data.length == 0) { ImageFetcherBridge.this, config, url, clientName, (byte[] data) -> {
callback.onResult(null); if (data == null || data.length == 0) {
} callback.onResult(null);
}
callback.onResult(new BaseGifImage(data));
}); callback.onResult(new BaseGifImage(data));
});
} }
/** /**
...@@ -91,9 +94,10 @@ public class ImageFetcherBridge { ...@@ -91,9 +94,10 @@ public class ImageFetcherBridge {
public void fetchImage(@ImageFetcherConfig int config, String url, String clientName, int width, public void fetchImage(@ImageFetcherConfig int config, String url, String clientName, int width,
int height, Callback<Bitmap> callback) { int height, Callback<Bitmap> callback) {
assert mNativeImageFetcherBridge != 0; assert mNativeImageFetcherBridge != 0;
nativeFetchImage(mNativeImageFetcherBridge, config, url, clientName, (bitmap) -> { ImageFetcherBridgeJni.get().fetchImage(mNativeImageFetcherBridge, ImageFetcherBridge.this,
callback.onResult(ImageFetcher.tryToResizeImage(bitmap, width, height)); config, url, clientName, (bitmap) -> {
}); callback.onResult(ImageFetcher.tryToResizeImage(bitmap, width, height));
});
} }
/** /**
...@@ -104,7 +108,8 @@ public class ImageFetcherBridge { ...@@ -104,7 +108,8 @@ public class ImageFetcherBridge {
*/ */
public void reportEvent(String clientName, @ImageFetcherEvent int eventId) { public void reportEvent(String clientName, @ImageFetcherEvent int eventId) {
assert mNativeImageFetcherBridge != 0; assert mNativeImageFetcherBridge != 0;
nativeReportEvent(mNativeImageFetcherBridge, clientName, eventId); ImageFetcherBridgeJni.get().reportEvent(
mNativeImageFetcherBridge, ImageFetcherBridge.this, clientName, eventId);
} }
/** /**
...@@ -116,7 +121,8 @@ public class ImageFetcherBridge { ...@@ -116,7 +121,8 @@ public class ImageFetcherBridge {
*/ */
public void reportCacheHitTime(String clientName, long startTimeMillis) { public void reportCacheHitTime(String clientName, long startTimeMillis) {
assert mNativeImageFetcherBridge != 0; assert mNativeImageFetcherBridge != 0;
nativeReportCacheHitTime(mNativeImageFetcherBridge, clientName, startTimeMillis); ImageFetcherBridgeJni.get().reportCacheHitTime(
mNativeImageFetcherBridge, ImageFetcherBridge.this, clientName, startTimeMillis);
} }
/** /**
...@@ -128,8 +134,8 @@ public class ImageFetcherBridge { ...@@ -128,8 +134,8 @@ public class ImageFetcherBridge {
*/ */
public void reportTotalFetchTimeFromNative(String clientName, long startTimeMillis) { public void reportTotalFetchTimeFromNative(String clientName, long startTimeMillis) {
assert mNativeImageFetcherBridge != 0; assert mNativeImageFetcherBridge != 0;
nativeReportTotalFetchTimeFromNative( ImageFetcherBridgeJni.get().reportTotalFetchTimeFromNative(
mNativeImageFetcherBridge, clientName, startTimeMillis); mNativeImageFetcherBridge, ImageFetcherBridge.this, clientName, startTimeMillis);
} }
/** /**
...@@ -140,20 +146,24 @@ public class ImageFetcherBridge { ...@@ -140,20 +146,24 @@ public class ImageFetcherBridge {
sImageFetcherBridge = imageFetcherBridge; sImageFetcherBridge = imageFetcherBridge;
} }
// Native methods @NativeMethods
private static native long nativeInit(Profile profile); interface Natives {
private native void nativeDestroy(long nativeImageFetcherBridge); // Native methods
private native String nativeGetFilePath(long nativeImageFetcherBridge, String url); long init(Profile profile);
private native void nativeFetchImageData(long nativeImageFetcherBridge,
@ImageFetcherConfig int config, String url, String clientName, void destroy(long nativeImageFetcherBridge, ImageFetcherBridge caller);
Callback<byte[]> callback); String getFilePath(long nativeImageFetcherBridge, ImageFetcherBridge caller, String url);
private native void nativeFetchImage(long nativeImageFetcherBridge, void fetchImageData(long nativeImageFetcherBridge, ImageFetcherBridge caller,
@ImageFetcherConfig int config, String url, String clientName, @ImageFetcherConfig int config, String url, String clientName,
Callback<Bitmap> callback); Callback<byte[]> callback);
private native void nativeReportEvent( void fetchImage(long nativeImageFetcherBridge, ImageFetcherBridge caller,
long nativeImageFetcherBridge, String clientName, int eventId); @ImageFetcherConfig int config, String url, String clientName,
private native void nativeReportCacheHitTime( Callback<Bitmap> callback);
long nativeImageFetcherBridge, String clientName, long startTimeMillis); void reportEvent(long nativeImageFetcherBridge, ImageFetcherBridge caller,
private native void nativeReportTotalFetchTimeFromNative( String clientName, int eventId);
long nativeImageFetcherBridge, String clientName, long startTimeMillis); void reportCacheHitTime(long nativeImageFetcherBridge, ImageFetcherBridge caller,
String clientName, long startTimeMillis);
void reportTotalFetchTimeFromNative(long nativeImageFetcherBridge,
ImageFetcherBridge caller, String clientName, long startTimeMillis);
}
} }
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment