Java Code Examples for org.chromium.chrome.browser.tabmodel.TabModel.TabLaunchType#FROM_EXTERNAL_APP

The following examples show how to use org.chromium.chrome.browser.tabmodel.TabModel.TabLaunchType#FROM_EXTERNAL_APP . 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: 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 2
Source File: InterceptNavigationDelegateImpl.java    From delion with Apache License 2.0 5 votes vote down vote up
/**
 * Called when Chrome decides to override URL loading and show an intent picker.
 */
private void onOverrideUrlLoadingAndLaunchIntent() {
    if (mTab.getWebContents() == null) return;

    // Before leaving Chrome, close the empty child tab.
    // If a new tab is created through JavaScript open to load this
    // url, we would like to close it as we will load this url in a
    // different Activity.
    if (shouldCloseContentsOnOverrideUrlLoadingAndLaunchIntent()) {
        if (mTab.getLaunchType() == TabLaunchType.FROM_EXTERNAL_APP) {
            // Moving task back before closing the tab allows back button to function better
            // when Chrome was an intermediate link redirector between two apps.
            // crbug.com/487938.
            mTab.getActivity().moveTaskToBack(true);
        }
        mTab.getTabModelSelector().closeTab(mTab);
    } else if (mTab.getTabRedirectHandler().isOnNavigation()) {
        int lastCommittedEntryIndexBeforeNavigation = mTab.getTabRedirectHandler()
                .getLastCommittedEntryIndexBeforeStartingNavigation();
        if (getLastCommittedEntryIndex() > lastCommittedEntryIndexBeforeNavigation) {
            // http://crbug/426679 : we want to go back to the last committed entry index which
            // was saved before this navigation, and remove the empty entries from the
            // navigation history.
            mClearAllForwardHistoryRequired = true;
            mTab.getWebContents().getNavigationController().goToNavigationIndex(
                    lastCommittedEntryIndexBeforeNavigation);
        }
    }
}
 
Example 3
Source File: LayoutManagerChrome.java    From AndroidChromium with Apache License 2.0 5 votes vote down vote up
@Override
public void willAddTab(Tab tab, TabLaunchType type) {
    // Open the new tab
    if (type == TabLaunchType.FROM_RESTORE) return;
    if (type == TabLaunchType.FROM_REPARENTING) return;
    if (type == TabLaunchType.FROM_EXTERNAL_APP) return;

    tabCreating(getTabModelSelector().getCurrentTabId(), tab.getUrl(), tab.isIncognito());
}
 
Example 4
Source File: InterceptNavigationDelegateImpl.java    From AndroidChromium with Apache License 2.0 5 votes vote down vote up
/**
 * Called when Chrome decides to override URL loading and show an intent picker.
 */
private void onOverrideUrlLoadingAndLaunchIntent() {
    if (mTab.getWebContents() == null) return;

    // Before leaving Chrome, close the empty child tab.
    // If a new tab is created through JavaScript open to load this
    // url, we would like to close it as we will load this url in a
    // different Activity.
    if (shouldCloseContentsOnOverrideUrlLoadingAndLaunchIntent()) {
        if (mTab.getLaunchType() == TabLaunchType.FROM_EXTERNAL_APP) {
            // Moving task back before closing the tab allows back button to function better
            // when Chrome was an intermediate link redirector between two apps.
            // crbug.com/487938.
            mTab.getActivity().moveTaskToBack(false);
        }
        mTab.getTabModelSelector().closeTab(mTab);
    } else if (mTab.getTabRedirectHandler().isOnNavigation()) {
        int lastCommittedEntryIndexBeforeNavigation = mTab.getTabRedirectHandler()
                .getLastCommittedEntryIndexBeforeStartingNavigation();
        if (getLastCommittedEntryIndex() > lastCommittedEntryIndexBeforeNavigation) {
            // http://crbug/426679 : we want to go back to the last committed entry index which
            // was saved before this navigation, and remove the empty entries from the
            // navigation history.
            mClearAllForwardHistoryRequired = true;
            mTab.getWebContents().getNavigationController().goToNavigationIndex(
                    lastCommittedEntryIndexBeforeNavigation);
        }
    }
}
 
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: LayoutManagerChrome.java    From 365browser with Apache License 2.0 5 votes vote down vote up
@Override
public void willAddTab(Tab tab, TabLaunchType type) {
    // Open the new tab
    if (type == TabLaunchType.FROM_RESTORE) return;
    if (type == TabLaunchType.FROM_REPARENTING) return;
    if (type == TabLaunchType.FROM_EXTERNAL_APP) return;
    if (type == TabLaunchType.FROM_LAUNCHER_SHORTCUT) return;

    tabCreating(getTabModelSelector().getCurrentTabId(), tab.getUrl(), tab.isIncognito());
}
 
