org.chromium.chrome.browser.tabmodel.TabModel.TabLaunchType Java Examples

The following examples show how to use org.chromium.chrome.browser.tabmodel.TabModel.TabLaunchType. 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: ChromeActionModeCallback.java    From AndroidChromium with Apache License 2.0 6 votes vote down vote up
private void search() {
    RecordUserAction.record("MobileActionMode.WebSearch");
    if (mTab.getTabModelSelector() == null) return;

    String query = mHelper.sanitizeQuery(mHelper.getSelectedText(),
            ActionModeCallbackHelper.MAX_SEARCH_QUERY_LENGTH);
    if (TextUtils.isEmpty(query)) return;

    String url = TemplateUrlService.getInstance().getUrlForSearchQuery(query);
    String headers = GeolocationHeader.getGeoHeader(mContext.getApplicationContext(),
            url, mTab.isIncognito());

    LoadUrlParams loadUrlParams = new LoadUrlParams(url);
    loadUrlParams.setVerbatimHeaders(headers);
    loadUrlParams.setTransitionType(PageTransition.GENERATED);
    mTab.getTabModelSelector().openNewTab(loadUrlParams,
            TabLaunchType.FROM_LONGPRESS_FOREGROUND, mTab, mTab.isIncognito());
}
 
Example #2
Source File: ChromeActionModeCallback.java    From 365browser with Apache License 2.0 6 votes vote down vote up
private void search() {
    RecordUserAction.record("MobileActionMode.WebSearch");
    if (mTab.getTabModelSelector() == null) return;

    String query = ActionModeCallbackHelper.sanitizeQuery(mHelper.getSelectedText(),
            ActionModeCallbackHelper.MAX_SEARCH_QUERY_LENGTH);
    if (TextUtils.isEmpty(query)) return;

    String url = TemplateUrlService.getInstance().getUrlForSearchQuery(query);
    String headers = GeolocationHeader.getGeoHeader(url, mTab);

    LoadUrlParams loadUrlParams = new LoadUrlParams(url);
    loadUrlParams.setVerbatimHeaders(headers);
    loadUrlParams.setTransitionType(PageTransition.GENERATED);
    mTab.getTabModelSelector().openNewTab(loadUrlParams,
            TabLaunchType.FROM_LONGPRESS_FOREGROUND, mTab, mTab.isIncognito());
}
 
Example #3
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 #4
Source File: ChromeTabCreator.java    From AndroidChromium with Apache License 2.0 6 votes vote down vote up
/**
 * @param type Type of the tab launch.
 * @param intent The intent causing the tab launch.
 * @return The page transition type constant.
 */
private int getTransitionType(TabLaunchType type, Intent intent) {
    int transition = PageTransition.LINK;
    switch (type) {
        case FROM_RESTORE:
        case FROM_LINK:
        case FROM_EXTERNAL_APP:
            transition = PageTransition.LINK | PageTransition.FROM_API;
            break;
        case FROM_CHROME_UI:
        case FROM_LONGPRESS_FOREGROUND:
        case FROM_LONGPRESS_BACKGROUND:
            transition = PageTransition.AUTO_TOPLEVEL;
            break;
        default:
            assert false;
            break;
    }

    return IntentHandler.getTransitionTypeFromIntent(mActivity.getApplicationContext(),
            intent, transition);
}
 
