Java Code Examples for org.chromium.chrome.browser.tab.Tab#initialize()

The following examples show how to use org.chromium.chrome.browser.tab.Tab#initialize() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: ChromeTabCreator.java    From delion with Apache License 2.0 6 votes vote down vote up
@Override
public boolean createTabWithWebContents(Tab parent, WebContents webContents, int parentId,
        TabLaunchType type, String url) {
    // The parent tab was already closed.  Do not open child tabs.
    if (mTabModel.isClosurePending(parentId)) return false;

    // If parent is in the same tab model, place the new tab next to it.
    int position = TabModel.INVALID_TAB_INDEX;
    int index = TabModelUtils.getTabIndexById(mTabModel, parentId);
    if (index != TabModel.INVALID_TAB_INDEX) position = index + 1;

    boolean openInForeground = mOrderController.willOpenInForeground(type, mIncognito);
    TabDelegateFactory delegateFactory = parent == null ? new TabDelegateFactory()
            : parent.getDelegateFactory();
    Tab tab = Tab.createLiveTab(Tab.INVALID_TAB_ID, mActivity, mIncognito,
            mNativeWindow, type, parentId, !openInForeground);
    tab.initialize(webContents, mTabContentManager, delegateFactory, !openInForeground, false);
    mTabModel.addTab(tab, position, type);
    return true;
}
 
Example 2
Source File: ChromeTabCreator.java    From AndroidChromium with Apache License 2.0 6 votes vote down vote up
@Override
public boolean createTabWithWebContents(Tab parent, WebContents webContents, int parentId,
        TabLaunchType type, String url) {
    // The parent tab was already closed.  Do not open child tabs.
    if (mTabModel.isClosurePending(parentId)) return false;

    // If parent is in the same tab model, place the new tab next to it.
    int position = TabModel.INVALID_TAB_INDEX;
    int index = TabModelUtils.getTabIndexById(mTabModel, parentId);
    if (index != TabModel.INVALID_TAB_INDEX) position = index + 1;

    boolean openInForeground = mOrderController.willOpenInForeground(type, mIncognito);
    TabDelegateFactory delegateFactory = parent == null ? createDefaultTabDelegateFactory()
            : parent.getDelegateFactory();
    Tab tab = Tab.createLiveTab(Tab.INVALID_TAB_ID, mActivity, mIncognito,
            mNativeWindow, type, parentId, !openInForeground);
    tab.initialize(webContents, mTabContentManager, delegateFactory, !openInForeground, false);
    mTabModel.addTab(tab, position, type);
    return true;
}
 
Example 3
Source File: ChromeTabCreator.java    From 365browser with Apache License 2.0 6 votes vote down vote up
@Override
public boolean createTabWithWebContents(Tab parent, WebContents webContents, int parentId,
        TabLaunchType type, String url) {
    // The parent tab was already closed.  Do not open child tabs.
    if (mTabModel.isClosurePending(parentId)) return false;

    // If parent is in the same tab model, place the new tab next to it.
    int position = TabModel.INVALID_TAB_INDEX;
    int index = TabModelUtils.getTabIndexById(mTabModel, parentId);
    if (index != TabModel.INVALID_TAB_INDEX) position = index + 1;

    boolean openInForeground = mOrderController.willOpenInForeground(type, mIncognito);
    TabDelegateFactory delegateFactory = parent == null ? createDefaultTabDelegateFactory()
            : parent.getDelegateFactory();
    Tab tab = Tab.createLiveTab(Tab.INVALID_TAB_ID, mActivity, mIncognito,
            mNativeWindow, type, parentId, !openInForeground);
    tab.initialize(webContents, mTabContentManager, delegateFactory, !openInForeground, false);
    mTabModel.addTab(tab, position, type);
    return true;
}
 
