org.chromium.chrome.browser.tab.TabIdManager Java Examples

The following examples show how to use org.chromium.chrome.browser.tab.TabIdManager. 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: TabDelegate.java    From delion with Apache License 2.0 6 votes vote down vote up
private Intent createNewTabIntent(AsyncTabCreationParams asyncParams, int parentId) {
    int assignedTabId = TabIdManager.getInstance().generateValidId(Tab.INVALID_TAB_ID);
    AsyncTabParamsManager.add(assignedTabId, asyncParams);

    Intent intent = new Intent(
            Intent.ACTION_VIEW, Uri.parse(asyncParams.getLoadUrlParams().getUrl()));
    intent.setClass(ContextUtils.getApplicationContext(), ChromeLauncherActivity.class);
    intent.putExtra(IntentHandler.EXTRA_TAB_ID, assignedTabId);
    intent.putExtra(IntentHandler.EXTRA_OPEN_NEW_INCOGNITO_TAB, mIsIncognito);
    intent.putExtra(IntentHandler.EXTRA_PARENT_TAB_ID, parentId);

    Activity parentActivity = ActivityDelegate.getActivityForTabId(parentId);
    if (parentActivity != null && parentActivity.getIntent() != null) {
        intent.putExtra(IntentHandler.EXTRA_PARENT_INTENT, parentActivity.getIntent());
    }

    if (asyncParams.getRequestId() != null) {
        intent.putExtra(ServiceTabLauncher.LAUNCH_REQUEST_ID_EXTRA,
                asyncParams.getRequestId().intValue());
    }

    intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
    return intent;
}
 
Example #2
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 #3
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 #4
Source File: DocumentTabModelSelector.java    From delion with Apache License 2.0 4 votes vote down vote up
private void initializeTabIdCounter() {
    int biggestId = getLargestTaskIdFromRecents();
    biggestId = getMaxTabId(mRegularTabModel, biggestId);
    biggestId = getMaxTabId(mIncognitoTabModel, biggestId);
    TabIdManager.getInstance().incrementIdCounterTo(biggestId + 1);
}
 
Example #5
Source File: TabDelegate.java    From AndroidChromium with Apache License 2.0 4 votes vote down vote up
private Intent createNewTabIntent(
        AsyncTabCreationParams asyncParams, int parentId, boolean isChromeUI) {
    int assignedTabId = TabIdManager.getInstance().generateValidId(Tab.INVALID_TAB_ID);
    AsyncTabParamsManager.add(assignedTabId, asyncParams);

    Intent intent = new Intent(
            Intent.ACTION_VIEW, Uri.parse(asyncParams.getLoadUrlParams().getUrl()));

    ComponentName componentName = asyncParams.getComponentName();
    if (componentName == null) {
        intent.setClass(ContextUtils.getApplicationContext(), ChromeLauncherActivity.class);
    } else {
        intent.setComponent(componentName);
    }

    Map<String, String> extraHeaders = asyncParams.getLoadUrlParams().getExtraHeaders();
    if (extraHeaders != null && !extraHeaders.isEmpty()) {
        Bundle bundle = new Bundle();
        for (Map.Entry<String, String> header : extraHeaders.entrySet()) {
            bundle.putString(header.getKey(), header.getValue());
        }
        intent.putExtra(Browser.EXTRA_HEADERS, bundle);
    }

    intent.putExtra(IntentHandler.EXTRA_TAB_ID, assignedTabId);
    intent.putExtra(IntentHandler.EXTRA_OPEN_NEW_INCOGNITO_TAB, mIsIncognito);
    intent.putExtra(IntentHandler.EXTRA_PARENT_TAB_ID, parentId);

    if (isChromeUI) {
        intent.putExtra(Browser.EXTRA_APPLICATION_ID,
                ContextUtils.getApplicationContext().getPackageName());
        intent.putExtra(Browser.EXTRA_CREATE_NEW_TAB, true);
    }

    Activity parentActivity = ActivityDelegate.getActivityForTabId(parentId);
    if (parentActivity != null && parentActivity.getIntent() != null) {
        intent.putExtra(IntentHandler.EXTRA_PARENT_INTENT, parentActivity.getIntent());
    }

    if (asyncParams.getRequestId() != null) {
        intent.putExtra(ServiceTabLauncher.LAUNCH_REQUEST_ID_EXTRA,
                asyncParams.getRequestId().intValue());
    }

    intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
    return intent;
}
 
