Chromium Code Reviews| 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.annotation.TargetApi; | 7 import android.annotation.TargetApi; |
| 8 import android.content.Context; | 8 import android.content.Context; |
| 9 import android.graphics.Canvas; | 9 import android.graphics.Canvas; |
| 10 import android.graphics.Point; | 10 import android.graphics.Point; |
| (...skipping 21 matching lines...) Expand all Loading... | |
| 32 import org.chromium.chrome.browser.UrlConstants; | 32 import org.chromium.chrome.browser.UrlConstants; |
| 33 import org.chromium.chrome.browser.compositor.layouts.content.InvalidationAwareT humbnailProvider; | 33 import org.chromium.chrome.browser.compositor.layouts.content.InvalidationAwareT humbnailProvider; |
| 34 import org.chromium.chrome.browser.download.DownloadManagerService; | 34 import org.chromium.chrome.browser.download.DownloadManagerService; |
| 35 import org.chromium.chrome.browser.metrics.StartupMetrics; | 35 import org.chromium.chrome.browser.metrics.StartupMetrics; |
| 36 import org.chromium.chrome.browser.ntp.NewTabPageView.NewTabPageManager; | 36 import org.chromium.chrome.browser.ntp.NewTabPageView.NewTabPageManager; |
| 37 import org.chromium.chrome.browser.ntp.snippets.SnippetsBridge; | 37 import org.chromium.chrome.browser.ntp.snippets.SnippetsBridge; |
| 38 import org.chromium.chrome.browser.ntp.snippets.SuggestionsSource; | 38 import org.chromium.chrome.browser.ntp.snippets.SuggestionsSource; |
| 39 import org.chromium.chrome.browser.profiles.Profile; | 39 import org.chromium.chrome.browser.profiles.Profile; |
| 40 import org.chromium.chrome.browser.search_engines.TemplateUrlService; | 40 import org.chromium.chrome.browser.search_engines.TemplateUrlService; |
| 41 import org.chromium.chrome.browser.search_engines.TemplateUrlService.TemplateUrl ServiceObserver; | 41 import org.chromium.chrome.browser.search_engines.TemplateUrlService.TemplateUrl ServiceObserver; |
| 42 import org.chromium.chrome.browser.suggestions.SuggestionsMetricsReporter; | 42 import org.chromium.chrome.browser.suggestions.SuggestionsEventReporter; |
| 43 import org.chromium.chrome.browser.suggestions.SuggestionsEventReporterBridge; | |
| 43 import org.chromium.chrome.browser.suggestions.SuggestionsNavigationDelegate; | 44 import org.chromium.chrome.browser.suggestions.SuggestionsNavigationDelegate; |
| 44 import org.chromium.chrome.browser.suggestions.SuggestionsNavigationDelegateImpl ; | 45 import org.chromium.chrome.browser.suggestions.SuggestionsNavigationDelegateImpl ; |
| 45 import org.chromium.chrome.browser.suggestions.SuggestionsUiDelegateImpl; | 46 import org.chromium.chrome.browser.suggestions.SuggestionsUiDelegateImpl; |
| 46 import org.chromium.chrome.browser.suggestions.Tile; | 47 import org.chromium.chrome.browser.suggestions.Tile; |
| 47 import org.chromium.chrome.browser.suggestions.TileGroup; | 48 import org.chromium.chrome.browser.suggestions.TileGroup; |
| 48 import org.chromium.chrome.browser.suggestions.TileGroupDelegateImpl; | 49 import org.chromium.chrome.browser.suggestions.TileGroupDelegateImpl; |
| 49 import org.chromium.chrome.browser.sync.SyncSessionsMetrics; | 50 import org.chromium.chrome.browser.sync.SyncSessionsMetrics; |
| 50 import org.chromium.chrome.browser.tab.EmptyTabObserver; | 51 import org.chromium.chrome.browser.tab.EmptyTabObserver; |
| 51 import org.chromium.chrome.browser.tab.Tab; | 52 import org.chromium.chrome.browser.tab.Tab; |
| 52 import org.chromium.chrome.browser.tab.TabObserver; | 53 import org.chromium.chrome.browser.tab.TabObserver; |
| (...skipping 114 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 167 } | 168 } |
| 168 | 169 |
| 169 @VisibleForTesting | 170 @VisibleForTesting |
| 170 public static void setSuggestionsSourceForTests(SuggestionsSource suggestion sSource) { | 171 public static void setSuggestionsSourceForTests(SuggestionsSource suggestion sSource) { |
| 171 sSuggestionsSourceForTests = suggestionsSource; | 172 sSuggestionsSourceForTests = suggestionsSource; |
| 172 } | 173 } |
| 173 | 174 |
| 174 private class NewTabPageManagerImpl | 175 private class NewTabPageManagerImpl |
| 175 extends SuggestionsUiDelegateImpl implements NewTabPageManager { | 176 extends SuggestionsUiDelegateImpl implements NewTabPageManager { |
| 176 public NewTabPageManagerImpl(SuggestionsSource suggestionsSource, | 177 public NewTabPageManagerImpl(SuggestionsSource suggestionsSource, |
| 177 SuggestionsMetricsReporter metricsReporter, | 178 SuggestionsEventReporter eventReporter, |
| 178 SuggestionsNavigationDelegate navigationDelegate, Profile profil e, | 179 SuggestionsNavigationDelegate navigationDelegate, Profile profil e, |
| 179 NativePageHost nativePageHost) { | 180 NativePageHost nativePageHost) { |
| 180 super(suggestionsSource, metricsReporter, navigationDelegate, profil e, nativePageHost); | 181 super(suggestionsSource, eventReporter, navigationDelegate, profile, nativePageHost); |
| 181 } | 182 } |
| 182 | 183 |
| 183 @Override | 184 @Override |
| 184 public boolean isLocationBarShownInNTP() { | 185 public boolean isLocationBarShownInNTP() { |
| 185 if (mIsDestroyed) return false; | 186 if (mIsDestroyed) return false; |
| 186 Context context = mNewTabPageView.getContext(); | 187 Context context = mNewTabPageView.getContext(); |
| 187 return isInSingleUrlBarMode(context) | 188 return isInSingleUrlBarMode(context) |
| 188 && !mNewTabPageView.urlFocusAnimationsDisabled(); | 189 && !mNewTabPageView.urlFocusAnimationsDisabled(); |
| 189 } | 190 } |
| 190 | 191 |
| (...skipping 117 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 308 public NewTabPage(ChromeActivity activity, NativePageHost nativePageHost, | 309 public NewTabPage(ChromeActivity activity, NativePageHost nativePageHost, |
| 309 TabModelSelector tabModelSelector) { | 310 TabModelSelector tabModelSelector) { |
| 310 mConstructedTimeNs = System.nanoTime(); | 311 mConstructedTimeNs = System.nanoTime(); |
| 311 TraceEvent.begin(TAG); | 312 TraceEvent.begin(TAG); |
| 312 | 313 |
| 313 mTab = nativePageHost.getActiveTab(); | 314 mTab = nativePageHost.getActiveTab(); |
| 314 mTabModelSelector = tabModelSelector; | 315 mTabModelSelector = tabModelSelector; |
| 315 Profile profile = mTab.getProfile(); | 316 Profile profile = mTab.getProfile(); |
| 316 | 317 |
| 317 mSnippetsBridge = new SnippetsBridge(profile); | 318 mSnippetsBridge = new SnippetsBridge(profile); |
| 319 SuggestionsEventReporter eventReporter = new SuggestionsEventReporterBri dge(); | |
| 318 | 320 |
| 319 SuggestionsNavigationDelegateImpl navigationDelegate = | 321 SuggestionsNavigationDelegateImpl navigationDelegate = |
| 320 new SuggestionsNavigationDelegateImpl( | 322 new SuggestionsNavigationDelegateImpl( |
| 321 activity, profile, nativePageHost, tabModelSelector); | 323 activity, profile, nativePageHost, tabModelSelector); |
| 322 mNewTabPageManager = new NewTabPageManagerImpl( | 324 mNewTabPageManager = new NewTabPageManagerImpl( |
| 323 mSnippetsBridge, mSnippetsBridge, navigationDelegate, profile, n ativePageHost); | 325 mSnippetsBridge, eventReporter, navigationDelegate, profile, nat ivePageHost); |
| 324 mTileGroupDelegate = new NewTabPageTileGroupDelegate( | 326 mTileGroupDelegate = new NewTabPageTileGroupDelegate( |
| 325 activity, profile, tabModelSelector, navigationDelegate); | 327 activity, profile, tabModelSelector, navigationDelegate); |
| 326 | 328 |
| 327 mTitle = activity.getResources().getString(R.string.button_new_tab); | 329 mTitle = activity.getResources().getString(R.string.button_new_tab); |
| 328 mBackgroundColor = ApiCompatibilityUtils.getColor(activity.getResources( ), R.color.ntp_bg); | 330 mBackgroundColor = ApiCompatibilityUtils.getColor(activity.getResources( ), R.color.ntp_bg); |
| 329 mThemeColor = ApiCompatibilityUtils.getColor( | 331 mThemeColor = ApiCompatibilityUtils.getColor( |
| 330 activity.getResources(), R.color.default_primary_color); | 332 activity.getResources(), R.color.default_primary_color); |
| 331 TemplateUrlService.getInstance().addObserver(this); | 333 TemplateUrlService.getInstance().addObserver(this); |
| 332 | 334 |
| 333 mTabObserver = new EmptyTabObserver() { | 335 mTabObserver = new EmptyTabObserver() { |
| (...skipping 34 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 368 } | 370 } |
| 369 }; | 371 }; |
| 370 mTab.addObserver(mTabObserver); | 372 mTab.addObserver(mTabObserver); |
| 371 updateSearchProviderHasLogo(); | 373 updateSearchProviderHasLogo(); |
| 372 | 374 |
| 373 LayoutInflater inflater = LayoutInflater.from(activity); | 375 LayoutInflater inflater = LayoutInflater.from(activity); |
| 374 mNewTabPageView = (NewTabPageView) inflater.inflate(R.layout.new_tab_pag e_view, null); | 376 mNewTabPageView = (NewTabPageView) inflater.inflate(R.layout.new_tab_pag e_view, null); |
| 375 mNewTabPageView.initialize(mNewTabPageManager, mTab, mTileGroupDelegate, | 377 mNewTabPageView.initialize(mNewTabPageManager, mTab, mTileGroupDelegate, |
| 376 mSearchProviderHasLogo, getScrollPositionFromNavigationEntry()); | 378 mSearchProviderHasLogo, getScrollPositionFromNavigationEntry()); |
| 377 | 379 |
| 378 if (mSnippetsBridge != null) { | 380 eventReporter.onSurfaceOpened(); |
|
Bernhard Bauer
2017/04/27 11:55:16
Huh, I think that check was unnecessary anyway.
| |
| 379 mSnippetsBridge.onNtpInitialized(); | |
| 380 } | |
| 381 | 381 |
| 382 DownloadManagerService.getDownloadManagerService().checkForExternallyRem ovedDownloads( | 382 DownloadManagerService.getDownloadManagerService().checkForExternallyRem ovedDownloads( |
| 383 /*isOffRecord=*/false); | 383 /*isOffRecord=*/false); |
| 384 | 384 |
| 385 RecordHistogram.recordBooleanHistogram( | 385 RecordHistogram.recordBooleanHistogram( |
| 386 "NewTabPage.MobileIsUserOnline", NetworkChangeNotifier.isOnline( )); | 386 "NewTabPage.MobileIsUserOnline", NetworkChangeNotifier.isOnline( )); |
| 387 NewTabPageUma.recordLoadType(activity); | 387 NewTabPageUma.recordLoadType(activity); |
| 388 TraceEvent.end(TAG); | 388 TraceEvent.end(TAG); |
| 389 } | 389 } |
| 390 | 390 |
| (...skipping 215 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 606 @Override | 606 @Override |
| 607 public boolean shouldCaptureThumbnail() { | 607 public boolean shouldCaptureThumbnail() { |
| 608 return mNewTabPageView.shouldCaptureThumbnail(); | 608 return mNewTabPageView.shouldCaptureThumbnail(); |
| 609 } | 609 } |
| 610 | 610 |
| 611 @Override | 611 @Override |
| 612 public void captureThumbnail(Canvas canvas) { | 612 public void captureThumbnail(Canvas canvas) { |
| 613 mNewTabPageView.captureThumbnail(canvas); | 613 mNewTabPageView.captureThumbnail(canvas); |
| 614 } | 614 } |
| 615 } | 615 } |
| OLD | NEW |