Example 7
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 8
Source File: InterceptNavigationDelegateImpl.java    From 365browser with Apache License 2.0 5 votes vote down vote up
/**
 * Called when Chrome decides to override URL loading and show an intent picker.
 */
private void onOverrideUrlLoadingAndLaunchIntent() {
    if (mTab.getWebContents() == null) return;

    // Before leaving Chrome, close the empty child tab.
    // If a new tab is created through JavaScript open to load this
    // url, we would like to close it as we will load this url in a
    // different Activity.
    if (shouldCloseContentsOnOverrideUrlLoadingAndLaunchIntent()) {
        if (mTab.getLaunchType() == TabLaunchType.FROM_EXTERNAL_APP) {
            // Moving task back before closing the tab allows back button to function better
            // when Chrome was an intermediate link redirector between two apps.
            // crbug.com/487938.
            mTab.getActivity().moveTaskToBack(false);
        }
        mTab.getTabModelSelector().closeTab(mTab);
    } else if (mTab.getTabRedirectHandler().isOnNavigation()) {
        int lastCommittedEntryIndexBeforeNavigation = mTab.getTabRedirectHandler()
                .getLastCommittedEntryIndexBeforeStartingNavigation();
        if (getLastCommittedEntryIndex() > lastCommittedEntryIndexBeforeNavigation) {
            // http://crbug/426679 : we want to go back to the last committed entry index which
            // was saved before this navigation, and remove the empty entries from the
            // navigation history.
            mClearAllForwardHistoryRequired = true;
            mTab.getWebContents().getNavigationController().goToNavigationIndex(
                    lastCommittedEntryIndexBeforeNavigation);
        }
    }
}
 
Example 9
Source File: TabModelSelectorImpl.java    From delion with Apache License 2.0 4 votes vote down vote up
@Override
public void requestToShowTab(Tab tab, TabSelectionType type) {
    boolean isFromExternalApp = tab != null
            && tab.getLaunchType() == TabLaunchType.FROM_EXTERNAL_APP;

    if (mVisibleTab != tab && tab != null && !tab.isNativePage()) {
        TabModelImpl.startTabSwitchLatencyTiming(type);
    }
    if (mVisibleTab != null && mVisibleTab != tab && !mVisibleTab.needsReload()) {
        if (mVisibleTab.isInitialized() && !mVisibleTab.isDetachedForReparenting()) {
            // TODO(dtrainor): Once we figure out why we can't grab a snapshot from the current
            // tab when we have other tabs loading from external apps remove the checks for
            // FROM_EXTERNAL_APP/FROM_NEW.
            if (!mVisibleTab.isClosing()
                    && (!isFromExternalApp || type != TabSelectionType.FROM_NEW)) {
                cacheTabBitmap(mVisibleTab);
            }
            mVisibleTab.hide();
            mVisibleTab.setFullscreenManager(null);
            mTabSaver.addTabToSaveQueue(mVisibleTab);
        }
        mVisibleTab = null;
    }

    if (tab == null) {
        notifyChanged();
        return;
    }

    // We hit this case when the user enters tab switcher and comes back to the current tab
    // without actual tab switch.
    if (mVisibleTab == tab && !mVisibleTab.isHidden()) {
        // The current tab might have been killed by the os while in tab switcher.
        tab.loadIfNeeded();
        return;
    }

    tab.setFullscreenManager(mActivity.getFullscreenManager());
    mVisibleTab = tab;

    // Don't execute the tab display part if Chrome has just been sent to background. This
    // avoids uneccessary work (tab restore) and prevents pollution of tab display metrics - see
    // http://crbug.com/316166.
    if (type != TabSelectionType.FROM_EXIT) {
        tab.show(type);
        mUma.onShowTab(tab.getId(), tab.isBeingRestored());
    }
}
 
Example 10
Source File: Tab.java    From delion with Apache License 2.0 4 votes vote down vote up
/**
 * @return Whether or not the tab was opened by an app other than Chrome.
 */
public boolean isCreatedForExternalApp() {
    String packageName = ContextUtils.getApplicationContext().getPackageName();
    return getLaunchType() == TabLaunchType.FROM_EXTERNAL_APP
            && !TextUtils.equals(getAppAssociatedWith(), packageName);
}
 