Example #5
Source File: CustomTabDelegateFactory.java    From 365browser with Apache License 2.0 6 votes vote down vote up
@Override
public void openNewTab(String url, String extraHeaders, ResourceRequestBody postData,
        int disposition, boolean isRendererInitiated) {
    // If attempting to open an incognito tab, always send the user to tabbed mode.
    if (disposition == WindowOpenDisposition.OFF_THE_RECORD) {
        if (isRendererInitiated) {
            throw new IllegalStateException(
                    "Invalid attempt to open an incognito tab from the renderer");
        }
        LoadUrlParams loadUrlParams = new LoadUrlParams(url);
        loadUrlParams.setVerbatimHeaders(extraHeaders);
        loadUrlParams.setPostData(postData);
        loadUrlParams.setIsRendererInitiated(isRendererInitiated);

        Class<? extends ChromeTabbedActivity> tabbedClass =
                MultiWindowUtils.getInstance().getTabbedActivityForIntent(
                        null, ContextUtils.getApplicationContext());
        AsyncTabCreationParams tabParams = new AsyncTabCreationParams(loadUrlParams,
                new ComponentName(ContextUtils.getApplicationContext(), tabbedClass));
        new TabDelegate(true).createNewTab(tabParams,
                TabLaunchType.FROM_LONGPRESS_FOREGROUND, TabModel.INVALID_TAB_INDEX);
        return;
    }

    super.openNewTab(url, extraHeaders, postData, disposition, isRendererInitiated);
}
 
Example #6
Source File: TabModelOrderController.java    From 365browser with Apache License 2.0 5 votes vote down vote up
/**
 * Determine the insertion index of the next tab.
 *
 * @param type The launch type of the new tab.
 * @return Where to insert the tab.
 */
public int determineInsertionIndex(TabLaunchType type, Tab newTab) {
    TabModel currentModel = mTabModelSelector.getCurrentModel();
    Tab currentTab = TabModelUtils.getCurrentTab(currentModel);
    if (currentTab == null) {
        assert (currentModel.getCount() == 0);
        return 0;
    }
    int currentId = currentTab.getId();
    int currentIndex = TabModelUtils.getTabIndexById(currentModel, currentId);

    if (sameModelType(currentModel, newTab)) {
        if (willOpenInForeground(type, newTab.isIncognito())) {
            // If the tab was opened in the foreground, insert it adjacent to
            // the tab that opened that link.
            return currentIndex + 1;
        } else {
            // If the tab was opened in the background, position at the end of
            // it's 'group'.
            int index = getIndexOfLastTabOpenedBy(currentId, currentIndex);
            if (index != NO_TAB) {
                return index + 1;
            } else {
                return currentIndex + 1;
            }
        }
    } else {
        // If the tab is opening in the other model type, just put it at the end.
        return mTabModelSelector.getModel(newTab.isIncognito()).getCount();
    }
}
 
Example #7
Source File: ContextualSearchManager.java    From 365browser with Apache License 2.0 5 votes vote down vote up
@Override
public void openResolvedSearchUrlInNewTab() {
    if (mSearchRequest != null && mSearchRequest.getSearchUrlForPromotion() != null) {
        TabModelSelector tabModelSelector = mActivity.getTabModelSelector();
        tabModelSelector.openNewTab(
                new LoadUrlParams(mSearchRequest.getSearchUrlForPromotion()),
                TabLaunchType.FROM_LINK,
                tabModelSelector.getCurrentTab(),
                tabModelSelector.isIncognitoSelected());
    }
}
 
Example #8
Source File: TabCreatorManager.java    From delion with Apache License 2.0 5 votes vote down vote up
/**
 * Creates a new tab and loads the NTP.
 */
public final void launchNTP() {
    try {
        TraceEvent.begin("TabCreator.launchNTP");
        launchUrl(UrlConstants.NTP_URL, TabModel.TabLaunchType.FROM_CHROME_UI);
    } finally {
        TraceEvent.end("TabCreator.launchNTP");
    }
}
 
Example #9
Source File: TabModelOrderController.java    From delion with Apache License 2.0 5 votes vote down vote up
/**
 * Determine the insertion index of the next tab. If it's not the result of
 * a link being pressed, the provided index will be returned.
 *
 * @param type The launch type of the new tab.
 * @param position The provided position.
 * @return Where to insert the tab.
 */
public int determineInsertionIndex(TabLaunchType type, int position, Tab newTab) {
    if (linkClicked(type)) {
        position = determineInsertionIndex(type, newTab);
    }

    if (willOpenInForeground(type, newTab.isIncognito())) {
        // Forget any existing relationships, we don't want to make things
        // too confusing by having multiple groups active at the same time.
        forgetAllOpeners();
    }

    return position;
}
 