Example 4
Source File: CustomTabActivity.java    From delion with Apache License 2.0 5 votes vote down vote up
private Tab createMainTab() {
    CustomTabsConnection customTabsConnection =
            CustomTabsConnection.getInstance(getApplication());
    String url = getUrlToLoad();
    // Get any referrer that has been explicitly set by the app.
    String referrerUrl = IntentHandler.getReferrerUrlIncludingExtraHeaders(getIntent(), this);
    if (referrerUrl == null) {
        Referrer referrer = customTabsConnection.getReferrerForSession(mSession);
        if (referrer != null) referrerUrl = referrer.getUrl();
    }
    Tab tab = new Tab(TabIdManager.getInstance().generateValidId(Tab.INVALID_TAB_ID),
            Tab.INVALID_TAB_ID, false, this, getWindowAndroid(),
            TabLaunchType.FROM_EXTERNAL_APP, null, null);
    tab.setAppAssociatedWith(customTabsConnection.getClientPackageNameForSession(mSession));

    mPrerenderedUrl = customTabsConnection.getPrerenderedUrl(mSession);
    WebContents webContents =
            customTabsConnection.takePrerenderedUrl(mSession, url, referrerUrl);
    mHasPrerendered = webContents != null;
    if (webContents == null) webContents = customTabsConnection.takeSpareWebContents();
    if (webContents == null) webContents = WebContentsFactory.createWebContents(false, false);
    tab.initialize(webContents, getTabContentManager(),
            new CustomTabDelegateFactory(mIntentDataProvider.shouldEnableUrlBarHiding()), false,
            false);
    tab.getTabRedirectHandler().updateIntent(getIntent());
    tab.getView().requestFocus();
    mTabObserver = new CustomTabObserver(getApplication(), mSession);
    tab.addObserver(mTabObserver);
    return tab;
}
 
Example 5
Source File: SearchActivity.java    From 365browser with Apache License 2.0 5 votes vote down vote up
@Override
public void finishNativeInitialization() {
    super.finishNativeInitialization();

    mTab = new Tab(TabIdManager.getInstance().generateValidId(Tab.INVALID_TAB_ID),
            Tab.INVALID_TAB_ID, false, this, getWindowAndroid(),
            TabLaunchType.FROM_EXTERNAL_APP, null, null);
    mTab.initialize(WebContentsFactory.createWebContents(false, false), null,
            new TabDelegateFactory(), false, false);
    mTab.loadUrl(new LoadUrlParams("about:blank"));

    mSearchBoxDataProvider.onNativeLibraryReady(mTab);
    mSearchBox.onNativeLibraryReady();

    // Force the user to choose a search engine if they have to.
    final Callback<Boolean> deferredCallback = new Callback<Boolean>() {
        @Override
        public void onResult(Boolean result) {
            if (result == null || !result.booleanValue()) {
                Log.e(TAG, "User failed to select a default search engine.");
                finish();
                return;
            }

            finishDeferredInitialization();
        }
    };
    if (!getActivityDelegate().showSearchEngineDialogIfNeeded(this, deferredCallback)) {
        mHandler.post(new Runnable() {
            @Override
            public void run() {
                finishDeferredInitialization();
            }
        });
    }
}
 
