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 3// found in the LICENSE file. 4 5package org.chromium.chrome.browser; 6 7import org.chromium.chrome.browser.ForeignSessionHelper.ForeignSession; 8import org.chromium.chrome.browser.profiles.Profile; 9 10/** 11 * This class allows Java code to read and modify preferences related to the NTP 12 */ 13public class NewTabPagePrefs { 14 private long mNativeNewTabPagePrefs; 15 16 /** 17 * Initialize this class with the given profile. 18 * @param profile Profile that will be used for syncing. 19 */ 20 public NewTabPagePrefs(Profile profile) { 21 mNativeNewTabPagePrefs = nativeInit(profile); 22 } 23 24 /** 25 * Clean up the C++ side of this class. After the call, this class instance shouldn't be used. 26 */ 27 public void destroy() { 28 assert mNativeNewTabPagePrefs != 0; 29 nativeDestroy(mNativeNewTabPagePrefs); 30 mNativeNewTabPagePrefs = 0; 31 } 32 33 /** 34 * Sets whether the list of currently open tabs is collapsed (vs expanded) on the Recent Tabs 35 * page. 36 * @param isCollapsed Whether we want the currently open tabs list to be collapsed. 37 */ 38 public void setCurrentlyOpenTabsCollapsed(boolean isCollapsed) { 39 nativeSetCurrentlyOpenTabsCollapsed(mNativeNewTabPagePrefs, isCollapsed); 40 } 41 42 /** 43 * Gets whether the list of currently open tabs is collapsed (vs expanded) on Recent Tabs page. 44 * @return Whether the list of currently open tabs is collapsed (vs expanded) on 45 * the Recent Tabs page. 46 */ 47 public boolean getCurrentlyOpenTabsCollapsed() { 48 return nativeGetCurrentlyOpenTabsCollapsed(mNativeNewTabPagePrefs); 49 } 50 51 /** 52 * Sets whether the list of snapshot documents is collapsed (vs expanded) on the Recent Tabs 53 * page. 54 * @param isCollapsed Whether we want the snapshot documents list to be collapsed. 55 */ 56 public void setSnapshotDocumentCollapsed(boolean isCollapsed) { 57 nativeSetSnapshotDocumentCollapsed(mNativeNewTabPagePrefs, isCollapsed); 58 } 59 60 /** 61 * Gets whether the list of snapshot documents is collapsed (vs expanded) on 62 * the Recent Tabs page. 63 * @return Whether the list of snapshot documents is collapsed (vs expanded) on 64 * the Recent Tabs page. 65 */ 66 public boolean getSnapshotDocumentCollapsed() { 67 return nativeGetSnapshotDocumentCollapsed(mNativeNewTabPagePrefs); 68 } 69 70 /** 71 * Sets whether the list of recently closed tabs is collapsed (vs expanded) on the Recent Tabs 72 * page. 73 * @param isCollapsed Whether we want the recently closed tabs list to be collapsed. 74 */ 75 public void setRecentlyClosedTabsCollapsed(boolean isCollapsed) { 76 nativeSetRecentlyClosedTabsCollapsed(mNativeNewTabPagePrefs, isCollapsed); 77 } 78 79 /** 80 * Gets whether the list of recently closed tabs is collapsed (vs expanded) on 81 * the Recent Tabs page. 82 * @return Whether the list of recently closed tabs is collapsed (vs expanded) on 83 * the Recent Tabs page. 84 */ 85 public boolean getRecentlyClosedTabsCollapsed() { 86 return nativeGetRecentlyClosedTabsCollapsed(mNativeNewTabPagePrefs); 87 } 88 89 /** 90 * Sets whether sync promo is collapsed (vs expanded) on the Recent Tabs page. 91 * @param isCollapsed Whether we want the sync promo to be collapsed. 92 */ 93 public void setSyncPromoCollapsed(boolean isCollapsed) { 94 nativeSetSyncPromoCollapsed(mNativeNewTabPagePrefs, isCollapsed); 95 } 96 97 /** 98 * Gets whether sync promo is collapsed (vs expanded) on the Recent Tabs page. 99 * @return Whether the sync promo is collapsed (vs expanded) on the Recent Tabs page. 100 */ 101 public boolean getSyncPromoCollapsed() { 102 return nativeGetSyncPromoCollapsed(mNativeNewTabPagePrefs); 103 } 104 105 /** 106 * Sets whether the given foreign session is collapsed (vs expanded) on the Recent Tabs page. 107 * @param session Session to set collapsed or expanded. 108 * @param isCollapsed Whether we want the foreign session to be collapsed. 109 */ 110 public void setForeignSessionCollapsed(ForeignSession session, boolean isCollapsed) { 111 nativeSetForeignSessionCollapsed(mNativeNewTabPagePrefs, session.tag, isCollapsed); 112 } 113 114 /** 115 * Gets whether the given foreign session is collapsed (vs expanded) on the Recent Tabs page. 116 * @param session Session to fetch collapsed state. 117 * @return Whether the given foreign session is collapsed (vs expanded) on the Recent Tabs page. 118 */ 119 public boolean getForeignSessionCollapsed(ForeignSession session) { 120 return nativeGetForeignSessionCollapsed(mNativeNewTabPagePrefs, session.tag); 121 } 122 123 private static native long nativeInit(Profile profile); 124 private static native void nativeDestroy(long nativeNewTabPagePrefs); 125 private static native void nativeSetCurrentlyOpenTabsCollapsed( 126 long nativeNewTabPagePrefs, boolean isCollapsed); 127 private static native boolean nativeGetCurrentlyOpenTabsCollapsed( 128 long nativeNewTabPagePrefs); 129 private static native void nativeSetSnapshotDocumentCollapsed( 130 long nativeNewTabPagePrefs, boolean isCollapsed); 131 private static native boolean nativeGetSnapshotDocumentCollapsed( 132 long nativeNewTabPagePrefs); 133 private static native void nativeSetRecentlyClosedTabsCollapsed( 134 long nativeNewTabPagePrefs, boolean isCollapsed); 135 private static native boolean nativeGetRecentlyClosedTabsCollapsed( 136 long nativeNewTabPagePrefs); 137 private static native void nativeSetSyncPromoCollapsed(long nativeNewTabPagePrefs, 138 boolean isCollapsed); 139 private static native boolean nativeGetSyncPromoCollapsed(long nativeNewTabPagePrefs); 140 private static native void nativeSetForeignSessionCollapsed( 141 long nativeNewTabPagePrefs, String sessionTag, boolean isCollapsed); 142 private static native boolean nativeGetForeignSessionCollapsed( 143 long nativeNewTabPagePrefs, String sessionTag); 144} 145