Chromium Code Reviews| OLD | NEW |
|---|---|
| (Empty) | |
| 1 // Copyright 2014 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 | |
| 5 package org.chromium.chrome.browser.tabmodel; | |
| 6 | |
| 7 import org.chromium.base.CalledByNative; | |
| 8 import org.chromium.chrome.browser.Tab; | |
| 9 import org.chromium.chrome.browser.profiles.Profile; | |
| 10 | |
| 11 /** | |
| 12 * Bridges between the C++ and Java {@link TabModel} interfaces. | |
| 13 */ | |
| 14 public abstract class TabModelJniBridge implements TabModel { | |
| 15 private final boolean mIsIncognito; | |
| 16 | |
| 17 /** Native TabModelJniBridge pointer, which will be set by {@link #setNative Ptr(long)}. */ | |
| 18 private long mNativeTabModelJniBridge; | |
| 19 | |
| 20 public TabModelJniBridge(boolean isIncognito) { | |
| 21 mIsIncognito = isIncognito; | |
| 22 } | |
| 23 | |
| 24 @CalledByNative | |
| 25 private void clearNativePtr() { | |
| 26 assert mNativeTabModelJniBridge != 0; | |
| 27 mNativeTabModelJniBridge = 0; | |
| 28 } | |
| 29 | |
| 30 @CalledByNative | |
| 31 private void setNativePtr(long nativePointer) { | |
| 32 assert mNativeTabModelJniBridge == 0; | |
| 33 mNativeTabModelJniBridge = nativePointer; | |
| 34 } | |
| 35 | |
| 36 @Override | |
| 37 public void destroy() { | |
| 38 if (mNativeTabModelJniBridge != 0) { | |
| 39 // This will invalidate all other native references to this object i n child classes. | |
| 40 nativeDestroy(mNativeTabModelJniBridge); | |
| 41 mNativeTabModelJniBridge = 0; | |
| 42 } | |
| 43 } | |
| 44 | |
| 45 @Override | |
| 46 public boolean isIncognito() { | |
| 47 return mIsIncognito; | |
| 48 } | |
| 49 | |
| 50 @Override | |
| 51 public Profile getProfile() { | |
| 52 return nativeGetProfileAndroid(mNativeTabModelJniBridge); | |
| 53 } | |
| 54 | |
| 55 /** Broadcast a native-side notification that all tabs are now loaded from s torage. */ | |
| 56 public void broadcastSessionRestoreComplete() { | |
| 57 assert mNativeTabModelJniBridge != 0; | |
| 58 nativeBroadcastSessionRestoreComplete(mNativeTabModelJniBridge); | |
| 59 } | |
| 60 | |
| 61 /** | |
| 62 * Called by subclasses when a Tab is added to the TabModel. | |
| 63 * @param tab Tab being added to the model. | |
| 64 */ | |
| 65 protected void tabAddedToModel(Tab tab) { | |
| 66 if (mNativeTabModelJniBridge != 0) nativeTabAddedToModel(mNativeTabModel JniBridge, tab); | |
| 67 } | |
| 68 | |
| 69 /** | |
| 70 * Sets the TabModel's index. | |
| 71 * @param index Index of the Tab to select. | |
| 72 */ | |
| 73 @CalledByNative | |
| 74 protected void setIndex(int index) { | |
|
David Trainor- moved to gerrit
2014/10/10 22:45:29
Okay. Ideally we'd use the TabModelUtils.setIndex
gone
2014/10/10 23:06:38
Done.
| |
| 75 TabModelUtils.setIndex(this, index); | |
| 76 } | |
| 77 | |
| 78 @Override | |
| 79 @CalledByNative | |
| 80 public abstract Tab getTabAt(int index); | |
| 81 | |
| 82 /** | |
| 83 * Closes the Tab at a particular index. | |
| 84 * @param index Index of the tab to close. | |
| 85 * @return Whether the was successfully closed. | |
| 86 */ | |
| 87 @CalledByNative | |
| 88 protected abstract boolean closeTabAt(int index); | |
| 89 | |
| 90 /** | |
| 91 * Creates a Tab with the given WebContents. | |
| 92 * @param incognito Whether or not the tab is incognito. | |
| 93 * @param nativeWebContents Pointer to the native WebContents. | |
| 94 * @param parentId ID of the parent. | |
| 95 */ | |
| 96 @CalledByNative | |
| 97 protected abstract Tab createTabWithNativeContents( | |
| 98 boolean incognito, long nativeWebContents, int parentId); | |
| 99 | |
| 100 /** | |
| 101 * Creates a Tab with the given WebContents for DevTools. | |
| 102 * @param url URL to show. | |
| 103 */ | |
| 104 @CalledByNative | |
| 105 protected abstract Tab createNewTabForDevTools(String url); | |
| 106 | |
| 107 @Override | |
| 108 @CalledByNative | |
| 109 public abstract int getCount(); | |
| 110 | |
| 111 @Override | |
| 112 @CalledByNative | |
| 113 public abstract int index(); | |
| 114 | |
| 115 /** @return Whether or not a sync session is currently being restored. */ | |
| 116 @CalledByNative | |
| 117 protected abstract boolean isSessionRestoreInProgress(); | |
| 118 | |
| 119 private native Profile nativeGetProfileAndroid(long nativeTabModelJniBridge) ; | |
| 120 private native void nativeBroadcastSessionRestoreComplete(long nativeTabMode lJniBridge); | |
| 121 private native void nativeDestroy(long nativeTabModelJniBridge); | |
| 122 private native void nativeTabAddedToModel(long nativeTabModelJniBridge, Tab tab); | |
| 123 } | |
| OLD | NEW |