Commit f863138d authored by Christian Dullweber's avatar Christian Dullweber Committed by Chromium LUCI CQ

[WebLayer] Provide FragmentManager for PageInfo

The current approach of getting a FragmentManager for PageInfo does not
work with WebLayer. Instead we use PageInfoControllerDelegate obtain a
FragmentManager from Chrome and WebLayer.

Contains BrowserFragmentImpl changes from https://crrev.com/c/2575753.

Bug: 1077766
Change-Id: I0f8d3ecfaaed68e99140e39836cbc1539ef8225f
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/2577206Reviewed-by: default avatarEhimare Okoyomon <eokoyomon@chromium.org>
Reviewed-by: default avatarRobbie McElrath <rmcelrath@chromium.org>
Reviewed-by: default avatarBo <boliu@chromium.org>
Commit-Queue: Christian Dullweber <dullweber@chromium.org>
Cr-Commit-Position: refs/heads/master@{#836095}
parent a6faa3f8
......@@ -16,6 +16,8 @@ import androidx.annotation.NonNull;
import androidx.annotation.Nullable;
import androidx.annotation.VisibleForTesting;
import androidx.appcompat.content.res.AppCompatResources;
import androidx.fragment.app.FragmentActivity;
import androidx.fragment.app.FragmentManager;
import org.chromium.base.Callback;
import org.chromium.base.Consumer;
......@@ -67,6 +69,7 @@ import java.util.Date;
*/
public class ChromePageInfoControllerDelegate extends PageInfoControllerDelegate {
private final WebContents mWebContents;
private Supplier<ModalDialogManager> mModalDialogManagerSupplier;
private final Context mContext;
private final Profile mProfile;
private String mOfflinePageCreationDate;
......@@ -75,8 +78,7 @@ public class ChromePageInfoControllerDelegate extends PageInfoControllerDelegate
public ChromePageInfoControllerDelegate(Context context, WebContents webContents,
Supplier<ModalDialogManager> modalDialogManagerSupplier,
OfflinePageLoadUrlDelegate offlinePageLoadUrlDelegate) {
super(modalDialogManagerSupplier,
new ChromeAutocompleteSchemeClassifier(Profile.fromWebContents(webContents)),
super(new ChromeAutocompleteSchemeClassifier(Profile.fromWebContents(webContents)),
VrModuleProvider.getDelegate(),
/** isSiteSettingsAvailable= */
SiteSettingsHelper.isSiteSettingsAvailable(webContents),
......@@ -84,6 +86,7 @@ public class ChromePageInfoControllerDelegate extends PageInfoControllerDelegate
CookieControlsBridge.isCookieControlsEnabled(Profile.fromWebContents(webContents)));
mContext = context;
mWebContents = webContents;
mModalDialogManagerSupplier = modalDialogManagerSupplier;
mProfile = Profile.fromWebContents(mWebContents);
mPreviewPageState = getPreviewPageStateAndRecordUma();
......@@ -142,6 +145,14 @@ public class ChromePageInfoControllerDelegate extends PageInfoControllerDelegate
}
}
/**
* {@inheritDoc}
*/
@Override
public ModalDialogManager getModalDialogManager() {
return mModalDialogManagerSupplier.get();
}
/**
* {@inheritDoc}
*/
......@@ -342,4 +353,11 @@ public class ChromePageInfoControllerDelegate extends PageInfoControllerDelegate
void setOfflinePageStateForTesting(@OfflinePageState int offlinePageState) {
mOfflinePageState = offlinePageState;
}
@Override
public FragmentManager getFragmentManager() {
FragmentActivity activity = ((FragmentActivity) mContext);
if (activity.isFinishing()) return null;
return activity.getSupportFragmentManager();
}
}
......@@ -10,10 +10,10 @@ import android.graphics.drawable.Drawable;
import androidx.annotation.IntDef;
import androidx.annotation.NonNull;
import androidx.annotation.Nullable;
import androidx.fragment.app.FragmentManager;
import org.chromium.base.Callback;
import org.chromium.base.Consumer;
import org.chromium.base.supplier.Supplier;
import org.chromium.components.browser_ui.site_settings.SiteSettingsClient;
import org.chromium.components.content_settings.CookieControlsBridge;
import org.chromium.components.content_settings.CookieControlsObserver;
......@@ -47,7 +47,6 @@ public abstract class PageInfoControllerDelegate {
int INSECURE_PAGE_PREVIEW = 3;
}
private final Supplier<ModalDialogManager> mModalDialogManager;
private final AutocompleteSchemeClassifier mAutocompleteSchemeClassifier;
private final VrHandler mVrHandler;
private final boolean mIsSiteSettingsAvailable;
......@@ -57,10 +56,8 @@ public abstract class PageInfoControllerDelegate {
protected boolean mIsHttpsImageCompressionApplied;
protected String mOfflinePageUrl;
public PageInfoControllerDelegate(Supplier<ModalDialogManager> modalDialogManager,
AutocompleteSchemeClassifier autocompleteSchemeClassifier, VrHandler vrHandler,
boolean isSiteSettingsAvailable, boolean cookieControlsShown) {
mModalDialogManager = modalDialogManager;
public PageInfoControllerDelegate(AutocompleteSchemeClassifier autocompleteSchemeClassifier,
VrHandler vrHandler, boolean isSiteSettingsAvailable, boolean cookieControlsShown) {
mAutocompleteSchemeClassifier = autocompleteSchemeClassifier;
mVrHandler = vrHandler;
mIsSiteSettingsAvailable = isSiteSettingsAvailable;
......@@ -89,9 +86,7 @@ public abstract class PageInfoControllerDelegate {
/**
* Return the ModalDialogManager to be used.
*/
public ModalDialogManager getModalDialogManager() {
return mModalDialogManager.get();
}
public abstract ModalDialogManager getModalDialogManager();
/**
* Initialize viewParams with Preview UI info, if any.
......@@ -253,4 +248,6 @@ public abstract class PageInfoControllerDelegate {
* @return Returns the drawable for the Preview UI.
*/
public abstract Drawable getPreviewUiIcon();
public abstract FragmentManager getFragmentManager();
}
......@@ -7,7 +7,7 @@ package org.chromium.components.page_info;
import android.view.View;
import android.view.ViewGroup;
import androidx.appcompat.app.AppCompatActivity;
import androidx.fragment.app.FragmentManager;
import org.chromium.components.browser_ui.site_settings.SingleWebsiteSettings;
import org.chromium.components.browser_ui.site_settings.SiteDataCleaner;
......@@ -73,8 +73,7 @@ public class PageInfoCookiesController
public View createViewForSubpage(ViewGroup parent) {
assert mSubPage == null;
mSubPage = new PageInfoCookiesPreference();
AppCompatActivity host = (AppCompatActivity) mRowView.getContext();
host.getSupportFragmentManager().beginTransaction().add(mSubPage, null).commitNow();
mDelegate.getFragmentManager().beginTransaction().add(mSubPage, null).commitNow();
PageInfoCookiesPreference.PageInfoCookiesViewParams params =
new PageInfoCookiesPreference.PageInfoCookiesViewParams();
......@@ -121,12 +120,12 @@ public class PageInfoCookiesController
@Override
public void onSubpageRemoved() {
assert mSubPage != null;
AppCompatActivity host = (AppCompatActivity) mRowView.getContext();
FragmentManager fragmentManager = mDelegate.getFragmentManager();
PageInfoCookiesPreference subPage = mSubPage;
mSubPage = null;
// If the activity is getting destroyed or saved, it is not allowed to modify fragments.
if (host.isFinishing() || host.getSupportFragmentManager().isStateSaved()) return;
host.getSupportFragmentManager().beginTransaction().remove(subPage).commitNow();
if (fragmentManager == null || fragmentManager.isStateSaved()) return;
fragmentManager.beginTransaction().remove(subPage).commitNow();
}
@Override
......
......@@ -10,8 +10,8 @@ import android.view.View;
import android.view.ViewGroup;
import androidx.annotation.VisibleForTesting;
import androidx.appcompat.app.AppCompatActivity;
import androidx.fragment.app.Fragment;
import androidx.fragment.app.FragmentManager;
import org.chromium.components.browser_ui.site_settings.SingleWebsiteSettings;
......@@ -56,20 +56,19 @@ public class PageInfoPermissionsController
mSubPage.setSiteSettingsClient(mDelegate.getSiteSettingsClient());
mSubPage.setHideNonPermissionPreferences(true);
mSubPage.setWebsiteSettingsObserver(this);
AppCompatActivity host = (AppCompatActivity) mRowView.getContext();
host.getSupportFragmentManager().beginTransaction().add(mSubPage, null).commitNow();
mDelegate.getFragmentManager().beginTransaction().add(mSubPage, null).commitNow();
return mSubPage.requireView();
}
@Override
public void onSubpageRemoved() {
assert mSubPage != null;
AppCompatActivity host = (AppCompatActivity) mRowView.getContext();
FragmentManager fragmentManager = mDelegate.getFragmentManager();
SingleWebsiteSettings subPage = mSubPage;
mSubPage = null;
// If the activity is getting destroyed or saved, it is not allowed to modify fragments.
if (host.isFinishing() || host.getSupportFragmentManager().isStateSaved()) return;
host.getSupportFragmentManager().beginTransaction().remove(subPage).commitNow();
if (fragmentManager == null || fragmentManager.isStateSaved()) return;
fragmentManager.beginTransaction().remove(subPage).commitNow();
}
public void setPermissions(PageInfoView.PermissionParams params) {
......
......@@ -15,6 +15,7 @@ import android.webkit.ValueCallback;
import androidx.annotation.NonNull;
import androidx.annotation.Nullable;
import androidx.fragment.app.FragmentManager;
import org.chromium.base.ObserverList;
import org.chromium.base.annotations.CalledByNative;
......@@ -571,6 +572,10 @@ public class BrowserImpl extends IBrowser.Stub implements View.OnAttachStateChan
return mInConfigurationChangeAndWasAttached;
}
public FragmentManager getFragmentManager() {
return mWindowAndroid.getFragmentManager();
}
public boolean isViewAttachedToWindow() {
return mViewAttachedToWindow;
}
......
......@@ -12,6 +12,8 @@ import android.content.IntentSender;
import android.os.Build;
import android.view.View;
import androidx.fragment.app.FragmentManager;
import org.chromium.ui.base.ActivityKeyboardVisibilityDelegate;
import org.chromium.ui.base.ImmutableWeakReference;
import org.chromium.ui.base.IntentWindowAndroid;
......@@ -79,6 +81,10 @@ public class FragmentWindowAndroid extends IntentWindowAndroid {
return mFragment.getBrowser();
}
public FragmentManager getFragmentManager() {
return mFragment.getSupportFragmentManager();
}
@Override
@TargetApi(Build.VERSION_CODES.O)
public void setWideColorEnabled(boolean enabled) {
......
......@@ -13,10 +13,10 @@ import android.webkit.ValueCallback;
import androidx.annotation.NonNull;
import androidx.annotation.Nullable;
import androidx.fragment.app.FragmentManager;
import org.chromium.base.Callback;
import org.chromium.base.StrictModeContext;
import org.chromium.base.supplier.Supplier;
import org.chromium.components.browser_ui.site_settings.ContentSettingsResources;
import org.chromium.components.browser_ui.site_settings.SiteSettingsCategory;
import org.chromium.components.browser_ui.site_settings.SiteSettingsClient;
......@@ -39,26 +39,34 @@ import org.chromium.weblayer_private.settings.WebLayerSiteSettingsClient;
public class PageInfoControllerDelegateImpl extends PageInfoControllerDelegate {
private final Context mContext;
private final WebContents mWebContents;
private final BrowserImpl mBrowser;
private final ProfileImpl mProfile;
static PageInfoControllerDelegateImpl create(WebContents webContents) {
TabImpl tab = TabImpl.fromWebContents(webContents);
assert tab != null;
return new PageInfoControllerDelegateImpl(tab.getBrowser().getContext(), webContents,
tab.getProfile(), tab.getBrowser().getWindowAndroid()::getModalDialogManager);
return new PageInfoControllerDelegateImpl(webContents, tab.getBrowser());
}
private PageInfoControllerDelegateImpl(Context context, WebContents webContents,
ProfileImpl profile, Supplier<ModalDialogManager> modalDialogManager) {
super(modalDialogManager, new AutocompleteSchemeClassifierImpl(),
private PageInfoControllerDelegateImpl(WebContents webContents, BrowserImpl browser) {
super(new AutocompleteSchemeClassifierImpl(),
/** vrHandler= */ null,
/** isSiteSettingsAvailable= */
isHttpOrHttps(webContents.getVisibleUrl()),
/** cookieControlsShown= */
CookieControlsBridge.isCookieControlsEnabled(profile));
mContext = context;
CookieControlsBridge.isCookieControlsEnabled(browser.getProfile()));
mContext = browser.getContext();
mWebContents = webContents;
mProfile = profile;
mBrowser = browser;
mProfile = browser.getProfile();
}
/**
* {@inheritDoc}
*/
@Override
public ModalDialogManager getModalDialogManager() {
return mBrowser.getWindowAndroid().getModalDialogManager();
}
/**
......@@ -69,7 +77,6 @@ public class PageInfoControllerDelegateImpl extends PageInfoControllerDelegate {
Intent intent = SettingsIntentHelper.createIntentForSiteSettingsSingleWebsite(
mContext, mProfile.getName(), mProfile.isIncognito(), url);
// Disabling StrictMode to avoid violations (https://crbug.com/819410).
launchIntent(intent);
}
......@@ -129,6 +136,9 @@ public class PageInfoControllerDelegateImpl extends PageInfoControllerDelegate {
}));
}
/**
* {@inheritDoc}
*/
@Override
@Nullable
public Drawable getPreviewUiIcon() {
......@@ -139,4 +149,12 @@ public class PageInfoControllerDelegateImpl extends PageInfoControllerDelegate {
String scheme = url.getScheme();
return UrlConstants.HTTP_SCHEME.equals(scheme) || UrlConstants.HTTPS_SCHEME.equals(scheme);
}
/**
* {@inheritDoc}
*/
@Override
public FragmentManager getFragmentManager() {
return mBrowser.getFragmentManager();
}
}
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