Example #10
Source File: CustomTabLayoutManager.java    From AndroidChromium with Apache License 2.0 5 votes vote down vote up
@Override
public void didAddTab(Tab tab, TabLaunchType type) {
    if (type == TabLaunchType.FROM_RESTORE) {
        getActiveLayout().onTabRestored(time(), tab.getId());
    } else {
        int newIndex = TabModelUtils.getTabIndexById(getTabModelSelector().getModel(false),
                tab.getId());
        getActiveLayout().onTabCreated(time(), tab.getId(), newIndex,
                getTabModelSelector().getCurrentTabId(), false, false, 0f, 0f);
    }
}
 
Example #11
Source File: TabModelOrderController.java    From AndroidChromium with Apache License 2.0 5 votes vote down vote up
/**
 * Determine the insertion index of the next tab.
 *
 * @param type The launch type of the new tab.
 * @return Where to insert the tab.
 */
public int determineInsertionIndex(TabLaunchType type, Tab newTab) {
    TabModel currentModel = mTabModelSelector.getCurrentModel();
    Tab currentTab = TabModelUtils.getCurrentTab(currentModel);
    if (currentTab == null) {
        assert (currentModel.getCount() == 0);
        return 0;
    }
    int currentId = currentTab.getId();
    int currentIndex = TabModelUtils.getTabIndexById(currentModel, currentId);

    if (sameModelType(currentModel, newTab)) {
        if (willOpenInForeground(type, newTab.isIncognito())) {
            // If the tab was opened in the foreground, insert it adjacent to
            // the tab that opened that link.
            return currentIndex + 1;
        } else {
            // If the tab was opened in the background, position at the end of
            // it's 'group'.
            int index = getIndexOfLastTabOpenedBy(currentId, currentIndex);
            if (index != NO_TAB) {
                return index + 1;
            } else {
                return currentIndex + 1;
            }
        }
    } else {
        // If the tab is opening in the other model type, just put it at the end.
        return mTabModelSelector.getModel(newTab.isIncognito()).getCount();
    }
}
 
Example #12
Source File: TabDelegate.java    From delion with Apache License 2.0 5 votes vote down vote up
@Override
public boolean createTabWithWebContents(Tab parent, WebContents webContents, int parentId,
        TabLaunchType type, String url) {
    if (url == null) url = "";

    AsyncTabCreationParams asyncParams =
            new AsyncTabCreationParams(
                    new LoadUrlParams(url, PageTransition.AUTO_TOPLEVEL), webContents);
    createNewTab(asyncParams, type, parentId);
    return true;
}
 
Example #13
Source File: OfflinePageDownloadBridge.java    From 365browser with Apache License 2.0 5 votes vote down vote up
/**
 * 'Opens' the offline page identified by the GUID.
 * This is done by creating a new tab and navigating it to the saved local snapshot.
 * No automatic redirection is happening based on the connection status.
 * If the item with specified GUID is not found or can't be opened, nothing happens.
 * @param guid          GUID of the item to open.
 * @param componentName If specified, targets a specific Activity to open the offline page in.
 */
@Override
public void openItem(String guid, @Nullable ComponentName componentName) {
    OfflinePageDownloadItem item = getItem(guid);
    if (item == null) return;

    LoadUrlParams params = OfflinePageUtils.getLoadUrlParamsForOpeningOfflineVersion(
            item.getUrl(), nativeGetOfflineIdByGuid(mNativeOfflinePageDownloadBridge, guid));
    AsyncTabCreationParams asyncParams = componentName == null
            ? new AsyncTabCreationParams(params)
            : new AsyncTabCreationParams(params, componentName);
    final TabDelegate tabDelegate = new TabDelegate(false);
    tabDelegate.createNewTab(asyncParams, TabLaunchType.FROM_CHROME_UI, Tab.INVALID_TAB_ID);
}
 
