зеркало из https://github.com/mozilla/gecko-dev.git
Bug 1352997 - Part 2 - Provide dedicated methods for typical homepage operations. r=sebastian,walkingice
That is figuring out whether a homepage has been set (but not caring about the specific page), or else getting the homepage URL with an automatic fallback (to about:home) if no homepage has been set. MozReview-Commit-ID: D6Uy3A4P4Qc --HG-- extra : rebase_source : 184240fc79678a2e78d7052635acc4b836fce400
This commit is contained in:
Родитель
8467f9e026
Коммит
639bd9d811
|
@ -1987,7 +1987,7 @@ public class BrowserApp extends GeckoApp
|
|||
Telemetry.addToHistogram("BROWSER_IS_USER_DEFAULT",
|
||||
(isDefaultBrowser(Intent.ACTION_VIEW) ? 1 : 0));
|
||||
Telemetry.addToHistogram("FENNEC_CUSTOM_HOMEPAGE",
|
||||
(TextUtils.isEmpty(Tabs.getHomepage(this)) ? 0 : 1));
|
||||
(Tabs.hasHomepage(this) ? 1 : 0));
|
||||
|
||||
final SharedPreferences prefs = GeckoSharedPrefs.forProfile(getContext());
|
||||
final boolean hasCustomHomepanels =
|
||||
|
@ -2767,7 +2767,7 @@ public class BrowserApp extends GeckoApp
|
|||
@Override
|
||||
public void onFinish() {
|
||||
if (mFirstrunAnimationContainer.showBrowserHint() &&
|
||||
TextUtils.isEmpty(Tabs.getHomepage(BrowserApp.this))) {
|
||||
!Tabs.hasHomepage(BrowserApp.this)) {
|
||||
enterEditingMode();
|
||||
}
|
||||
}
|
||||
|
|
|
@ -1645,8 +1645,7 @@ public abstract class GeckoApp
|
|||
// to the Recent Tabs folder of the Combined History panel.
|
||||
Tabs.getInstance().loadUrl(AboutPages.getURLForBuiltinPanelType(PanelType.DEPRECATED_RECENT_TABS), flags);
|
||||
} else {
|
||||
final String homepage = Tabs.getHomepage(this);
|
||||
Tabs.getInstance().loadUrl(!TextUtils.isEmpty(homepage) ? homepage : AboutPages.HOME, flags);
|
||||
Tabs.getInstance().loadUrl(Tabs.getHomepageForStartupTab(this), flags);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -1172,6 +1172,10 @@ public class Tabs implements BundleEventListener {
|
|||
return tabToSelect;
|
||||
}
|
||||
|
||||
/**
|
||||
* Opens a new tab and loads either about:home or, if PREFS_HOMEPAGE_FOR_EVERY_NEW_TAB is set,
|
||||
* the user's homepage.
|
||||
*/
|
||||
public Tab addTab() {
|
||||
return loadUrl(getHomepageForNewTab(mAppContext), Tabs.LOADURL_NEW_TAB);
|
||||
}
|
||||
|
@ -1338,20 +1342,35 @@ public class Tabs implements BundleEventListener {
|
|||
EventDispatcher.getInstance().dispatch("Tab:Move", data);
|
||||
}
|
||||
|
||||
/**
|
||||
* @return True if the homepage preference is not empty.
|
||||
*/
|
||||
public static boolean hasHomepage(Context context) {
|
||||
return !TextUtils.isEmpty(getHomepage(context));
|
||||
}
|
||||
|
||||
/**
|
||||
* Note: For opening a new tab while respecting the user's preferences, just use
|
||||
* {@link Tabs#addTab()} instead.
|
||||
*
|
||||
* @return The user's homepage (falling back to about:home) if PREFS_HOMEPAGE_FOR_EVERY_NEW_TAB
|
||||
* is enabled, or else about:home.
|
||||
*/
|
||||
@NonNull
|
||||
public static String getHomepageForNewTab(Context context) {
|
||||
private static String getHomepageForNewTab(Context context) {
|
||||
final SharedPreferences preferences = GeckoSharedPrefs.forApp(context);
|
||||
final boolean forEveryNewTab = preferences.getBoolean(GeckoPreferences.PREFS_HOMEPAGE_FOR_EVERY_NEW_TAB, false);
|
||||
|
||||
if (forEveryNewTab) {
|
||||
final String homePage = getHomepage(context);
|
||||
if (TextUtils.isEmpty(homePage)) {
|
||||
return AboutPages.HOME;
|
||||
} else {
|
||||
return homePage;
|
||||
}
|
||||
}
|
||||
return AboutPages.HOME;
|
||||
return forEveryNewTab ? getHomepageForStartupTab(context) : AboutPages.HOME;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return The user's homepage, or about:home if none is set.
|
||||
*/
|
||||
@NonNull
|
||||
public static String getHomepageForStartupTab(Context context) {
|
||||
final String homepage = Tabs.getHomepage(context);
|
||||
return TextUtils.isEmpty(homepage) ? AboutPages.HOME : homepage;
|
||||
}
|
||||
|
||||
@Nullable
|
||||
|
|
Загрузка…
Ссылка в новой задаче