Commit 258c4aa6 authored by Yusuf Ozuysal's avatar Yusuf Ozuysal Committed by Commit Bot

Add an API for plumbing screenshots from C++ -> Java

Uses ThumbnailCache's DecompressThumbnailFromFile to read, decompress
and return tab thumbnails on the Java side.

Change-Id: Ia3905cf2f3aa859318897db0fcb2d1b489a7827a
Reviewed-on: https://chromium-review.googlesource.com/c/1423702Reviewed-by: default avatarMatthew Jones <mdjones@chromium.org>
Commit-Queue: Yusuf Ozuysal <yusufo@chromium.org>
Cr-Commit-Position: refs/heads/master@{#626147}
parent ef18f94a
...@@ -10,6 +10,7 @@ import android.graphics.Canvas; ...@@ -10,6 +10,7 @@ import android.graphics.Canvas;
import android.view.View; import android.view.View;
import android.view.ViewGroup.MarginLayoutParams; import android.view.ViewGroup.MarginLayoutParams;
import org.chromium.base.Callback;
import org.chromium.base.CommandLine; import org.chromium.base.CommandLine;
import org.chromium.base.annotations.CalledByNative; import org.chromium.base.annotations.CalledByNative;
import org.chromium.base.annotations.JNINamespace; import org.chromium.base.annotations.JNINamespace;
...@@ -212,6 +213,23 @@ public class TabContentManager { ...@@ -212,6 +213,23 @@ public class TabContentManager {
return nativeHasFullCachedThumbnail(mNativeTabContentManager, tabId); return nativeHasFullCachedThumbnail(mNativeTabContentManager, tabId);
} }
/**
* Call to get a thumbnail for a given tab ID from disk through a {@link Callback}. If there is
* no up to date thumbnail on the cache for the given tab, callback returns a null result.
* Currently this read a compressed file from disk and sends the Bitmap over the
* JNI boundary after decompressing. In its current form, should be used for experimental
* purposes only.
* TODO(yusufo): Change the plumbing so that at the least a {@link android.net.Uri} is send
* over JNI of an uncompressed file on disk.
* @param tabID The ID of the tab.
* @param callback The callback to send the {@link Bitmap} with.
*/
public void getTabThumbnailWithCallback(int tabID, Callback<Bitmap> callback) {
if (mNativeTabContentManager == 0 || !mSnapshotsEnabled) return;
nativeGetTabThumbnailWithCallback(mNativeTabContentManager, tabID, callback);
}
/** /**
* Cache the content of a tab as a thumbnail. * Cache the content of a tab as a thumbnail.
* @param tab The tab whose content we will cache. * @param tab The tab whose content we will cache.
...@@ -302,5 +320,7 @@ public class TabContentManager { ...@@ -302,5 +320,7 @@ public class TabContentManager {
private native void nativeUpdateVisibleIds( private native void nativeUpdateVisibleIds(
long nativeTabContentManager, int[] priority, int primaryTabId); long nativeTabContentManager, int[] priority, int primaryTabId);
private native void nativeRemoveTabThumbnail(long nativeTabContentManager, int tabId); private native void nativeRemoveTabThumbnail(long nativeTabContentManager, int tabId);
private native void nativeGetTabThumbnailWithCallback(
long nativeTabContentManager, int tabId, Callback<Bitmap> callback);
private static native void nativeDestroy(long nativeTabContentManager); private static native void nativeDestroy(long nativeTabContentManager);
} }
...@@ -10,6 +10,7 @@ ...@@ -10,6 +10,7 @@
#include <memory> #include <memory>
#include <utility> #include <utility>
#include "base/android/callback_android.h"
#include "base/android/jni_android.h" #include "base/android/jni_android.h"
#include "base/android/jni_string.h" #include "base/android/jni_string.h"
#include "base/android/scoped_java_ref.h" #include "base/android/scoped_java_ref.h"
...@@ -297,6 +298,18 @@ void TabContentManager::RemoveTabThumbnail(JNIEnv* env, ...@@ -297,6 +298,18 @@ void TabContentManager::RemoveTabThumbnail(JNIEnv* env,
NativeRemoveTabThumbnail(tab_id); NativeRemoveTabThumbnail(tab_id);
} }
void TabContentManager::GetTabThumbnailWithCallback(
JNIEnv* env,
const base::android::JavaParamRef<jobject>& obj,
jint tab_id,
const base::android::JavaParamRef<jobject>& j_callback) {
thumbnail_cache_->DecompressThumbnailFromFile(
tab_id, base::BindRepeating(
&TabContentManager::TabThumbnailAvailableFromDisk,
weak_factory_.GetWeakPtr(),
base::android::ScopedJavaGlobalRef<jobject>(j_callback)));
}
void TabContentManager::OnUIResourcesWereEvicted() { void TabContentManager::OnUIResourcesWereEvicted() {
thumbnail_cache_->OnUIResourcesWereEvicted(); thumbnail_cache_->OnUIResourcesWereEvicted();
} }
...@@ -320,6 +333,17 @@ void TabContentManager::PutThumbnailIntoCache(int tab_id, ...@@ -320,6 +333,17 @@ void TabContentManager::PutThumbnailIntoCache(int tab_id,
thumbnail_cache_->Put(tab_id, bitmap, thumbnail_scale); thumbnail_cache_->Put(tab_id, bitmap, thumbnail_scale);
} }
void TabContentManager::TabThumbnailAvailableFromDisk(
base::android::ScopedJavaGlobalRef<jobject> j_callback,
bool result,
SkBitmap bitmap) {
ScopedJavaLocalRef<jobject> j_bitmap;
if (!bitmap.isNull() && result)
j_bitmap = gfx::ConvertToJavaBitmap(&bitmap);
RunObjectCallbackAndroid(j_callback, j_bitmap);
}
// ---------------------------------------------------------------------------- // ----------------------------------------------------------------------------
// Native JNI methods // Native JNI methods
// ---------------------------------------------------------------------------- // ----------------------------------------------------------------------------
......
...@@ -11,6 +11,7 @@ ...@@ -11,6 +11,7 @@
#include "base/android/jni_android.h" #include "base/android/jni_android.h"
#include "base/android/jni_weak_ref.h" #include "base/android/jni_weak_ref.h"
#include "base/android/scoped_java_ref.h"
#include "base/containers/flat_map.h" #include "base/containers/flat_map.h"
#include "base/macros.h" #include "base/macros.h"
#include "base/memory/weak_ptr.h" #include "base/memory/weak_ptr.h"
...@@ -96,6 +97,11 @@ class TabContentManager : public ThumbnailCacheObserver { ...@@ -96,6 +97,11 @@ class TabContentManager : public ThumbnailCacheObserver {
const base::android::JavaParamRef<jobject>& obj, const base::android::JavaParamRef<jobject>& obj,
jint tab_id); jint tab_id);
void OnUIResourcesWereEvicted(); void OnUIResourcesWereEvicted();
void GetTabThumbnailWithCallback(
JNIEnv* env,
const base::android::JavaParamRef<jobject>& obj,
jint tab_id,
const base::android::JavaParamRef<jobject>& j_callback);
// ThumbnailCacheObserver implementation; // ThumbnailCacheObserver implementation;
void OnFinishedThumbnailRead(TabId tab_id) override; void OnFinishedThumbnailRead(TabId tab_id) override;
...@@ -113,6 +119,11 @@ class TabContentManager : public ThumbnailCacheObserver { ...@@ -113,6 +119,11 @@ class TabContentManager : public ThumbnailCacheObserver {
float thumbnail_scale, float thumbnail_scale,
const SkBitmap& bitmap); const SkBitmap& bitmap);
void TabThumbnailAvailableFromDisk(
base::android::ScopedJavaGlobalRef<jobject> j_callback,
bool result,
SkBitmap bitmap);
std::unique_ptr<ThumbnailCache> thumbnail_cache_; std::unique_ptr<ThumbnailCache> thumbnail_cache_;
ThumbnailLayerMap static_layer_cache_; ThumbnailLayerMap static_layer_cache_;
LayerMap live_layer_list_; LayerMap live_layer_list_;
......
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