Skip to content

Commit

Permalink
fix crash omnibox search banner android
Browse files Browse the repository at this point in the history
  • Loading branch information
deeppandya committed Aug 30, 2022
1 parent bc74624 commit 7587531
Show file tree
Hide file tree
Showing 6 changed files with 1 addition and 73 deletions.
4 changes: 0 additions & 4 deletions android/java/apk_for_test.flags
Original file line number Diff line number Diff line change
Expand Up @@ -467,11 +467,7 @@
}

-keep class org.chromium.chrome.browser.omnibox.suggestions.DropdownItemViewInfoListBuilder {
*** mDropdownHeight;
*** mPriorityOrderedSuggestionProcessors;
public <init>(...);
*** getVisibleSuggestionsCount(...);
*** getProcessorForSuggestion(...);
}

-keep class org.chromium.chrome.browser.omnibox.suggestions.BraveDropdownItemViewInfoListBuilder {
Expand Down
5 changes: 0 additions & 5 deletions android/java/proguard.flags
Original file line number Diff line number Diff line change
Expand Up @@ -13,11 +13,6 @@
*** createViewProvider(...);
}

-keep class org.chromium.chrome.browser.omnibox.suggestions.DropdownItemViewInfoListBuilder {
*** getVisibleSuggestionsCount(...);
*** getProcessorForSuggestion(...);
}

-keep class org.chromium.components.browser_ui.site_settings.ContentSettingsResources {
*** getResourceItem(...);
}
Expand Down
14 changes: 0 additions & 14 deletions android/javatests/org/chromium/chrome/browser/BytecodeTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -404,14 +404,6 @@ public void testMethodsForInvocationExist() throws Exception {
"createViewProvider", true, ViewProvider.class, Context.class,
MVCListAdapter.ModelList.class));

Assert.assertTrue(methodExists(
"org/chromium/chrome/browser/omnibox/suggestions/DropdownItemViewInfoListBuilder",
"getVisibleSuggestionsCount", true, int.class, AutocompleteResult.class));
Assert.assertTrue(methodExists(
"org/chromium/chrome/browser/omnibox/suggestions/DropdownItemViewInfoListBuilder",
"getProcessorForSuggestion", true, SuggestionProcessor.class,
AutocompleteMatch.class, int.class));

// Check for method type declaration changes here
Assert.assertTrue(methodExists(
"org/chromium/components/browser_ui/site_settings/BraveContentSettingsResources",
Expand Down Expand Up @@ -770,12 +762,6 @@ public void testFieldsExist() throws Exception {
"org/chromium/chrome/browser/ntp/NewTabPageLayout", "mMvTilesContainerLayout"));
Assert.assertTrue(
fieldExists("org/chromium/chrome/browser/dom_distiller/ReaderModeManager", "mTab"));
Assert.assertTrue(fieldExists(
"org/chromium/chrome/browser/omnibox/suggestions/DropdownItemViewInfoListBuilder",
"mDropdownHeight"));
Assert.assertTrue(fieldExists(
"org/chromium/chrome/browser/omnibox/suggestions/DropdownItemViewInfoListBuilder",
"mPriorityOrderedSuggestionProcessors"));
}

@Test
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -37,17 +37,12 @@ class BraveDropdownItemViewInfoListBuilder extends DropdownItemViewInfoListBuild
private @Nullable BraveSearchBannerProcessor mBraveSearchBannerProcessor;
private UrlBarEditingTextStateProvider mUrlBarEditingTextProvider;
private @NonNull Supplier<Tab> mActivityTabSupplier;
private List<SuggestionProcessor> mPriorityOrderedSuggestionProcessors;
private static final List<String> mBraveSearchEngineDefaultRegions =
Arrays.asList("CA", "DE", "FR", "GB", "US", "AT", "ES", "MX");
@Px
private static final int DROPDOWN_HEIGHT_UNKNOWN = -1;
private static final int DEFAULT_SIZE_OF_VISIBLE_GROUP = 5;

