Skip to content
This repository has been archived by the owner on Jul 22, 2024. It is now read-only.

Handle potential exception capturing snapshots #2386

Merged
merged 2 commits into from
Nov 27, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -474,15 +474,25 @@ public void captureBitmap() {
if (mState.mDisplay == null || !mFirstContentfulPaint) {
return;
}
mState.mDisplay.screenshot().aspectPreservingSize(500).capture().then(bitmap -> {
if (bitmap != null) {
BitmapCache.getInstance(mContext).addBitmap(getId(), bitmap);
for (BitmapChangedListener listener: mBitmapChangedListeners) {
listener.onBitmapChanged(Session.this, bitmap);
try {
mState.mDisplay.screenshot().aspectPreservingSize(500).capture().then(bitmap -> {
if (bitmap != null) {
BitmapCache.getInstance(mContext).addBitmap(getId(), bitmap);
for (BitmapChangedListener listener: mBitmapChangedListeners) {
listener.onBitmapChanged(Session.this, bitmap);
}
}
}
return null;
});
return null;
}).exceptionally(throwable -> {
Log.e(LOGTAG, "Error capturing session bitmap");
throwable.printStackTrace();
return null;
});
} catch (Exception ex) {
Log.e(LOGTAG, "Error capturing session bitmap");
ex.printStackTrace();
}

}

public CompletableFuture<Void> captureBackgroundBitmap(int displayWidth, int displayHeight) {
Expand All @@ -497,19 +507,38 @@ public CompletableFuture<Void> captureBackgroundBitmap(int displayWidth, int dis
CompletableFuture<Void> result = new CompletableFuture<>();
GeckoDisplay display = mState.mSession.acquireDisplay();
display.surfaceChanged(captureSurface, displayWidth, displayHeight);
display.screenshot().aspectPreservingSize(500).capture().then(bitmap -> {
if (bitmap != null) {
BitmapCache.getInstance(mContext).addBitmap(getId(), bitmap);
for (BitmapChangedListener listener: mBitmapChangedListeners) {
listener.onBitmapChanged(Session.this, bitmap);
}
}

Runnable cleanResources = () -> {
display.surfaceDestroyed();
mState.mSession.releaseDisplay(display);
BitmapCache.getInstance(mContext).releaseCaptureSurface();
};

try {
display.screenshot().aspectPreservingSize(500).capture().then(bitmap -> {
if (bitmap != null) {
BitmapCache.getInstance(mContext).addBitmap(getId(), bitmap);
for (BitmapChangedListener listener : mBitmapChangedListeners) {
listener.onBitmapChanged(Session.this, bitmap);
}
}
cleanResources.run();
result.complete(null);
return null;
}).exceptionally(throwable -> {
Log.e(LOGTAG, "Error capturing session background bitmap");
throwable.printStackTrace();
cleanResources.run();
result.complete(null);
return null;
});
}
catch (Exception ex) {
Log.e(LOGTAG, "Error capturing session background bitmap");
ex.printStackTrace();
cleanResources.run();
result.complete(null);
return null;
});
}
return result;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1075,6 +1075,7 @@ public void setSession(@NonNull Session aSession, @OldSessionDisplayAction int a
listener.onSessionChanged(oldSession, aSession);
}
}
mCaptureOnPageStop = false;
hideLibraryPanels();
}

Expand Down