Example #14
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 #15
Source File: ChromeTabbedActivity.java    From 365browser with Apache License 2.0 5 votes vote down vote up
/**
 * Launch a URL from an intent.
 *
 * @param url           The url from the intent.
 * @param referer       Optional referer URL to be used.
 * @param headers       Optional headers to be sent when opening the URL.
 * @param externalAppId External app id.
 * @param forceNewTab   Whether to force the URL to be launched in a new tab or to fall
 *                      back to the default behavior for making that determination.
 * @param intent        The original intent.
 */
private Tab launchIntent(String url, String referer, String headers,
        String externalAppId, boolean forceNewTab, Intent intent) {
    if (mUIInitialized) {
        mLayoutManager.hideOverview(false);
        getToolbarManager().finishAnimations();
    }
    if (TextUtils.equals(externalAppId, getPackageName())) {
        // If the intent was launched by chrome, open the new tab in the appropriate model.
        // Using FROM_LINK ensures the tab is parented to the current tab, which allows
        // the back button to close these tabs and restore selection to the previous tab.
        boolean isIncognito = IntentUtils.safeGetBooleanExtra(intent,
                IntentHandler.EXTRA_OPEN_NEW_INCOGNITO_TAB, false);
        boolean fromLauncherShortcut = IntentUtils.safeGetBooleanExtra(
                intent, IntentHandler.EXTRA_INVOKED_FROM_SHORTCUT, false);
        LoadUrlParams loadUrlParams = new LoadUrlParams(url);
        loadUrlParams.setIntentReceivedTimestamp(mIntentHandlingTimeMs);
        loadUrlParams.setVerbatimHeaders(headers);
        return getTabCreator(isIncognito).createNewTab(
                loadUrlParams,
                fromLauncherShortcut ? TabLaunchType.FROM_LAUNCHER_SHORTCUT
                        : TabLaunchType.FROM_LINK,
                null,
                intent);
    } else {
        return getTabCreator(false).launchUrlFromExternalApp(url, referer, headers,
                externalAppId, forceNewTab, intent, mIntentHandlingTimeMs);
    }
}
 
Example #16
Source File: DocumentTabModelSelector.java    From delion with Apache License 2.0 5 votes vote down vote up
@Override
public Tab openNewTab(LoadUrlParams loadUrlParams, TabLaunchType type, Tab parent,
        boolean incognito) {
    TabDelegate delegate = getTabCreator(incognito);
    delegate.createNewTab(loadUrlParams, type, parent);
    return null;
}
 
Example #17
Source File: SingleTabModelSelector.java    From delion with Apache License 2.0 5 votes vote down vote up
@Override
public Tab openNewTab(LoadUrlParams loadUrlParams, TabLaunchType type, Tab parent,
        boolean incognito) {
    Intent intent = new Intent(Intent.ACTION_VIEW, Uri.parse(loadUrlParams.getUrl()));
    intent.setPackage(mApplicationContext.getPackageName());
    intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
    mApplicationContext.startActivity(intent);
    return null;
}
 
Example #18
Source File: SingleTabModelSelector.java    From 365browser with Apache License 2.0 5 votes vote down vote up
@Override
public Tab openNewTab(LoadUrlParams loadUrlParams, TabLaunchType type, Tab parent,
        boolean incognito) {
    Intent intent = new Intent(Intent.ACTION_VIEW, Uri.parse(loadUrlParams.getUrl()));
    intent.setPackage(mApplicationContext.getPackageName());
    intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
    mApplicationContext.startActivity(intent);
    return null;
}
 
Example #19
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 #20
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 #21
Source File: BookmarkActionBar.java    From AndroidChromium with Apache License 2.0 5 votes vote down vote up
private static void openBookmarksInNewTabs(
        List<BookmarkId> bookmarks, TabDelegate tabDelegate, BookmarkModel model) {
    for (BookmarkId id : bookmarks) {
        tabDelegate.createNewTab(new LoadUrlParams(model.getBookmarkById(id).getUrl()),
                TabLaunchType.FROM_LONGPRESS_BACKGROUND, null);
    }
}
 
