Java Code Examples for org.chromium.chrome.browser.ntp.NewTabPage#isNTPUrl()

The following examples show how to use org.chromium.chrome.browser.ntp.NewTabPage#isNTPUrl() . 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: ActivityTabTaskDescriptionHelper.java    From delion with Apache License 2.0 5 votes vote down vote up
private void updateTaskDescription() {
    if (mCurrentTab == null) {
        updateTaskDescription(null, null);
        return;
    }

    if (NewTabPage.isNTPUrl(mCurrentTab.getUrl()) && !mCurrentTab.isIncognito()) {
        // NTP needs a new color in recents, but uses the default application title and icon
        updateTaskDescription(null, null);
        return;
    }

    String label = mCurrentTab.getTitle();
    String domain = UrlUtilities.getDomainAndRegistry(mCurrentTab.getUrl(), false);
    if (TextUtils.isEmpty(label)) {
        label = domain;
    }
    if (mLargestFavicon == null && TextUtils.isEmpty(label)) {
        updateTaskDescription(null, null);
        return;
    }

    Bitmap bitmap = null;
    if (!mCurrentTab.isIncognito()) {
        bitmap = mIconGenerator.getBitmap(mCurrentTab.getUrl(), mLargestFavicon);
    }

    updateTaskDescription(label, bitmap);
}
 
Example 2
Source File: ActivityTabTaskDescriptionHelper.java    From AndroidChromium with Apache License 2.0 5 votes vote down vote up
private void updateTaskDescription() {
    if (mCurrentTab == null) {
        updateTaskDescription(null, null);
        return;
    }

    if (NewTabPage.isNTPUrl(mCurrentTab.getUrl()) && !mCurrentTab.isIncognito()) {
        // NTP needs a new color in recents, but uses the default application title and icon
        updateTaskDescription(null, null);
        return;
    }

    String label = mCurrentTab.getTitle();
    String domain = UrlUtilities.getDomainAndRegistry(mCurrentTab.getUrl(), false);
    if (TextUtils.isEmpty(label)) {
        label = domain;
    }
    if (mLargestFavicon == null && TextUtils.isEmpty(label)) {
        updateTaskDescription(null, null);
        return;
    }

    Bitmap bitmap = null;
    if (!mCurrentTab.isIncognito()) {
        bitmap = mIconGenerator.getBitmap(mCurrentTab.getUrl(), mLargestFavicon);
    }

    updateTaskDescription(label, bitmap);
}
 
Example 3
Source File: ChromeTabbedActivity.java    From 365browser with Apache License 2.0 5 votes vote down vote up
/**
 * Create an initial tab for cold start without restored tabs.
 */
private void createInitialTab() {
    String url = HomepageManager.getHomepageUri(getApplicationContext());
    if (TextUtils.isEmpty(url) || NewTabPage.isNTPUrl(url)) {
        url = UrlConstants.NTP_URL;
    }

    getTabCreator(false).launchUrl(url, TabLaunchType.FROM_CHROME_UI);
}
 
Example 4
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 5
Source File: TabPersistentStore.java    From 365browser with Apache License 2.0 5 votes vote down vote up
private void addTabToSaveQueueIfApplicable(Tab tab) {
    if (tab == null) return;
    if (mTabsToSave.contains(tab) || !tab.isTabStateDirty() || isTabUrlContentScheme(tab)) {
        return;
    }

    if (NewTabPage.isNTPUrl(tab.getUrl()) && !tab.canGoBack() && !tab.canGoForward()) {
        return;
    }
    mTabsToSave.addLast(tab);
}
 
Example 6
Source File: ActivityTabTaskDescriptionHelper.java    From 365browser with Apache License 2.0 5 votes vote down vote up
private void updateTaskDescription() {
    if (mCurrentTab == null) {
        updateTaskDescription(null, null);
        return;
    }

    if (NewTabPage.isNTPUrl(mCurrentTab.getUrl()) && !mCurrentTab.isIncognito()) {
        // NTP needs a new color in recents, but uses the default application title and icon
        updateTaskDescription(null, null);
        return;
    }

    String label = mCurrentTab.getTitle();
    String domain = UrlUtilities.getDomainAndRegistry(mCurrentTab.getUrl(), false);
    if (TextUtils.isEmpty(label)) {
        label = domain;
    }
    if (mLargestFavicon == null && TextUtils.isEmpty(label)) {
        updateTaskDescription(null, null);
        return;
    }

    Bitmap bitmap = null;
    if (!mCurrentTab.isIncognito()) {
        bitmap = mIconGenerator.getBitmap(mCurrentTab.getUrl(), mLargestFavicon);
    }

    updateTaskDescription(label, bitmap);
}
 
