Commit 1858b3af authored by Brandon Wylie's avatar Brandon Wylie Committed by Commit Bot

Remove ChromeActivity reference from BookmarkPage

Bug: 1123209
Change-Id: I9115677e06b9e2ca8486c028f005f757b7a33ee5
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/2490338
Commit-Queue: Brandon Wylie <wylieb@chromium.org>
Reviewed-by: default avatarTheresa  <twellington@chromium.org>
Cr-Commit-Position: refs/heads/master@{#819651}
parent 6e50c5a3
...@@ -68,9 +68,6 @@ specific_include_rules = { ...@@ -68,9 +68,6 @@ specific_include_rules = {
"CardUnmaskPrompt\.java": [ "CardUnmaskPrompt\.java": [
"+chrome/android/java/src/org/chromium/chrome/browser/app/ChromeActivity.java", "+chrome/android/java/src/org/chromium/chrome/browser/app/ChromeActivity.java",
], ],
"BookmarkPage\.java": [
"+chrome/android/java/src/org/chromium/chrome/browser/app/ChromeActivity.java",
],
"BookmarkUtils\.java": [ "BookmarkUtils\.java": [
"+chrome/android/java/src/org/chromium/chrome/browser/app/ChromeActivity.java", "+chrome/android/java/src/org/chromium/chrome/browser/app/ChromeActivity.java",
], ],
......
...@@ -10,6 +10,8 @@ import android.text.TextUtils; ...@@ -10,6 +10,8 @@ import android.text.TextUtils;
import androidx.annotation.VisibleForTesting; import androidx.annotation.VisibleForTesting;
import org.chromium.base.IntentUtils;
import org.chromium.chrome.browser.IntentHandler;
import org.chromium.chrome.browser.SnackbarActivity; import org.chromium.chrome.browser.SnackbarActivity;
import org.chromium.components.bookmarks.BookmarkId; import org.chromium.components.bookmarks.BookmarkId;
import org.chromium.components.embedder_support.util.UrlConstants; import org.chromium.components.embedder_support.util.UrlConstants;
...@@ -28,7 +30,10 @@ public class BookmarkActivity extends SnackbarActivity { ...@@ -28,7 +30,10 @@ public class BookmarkActivity extends SnackbarActivity {
@Override @Override
protected void onCreate(Bundle savedInstanceState) { protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState); super.onCreate(savedInstanceState);
mBookmarkManager = new BookmarkManager(this, true, getSnackbarManager()); mBookmarkManager = new BookmarkManager(this,
IntentUtils.safeGetParcelableExtra(
getIntent(), IntentHandler.EXTRA_PARENT_COMPONENT),
true, getSnackbarManager());
String url = getIntent().getDataString(); String url = getIntent().getDataString();
if (TextUtils.isEmpty(url)) url = UrlConstants.BOOKMARKS_URL; if (TextUtils.isEmpty(url)) url = UrlConstants.BOOKMARKS_URL;
mBookmarkManager.updateForUrl(url); mBookmarkManager.updateForUrl(url);
......
...@@ -4,10 +4,11 @@ ...@@ -4,10 +4,11 @@
package org.chromium.chrome.browser.bookmarks; package org.chromium.chrome.browser.bookmarks;
import android.app.Activity;
import android.app.ActivityManager; import android.app.ActivityManager;
import android.content.ComponentName;
import android.content.Context; import android.content.Context;
import android.text.TextUtils; import android.text.TextUtils;
import android.view.LayoutInflater;
import android.view.View; import android.view.View;
import android.view.ViewGroup; import android.view.ViewGroup;
import android.view.accessibility.AccessibilityManager; import android.view.accessibility.AccessibilityManager;
...@@ -49,7 +50,8 @@ public class BookmarkManager ...@@ -49,7 +50,8 @@ public class BookmarkManager
private static boolean sPreventLoadingForTesting; private static boolean sPreventLoadingForTesting;
private Activity mActivity; private Context mContext;
private ComponentName mOpenBookmarkComponentName;
private ViewGroup mMainView; private ViewGroup mMainView;
private BookmarkModel mBookmarkModel; private BookmarkModel mBookmarkModel;
private BookmarkUndoController mUndoController; private BookmarkUndoController mUndoController;
...@@ -158,12 +160,15 @@ public class BookmarkManager ...@@ -158,12 +160,15 @@ public class BookmarkManager
/** /**
* Creates an instance of {@link BookmarkManager}. It also initializes resources, * Creates an instance of {@link BookmarkManager}. It also initializes resources,
* bookmark models and jni bridges. * bookmark models and jni bridges.
* @param activity The activity context to use. * @param context The current {@link Context} used to obtain resources or inflate views.
* @param openBookmarkComponentName The component to use when opening a bookmark.
* @param isDialogUi Whether the main bookmarks UI will be shown in a dialog, not a NativePage. * @param isDialogUi Whether the main bookmarks UI will be shown in a dialog, not a NativePage.
* @param snackbarManager The {@link SnackbarManager} used to display snackbars. * @param snackbarManager The {@link SnackbarManager} used to display snackbars.
*/ */
public BookmarkManager(Activity activity, boolean isDialogUi, SnackbarManager snackbarManager) { public BookmarkManager(Context context, ComponentName openBookmarkComponentName,
mActivity = activity; boolean isDialogUi, SnackbarManager snackbarManager) {
mContext = context;
mOpenBookmarkComponentName = openBookmarkComponentName;
mIsDialogUi = isDialogUi; mIsDialogUi = isDialogUi;
mSelectionDelegate = new SelectionDelegate<BookmarkId>() { mSelectionDelegate = new SelectionDelegate<BookmarkId>() {
...@@ -180,7 +185,7 @@ public class BookmarkManager ...@@ -180,7 +185,7 @@ public class BookmarkManager
mDragStateDelegate = new BookmarkDragStateDelegate(); mDragStateDelegate = new BookmarkDragStateDelegate();
mBookmarkModel = new BookmarkModel(); mBookmarkModel = new BookmarkModel();
mMainView = (ViewGroup) mActivity.getLayoutInflater().inflate(R.layout.bookmark_main, null); mMainView = (ViewGroup) LayoutInflater.from(mContext).inflate(R.layout.bookmark_main, null);
@SuppressWarnings("unchecked") @SuppressWarnings("unchecked")
SelectableListLayout<BookmarkId> selectableList = SelectableListLayout<BookmarkId> selectableList =
...@@ -189,7 +194,7 @@ public class BookmarkManager ...@@ -189,7 +194,7 @@ public class BookmarkManager
mSelectableListLayout.initializeEmptyView( mSelectableListLayout.initializeEmptyView(
R.string.bookmarks_folder_empty, R.string.bookmark_no_result); R.string.bookmarks_folder_empty, R.string.bookmark_no_result);
mAdapter = new BookmarkItemsAdapter(activity); mAdapter = new BookmarkItemsAdapter(mContext);
mAdapterDataObserver = new AdapterDataObserver() { mAdapterDataObserver = new AdapterDataObserver() {
@Override @Override
...@@ -214,7 +219,7 @@ public class BookmarkManager ...@@ -214,7 +219,7 @@ public class BookmarkManager
mSelectableListLayout.configureWideDisplayStyle(); mSelectableListLayout.configureWideDisplayStyle();
mUndoController = new BookmarkUndoController(activity, mBookmarkModel, snackbarManager); mUndoController = new BookmarkUndoController(mContext, mBookmarkModel, snackbarManager);
mBookmarkModel.addObserver(mBookmarkModelObserver); mBookmarkModel.addObserver(mBookmarkModelObserver);
initializeToLoadingState(); initializeToLoadingState();
if (!sPreventLoadingForTesting) { if (!sPreventLoadingForTesting) {
...@@ -400,7 +405,7 @@ public class BookmarkManager ...@@ -400,7 +405,7 @@ public class BookmarkManager
if (state.mState == BookmarkUIState.STATE_FOLDER) { if (state.mState == BookmarkUIState.STATE_FOLDER) {
// Loading and searching states may be pushed to the stack but should never be stored in // Loading and searching states may be pushed to the stack but should never be stored in
// preferences. // preferences.
BookmarkUtils.setLastUsedUrl(mActivity, state.mUrl); BookmarkUtils.setLastUsedUrl(mContext, state.mUrl);
// If a loading state is replaced by another loading state, do not notify this change. // If a loading state is replaced by another loading state, do not notify this change.
if (mNativePage != null) { if (mNativePage != null) {
mNativePage.onStateChange(state.mUrl, false); mNativePage.onStateChange(state.mUrl, false);
...@@ -489,8 +494,9 @@ public class BookmarkManager ...@@ -489,8 +494,9 @@ public class BookmarkManager
@Override @Override
public void openBookmark(BookmarkId bookmark) { public void openBookmark(BookmarkId bookmark) {
if (BookmarkUtils.openBookmark(mBookmarkModel, mActivity, bookmark)) { if (BookmarkUtils.openBookmark(
BookmarkUtils.finishActivityOnPhone(mActivity); mContext, mOpenBookmarkComponentName, mBookmarkModel, bookmark)) {
BookmarkUtils.finishActivityOnPhone(mContext);
} }
} }
......
...@@ -4,10 +4,12 @@ ...@@ -4,10 +4,12 @@
package org.chromium.chrome.browser.bookmarks; package org.chromium.chrome.browser.bookmarks;
import android.content.ComponentName;
import androidx.annotation.VisibleForTesting; import androidx.annotation.VisibleForTesting;
import org.chromium.chrome.R; import org.chromium.chrome.R;
import org.chromium.chrome.browser.app.ChromeActivity; import org.chromium.chrome.browser.ui.messages.snackbar.SnackbarManager;
import org.chromium.chrome.browser.ui.native_page.BasicNativePage; import org.chromium.chrome.browser.ui.native_page.BasicNativePage;
import org.chromium.chrome.browser.ui.native_page.NativePageHost; import org.chromium.chrome.browser.ui.native_page.NativePageHost;
import org.chromium.components.embedder_support.util.UrlConstants; import org.chromium.components.embedder_support.util.UrlConstants;
...@@ -21,13 +23,16 @@ public class BookmarkPage extends BasicNativePage { ...@@ -21,13 +23,16 @@ public class BookmarkPage extends BasicNativePage {
/** /**
* Create a new instance of the bookmarks page. * Create a new instance of the bookmarks page.
* @param componentName The current activity component, used to open bookmarks.
* @param snackbarManager Allows control over the app snackbar.
* @param activity The activity to get context and manage fragments. * @param activity The activity to get context and manage fragments.
* @param host A NativePageHost to load urls. * @param host A NativePageHost to load urls.
*/ */
public BookmarkPage(ChromeActivity activity, NativePageHost host) { public BookmarkPage(
ComponentName componentName, SnackbarManager snackbarManager, NativePageHost host) {
super(host); super(host);
mManager = new BookmarkManager(activity, false, activity.getSnackbarManager()); mManager = new BookmarkManager(host.getContext(), componentName, false, snackbarManager);
mManager.setBasicNativePage(this); mManager.setBasicNativePage(this);
mTitle = host.getContext().getResources().getString(R.string.bookmarks); mTitle = host.getContext().getResources().getString(R.string.bookmarks);
......
...@@ -16,8 +16,7 @@ import org.chromium.chrome.browser.ui.messages.snackbar.SnackbarManager; ...@@ -16,8 +16,7 @@ import org.chromium.chrome.browser.ui.messages.snackbar.SnackbarManager;
import java.util.Locale; import java.util.Locale;
/** /**
* Shows an undo bar when the user modifies bookmarks, * Shows an undo bar when the user modifies bookmarks, allowing them to undo their changes.
* allowing them to undo their changes.
*/ */
public class BookmarkUndoController extends BookmarkModelObserver implements public class BookmarkUndoController extends BookmarkModelObserver implements
SnackbarManager.SnackbarController, BookmarkDeleteObserver { SnackbarManager.SnackbarController, BookmarkDeleteObserver {
......
...@@ -15,7 +15,6 @@ import android.text.TextUtils; ...@@ -15,7 +15,6 @@ import android.text.TextUtils;
import androidx.annotation.VisibleForTesting; import androidx.annotation.VisibleForTesting;
import org.chromium.base.BuildInfo; import org.chromium.base.BuildInfo;
import org.chromium.base.IntentUtils;
import org.chromium.base.Log; import org.chromium.base.Log;
import org.chromium.base.ThreadUtils; import org.chromium.base.ThreadUtils;
import org.chromium.base.metrics.RecordHistogram; import org.chromium.base.metrics.RecordHistogram;
...@@ -245,32 +244,22 @@ public class BookmarkUtils { ...@@ -245,32 +244,22 @@ public class BookmarkUtils {
/** /**
* Opens a bookmark and reports UMA. * Opens a bookmark and reports UMA.
* @param context The current context used to launch the intent.
* @param openBookmarkComponentName The component to use when opening a bookmark.
* @param model Bookmarks model to manage the bookmark. * @param model Bookmarks model to manage the bookmark.
* @param activity Activity requesting to open the bookmark.
* @param bookmarkId ID of the bookmark to be opened. * @param bookmarkId ID of the bookmark to be opened.
* @return Whether the bookmark was successfully opened. * @return Whether the bookmark was successfully opened.
*/ */
public static boolean openBookmark( public static boolean openBookmark(Context context, ComponentName openBookmarkComponentName,
BookmarkModel model, Activity activity, BookmarkId bookmarkId) { BookmarkModel model, BookmarkId bookmarkId) {
if (model.getBookmarkById(bookmarkId) == null) return false; if (model.getBookmarkById(bookmarkId) == null) return false;
String url = model.getBookmarkById(bookmarkId).getUrl();
RecordUserAction.record("MobileBookmarkManagerEntryOpened"); RecordUserAction.record("MobileBookmarkManagerEntryOpened");
RecordHistogram.recordEnumeratedHistogram( RecordHistogram.recordEnumeratedHistogram(
"Bookmarks.OpenBookmarkType", bookmarkId.getType(), BookmarkType.LAST + 1); "Bookmarks.OpenBookmarkType", bookmarkId.getType(), BookmarkType.LAST + 1);
if (activity instanceof BookmarkActivity) { String url = model.getBookmarkById(bookmarkId).getUrl();
// For phones, the bookmark manager is a separate activity. When the activity is openUrl(context, url, openBookmarkComponentName);
// launched, an intent extra is set specifying the parent component.
ComponentName parentComponent = IntentUtils.safeGetParcelableExtra(
activity.getIntent(), IntentHandler.EXTRA_PARENT_COMPONENT);
openUrl(activity, url, parentComponent);
} else {
// For tablets, the bookmark manager is open in a tab in the ChromeActivity. Use
// the ComponentName of the ChromeActivity passed into this method.
openUrl(activity, url, activity.getComponentName());
}
return true; return true;
} }
...@@ -291,10 +280,10 @@ public class BookmarkUtils { ...@@ -291,10 +280,10 @@ public class BookmarkUtils {
return R.color.default_icon_color_tint_list; return R.color.default_icon_color_tint_list;
} }
private static void openUrl(Activity activity, String url, ComponentName componentName) { private static void openUrl(Context context, String url, ComponentName componentName) {
Intent intent = new Intent(Intent.ACTION_VIEW, Uri.parse(url)); Intent intent = new Intent(Intent.ACTION_VIEW, Uri.parse(url));
intent.putExtra(Browser.EXTRA_APPLICATION_ID, intent.putExtra(
activity.getApplicationContext().getPackageName()); Browser.EXTRA_APPLICATION_ID, context.getApplicationContext().getPackageName());
intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK); intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
intent.putExtra(IntentHandler.EXTRA_PAGE_TRANSITION_TYPE, PageTransition.AUTO_BOOKMARK); intent.putExtra(IntentHandler.EXTRA_PAGE_TRANSITION_TYPE, PageTransition.AUTO_BOOKMARK);
...@@ -304,7 +293,7 @@ public class BookmarkUtils { ...@@ -304,7 +293,7 @@ public class BookmarkUtils {
// If the bookmark manager is shown in a tab on a phone (rather than in a separate // If the bookmark manager is shown in a tab on a phone (rather than in a separate
// activity) the component name may be null. Send the intent through // activity) the component name may be null. Send the intent through
// ChromeLauncherActivity instead to avoid crashing. See crbug.com/615012. // ChromeLauncherActivity instead to avoid crashing. See crbug.com/615012.
intent.setClass(activity, ChromeLauncherActivity.class); intent.setClass(context.getApplicationContext(), ChromeLauncherActivity.class);
} }
IntentHandler.startActivityForTrustedIntent(intent); IntentHandler.startActivityForTrustedIntent(intent);
......
...@@ -94,7 +94,8 @@ public class NativePageFactory { ...@@ -94,7 +94,8 @@ public class NativePageFactory {
} }
protected NativePage buildBookmarksPage(Tab tab) { protected NativePage buildBookmarksPage(Tab tab) {
return new BookmarkPage(mActivity, new TabShim(tab, mActivity)); return new BookmarkPage(mActivity.getComponentName(), mActivity.getSnackbarManager(),
new TabShim(tab, mActivity));
} }
protected NativePage buildDownloadsPage(Tab tab) { protected NativePage buildDownloadsPage(Tab tab) {
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment