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

[Android] Fix for shields on custom tabs (uplift to 1.11.x) #6044

Merged
merged 1 commit into from
Jul 9, 2020
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 @@ -50,10 +50,10 @@ protected void onCreate(Bundle savedInstanceState) {
mBraveRewardsNativeWorker.AddObserver(this);

String publisherFavIconURL = mBraveRewardsNativeWorker.GetPublisherFavIconURL(currentTabId_);
Tab currentActiveTab = BraveRewardsHelper.currentActiveTab();
Tab currentActiveTab = BraveRewardsHelper.currentActiveChromeTabbedActivityTab();
String url = currentActiveTab.getUrlString();
String favicon_url = (publisherFavIconURL.isEmpty()) ? url : publisherFavIconURL;
mIconFetcher = new org.chromium.chrome.browser.BraveRewardsHelper();
mIconFetcher = new org.chromium.chrome.browser.BraveRewardsHelper(currentActiveTab);
mIconFetcher.retrieveLargeIcon(favicon_url, this);
SetData();
SetAnimation();
Expand Down
30 changes: 18 additions & 12 deletions android/java/org/chromium/chrome/browser/BraveRewardsHelper.java
Original file line number Diff line number Diff line change
Expand Up @@ -55,15 +55,18 @@ public class BraveRewardsHelper implements LargeIconBridge.LargeIconCallback{
public static final int THANKYOU_FADE_IN_DURATION = 1500; //ms
public static final int THANKYOU_STAY_DURATION = 2000; //ms
private static final float DP_PER_INCH_MDPI = 160f;
private Tab mTab;


public interface LargeIconReadyCallback {
void onLargeIconReady(Bitmap icon);
}

public BraveRewardsHelper () {
if (mLargeIconBridge == null) {
mLargeIconBridge = new LargeIconBridge(Profile.fromWebContents(((TabImpl)currentActiveTab()).getWebContents()));
public BraveRewardsHelper(Tab tab) {
mTab = tab;
assert mTab != null;
if (mLargeIconBridge == null && mTab != null) {
mLargeIconBridge = new LargeIconBridge(Profile.fromWebContents(mTab.getWebContents()));
}
}

Expand Down Expand Up @@ -94,9 +97,8 @@ private void retrieveLargeIconInternal() {

//favIconURL (or content URL) is still not available, try to read it again
if (mFaviconUrl == null || mFaviconUrl.isEmpty() || mFaviconUrl.equals("clear")) {
Tab tab = currentActiveTab();
if (tab != null) {
mFaviconUrl = tab.getUrlString();
if (mTab != null) {
mFaviconUrl = mTab.getUrlString();
}

mHandler.postDelayed(new Runnable() {
Expand All @@ -115,6 +117,10 @@ public void run() {
}
}

public Tab getTab() {
return mTab;
}

@Override
@CalledByNative("LargeIconCallback")
public void onLargeIconAvailable(@Nullable Bitmap icon, int fallbackColor,
Expand Down Expand Up @@ -241,12 +247,12 @@ static public String getCurrentYear(Resources resources) {
return Integer.toString(currentTime.get(Calendar.YEAR));
}

public static Tab currentActiveTab() {
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.getTabModelSelector() == null) {
return null;
}
return activity.getActivityTab();
}

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -152,7 +152,7 @@ private void TriggerOnNotifyFrontTabUrlChanged() {
mHandler.post(new Runnable() {
@Override
public void run() {
Tab tab = BraveRewardsHelper.currentActiveTab();
Tab tab = BraveRewardsHelper.currentActiveChromeTabbedActivityTab();
if (tab != null && !tab.isIncognito()) {
OnNotifyFrontTabUrlChanged(tab.getId(), tab.getUrlString());
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -192,7 +192,7 @@ public BraveRewardsPanelPopup(View anchor) {
this.window.setElevation(20);
}
thisObject = this;
mIconFetcher = new BraveRewardsHelper();
mIconFetcher = new BraveRewardsHelper(BraveRewardsHelper.currentActiveChromeTabbedActivityTab());

this.window.setTouchInterceptor(new View.OnTouchListener() {
@Override
Expand Down Expand Up @@ -656,7 +656,7 @@ public void ShowWebSiteView(boolean returning_to_rewards) {
((LinearLayout)this.root.findViewById(R.id.website_summary)).setVisibility(View.VISIBLE);
((LinearLayout)this.root.findViewById(R.id.rewards_welcome_back)).setVisibility(View.GONE);
ShowRewardsSummary();
Tab currentActiveTab = BraveRewardsHelper.currentActiveTab();
Tab currentActiveTab = BraveRewardsHelper.currentActiveChromeTabbedActivityTab();
if (currentActiveTab != null && !currentActiveTab.isIncognito()) {
String url = currentActiveTab.getUrlString();
if (URLUtil.isValidUrl(url)) {
Expand Down Expand Up @@ -1207,7 +1207,7 @@ public void OnPublisherInfo(int tabId) {
}

String publisherFavIconURL = mBraveRewardsNativeWorker.GetPublisherFavIconURL(currentTabId);
Tab currentActiveTab = BraveRewardsHelper.currentActiveTab();
Tab currentActiveTab = BraveRewardsHelper.currentActiveChromeTabbedActivityTab();
String url = currentActiveTab.getUrlString();
final String favicon_url = (publisherFavIconURL.isEmpty()) ? url : publisherFavIconURL;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -128,10 +128,10 @@ public void onClick(View view) {
publisher.setText(publisherName);

String publisherFavIconURL = mBraveRewardsNativeWorker.GetPublisherFavIconURL(currentTabId_);
Tab currentActiveTab = BraveRewardsHelper.currentActiveTab();
Tab currentActiveTab = BraveRewardsHelper.currentActiveChromeTabbedActivityTab();
String url = currentActiveTab.getUrlString();
String favicon_url = (publisherFavIconURL.isEmpty()) ? url : publisherFavIconURL;
mIconFetcher = new BraveRewardsHelper();
mIconFetcher = new BraveRewardsHelper(currentActiveTab);
mIconFetcher.retrieveLargeIcon(favicon_url, this);

double balance = .0;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -183,16 +183,16 @@ public void addObserver(BraveShieldsMenuObserver menuObserver) {
mMenuObserver = menuObserver;
}

public void show(View anchorView, String host, String title, int tabId,
Profile profile) {
public void show(View anchorView, Tab tab) {
if (mHardwareButtonMenuAnchor == null) return;
mHost = host;
mTitle = title;
mTabId = tabId;
mProfile = profile;

mHost = tab.getUrlString();
mTitle = tab.getUrl().getHost();
mTabId = tab.getId();
mProfile = Profile.fromWebContents(tab.getWebContents());

mBraveRewardsNativeWorker = BraveRewardsNativeWorker.getInstance();
mIconFetcher = new BraveRewardsHelper();
mIconFetcher = new BraveRewardsHelper(tab);

int rotation = ((Activity)mContext).getWindowManager().getDefaultDisplay().getRotation();
// This fixes the bug where the bottom of the menu starts at the top of
Expand Down Expand Up @@ -349,7 +349,7 @@ private void initViews() {

private void setUpMainLayout() {
String favIconURL = mBraveRewardsNativeWorker.GetPublisherFavIconURL(mTabId);
Tab currentActiveTab = BraveRewardsHelper.currentActiveTab();
Tab currentActiveTab = mIconFetcher.getTab();
String url = currentActiveTab.getUrlString();
final String favicon_url = (favIconURL.isEmpty()) ? url : favIconURL;
mIconFetcher.retrieveLargeIcon(favicon_url, this);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -283,8 +283,7 @@ public void onClick(View v) {
if (!isValidProtocolForShields(url.getProtocol())) {
return;
}
mBraveShieldsHandler.show(mBraveShieldsButton, currentTab.getUrlString(),
url.getHost(), currentTab.getId(), Profile.fromWebContents(((TabImpl)currentTab).getWebContents()));
mBraveShieldsHandler.show(mBraveShieldsButton, currentTab);
} catch (Exception e) {
// Do nothing if url is invalid.
// Just return w/o showing shields popup.
Expand Down