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.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.text.TextUtils; | |
| 13 import android.view.ContextMenu; | 14 import android.view.ContextMenu; |
| 14 import android.view.LayoutInflater; | 15 import android.view.LayoutInflater; |
| 15 import android.view.Menu; | 16 import android.view.Menu; |
| 16 import android.view.MenuItem.OnMenuItemClickListener; | 17 import android.view.MenuItem.OnMenuItemClickListener; |
| 17 import android.view.View; | 18 import android.view.View; |
| 18 | 19 |
| 19 import org.chromium.base.ApiCompatibilityUtils; | 20 import org.chromium.base.ApiCompatibilityUtils; |
| 20 import org.chromium.base.VisibleForTesting; | 21 import org.chromium.base.VisibleForTesting; |
| 21 import org.chromium.base.metrics.RecordHistogram; | 22 import org.chromium.base.metrics.RecordHistogram; |
| 22 import org.chromium.base.metrics.RecordUserAction; | 23 import org.chromium.base.metrics.RecordUserAction; |
| (...skipping 25 matching lines...) Expand all Loading... | |
| 48 import org.chromium.chrome.browser.tab.Tab; | 49 import org.chromium.chrome.browser.tab.Tab; |
| 49 import org.chromium.chrome.browser.tabmodel.TabModel.TabLaunchType; | 50 import org.chromium.chrome.browser.tabmodel.TabModel.TabLaunchType; |
| 50 import org.chromium.chrome.browser.tabmodel.TabModelSelector; | 51 import org.chromium.chrome.browser.tabmodel.TabModelSelector; |
| 51 import org.chromium.chrome.browser.util.FeatureUtilities; | 52 import org.chromium.chrome.browser.util.FeatureUtilities; |
| 52 import org.chromium.content_public.browser.LoadUrlParams; | 53 import org.chromium.content_public.browser.LoadUrlParams; |
| 53 import org.chromium.ui.base.DeviceFormFactor; | 54 import org.chromium.ui.base.DeviceFormFactor; |
| 54 import org.chromium.ui.base.PageTransition; | 55 import org.chromium.ui.base.PageTransition; |
| 55 | 56 |
| 56 import java.util.concurrent.TimeUnit; | 57 import java.util.concurrent.TimeUnit; |
| 57 | 58 |
| 59 import jp.tomorrowkey.android.gifplayer.BaseGifImage; | |
| 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 // The number of times that an opt-out promo will be shown. |
| 65 private static final int MAX_OPT_OUT_PROMO_COUNT = 10; | 68 private static final int MAX_OPT_OUT_PROMO_COUNT = 10; |
| 66 | 69 |
| 67 // MostVisitedItem Context menu item IDs. | 70 // MostVisitedItem Context menu item IDs. |
| (...skipping 12 matching lines...) Expand all Loading... | |
| 80 private final int mBackgroundColor; | 83 private final int mBackgroundColor; |
| 81 private final NewTabPageView mNewTabPageView; | 84 private final NewTabPageView mNewTabPageView; |
| 82 | 85 |
| 83 private MostVisitedSites mMostVisitedSites; | 86 private MostVisitedSites mMostVisitedSites; |
| 84 private FaviconHelper mFaviconHelper; | 87 private FaviconHelper mFaviconHelper; |
| 85 private LargeIconBridge mLargeIconBridge; | 88 private LargeIconBridge mLargeIconBridge; |
| 86 private LogoBridge mLogoBridge; | 89 private LogoBridge mLogoBridge; |
| 87 private boolean mSearchProviderHasLogo; | 90 private boolean mSearchProviderHasLogo; |
| 88 private final boolean mOptOutPromoShown; | 91 private final boolean mOptOutPromoShown; |
| 89 private String mOnLogoClickUrl; | 92 private String mOnLogoClickUrl; |
| 93 private String mGifUrl; | |
|
newt (away)
2015/09/18 20:46:02
Call this "mAnimatedLogoUrl". Yes, it's a gif, but
Ian Wen
2015/09/22 21:39:06
Done.
| |
| 90 private FakeboxDelegate mFakeboxDelegate; | 94 private FakeboxDelegate mFakeboxDelegate; |
| 91 | 95 |
| 92 // The timestamp at which the constructor was called. | 96 // The timestamp at which the constructor was called. |
| 93 private final long mConstructedTimeNs; | 97 private final long mConstructedTimeNs; |
| 94 | 98 |
| 95 private boolean mIsLoaded; | 99 private boolean mIsLoaded; |
| 96 | 100 |
| 97 // Whether destroy() has been called. | 101 // Whether destroy() has been called. |
| 98 private boolean mIsDestroyed; | 102 private boolean mIsDestroyed; |
| 99 | 103 |
| (...skipping 245 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 345 FaviconAvailabilityCallback callback) { | 349 FaviconAvailabilityCallback callback) { |
| 346 if (mIsDestroyed) return; | 350 if (mIsDestroyed) return; |
| 347 if (mFaviconHelper == null) mFaviconHelper = new FaviconHelper(); | 351 if (mFaviconHelper == null) mFaviconHelper = new FaviconHelper(); |
| 348 mFaviconHelper.ensureFaviconIsAvailable(mProfile, mTab.getWebContent s(), pageUrl, | 352 mFaviconHelper.ensureFaviconIsAvailable(mProfile, mTab.getWebContent s(), pageUrl, |
| 349 faviconUrl, callback); | 353 faviconUrl, callback); |
| 350 } | 354 } |
| 351 | 355 |
| 352 @Override | 356 @Override |
| 353 public void openLogoLink() { | 357 public void openLogoLink() { |
| 354 if (mIsDestroyed) return; | 358 if (mIsDestroyed) return; |
| 355 if (mOnLogoClickUrl == null) return; | 359 if (mOnLogoClickUrl == null) return; |
|
newt (away)
2015/09/18 20:46:02
This check should be moved inside the if clause be
Ian Wen
2015/09/22 21:39:06
Done.
| |
| 356 mTab.loadUrl(new LoadUrlParams(mOnLogoClickUrl, PageTransition.LINK) ); | 360 |
| 361 if (TextUtils.isEmpty(mGifUrl) || mNewTabPageView.isGifPlaying()) { | |
|
newt (away)
2015/09/18 20:46:02
I'd rename this method to onLogoClicked() since it
Ian Wen
2015/09/22 21:39:06
Done.
| |
| 362 mTab.loadUrl(new LoadUrlParams(mOnLogoClickUrl, PageTransition.L INK)); | |
| 363 } else { | |
| 364 mLogoBridge.getGif(new LogoBridge.GifListener() { | |
| 365 @Override | |
| 366 public void onGifDownloaded(byte[] bytes) { | |
|
newt (away)
2015/09/18 20:46:02
add "if (mIsDestroyed) return;" or "assert !mIsDes
Ian Wen
2015/09/22 21:39:06
Done.
| |
| 367 mNewTabPageView.updateLogoGif(new BaseGifImage(bytes)); | |
| 368 } | |
| 369 }, mGifUrl); | |
| 370 } | |
| 357 } | 371 } |
| 358 | 372 |
| 359 @Override | 373 @Override |
| 360 public void getSearchProviderLogo(final LogoObserver logoObserver) { | 374 public void getSearchProviderLogo(final LogoObserver logoObserver) { |
| 361 if (mIsDestroyed) return; | 375 if (mIsDestroyed) return; |
| 362 LogoObserver wrapperCallback = new LogoObserver() { | 376 LogoObserver wrapperCallback = new LogoObserver() { |
| 363 @Override | 377 @Override |
| 364 public void onLogoAvailable(Logo logo, boolean fromCache) { | 378 public void onLogoAvailable(Logo logo, boolean fromCache) { |
| 365 if (mIsDestroyed) return; | 379 if (mIsDestroyed) return; |
| 366 mOnLogoClickUrl = logo != null ? logo.onClickUrl : null; | 380 mOnLogoClickUrl = logo != null ? logo.onClickUrl : null; |
| 381 mGifUrl = logo != null ? logo.gifUrl : null; | |
| 367 logoObserver.onLogoAvailable(logo, fromCache); | 382 logoObserver.onLogoAvailable(logo, fromCache); |
| 368 } | 383 } |
| 369 }; | 384 }; |
| 370 mLogoBridge.getCurrentLogo(wrapperCallback); | 385 mLogoBridge.getCurrentLogo(wrapperCallback); |
| 371 } | 386 } |
| 372 | 387 |
| 373 @Override | 388 @Override |
| 374 public void onLoadingComplete() { | 389 public void onLoadingComplete() { |
| 375 long loadTimeMs = (System.nanoTime() - mConstructedTimeNs) / 1000000 ; | 390 long loadTimeMs = (System.nanoTime() - mConstructedTimeNs) / 1000000 ; |
| 376 RecordHistogram.recordTimesHistogram( | 391 RecordHistogram.recordTimesHistogram( |
| (...skipping 228 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 605 public void onBookmarkSelected(String url, String title, Bitmap favicon) { | 620 public void onBookmarkSelected(String url, String title, Bitmap favicon) { |
| 606 if (mDialog != null) mDialog.dismiss(); | 621 if (mDialog != null) mDialog.dismiss(); |
| 607 mTab.loadUrl(new LoadUrlParams(url)); | 622 mTab.loadUrl(new LoadUrlParams(url)); |
| 608 } | 623 } |
| 609 | 624 |
| 610 public void setDialog(Dialog dialog) { | 625 public void setDialog(Dialog dialog) { |
| 611 mDialog = dialog; | 626 mDialog = dialog; |
| 612 } | 627 } |
| 613 } | 628 } |
| 614 } | 629 } |
| OLD | NEW |