Bug 1351739 - Part 0 - Use INVALID_TAB_ID more. r=sebastian,walkingice

-1 is probably not all that mysterious as far as magic numbers go, but still...

MozReview-Commit-ID: zK3P6HeWzK

--HG--
extra : rebase_source : 59530eafb11f68fddb29a53775a394fcd1a08d69
This commit is contained in:
Jan Henning 2017-04-06 21:30:55 +02:00
Родитель c768aca43c
Коммит 1c3e4ca69b
2 изменённых файлов: 17 добавлений и 15 удалений

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

@ -129,6 +129,8 @@ import java.util.Map;
import java.util.Set;
import java.util.concurrent.TimeUnit;
import static org.mozilla.gecko.Tabs.INVALID_TAB_ID;
public abstract class GeckoApp
extends GeckoActivity
implements
@ -214,7 +216,7 @@ public abstract class GeckoApp
protected boolean mShouldRestore;
private boolean mSessionRestoreParsingFinished = false;
protected int lastSelectedTabId = -1;
protected int lastSelectedTabId = INVALID_TAB_ID;
private boolean foregrounded = false;
@ -242,7 +244,7 @@ public abstract class GeckoApp
}
public int getNewTabId(int oldTabId) {
return tabIdMap.get(oldTabId, -1);
return tabIdMap.get(oldTabId, INVALID_TAB_ID);
}
@Override
@ -294,7 +296,7 @@ public abstract class GeckoApp
});
try {
int oldTabId = tabObject.optInt("tabId", -1);
int oldTabId = tabObject.optInt("tabId", INVALID_TAB_ID);
int newTabId = tab.getId();
tabObject.put("tabId", newTabId);
if (oldTabId >= 0) {
@ -2202,7 +2204,7 @@ public abstract class GeckoApp
if (ACTION_LOAD.equals(action)) {
Tabs.getInstance().loadUrl(intent.getDataString());
lastSelectedTabId = -1;
lastSelectedTabId = INVALID_TAB_ID;
} else if (Intent.ACTION_VIEW.equals(action)) {
processActionViewIntent(new Runnable() {
@Override
@ -2215,7 +2217,7 @@ public abstract class GeckoApp
Tabs.getInstance().loadUrlWithIntentExtras(url, intent, flags);
}
});
lastSelectedTabId = -1;
lastSelectedTabId = INVALID_TAB_ID;
} else if (ACTION_HOMESCREEN_SHORTCUT.equals(action)) {
mLayerView.loadUri(uri, GeckoView.LOAD_SWITCH_TAB);
} else if (Intent.ACTION_SEARCH.equals(action)) {
@ -2229,9 +2231,9 @@ public abstract class GeckoApp
settingsIntent.putExtras(intent.getUnsafe());
startActivity(settingsIntent);
} else if (ACTION_SWITCH_TAB.equals(action)) {
final int tabId = intent.getIntExtra("TabId", -1);
final int tabId = intent.getIntExtra("TabId", INVALID_TAB_ID);
Tabs.getInstance().selectTab(tabId);
lastSelectedTabId = -1;
lastSelectedTabId = INVALID_TAB_ID;
}
recordStartupActionTelemetry(passedUri, action);

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

@ -221,7 +221,7 @@ public class Tabs implements BundleEventListener {
return tab.getId();
}
}
return -1;
return INVALID_TAB_ID;
}
// Must be synchronized to avoid racing on mBookmarksContentObserver.
@ -389,7 +389,7 @@ public class Tabs implements BundleEventListener {
@RobocopTarget
public synchronized Tab getTab(int id) {
if (id == -1)
if (id == INVALID_TAB_ID)
return null;
if (mTabs.size() == 0)
@ -552,7 +552,7 @@ public class Tabs implements BundleEventListener {
}
// All other events handled below should contain a tabID property
final int id = message.getInt("tabID", -1);
final int id = message.getInt("tabID", INVALID_TAB_ID);
Tab tab = getTab(id);
// "Tab:Added" is a special case because tab will be null if the tab was just added
@ -691,7 +691,7 @@ public class Tabs implements BundleEventListener {
}
} else if ("Tab:SetParentId".equals(event)) {
tab.setParentId(message.getInt("parentID", -1));
tab.setParentId(message.getInt("parentID", INVALID_TAB_ID));
}
}
@ -931,7 +931,7 @@ public class Tabs implements BundleEventListener {
*/
@RobocopTarget
public Tab loadUrl(String url, int flags) {
return loadUrl(url, null, -1, null, flags);
return loadUrl(url, null, INVALID_TAB_ID, null, flags);
}
public Tab loadUrlWithIntentExtras(final String url, final SafeIntent intent, final int flags) {
@ -944,7 +944,7 @@ public class Tabs implements BundleEventListener {
// 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);
return loadUrl(url, null, INVALID_TAB_ID, intent, flags);
}
public Tab loadUrl(final String url, final String searchEngine, final int parentId, final int flags) {
@ -957,7 +957,7 @@ public class Tabs implements BundleEventListener {
* @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 parentId ID of this tab's parent, or INVALID_TAB_ID (-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
*
@ -1098,7 +1098,7 @@ public class Tabs implements BundleEventListener {
// getSelectedTab() can return null if no tab has been created yet
// (i.e., we're restoring a session after a crash). In these cases,
// don't mark any tabs as a parent.
int parentId = -1;
int parentId = INVALID_TAB_ID;
int flags = LOADURL_NEW_TAB;
final Tab selectedTab = getSelectedTab();