This source file includes following definitions.
- isIncognito
- onSaveToClipboard
- onSaveImageToClipboard
- onLoadProgressChanged
- onLoadStarted
- onLoadStopped
- onUpdateUrl
- showRepostFormWarningDialog
- toggleFullscreenModeForTab
- navigationStateChanged
- buildContextMenu
- navigationEntryCommitted
- didFailLoad
- didStartProvisionalLoadForFrame
- addObserver
- removeObserver
- canGoBack
- canGoForward
- goBack
- goForward
- getDirectedNavigationHistory
- goToNavigationIndex
- loadIfNecessary
- requestRestoreLoad
- loadUrl
- isShowingInterstitialPage
- isReady
- getView
- getWidth
- getHeight
- getApplicationContext
- getInfoBarContainer
- createAutoLoginProcessor
- print
- reload
- reloadIgnoringCache
- stopLoading
- getBackgroundColor
- getWebContents
- getProfile
- getId
- isIncognito
- getContentView
- getContentViewCore
- getPageInfo
- getNativePage
- isNativePage
- setUseDesktopUserAgent
- getUseDesktopUserAgent
- getSecurityLevel
- getSyncId
- setSyncId
- getTabObservers
- getContentViewClient
- setContentViewClient
- show
- hide
- showNativePage
- showRenderedPage
- initialize
- initializeNative
- initContentView
- initContentView
- setContentView
- destroy
- isInitialized
- getUrl
- getTitle
- getFavicon
- loadIfNeeded
- getParentId
- isGroupedWithParent
- setGroupedWithParent
- destroyNativePageInternal
- destroyContentView
- destroyContentViewInternal
- createWebContentsDelegate
- createContextMenuPopulator
- getWindowAndroid
- getChromeWebContentsDelegateAndroid
- onFaviconUpdated
- onNavEntryChanged
- getNativePtr
- swapWebContents
- swapContentView
- clearNativePtr
- setNativePtr
- getNativeInfoBarContainer
- generateValidId
- generateNextId
- pushNativePageStateToNavigationEntry
- incrementIdCounterTo
- nativeInit
- nativeDestroy
- nativeInitWebContents
- nativeDestroyWebContents
- nativeGetWebContents
- nativeGetProfileAndroid
- nativeLoadUrl
- nativeGetSecurityLevel
- nativeSetActiveNavigationEntryTitleForUrl
- nativePrint
package org.chromium.chrome.browser;
import android.app.Activity;
import android.content.Context;
import android.graphics.Bitmap;
import android.graphics.Color;
import android.view.ContextMenu;
import android.view.View;
import org.chromium.base.CalledByNative;
import org.chromium.base.ObserverList;
import org.chromium.base.TraceEvent;
import org.chromium.chrome.browser.banners.AppBannerManager;
import org.chromium.chrome.browser.contextmenu.ChromeContextMenuItemDelegate;
import org.chromium.chrome.browser.contextmenu.ChromeContextMenuPopulator;
import org.chromium.chrome.browser.contextmenu.ContextMenuParams;
import org.chromium.chrome.browser.contextmenu.ContextMenuPopulator;
import org.chromium.chrome.browser.contextmenu.ContextMenuPopulatorWrapper;
import org.chromium.chrome.browser.contextmenu.EmptyChromeContextMenuItemDelegate;
import org.chromium.chrome.browser.dom_distiller.DomDistillerFeedbackReporter;
import org.chromium.chrome.browser.infobar.AutoLoginProcessor;
import org.chromium.chrome.browser.infobar.InfoBarContainer;
import org.chromium.chrome.browser.profiles.Profile;
import org.chromium.chrome.browser.ui.toolbar.ToolbarModelSecurityLevel;
import org.chromium.content.browser.ContentView;
import org.chromium.content.browser.ContentViewClient;
import org.chromium.content.browser.ContentViewCore;
import org.chromium.content.browser.LoadUrlParams;
import org.chromium.content.browser.NavigationClient;
import org.chromium.content.browser.NavigationHistory;
import org.chromium.content.browser.PageInfo;
import org.chromium.content.browser.WebContentsObserverAndroid;
import org.chromium.content_public.browser.WebContents;
import org.chromium.ui.base.Clipboard;
import org.chromium.ui.base.WindowAndroid;
import java.util.concurrent.atomic.AtomicInteger;
public class Tab implements NavigationClient {
public static final int INVALID_TAB_ID = -1;
private static final AtomicInteger sIdCounter = new AtomicInteger();
private long mNativeTabAndroid;
private final int mId;
private final boolean mIncognito;
private final Context mApplicationContext;
private final Context mContext;
private final WindowAndroid mWindowAndroid;
private NativePage mNativePage;
private ContentView mContentView;
private InfoBarContainer mInfoBarContainer;
private AppBannerManager mAppBannerManager;
private int mSyncId;
private ContentViewCore mContentViewCore;
private final ObserverList<TabObserver> mObservers = new ObserverList<TabObserver>();
private ContentViewClient mContentViewClient;
private WebContentsObserverAndroid mWebContentsObserver;
private VoiceSearchTabHelper mVoiceSearchTabHelper;
private TabChromeWebContentsDelegateAndroid mWebContentsDelegate;
private DomDistillerFeedbackReporter mDomDistillerFeedbackReporter;
private int mParentId = INVALID_TAB_ID;
private boolean mGroupedWithParent = true;
protected class TabChromeContextMenuItemDelegate
extends EmptyChromeContextMenuItemDelegate {
private final Clipboard mClipboard;
public TabChromeContextMenuItemDelegate() {
mClipboard = new Clipboard(getApplicationContext());
}
@Override
public boolean isIncognito() {
return mIncognito;
}
@Override
public void onSaveToClipboard(String text, boolean isUrl) {
mClipboard.setText(text, text);
}
@Override
public void onSaveImageToClipboard(String url) {
mClipboard.setHTMLText("<img src=\"" + url + "\">", url, url);
}
}
public class TabChromeWebContentsDelegateAndroid
extends ChromeWebContentsDelegateAndroid {
@Override
public void onLoadProgressChanged(int progress) {
for (TabObserver observer : mObservers) {
observer.onLoadProgressChanged(Tab.this, progress);
}
}
@Override
public void onLoadStarted() {
for (TabObserver observer : mObservers) observer.onLoadStarted(Tab.this);
}
@Override
public void onLoadStopped() {
for (TabObserver observer : mObservers) observer.onLoadStopped(Tab.this);
}
@Override
public void onUpdateUrl(String url) {
for (TabObserver observer : mObservers) observer.onUpdateUrl(Tab.this, url);
}
@Override
public void showRepostFormWarningDialog(final ContentViewCore contentViewCore) {
RepostFormWarningDialog warningDialog = new RepostFormWarningDialog(
new Runnable() {
@Override
public void run() {
contentViewCore.cancelPendingReload();
}
}, new Runnable() {
@Override
public void run() {
contentViewCore.continuePendingReload();
}
});
Activity activity = (Activity) mContext;
warningDialog.show(activity.getFragmentManager(), null);
}
@Override
public void toggleFullscreenModeForTab(boolean enableFullscreen) {
for (TabObserver observer : mObservers) {
observer.onToggleFullscreenMode(Tab.this, enableFullscreen);
}
}
@Override
public void navigationStateChanged(int flags) {
if ((flags & INVALIDATE_TYPE_TITLE) != 0) {
for (TabObserver observer : mObservers) observer.onTitleUpdated(Tab.this);
}
if ((flags & INVALIDATE_TYPE_URL) != 0) {
for (TabObserver observer : mObservers) observer.onUrlUpdated(Tab.this);
}
}
}
private class TabContextMenuPopulator extends ContextMenuPopulatorWrapper {
public TabContextMenuPopulator(ContextMenuPopulator populator) {
super(populator);
}
@Override
public void buildContextMenu(ContextMenu menu, Context context, ContextMenuParams params) {
super.buildContextMenu(menu, context, params);
for (TabObserver observer : mObservers) observer.onContextMenuShown(Tab.this, menu);
}
}
private class TabWebContentsObserverAndroid extends WebContentsObserverAndroid {
public TabWebContentsObserverAndroid(ContentViewCore contentViewCore) {
super(contentViewCore);
}
@Override
public void navigationEntryCommitted() {
if (getNativePage() != null) {
pushNativePageStateToNavigationEntry();
}
}
@Override
public void didFailLoad(boolean isProvisionalLoad, boolean isMainFrame, int errorCode,
String description, String failingUrl) {
for (TabObserver observer : mObservers) {
observer.onDidFailLoad(Tab.this, isProvisionalLoad, isMainFrame, errorCode,
description, failingUrl);
}
}
@Override
public void didStartProvisionalLoadForFrame(long frameId, long parentFrameId,
boolean isMainFrame, String validatedUrl, boolean isErrorPage,
boolean isIframeSrcdoc) {
for (TabObserver observer : mObservers) {
observer.onDidStartProvisionalLoadForFrame(Tab.this, frameId, parentFrameId,
isMainFrame, validatedUrl, isErrorPage, isIframeSrcdoc);
}
}
}
public Tab(boolean incognito, Context context, WindowAndroid window) {
this(INVALID_TAB_ID, incognito, context, window);
}
public Tab(int id, boolean incognito, Context context, WindowAndroid window) {
this(INVALID_TAB_ID, id, incognito, context, window);
}
public Tab(int id, int parentId, boolean incognito, Context context, WindowAndroid window) {
assert context == null || context instanceof Activity;
mId = generateValidId(id);
mParentId = parentId;
mIncognito = incognito;
mContext = context;
mApplicationContext = context != null ? context.getApplicationContext() : null;
mWindowAndroid = window;
}
public final void addObserver(TabObserver observer) {
mObservers.addObserver(observer);
}
public final void removeObserver(TabObserver observer) {
mObservers.removeObserver(observer);
}
public boolean canGoBack() {
return mContentViewCore != null && mContentViewCore.canGoBack();
}
public boolean canGoForward() {
return mContentViewCore != null && mContentViewCore.canGoForward();
}
public void goBack() {
if (mContentViewCore != null) mContentViewCore.goBack();
}
public void goForward() {
if (mContentViewCore != null) mContentViewCore.goForward();
}
@Override
public NavigationHistory getDirectedNavigationHistory(boolean isForward, int itemLimit) {
if (mContentViewCore != null) {
return mContentViewCore.getDirectedNavigationHistory(isForward, itemLimit);
} else {
return new NavigationHistory();
}
}
@Override
public void goToNavigationIndex(int index) {
if (mContentViewCore != null) mContentViewCore.goToNavigationIndex(index);
}
public void loadIfNecessary() {
if (mContentViewCore != null) mContentViewCore.loadIfNecessary();
}
protected void requestRestoreLoad() {
if (mContentViewCore != null) mContentViewCore.requestRestoreLoad();
}
public int loadUrl(LoadUrlParams params) {
TraceEvent.begin();
int loadType = nativeLoadUrl(
mNativeTabAndroid,
params.getUrl(),
params.getVerbatimHeaders(),
params.getPostData(),
params.getTransitionType(),
params.getReferrer() != null ? params.getReferrer().getUrl() : null,
params.getReferrer() != null ? params.getReferrer().getPolicy() : 0);
TraceEvent.end();
for (TabObserver observer : mObservers) {
observer.onLoadUrl(this, params.getUrl(), loadType);
}
return loadType;
}
public boolean isShowingInterstitialPage() {
ContentViewCore contentViewCore = getContentViewCore();
return contentViewCore != null && contentViewCore.isShowingInterstitialPage();
}
public boolean isReady() {
return mNativePage != null || (mContentViewCore != null && mContentViewCore.isReady());
}
public View getView() {
PageInfo pageInfo = getPageInfo();
return pageInfo != null ? pageInfo.getView() : null;
}
public int getWidth() {
View view = getView();
return view != null ? view.getWidth() : 0;
}
public int getHeight() {
View view = getView();
return view != null ? view.getHeight() : 0;
}
protected Context getApplicationContext() {
return mApplicationContext;
}
public final InfoBarContainer getInfoBarContainer() {
return mInfoBarContainer;
}
protected AutoLoginProcessor createAutoLoginProcessor() {
return new AutoLoginProcessor() {
@Override
public void processAutoLoginResult(String accountName, String authToken,
boolean success, String result) {
}
};
}
public boolean print() {
assert mNativeTabAndroid != 0;
return nativePrint(mNativeTabAndroid);
}
public void reload() {
if (mContentViewCore != null) mContentViewCore.reload(true);
}
public void reloadIgnoringCache() {
if (mContentViewCore != null) mContentViewCore.reloadIgnoringCache(true);
}
public void stopLoading() {
if (mContentViewCore != null) mContentViewCore.stopLoading();
}
public int getBackgroundColor() {
return getPageInfo() != null ? getPageInfo().getBackgroundColor() : Color.WHITE;
}
public WebContents getWebContents() {
if (mNativeTabAndroid == 0) return null;
return nativeGetWebContents(mNativeTabAndroid);
}
public Profile getProfile() {
if (mNativeTabAndroid == 0) return null;
return nativeGetProfileAndroid(mNativeTabAndroid);
}
@CalledByNative
public int getId() {
return mId;
}
public boolean isIncognito() {
return mIncognito;
}
public ContentView getContentView() {
return mNativePage == null ? mContentView : null;
}
public ContentViewCore getContentViewCore() {
return mNativePage == null ? mContentViewCore : null;
}
public PageInfo getPageInfo() {
return mNativePage != null ? mNativePage : mContentView;
}
public NativePage getNativePage() {
return mNativePage;
}
public boolean isNativePage() {
return mNativePage != null;
}
public void setUseDesktopUserAgent(boolean useDesktop, boolean reloadOnChange) {
if (mContentViewCore != null) {
mContentViewCore.setUseDesktopUserAgent(useDesktop, reloadOnChange);
}
}
public boolean getUseDesktopUserAgent() {
return mContentViewCore != null && mContentViewCore.getUseDesktopUserAgent();
}
public int getSecurityLevel() {
if (mNativeTabAndroid == 0) return ToolbarModelSecurityLevel.NONE;
return nativeGetSecurityLevel(mNativeTabAndroid);
}
@CalledByNative
protected int getSyncId() {
return mSyncId;
}
@CalledByNative
protected void setSyncId(int syncId) {
mSyncId = syncId;
}
protected ObserverList.RewindableIterator<TabObserver> getTabObservers() {
return mObservers.rewindableIterator();
}
protected ContentViewClient getContentViewClient() {
return mContentViewClient;
}
protected void setContentViewClient(ContentViewClient client) {
if (mContentViewClient == client) return;
ContentViewClient oldClient = mContentViewClient;
mContentViewClient = client;
if (mContentViewCore == null) return;
if (mContentViewClient != null) {
mContentViewCore.setContentViewClient(mContentViewClient);
} else if (oldClient != null) {
mContentViewCore.setContentViewClient(new ContentViewClient());
}
}
protected void show() {
if (mContentViewCore != null) mContentViewCore.onShow();
}
protected void hide() {
if (mContentViewCore != null) mContentViewCore.onHide();
}
protected void showNativePage(NativePage nativePage) {
if (mNativePage == nativePage) return;
NativePage previousNativePage = mNativePage;
mNativePage = nativePage;
pushNativePageStateToNavigationEntry();
for (TabObserver observer : mObservers) observer.onContentChanged(this);
destroyNativePageInternal(previousNativePage);
}
protected void showRenderedPage() {
if (mNativePage == null) return;
NativePage previousNativePage = mNativePage;
mNativePage = null;
for (TabObserver observer : mObservers) observer.onContentChanged(this);
destroyNativePageInternal(previousNativePage);
}
public void initialize() {
initializeNative();
}
protected void initializeNative() {
if (mNativeTabAndroid == 0) nativeInit();
assert mNativeTabAndroid != 0;
}
protected final void initContentView() {
initContentView(ContentViewUtil.createNativeWebContents(mIncognito));
}
protected void initContentView(long nativeWebContents) {
setContentView(ContentView.newInstance(mContext, nativeWebContents, getWindowAndroid()));
}
protected void setContentView(ContentView view) {
NativePage previousNativePage = mNativePage;
mNativePage = null;
destroyNativePageInternal(previousNativePage);
mContentView = view;
mContentViewCore = mContentView.getContentViewCore();
mWebContentsDelegate = createWebContentsDelegate();
mWebContentsObserver = new TabWebContentsObserverAndroid(mContentViewCore);
mVoiceSearchTabHelper = new VoiceSearchTabHelper(mContentViewCore);
if (mContentViewClient != null) mContentViewCore.setContentViewClient(mContentViewClient);
assert mNativeTabAndroid != 0;
nativeInitWebContents(
mNativeTabAndroid, mIncognito, mContentViewCore, mWebContentsDelegate,
new TabContextMenuPopulator(createContextMenuPopulator()));
if (mInfoBarContainer == null) {
WebContents webContents = view.getContentViewCore().getWebContents();
mInfoBarContainer = new InfoBarContainer(
(Activity) mContext, createAutoLoginProcessor(), getId(), getContentView(),
webContents);
} else {
mInfoBarContainer.onParentViewChanged(getId(), getContentView());
}
if (AppBannerManager.isEnabled() && mAppBannerManager == null) {
mAppBannerManager = new AppBannerManager(this);
}
if (DomDistillerFeedbackReporter.isEnabled() && mDomDistillerFeedbackReporter == null) {
mDomDistillerFeedbackReporter = new DomDistillerFeedbackReporter(this);
}
for (TabObserver observer : mObservers) observer.onContentChanged(this);
}
public void destroy() {
for (TabObserver observer : mObservers) observer.onDestroyed(this);
mObservers.clear();
NativePage currentNativePage = mNativePage;
mNativePage = null;
destroyNativePageInternal(currentNativePage);
destroyContentView(true);
assert mNativeTabAndroid != 0;
nativeDestroy(mNativeTabAndroid);
assert mNativeTabAndroid == 0;
if (mInfoBarContainer != null) {
mInfoBarContainer.destroy();
mInfoBarContainer = null;
}
}
public boolean isInitialized() {
return mNativeTabAndroid != 0;
}
@CalledByNative
public String getUrl() {
return mContentView != null ? mContentView.getUrl() : "";
}
@CalledByNative
public String getTitle() {
return getPageInfo() != null ? getPageInfo().getTitle() : "";
}
public Bitmap getFavicon() {
return null;
}
@CalledByNative
public boolean loadIfNeeded() {
return false;
}
public int getParentId() {
return mParentId;
}
public boolean isGroupedWithParent() {
return mGroupedWithParent;
}
public void setGroupedWithParent(boolean groupedWithParent) {
mGroupedWithParent = groupedWithParent;
}
private void destroyNativePageInternal(NativePage nativePage) {
if (nativePage == null) return;
assert getPageInfo() != nativePage : "Attempting to destroy active page.";
nativePage.destroy();
}
protected final void destroyContentView(boolean deleteNativeWebContents) {
if (mContentView == null) return;
destroyContentViewInternal(mContentView);
if (mInfoBarContainer != null && mInfoBarContainer.getParent() != null) {
mInfoBarContainer.removeFromParentView();
}
if (mContentViewCore != null) mContentViewCore.destroy();
mContentView = null;
mContentViewCore = null;
mWebContentsDelegate = null;
mWebContentsObserver = null;
mVoiceSearchTabHelper = null;
assert mNativeTabAndroid != 0;
nativeDestroyWebContents(mNativeTabAndroid, deleteNativeWebContents);
}
protected void destroyContentViewInternal(ContentView contentView) {
}
protected TabChromeWebContentsDelegateAndroid createWebContentsDelegate() {
return new TabChromeWebContentsDelegateAndroid();
}
protected ContextMenuPopulator createContextMenuPopulator() {
return new ChromeContextMenuPopulator(new TabChromeContextMenuItemDelegate());
}
public WindowAndroid getWindowAndroid() {
return mWindowAndroid;
}
protected TabChromeWebContentsDelegateAndroid getChromeWebContentsDelegateAndroid() {
return mWebContentsDelegate;
}
@CalledByNative
protected void onFaviconUpdated() {
for (TabObserver observer : mObservers) observer.onFaviconUpdated(this);
}
@CalledByNative
protected void onNavEntryChanged() {
}
@CalledByNative
protected long getNativePtr() {
return mNativeTabAndroid;
}
@CalledByNative
private void swapWebContents(
final long newWebContents, boolean didStartLoad, boolean didFinishLoad) {
swapContentView(ContentView.newInstance(mContext, newWebContents, getWindowAndroid()),
false);
for (TabObserver observer : mObservers) {
observer.onWebContentsSwapped(this, didStartLoad, didFinishLoad);
}
}
protected void swapContentView(ContentView view, boolean deleteOldNativeWebContents) {
int originalWidth = 0;
int originalHeight = 0;
if (mContentViewCore != null) {
originalWidth = mContentViewCore.getViewportWidthPix();
originalHeight = mContentViewCore.getViewportHeightPix();
mContentViewCore.onHide();
}
destroyContentView(deleteOldNativeWebContents);
NativePage previousNativePage = mNativePage;
mNativePage = null;
setContentView(view);
mContentViewCore.onSizeChanged(originalWidth, originalHeight, 0, 0);
mContentViewCore.onShow();
mContentViewCore.attachImeAdapter();
for (TabObserver observer : mObservers) observer.onContentChanged(this);
destroyNativePageInternal(previousNativePage);
}
@CalledByNative
private void clearNativePtr() {
assert mNativeTabAndroid != 0;
mNativeTabAndroid = 0;
}
@CalledByNative
private void setNativePtr(long nativePtr) {
assert mNativeTabAndroid == 0;
mNativeTabAndroid = nativePtr;
}
@CalledByNative
private long getNativeInfoBarContainer() {
return getInfoBarContainer().getNative();
}
private static int generateValidId(int id) {
if (id == INVALID_TAB_ID) id = generateNextId();
incrementIdCounterTo(id + 1);
return id;
}
private static int generateNextId() {
return sIdCounter.getAndIncrement();
}
private void pushNativePageStateToNavigationEntry() {
assert mNativeTabAndroid != 0 && getNativePage() != null;
nativeSetActiveNavigationEntryTitleForUrl(mNativeTabAndroid, getNativePage().getUrl(),
getNativePage().getTitle());
}
public static void incrementIdCounterTo(int id) {
int diff = id - sIdCounter.get();
if (diff <= 0) return;
sIdCounter.addAndGet(diff);
}
private native void nativeInit();
private native void nativeDestroy(long nativeTabAndroid);
private native void nativeInitWebContents(long nativeTabAndroid, boolean incognito,
ContentViewCore contentViewCore, ChromeWebContentsDelegateAndroid delegate,
ContextMenuPopulator contextMenuPopulator);
private native void nativeDestroyWebContents(long nativeTabAndroid, boolean deleteNative);
private native WebContents nativeGetWebContents(long nativeTabAndroid);
private native Profile nativeGetProfileAndroid(long nativeTabAndroid);
private native int nativeLoadUrl(long nativeTabAndroid, String url, String extraHeaders,
byte[] postData, int transition, String referrerUrl, int referrerPolicy);
private native int nativeGetSecurityLevel(long nativeTabAndroid);
private native void nativeSetActiveNavigationEntryTitleForUrl(long nativeTabAndroid, String url,
String title);
private native boolean nativePrint(long nativeTabAndroid);
}