OLD | NEW |
---|---|
1 // Copyright 2015 The Chromium Authors. All rights reserved. | 1 // Copyright 2015 The Chromium Authors. All rights reserved. |
2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 | 4 |
5 package org.chromium.chrome.browser.ntp; | 5 package org.chromium.chrome.browser.ntp; |
6 | 6 |
7 import android.app.Activity; | 7 import android.app.Activity; |
8 import android.app.Dialog; | 8 import android.app.Dialog; |
9 import android.content.Context; | 9 import android.content.Context; |
10 import android.graphics.Bitmap; | 10 import android.graphics.Bitmap; |
11 import android.graphics.Canvas; | 11 import android.graphics.Canvas; |
12 import android.graphics.Rect; | 12 import android.graphics.Rect; |
13 import android.view.ContextMenu; | 13 import android.view.ContextMenu; |
14 import android.view.LayoutInflater; | 14 import android.view.LayoutInflater; |
15 import android.view.Menu; | 15 import android.view.Menu; |
16 import android.view.MenuItem.OnMenuItemClickListener; | 16 import android.view.MenuItem.OnMenuItemClickListener; |
17 import android.view.View; | 17 import android.view.View; |
18 | 18 |
19 import org.chromium.base.ApiCompatibilityUtils; | 19 import org.chromium.base.ApiCompatibilityUtils; |
20 import org.chromium.base.CommandLine; | |
21 import org.chromium.base.FieldTrialList; | |
20 import org.chromium.base.VisibleForTesting; | 22 import org.chromium.base.VisibleForTesting; |
21 import org.chromium.base.metrics.RecordHistogram; | 23 import org.chromium.base.metrics.RecordHistogram; |
22 import org.chromium.base.metrics.RecordUserAction; | 24 import org.chromium.base.metrics.RecordUserAction; |
23 import org.chromium.chrome.R; | 25 import org.chromium.chrome.R; |
26 import org.chromium.chrome.browser.ChromeSwitches; | |
24 import org.chromium.chrome.browser.NativePage; | 27 import org.chromium.chrome.browser.NativePage; |
25 import org.chromium.chrome.browser.UrlConstants; | 28 import org.chromium.chrome.browser.UrlConstants; |
26 import org.chromium.chrome.browser.compositor.layouts.content.InvalidationAwareT humbnailProvider; | 29 import org.chromium.chrome.browser.compositor.layouts.content.InvalidationAwareT humbnailProvider; |
27 import org.chromium.chrome.browser.document.DocumentMetricIds; | 30 import org.chromium.chrome.browser.document.DocumentMetricIds; |
28 import org.chromium.chrome.browser.enhancedbookmarks.EnhancedBookmarkUtils; | 31 import org.chromium.chrome.browser.enhancedbookmarks.EnhancedBookmarkUtils; |
29 import org.chromium.chrome.browser.favicon.FaviconHelper; | 32 import org.chromium.chrome.browser.favicon.FaviconHelper; |
30 import org.chromium.chrome.browser.favicon.FaviconHelper.FaviconAvailabilityCall back; | 33 import org.chromium.chrome.browser.favicon.FaviconHelper.FaviconAvailabilityCall back; |
31 import org.chromium.chrome.browser.favicon.FaviconHelper.FaviconImageCallback; | 34 import org.chromium.chrome.browser.favicon.FaviconHelper.FaviconImageCallback; |
32 import org.chromium.chrome.browser.favicon.LargeIconBridge; | 35 import org.chromium.chrome.browser.favicon.LargeIconBridge; |
33 import org.chromium.chrome.browser.favicon.LargeIconBridge.LargeIconCallback; | 36 import org.chromium.chrome.browser.favicon.LargeIconBridge.LargeIconCallback; |
(...skipping 20 matching lines...) Expand all Loading... | |
54 import org.chromium.ui.base.PageTransition; | 57 import org.chromium.ui.base.PageTransition; |
55 | 58 |
56 import java.util.concurrent.TimeUnit; | 59 import java.util.concurrent.TimeUnit; |
57 | 60 |
58 /** | 61 /** |
59 * Provides functionality when the user interacts with the NTP. | 62 * Provides functionality when the user interacts with the NTP. |
60 */ | 63 */ |
61 public class NewTabPage | 64 public class NewTabPage |
62 implements NativePage, InvalidationAwareThumbnailProvider, TemplateUrlSe rviceObserver { | 65 implements NativePage, InvalidationAwareThumbnailProvider, TemplateUrlSe rviceObserver { |
63 | 66 |
64 // The number of times that an opt-out promo will be shown. | 67 private static final String ICON_NTP_FIELD_TRIAL_NAME = "IconNTP"; |
newt (away)
2015/09/28 22:34:21
I moved finch logic from NewTabPageView to NewTabP
| |
68 private static final String ICON_NTP_ENABLED_GROUP = "Enabled"; | |
69 | |
70 // The number of times that the document-mode opt-out promo will be shown. | |
65 private static final int MAX_OPT_OUT_PROMO_COUNT = 10; | 71 private static final int MAX_OPT_OUT_PROMO_COUNT = 10; |
66 | 72 |
67 // MostVisitedItem Context menu item IDs. | 73 // MostVisitedItem Context menu item IDs. |
68 static final int ID_OPEN_IN_NEW_TAB = 0; | 74 static final int ID_OPEN_IN_NEW_TAB = 0; |
69 static final int ID_OPEN_IN_INCOGNITO_TAB = 1; | 75 static final int ID_OPEN_IN_INCOGNITO_TAB = 1; |
70 static final int ID_REMOVE = 2; | 76 static final int ID_REMOVE = 2; |
71 | 77 |
72 private static MostVisitedSites sMostVisitedSitesForTests; | 78 private static MostVisitedSites sMostVisitedSitesForTests; |
73 | 79 |
74 private final Tab mTab; | 80 private final Tab mTab; |
75 private final TabModelSelector mTabModelSelector; | 81 private final TabModelSelector mTabModelSelector; |
76 private final Activity mActivity; | 82 private final Activity mActivity; |
77 | 83 |
78 private final Profile mProfile; | 84 private final Profile mProfile; |
79 private final String mTitle; | 85 private final String mTitle; |
80 private final int mBackgroundColor; | 86 private final int mBackgroundColor; |
81 private final NewTabPageView mNewTabPageView; | 87 private final NewTabPageView mNewTabPageView; |
82 | 88 |
83 private MostVisitedSites mMostVisitedSites; | 89 private MostVisitedSites mMostVisitedSites; |
84 private FaviconHelper mFaviconHelper; | 90 private FaviconHelper mFaviconHelper; |
85 private LargeIconBridge mLargeIconBridge; | 91 private LargeIconBridge mLargeIconBridge; |
86 private LogoBridge mLogoBridge; | 92 private LogoBridge mLogoBridge; |
87 private boolean mSearchProviderHasLogo; | 93 private boolean mSearchProviderHasLogo; |
94 private boolean mIsIconMode; | |
88 private final boolean mOptOutPromoShown; | 95 private final boolean mOptOutPromoShown; |
89 private String mOnLogoClickUrl; | 96 private String mOnLogoClickUrl; |
90 private FakeboxDelegate mFakeboxDelegate; | 97 private FakeboxDelegate mFakeboxDelegate; |
91 | 98 |
92 // The timestamp at which the constructor was called. | 99 // The timestamp at which the constructor was called. |
93 private final long mConstructedTimeNs; | 100 private final long mConstructedTimeNs; |
94 | 101 |
95 private boolean mIsLoaded; | 102 private boolean mIsLoaded; |
96 | 103 |
97 // Whether destroy() has been called. | 104 // Whether destroy() has been called. |
(...skipping 91 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
189 | 196 |
190 private void recordOpenedMostVisitedItem(MostVisitedItem item) { | 197 private void recordOpenedMostVisitedItem(MostVisitedItem item) { |
191 if (mIsDestroyed) return; | 198 if (mIsDestroyed) return; |
192 NewTabPageUma.recordAction(NewTabPageUma.ACTION_OPENED_MOST_VISITED_ ENTRY); | 199 NewTabPageUma.recordAction(NewTabPageUma.ACTION_OPENED_MOST_VISITED_ ENTRY); |
193 NewTabPageUma.recordExplicitUserNavigation( | 200 NewTabPageUma.recordExplicitUserNavigation( |
194 item.getUrl(), NewTabPageUma.RAPPOR_ACTION_VISITED_SUGGESTED _TILE); | 201 item.getUrl(), NewTabPageUma.RAPPOR_ACTION_VISITED_SUGGESTED _TILE); |
195 RecordHistogram.recordEnumeratedHistogram("NewTabPage.MostVisited", item.getIndex(), | 202 RecordHistogram.recordEnumeratedHistogram("NewTabPage.MostVisited", item.getIndex(), |
196 NewTabPageView.MAX_MOST_VISITED_SITES); | 203 NewTabPageView.MAX_MOST_VISITED_SITES); |
197 RecordHistogram.recordMediumTimesHistogram("NewTabPage.MostVisitedTi me", | 204 RecordHistogram.recordMediumTimesHistogram("NewTabPage.MostVisitedTi me", |
198 System.nanoTime() - mConstructedTimeNs, TimeUnit.NANOSECONDS ); | 205 System.nanoTime() - mConstructedTimeNs, TimeUnit.NANOSECONDS ); |
199 mMostVisitedSites.recordOpenedMostVisitedItem(item.getIndex()); | 206 mMostVisitedSites.recordOpenedMostVisitedItem(item.getIndex(), item. getTileType()); |
200 } | 207 } |
201 | 208 |
202 private void recordDocumentOptOutPromoClick(int which) { | 209 private void recordDocumentOptOutPromoClick(int which) { |
203 RecordHistogram.recordEnumeratedHistogram("DocumentActivity.OptOutCl ick", which, | 210 RecordHistogram.recordEnumeratedHistogram("DocumentActivity.OptOutCl ick", which, |
204 DocumentMetricIds.OPT_OUT_CLICK_COUNT); | 211 DocumentMetricIds.OPT_OUT_CLICK_COUNT); |
205 } | 212 } |
206 | 213 |
207 @Override | 214 @Override |
208 public boolean shouldShowOptOutPromo() { | 215 public boolean shouldShowOptOutPromo() { |
209 if (!FeatureUtilities.isDocumentMode(mActivity)) return false; | 216 if (!FeatureUtilities.isDocumentMode(mActivity)) return false; |
(...skipping 154 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
364 public void onLogoAvailable(Logo logo, boolean fromCache) { | 371 public void onLogoAvailable(Logo logo, boolean fromCache) { |
365 if (mIsDestroyed) return; | 372 if (mIsDestroyed) return; |
366 mOnLogoClickUrl = logo != null ? logo.onClickUrl : null; | 373 mOnLogoClickUrl = logo != null ? logo.onClickUrl : null; |
367 logoObserver.onLogoAvailable(logo, fromCache); | 374 logoObserver.onLogoAvailable(logo, fromCache); |
368 } | 375 } |
369 }; | 376 }; |
370 mLogoBridge.getCurrentLogo(wrapperCallback); | 377 mLogoBridge.getCurrentLogo(wrapperCallback); |
371 } | 378 } |
372 | 379 |
373 @Override | 380 @Override |
374 public void onLoadingComplete() { | 381 public void onLoadingComplete(MostVisitedItem[] items) { |
375 long loadTimeMs = (System.nanoTime() - mConstructedTimeNs) / 1000000 ; | 382 long loadTimeMs = (System.nanoTime() - mConstructedTimeNs) / 1000000 ; |
376 RecordHistogram.recordTimesHistogram( | 383 RecordHistogram.recordTimesHistogram( |
377 "Tab.NewTabOnload", loadTimeMs, TimeUnit.MILLISECONDS); | 384 "Tab.NewTabOnload", loadTimeMs, TimeUnit.MILLISECONDS); |
378 mIsLoaded = true; | 385 mIsLoaded = true; |
379 | 386 |
380 if (mIsDestroyed) return; | 387 if (mIsDestroyed) return; |
381 mMostVisitedSites.onLoadingComplete(); | 388 |
389 int tileTypes[] = new int[items.length]; | |
390 for (int i = 0; i < items.length; i++) { | |
391 tileTypes[i] = items[i].getTileType(); | |
392 } | |
393 mMostVisitedSites.recordTileTypeMetrics(tileTypes, mIsIconMode); | |
382 } | 394 } |
383 }; | 395 }; |
384 | 396 |
385 /** | 397 /** |
386 * Constructs a NewTabPage. | 398 * Constructs a NewTabPage. |
387 * @param activity The activity used for context to create the new tab page' s View. | 399 * @param activity The activity used for context to create the new tab page' s View. |
388 * @param tab The Tab that is showing this new tab page. | 400 * @param tab The Tab that is showing this new tab page. |
389 * @param tabModelSelector The TabModelSelector used to open tabs. | 401 * @param tabModelSelector The TabModelSelector used to open tabs. |
390 */ | 402 */ |
391 public NewTabPage(Activity activity, Tab tab, TabModelSelector tabModelSelec tor) { | 403 public NewTabPage(Activity activity, Tab tab, TabModelSelector tabModelSelec tor) { |
(...skipping 12 matching lines...) Expand all Loading... | |
404 // because the user can dismiss the promo. To ensure the UI is consiste nt, cache the | 416 // because the user can dismiss the promo. To ensure the UI is consiste nt, cache the |
405 // value initially and ignore further updates. | 417 // value initially and ignore further updates. |
406 mOptOutPromoShown = mNewTabPageManager.shouldShowOptOutPromo(); | 418 mOptOutPromoShown = mNewTabPageManager.shouldShowOptOutPromo(); |
407 | 419 |
408 mMostVisitedSites = buildMostVisitedSites(mProfile); | 420 mMostVisitedSites = buildMostVisitedSites(mProfile); |
409 mLogoBridge = new LogoBridge(mProfile); | 421 mLogoBridge = new LogoBridge(mProfile); |
410 updateSearchProviderHasLogo(); | 422 updateSearchProviderHasLogo(); |
411 | 423 |
412 LayoutInflater inflater = LayoutInflater.from(activity); | 424 LayoutInflater inflater = LayoutInflater.from(activity); |
413 mNewTabPageView = (NewTabPageView) inflater.inflate(R.layout.new_tab_pag e, null); | 425 mNewTabPageView = (NewTabPageView) inflater.inflate(R.layout.new_tab_pag e, null); |
426 mIsIconMode = isIconNtpEnabled(); | |
414 mNewTabPageView.initialize(mNewTabPageManager, isInSingleUrlBarMode(acti vity), | 427 mNewTabPageView.initialize(mNewTabPageManager, isInSingleUrlBarMode(acti vity), |
415 mSearchProviderHasLogo); | 428 mSearchProviderHasLogo, mIsIconMode); |
416 } | 429 } |
417 | 430 |
418 private static MostVisitedSites buildMostVisitedSites(Profile profile) { | 431 private static MostVisitedSites buildMostVisitedSites(Profile profile) { |
419 if (sMostVisitedSitesForTests != null) { | 432 if (sMostVisitedSitesForTests != null) { |
420 return sMostVisitedSitesForTests; | 433 return sMostVisitedSitesForTests; |
421 } else { | 434 } else { |
422 return new MostVisitedSites(profile); | 435 return new MostVisitedSites(profile); |
423 } | 436 } |
424 } | 437 } |
425 | 438 |
439 private boolean isIconNtpEnabled() { | |
440 // Query the field trial state first, to ensure that UMA reports the cor rect group. | |
441 String fieldTrialGroup = FieldTrialList.findFullName(ICON_NTP_FIELD_TRIA L_NAME); | |
442 CommandLine commandLine = CommandLine.getInstance(); | |
443 if (commandLine.hasSwitch(ChromeSwitches.DISABLE_ICON_NTP)) return false ; | |
444 if (commandLine.hasSwitch(ChromeSwitches.ENABLE_ICON_NTP)) return true; | |
445 return fieldTrialGroup.equals(ICON_NTP_ENABLED_GROUP); | |
446 } | |
447 | |
426 /** @return The view container for the new tab page. */ | 448 /** @return The view container for the new tab page. */ |
427 @VisibleForTesting | 449 @VisibleForTesting |
428 NewTabPageView getNewTabPageView() { | 450 NewTabPageView getNewTabPageView() { |
429 return mNewTabPageView; | 451 return mNewTabPageView; |
430 } | 452 } |
431 | 453 |
432 /** | 454 /** |
433 * Updates whether the NewTabPage should animate on URL focus changes. | 455 * Updates whether the NewTabPage should animate on URL focus changes. |
434 * @param disable Whether to disable the animations. | 456 * @param disable Whether to disable the animations. |
435 */ | 457 */ |
(...skipping 169 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
605 public void onBookmarkSelected(String url, String title, Bitmap favicon) { | 627 public void onBookmarkSelected(String url, String title, Bitmap favicon) { |
606 if (mDialog != null) mDialog.dismiss(); | 628 if (mDialog != null) mDialog.dismiss(); |
607 mTab.loadUrl(new LoadUrlParams(url)); | 629 mTab.loadUrl(new LoadUrlParams(url)); |
608 } | 630 } |
609 | 631 |
610 public void setDialog(Dialog dialog) { | 632 public void setDialog(Dialog dialog) { |
611 mDialog = dialog; | 633 mDialog = dialog; |
612 } | 634 } |
613 } | 635 } |
614 } | 636 } |
OLD | NEW |