Fix bug with background tabs opening urls

If a background tab opened a URL that triggered the intent chooser, and
the user chose to open the URL in the browser, the current tab would
open the URL instead of the originating URL. Using the tab’s hashcode,
the original tab now will open the URL.
This commit is contained in:
anthony restaino 2017-05-02 22:04:31 -04:00
parent e8b8ddaa02
commit ee078c1495
4 changed files with 100 additions and 75 deletions

View File

@ -556,6 +556,26 @@ public class TabsManager {
return mCurrentTab; return mCurrentTab;
} }
/**
* Returns the {@link LightningView} with
* the provided hash, or null if there is
* no tab with the hash.
*
* @param hashCode the hashcode.
* @return the tab with an identical hash, or null.
*/
@Nullable
public synchronized LightningView getTabForHashCode(int hashCode) {
for (LightningView tab : mTabList) {
if (tab.getWebView() != null) {
if (tab.getWebView().hashCode() == hashCode) {
return tab;
}
}
}
return null;
}
/** /**
* Switch the current tab to the one at the given position. * Switch the current tab to the one at the given position.
* It returns the selected tab that has been switced to. * It returns the selected tab that has been switced to.

View File

@ -220,13 +220,16 @@ public class BrowserPresenter {
} else { } else {
url = null; url = null;
} }
int num = 0; int tabHashCode = 0;
if (intent != null && intent.getExtras() != null) { if (intent != null && intent.getExtras() != null) {
num = intent.getExtras().getInt(Constants.INTENT_ORIGIN); tabHashCode = intent.getExtras().getInt(Constants.INTENT_ORIGIN);
} }
if (num == 1) { if (tabHashCode != 0) {
loadUrlInCurrentView(url); LightningView tab = mTabsModel.getTabForHashCode(tabHashCode);
if (tab != null) {
tab.loadUrl(url);
}
} else if (url != null) { } else if (url != null) {
if (url.startsWith(Constants.FILE)) { if (url.startsWith(Constants.FILE)) {
mView.showBlockedLocalFileDialog(new DialogInterface.OnClickListener() { mView.showBlockedLocalFileDialog(new DialogInterface.OnClickListener() {

View File

@ -31,7 +31,7 @@ public class IntentUtils {
"(?:http|https|file)://" + "|(?:inline|data|about|javascript):" + "|(?:.*:.*@)" "(?:http|https|file)://" + "|(?:inline|data|about|javascript):" + "|(?:.*:.*@)"
+ ')' + "(.*)"); + ')' + "(.*)");
public IntentUtils(Activity activity) { public IntentUtils(@NonNull Activity activity) {
mActivity = activity; mActivity = activity;
} }
@ -63,7 +63,7 @@ public class IntentUtils {
} }
} }
if (tab != null) { if (tab != null) {
intent.putExtra(Constants.INTENT_ORIGIN, 1); intent.putExtra(Constants.INTENT_ORIGIN, tab.hashCode());
} }
Matcher m = ACCEPTED_URI_SCHEMA.matcher(url); Matcher m = ACCEPTED_URI_SCHEMA.matcher(url);
@ -84,7 +84,7 @@ public class IntentUtils {
* Search for intent handlers that are specific to this URL aka, specialized * Search for intent handlers that are specific to this URL aka, specialized
* apps like google maps or youtube * apps like google maps or youtube
*/ */
private boolean isSpecializedHandlerAvailable(Intent intent) { private boolean isSpecializedHandlerAvailable(@NonNull Intent intent) {
PackageManager pm = mActivity.getPackageManager(); PackageManager pm = mActivity.getPackageManager();
List<ResolveInfo> handlers = pm.queryIntentActivities(intent, List<ResolveInfo> handlers = pm.queryIntentActivities(intent,
PackageManager.GET_RESOLVED_FILTER); PackageManager.GET_RESOLVED_FILTER);

View File

@ -77,8 +77,8 @@ public class LightningView {
private static final int API = android.os.Build.VERSION.SDK_INT; private static final int API = android.os.Build.VERSION.SDK_INT;
private static final int SCROLL_UP_THRESHOLD = Utils.dpToPx(10); private static final int SCROLL_UP_THRESHOLD = Utils.dpToPx(10);
private static String sHomepage; @Nullable private static String sHomepage;
private static String sDefaultUserAgent; @Nullable private static String sDefaultUserAgent;
private static float sMaxFling; private static float sMaxFling;
private static final float[] sNegativeColorArray = { private static final float[] sNegativeColorArray = {
-1.0f, 0, 0, 0, 255, // red -1.0f, 0, 0, 0, 255, // red
@ -193,6 +193,8 @@ public class LightningView {
if (mWebView == null) { if (mWebView == null) {
return; return;
} }
Preconditions.checkNonNull(sHomepage);
switch (sHomepage) { switch (sHomepage) {
case Constants.SCHEME_HOMEPAGE: case Constants.SCHEME_HOMEPAGE:
loadStartpage(); loadStartpage();