Index: chrome/android/java/src/org/chromium/chrome/browser/history/HistoryManager.java |
diff --git a/chrome/android/java/src/org/chromium/chrome/browser/history/HistoryManager.java b/chrome/android/java/src/org/chromium/chrome/browser/history/HistoryManager.java |
index 28fdcb3529f85de1a7fe650c92877e294fea193b..cbe8dfaabd4dd367c18130de6bda78f2ddb333ea 100644 |
--- a/chrome/android/java/src/org/chromium/chrome/browser/history/HistoryManager.java |
+++ b/chrome/android/java/src/org/chromium/chrome/browser/history/HistoryManager.java |
@@ -5,17 +5,26 @@ |
package org.chromium.chrome.browser.history; |
import android.app.Activity; |
+import android.content.ComponentName; |
+import android.content.Intent; |
+import android.net.Uri; |
+import android.provider.Browser; |
import android.support.v7.widget.Toolbar.OnMenuItemClickListener; |
import android.view.LayoutInflater; |
import android.view.MenuItem; |
import android.view.ViewGroup; |
import org.chromium.chrome.R; |
+import org.chromium.chrome.browser.IntentHandler; |
+import org.chromium.chrome.browser.document.ChromeLauncherActivity; |
+import org.chromium.chrome.browser.util.IntentUtils; |
import org.chromium.chrome.browser.widget.TintedDrawable; |
import org.chromium.chrome.browser.widget.selection.SelectableListLayout; |
import org.chromium.chrome.browser.widget.selection.SelectionDelegate; |
import org.chromium.ui.base.DeviceFormFactor; |
+import java.util.List; |
+ |
/** |
* Displays and manages the UI for browsing history. |
*/ |
@@ -33,7 +42,7 @@ public class HistoryManager implements OnMenuItemClickListener { |
mActivity = activity; |
mSelectionDelegate = new SelectionDelegate<>(); |
- mHistoryAdapter = new HistoryAdapter(mSelectionDelegate); |
+ mHistoryAdapter = new HistoryAdapter(mSelectionDelegate, this); |
mSelectableListLayout = |
(SelectableListLayout) LayoutInflater.from(activity).inflate( |
@@ -58,6 +67,14 @@ public class HistoryManager implements OnMenuItemClickListener { |
if (item.getItemId() == R.id.close_menu_id && !DeviceFormFactor.isTablet(mActivity)) { |
mActivity.finish(); |
return true; |
+ } else if (item.getItemId() == R.id.selection_mode_open_in_new_tab) { |
+ openItemsInNewTabs(mSelectionDelegate.getSelectedItems(), false); |
+ mSelectionDelegate.clearSelection(); |
+ return true; |
+ } else if (item.getItemId() == R.id.selection_mode_open_in_incognito) { |
+ openItemsInNewTabs(mSelectionDelegate.getSelectedItems(), true); |
+ mSelectionDelegate.clearSelection(); |
+ return true; |
} |
return false; |
} |
@@ -76,4 +93,48 @@ public class HistoryManager implements OnMenuItemClickListener { |
mSelectableListLayout.onDestroyed(); |
mHistoryAdapter.onDestroyed(); |
} |
+ |
+ /** |
+ * Open the history item. |
+ * @param url The URL of the history item. |
+ * @param isIncognito Whether to open the history item in an incognito tab. If null, the tab |
+ * will open in the current tab model. |
+ * @param createNewTab Whether a new tab should be created. If false, the item will clobber the |
+ * the current tab. |
+ */ |
+ public void openItem(String url, Boolean isIncognito, boolean createNewTab) { |
+ // Construct basic intent. |
+ Intent viewIntent = new Intent(Intent.ACTION_VIEW, Uri.parse(url)); |
+ viewIntent.putExtra(Browser.EXTRA_APPLICATION_ID, |
+ mActivity.getApplicationContext().getPackageName()); |
+ |
+ // Determine component or class name. |
+ ComponentName component; |
+ if (DeviceFormFactor.isTablet(mActivity)) { |
+ component = mActivity.getComponentName(); |
+ } else { |
+ component = IntentUtils.safeGetParcelableExtra( |
+ mActivity.getIntent(), IntentHandler.EXTRA_PARENT_COMPONENT); |
+ } |
+ if (component != null) { |
+ viewIntent.setComponent(component); |
+ } else { |
+ viewIntent.setClass(mActivity, ChromeLauncherActivity.class); |
+ } |
+ |
+ // Set other intent extras. |
+ if (isIncognito != null) { |
+ viewIntent.putExtra(IntentHandler.EXTRA_OPEN_NEW_INCOGNITO_TAB, isIncognito); |
+ } |
+ if (createNewTab) viewIntent.putExtra(Browser.EXTRA_CREATE_NEW_TAB, true); |
+ |
+ // Send intent. |
+ IntentHandler.startActivityForTrustedIntent(viewIntent, mActivity); |
+ } |
+ |
+ private void openItemsInNewTabs(List<HistoryItem> items, boolean isIncognito) { |
+ for (HistoryItem item : items) { |
+ openItem(item.getUrl(), isIncognito, true); |
+ } |
+ } |
} |