| 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.app.Activity; | 8 import android.app.Activity; |
| 9 import android.app.ActivityManager; | 9 import android.app.ActivityManager; |
| 10 import android.app.Dialog; | 10 import android.app.Dialog; |
| 11 import android.content.Context; | 11 import android.content.Context; |
| 12 import android.content.Intent; | 12 import android.content.Intent; |
| 13 import android.graphics.Canvas; | 13 import android.graphics.Canvas; |
| 14 import android.graphics.Color; | 14 import android.graphics.Color; |
| 15 import android.graphics.Rect; | 15 import android.graphics.Rect; |
| 16 import android.os.Build; | 16 import android.os.Build; |
| 17 import android.view.ContextMenu; | 17 import android.view.ContextMenu; |
| 18 import android.view.LayoutInflater; | 18 import android.view.LayoutInflater; |
| 19 import android.view.Menu; | 19 import android.view.Menu; |
| 20 import android.view.MenuItem.OnMenuItemClickListener; | 20 import android.view.MenuItem.OnMenuItemClickListener; |
| 21 import android.view.View; | 21 import android.view.View; |
| 22 | 22 |
| 23 import org.chromium.base.ApiCompatibilityUtils; | 23 import org.chromium.base.ApiCompatibilityUtils; |
| 24 import org.chromium.base.CommandLine; | 24 import org.chromium.base.CommandLine; |
| 25 import org.chromium.base.VisibleForTesting; | 25 import org.chromium.base.VisibleForTesting; |
| 26 import org.chromium.base.metrics.RecordHistogram; | 26 import org.chromium.base.metrics.RecordHistogram; |
| 27 import org.chromium.base.metrics.RecordUserAction; | 27 import org.chromium.base.metrics.RecordUserAction; |
| 28 import org.chromium.chrome.R; | 28 import org.chromium.chrome.R; |
| 29 import org.chromium.chrome.browser.ChromeApplication; | 29 import org.chromium.chrome.browser.ChromeApplication; |
| 30 import org.chromium.chrome.browser.ChromeFeatureList; |
| 30 import org.chromium.chrome.browser.ChromeSwitches; | 31 import org.chromium.chrome.browser.ChromeSwitches; |
| 31 import org.chromium.chrome.browser.NativePage; | 32 import org.chromium.chrome.browser.NativePage; |
| 32 import org.chromium.chrome.browser.UrlConstants; | 33 import org.chromium.chrome.browser.UrlConstants; |
| 33 import org.chromium.chrome.browser.compositor.layouts.content.InvalidationAwareT
humbnailProvider; | 34 import org.chromium.chrome.browser.compositor.layouts.content.InvalidationAwareT
humbnailProvider; |
| 34 import org.chromium.chrome.browser.document.DocumentMetricIds; | 35 import org.chromium.chrome.browser.document.DocumentMetricIds; |
| 35 import org.chromium.chrome.browser.document.DocumentUtils; | 36 import org.chromium.chrome.browser.document.DocumentUtils; |
| 36 import org.chromium.chrome.browser.enhancedbookmarks.EnhancedBookmarkUtils; | 37 import org.chromium.chrome.browser.enhancedbookmarks.EnhancedBookmarkUtils; |
| 37 import org.chromium.chrome.browser.favicon.FaviconHelper; | 38 import org.chromium.chrome.browser.favicon.FaviconHelper; |
| 38 import org.chromium.chrome.browser.favicon.FaviconHelper.FaviconImageCallback; | 39 import org.chromium.chrome.browser.favicon.FaviconHelper.FaviconImageCallback; |
| 39 import org.chromium.chrome.browser.favicon.FaviconHelper.IconAvailabilityCallbac
k; | 40 import org.chromium.chrome.browser.favicon.FaviconHelper.IconAvailabilityCallbac
k; |
| (...skipping 163 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 203 manager.setDialog(dialog); | 204 manager.setDialog(dialog); |
| 204 dialog.show(); | 205 dialog.show(); |
| 205 } | 206 } |
| 206 | 207 |
| 207 @VisibleForTesting | 208 @VisibleForTesting |
| 208 static void setMostVisitedSitesForTests(MostVisitedSites mostVisitedSitesFor
Tests) { | 209 static void setMostVisitedSitesForTests(MostVisitedSites mostVisitedSitesFor
Tests) { |
| 209 sMostVisitedSitesForTests = mostVisitedSitesForTests; | 210 sMostVisitedSitesForTests = mostVisitedSitesForTests; |
| 210 } | 211 } |
| 211 | 212 |
| 212 private final NewTabPageManager mNewTabPageManager = new NewTabPageManager()
{ | 213 private final NewTabPageManager mNewTabPageManager = new NewTabPageManager()
{ |
| 214 private static final String NTP_OFFLINE_PAGES_FEATURE_NAME = "NTPOffline
Pages"; |
| 215 |
| 216 private boolean isNtpOfflinePagesEnabled() { |
| 217 return OfflinePageBridge.isEnabled() |
| 218 && ChromeFeatureList.isEnabled(NTP_OFFLINE_PAGES_FEATURE_NAM
E); |
| 219 } |
| 220 |
| 213 @Override | 221 @Override |
| 214 public boolean isLocationBarShownInNTP() { | 222 public boolean isLocationBarShownInNTP() { |
| 215 if (mIsDestroyed) return false; | 223 if (mIsDestroyed) return false; |
| 216 Context context = mNewTabPageView.getContext(); | 224 Context context = mNewTabPageView.getContext(); |
| 217 return isInSingleUrlBarMode(context) | 225 return isInSingleUrlBarMode(context) |
| 218 && !mNewTabPageView.urlFocusAnimationsDisabled(); | 226 && !mNewTabPageView.urlFocusAnimationsDisabled(); |
| 219 } | 227 } |
| 220 | 228 |
| 221 @Override | 229 @Override |
| 222 public boolean isVoiceSearchEnabled() { | 230 public boolean isVoiceSearchEnabled() { |
| (...skipping 214 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 437 public void ensureIconIsAvailable(String pageUrl, String iconUrl, boolea
n isLargeIcon, | 445 public void ensureIconIsAvailable(String pageUrl, String iconUrl, boolea
n isLargeIcon, |
| 438 IconAvailabilityCallback callback) { | 446 IconAvailabilityCallback callback) { |
| 439 if (mIsDestroyed) return; | 447 if (mIsDestroyed) return; |
| 440 if (mFaviconHelper == null) mFaviconHelper = new FaviconHelper(); | 448 if (mFaviconHelper == null) mFaviconHelper = new FaviconHelper(); |
| 441 mFaviconHelper.ensureIconIsAvailable( | 449 mFaviconHelper.ensureIconIsAvailable( |
| 442 mProfile, mTab.getWebContents(), pageUrl, iconUrl, isLargeIc
on, callback); | 450 mProfile, mTab.getWebContents(), pageUrl, iconUrl, isLargeIc
on, callback); |
| 443 } | 451 } |
| 444 | 452 |
| 445 @Override | 453 @Override |
| 446 public boolean isOfflineAvailable(String pageUrl) { | 454 public boolean isOfflineAvailable(String pageUrl) { |
| 447 if (mIsDestroyed || !OfflinePageBridge.isEnabled()) return false; | 455 if (mIsDestroyed || !isNtpOfflinePagesEnabled()) return false; |
| 448 if (mOfflinePageBridge == null) mOfflinePageBridge = new OfflinePage
Bridge(mProfile); | 456 if (mOfflinePageBridge == null) mOfflinePageBridge = new OfflinePage
Bridge(mProfile); |
| 449 return mOfflinePageBridge.getPageByOnlineURL(pageUrl) != null; | 457 return mOfflinePageBridge.getPageByOnlineURL(pageUrl) != null; |
| 450 } | 458 } |
| 451 | 459 |
| 452 @Override | 460 @Override |
| 453 public void onLogoClicked(boolean isAnimatedLogoShowing) { | 461 public void onLogoClicked(boolean isAnimatedLogoShowing) { |
| 454 if (mIsDestroyed) return; | 462 if (mIsDestroyed) return; |
| 455 | 463 |
| 456 if (!isAnimatedLogoShowing && mAnimatedLogoUrl != null) { | 464 if (!isAnimatedLogoShowing && mAnimatedLogoUrl != null) { |
| 457 mNewTabPageView.showLogoLoadingView(); | 465 mNewTabPageView.showLogoLoadingView(); |
| (...skipping 295 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 753 @Override | 761 @Override |
| 754 public boolean shouldCaptureThumbnail() { | 762 public boolean shouldCaptureThumbnail() { |
| 755 return mNewTabPageView.shouldCaptureThumbnail(); | 763 return mNewTabPageView.shouldCaptureThumbnail(); |
| 756 } | 764 } |
| 757 | 765 |
| 758 @Override | 766 @Override |
| 759 public void captureThumbnail(Canvas canvas) { | 767 public void captureThumbnail(Canvas canvas) { |
| 760 mNewTabPageView.captureThumbnail(canvas); | 768 mNewTabPageView.captureThumbnail(canvas); |
| 761 } | 769 } |
| 762 } | 770 } |
| OLD | NEW |