org.chromium.chrome.browser.ntp.NewTabPageUma Java Examples

The following examples show how to use org.chromium.chrome.browser.ntp.NewTabPageUma. 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: BookmarkUtils.java    From delion with Apache License 2.0 6 votes vote down vote up
/**
 * Opens a bookmark and reports UMA.
 * @param model Bookmarks model to manage the bookmark.
 * @param activity Activity requesting to open the bookmark.
 * @param bookmarkId ID of the bookmark to be opened.
 * @param launchLocation Location from which the bookmark is being opened.
 * @return Whether the bookmark was successfully opened.
 */
public static boolean openBookmark(BookmarkModel model, Activity activity,
        BookmarkId bookmarkId, int launchLocation) {
    if (model.getBookmarkById(bookmarkId) == null) return false;

    String url = model.getBookmarkById(bookmarkId).getUrl();

    NewTabPageUma.recordAction(NewTabPageUma.ACTION_OPENED_BOOKMARK);
    RecordHistogram.recordEnumeratedHistogram(
            "Stars.LaunchLocation", launchLocation, BookmarkLaunchLocation.COUNT);

    if (DeviceFormFactor.isTablet(activity)) {
        // For tablets, the bookmark manager is open in a tab in the ChromeActivity. Use
        // the ComponentName of the ChromeActivity passed into this method.
        openUrl(activity, url, activity.getComponentName());
    } else {
        // For phones, the bookmark manager is a separate activity. When the activity is
        // launched, an intent extra is set specifying the parent component.
        ComponentName parentComponent = IntentUtils.safeGetParcelableExtra(
                activity.getIntent(), IntentHandler.EXTRA_PARENT_COMPONENT);
        openUrl(activity, url, parentComponent);
    }

    return true;
}
 
Example #2
Source File: NewTabPageAdapter.java    From delion with Apache License 2.0 6 votes vote down vote up
@Override
public void onSnippetsReceived(List<SnippetArticle> listSnippets) {
    if (!mWantsSnippets) return;

    int newSnippetCount = listSnippets.size();
    Log.d(TAG, "Received %d new snippets.", newSnippetCount);

    // At first, there might be no snippets available, we wait until they have been fetched.
    if (newSnippetCount == 0) return;

    loadSnippets(listSnippets);

    // We don't want to get notified of other changes.
    mWantsSnippets = false;
    NewTabPageUma.recordSnippetAction(NewTabPageUma.SNIPPETS_ACTION_SHOWN);
}
 
Example #3
Source File: BookmarkUtils.java    From AndroidChromium with Apache License 2.0 6 votes vote down vote up
/**
 * Opens a bookmark and reports UMA.
 * @param model Bookmarks model to manage the bookmark.
 * @param activity Activity requesting to open the bookmark.
 * @param bookmarkId ID of the bookmark to be opened.
 * @param launchLocation Location from which the bookmark is being opened.
 * @return Whether the bookmark was successfully opened.
 */
public static boolean openBookmark(BookmarkModel model, Activity activity,
        BookmarkId bookmarkId, int launchLocation) {
    if (model.getBookmarkById(bookmarkId) == null) return false;

    String url = model.getBookmarkById(bookmarkId).getUrl();

    NewTabPageUma.recordAction(NewTabPageUma.ACTION_OPENED_BOOKMARK);
    RecordHistogram.recordEnumeratedHistogram(
            "Stars.LaunchLocation", launchLocation, BookmarkLaunchLocation.COUNT);

    if (DeviceFormFactor.isTablet(activity)) {
        // For tablets, the bookmark manager is open in a tab in the ChromeActivity. Use
        // the ComponentName of the ChromeActivity passed into this method.
        openUrl(activity, url, activity.getComponentName());
    } else {
        // For phones, the bookmark manager is a separate activity. When the activity is
        // launched, an intent extra is set specifying the parent component.
        ComponentName parentComponent = IntentUtils.safeGetParcelableExtra(
                activity.getIntent(), IntentHandler.EXTRA_PARENT_COMPONENT);
        openUrl(activity, url, parentComponent);
    }

    return true;
}
 
