| OLD | NEW |
| 1 // Copyright 2013 The Chromium Authors. All rights reserved. | 1 // Copyright 2013 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.ntp; | 5 package org.chromium.chrome.browser.ntp; |
| 6 | 6 |
| 7 import org.chromium.base.annotations.CalledByNative; | 7 import org.chromium.base.annotations.CalledByNative; |
| 8 import org.chromium.chrome.browser.profiles.Profile; | 8 import org.chromium.chrome.browser.profiles.Profile; |
| 9 import org.chromium.chrome.browser.tab.Tab; | 9 import org.chromium.chrome.browser.tab.Tab; |
| 10 | 10 |
| 11 import java.util.ArrayList; | 11 import java.util.ArrayList; |
| 12 import java.util.List; | 12 import java.util.List; |
| 13 | 13 |
| 14 /** | 14 /** |
| 15 * This class allows Java code to get and clear the list of recently closed tabs
. | 15 * This class allows Java code to get and clear the list of recently closed tabs
. |
| 16 */ | 16 */ |
| 17 class RecentlyClosedBridge { | 17 public class RecentlyClosedBridge { |
| 18 private long mNativeRecentlyClosedTabsBridge; | 18 private long mNativeRecentlyClosedTabsBridge; |
| 19 | 19 |
| 20 /** | 20 /** |
| 21 * Callback interface for getting notified when the list of recently closed
tabs is updated. | 21 * Callback interface for getting notified when the list of recently closed
tabs is updated. |
| 22 */ | 22 */ |
| 23 interface RecentlyClosedCallback { | 23 interface RecentlyClosedCallback { |
| 24 /** | 24 /** |
| 25 * This method will be called every time the list of recently closed tab
s is updated. | 25 * This method will be called every time the list of recently closed tab
s is updated. |
| 26 * | 26 * |
| 27 * It's a good place to call {@link RecentlyClosedBridge#getRecentlyClos
edTabs()} to get the | 27 * It's a good place to call {@link RecentlyClosedBridge#getRecentlyClos
edTabs()} to get the |
| (...skipping 11 matching lines...) Expand all Loading... |
| 39 public final String title; | 39 public final String title; |
| 40 public final String url; | 40 public final String url; |
| 41 | 41 |
| 42 private RecentlyClosedTab(int id, String title, String url) { | 42 private RecentlyClosedTab(int id, String title, String url) { |
| 43 this.id = id; | 43 this.id = id; |
| 44 this.title = title; | 44 this.title = title; |
| 45 this.url = url; | 45 this.url = url; |
| 46 } | 46 } |
| 47 } | 47 } |
| 48 | 48 |
| 49 public void openRecentClosedTab() { |
| 50 nativeOpenMostRecentlyClosedTab(mNativeRecentlyClosedTabsBridge); |
| 51 } |
| 52 |
| 49 @CalledByNative | 53 @CalledByNative |
| 50 private static void pushTab( | 54 private static void pushTab( |
| 51 List<RecentlyClosedTab> tabs, int id, String title, String url) { | 55 List<RecentlyClosedTab> tabs, int id, String title, String url) { |
| 52 RecentlyClosedTab tab = new RecentlyClosedTab(id, title, url); | 56 RecentlyClosedTab tab = new RecentlyClosedTab(id, title, url); |
| 53 tabs.add(tab); | 57 tabs.add(tab); |
| 54 } | 58 } |
| 55 | 59 |
| 56 /** | 60 /** |
| 57 * Initializes this class with the given profile. | 61 * Initializes this class with the given profile. |
| 58 * @param profile The Profile whose recently closed tabs will be queried. | 62 * @param profile The Profile whose recently closed tabs will be queried. |
| 59 */ | 63 */ |
| 60 RecentlyClosedBridge(Profile profile) { | 64 public RecentlyClosedBridge(Profile profile) { |
| 61 mNativeRecentlyClosedTabsBridge = nativeInit(profile); | 65 mNativeRecentlyClosedTabsBridge = nativeInit(profile); |
| 62 } | 66 } |
| 63 | 67 |
| 64 /** | 68 /** |
| 65 * Cleans up the C++ side of this class. This instance must not be used afte
r calling destroy(). | 69 * Cleans up the C++ side of this class. This instance must not be used afte
r calling destroy(). |
| 66 */ | 70 */ |
| 67 void destroy() { | 71 public void destroy() { |
| 68 assert mNativeRecentlyClosedTabsBridge != 0; | 72 assert mNativeRecentlyClosedTabsBridge != 0; |
| 69 nativeDestroy(mNativeRecentlyClosedTabsBridge); | 73 nativeDestroy(mNativeRecentlyClosedTabsBridge); |
| 70 mNativeRecentlyClosedTabsBridge = 0; | 74 mNativeRecentlyClosedTabsBridge = 0; |
| 71 } | 75 } |
| 72 | 76 |
| 73 /** | 77 /** |
| 74 * Sets the callback to be called whenever the list of recently closed tabs
changes. | 78 * Sets the callback to be called whenever the list of recently closed tabs
changes. |
| 75 * @param callback The RecentlyClosedCallback to be notified, or null. | 79 * @param callback The RecentlyClosedCallback to be notified, or null. |
| 76 */ | 80 */ |
| 77 void setRecentlyClosedCallback(RecentlyClosedCallback callback) { | 81 void setRecentlyClosedCallback(RecentlyClosedCallback callback) { |
| (...skipping 35 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 113 } | 117 } |
| 114 | 118 |
| 115 private native long nativeInit(Profile profile); | 119 private native long nativeInit(Profile profile); |
| 116 private native void nativeDestroy(long nativeRecentlyClosedTabsBridge); | 120 private native void nativeDestroy(long nativeRecentlyClosedTabsBridge); |
| 117 private native void nativeSetRecentlyClosedCallback( | 121 private native void nativeSetRecentlyClosedCallback( |
| 118 long nativeRecentlyClosedTabsBridge, RecentlyClosedCallback callback
); | 122 long nativeRecentlyClosedTabsBridge, RecentlyClosedCallback callback
); |
| 119 private native boolean nativeGetRecentlyClosedTabs( | 123 private native boolean nativeGetRecentlyClosedTabs( |
| 120 long nativeRecentlyClosedTabsBridge, List<RecentlyClosedTab> tabs, i
nt maxTabCount); | 124 long nativeRecentlyClosedTabsBridge, List<RecentlyClosedTab> tabs, i
nt maxTabCount); |
| 121 private native boolean nativeOpenRecentlyClosedTab(long nativeRecentlyClosed
TabsBridge, | 125 private native boolean nativeOpenRecentlyClosedTab(long nativeRecentlyClosed
TabsBridge, |
| 122 Tab tab, int recentTabId, int windowOpenDisposition); | 126 Tab tab, int recentTabId, int windowOpenDisposition); |
| 127 private native boolean nativeOpenMostRecentlyClosedTab(long nativeRecentlyCl
osedTabsBridge); |
| 123 private native void nativeClearRecentlyClosedTabs(long nativeRecentlyClosedT
absBridge); | 128 private native void nativeClearRecentlyClosedTabs(long nativeRecentlyClosedT
absBridge); |
| 124 } | 129 } |
| OLD | NEW |