Example 7
Source File: LocationBarLayout.java    From delion with Apache License 2.0 4 votes vote down vote up
/**
 * Sets the displayed URL to be the URL of the page currently showing.
 *
 * <p>The URL is converted to the most user friendly format (removing HTTP:// for example).
 *
 * <p>If the current tab is null, the URL text will be cleared.
 */
@Override
public void setUrlToPageUrl() {
    String url = getOnlineUrlFromTab();

    // If the URL is currently focused, do not replace the text they have entered with the URL.
    // Once they stop editing the URL, the current tab's URL will automatically be filled in.
    if (mUrlBar.hasFocus()) {
        if (mUrlFocusedWithoutAnimations && !NewTabPage.isNTPUrl(url)) {
            // If we did not run the focus animations, then the user has not typed any text.
            // So, clear the focus and accept whatever URL the page is currently attempting to
            // display.
            setUrlBarFocus(false);
        } else {
            return;
        }
    }

    if (getCurrentTab() == null) {
        setUrlBarText("", null);
        return;
    }

    // Profile may be null if switching to a tab that has not yet been initialized.
    Profile profile = getCurrentTab().getProfile();
    if (profile != null) mOmniboxPrerender.clear(profile);

    mOriginalUrl = url;

    if (NativePageFactory.isNativePageUrl(url, getCurrentTab().isIncognito())
            || NewTabPage.isNTPUrl(url)) {
        // Don't show anything for Chrome URLs.
        setUrlBarText(null, "");
        return;
    }

    if (setUrlBarText(url, mToolbarDataProvider.getText())) {
        mUrlBar.deEmphasizeUrl();
        emphasizeUrl();
    }
    updateCustomSelectionActionModeCallback();
}
 
Example 8
Source File: LocationBarLayout.java    From AndroidChromium with Apache License 2.0 4 votes vote down vote up
/**
 * Sets the displayed URL to be the URL of the page currently showing.
 *
 * <p>The URL is converted to the most user friendly format (removing HTTP:// for example).
 *
 * <p>If the current tab is null, the URL text will be cleared.
 */
@Override
public void setUrlToPageUrl() {
    String url = getCurrentTabUrl();

    // If the URL is currently focused, do not replace the text they have entered with the URL.
    // Once they stop editing the URL, the current tab's URL will automatically be filled in.
    if (mUrlBar.hasFocus()) {
        if (mUrlFocusedWithoutAnimations && !NewTabPage.isNTPUrl(url)) {
            // If we did not run the focus animations, then the user has not typed any text.
            // So, clear the focus and accept whatever URL the page is currently attempting to
            // display.
            setUrlBarFocus(false);
        } else {
            return;
        }
    }

    if (getCurrentTab() == null) {
        setUrlBarText("", null);
        return;
    }

    // Profile may be null if switching to a tab that has not yet been initialized.
    Profile profile = getCurrentTab().getProfile();
    if (profile != null) mOmniboxPrerender.clear(profile);

    mOriginalUrl = url;

    if (NativePageFactory.isNativePageUrl(url, getCurrentTab().isIncognito())
            || NewTabPage.isNTPUrl(url)) {
        // Don't show anything for Chrome URLs.
        setUrlBarText(null, "");
        return;
    }

    if (setUrlBarText(url, mToolbarDataProvider.getText())) {
        mUrlBar.deEmphasizeUrl();
        emphasizeUrl();
    }
    updateCustomSelectionActionModeCallback();
}
 
