Skip to content
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

Guard ChromeActivity.getTabModelSelector with areTabModelsInitialized #26724

Merged
merged 3 commits into from
Nov 26, 2024
Merged
Show file tree
Hide file tree
Changes from 1 commit
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
16 changes: 9 additions & 7 deletions android/java/org/chromium/chrome/browser/BraveRewardsHelper.java
Original file line number Diff line number Diff line change
Expand Up @@ -428,13 +428,15 @@ public static String getCurrentYear(Resources resources) {
return Integer.toString(currentTime.get(Calendar.YEAR));
}

public static Tab currentActiveChromeTabbedActivityTab() {
ChromeTabbedActivity activity = BraveRewardsHelper.getChromeTabbedActivity();
if (activity == null || activity.getTabModelSelector() == null) {
return null;
}
return activity.getActivityTab();
}
public static Tab currentActiveChromeTabbedActivityTab() {
ChromeTabbedActivity activity = BraveRewardsHelper.getChromeTabbedActivity();
if (activity == null
|| !activity.areTabModelsInitialized()
|| activity.getTabModelSelector() == null) {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

could you please also change getTabModelSelector(it's deprecated) to getTabModelSelectorSupplier as

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

thanks, changed at 3ba5886

return null;
}
return activity.getActivityTab();
}

/**
* @param fadeout: can be null
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1221,6 +1221,9 @@ public static Profile getProfile(boolean isIncognito) {
if (chromeActivity == null) {
return ProfileManager.getLastUsedRegularProfile(); // Last resort
}
if (!chromeActivity.areTabModelsInitialized()) {
return ProfileManager.getLastUsedRegularProfile();
}
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Because both return ProfileManager.getLastUsedRegularProfile(); I would unify this if statement with the one above by simply changing the condition into if (chromeActivity == null || !chromeActivity.areTabModelsInitialized())

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

thanks, fixed at a2a11d8


return chromeActivity.getTabModelSelector().getModel(isIncognito).getProfile();
}
Expand Down
17 changes: 11 additions & 6 deletions android/java/org/chromium/chrome/browser/util/TabUtils.java
Original file line number Diff line number Diff line change
Expand Up @@ -193,7 +193,7 @@ public static void openNewTab() {
}

private static void openNewTab(BraveActivity braveActivity, boolean isIncognito) {
if (braveActivity == null) return;
if (braveActivity == null || !braveActivity.areTabModelsInitialized()) return;
braveActivity.getTabModelSelector().getModel(isIncognito).commitAllTabClosures();
braveActivity.getTabCreator(isIncognito).launchNtp();
}
Expand All @@ -211,12 +211,17 @@ public static void openUrlInNewTabInBackground(boolean isIncognito, String url)
try {
BraveActivity braveActivity = BraveActivity.getBraveActivity();
if (braveActivity.getTabModelSelector() != null
&& braveActivity.areTabModelsInitialized()
&& braveActivity.getActivityTab() != null) {
braveActivity.getTabModelSelector().openNewTab(new LoadUrlParams(url),
BraveTabUiFeatureUtilities.isBraveTabGroupsEnabled()
? TabLaunchType.FROM_LONGPRESS_BACKGROUND_IN_GROUP
: TabLaunchType.FROM_LONGPRESS_BACKGROUND,
braveActivity.getActivityTab(), isIncognito);
braveActivity
.getTabModelSelector()
.openNewTab(
new LoadUrlParams(url),
BraveTabUiFeatureUtilities.isBraveTabGroupsEnabled()
? TabLaunchType.FROM_LONGPRESS_BACKGROUND_IN_GROUP
: TabLaunchType.FROM_LONGPRESS_BACKGROUND,
braveActivity.getActivityTab(),
isIncognito);
}
} catch (BraveActivity.BraveActivityNotFoundException e) {
Log.e(TAG, "openUrlInNewTabInBackground " + e);
Expand Down
Loading