1 | // Copyright (c) 2012 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; |
6 | |
7 | import org.chromium.base.CalledByNative; |
8 | import org.chromium.content.browser.ContentView; |
9 | import org.chromium.ui.WindowAndroid; |
10 | |
11 | /** |
12 | * The basic Java representation of a tab. Contains and manages a {@link ContentView}. |
13 | * |
14 | * TabBase provides common functionality for ChromiumTestshell's Tab as well as Chrome on Android's |
15 | * tab. It's intended to be extended both on Java and C++, with ownership managed by the subclass. |
16 | * Because of the inner-workings of JNI, the subclass is responsible for constructing the native |
17 | * subclass which in turn constructs TabAndroid (the native counterpart to TabBase) which in turn |
18 | * sets the native pointer for TabBase. The same is true for destruction. The Java subclass must be |
19 | * destroyed which will call into the native subclass and finally lead to the destruction of the |
20 | * parent classes. |
21 | */ |
22 | public abstract class TabBase { |
23 | public static final int INVALID_TAB_ID = -1; |
24 | |
25 | private final WindowAndroid mWindowAndroid; |
26 | private int mNativeTabAndroid; |
27 | |
28 | protected TabBase(WindowAndroid window) { |
29 | mWindowAndroid = window; |
30 | } |
31 | |
32 | @CalledByNative |
33 | private void destroyBase() { |
34 | assert mNativeTabAndroid != 0; |
35 | mNativeTabAndroid = 0; |
36 | } |
37 | |
38 | @CalledByNative |
39 | private void setNativePtr(int nativePtr) { |
40 | assert mNativeTabAndroid == 0; |
41 | mNativeTabAndroid = nativePtr; |
42 | } |
43 | |
44 | int getNativePtr() { |
45 | return mNativeTabAndroid; |
46 | } |
47 | |
48 | protected WindowAndroid getWindowAndroid() { |
49 | return mWindowAndroid; |
50 | } |
51 | } |