Skip to content

[Android] Fixed crash on retrieving favicon for private tab #9972

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Sep 3, 2021
Merged
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
18 changes: 10 additions & 8 deletions android/java/org/chromium/chrome/browser/BraveRewardsHelper.java
Original file line number Diff line number Diff line change
Expand Up @@ -78,6 +78,7 @@ public class BraveRewardsHelper implements LargeIconBridge.LargeIconCallback{
public static final int THANKYOU_STAY_DURATION = 2000; //ms
private static final float DP_PER_INCH_MDPI = 160f;
private Tab mTab;
private Profile mProfile;

public static void setRewardsEnvChange(boolean isEnabled) {
SharedPreferences.Editor sharedPreferencesEditor =
Expand Down Expand Up @@ -185,8 +186,9 @@ public interface LargeIconReadyCallback {
public BraveRewardsHelper(Tab tab) {
mTab = tab;
assert mTab != null;
if (mLargeIconBridge == null && mTab != null) {
mLargeIconBridge = new LargeIconBridge(Profile.fromWebContents(mTab.getWebContents()));
mProfile = Profile.getLastUsedRegularProfile();
if (mLargeIconBridge == null && mTab != null && mProfile != null) {
mLargeIconBridge = new LargeIconBridge(mProfile);
}
}

Expand All @@ -201,7 +203,6 @@ private void destroy() {
mCallback = null;
}


public void detach() {
mCallback = null;
}
Expand All @@ -213,9 +214,9 @@ public void retrieveLargeIcon(String favIconURL, LargeIconReadyCallback callback
}

private void retrieveLargeIconInternal() {
mFetchCount ++;
mFetchCount++;

//favIconURL (or content URL) is still not available, try to read it again
// FavIconURL (or content URL) is still not available, try to read it again.
if (mFaviconUrl == null || mFaviconUrl.isEmpty() || mFaviconUrl.equals("clear")) {
if (mTab != null) {
mFaviconUrl = mTab.getUrl().getSpec();
Expand All @@ -231,9 +232,10 @@ public void run() {
return;
}

//get the icon
if (mLargeIconBridge!= null && mCallback != null && !mFaviconUrl.isEmpty()) {
mLargeIconBridge.getLargeIconForUrl(new GURL(mFaviconUrl),FAVICON_DESIRED_SIZE, this);
// Get the icon.
if (mLargeIconBridge != null && mCallback != null && !mFaviconUrl.isEmpty()
&& mProfile.isNativeInitialized()) {
mLargeIconBridge.getLargeIconForUrl(new GURL(mFaviconUrl), FAVICON_DESIRED_SIZE, this);
}
}

Expand Down