Chromium Code Reviews| OLD | NEW |
|---|---|
| 1 // Copyright 2016 The Chromium Authors. All rights reserved. | 1 // Copyright 2016 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.suggestions; | 5 package org.chromium.chrome.browser.suggestions; |
| 6 | 6 |
| 7 import android.content.Context; | |
| 8 import android.content.Intent; | 7 import android.content.Intent; |
| 9 import android.os.Bundle; | 8 import android.os.Bundle; |
| 10 import android.view.LayoutInflater; | 9 import android.view.LayoutInflater; |
| 11 import android.view.Menu; | 10 import android.view.Menu; |
| 12 | 11 |
| 13 import org.chromium.base.Callback; | |
| 14 import org.chromium.base.ObserverList; | |
| 15 import org.chromium.chrome.R; | 12 import org.chromium.chrome.R; |
| 13 import org.chromium.chrome.browser.ChromeActivity; | |
| 16 import org.chromium.chrome.browser.ChromeFeatureList; | 14 import org.chromium.chrome.browser.ChromeFeatureList; |
| 17 import org.chromium.chrome.browser.SynchronousInitializationActivity; | 15 import org.chromium.chrome.browser.SynchronousInitializationActivity; |
| 18 import org.chromium.chrome.browser.favicon.FaviconHelper.FaviconImageCallback; | |
| 19 import org.chromium.chrome.browser.favicon.FaviconHelper.IconAvailabilityCallbac k; | |
| 20 import org.chromium.chrome.browser.favicon.LargeIconBridge.LargeIconCallback; | |
| 21 import org.chromium.chrome.browser.ntp.ContextMenuManager; | 16 import org.chromium.chrome.browser.ntp.ContextMenuManager; |
| 22 import org.chromium.chrome.browser.ntp.LogoBridge.LogoObserver; | |
| 23 import org.chromium.chrome.browser.ntp.MostVisitedItem; | |
| 24 import org.chromium.chrome.browser.ntp.NewTabPage.DestructionObserver; | 17 import org.chromium.chrome.browser.ntp.NewTabPage.DestructionObserver; |
| 25 import org.chromium.chrome.browser.ntp.NewTabPageView.NewTabPageManager; | |
| 26 import org.chromium.chrome.browser.ntp.UiConfig; | 18 import org.chromium.chrome.browser.ntp.UiConfig; |
| 27 import org.chromium.chrome.browser.ntp.cards.NewTabPageAdapter; | 19 import org.chromium.chrome.browser.ntp.cards.NewTabPageAdapter; |
| 28 import org.chromium.chrome.browser.ntp.cards.NewTabPageRecyclerView; | 20 import org.chromium.chrome.browser.ntp.cards.NewTabPageRecyclerView; |
| 29 import org.chromium.chrome.browser.ntp.snippets.SnippetArticle; | |
| 30 import org.chromium.chrome.browser.ntp.snippets.SnippetsBridge; | 21 import org.chromium.chrome.browser.ntp.snippets.SnippetsBridge; |
| 31 import org.chromium.chrome.browser.ntp.snippets.SuggestionsSource; | |
| 32 import org.chromium.chrome.browser.offlinepages.OfflinePageBridge; | 22 import org.chromium.chrome.browser.offlinepages.OfflinePageBridge; |
| 33 import org.chromium.chrome.browser.profiles.MostVisitedSites.MostVisitedURLsObse rver; | |
| 34 import org.chromium.chrome.browser.profiles.Profile; | 23 import org.chromium.chrome.browser.profiles.Profile; |
| 24 import org.chromium.chrome.browser.tab.Tab; | |
| 25 import org.chromium.chrome.browser.tabmodel.TabModelSelector; | |
| 35 | 26 |
| 36 import java.util.Set; | 27 import java.lang.ref.WeakReference; |
| 37 | 28 |
| 38 /** | 29 /** |
| 39 * Experimental activity to show content suggestions outside of the New Tab Page . | 30 * Experimental activity to show content suggestions outside of the New Tab Page . |
| 40 */ | 31 */ |
| 41 public class ContentSuggestionsActivity extends SynchronousInitializationActivit y { | 32 public class ContentSuggestionsActivity extends SynchronousInitializationActivit y { |
| 42 private final ObserverList<DestructionObserver> mDestructionObservers = new ObserverList<>(); | 33 private static WeakReference<ChromeActivity> sCallerActivity; |
| 43 | 34 |
| 44 private ContextMenuManager mContextMenuManager; | 35 private ContextMenuManager mContextMenuManager; |
| 45 private SnippetsBridge mSnippetsBridge; | 36 private SuggestionsUiDelegateImpl mSuggestionsManager; |
| 46 private NewTabPageRecyclerView mRecyclerView; | |
| 47 | 37 |
| 48 public static void launch(Context context) { | 38 public static void launch(ChromeActivity activity) { |
| 39 sCallerActivity = new WeakReference<>(activity); | |
| 40 | |
| 49 Intent intent = new Intent(); | 41 Intent intent = new Intent(); |
| 50 intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK); | 42 intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK); |
| 51 intent.setClass(context, ContentSuggestionsActivity.class); | 43 intent.setClass(activity, ContentSuggestionsActivity.class); |
| 52 context.startActivity(intent); | 44 activity.startActivity(intent); |
| 53 } | |
| 54 | |
| 55 private class SuggestionsNewTabPageManager implements NewTabPageManager { | |
| 56 @Override | |
| 57 public void removeMostVisitedItem(MostVisitedItem item) {} | |
| 58 | |
| 59 @Override | |
| 60 public void openMostVisitedItem(int windowDisposition, MostVisitedItem i tem) {} | |
| 61 | |
| 62 @Override | |
| 63 public boolean isLocationBarShownInNTP() { | |
| 64 return false; | |
| 65 } | |
| 66 | |
| 67 @Override | |
| 68 public boolean isVoiceSearchEnabled() { | |
| 69 return false; | |
| 70 } | |
| 71 | |
| 72 @Override | |
| 73 public boolean isFakeOmniboxTextEnabledTablet() { | |
| 74 return false; | |
| 75 } | |
| 76 | |
| 77 @Override | |
| 78 public boolean isOpenInNewWindowEnabled() { | |
| 79 return true; | |
| 80 } | |
| 81 | |
| 82 @Override | |
| 83 public boolean isOpenInIncognitoEnabled() { | |
| 84 return true; | |
| 85 } | |
| 86 | |
| 87 @Override | |
| 88 public void navigateToBookmarks() {} | |
| 89 | |
| 90 @Override | |
| 91 public void navigateToRecentTabs() {} | |
| 92 | |
| 93 @Override | |
| 94 public void navigateToDownloadManager() {} | |
| 95 | |
| 96 @Override | |
| 97 public void openSnippet(int windowOpenDisposition, SnippetArticle articl e) {} | |
| 98 | |
| 99 @Override | |
| 100 public void focusSearchBox(boolean beginVoiceSearch, String pastedText) {} | |
| 101 | |
| 102 @Override | |
| 103 public void setMostVisitedURLsObserver(MostVisitedURLsObserver observer, int numResults) {} | |
| 104 | |
| 105 @Override | |
| 106 public void getLocalFaviconImageForURL( | |
| 107 String url, int size, FaviconImageCallback faviconCallback) {} | |
| 108 | |
| 109 @Override | |
| 110 public void getLargeIconForUrl(String url, int size, LargeIconCallback c allback) {} | |
| 111 | |
| 112 @Override | |
| 113 public void ensureIconIsAvailable(String pageUrl, String iconUrl, boolea n isLargeIcon, | |
| 114 boolean isTemporary, IconAvailabilityCallback callback) {} | |
| 115 | |
| 116 @Override | |
| 117 public void getUrlsAvailableOffline(Set<String> pageUrls, Callback<Set<S tring>> callback) {} | |
| 118 | |
| 119 @Override | |
| 120 public void onLogoClicked(boolean isAnimatedLogoShowing) {} | |
| 121 | |
| 122 @Override | |
| 123 public void getSearchProviderLogo(LogoObserver logoObserver) {} | |
| 124 | |
| 125 @Override | |
| 126 public void onLoadingComplete(MostVisitedItem[] mostVisitedItems) {} | |
| 127 | |
| 128 @Override | |
| 129 public void onLearnMoreClicked() {} | |
| 130 | |
| 131 @Override | |
| 132 public SuggestionsSource getSuggestionsSource() { | |
| 133 return mSnippetsBridge; | |
| 134 } | |
| 135 | |
| 136 @Override | |
| 137 public void addDestructionObserver(DestructionObserver destructionObserv er) { | |
| 138 mDestructionObservers.addObserver(destructionObserver); | |
| 139 } | |
| 140 | |
| 141 @Override | |
| 142 public boolean isCurrentPage() { | |
| 143 return true; | |
| 144 } | |
| 145 | |
| 146 @Override | |
| 147 public ContextMenuManager getContextMenuManager() { | |
| 148 return mContextMenuManager; | |
| 149 } | |
| 150 | |
| 151 @Override | |
| 152 public SuggestionsMetricsReporter getSuggestionsMetricsReporter() { | |
| 153 return mSnippetsBridge; | |
| 154 } | |
| 155 } | 45 } |
| 156 | 46 |
| 157 @Override | 47 @Override |
| 158 protected void onCreate(Bundle savedInstanceState) { | 48 protected void onCreate(Bundle savedInstanceState) { |
| 159 super.onCreate(savedInstanceState); | 49 super.onCreate(savedInstanceState); |
| 160 | 50 |
| 161 assert ChromeFeatureList.isEnabled(ChromeFeatureList.NTP_SUGGESTIONS_STA NDALONE_UI); | 51 assert ChromeFeatureList.isEnabled(ChromeFeatureList.NTP_SUGGESTIONS_STA NDALONE_UI); |
| 162 | 52 |
| 163 mRecyclerView = (NewTabPageRecyclerView) LayoutInflater.from(this).infla te( | 53 NewTabPageRecyclerView recyclerView = |
| 164 R.layout.new_tab_page_recycler_view, null, false); | 54 (NewTabPageRecyclerView) LayoutInflater.from(this).inflate( |
| 55 R.layout.new_tab_page_recycler_view, null, false); | |
| 165 | 56 |
| 166 Profile profile = Profile.getLastUsedProfile(); | 57 Profile profile = Profile.getLastUsedProfile(); |
| 167 mSnippetsBridge = new SnippetsBridge(profile); | 58 UiConfig uiConfig = new UiConfig(recyclerView); |
| 168 | 59 |
| 169 NewTabPageManager manager = new SuggestionsNewTabPageManager(); | 60 // TODO(dgn): properly handle retrieving the tab information, or the bas e activity being |
| 170 mContextMenuManager = new ContextMenuManager(this, manager, mRecyclerVie w); | 61 // destroyed. |
|
Bernhard Bauer
2017/01/16 11:08:37
I think this is causing a FindBugs error during bu
dgn
2017/01/18 16:22:27
added an assert. Will look at the actual issue bet
| |
| 171 UiConfig uiConfig = new UiConfig(mRecyclerView); | 62 Tab currentTab = sCallerActivity.get().getActivityTab(); |
| 172 NewTabPageAdapter adapter = new NewTabPageAdapter( | 63 TabModelSelector tabModelSelector = sCallerActivity.get().getTabModelSel ector(); |
| 173 manager, null, uiConfig, OfflinePageBridge.getForProfile(profile )); | |
| 174 mRecyclerView.setAdapter(adapter); | |
| 175 mRecyclerView.setUpSwipeToDismiss(); | |
| 176 | 64 |
| 177 setContentView(mRecyclerView); | 65 final SnippetsBridge snippetsBridge = new SnippetsBridge(profile); |
| 66 SuggestionsNavigationDelegateImpl navigationDelegate = | |
| 67 new SuggestionsNavigationDelegateImpl(this, profile, currentTab, tabModelSelector); | |
| 68 | |
| 69 mSuggestionsManager = new SuggestionsUiDelegateImpl( | |
| 70 snippetsBridge, snippetsBridge, navigationDelegate, profile, cur rentTab); | |
| 71 | |
| 72 mSuggestionsManager.addDestructionObserver(new DestructionObserver() { | |
| 73 @Override | |
| 74 public void onDestroy() { | |
| 75 snippetsBridge.destroy(); | |
|
Bernhard Bauer
2017/01/16 11:08:37
Can't we just destroy the SnippetsBridge in our ow
dgn
2017/01/18 16:22:27
Means then that we need to make it a member... I m
dgn
2017/01/18 18:00:26
Used a member and the old #destroy() method in the
| |
| 76 } | |
| 77 }); | |
| 78 mSuggestionsManager.addDestructionObserver(navigationDelegate); | |
| 79 mContextMenuManager = new ContextMenuManager(this, navigationDelegate, r ecyclerView); | |
| 80 | |
| 81 NewTabPageAdapter adapter = new NewTabPageAdapter(mSuggestionsManager, n ull, uiConfig, | |
| 82 OfflinePageBridge.getForProfile(profile), mContextMenuManager); | |
| 83 recyclerView.setAdapter(adapter); | |
| 84 recyclerView.setUpSwipeToDismiss(); | |
| 85 | |
| 86 setContentView(recyclerView); | |
| 178 } | 87 } |
| 179 | 88 |
| 180 @Override | 89 @Override |
| 181 public void onContextMenuClosed(Menu menu) { | 90 public void onContextMenuClosed(Menu menu) { |
| 182 mContextMenuManager.onContextMenuClosed(); | 91 mContextMenuManager.onContextMenuClosed(); |
| 183 } | 92 } |
| 184 | 93 |
| 185 @Override | 94 @Override |
| 186 protected void onDestroy() { | 95 protected void onDestroy() { |
| 187 for (DestructionObserver observer : mDestructionObservers) { | 96 mSuggestionsManager.onDestroy(); |
| 188 observer.onDestroy(); | |
| 189 } | |
| 190 | |
| 191 mSnippetsBridge.destroy(); | |
| 192 mSnippetsBridge = null; | |
| 193 | |
| 194 super.onDestroy(); | 97 super.onDestroy(); |
| 195 } | 98 } |
| 196 } | 99 } |
| OLD | NEW |