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