Example #4
Source File: AllDismissedItem.java    From AndroidChromium with Apache License 2.0 6 votes vote down vote up
public ViewHolder(
        ViewGroup root, final NewTabPageManager manager, final NewTabPageAdapter adapter) {
    super(LayoutInflater.from(root.getContext())
                    .inflate(R.layout.new_tab_page_all_dismissed, root, false));
    mBodyTextView = (TextView) itemView.findViewById(R.id.body_text);

    ((Button) itemView.findViewById(R.id.action_button))
            .setOnClickListener(new OnClickListener() {
                @Override
                public void onClick(View v) {
                    NewTabPageUma.recordAction(
                            NewTabPageUma.ACTION_CLICKED_ALL_DISMISSED_REFRESH);
                    manager.getSuggestionsSource().restoreDismissedCategories();
                    adapter.resetSections(/*allowEmptySections=*/true);
                    adapter.reloadSnippets();
                }
            });
}
 
Example #5
Source File: SuggestionsSection.java    From 365browser with Apache License 2.0 6 votes vote down vote up
/**
 * Adds the provided suggestions to the ones currently displayed by the section.
 *
 * @param suggestions The suggestions to be added at the end of the current list.
 * @param userRequested Whether the operation is explicitly requested by the user, preventing
 *                      scheduled updates to override the new data.
 */
public void appendSuggestions(List<SnippetArticle> suggestions, boolean userRequested) {
    mSuggestionsList.addAll(suggestions);

    for (SnippetArticle article : suggestions) {
        if (!article.requiresExactOfflinePage()) {
            mOfflineModelObserver.updateOfflinableSuggestionAvailability(article);
        }
    }

    if (userRequested) {
        NewTabPageUma.recordUIUpdateResult(NewTabPageUma.UI_UPDATE_SUCCESS_APPENDED);
        mHasAppended = true;
    } else {
        NewTabPageUma.recordNumberOfSuggestionsSeenBeforeUIUpdateSuccess(
                mNumberOfSuggestionsSeen);
        NewTabPageUma.recordUIUpdateResult(NewTabPageUma.UI_UPDATE_SUCCESS_REPLACED);
    }
}
 
Example #6
Source File: SuggestionsSection.java    From 365browser with Apache License 2.0 6 votes vote down vote up
/**
 * Returns whether the list of suggestions can be updated at the moment.
 */
private boolean canUpdateSuggestions() {
    if (!hasSuggestions()) return true; // If we don't have any, we always accept updates.

    if (CardsVariationParameters.ignoreUpdatesForExistingSuggestions()) {
        Log.d(TAG, "setSuggestions: replacing existing suggestion disabled");
        NewTabPageUma.recordUIUpdateResult(NewTabPageUma.UI_UPDATE_FAIL_DISABLED);
        return false;
    }

    if (mNumberOfSuggestionsSeen >= getSuggestionsCount() || mHasAppended) {
        Log.d(TAG, "setSuggestions: replacing existing suggestion not possible, all seen");
        NewTabPageUma.recordUIUpdateResult(NewTabPageUma.UI_UPDATE_FAIL_ALL_SEEN);
        return false;
    }

    return true;
}
 
Example #7
Source File: SuggestionsEventReporterBridge.java    From 365browser with Apache License 2.0 6 votes vote down vote up
@Override
public void onMoreButtonClicked(ActionItem actionItem) {
    @CategoryInt
    int category = actionItem.getCategory();
    nativeOnMoreButtonClicked(category, actionItem.getPerSectionRank());
    switch (category) {
        case KnownCategories.BOOKMARKS:
            NewTabPageUma.recordAction(NewTabPageUma.ACTION_OPENED_BOOKMARKS_MANAGER);
            break;
        // MORE button in both categories leads to the recent tabs manager
        case KnownCategories.FOREIGN_TABS:
        case KnownCategories.RECENT_TABS:
            NewTabPageUma.recordAction(NewTabPageUma.ACTION_OPENED_RECENT_TABS_MANAGER);
            break;
        case KnownCategories.DOWNLOADS:
            NewTabPageUma.recordAction(NewTabPageUma.ACTION_OPENED_DOWNLOADS_MANAGER);
            break;
        default:
            // No action associated
            break;
    }
}
 