Example #22
Source File: TabContextMenuItemDelegate.java    From delion with Apache License 2.0 5 votes vote down vote up
@Override
public void onOpenInNewTab(String url, Referrer referrer) {
    RecordUserAction.record("MobileNewTabOpened");
    LoadUrlParams loadUrlParams = new LoadUrlParams(url);
    loadUrlParams.setReferrer(referrer);
    Tab newTab = mTab.getTabModelSelector().openNewTab(
            loadUrlParams, TabLaunchType.FROM_LONGPRESS_BACKGROUND, mTab, isIncognito());

    // {@code newTab} is null in document mode. Do not record metrics for document mode.
    if (mTab.getTabUma() != null && newTab != null) {
        mTab.getTabUma().onBackgroundTabOpenedFromContextMenu(newTab);
    }
}
 
Example #23
Source File: TabModelOrderController.java    From 365browser with Apache License 2.0 5 votes vote down vote up
/**
 * Determine the insertion index of the next tab. If it's not the result of
 * a link being pressed, the provided index will be returned.
 *
 * @param type The launch type of the new tab.
 * @param position The provided position.
 * @return Where to insert the tab.
 */
public int determineInsertionIndex(TabLaunchType type, int position, Tab newTab) {
    if (linkClicked(type)) {
        position = determineInsertionIndex(type, newTab);
    }

    if (willOpenInForeground(type, newTab.isIncognito())) {
        // Forget any existing relationships, we don't want to make things
        // too confusing by having multiple groups active at the same time.
        forgetAllOpeners();
    }

    return position;
}
 
Example #24
Source File: CustomTabLayoutManager.java    From 365browser with Apache License 2.0 5 votes vote down vote up
@Override
public void didAddTab(Tab tab, TabLaunchType type) {
    if (type == TabLaunchType.FROM_RESTORE) {
        getActiveLayout().onTabRestored(time(), tab.getId());
    } else {
        int newIndex = TabModelUtils.getTabIndexById(getTabModelSelector().getModel(false),
                tab.getId());
        getActiveLayout().onTabCreated(time(), tab.getId(), newIndex,
                getTabModelSelector().getCurrentTabId(), false, false, 0f, 0f);
    }
}
 
Example #25
Source File: MainIntentBehaviorMetrics.java    From 365browser with Apache License 2.0 5 votes vote down vote up
/**
 * Signal that an intent with ACTION_MAIN was received.
 *
 * This must only be called after the native libraries have been initialized.
 */
@SuppressFBWarnings("ST_WRITE_TO_STATIC_FROM_INSTANCE_METHOD")
public void onMainIntentWithNative(long backgroundDurationMs) {
    sLastMainIntentBehavior = null;

    RecordUserAction.record("MobileStartup.MainIntentReceived");

    if (backgroundDurationMs >= BACKGROUND_TIME_24_HOUR_MS) {
        RecordUserAction.record("MobileStartup.MainIntentReceived.After24Hours");
    } else if (backgroundDurationMs >= BACKGROUND_TIME_12_HOUR_MS) {
        RecordUserAction.record("MobileStartup.MainIntentReceived.After12Hours");
    } else if (backgroundDurationMs >= BACKGROUND_TIME_6_HOUR_MS) {
        RecordUserAction.record("MobileStartup.MainIntentReceived.After6Hours");
    } else if (backgroundDurationMs >= BACKGROUND_TIME_1_HOUR_MS) {
        RecordUserAction.record("MobileStartup.MainIntentReceived.After1Hour");
    }

    if (mPendingActionRecordForMainIntent) return;
    mBackgroundDurationMs = backgroundDurationMs;

    ApplicationStatus.registerStateListenerForActivity(this, mActivity);
    mPendingActionRecordForMainIntent = true;

    mHandler.postDelayed(mTimeoutRunnable, sTimeoutDurationMs);

    mTabModelObserver = new TabModelSelectorTabModelObserver(
            mActivity.getTabModelSelector()) {
        @Override
        public void didAddTab(Tab tab, TabLaunchType type) {
            if (TabLaunchType.FROM_RESTORE.equals(type)) return;
            if (NewTabPage.isNTPUrl(tab.getUrl())) recordUserBehavior(NTP_CREATED);
        }

        @Override
        public void didSelectTab(Tab tab, TabSelectionType type, int lastId) {
            recordUserBehavior(SWITCH_TABS);
        }
    };
}
 
