Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(464)

Side by Side Diff: chrome/android/java/src/org/chromium/chrome/browser/Tab.java

Issue 148523013: [Android] Rename TabBase to Tab (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@2014_01_22_tabbase
Patch Set: sync Created 6 years, 9 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
1 // Copyright 2012 The Chromium Authors. All rights reserved. 1 // Copyright 2012 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; 5 package org.chromium.chrome.browser;
6 6
7 import android.app.Activity; 7 import android.app.Activity;
8 import android.content.Context; 8 import android.content.Context;
9 import android.graphics.Bitmap; 9 import android.graphics.Bitmap;
10 import android.graphics.Color; 10 import android.graphics.Color;
(...skipping 22 matching lines...) Expand all
33 import org.chromium.content.browser.WebContentsObserverAndroid; 33 import org.chromium.content.browser.WebContentsObserverAndroid;
34 import org.chromium.content_public.browser.WebContents; 34 import org.chromium.content_public.browser.WebContents;
35 import org.chromium.ui.base.Clipboard; 35 import org.chromium.ui.base.Clipboard;
36 import org.chromium.ui.base.WindowAndroid; 36 import org.chromium.ui.base.WindowAndroid;
37 37
38 import java.util.concurrent.atomic.AtomicInteger; 38 import java.util.concurrent.atomic.AtomicInteger;
39 39
40 /** 40 /**
41 * The basic Java representation of a tab. Contains and manages a {@link Conten tView}. 41 * The basic Java representation of a tab. Contains and manages a {@link Conten tView}.
42 * 42 *
43 * TabBase provides common functionality for ChromiumTestshell's Tab as well as Chrome on Android's 43 * Tab provides common functionality for ChromiumTestshell's Tab as well as Chro me on Android's
44 * tab. It is intended to be extended either on Java or both Java and C++, with ownership managed 44 * tab. It is intended to be extended either on Java or both Java and C++, with ownership managed
45 * by this base class. 45 * by this base class.
46 * 46 *
47 * Extending just Java: 47 * Extending just Java:
48 * - Just extend the class normally. Do not override initializeNative(). 48 * - Just extend the class normally. Do not override initializeNative().
49 * Extending Java and C++: 49 * Extending Java and C++:
50 * - Because of the inner-workings of JNI, the subclass is responsible for cons tructing the native 50 * - Because of the inner-workings of JNI, the subclass is responsible for cons tructing the native
51 * subclass, which in turn constructs TabAndroid (the native counterpart to T abBase), which in 51 * subclass, which in turn constructs TabAndroid (the native counterpart to T ab), which in
52 * turn sets the native pointer for TabBase. For destruction, subclasses in Java must clear 52 * turn sets the native pointer for Tab. For destruction, subclasses in Java must clear
53 * their own native pointer reference, but TabBase#destroy() will handle dele ting the native 53 * their own native pointer reference, but Tab#destroy() will handle deleting the native
54 * object. 54 * object.
55 */ 55 */
56 public abstract class TabBase implements NavigationClient { 56 public abstract class Tab implements NavigationClient {
57 public static final int INVALID_TAB_ID = -1; 57 public static final int INVALID_TAB_ID = -1;
58 58
59 /** Used for automatically generating tab ids. */ 59 /** Used for automatically generating tab ids. */
60 private static final AtomicInteger sIdCounter = new AtomicInteger(); 60 private static final AtomicInteger sIdCounter = new AtomicInteger();
61 61
62 private long mNativeTabAndroid; 62 private long mNativeTabAndroid;
63 63
64 /** Unique id of this tab (within its container). */ 64 /** Unique id of this tab (within its container). */
65 private final int mId; 65 private final int mId;
66 66
67 /** Whether or not this tab is an incognito tab. */ 67 /** Whether or not this tab is an incognito tab. */
68 private final boolean mIncognito; 68 private final boolean mIncognito;
69 69
70 /** An Application {@link Context}. Unlike {@link #mContext}, this is the o nly one that is 70 /** An Application {@link Context}. Unlike {@link #mContext}, this is the o nly one that is
71 * publicly exposed to help prevent leaking the {@link Activity}. */ 71 * publicly exposed to help prevent leaking the {@link Activity}. */
72 private final Context mApplicationContext; 72 private final Context mApplicationContext;
73 73
74 /** The {@link Context} used to create {@link View}s and other Android compo nents. Unlike 74 /** The {@link Context} used to create {@link View}s and other Android compo nents. Unlike
75 * {@link #mApplicationContext}, this is not publicly exposed to help preven t leaking the 75 * {@link #mApplicationContext}, this is not publicly exposed to help preven t leaking the
76 * {@link Activity}. */ 76 * {@link Activity}. */
77 private final Context mContext; 77 private final Context mContext;
78 78
79 /** Gives {@link TabBase} a way to interact with the Android window. */ 79 /** Gives {@link Tab} a way to interact with the Android window. */
80 private final WindowAndroid mWindowAndroid; 80 private final WindowAndroid mWindowAndroid;
81 81
82 /** The current native page (e.g. chrome-native://newtab), or {@code null} i f there is none. */ 82 /** The current native page (e.g. chrome-native://newtab), or {@code null} i f there is none. */
83 private NativePage mNativePage; 83 private NativePage mNativePage;
84 84
85 /** The {@link ContentView} showing the current page or {@code null} if the tab is frozen. */ 85 /** The {@link ContentView} showing the current page or {@code null} if the tab is frozen. */
86 private ContentView mContentView; 86 private ContentView mContentView;
87 87
88 /** InfoBar container to show InfoBars for this tab. */ 88 /** InfoBar container to show InfoBars for this tab. */
89 private InfoBarContainer mInfoBarContainer; 89 private InfoBarContainer mInfoBarContainer;
90 90
91 /** Manages app banners shown for this tab. */ 91 /** Manages app banners shown for this tab. */
92 private AppBannerManager mAppBannerManager; 92 private AppBannerManager mAppBannerManager;
93 93
94 /** The sync id of the TabBase if session sync is enabled. */ 94 /** The sync id of the Tab if session sync is enabled. */
95 private int mSyncId; 95 private int mSyncId;
96 96
97 /** 97 /**
98 * The {@link ContentViewCore} for the current page, provided for convenienc e. This always 98 * The {@link ContentViewCore} for the current page, provided for convenienc e. This always
99 * equals {@link ContentView#getContentViewCore()}, or {@code null} if mCont entView is 99 * equals {@link ContentView#getContentViewCore()}, or {@code null} if mCont entView is
100 * {@code null}. 100 * {@code null}.
101 */ 101 */
102 private ContentViewCore mContentViewCore; 102 private ContentViewCore mContentViewCore;
103 103
104 /** 104 /**
105 * A list of TabBase observers. These are used to broadcast TabBase events to listeners. 105 * A list of Tab observers. These are used to broadcast Tab events to liste ners.
106 */ 106 */
107 private final ObserverList<TabObserver> mObservers = new ObserverList<TabObs erver>(); 107 private final ObserverList<TabObserver> mObservers = new ObserverList<TabObs erver>();
108 108
109 // Content layer Observers and Delegates 109 // Content layer Observers and Delegates
110 private ContentViewClient mContentViewClient; 110 private ContentViewClient mContentViewClient;
111 private WebContentsObserverAndroid mWebContentsObserver; 111 private WebContentsObserverAndroid mWebContentsObserver;
112 private VoiceSearchTabHelper mVoiceSearchTabHelper; 112 private VoiceSearchTabHelper mVoiceSearchTabHelper;
113 private TabBaseChromeWebContentsDelegateAndroid mWebContentsDelegate; 113 private TabChromeWebContentsDelegateAndroid mWebContentsDelegate;
114 114
115 /** 115 /**
116 * A default {@link ChromeContextMenuItemDelegate} that supports some of the context menu 116 * A default {@link ChromeContextMenuItemDelegate} that supports some of the context menu
117 * functionality. 117 * functionality.
118 */ 118 */
119 protected class TabBaseChromeContextMenuItemDelegate 119 protected class TabChromeContextMenuItemDelegate
120 extends EmptyChromeContextMenuItemDelegate { 120 extends EmptyChromeContextMenuItemDelegate {
121 private final Clipboard mClipboard; 121 private final Clipboard mClipboard;
122 122
123 /** 123 /**
124 * Builds a {@link TabBaseChromeContextMenuItemDelegate} instance. 124 * Builds a {@link TabChromeContextMenuItemDelegate} instance.
125 */ 125 */
126 public TabBaseChromeContextMenuItemDelegate() { 126 public TabChromeContextMenuItemDelegate() {
127 mClipboard = new Clipboard(getApplicationContext()); 127 mClipboard = new Clipboard(getApplicationContext());
128 } 128 }
129 129
130 @Override 130 @Override
131 public boolean isIncognito() { 131 public boolean isIncognito() {
132 return mIncognito; 132 return mIncognito;
133 } 133 }
134 134
135 @Override 135 @Override
136 public void onSaveToClipboard(String text, boolean isUrl) { 136 public void onSaveToClipboard(String text, boolean isUrl) {
137 mClipboard.setText(text, text); 137 mClipboard.setText(text, text);
138 } 138 }
139 139
140 @Override 140 @Override
141 public void onSaveImageToClipboard(String url) { 141 public void onSaveImageToClipboard(String url) {
142 mClipboard.setHTMLText("<img src=\"" + url + "\">", url, url); 142 mClipboard.setHTMLText("<img src=\"" + url + "\">", url, url);
143 } 143 }
144 } 144 }
145 145
146 /** 146 /**
147 * A basic {@link ChromeWebContentsDelegateAndroid} that forwards some calls to the registered 147 * A basic {@link ChromeWebContentsDelegateAndroid} that forwards some calls to the registered
148 * {@link TabObserver}s. Meant to be overridden by subclasses. 148 * {@link TabObserver}s. Meant to be overridden by subclasses.
149 */ 149 */
150 public class TabBaseChromeWebContentsDelegateAndroid 150 public class TabChromeWebContentsDelegateAndroid
151 extends ChromeWebContentsDelegateAndroid { 151 extends ChromeWebContentsDelegateAndroid {
152 @Override 152 @Override
153 public void onLoadProgressChanged(int progress) { 153 public void onLoadProgressChanged(int progress) {
154 for (TabObserver observer : mObservers) { 154 for (TabObserver observer : mObservers) {
155 observer.onLoadProgressChanged(TabBase.this, progress); 155 observer.onLoadProgressChanged(Tab.this, progress);
156 } 156 }
157 } 157 }
158 158
159 @Override 159 @Override
160 public void onUpdateUrl(String url) { 160 public void onUpdateUrl(String url) {
161 for (TabObserver observer : mObservers) observer.onUpdateUrl(TabBase .this, url); 161 for (TabObserver observer : mObservers) observer.onUpdateUrl(Tab.thi s, url);
162 } 162 }
163 163
164 @Override 164 @Override
165 public void showRepostFormWarningDialog(final ContentViewCore contentVie wCore) { 165 public void showRepostFormWarningDialog(final ContentViewCore contentVie wCore) {
166 RepostFormWarningDialog warningDialog = new RepostFormWarningDialog( 166 RepostFormWarningDialog warningDialog = new RepostFormWarningDialog(
167 new Runnable() { 167 new Runnable() {
168 @Override 168 @Override
169 public void run() { 169 public void run() {
170 contentViewCore.cancelPendingReload(); 170 contentViewCore.cancelPendingReload();
171 } 171 }
172 }, new Runnable() { 172 }, new Runnable() {
173 @Override 173 @Override
174 public void run() { 174 public void run() {
175 contentViewCore.continuePendingReload(); 175 contentViewCore.continuePendingReload();
176 } 176 }
177 }); 177 });
178 Activity activity = (Activity) mContext; 178 Activity activity = (Activity) mContext;
179 warningDialog.show(activity.getFragmentManager(), null); 179 warningDialog.show(activity.getFragmentManager(), null);
180 } 180 }
181 181
182 @Override 182 @Override
183 public void toggleFullscreenModeForTab(boolean enableFullscreen) { 183 public void toggleFullscreenModeForTab(boolean enableFullscreen) {
184 for (TabObserver observer : mObservers) { 184 for (TabObserver observer : mObservers) {
185 observer.onToggleFullscreenMode(TabBase.this, enableFullscreen); 185 observer.onToggleFullscreenMode(Tab.this, enableFullscreen);
186 } 186 }
187 } 187 }
188 188
189 @Override 189 @Override
190 public void navigationStateChanged(int flags) { 190 public void navigationStateChanged(int flags) {
191 if ((flags & INVALIDATE_TYPE_TITLE) != 0) { 191 if ((flags & INVALIDATE_TYPE_TITLE) != 0) {
192 for (TabObserver observer : mObservers) observer.onTitleUpdated( TabBase.this); 192 for (TabObserver observer : mObservers) observer.onTitleUpdated( Tab.this);
193 } 193 }
194 if ((flags & INVALIDATE_TYPE_URL) != 0) { 194 if ((flags & INVALIDATE_TYPE_URL) != 0) {
195 for (TabObserver observer : mObservers) observer.onUrlUpdated(Ta bBase.this); 195 for (TabObserver observer : mObservers) observer.onUrlUpdated(Ta b.this);
196 } 196 }
197 } 197 }
198 } 198 }
199 199
200 private class TabBaseContextMenuPopulator extends ContextMenuPopulatorWrappe r { 200 private class TabContextMenuPopulator extends ContextMenuPopulatorWrapper {
201 public TabBaseContextMenuPopulator(ContextMenuPopulator populator) { 201 public TabContextMenuPopulator(ContextMenuPopulator populator) {
202 super(populator); 202 super(populator);
203 } 203 }
204 204
205 @Override 205 @Override
206 public void buildContextMenu(ContextMenu menu, Context context, ContextM enuParams params) { 206 public void buildContextMenu(ContextMenu menu, Context context, ContextM enuParams params) {
207 super.buildContextMenu(menu, context, params); 207 super.buildContextMenu(menu, context, params);
208 for (TabObserver observer : mObservers) observer.onContextMenuShown( TabBase.this, menu); 208 for (TabObserver observer : mObservers) observer.onContextMenuShown( Tab.this, menu);
209 } 209 }
210 } 210 }
211 211
212 private class TabBaseWebContentsObserverAndroid extends WebContentsObserverA ndroid { 212 private class TabWebContentsObserverAndroid extends WebContentsObserverAndro id {
213 public TabBaseWebContentsObserverAndroid(ContentViewCore contentViewCore ) { 213 public TabWebContentsObserverAndroid(ContentViewCore contentViewCore) {
214 super(contentViewCore); 214 super(contentViewCore);
215 } 215 }
216 216
217 @Override 217 @Override
218 public void navigationEntryCommitted() { 218 public void navigationEntryCommitted() {
219 if (getNativePage() != null) { 219 if (getNativePage() != null) {
220 pushNativePageStateToNavigationEntry(); 220 pushNativePageStateToNavigationEntry();
221 } 221 }
222 } 222 }
223 223
224 @Override 224 @Override
225 public void didFailLoad(boolean isProvisionalLoad, boolean isMainFrame, int errorCode, 225 public void didFailLoad(boolean isProvisionalLoad, boolean isMainFrame, int errorCode,
226 String description, String failingUrl) { 226 String description, String failingUrl) {
227 for (TabObserver observer : mObservers) { 227 for (TabObserver observer : mObservers) {
228 observer.onDidFailLoad(TabBase.this, isProvisionalLoad, isMainFr ame, errorCode, 228 observer.onDidFailLoad(Tab.this, isProvisionalLoad, isMainFrame, errorCode,
229 description, failingUrl); 229 description, failingUrl);
230 } 230 }
231 } 231 }
232 } 232 }
233 233
234 /** 234 /**
235 * Creates an instance of a {@link TabBase} with no id. 235 * Creates an instance of a {@link Tab} with no id.
236 * @param incognito Whether or not this tab is incognito. 236 * @param incognito Whether or not this tab is incognito.
237 * @param context An instance of a {@link Context}. 237 * @param context An instance of a {@link Context}.
238 * @param window An instance of a {@link WindowAndroid}. 238 * @param window An instance of a {@link WindowAndroid}.
239 */ 239 */
240 public TabBase(boolean incognito, Context context, WindowAndroid window) { 240 public Tab(boolean incognito, Context context, WindowAndroid window) {
241 this(INVALID_TAB_ID, incognito, context, window); 241 this(INVALID_TAB_ID, incognito, context, window);
242 } 242 }
243 243
244 /** 244 /**
245 * Creates an instance of a {@link TabBase}. 245 * Creates an instance of a {@link Tab}.
246 * @param id The id this tab should be identified with. 246 * @param id The id this tab should be identified with.
247 * @param incognito Whether or not this tab is incognito. 247 * @param incognito Whether or not this tab is incognito.
248 * @param context An instance of a {@link Context}. 248 * @param context An instance of a {@link Context}.
249 * @param window An instance of a {@link WindowAndroid}. 249 * @param window An instance of a {@link WindowAndroid}.
250 */ 250 */
251 public TabBase(int id, boolean incognito, Context context, WindowAndroid win dow) { 251 public Tab(int id, boolean incognito, Context context, WindowAndroid window) {
252 // We need a valid Activity Context to build the ContentView with. 252 // We need a valid Activity Context to build the ContentView with.
253 assert context == null || context instanceof Activity; 253 assert context == null || context instanceof Activity;
254 254
255 mId = generateValidId(id); 255 mId = generateValidId(id);
256 mIncognito = incognito; 256 mIncognito = incognito;
257 // TODO(dtrainor): Only store application context here. 257 // TODO(dtrainor): Only store application context here.
258 mContext = context; 258 mContext = context;
259 mApplicationContext = context != null ? context.getApplicationContext() : null; 259 mApplicationContext = context != null ? context.getApplicationContext() : null;
260 mWindowAndroid = window; 260 mWindowAndroid = window;
261 } 261 }
262 262
263 /** 263 /**
264 * Adds a {@link TabObserver} to be notified on {@link TabBase} changes. 264 * Adds a {@link TabObserver} to be notified on {@link Tab} changes.
265 * @param observer The {@link TabObserver} to add. 265 * @param observer The {@link TabObserver} to add.
266 */ 266 */
267 public final void addObserver(TabObserver observer) { 267 public final void addObserver(TabObserver observer) {
268 mObservers.addObserver(observer); 268 mObservers.addObserver(observer);
269 } 269 }
270 270
271 /** 271 /**
272 * Removes a {@link TabObserver}. 272 * Removes a {@link TabObserver}.
273 * @param observer The {@link TabObserver} to remove. 273 * @param observer The {@link TabObserver} to remove.
274 */ 274 */
(...skipping 51 matching lines...) Expand 10 before | Expand all | Expand 10 after
326 } 326 }
327 327
328 /** 328 /**
329 * Requests the current navigation to be loaded upon the next call to loadIf Necessary(). 329 * Requests the current navigation to be loaded upon the next call to loadIf Necessary().
330 */ 330 */
331 protected void requestRestoreLoad() { 331 protected void requestRestoreLoad() {
332 if (mContentViewCore != null) mContentViewCore.requestRestoreLoad(); 332 if (mContentViewCore != null) mContentViewCore.requestRestoreLoad();
333 } 333 }
334 334
335 /** 335 /**
336 * @return Whether or not the {@link TabBase} is currently showing an inters titial page, such as 336 * @return Whether or not the {@link Tab} is currently showing an interstiti al page, such as
337 * a bad HTTPS page. 337 * a bad HTTPS page.
338 */ 338 */
339 public boolean isShowingInterstitialPage() { 339 public boolean isShowingInterstitialPage() {
340 ContentViewCore contentViewCore = getContentViewCore(); 340 ContentViewCore contentViewCore = getContentViewCore();
341 return contentViewCore != null && contentViewCore.isShowingInterstitialP age(); 341 return contentViewCore != null && contentViewCore.isShowingInterstitialP age();
342 } 342 }
343 343
344 /** 344 /**
345 * @return Whether or not the tab has something valid to render. 345 * @return Whether or not the tab has something valid to render.
346 */ 346 */
(...skipping 145 matching lines...) Expand 10 before | Expand all | Expand 10 after
492 /** 492 /**
493 * @return The {@link NativePage} associated with the current page, or {@cod e null} if there is 493 * @return The {@link NativePage} associated with the current page, or {@cod e null} if there is
494 * no current page or the current page is displayed using something besides 494 * no current page or the current page is displayed using something besides
495 * {@link NativePage}. 495 * {@link NativePage}.
496 */ 496 */
497 public NativePage getNativePage() { 497 public NativePage getNativePage() {
498 return mNativePage; 498 return mNativePage;
499 } 499 }
500 500
501 /** 501 /**
502 * @return Whether or not the {@link TabBase} represents a {@link NativePage }. 502 * @return Whether or not the {@link Tab} represents a {@link NativePage}.
503 */ 503 */
504 public boolean isNativePage() { 504 public boolean isNativePage() {
505 return mNativePage != null; 505 return mNativePage != null;
506 } 506 }
507 507
508 /** 508 /**
509 * Set whether or not the {@link ContentViewCore} should be using a desktop user agent for the 509 * Set whether or not the {@link ContentViewCore} should be using a desktop user agent for the
510 * currently loaded page. 510 * currently loaded page.
511 * @param useDesktop If {@code true}, use a desktop user agent. Otherwi se use a mobile one. 511 * @param useDesktop If {@code true}, use a desktop user agent. Otherwi se use a mobile one.
512 * @param reloadOnChange Reload the page if the user agent has changed. 512 * @param reloadOnChange Reload the page if the user agent has changed.
(...skipping 49 matching lines...) Expand 10 before | Expand all | Expand 10 after
562 * @return The {@link ContentViewClient} currently bound to any {@link Conte ntViewCore} 562 * @return The {@link ContentViewClient} currently bound to any {@link Conte ntViewCore}
563 * associated with the current page. There can still be a {@link Co ntentViewClient} 563 * associated with the current page. There can still be a {@link Co ntentViewClient}
564 * even when there is no {@link ContentViewCore}. 564 * even when there is no {@link ContentViewCore}.
565 */ 565 */
566 protected ContentViewClient getContentViewClient() { 566 protected ContentViewClient getContentViewClient() {
567 return mContentViewClient; 567 return mContentViewClient;
568 } 568 }
569 569
570 /** 570 /**
571 * @param client The {@link ContentViewClient} to be bound to any current or new 571 * @param client The {@link ContentViewClient} to be bound to any current or new
572 * {@link ContentViewCore}s associated with this {@link TabBas e}. 572 * {@link ContentViewCore}s associated with this {@link Tab}.
573 */ 573 */
574 protected void setContentViewClient(ContentViewClient client) { 574 protected void setContentViewClient(ContentViewClient client) {
575 if (mContentViewClient == client) return; 575 if (mContentViewClient == client) return;
576 576
577 ContentViewClient oldClient = mContentViewClient; 577 ContentViewClient oldClient = mContentViewClient;
578 mContentViewClient = client; 578 mContentViewClient = client;
579 579
580 if (mContentViewCore == null) return; 580 if (mContentViewCore == null) return;
581 581
582 if (mContentViewClient != null) { 582 if (mContentViewClient != null) {
(...skipping 36 matching lines...) Expand 10 before | Expand all | Expand 10 after
619 */ 619 */
620 protected void showRenderedPage() { 620 protected void showRenderedPage() {
621 if (mNativePage == null) return; 621 if (mNativePage == null) return;
622 NativePage previousNativePage = mNativePage; 622 NativePage previousNativePage = mNativePage;
623 mNativePage = null; 623 mNativePage = null;
624 for (TabObserver observer : mObservers) observer.onContentChanged(this); 624 for (TabObserver observer : mObservers) observer.onContentChanged(this);
625 destroyNativePageInternal(previousNativePage); 625 destroyNativePageInternal(previousNativePage);
626 } 626 }
627 627
628 /** 628 /**
629 * Initializes this {@link TabBase}. 629 * Initializes this {@link Tab}.
630 */ 630 */
631 public void initialize() { 631 public void initialize() {
632 initializeNative(); 632 initializeNative();
633 } 633 }
634 634
635 /** 635 /**
636 * Builds the native counterpart to this class. Meant to be overridden by s ubclasses to build 636 * Builds the native counterpart to this class. Meant to be overridden by s ubclasses to build
637 * subclass native counterparts instead. Subclasses should not call this vi a super and instead 637 * subclass native counterparts instead. Subclasses should not call this vi a super and instead
638 * rely on the native class to create the JNI association. 638 * rely on the native class to create the JNI association.
639 */ 639 */
(...skipping 21 matching lines...) Expand all
661 */ 661 */
662 protected void initContentView(long nativeWebContents) { 662 protected void initContentView(long nativeWebContents) {
663 NativePage previousNativePage = mNativePage; 663 NativePage previousNativePage = mNativePage;
664 mNativePage = null; 664 mNativePage = null;
665 destroyNativePageInternal(previousNativePage); 665 destroyNativePageInternal(previousNativePage);
666 666
667 mContentView = ContentView.newInstance(mContext, nativeWebContents, getW indowAndroid()); 667 mContentView = ContentView.newInstance(mContext, nativeWebContents, getW indowAndroid());
668 668
669 mContentViewCore = mContentView.getContentViewCore(); 669 mContentViewCore = mContentView.getContentViewCore();
670 mWebContentsDelegate = createWebContentsDelegate(); 670 mWebContentsDelegate = createWebContentsDelegate();
671 mWebContentsObserver = new TabBaseWebContentsObserverAndroid(mContentVie wCore); 671 mWebContentsObserver = new TabWebContentsObserverAndroid(mContentViewCor e);
672 mVoiceSearchTabHelper = new VoiceSearchTabHelper(mContentViewCore); 672 mVoiceSearchTabHelper = new VoiceSearchTabHelper(mContentViewCore);
673 673
674 if (mContentViewClient != null) mContentViewCore.setContentViewClient(mC ontentViewClient); 674 if (mContentViewClient != null) mContentViewCore.setContentViewClient(mC ontentViewClient);
675 675
676 assert mNativeTabAndroid != 0; 676 assert mNativeTabAndroid != 0;
677 nativeInitWebContents( 677 nativeInitWebContents(
678 mNativeTabAndroid, mIncognito, mContentViewCore, mWebContentsDel egate, 678 mNativeTabAndroid, mIncognito, mContentViewCore, mWebContentsDel egate,
679 new TabBaseContextMenuPopulator(createContextMenuPopulator())); 679 new TabContextMenuPopulator(createContextMenuPopulator()));
680 680
681 // In the case where restoring a Tab or showing a prerendered one we alr eady have a 681 // In the case where restoring a Tab or showing a prerendered one we alr eady have a
682 // valid infobar container, no need to recreate one. 682 // valid infobar container, no need to recreate one.
683 if (mInfoBarContainer == null) { 683 if (mInfoBarContainer == null) {
684 // The InfoBarContainer needs to be created after the ContentView ha s been natively 684 // The InfoBarContainer needs to be created after the ContentView ha s been natively
685 // initialized. 685 // initialized.
686 mInfoBarContainer = new InfoBarContainer( 686 mInfoBarContainer = new InfoBarContainer(
687 (Activity) mContext, createAutoLoginProcessor(), getId(), ge tContentView(), 687 (Activity) mContext, createAutoLoginProcessor(), getId(), ge tContentView(),
688 nativeWebContents); 688 nativeWebContents);
689 } else { 689 } else {
690 mInfoBarContainer.onParentViewChanged(getId(), getContentView()); 690 mInfoBarContainer.onParentViewChanged(getId(), getContentView());
691 } 691 }
692 692
693 if (AppBannerManager.isEnabled() && mAppBannerManager == null) { 693 if (AppBannerManager.isEnabled() && mAppBannerManager == null) {
694 mAppBannerManager = new AppBannerManager(this); 694 mAppBannerManager = new AppBannerManager(this);
695 } 695 }
696 696
697 for (TabObserver observer : mObservers) observer.onContentChanged(this); 697 for (TabObserver observer : mObservers) observer.onContentChanged(this);
698 } 698 }
699 699
700 /** 700 /**
701 * Cleans up all internal state, destroying any {@link NativePage} or {@link ContentView} 701 * Cleans up all internal state, destroying any {@link NativePage} or {@link ContentView}
702 * currently associated with this {@link TabBase}. This also destroys the n ative counterpart 702 * currently associated with this {@link Tab}. This also destroys the nativ e counterpart
703 * to this class, which means that all subclasses should erase their native pointers after 703 * to this class, which means that all subclasses should erase their native pointers after
704 * this method is called. Once this call is made this {@link TabBase} shoul d no longer be used. 704 * this method is called. Once this call is made this {@link Tab} should no longer be used.
705 */ 705 */
706 public void destroy() { 706 public void destroy() {
707 for (TabObserver observer : mObservers) observer.onDestroyed(this); 707 for (TabObserver observer : mObservers) observer.onDestroyed(this);
708 708
709 NativePage currentNativePage = mNativePage; 709 NativePage currentNativePage = mNativePage;
710 mNativePage = null; 710 mNativePage = null;
711 destroyNativePageInternal(currentNativePage); 711 destroyNativePageInternal(currentNativePage);
712 destroyContentView(true); 712 destroyContentView(true);
713 713
714 // Destroys the native tab after destroying the ContentView but before d estroying the 714 // Destroys the native tab after destroying the ContentView but before d estroying the
(...skipping 86 matching lines...) Expand 10 before | Expand all | Expand 10 after
801 * Gives subclasses the chance to clean up some state associated with this { @link ContentView}. 801 * Gives subclasses the chance to clean up some state associated with this { @link ContentView}.
802 * This is because {@link #getContentView()} can return {@code null} if a {@ link NativePage} 802 * This is because {@link #getContentView()} can return {@code null} if a {@ link NativePage}
803 * is showing. 803 * is showing.
804 * @param contentView The {@link ContentView} that should have associated st ate cleaned up. 804 * @param contentView The {@link ContentView} that should have associated st ate cleaned up.
805 */ 805 */
806 protected void destroyContentViewInternal(ContentView contentView) { 806 protected void destroyContentViewInternal(ContentView contentView) {
807 } 807 }
808 808
809 /** 809 /**
810 * A helper method to allow subclasses to build their own delegate. 810 * A helper method to allow subclasses to build their own delegate.
811 * @return An instance of a {@link TabBaseChromeWebContentsDelegateAndroid}. 811 * @return An instance of a {@link TabChromeWebContentsDelegateAndroid}.
812 */ 812 */
813 protected TabBaseChromeWebContentsDelegateAndroid createWebContentsDelegate( ) { 813 protected TabChromeWebContentsDelegateAndroid createWebContentsDelegate() {
814 return new TabBaseChromeWebContentsDelegateAndroid(); 814 return new TabChromeWebContentsDelegateAndroid();
815 } 815 }
816 816
817 /** 817 /**
818 * A helper method to allow subclasses to build their own menu populator. 818 * A helper method to allow subclasses to build their own menu populator.
819 * @return An instance of a {@link ContextMenuPopulator}. 819 * @return An instance of a {@link ContextMenuPopulator}.
820 */ 820 */
821 protected ContextMenuPopulator createContextMenuPopulator() { 821 protected ContextMenuPopulator createContextMenuPopulator() {
822 return new ChromeContextMenuPopulator(new TabBaseChromeContextMenuItemDe legate()); 822 return new ChromeContextMenuPopulator(new TabChromeContextMenuItemDelega te());
823 } 823 }
824 824
825 /** 825 /**
826 * @return The {@link WindowAndroid} associated with this {@link TabBase}. 826 * @return The {@link WindowAndroid} associated with this {@link Tab}.
827 */ 827 */
828 public WindowAndroid getWindowAndroid() { 828 public WindowAndroid getWindowAndroid() {
829 return mWindowAndroid; 829 return mWindowAndroid;
830 } 830 }
831 831
832 /** 832 /**
833 * @return The current {@link TabBaseChromeWebContentsDelegateAndroid} insta nce. 833 * @return The current {@link TabChromeWebContentsDelegateAndroid} instance.
834 */ 834 */
835 protected TabBaseChromeWebContentsDelegateAndroid getChromeWebContentsDelega teAndroid() { 835 protected TabChromeWebContentsDelegateAndroid getChromeWebContentsDelegateAn droid() {
836 return mWebContentsDelegate; 836 return mWebContentsDelegate;
837 } 837 }
838 838
839 /** 839 /**
840 * Called when the favicon of the content this tab represents changes. 840 * Called when the favicon of the content this tab represents changes.
841 */ 841 */
842 @CalledByNative 842 @CalledByNative
843 protected void onFaviconUpdated() { 843 protected void onFaviconUpdated() {
844 for (TabObserver observer : mObservers) observer.onFaviconUpdated(this); 844 for (TabObserver observer : mObservers) observer.onFaviconUpdated(this);
845 } 845 }
846 846
847 /** 847 /**
848 * Called when the navigation entry containing the historyitem changed, 848 * Called when the navigation entry containing the historyitem changed,
849 * for example because of a scroll offset or form field change. 849 * for example because of a scroll offset or form field change.
850 */ 850 */
851 @CalledByNative 851 @CalledByNative
852 protected void onNavEntryChanged() { 852 protected void onNavEntryChanged() {
853 } 853 }
854 854
855 /** 855 /**
856 * @return The native pointer representing the native side of this {@link Ta bBase} object. 856 * @return The native pointer representing the native side of this {@link Ta b} object.
857 */ 857 */
858 @CalledByNative 858 @CalledByNative
859 protected long getNativePtr() { 859 protected long getNativePtr() {
860 return mNativeTabAndroid; 860 return mNativeTabAndroid;
861 } 861 }
862 862
863 /** This is currently called when committing a pre-rendered page. */ 863 /** This is currently called when committing a pre-rendered page. */
864 @CalledByNative 864 @CalledByNative
865 private void swapWebContents( 865 private void swapWebContents(
866 final long newWebContents, boolean didStartLoad, boolean didFinishLo ad) { 866 final long newWebContents, boolean didStartLoad, boolean didFinishLo ad) {
(...skipping 88 matching lines...) Expand 10 before | Expand all | Expand 10 after
955 ContentViewCore contentViewCore, ChromeWebContentsDelegateAndroid de legate, 955 ContentViewCore contentViewCore, ChromeWebContentsDelegateAndroid de legate,
956 ContextMenuPopulator contextMenuPopulator); 956 ContextMenuPopulator contextMenuPopulator);
957 private native void nativeDestroyWebContents(long nativeTabAndroid, boolean deleteNative); 957 private native void nativeDestroyWebContents(long nativeTabAndroid, boolean deleteNative);
958 private native WebContents nativeGetWebContents(long nativeTabAndroid); 958 private native WebContents nativeGetWebContents(long nativeTabAndroid);
959 private native Profile nativeGetProfileAndroid(long nativeTabAndroid); 959 private native Profile nativeGetProfileAndroid(long nativeTabAndroid);
960 private native int nativeGetSecurityLevel(long nativeTabAndroid); 960 private native int nativeGetSecurityLevel(long nativeTabAndroid);
961 private native void nativeSetActiveNavigationEntryTitleForUrl(long nativeTab Android, String url, 961 private native void nativeSetActiveNavigationEntryTitleForUrl(long nativeTab Android, String url,
962 String title); 962 String title);
963 private native boolean nativePrint(long nativeTabAndroid); 963 private native boolean nativePrint(long nativeTabAndroid);
964 } 964 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698