Example #8
Source File: SnippetArticle.java    From delion with Apache License 2.0 5 votes vote down vote up
/** Tracks click on this NTP snippet in UMA. */
public void trackClick() {
    RecordUserAction.record("MobileNTP.Snippets.Click");
    RecordHistogram.recordSparseSlowlyHistogram("NewTabPage.Snippets.CardClicked", mPosition);
    NewTabPageUma.recordSnippetAction(NewTabPageUma.SNIPPETS_ACTION_CLICKED);
    NewTabPageUma.recordAction(NewTabPageUma.ACTION_OPENED_SNIPPET);
    recordAgeAndScore("NewTabPage.Snippets.CardClicked");
}
 
Example #9
Source File: InterestsPage.java    From delion with Apache License 2.0 5 votes vote down vote up
public void setListener(final InterestsClickListener listener) {
    mPageView.setListener(new InterestsClickListener() {
        public void onInterestClicked(String interest) {
            mClicked = true;
            NewTabPageUma.recordAction(NewTabPageUma.ACTION_CLICKED_INTEREST);
            RecordUserAction.record("MobileNTP.Interests.Click");
            listener.onInterestClicked(interest);
        }
    });
}
 
Example #10
Source File: AllDismissedItem.java    From 365browser with Apache License 2.0 5 votes vote down vote up
public ViewHolder(ViewGroup root, final SectionList sections) {
    super(LayoutInflater.from(root.getContext())
                    .inflate(R.layout.new_tab_page_all_dismissed, root, false));
    mBodyTextView = (TextView) itemView.findViewById(R.id.body_text);

    ((Button) itemView.findViewById(R.id.action_button))
            .setOnClickListener(new OnClickListener() {
                @Override
                public void onClick(View v) {
                    NewTabPageUma.recordAction(
                            NewTabPageUma.ACTION_CLICKED_ALL_DISMISSED_REFRESH);
                    sections.restoreDismissedSections();
                }
            });
}
 
Example #11
Source File: TileGroupDelegateImpl.java    From 365browser with Apache License 2.0 5 votes vote down vote up
private void recordOpenedTile(Tile tile) {
    NewTabPageUma.recordAction(NewTabPageUma.ACTION_OPENED_MOST_VISITED_TILE);
    RecordUserAction.record("MobileNTPMostVisited");
    NewTabPageUma.recordExplicitUserNavigation(
            tile.getUrl(), NewTabPageUma.RAPPOR_ACTION_VISITED_SUGGESTED_TILE);
    mMostVisitedSites.recordOpenedMostVisitedItem(
            tile.getIndex(), tile.getType(), tile.getSource());
}
 
Example #12
Source File: SuggestionsNavigationDelegateImpl.java    From 365browser with Apache License 2.0 5 votes vote down vote up
@Override
public void navigateToHelpPage() {
    NewTabPageUma.recordAction(NewTabPageUma.ACTION_CLICKED_LEARN_MORE);
    // TODO(dgn): Use the standard Help UI rather than a random link to online help?
    openUrl(WindowOpenDisposition.CURRENT_TAB,
            new LoadUrlParams(NEW_TAB_URL_HELP, PageTransition.AUTO_BOOKMARK));
}
 