Example 6
Source File: CustomTabActivity.java    From 365browser with Apache License 2.0 5 votes vote down vote up
private Tab createMainTab() {
    CustomTabsConnection connection = CustomTabsConnection.getInstance(getApplication());
    String url = getUrlToLoad();
    String referrerUrl = connection.getReferrer(mSession, getIntent());
    Tab tab = new Tab(Tab.INVALID_TAB_ID, Tab.INVALID_TAB_ID, false, this, getWindowAndroid(),
            TabLaunchType.FROM_EXTERNAL_APP, null, null);
    tab.setAppAssociatedWith(connection.getClientPackageNameForSession(mSession));

    int webContentsStateOnLaunch = WEBCONTENTS_STATE_NO_WEBCONTENTS;
    WebContents webContents = connection.takePrerenderedUrl(mSession, url, referrerUrl);
    mUsingPrerender = webContents != null;
    if (mUsingPrerender) webContentsStateOnLaunch = WEBCONTENTS_STATE_PRERENDERED_WEBCONTENTS;
    if (!mUsingPrerender) {
        webContents = WarmupManager.getInstance().takeSpareWebContents(false, false);
        if (webContents != null) webContentsStateOnLaunch = WEBCONTENTS_STATE_SPARE_WEBCONTENTS;
    }
    RecordHistogram.recordEnumeratedHistogram("CustomTabs.WebContentsStateOnLaunch",
            webContentsStateOnLaunch, WEBCONTENTS_STATE_MAX);
    if (webContents == null) {
        webContents = WebContentsFactory.createWebContentsWithWarmRenderer(false, false);
    }
    if (!mUsingPrerender) {
        connection.resetPostMessageHandlerForSession(mSession, webContents);
    }
    tab.initialize(
            webContents, getTabContentManager(),
            new CustomTabDelegateFactory(
                    mIntentDataProvider.shouldEnableUrlBarHiding(),
                    mIntentDataProvider.isOpenedByChrome(),
                    getFullscreenManager().getBrowserVisibilityDelegate()),
            false, false);

    if (mIntentDataProvider.shouldEnableEmbeddedMediaExperience()) {
        tab.enableEmbeddedMediaExperience(true);
    }

    initializeMainTab(tab);
    return tab;
}
 
Example 7
Source File: CustomTabActivity.java    From AndroidChromium with Apache License 2.0 4 votes vote down vote up
private Tab createMainTab() {
    CustomTabsConnection customTabsConnection =
            CustomTabsConnection.getInstance(getApplication());
    String url = getUrlToLoad();
    // Get any referrer that has been explicitly set by the app.
    String referrerUrl = IntentHandler.getReferrerUrlIncludingExtraHeaders(getIntent(), this);
    if (referrerUrl == null) {
        Referrer referrer = customTabsConnection.getReferrerForSession(mSession);
        if (referrer != null) referrerUrl = referrer.getUrl();
    }
    Tab tab = new Tab(TabIdManager.getInstance().generateValidId(Tab.INVALID_TAB_ID),
            Tab.INVALID_TAB_ID, false, this, getWindowAndroid(),
            TabLaunchType.FROM_EXTERNAL_APP, null, null);
    tab.setAppAssociatedWith(customTabsConnection.getClientPackageNameForSession(mSession));

    mPrerenderedUrl = customTabsConnection.getPrerenderedUrl(mSession);
    int webContentsStateOnLaunch = WEBCONTENTS_STATE_NO_WEBCONTENTS;
    WebContents webContents =
            customTabsConnection.takePrerenderedUrl(mSession, url, referrerUrl);
    mHasPrerendered = webContents != null;
    if (mHasPrerendered) webContentsStateOnLaunch = WEBCONTENTS_STATE_PRERENDERED_WEBCONTENTS;
    if (!mHasPrerendered) {
        webContents = WarmupManager.getInstance().takeSpareWebContents(false, false);
        if (webContents != null) webContentsStateOnLaunch = WEBCONTENTS_STATE_SPARE_WEBCONTENTS;
    }
    RecordHistogram.recordEnumeratedHistogram("CustomTabs.WebcontentsStateOnLaunch",
            webContentsStateOnLaunch, WEBCONTENTS_STATE_MAX);
    if (webContents == null) webContents = WebContentsFactory.createWebContents(false, false);
    if (!mHasPrerendered) {
        customTabsConnection.resetPostMessageHandlerForSession(mSession, webContents);
    }
    tab.initialize(
            webContents, getTabContentManager(),
            new CustomTabDelegateFactory(
                    mIntentDataProvider.shouldEnableUrlBarHiding(),
                    mIntentDataProvider.isOpenedByChrome(),
                    getFullscreenManager().getBrowserVisibilityDelegate()),
            false, false);
    initializeMainTab(tab);
    return tab;
}