This source file includes following definitions.
- generateId
- setNativeInfoBar
- replaceNativePointer
- shouldExpire
- setExpireOnNavigation
- ownsNativeInfoBar
- isDismissed
- setContext
- getContext
- createView
- dismissJavaOnlyInfoBar
- closeInfoBar
- getContentWrapper
- getInfoBarContainer
- getContentWrapper
- setInfoBarContainer
- areControlsEnabled
- setControlsEnabled
- onButtonClicked
- onLinkClicked
- createContent
- getPrimaryButtonText
- getSecondaryButtonText
- getTabId
- getId
- setDismissedListener
- nativeOnLinkClicked
- nativeOnButtonClicked
- nativeOnCloseButtonClicked
package org.chromium.chrome.browser.infobar;
import android.content.Context;
import android.view.View;
import com.google.common.annotations.VisibleForTesting;
import org.chromium.base.CalledByNative;
import org.chromium.chrome.R;
public abstract class InfoBar implements InfoBarView {
    private static final String TAG = "InfoBar";
    
    public static final int ACTION_TYPE_NONE = 0;
    
    public static final int ACTION_TYPE_OK = 1;
    public static final int ACTION_TYPE_CANCEL = 2;
    
    public static final int ACTION_TYPE_TRANSLATE = 3;
    public static final int ACTION_TYPE_TRANSLATE_SHOW_ORIGINAL = 4;
    
    public static final int BACKGROUND_TYPE_INFO = 0;
    public static final int BACKGROUND_TYPE_WARNING = 1;
    private final int mBackgroundType;
    private final int mIconDrawableId;
    private InfoBarListeners.Dismiss mListener;
    private ContentWrapperView mContentView;
    private InfoBarContainer mContainer;
    private Context mContext;
    private boolean mExpireOnNavigation;
    private boolean mIsDismissed;
    private boolean mControlsEnabled;
    
    
    
    protected long mNativeInfoBarPtr;
    
    private final int mId;
    private static int sIdCounter = 0;
    private static int generateId() {
        return sIdCounter++;
    }
    
    public InfoBar(InfoBarListeners.Dismiss listener, int backgroundType, int iconDrawableId) {
        mListener = listener;
        mId = generateId();
        mBackgroundType = backgroundType;
        mIconDrawableId = iconDrawableId;
        mExpireOnNavigation = true;
    }
    
    protected void setNativeInfoBar(long nativeInfoBarPtr) {
        if (nativeInfoBarPtr != 0) {
            
            mExpireOnNavigation = false;
            mNativeInfoBarPtr = nativeInfoBarPtr;
        }
    }
    
    protected void replaceNativePointer(long newInfoBarPtr) {
        mNativeInfoBarPtr = newInfoBarPtr;
    }
    
    
    
    
    
    public final boolean shouldExpire(String url) {
        return mExpireOnNavigation && mNativeInfoBarPtr == 0;
    }
    
    public void setExpireOnNavigation(boolean expireOnNavigation) {
        mExpireOnNavigation = expireOnNavigation;
    }
    
    boolean ownsNativeInfoBar(long nativePointer) {
        return mNativeInfoBarPtr == nativePointer;
    }
    
    protected boolean isDismissed() {
        return mIsDismissed;
    }
    
    protected void setContext(Context context) {
        mContext = context;
    }
    
    protected Context getContext() {
        return mContext;
    }
    
    protected final View createView() {
        assert mContext != null;
        return new InfoBarLayout(mContext, this, mBackgroundType, mIconDrawableId);
    }
    
    public void dismissJavaOnlyInfoBar() {
        assert mNativeInfoBarPtr == 0;
        if (closeInfoBar() && mListener != null) {
            mListener.onInfoBarDismissed(this);
        }
    }
    
    @CalledByNative
    public boolean closeInfoBar() {
        if (!mIsDismissed) {
            mIsDismissed = true;
            if (!mContainer.hasBeenDestroyed()) {
                
                mContainer.removeInfoBar(this);
            }
            return true;
        }
        return false;
    }
    protected ContentWrapperView getContentWrapper(boolean createIfNotFound) {
        if (mContentView == null && createIfNotFound) {
            mContentView = new ContentWrapperView(getContext(), this, mBackgroundType,
                    createView(), getInfoBarContainer().areInfoBarsOnTop());
            mContentView.setFocusable(false);
        }
        return mContentView;
    }
    protected InfoBarContainer getInfoBarContainer() {
        return mContainer;
    }
    
    public ContentWrapperView getContentWrapper() {
        return getContentWrapper(true);
    }
    void setInfoBarContainer(InfoBarContainer container) {
        mContainer = container;
    }
    public boolean areControlsEnabled() {
        return mControlsEnabled;
    }
    @Override
    public void setControlsEnabled(boolean state) {
        mControlsEnabled = state;
        
        if (mContentView != null) {
            View closeButton = mContentView.findViewById(R.id.infobar_close_button);
            if (closeButton != null) closeButton.setEnabled(state);
        }
    }
    @Override
    public void onButtonClicked(boolean isPrimaryButton) {
    }
    @Override
    public void onLinkClicked() {
        nativeOnLinkClicked(mNativeInfoBarPtr);
    }
    @Override
    public void createContent(InfoBarLayout layout) {
    }
    @Override
    public String getPrimaryButtonText(Context context) {
        return null;
    }
    @Override
    public String getSecondaryButtonText(Context context) {
        return null;
    }
    
    public int getTabId() {
        return mContainer.getTabId();
    }
    @VisibleForTesting
    public int getId() {
        return mId;
    }
    @VisibleForTesting
    public void setDismissedListener(InfoBarListeners.Dismiss listener) {
        mListener = listener;
    }
    protected native void nativeOnLinkClicked(long nativeInfoBarAndroid);
    protected native void nativeOnButtonClicked(
            long nativeInfoBarAndroid, int action, String actionValue);
    protected native void nativeOnCloseButtonClicked(long nativeInfoBarAndroid);
}