Example #13
Source File: ChromeTabbedActivity.java    From AndroidChromium with Apache License 2.0 4 votes vote down vote up
@Override
public void initializeCompositor() {
    try {
        TraceEvent.begin("ChromeTabbedActivity.initializeCompositor");
        super.initializeCompositor();

        mTabModelSelectorImpl.onNativeLibraryReady(getTabContentManager());
        mVrShellDelegate.onNativeLibraryReady();

        mTabModelObserver = new TabModelSelectorTabModelObserver(mTabModelSelectorImpl) {
            @Override
            public void didCloseTab(int tabId, boolean incognito) {
                closeIfNoTabsAndHomepageEnabled(false);
            }

            @Override
            public void tabPendingClosure(Tab tab) {
                closeIfNoTabsAndHomepageEnabled(true);
            }

            @Override
            public void tabRemoved(Tab tab) {
                closeIfNoTabsAndHomepageEnabled(false);
            }

            private void closeIfNoTabsAndHomepageEnabled(boolean isPendingClosure) {
                if (getTabModelSelector().getTotalTabCount() == 0) {
                    // If the last tab is closed, and homepage is enabled, then exit Chrome.
                    if (HomepageManager.isHomepageEnabled(getApplicationContext())) {
                        finish();
                    } else if (isPendingClosure) {
                        NewTabPageUma.recordNTPImpression(
                                NewTabPageUma.NTP_IMPESSION_POTENTIAL_NOTAB);
                    }
                }
            }

            @Override
            public void didAddTab(Tab tab, TabLaunchType type) {
                if (type == TabLaunchType.FROM_LONGPRESS_BACKGROUND
                        && !DeviceClassManager.enableAnimations(getApplicationContext())) {
                    Toast.makeText(ChromeTabbedActivity.this,
                            R.string.open_in_new_tab_toast,
                            Toast.LENGTH_SHORT).show();
                }
            }

            @Override
            public void allTabsPendingClosure(List<Integer> tabIds) {
                NewTabPageUma.recordNTPImpression(
                        NewTabPageUma.NTP_IMPESSION_POTENTIAL_NOTAB);
            }
        };

        Bundle state = getSavedInstanceState();
        if (state != null && state.containsKey(FRE_RUNNING)) {
            mIsOnFirstRun = state.getBoolean(FRE_RUNNING);
        }
    } finally {
        TraceEvent.end("ChromeTabbedActivity.initializeCompositor");
    }
}
 
Example #14
Source File: ChromeTabbedActivity.java    From 365browser with Apache License 2.0 4 votes vote down vote up
@Override
public void initializeCompositor() {
    try {
        TraceEvent.begin("ChromeTabbedActivity.initializeCompositor");
        super.initializeCompositor();

        mTabModelSelectorImpl.onNativeLibraryReady(getTabContentManager());

        mTabModelObserver = new TabModelSelectorTabModelObserver(mTabModelSelectorImpl) {
            @Override
            public void didCloseTab(int tabId, boolean incognito) {
                closeIfNoTabsAndHomepageEnabled(false);
            }

            @Override
            public void tabPendingClosure(Tab tab) {
                closeIfNoTabsAndHomepageEnabled(true);
            }

            @Override
            public void tabRemoved(Tab tab) {
                closeIfNoTabsAndHomepageEnabled(false);
            }

            private void closeIfNoTabsAndHomepageEnabled(boolean isPendingClosure) {
                if (getTabModelSelector().getTotalTabCount() == 0) {
                    // If the last tab is closed, and homepage is enabled, then exit Chrome.
                    if (HomepageManager.isHomepageEnabled(getApplicationContext())) {
                        finish();
                    } else if (isPendingClosure) {
                        NewTabPageUma.recordNTPImpression(
                                NewTabPageUma.NTP_IMPESSION_POTENTIAL_NOTAB);
                    }
                }
            }

            @Override
            public void didAddTab(Tab tab, TabLaunchType type) {
                if (type == TabLaunchType.FROM_LONGPRESS_BACKGROUND
                        && !DeviceClassManager.enableAnimations()) {
                    Toast.makeText(ChromeTabbedActivity.this,
                            R.string.open_in_new_tab_toast,
                            Toast.LENGTH_SHORT).show();
                }
            }

            @Override
            public void allTabsPendingClosure(List<Tab> tabs) {
                NewTabPageUma.recordNTPImpression(
                        NewTabPageUma.NTP_IMPESSION_POTENTIAL_NOTAB);
            }
        };

        Bundle state = getSavedInstanceState();
        if (state != null && state.containsKey(FRE_RUNNING)) {
            mIsOnFirstRun = state.getBoolean(FRE_RUNNING);
        }
    } finally {
        TraceEvent.end("ChromeTabbedActivity.initializeCompositor");
    }
}
 
Example #15
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;
}