Bug 1162423 - Handle Browser.EXTRA_CREATE_NEW_TAB. r=margaret

I simplified the code by passing an Intent into the loadUrl functions rather
than two arguments.

--HG--
extra : rebase_source : 509865bd053c8d8fca0268fb507876325a81fdb9
This commit is contained in:
Michael Comella 2015-05-11 11:11:18 -07:00
Родитель 66c14e8046
Коммит 39f6610772
3 изменённых файлов: 37 добавлений и 30 удалений

Просмотреть файл

@ -20,7 +20,6 @@ import java.util.Locale;
import java.util.Map;
import java.util.Set;
import android.provider.Browser;
import org.json.JSONArray;
import org.json.JSONException;
import org.json.JSONObject;
@ -1436,18 +1435,18 @@ public abstract class GeckoApp
* Loads the initial tab at Fennec startup. This tab will load with the given
* external URL. If that URL is invalid, about:home will be loaded.
*
* @param url External URL to load.
* @param extraApplicationId Identifies the calling application; delivered with the URL
* @param url External URL to load.
* @param intent External intent whose extras modify the request
* @param flags Flags used to load the load
*/
protected void loadStartupTabWithExternalUrl(final String url, final String extraApplicationId,
final int flags) {
protected void loadStartupTab(final String url, final SafeIntent intent, final int flags) {
// Invalid url
if (url == null) {
loadStartupTabWithAboutHome(flags);
return;
}
Tabs.getInstance().loadUrl(url, extraApplicationId, flags);
Tabs.getInstance().loadUrlWithIntentExtras(url, intent, flags);
}
private void initialize() {
@ -1514,8 +1513,7 @@ public abstract class GeckoApp
if (ACTION_HOMESCREEN_SHORTCUT.equals(action)) {
flags |= Tabs.LOADURL_PINNED;
}
final String extraApplicationId = intent.getStringExtra(Browser.EXTRA_APPLICATION_ID);
loadStartupTabWithExternalUrl(passedUri, extraApplicationId, flags);
loadStartupTab(passedUri, intent, flags);
} else {
if (!mIsRestoringActivity) {
loadStartupTabWithAboutHome(Tabs.LOADURL_NEW_TAB);
@ -1829,11 +1827,10 @@ public abstract class GeckoApp
TabQueueHelper.openQueuedUrls(GeckoApp.this, mProfile, TabQueueHelper.FILE_NAME, true);
} else {
String uri = intent.getDataString();
final String extraApplicationId = intent.getStringExtra(Browser.EXTRA_APPLICATION_ID);
Tabs.getInstance().loadUrl(uri, extraApplicationId, Tabs.LOADURL_NEW_TAB |
Tabs.LOADURL_USER_ENTERED |
Tabs.LOADURL_EXTERNAL);
final String url = intent.getDataString();
Tabs.getInstance().loadUrlWithIntentExtras(url, intent, Tabs.LOADURL_NEW_TAB |
Tabs.LOADURL_USER_ENTERED |
Tabs.LOADURL_EXTERNAL);
}
}
});

Просмотреть файл

@ -13,9 +13,12 @@ import java.util.concurrent.atomic.AtomicInteger;
import org.json.JSONException;
import org.json.JSONObject;
import org.mozilla.gecko.AppConstants.Versions;
import org.mozilla.gecko.db.BrowserDB;
import org.mozilla.gecko.favicons.Favicons;
import org.mozilla.gecko.fxa.FirefoxAccounts;
import org.mozilla.gecko.mozglue.ContextUtils.SafeIntent;
import org.mozilla.gecko.mozglue.JNITarget;
import org.mozilla.gecko.mozglue.RobocopTarget;
import org.mozilla.gecko.sync.setup.SyncAccounts;
@ -31,6 +34,7 @@ import android.database.ContentObserver;
import android.graphics.Color;
import android.net.Uri;
import android.os.Handler;
import android.provider.Browser;
import android.util.Log;
public class Tabs implements GeckoEventListener {
@ -813,8 +817,10 @@ public class Tabs implements GeckoEventListener {
return loadUrl(url, null, -1, null, flags);
}
public Tab loadUrl(final String url, final String applicationId, final int flags) {
return loadUrl(url, null, -1, applicationId, flags);
public Tab loadUrlWithIntentExtras(final String url, final SafeIntent intent, final int flags) {
// Note: we don't get the URL from the intent so the calling
// method has the opportunity to change the URL if applicable.
return loadUrl(url, null, -1, intent, flags);
}
public Tab loadUrl(final String url, final String searchEngine, final int parentId, final int flags) {
@ -824,17 +830,17 @@ public class Tabs implements GeckoEventListener {
/**
* Loads a tab with the given URL.
*
* @param url URL of page to load, or search term used if searchEngine is given
* @param searchEngine if given, the search engine with this name is used
* to search for the url string; if null, the URL is loaded directly
* @param parentId ID of this tab's parent, or -1 if it has no parent
* @param applicationId Identity of the calling application
* @param flags flags used to load tab
* @param url URL of page to load, or search term used if searchEngine is given
* @param searchEngine if given, the search engine with this name is used
* to search for the url string; if null, the URL is loaded directly
* @param parentId ID of this tab's parent, or -1 if it has no parent
* @param intent an intent whose extras are used to modify the request
* @param flags flags used to load tab
*
* @return the Tab if a new one was created; null otherwise
* @return the Tab if a new one was created; null otherwise
*/
public Tab loadUrl(final String url, final String searchEngine, final int parentId,
final String applicationId, final int flags) {
final SafeIntent intent, final int flags) {
JSONObject args = new JSONObject();
Tab tabToSelect = null;
boolean delayLoad = (flags & LOADURL_DELAY_LOAD) != 0;
@ -857,11 +863,16 @@ public class Tabs implements GeckoEventListener {
args.put("desktopMode", desktopMode);
final boolean needsNewTab;
final String applicationId = (intent == null) ? null :
intent.getStringExtra(Browser.EXTRA_APPLICATION_ID);
if (applicationId == null) {
needsNewTab = (flags & LOADURL_NEW_TAB) != 0;
} else {
// If you modify this code, be careful that intent != null.
final boolean extraCreateNewTab = (Versions.feature12Plus) ?
intent.getBooleanExtra(Browser.EXTRA_CREATE_NEW_TAB, false) : false;
final Tab applicationTab = getTabForApplicationId(applicationId);
if (applicationTab == null) {
if (applicationTab == null || extraCreateNewTab) {
needsNewTab = true;
} else {
needsNewTab = false;

Просмотреть файл

@ -186,18 +186,17 @@ public class WebappImpl extends GeckoApp implements InstallCallback {
@Override
protected void loadStartupTabWithAboutHome(final int flags) {
loadStartupTabWithExternalUrl(null, null, flags);
loadStartupTab(null, null, flags);
}
// Note: there is no support for applicationId in Webapps at
// the moment because I don't have time to debug/test.
// Note: there is no support for loading with intent extras in
// Webapps at the moment because I don't have time to debug/test.
@Override
protected void loadStartupTabWithExternalUrl(final String uri, final String applicationId,
int flags) {
protected void loadStartupTab(final String uri, final SafeIntent unusedIntent, int flags) {
// Load a tab so it's available for any code that assumes a tab
// before the app tab itself is loaded in BrowserApp._loadWebapp.
flags = Tabs.LOADURL_NEW_TAB | Tabs.LOADURL_USER_ENTERED | Tabs.LOADURL_EXTERNAL;
super.loadStartupTabWithExternalUrl("about:blank", null, flags);
super.loadStartupTab("about:blank", null, flags);
}
private void showSplash() {