Example 9
Source File: ChromeTabbedActivity.java    From 365browser with Apache License 2.0 4 votes vote down vote up
@Override
public boolean onMenuOrKeyboardAction(final int id, boolean fromMenu) {
    final Tab currentTab = getActivityTab();
    boolean currentTabIsNtp = currentTab != null && NewTabPage.isNTPUrl(currentTab.getUrl());
    if (id == R.id.move_to_other_window_menu_id) {
        if (currentTab != null) moveTabToOtherWindow(currentTab);
    } else if (id == R.id.new_tab_menu_id) {
        getTabModelSelector().getModel(false).commitAllTabClosures();
        RecordUserAction.record("MobileMenuNewTab");
        RecordUserAction.record("MobileNewTabOpened");
        reportNewTabShortcutUsed(false);
        getTabCreator(false).launchNTP();

        mLocaleManager.showSearchEnginePromoIfNeeded(this, null);
    } else if (id == R.id.new_incognito_tab_menu_id) {
        if (PrefServiceBridge.getInstance().isIncognitoModeEnabled()) {
            getTabModelSelector().getModel(false).commitAllTabClosures();
            // This action must be recorded before opening the incognito tab since UMA actions
            // are dropped when an incognito tab is open.
            RecordUserAction.record("MobileMenuNewIncognitoTab");
            RecordUserAction.record("MobileNewTabOpened");
            reportNewTabShortcutUsed(true);
            getTabCreator(true).launchNTP();
        }
    } else if (id == R.id.all_bookmarks_menu_id) {
        if (currentTab != null) {
            getCompositorViewHolder().hideKeyboard(new Runnable() {
                @Override
                public void run() {
                    StartupMetrics.getInstance().recordOpenedBookmarks();
                    BookmarkUtils.showBookmarkManager(ChromeTabbedActivity.this);
                }
            });
            if (currentTabIsNtp) {
                NewTabPageUma.recordAction(NewTabPageUma.ACTION_OPENED_BOOKMARKS_MANAGER);
            }
            RecordUserAction.record("MobileMenuAllBookmarks");
        }
    } else if (id == R.id.recent_tabs_menu_id) {
        if (currentTab != null) {
            currentTab.loadUrl(new LoadUrlParams(
                    UrlConstants.RECENT_TABS_URL,
                    PageTransition.AUTO_BOOKMARK));
            if (currentTabIsNtp) {
                NewTabPageUma.recordAction(NewTabPageUma.ACTION_OPENED_RECENT_TABS_MANAGER);
            }
            RecordUserAction.record("MobileMenuRecentTabs");
        }
    } else if (id == R.id.close_all_tabs_menu_id) {
        // Close both incognito and normal tabs
        getTabModelSelector().closeAllTabs();
        RecordUserAction.record("MobileMenuCloseAllTabs");
    } else if (id == R.id.close_all_incognito_tabs_menu_id) {
        // Close only incognito tabs
        getTabModelSelector().getModel(true).closeAllTabs();
        // TODO(nileshagrawal) Record unique action for this. See bug http://b/5542946.
        RecordUserAction.record("MobileMenuCloseAllTabs");
    } else if (id == R.id.find_in_page_id) {
        mFindToolbarManager.showToolbar();
        if (getContextualSearchManager() != null) {
            getContextualSearchManager().hideContextualSearch(StateChangeReason.UNKNOWN);
        }
        if (fromMenu) {
            RecordUserAction.record("MobileMenuFindInPage");
        } else {
            RecordUserAction.record("MobileShortcutFindInPage");
        }
    } else if (id == R.id.focus_url_bar) {
        boolean isUrlBarVisible = !mLayoutManager.overviewVisible()
                && (!isTablet() || getCurrentTabModel().getCount() != 0);
        if (isUrlBarVisible) {
            getToolbarManager().setUrlBarFocus(true);
        }
    } else if (id == R.id.downloads_menu_id) {
        DownloadUtils.showDownloadManager(this, currentTab);
        if (currentTabIsNtp) {
            NewTabPageUma.recordAction(NewTabPageUma.ACTION_OPENED_DOWNLOADS_MANAGER);
        }
        RecordUserAction.record("MobileMenuDownloadManager");
    } else if (id == R.id.open_recently_closed_tab) {
        TabModel currentModel = mTabModelSelectorImpl.getCurrentModel();
        if (!currentModel.isIncognito()) currentModel.openMostRecentlyClosedTab();
        RecordUserAction.record("MobileTabClosedUndoShortCut");
    } else if (id == R.id.enter_vr_id) {
        VrShellDelegate.enterVrIfNecessary();
    } else {
        return super.onMenuOrKeyboardAction(id, fromMenu);
    }
    return true;
}
 
Example 10
Source File: TabPersistentStore.java    From 365browser with Apache License 2.0 4 votes vote down vote up
/**
 * Handles restoring an individual tab.
 *
 * @param tabToRestore Meta data about the tab to be restored.
 * @param tabState     The previously serialized state of the tab to be restored.
 * @param setAsActive  Whether the tab should be set as the active tab as part of the
 *                     restoration process.
 */