Example 11
Source File: TabModelSelectorImpl.java    From AndroidChromium with Apache License 2.0 4 votes vote down vote up
@Override
public void requestToShowTab(Tab tab, TabSelectionType type) {
    boolean isFromExternalApp = tab != null
            && tab.getLaunchType() == TabLaunchType.FROM_EXTERNAL_APP;

    if (mVisibleTab != tab && tab != null && !tab.isNativePage()) {
        TabModelImpl.startTabSwitchLatencyTiming(type);
    }
    if (mVisibleTab != null && mVisibleTab != tab && !mVisibleTab.needsReload()) {
        if (mVisibleTab.isInitialized() && !mVisibleTab.isDetachedForReparenting()) {
            // TODO(dtrainor): Once we figure out why we can't grab a snapshot from the current
            // tab when we have other tabs loading from external apps remove the checks for
            // FROM_EXTERNAL_APP/FROM_NEW.
            if (!mVisibleTab.isClosing()
                    && (!isFromExternalApp || type != TabSelectionType.FROM_NEW)) {
                cacheTabBitmap(mVisibleTab);
            }
            mVisibleTab.hide();
            mTabSaver.addTabToSaveQueue(mVisibleTab);
        }
        mVisibleTab = null;
    }

    if (tab == null) {
        notifyChanged();
        return;
    }

    // We hit this case when the user enters tab switcher and comes back to the current tab
    // without actual tab switch.
    if (mVisibleTab == tab && !mVisibleTab.isHidden()) {
        // The current tab might have been killed by the os while in tab switcher.
        tab.loadIfNeeded();
        return;
    }
    mVisibleTab = tab;

    // Don't execute the tab display part if Chrome has just been sent to background. This
    // avoids uneccessary work (tab restore) and prevents pollution of tab display metrics - see
    // http://crbug.com/316166.
    if (type != TabSelectionType.FROM_EXIT) {
        tab.show(type);
        mUma.onShowTab(tab.getId(), tab.isBeingRestored());
    }
}
 
Example 12
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;
}
 
Example 13
Source File: Tab.java    From AndroidChromium with Apache License 2.0 4 votes vote down vote up
/**
 * @return Whether or not the tab was opened by an app other than Chrome.
 */
public boolean isCreatedForExternalApp() {
    String packageName = ContextUtils.getApplicationContext().getPackageName();
    return getLaunchType() == TabLaunchType.FROM_EXTERNAL_APP
            && !TextUtils.equals(getAppAssociatedWith(), packageName);
}
 
Example 14
Source File: TabModelSelectorImpl.java    From 365browser with Apache License 2.0 4 votes vote down vote up
@Override
public void requestToShowTab(Tab tab, TabSelectionType type) {
    boolean isFromExternalApp = tab != null
            && tab.getLaunchType() == TabLaunchType.FROM_EXTERNAL_APP;

    if (mVisibleTab != tab && tab != null && !tab.isNativePage()) {
        TabModelImpl.startTabSwitchLatencyTiming(type);
    }
    if (mVisibleTab != null && mVisibleTab != tab && !mVisibleTab.needsReload()) {
        if (mVisibleTab.isInitialized() && !mVisibleTab.isDetached()) {
            // TODO(dtrainor): Once we figure out why we can't grab a snapshot from the current
            // tab when we have other tabs loading from external apps remove the checks for
            // FROM_EXTERNAL_APP/FROM_NEW.
            if (!mVisibleTab.isClosing()
                    && (!isFromExternalApp || type != TabSelectionType.FROM_NEW)) {
                cacheTabBitmap(mVisibleTab);
            }
            mVisibleTab.hide();
            mTabSaver.addTabToSaveQueue(mVisibleTab);
        }
        mVisibleTab = null;
    }

    if (tab == null) {
        notifyChanged();
        return;
    }

    // We hit this case when the user enters tab switcher and comes back to the current tab
    // without actual tab switch.
    if (mVisibleTab == tab && !mVisibleTab.isHidden()) {
        // The current tab might have been killed by the os while in tab switcher.
        tab.loadIfNeeded();
        return;
    }
    mVisibleTab = tab;

    // Don't execute the tab display part if Chrome has just been sent to background. This
    // avoids uneccessary work (tab restore) and prevents pollution of tab display metrics - see
    // http://crbug.com/316166.
    if (type != TabSelectionType.FROM_EXIT) {
        tab.show(type);
        mUma.onShowTab(tab.getId(), tab.isBeingRestored());
    }
}
 
Example 15
Source File: Tab.java    From 365browser with Apache License 2.0 4 votes vote down vote up
/**
 * @return Whether or not the tab was opened by an app other than Chrome.
 */
public boolean isCreatedForExternalApp() {
    String packageName = ContextUtils.getApplicationContext().getPackageName();
    return getLaunchType() == TabLaunchType.FROM_EXTERNAL_APP
            && !TextUtils.equals(getAppAssociatedWith(), packageName);
}