Example #26
Source File: OtherFormsOfHistoryDialogFragment.java    From delion with Apache License 2.0 5 votes vote down vote up
@Override
public Dialog onCreateDialog(Bundle savedInstanceState) {
    super.onCreateDialog(savedInstanceState);
    LayoutInflater inflater = getActivity().getLayoutInflater();
    View view = inflater.inflate(R.layout.other_forms_of_history_dialog, null);

    // Linkify the <link></link> span in the dialog text.
    TextView textView = (TextView) view.findViewById(R.id.text);
    final SpannableString textWithLink = SpanApplier.applySpans(
            textView.getText().toString(),
            new SpanApplier.SpanInfo("<link>", "</link>", new NoUnderlineClickableSpan() {
                @Override
                public void onClick(View widget) {
                    new TabDelegate(false /* incognito */).launchUrl(
                            WEB_HISTORY_URL, TabLaunchType.FROM_CHROME_UI);
                }
            }));

    textView.setText(textWithLink);
    textView.setMovementMethod(LinkMovementMethod.getInstance());

    // Construct the dialog.
    AlertDialog dialog = new AlertDialog.Builder(getActivity(), R.style.AlertDialogTheme)
            .setView(view)
            .setTitle(R.string.clear_browsing_data_history_dialog_title)
            .setPositiveButton(
                    R.string.ok_got_it, this)
            .create();

    dialog.setCanceledOnTouchOutside(false);
    return dialog;
}
 
Example #27
Source File: Tab.java    From delion with Apache License 2.0 5 votes vote down vote up
/**
 * Creates a fresh tab. initialize() needs to be called afterwards to complete the second level
 * initialization.
 * @param initiallyHidden true iff the tab being created is initially in background
 */
public static Tab createLiveTab(int id, ChromeActivity activity, boolean incognito,
        WindowAndroid nativeWindow, TabLaunchType type, int parentId, boolean initiallyHidden) {
    return new Tab(id, parentId, incognito, activity, nativeWindow, type, initiallyHidden
            ? TabCreationState.LIVE_IN_BACKGROUND
            : TabCreationState.LIVE_IN_FOREGROUND, null);
}
 
Example #28
Source File: FullScreenActivity.java    From delion with Apache License 2.0 5 votes vote down vote up
@Override
public void preInflationStartup() {
    super.preInflationStartup();

    setTabCreators(createTabDelegate(false), createTabDelegate(true));
    setTabModelSelector(new SingleTabModelSelector(this, false, false) {
        @Override
        public Tab openNewTab(LoadUrlParams loadUrlParams, TabLaunchType type, Tab parent,
                boolean incognito) {
            getTabCreator(incognito).createNewTab(loadUrlParams, type, parent);
            return null;
        }
    });
}
 
Example #29
Source File: LayoutManagerChromePhone.java    From 365browser with Apache License 2.0 5 votes vote down vote up
@Override
protected void tabCreated(int id, int sourceId, TabLaunchType launchType, boolean isIncognito,
        boolean willBeSelected, float originX, float originY) {
    super.tabCreated(id, sourceId, launchType, isIncognito, willBeSelected, originX, originY);

    if (willBeSelected) {
        Tab newTab = TabModelUtils.getTabById(getTabModelSelector().getModel(isIncognito), id);
        if (newTab != null) newTab.requestFocus();
    }
}
 
Example #30
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);
        }
    }
}