Example #6
Source File: DocumentTabModelSelector.java    From AndroidChromium with Apache License 2.0 4 votes vote down vote up
private void initializeTabIdCounter() {
    int biggestId = getLargestTaskIdFromRecents();
    biggestId = getMaxTabId(mRegularTabModel, biggestId);
    biggestId = getMaxTabId(mIncognitoTabModel, biggestId);
    TabIdManager.getInstance().incrementIdCounterTo(biggestId + 1);
}
 
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;
}
 
Example #8
Source File: TabDelegate.java    From 365browser with Apache License 2.0 4 votes vote down vote up
private Intent createNewTabIntent(
        AsyncTabCreationParams asyncParams, int parentId, boolean isChromeUI) {
    int assignedTabId = TabIdManager.getInstance().generateValidId(Tab.INVALID_TAB_ID);
    AsyncTabParamsManager.add(assignedTabId, asyncParams);

    Intent intent = new Intent(
            Intent.ACTION_VIEW, Uri.parse(asyncParams.getLoadUrlParams().getUrl()));

    ComponentName componentName = asyncParams.getComponentName();
    if (componentName == null) {
        intent.setClass(ContextUtils.getApplicationContext(), ChromeLauncherActivity.class);
    } else {
        intent.setComponent(componentName);
    }

    Map<String, String> extraHeaders = asyncParams.getLoadUrlParams().getExtraHeaders();
    if (extraHeaders != null && !extraHeaders.isEmpty()) {
        Bundle bundle = new Bundle();
        for (Map.Entry<String, String> header : extraHeaders.entrySet()) {
            bundle.putString(header.getKey(), header.getValue());
        }
        intent.putExtra(Browser.EXTRA_HEADERS, bundle);
    }

    intent.putExtra(IntentHandler.EXTRA_TAB_ID, assignedTabId);
    intent.putExtra(IntentHandler.EXTRA_OPEN_NEW_INCOGNITO_TAB, mIsIncognito);
    intent.putExtra(IntentHandler.EXTRA_PARENT_TAB_ID, parentId);

    if (mIsIncognito || isChromeUI) {
        intent.putExtra(Browser.EXTRA_APPLICATION_ID,
                ContextUtils.getApplicationContext().getPackageName());
    }

    if (isChromeUI) intent.putExtra(Browser.EXTRA_CREATE_NEW_TAB, true);

    Activity parentActivity = ActivityDelegate.getActivityForTabId(parentId);
    if (parentActivity != null && parentActivity.getIntent() != null) {
        intent.putExtra(IntentHandler.EXTRA_PARENT_INTENT, parentActivity.getIntent());
    }

    if (asyncParams.getRequestId() != null) {
        intent.putExtra(ServiceTabLauncher.LAUNCH_REQUEST_ID_EXTRA,
                asyncParams.getRequestId().intValue());
    }

    intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
    return intent;
}
 
Example #9
Source File: DocumentTabModelSelector.java    From 365browser with Apache License 2.0 4 votes vote down vote up
private void initializeTabIdCounter() {
    int biggestId = getLargestTaskIdFromRecents();
    biggestId = getMaxTabId(mRegularTabModel, biggestId);
    biggestId = getMaxTabId(mIncognitoTabModel, biggestId);
    TabIdManager.getInstance().incrementIdCounterTo(biggestId + 1);
}