@VisibleForTesting
protected void restoreTab(
        TabRestoreDetails tabToRestore, TabState tabState, boolean setAsActive) {
    // If we don't have enough information about the Tab, bail out.
    boolean isIncognito = isIncognitoTabBeingRestored(tabToRestore, tabState);
    if (tabState == null) {
        if (tabToRestore.isIncognito == null) {
            Log.w(TAG, "Failed to restore tab: not enough info about its type was available.");
            return;
        } else if (isIncognito) {
            Log.i(TAG, "Failed to restore Incognito tab: its TabState could not be restored.");
            return;
        }
    }

    TabModel model = mTabModelSelector.getModel(isIncognito);
    SparseIntArray restoredTabs = isIncognito ? mIncognitoTabsRestored : mNormalTabsRestored;
    int restoredIndex = 0;
    if (tabToRestore.fromMerge) {
        // Put any tabs being merged into this list at the end.
        restoredIndex = mTabModelSelector.getModel(isIncognito).getCount();
    } else if (restoredTabs.size() > 0
            && tabToRestore.originalIndex > restoredTabs.keyAt(restoredTabs.size() - 1)) {
        // If the tab's index is too large, restore it at the end of the list.
        restoredIndex = restoredTabs.size();
    } else {
         // Otherwise try to find the tab we should restore before, if any.
        for (int i = 0; i < restoredTabs.size(); i++) {
            if (restoredTabs.keyAt(i) > tabToRestore.originalIndex) {
                Tab nextTabByIndex = TabModelUtils.getTabById(model, restoredTabs.valueAt(i));
                restoredIndex = nextTabByIndex != null ? model.indexOf(nextTabByIndex) : -1;
                break;
            }
        }
    }

    int tabId = tabToRestore.id;
    if (tabState != null) {
        mTabCreatorManager.getTabCreator(isIncognito).createFrozenTab(
                tabState, tabToRestore.id, restoredIndex);
    } else {
        if (NewTabPage.isNTPUrl(tabToRestore.url) && !setAsActive && !tabToRestore.fromMerge) {
            Log.i(TAG, "Skipping restore of non-selected NTP.");
            return;
        }

        Log.w(TAG, "Failed to restore TabState; creating Tab with last known URL.");
        Tab fallbackTab = mTabCreatorManager.getTabCreator(isIncognito).createNewTab(
                new LoadUrlParams(tabToRestore.url), TabModel.TabLaunchType.FROM_RESTORE, null);
        tabId = fallbackTab.getId();
        model.moveTab(tabId, restoredIndex);
    }

    // If the tab is being restored from a merge and its index is 0, then the model being
    // merged into doesn't contain any tabs. Select the first tab to avoid having no tab
    // selected. TODO(twellington): The first tab will always be selected. Instead, the tab that
    // was selected in the other model before the merge should be selected after the merge.
    if (setAsActive || (tabToRestore.fromMerge && restoredIndex == 0)) {
        boolean wasIncognitoTabModelSelected = mTabModelSelector.isIncognitoSelected();
        int selectedModelTabCount = mTabModelSelector.getCurrentModel().getCount();

        TabModelUtils.setIndex(model, TabModelUtils.getTabIndexById(model, tabId));
        boolean isIncognitoTabModelSelected = mTabModelSelector.isIncognitoSelected();

        // Setting the index will cause the tab's model to be selected. Set it back to the model
        // that was selected before setting the index if the index is being set during a merge
        // unless the previously selected model is empty (e.g. showing the empty background
        // view on tablets).
        if (tabToRestore.fromMerge
                && wasIncognitoTabModelSelected != isIncognitoTabModelSelected
                && selectedModelTabCount != 0) {
            mTabModelSelector.selectModel(wasIncognitoTabModelSelected);
        }
    }
    restoredTabs.put(tabToRestore.originalIndex, tabId);
}
 
Example 11
Source File: LocationBarLayout.java    From 365browser with Apache License 2.0 4 votes vote down vote up
/**
 * Sets the displayed URL to be the URL of the page currently showing.
 *
 * <p>The URL is converted to the most user friendly format (removing HTTP:// for example).
 *
 * <p>If the current tab is null, the URL text will be cleared.
 */
@Override
public void setUrlToPageUrl() {
    String url = getCurrentTabUrl();

    // If the URL is currently focused, do not replace the text they have entered with the URL.
    // Once they stop editing the URL, the current tab's URL will automatically be filled in.
    if (mUrlBar.hasFocus()) {
        if ((mUrlFocusedWithoutAnimations && !NewTabPage.isNTPUrl(url))
                || (mBottomSheet != null && mBottomSheet.isShowingNewTab())) {
            // If we did not run the focus animations, then the user has not typed any text.
            // So, clear the focus and accept whatever URL the page is currently attempting to
            // display. If the NTP is showing, the current page's URL should not be displayed.
            setUrlBarFocus(false);
        } else {
            return;
        }
    }

    if (getCurrentTab() == null) {
        setUrlBarText("", null);
        return;
    }

    // Profile may be null if switching to a tab that has not yet been initialized.
    Profile profile = getCurrentTab().getProfile();
    if (profile != null) mOmniboxPrerender.clear(profile);

    mOriginalUrl = url;

    if (NativePageFactory.isNativePageUrl(url, getCurrentTab().isIncognito())
            || NewTabPage.isNTPUrl(url)) {
        // Don't show anything for Chrome URLs.
        setUrlBarText(null, "");
        return;
    }

    if (setUrlBarText(url, mToolbarDataProvider.getText())) {
        mUrlBar.deEmphasizeUrl();
        emphasizeUrl();
    }
}