Skip to content

Commit

Permalink
[Android] Fixed crash on retrieving favicon for private tab
Browse files Browse the repository at this point in the history
  • Loading branch information
samartnik committed Sep 3, 2021
1 parent fbc2af9 commit a41edcf
Showing 1 changed file with 10 additions and 8 deletions.
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

0 comments on commit a41edcf

Please sign in to comment.