OLD | NEW |
| (Empty) |
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 | |
3 // found in the LICENSE file. | |
4 | |
5 package org.chromium.chrome.browser.suggestions; | |
6 | |
7 import android.content.Intent; | |
8 import android.os.Bundle; | |
9 import android.view.Menu; | |
10 | |
11 import org.chromium.chrome.browser.ChromeActivity; | |
12 import org.chromium.chrome.browser.ChromeFeatureList; | |
13 import org.chromium.chrome.browser.NativePageHost; | |
14 import org.chromium.chrome.browser.SynchronousInitializationActivity; | |
15 import org.chromium.chrome.browser.TabLoadStatus; | |
16 import org.chromium.chrome.browser.tab.Tab; | |
17 import org.chromium.chrome.browser.tabmodel.TabModel; | |
18 import org.chromium.content_public.browser.LoadUrlParams; | |
19 | |
20 import java.lang.ref.WeakReference; | |
21 | |
22 /** | |
23 * TODO(dgn): Nuke this class | |
24 * Experimental activity to show content suggestions outside of the New Tab Page
. | |
25 */ | |
26 public class ContentSuggestionsActivity extends SynchronousInitializationActivit
y { | |
27 private static WeakReference<ChromeActivity> sCallerActivity; | |
28 | |
29 private SuggestionsBottomSheetContent mBottomSheetContent; | |
30 | |
31 public static void launch(ChromeActivity activity) { | |
32 sCallerActivity = new WeakReference<>(activity); | |
33 | |
34 Intent intent = new Intent(); | |
35 intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK); | |
36 intent.setClass(activity, ContentSuggestionsActivity.class); | |
37 activity.startActivity(intent); | |
38 } | |
39 | |
40 @Override | |
41 protected void onCreate(Bundle savedInstanceState) { | |
42 super.onCreate(savedInstanceState); | |
43 | |
44 assert ChromeFeatureList.isEnabled(ChromeFeatureList.NTP_SUGGESTIONS_STA
NDALONE_UI); | |
45 | |
46 // TODO(dgn): properly handle retrieving the tab information, or the bas
e activity being | |
47 // destroyed. (https://crbug.com/677672) | |
48 ChromeActivity activity = sCallerActivity.get(); | |
49 if (activity == null) throw new IllegalStateException(); | |
50 | |
51 // TODO(dgn): Because the passed activity here is the Chrome one and not
the one showing | |
52 // the surface, some things, like closing the context menu will not work
as they would | |
53 // affect the wrong one. | |
54 mBottomSheetContent = new SuggestionsBottomSheetContent( | |
55 activity, new TabShim(activity.getActivityTab()), activity.getTa
bModelSelector()); | |
56 setContentView(mBottomSheetContent.getScrollingContentView()); | |
57 } | |
58 | |
59 @Override | |
60 public void onContextMenuClosed(Menu menu) { | |
61 mBottomSheetContent.getContextMenuManager().onContextMenuClosed(); | |
62 } | |
63 | |
64 @Override | |
65 protected void onDestroy() { | |
66 mBottomSheetContent.destroy(); | |
67 super.onDestroy(); | |
68 } | |
69 | |
70 /** Simple implementation of NativePageHost backed by a {@link Tab} */ | |
71 private static class TabShim implements NativePageHost { | |
72 private final Tab mTab; | |
73 | |
74 public TabShim(Tab mTab) { | |
75 this.mTab = mTab; | |
76 } | |
77 | |
78 @Override | |
79 public int loadUrl(LoadUrlParams urlParams, boolean incognito) { | |
80 if (incognito && !mTab.isIncognito()) { | |
81 mTab.getTabModelSelector().openNewTab(urlParams, | |
82 TabModel.TabLaunchType.FROM_LONGPRESS_BACKGROUND, mTab, | |
83 /* incognito = */ true); | |
84 return TabLoadStatus.DEFAULT_PAGE_LOAD; | |
85 } | |
86 | |
87 return mTab.loadUrl(urlParams); | |
88 } | |
89 | |
90 @Override | |
91 public boolean isIncognito() { | |
92 return mTab.isIncognito(); | |
93 } | |
94 | |
95 @Override | |
96 public int getParentId() { | |
97 return mTab.getParentId(); | |
98 } | |
99 | |
100 @Override | |
101 public Tab getActiveTab() { | |
102 return mTab; | |
103 } | |
104 } | |
105 } | |
OLD | NEW |