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 = {
"CardUnmaskPrompt\.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": [
"+chrome/android/java/src/org/chromium/chrome/browser/app/ChromeActivity.java",
],
......
......@@ -10,6 +10,8 @@ import android.text.TextUtils;
import androidx.annotation.VisibleForTesting;
import org.chromium.base.IntentUtils;
import org.chromium.chrome.browser.IntentHandler;
import org.chromium.chrome.browser.SnackbarActivity;
import org.chromium.components.bookmarks.BookmarkId;
import org.chromium.components.embedder_support.util.UrlConstants;
......@@ -28,7 +30,10 @@ public class BookmarkActivity extends SnackbarActivity {
@Override
protected void onCreate(Bundle 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();
if (TextUtils.isEmpty(url)) url = UrlConstants.BOOKMARKS_URL;
mBookmarkManager.updateForUrl(url);
......
......@@ -4,10 +4,11 @@
package org.chromium.chrome.browser.bookmarks;
import android.app.Activity;
import android.app.ActivityManager;
import android.content.ComponentName;
import android.content.Context;
import android.text.TextUtils;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.view.accessibility.AccessibilityManager;
......@@ -49,7 +50,8 @@ public class BookmarkManager
private static boolean sPreventLoadingForTesting;
private Activity mActivity;
private Context mContext;
private ComponentName mOpenBookmarkComponentName;
private ViewGroup mMainView;
private BookmarkModel mBookmarkModel;
private BookmarkUndoController mUndoController;
......@@ -158,12 +160,15 @@ public class BookmarkManager
/**
* Creates an instance of {@link BookmarkManager}. It also initializes resources,
* 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 snackbarManager The {@link SnackbarManager} used to display snackbars.
*/
public BookmarkManager(Activity activity, boolean isDialogUi, SnackbarManager snackbarManager) {
mActivity = activity;
public BookmarkManager(Context context, ComponentName openBookmarkComponentName,
boolean isDialogUi, SnackbarManager snackbarManager) {
mContext = context;
mOpenBookmarkComponentName = openBookmarkComponentName;
mIsDialogUi = isDialogUi;
mSelectionDelegate = new SelectionDelegate<BookmarkId>() {
......@@ -180,7 +185,7 @@ public class BookmarkManager
mDragStateDelegate = new BookmarkDragStateDelegate();
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")
SelectableListLayout<BookmarkId> selectableList =
......@@ -189,7 +194,7 @@ public class BookmarkManager
mSelectableListLayout.initializeEmptyView(
R.string.bookmarks_folder_empty, R.string.bookmark_no_result);
mAdapter = new BookmarkItemsAdapter(activity);
mAdapter = new BookmarkItemsAdapter(mContext);
mAdapterDataObserver = new AdapterDataObserver() {
@Override
......@@ -214,7 +219,7 @@ public class BookmarkManager
mSelectableListLayout.configureWideDisplayStyle();
mUndoController = new BookmarkUndoController(activity, mBookmarkModel, snackbarManager);
mUndoController = new BookmarkUndoController(mContext, mBookmarkModel, snackbarManager);
mBookmarkModel.addObserver(mBookmarkModelObserver);
initializeToLoadingState();
if (!sPreventLoadingForTesting) {
......@@ -400,7 +405,7 @@ public class BookmarkManager
if (state.mState == BookmarkUIState.STATE_FOLDER) {
// Loading and searching states may be pushed to the stack but should never be stored in
// 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 (mNativePage != null) {
mNativePage.onStateChange(state.mUrl, false);
......@@ -489,8 +494,9 @@ public class BookmarkManager
@Override
public void openBookmark(BookmarkId bookmark) {
if (BookmarkUtils.openBookmark(mBookmarkModel, mActivity, bookmark)) {
BookmarkUtils.finishActivityOnPhone(mActivity);
if (BookmarkUtils.openBookmark(
mContext, mOpenBookmarkComponentName, mBookmarkModel, bookmark)) {
BookmarkUtils.finishActivityOnPhone(mContext);
}
}
......
......@@ -4,10 +4,12 @@
package org.chromium.chrome.browser.bookmarks;
import android.content.ComponentName;
import androidx.annotation.VisibleForTesting;
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.NativePageHost;
import org.chromium.components.embedder_support.util.UrlConstants;
......@@ -21,13 +23,16 @@ public class BookmarkPage extends BasicNativePage {
/**
* 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 host A NativePageHost to load urls.
*/
public BookmarkPage(ChromeActivity activity, NativePageHost host) {
public BookmarkPage(
ComponentName componentName, SnackbarManager snackbarManager, NativePageHost host) {
super(host);
mManager = new BookmarkManager(activity, false, activity.getSnackbarManager());
mManager = new BookmarkManager(host.getContext(), componentName, false, snackbarManager);
mManager.setBasicNativePage(this);
mTitle = host.getContext().getResources().getString(R.string.bookmarks);
......
......@@ -16,8 +16,7 @@ import org.chromium.chrome.browser.ui.messages.snackbar.SnackbarManager;
import java.util.Locale;
/**
* Shows an undo bar when the user modifies bookmarks,
* allowing them to undo their changes.
* Shows an undo bar when the user modifies bookmarks, allowing them to undo their changes.
*/
public class BookmarkUndoController extends BookmarkModelObserver implements
SnackbarManager.SnackbarController, BookmarkDeleteObserver {
......
......@@ -15,7 +15,6 @@ import android.text.TextUtils;
import androidx.annotation.VisibleForTesting;
import org.chromium.base.BuildInfo;
import org.chromium.base.IntentUtils;
import org.chromium.base.Log;
import org.chromium.base.ThreadUtils;
import org.chromium.base.metrics.RecordHistogram;
......@@ -245,32 +244,22 @@ public class BookmarkUtils {
/**
* 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 activity Activity requesting to open the bookmark.
* @param bookmarkId ID of the bookmark to be opened.
* @return Whether the bookmark was successfully opened.
*/
public static boolean openBookmark(
BookmarkModel model, Activity activity, BookmarkId bookmarkId) {
public static boolean openBookmark(Context context, ComponentName openBookmarkComponentName,
BookmarkModel model, BookmarkId bookmarkId) {
if (model.getBookmarkById(bookmarkId) == null) return false;
String url = model.getBookmarkById(bookmarkId).getUrl();
RecordUserAction.record("MobileBookmarkManagerEntryOpened");
RecordHistogram.recordEnumeratedHistogram(
"Bookmarks.OpenBookmarkType", bookmarkId.getType(), BookmarkType.LAST + 1);
if (activity instanceof BookmarkActivity) {
// For phones, the bookmark manager is a separate activity. When the activity is
// 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());
}
String url = model.getBookmarkById(bookmarkId).getUrl();
openUrl(context, url, openBookmarkComponentName);
return true;
}
......@@ -291,10 +280,10 @@ public class BookmarkUtils {
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.putExtra(Browser.EXTRA_APPLICATION_ID,
activity.getApplicationContext().getPackageName());
intent.putExtra(
Browser.EXTRA_APPLICATION_ID, context.getApplicationContext().getPackageName());
intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
intent.putExtra(IntentHandler.EXTRA_PAGE_TRANSITION_TYPE, PageTransition.AUTO_BOOKMARK);
......@@ -304,7 +293,7 @@ public class BookmarkUtils {
// 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
// ChromeLauncherActivity instead to avoid crashing. See crbug.com/615012.
intent.setClass(activity, ChromeLauncherActivity.class);
intent.setClass(context.getApplicationContext(), ChromeLauncherActivity.class);
}
IntentHandler.startActivityForTrustedIntent(intent);
......
......@@ -94,7 +94,8 @@ public class NativePageFactory {
}
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) {
......
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