@Px
private int mDropdownHeight;
@Px
private int mCalculatedSuggestionsHeight;
private Context mContext;

BraveDropdownItemViewInfoListBuilder(@NonNull Supplier<Tab> tabSupplier,
Expand Down Expand Up @@ -81,51 +76,14 @@ void onNativeInitialized() {
mBraveSearchBannerProcessor.onNativeInitialized();
}

private void calculateSuggestionsHeight(
AutocompleteResult autocompleteResult, int visibleSuggestionsCount) {
final List<AutocompleteMatch> suggestions = autocompleteResult.getSuggestionsList();

@Px
int calculatedSuggestionsHeight = 0;
int lastVisibleIndex;
for (lastVisibleIndex = 0; lastVisibleIndex < visibleSuggestionsCount; lastVisibleIndex++) {
final AutocompleteMatch suggestion = suggestions.get(lastVisibleIndex);

final SuggestionProcessor processor =
(SuggestionProcessor) BraveReflectionUtil.InvokeMethod(
DropdownItemViewInfoListBuilder.class, this,
"getProcessorForSuggestion", AutocompleteMatch.class, suggestion,
int.class, lastVisibleIndex);

calculatedSuggestionsHeight += processor.getMinimumViewHeight();
}

mCalculatedSuggestionsHeight = calculatedSuggestionsHeight;
}

@Override
@NonNull
List<DropdownItemViewInfo> buildDropdownViewInfoList(AutocompleteResult autocompleteResult) {
mBraveSearchBannerProcessor.onSuggestionsReceived();
List<DropdownItemViewInfo> viewInfoList =
super.buildDropdownViewInfoList(autocompleteResult);
if (mDropdownHeight != DROPDOWN_HEIGHT_UNKNOWN) {
int visibleSuggestionsCount = (int) BraveReflectionUtil.InvokeMethod(
DropdownItemViewInfoListBuilder.class, this, "getVisibleSuggestionsCount",
AutocompleteResult.class, autocompleteResult);

calculateSuggestionsHeight(autocompleteResult, visibleSuggestionsCount);
}

if (isBraveSearchPromoBanner()) {
mCalculatedSuggestionsHeight += mBraveSearchBannerProcessor.getMinimumViewHeight();
int viewHeight = mContext.getResources().getDimensionPixelSize(
R.dimen.omnibox_suggestion_semicompact_height);
while (mCalculatedSuggestionsHeight >= mDropdownHeight) {
mCalculatedSuggestionsHeight -= viewHeight;
viewInfoList.remove(viewInfoList.size() - 1);
}

final PropertyModel model = mBraveSearchBannerProcessor.createModel();
mBraveSearchBannerProcessor.populateModel(model);
viewInfoList.add(new DropdownItemViewInfo(mBraveSearchBannerProcessor, model,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@
import org.chromium.ui.base.PageTransition;
import org.chromium.ui.modelutil.PropertyModel;

/** A class that handles model and view creation for the suggestion headers. */
/** A class that handles model and view creation for the suggestion brave search banner. */
public class BraveSearchBannerProcessor implements DropdownItemProcessor {
private final BraveSuggestionHost mSuggestionHost;
private final int mMinimumHeight;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,12 +19,5 @@ public BraveDropdownItemViewInfoListBuilderClassAdapter(ClassVisitor visitor) {

redirectConstructor(
sDropdownItemViewInfoListBuilder, sBraveDropdownItemViewInfoListBuilder);

deleteField(sBraveDropdownItemViewInfoListBuilder, "mDropdownHeight");
makeProtectedField(sDropdownItemViewInfoListBuilder, "mDropdownHeight");

deleteField(sBraveDropdownItemViewInfoListBuilder, "mPriorityOrderedSuggestionProcessors");
makeProtectedField(
sDropdownItemViewInfoListBuilder, "mPriorityOrderedSuggestionProcessors");
}
}

0 comments on commit 7587531

Please sign in to comment.