OLD | NEW |
---|---|
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 Loading... | |
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) |
209 observer.onContextMenuShown(Tab.this, menu); | |
Ted C
2014/02/27 17:25:44
This should go back on the previous line (braces a
Bernhard Bauer
2014/02/27 17:40:04
Done.
| |
209 } | 210 } |
210 } | 211 } |
211 | 212 |
212 private class TabBaseWebContentsObserverAndroid extends WebContentsObserverA ndroid { | 213 private class TabWebContentsObserverAndroid extends WebContentsObserverAndro id { |
213 public TabBaseWebContentsObserverAndroid(ContentViewCore contentViewCore ) { | 214 public TabWebContentsObserverAndroid(ContentViewCore contentViewCore) { |
214 super(contentViewCore); | 215 super(contentViewCore); |
215 } | 216 } |
216 | 217 |
217 @Override | 218 @Override |
218 public void navigationEntryCommitted() { | 219 public void navigationEntryCommitted() { |
219 if (getNativePage() != null) { | 220 if (getNativePage() != null) { |
220 pushNativePageStateToNavigationEntry(); | 221 pushNativePageStateToNavigationEntry(); |
221 } | 222 } |
222 } | 223 } |
223 | 224 |
224 @Override | 225 @Override |
225 public void didFailLoad(boolean isProvisionalLoad, boolean isMainFrame, int errorCode, | 226 public void didFailLoad(boolean isProvisionalLoad, boolean isMainFrame, int errorCode, |
226 String description, String failingUrl) { | 227 String description, String failingUrl) { |
227 for (TabObserver observer : mObservers) { | 228 for (TabObserver observer : mObservers) { |
228 observer.onDidFailLoad(TabBase.this, isProvisionalLoad, isMainFr ame, errorCode, | 229 observer.onDidFailLoad(Tab.this, isProvisionalLoad, isMainFrame, errorCode, |
229 description, failingUrl); | 230 description, failingUrl); |
230 } | 231 } |
231 } | 232 } |
232 } | 233 } |
233 | 234 |
234 /** | 235 /** |
235 * Creates an instance of a {@link TabBase} with no id. | 236 * Creates an instance of a {@link Tab} with no id. |
236 * @param incognito Whether or not this tab is incognito. | 237 * @param incognito Whether or not this tab is incognito. |
237 * @param context An instance of a {@link Context}. | 238 * @param context An instance of a {@link Context}. |
238 * @param window An instance of a {@link WindowAndroid}. | 239 * @param window An instance of a {@link WindowAndroid}. |
239 */ | 240 */ |
240 public TabBase(boolean incognito, Context context, WindowAndroid window) { | 241 protected Tab(boolean incognito, Context context, WindowAndroid window) { |
Ted C
2014/02/27 17:25:44
any reason to reduce the visibility of the constru
Bernhard Bauer
2014/02/27 17:40:04
Hm, I think that was an artifact from an older ver
| |
241 this(INVALID_TAB_ID, incognito, context, window); | 242 this(INVALID_TAB_ID, incognito, context, window); |
242 } | 243 } |
243 | 244 |
244 /** | 245 /** |
245 * Creates an instance of a {@link TabBase}. | 246 * Creates an instance of a {@link Tab}. |
246 * @param id The id this tab should be identified with. | 247 * @param id The id this tab should be identified with. |
247 * @param incognito Whether or not this tab is incognito. | 248 * @param incognito Whether or not this tab is incognito. |
248 * @param context An instance of a {@link Context}. | 249 * @param context An instance of a {@link Context}. |
249 * @param window An instance of a {@link WindowAndroid}. | 250 * @param window An instance of a {@link WindowAndroid}. |
250 */ | 251 */ |
251 public TabBase(int id, boolean incognito, Context context, WindowAndroid win dow) { | 252 protected Tab(int id, boolean incognito, Context context, WindowAndroid wind ow) { |
252 // We need a valid Activity Context to build the ContentView with. | 253 // We need a valid Activity Context to build the ContentView with. |
253 assert context == null || context instanceof Activity; | 254 assert context == null || context instanceof Activity; |
254 | 255 |
255 mId = generateValidId(id); | 256 mId = generateValidId(id); |
256 mIncognito = incognito; | 257 mIncognito = incognito; |
257 // TODO(dtrainor): Only store application context here. | 258 // TODO(dtrainor): Only store application context here. |
258 mContext = context; | 259 mContext = context; |
259 mApplicationContext = context != null ? context.getApplicationContext() : null; | 260 mApplicationContext = context != null ? context.getApplicationContext() : null; |
260 mWindowAndroid = window; | 261 mWindowAndroid = window; |
261 } | 262 } |
262 | 263 |
263 /** | 264 /** |
264 * Adds a {@link TabObserver} to be notified on {@link TabBase} changes. | 265 * Adds a {@link TabObserver} to be notified on {@link Tab} changes. |
265 * @param observer The {@link TabObserver} to add. | 266 * @param observer The {@link TabObserver} to add. |
266 */ | 267 */ |
267 public final void addObserver(TabObserver observer) { | 268 public final void addObserver(TabObserver observer) { |
268 mObservers.addObserver(observer); | 269 mObservers.addObserver(observer); |
269 } | 270 } |
270 | 271 |
271 /** | 272 /** |
272 * Removes a {@link TabObserver}. | 273 * Removes a {@link TabObserver}. |
273 * @param observer The {@link TabObserver} to remove. | 274 * @param observer The {@link TabObserver} to remove. |
274 */ | 275 */ |
(...skipping 51 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
326 } | 327 } |
327 | 328 |
328 /** | 329 /** |
329 * Requests the current navigation to be loaded upon the next call to loadIf Necessary(). | 330 * Requests the current navigation to be loaded upon the next call to loadIf Necessary(). |
330 */ | 331 */ |
331 protected void requestRestoreLoad() { | 332 protected void requestRestoreLoad() { |
332 if (mContentViewCore != null) mContentViewCore.requestRestoreLoad(); | 333 if (mContentViewCore != null) mContentViewCore.requestRestoreLoad(); |
333 } | 334 } |
334 | 335 |
335 /** | 336 /** |
336 * @return Whether or not the {@link TabBase} is currently showing an inters titial page, such as | 337 * @return Whether or not the {@link Tab} is currently showing an interstiti al page, such as |
337 * a bad HTTPS page. | 338 * a bad HTTPS page. |
338 */ | 339 */ |
339 public boolean isShowingInterstitialPage() { | 340 public boolean isShowingInterstitialPage() { |
340 ContentViewCore contentViewCore = getContentViewCore(); | 341 ContentViewCore contentViewCore = getContentViewCore(); |
341 return contentViewCore != null && contentViewCore.isShowingInterstitialP age(); | 342 return contentViewCore != null && contentViewCore.isShowingInterstitialP age(); |
342 } | 343 } |
343 | 344 |
344 /** | 345 /** |
345 * @return Whether or not the tab has something valid to render. | 346 * @return Whether or not the tab has something valid to render. |
346 */ | 347 */ |
(...skipping 145 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
492 /** | 493 /** |
493 * @return The {@link NativePage} associated with the current page, or {@cod e null} if there is | 494 * @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 | 495 * no current page or the current page is displayed using something besides |
495 * {@link NativePage}. | 496 * {@link NativePage}. |
496 */ | 497 */ |
497 public NativePage getNativePage() { | 498 public NativePage getNativePage() { |
498 return mNativePage; | 499 return mNativePage; |
499 } | 500 } |
500 | 501 |
501 /** | 502 /** |
502 * @return Whether or not the {@link TabBase} represents a {@link NativePage }. | 503 * @return Whether or not the {@link Tab} represents a {@link NativePage}. |
503 */ | 504 */ |
504 public boolean isNativePage() { | 505 public boolean isNativePage() { |
505 return mNativePage != null; | 506 return mNativePage != null; |
506 } | 507 } |
507 | 508 |
508 /** | 509 /** |
509 * Set whether or not the {@link ContentViewCore} should be using a desktop user agent for the | 510 * Set whether or not the {@link ContentViewCore} should be using a desktop user agent for the |
510 * currently loaded page. | 511 * currently loaded page. |
511 * @param useDesktop If {@code true}, use a desktop user agent. Otherwi se use a mobile one. | 512 * @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. | 513 * @param reloadOnChange Reload the page if the user agent has changed. |
(...skipping 49 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
562 * @return The {@link ContentViewClient} currently bound to any {@link Conte ntViewCore} | 563 * @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} | 564 * associated with the current page. There can still be a {@link Co ntentViewClient} |
564 * even when there is no {@link ContentViewCore}. | 565 * even when there is no {@link ContentViewCore}. |
565 */ | 566 */ |
566 protected ContentViewClient getContentViewClient() { | 567 protected ContentViewClient getContentViewClient() { |
567 return mContentViewClient; | 568 return mContentViewClient; |
568 } | 569 } |
569 | 570 |
570 /** | 571 /** |
571 * @param client The {@link ContentViewClient} to be bound to any current or new | 572 * @param client The {@link ContentViewClient} to be bound to any current or new |
572 * {@link ContentViewCore}s associated with this {@link TabBas e}. | 573 * {@link ContentViewCore}s associated with this {@link Tab}. |
573 */ | 574 */ |
574 protected void setContentViewClient(ContentViewClient client) { | 575 protected void setContentViewClient(ContentViewClient client) { |
575 if (mContentViewClient == client) return; | 576 if (mContentViewClient == client) return; |
576 | 577 |
577 ContentViewClient oldClient = mContentViewClient; | 578 ContentViewClient oldClient = mContentViewClient; |
578 mContentViewClient = client; | 579 mContentViewClient = client; |
579 | 580 |
580 if (mContentViewCore == null) return; | 581 if (mContentViewCore == null) return; |
581 | 582 |
582 if (mContentViewClient != null) { | 583 if (mContentViewClient != null) { |
(...skipping 36 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
619 */ | 620 */ |
620 protected void showRenderedPage() { | 621 protected void showRenderedPage() { |
621 if (mNativePage == null) return; | 622 if (mNativePage == null) return; |
622 NativePage previousNativePage = mNativePage; | 623 NativePage previousNativePage = mNativePage; |
623 mNativePage = null; | 624 mNativePage = null; |
624 for (TabObserver observer : mObservers) observer.onContentChanged(this); | 625 for (TabObserver observer : mObservers) observer.onContentChanged(this); |
625 destroyNativePageInternal(previousNativePage); | 626 destroyNativePageInternal(previousNativePage); |
626 } | 627 } |
627 | 628 |
628 /** | 629 /** |
629 * Initializes this {@link TabBase}. | 630 * Initializes this {@link Tab}. |
630 */ | 631 */ |
631 public void initialize() { | 632 public void initialize() { |
632 initializeNative(); | 633 initializeNative(); |
633 } | 634 } |
634 | 635 |
635 /** | 636 /** |
636 * Builds the native counterpart to this class. Meant to be overridden by s ubclasses to build | 637 * 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 | 638 * 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. | 639 * rely on the native class to create the JNI association. |
639 */ | 640 */ |
(...skipping 21 matching lines...) Expand all Loading... | |
661 */ | 662 */ |
662 protected void initContentView(long nativeWebContents) { | 663 protected void initContentView(long nativeWebContents) { |
663 NativePage previousNativePage = mNativePage; | 664 NativePage previousNativePage = mNativePage; |
664 mNativePage = null; | 665 mNativePage = null; |
665 destroyNativePageInternal(previousNativePage); | 666 destroyNativePageInternal(previousNativePage); |
666 | 667 |
667 mContentView = ContentView.newInstance(mContext, nativeWebContents, getW indowAndroid()); | 668 mContentView = ContentView.newInstance(mContext, nativeWebContents, getW indowAndroid()); |
668 | 669 |
669 mContentViewCore = mContentView.getContentViewCore(); | 670 mContentViewCore = mContentView.getContentViewCore(); |
670 mWebContentsDelegate = createWebContentsDelegate(); | 671 mWebContentsDelegate = createWebContentsDelegate(); |
671 mWebContentsObserver = new TabBaseWebContentsObserverAndroid(mContentVie wCore); | 672 mWebContentsObserver = new TabWebContentsObserverAndroid(mContentViewCor e); |
672 mVoiceSearchTabHelper = new VoiceSearchTabHelper(mContentViewCore); | 673 mVoiceSearchTabHelper = new VoiceSearchTabHelper(mContentViewCore); |
673 | 674 |
674 if (mContentViewClient != null) mContentViewCore.setContentViewClient(mC ontentViewClient); | 675 if (mContentViewClient != null) mContentViewCore.setContentViewClient(mC ontentViewClient); |
675 | 676 |
676 assert mNativeTabAndroid != 0; | 677 assert mNativeTabAndroid != 0; |
677 nativeInitWebContents( | 678 nativeInitWebContents( |
678 mNativeTabAndroid, mIncognito, mContentViewCore, mWebContentsDel egate, | 679 mNativeTabAndroid, mIncognito, mContentViewCore, mWebContentsDel egate, |
679 new TabBaseContextMenuPopulator(createContextMenuPopulator())); | 680 new TabContextMenuPopulator(createContextMenuPopulator())); |
680 | 681 |
681 // In the case where restoring a Tab or showing a prerendered one we alr eady have a | 682 // 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. | 683 // valid infobar container, no need to recreate one. |
683 if (mInfoBarContainer == null) { | 684 if (mInfoBarContainer == null) { |
684 // The InfoBarContainer needs to be created after the ContentView ha s been natively | 685 // The InfoBarContainer needs to be created after the ContentView ha s been natively |
685 // initialized. | 686 // initialized. |
686 mInfoBarContainer = new InfoBarContainer( | 687 mInfoBarContainer = new InfoBarContainer( |
687 (Activity) mContext, createAutoLoginProcessor(), getId(), ge tContentView(), | 688 (Activity) mContext, createAutoLoginProcessor(), getId(), ge tContentView(), |
688 nativeWebContents); | 689 nativeWebContents); |
689 } else { | 690 } else { |
690 mInfoBarContainer.onParentViewChanged(getId(), getContentView()); | 691 mInfoBarContainer.onParentViewChanged(getId(), getContentView()); |
691 } | 692 } |
692 | 693 |
693 if (AppBannerManager.isEnabled() && mAppBannerManager == null) { | 694 if (AppBannerManager.isEnabled() && mAppBannerManager == null) { |
694 mAppBannerManager = new AppBannerManager(this); | 695 mAppBannerManager = new AppBannerManager(this); |
695 } | 696 } |
696 | 697 |
697 for (TabObserver observer : mObservers) observer.onContentChanged(this); | 698 for (TabObserver observer : mObservers) observer.onContentChanged(this); |
698 } | 699 } |
699 | 700 |
700 /** | 701 /** |
701 * Cleans up all internal state, destroying any {@link NativePage} or {@link ContentView} | 702 * 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 | 703 * 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 | 704 * 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. | 705 * this method is called. Once this call is made this {@link Tab} should no longer be used. |
705 */ | 706 */ |
706 public void destroy() { | 707 public void destroy() { |
707 for (TabObserver observer : mObservers) observer.onDestroyed(this); | 708 for (TabObserver observer : mObservers) observer.onDestroyed(this); |
708 | 709 |
709 NativePage currentNativePage = mNativePage; | 710 NativePage currentNativePage = mNativePage; |
710 mNativePage = null; | 711 mNativePage = null; |
711 destroyNativePageInternal(currentNativePage); | 712 destroyNativePageInternal(currentNativePage); |
712 destroyContentView(true); | 713 destroyContentView(true); |
713 | 714 |
714 // Destroys the native tab after destroying the ContentView but before d estroying the | 715 // 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 Loading... | |
801 * Gives subclasses the chance to clean up some state associated with this { @link ContentView}. | 802 * 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} | 803 * This is because {@link #getContentView()} can return {@code null} if a {@ link NativePage} |
803 * is showing. | 804 * is showing. |
804 * @param contentView The {@link ContentView} that should have associated st ate cleaned up. | 805 * @param contentView The {@link ContentView} that should have associated st ate cleaned up. |
805 */ | 806 */ |
806 protected void destroyContentViewInternal(ContentView contentView) { | 807 protected void destroyContentViewInternal(ContentView contentView) { |
807 } | 808 } |
808 | 809 |
809 /** | 810 /** |
810 * A helper method to allow subclasses to build their own delegate. | 811 * A helper method to allow subclasses to build their own delegate. |
811 * @return An instance of a {@link TabBaseChromeWebContentsDelegateAndroid}. | 812 * @return An instance of a {@link TabChromeWebContentsDelegateAndroid}. |
812 */ | 813 */ |
813 protected TabBaseChromeWebContentsDelegateAndroid createWebContentsDelegate( ) { | 814 protected TabChromeWebContentsDelegateAndroid createWebContentsDelegate() { |
814 return new TabBaseChromeWebContentsDelegateAndroid(); | 815 return new TabChromeWebContentsDelegateAndroid(); |
815 } | 816 } |
816 | 817 |
817 /** | 818 /** |
818 * A helper method to allow subclasses to build their own menu populator. | 819 * A helper method to allow subclasses to build their own menu populator. |
819 * @return An instance of a {@link ContextMenuPopulator}. | 820 * @return An instance of a {@link ContextMenuPopulator}. |
820 */ | 821 */ |
821 protected ContextMenuPopulator createContextMenuPopulator() { | 822 protected ContextMenuPopulator createContextMenuPopulator() { |
822 return new ChromeContextMenuPopulator(new TabBaseChromeContextMenuItemDe legate()); | 823 return new ChromeContextMenuPopulator(new TabChromeContextMenuItemDelega te()); |
823 } | 824 } |
824 | 825 |
825 /** | 826 /** |
826 * @return The {@link WindowAndroid} associated with this {@link TabBase}. | 827 * @return The {@link WindowAndroid} associated with this {@link Tab}. |
827 */ | 828 */ |
828 public WindowAndroid getWindowAndroid() { | 829 public WindowAndroid getWindowAndroid() { |
829 return mWindowAndroid; | 830 return mWindowAndroid; |
830 } | 831 } |
831 | 832 |
832 /** | 833 /** |
833 * @return The current {@link TabBaseChromeWebContentsDelegateAndroid} insta nce. | 834 * @return The current {@link TabChromeWebContentsDelegateAndroid} instance. |
834 */ | 835 */ |
835 protected TabBaseChromeWebContentsDelegateAndroid getChromeWebContentsDelega teAndroid() { | 836 protected TabChromeWebContentsDelegateAndroid getChromeWebContentsDelegateAn droid() { |
836 return mWebContentsDelegate; | 837 return mWebContentsDelegate; |
837 } | 838 } |
838 | 839 |
839 /** | 840 /** |
840 * Called when the favicon of the content this tab represents changes. | 841 * Called when the favicon of the content this tab represents changes. |
841 */ | 842 */ |
842 @CalledByNative | 843 @CalledByNative |
843 protected void onFaviconUpdated() { | 844 protected void onFaviconUpdated() { |
844 for (TabObserver observer : mObservers) observer.onFaviconUpdated(this); | 845 for (TabObserver observer : mObservers) observer.onFaviconUpdated(this); |
845 } | 846 } |
846 | 847 |
847 /** | 848 /** |
848 * Called when the navigation entry containing the historyitem changed, | 849 * Called when the navigation entry containing the historyitem changed, |
849 * for example because of a scroll offset or form field change. | 850 * for example because of a scroll offset or form field change. |
850 */ | 851 */ |
851 @CalledByNative | 852 @CalledByNative |
852 protected void onNavEntryChanged() { | 853 protected void onNavEntryChanged() { |
853 } | 854 } |
854 | 855 |
855 /** | 856 /** |
856 * @return The native pointer representing the native side of this {@link Ta bBase} object. | 857 * @return The native pointer representing the native side of this {@link Ta b} object. |
857 */ | 858 */ |
858 @CalledByNative | 859 @CalledByNative |
859 protected long getNativePtr() { | 860 protected long getNativePtr() { |
860 return mNativeTabAndroid; | 861 return mNativeTabAndroid; |
861 } | 862 } |
862 | 863 |
863 /** This is currently called when committing a pre-rendered page. */ | 864 /** This is currently called when committing a pre-rendered page. */ |
864 @CalledByNative | 865 @CalledByNative |
865 private void swapWebContents( | 866 private void swapWebContents( |
866 final long newWebContents, boolean didStartLoad, boolean didFinishLo ad) { | 867 final long newWebContents, boolean didStartLoad, boolean didFinishLo ad) { |
(...skipping 88 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
955 ContentViewCore contentViewCore, ChromeWebContentsDelegateAndroid de legate, | 956 ContentViewCore contentViewCore, ChromeWebContentsDelegateAndroid de legate, |
956 ContextMenuPopulator contextMenuPopulator); | 957 ContextMenuPopulator contextMenuPopulator); |
957 private native void nativeDestroyWebContents(long nativeTabAndroid, boolean deleteNative); | 958 private native void nativeDestroyWebContents(long nativeTabAndroid, boolean deleteNative); |
958 private native WebContents nativeGetWebContents(long nativeTabAndroid); | 959 private native WebContents nativeGetWebContents(long nativeTabAndroid); |
959 private native Profile nativeGetProfileAndroid(long nativeTabAndroid); | 960 private native Profile nativeGetProfileAndroid(long nativeTabAndroid); |
960 private native int nativeGetSecurityLevel(long nativeTabAndroid); | 961 private native int nativeGetSecurityLevel(long nativeTabAndroid); |
961 private native void nativeSetActiveNavigationEntryTitleForUrl(long nativeTab Android, String url, | 962 private native void nativeSetActiveNavigationEntryTitleForUrl(long nativeTab Android, String url, |
962 String title); | 963 String title); |
963 private native boolean nativePrint(long nativeTabAndroid); | 964 private native boolean nativePrint(long nativeTabAndroid); |
964 } | 965 } |
OLD | NEW |