| OLD | NEW |
| 1 // Copyright 2016 The Chromium Authors. All rights reserved. | 1 // Copyright 2016 The Chromium Authors. All rights reserved. |
| 2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
| 4 | 4 |
| 5 package org.chromium.chrome.browser.history; | 5 package org.chromium.chrome.browser.history; |
| 6 | 6 |
| 7 import android.content.Context; | 7 import android.content.Context; |
| 8 import android.content.Intent; | 8 import android.content.Intent; |
| 9 | 9 |
| 10 import org.chromium.base.ContextUtils; | 10 import org.chromium.base.ContextUtils; |
| 11 import org.chromium.chrome.R; | 11 import org.chromium.chrome.R; |
| 12 import org.chromium.chrome.browser.ChromeActivity; | 12 import org.chromium.chrome.browser.ChromeActivity; |
| 13 import org.chromium.chrome.browser.ChromeFeatureList; | |
| 14 import org.chromium.chrome.browser.IntentHandler; | 13 import org.chromium.chrome.browser.IntentHandler; |
| 15 import org.chromium.chrome.browser.UrlConstants; | 14 import org.chromium.chrome.browser.UrlConstants; |
| 16 import org.chromium.chrome.browser.tab.Tab; | 15 import org.chromium.chrome.browser.tab.Tab; |
| 17 import org.chromium.content_public.browser.LoadUrlParams; | 16 import org.chromium.content_public.browser.LoadUrlParams; |
| 18 import org.chromium.ui.base.DeviceFormFactor; | 17 import org.chromium.ui.base.DeviceFormFactor; |
| 19 import org.chromium.ui.base.PageTransition; | |
| 20 | 18 |
| 21 /** | 19 /** |
| 22 * Utility methods for the browsing history manager. | 20 * Utility methods for the browsing history manager. |
| 23 */ | 21 */ |
| 24 public class HistoryManagerUtils { | 22 public class HistoryManagerUtils { |
| 25 private static final Object NATIVE_HISTORY_ENABLED_LOCK = new Object(); | |
| 26 private static Boolean sNativeHistoryEnabled; | |
| 27 | |
| 28 /** | |
| 29 * @return Whether the Android-specific browsing history manager is enabled. | |
| 30 */ | |
| 31 public static boolean isAndroidHistoryManagerEnabled() { | |
| 32 synchronized (NATIVE_HISTORY_ENABLED_LOCK) { | |
| 33 if (sNativeHistoryEnabled == null) { | |
| 34 sNativeHistoryEnabled = ChromeFeatureList.isEnabled("AndroidHist
oryManager"); | |
| 35 } | |
| 36 } | |
| 37 | |
| 38 return sNativeHistoryEnabled; | |
| 39 } | |
| 40 | |
| 41 /** | 23 /** |
| 42 * Opens the browsing history manager. | 24 * Opens the browsing history manager. |
| 43 * | 25 * |
| 44 * @param activity The {@link ChromeActivity} that owns the {@link HistoryMa
nager}. | 26 * @param activity The {@link ChromeActivity} that owns the {@link HistoryMa
nager}. |
| 45 * @param tab The {@link Tab} to used to display the native page version of
the | 27 * @param tab The {@link Tab} to used to display the native page version of
the |
| 46 * {@link HistoryManager}. | 28 * {@link HistoryManager}. |
| 47 */ | 29 */ |
| 48 public static void showHistoryManager(ChromeActivity activity, Tab tab) { | 30 public static void showHistoryManager(ChromeActivity activity, Tab tab) { |
| 49 if (!isAndroidHistoryManagerEnabled()) { | |
| 50 tab.loadUrl(new LoadUrlParams(UrlConstants.HISTORY_URL, PageTransiti
on.AUTO_TOPLEVEL)); | |
| 51 return; | |
| 52 } | |
| 53 | |
| 54 Context appContext = ContextUtils.getApplicationContext(); | 31 Context appContext = ContextUtils.getApplicationContext(); |
| 55 if (activity.getBottomSheet() != null) { | 32 if (activity.getBottomSheet() != null) { |
| 56 activity.getBottomSheetContentController().showContentAndOpenSheet(R
.id.action_history); | 33 activity.getBottomSheetContentController().showContentAndOpenSheet(R
.id.action_history); |
| 57 } else if (DeviceFormFactor.isTablet(appContext)) { | 34 } else if (DeviceFormFactor.isTablet(appContext)) { |
| 58 // History shows up as a tab on tablets. | 35 // History shows up as a tab on tablets. |
| 59 LoadUrlParams params = new LoadUrlParams(UrlConstants.NATIVE_HISTORY
_URL); | 36 LoadUrlParams params = new LoadUrlParams(UrlConstants.NATIVE_HISTORY
_URL); |
| 60 tab.loadUrl(params); | 37 tab.loadUrl(params); |
| 61 } else { | 38 } else { |
| 62 Intent intent = new Intent(); | 39 Intent intent = new Intent(); |
| 63 intent.setClass(appContext, HistoryActivity.class); | 40 intent.setClass(appContext, HistoryActivity.class); |
| 64 intent.putExtra(IntentHandler.EXTRA_PARENT_COMPONENT, activity.getCo
mponentName()); | 41 intent.putExtra(IntentHandler.EXTRA_PARENT_COMPONENT, activity.getCo
mponentName()); |
| 65 activity.startActivity(intent); | 42 activity.startActivity(intent); |
| 66 } | 43 } |
| 67 } | 44 } |
| 68 } | 45 } |
| OLD | NEW |