Commit 6f8efcb3 authored by Christian Dullweber's avatar Christian Dullweber Committed by Commit Bot

Tweak Cookie subpage in PageInfo

Hide strings for zero blocked cookies. Always show cookie section.
Remove "cookies in use" on main page.  Some code cleanup.

Bug: 1077766
Change-Id: I892373fdbd62a6a95c253a293ac125dd7bf3a1cb
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/2416068Reviewed-by: default avatarEhimare Okoyomon <eokoyomon@chromium.org>
Commit-Queue: Christian Dullweber <dullweber@chromium.org>
Cr-Commit-Position: refs/heads/master@{#809367}
parent 0a4940fb
......@@ -51,9 +51,6 @@ public class PageInfoConnectionController
return mContainer;
}
@Override
public void onSubPageAttached() {}
@Override
public void onSubpageRemoved() {
mContainer = null;
......
......@@ -264,14 +264,6 @@ public class PageInfoController implements PageInfoMainController, ModalDialogPr
containerParams.urlTitleLongClickCallback = viewParams.urlTitleLongClickCallback;
containerParams.urlTitleShown = viewParams.urlTitleShown;
mContainer.setParams(containerParams);
mContainer.showPage(mView, null, null);
PageInfoViewV2 view2 = (PageInfoViewV2) mView;
mConnectionController = new PageInfoConnectionController(
this, view2.getConnectionRowView(), mWebContents, mDelegate.getVrHandler());
mPermissionsController = new PageInfoPermissionsController(
this, view2.getPermissionsRowView(), mDelegate, mFullUrl);
mCookiesController = new PageInfoCookiesController(this, view2.getCookiesRowView(),
mDelegate, viewParams.cookieControlsShown, mFullUrl);
mDelegate.getFavicon(mFullUrl, favicon -> {
if (favicon != null) {
mContainer.setFavicon(favicon);
......@@ -280,6 +272,15 @@ public class PageInfoController implements PageInfoMainController, ModalDialogPr
SettingsUtils.getTintedIcon(mContext, R.drawable.ic_globe_24dp));
}
});
mContainer.showPage(mView, null, null);
PageInfoViewV2 view2 = (PageInfoViewV2) mView;
mConnectionController = new PageInfoConnectionController(
this, view2.getConnectionRowView(), mWebContents, mDelegate.getVrHandler());
mPermissionsController = new PageInfoPermissionsController(
this, view2.getPermissionsRowView(), mDelegate, mFullUrl);
mCookiesController = new PageInfoCookiesController(
this, view2.getCookiesRowView(), mDelegate, mFullUrl);
} else {
mView.showPerformanceInfo(mDelegate.shouldShowPerformanceBadge(mFullUrl));
mView.showHttpsImageCompressionInfo(mDelegate.isHttpsImageCompressionApplied());
......@@ -585,7 +586,6 @@ public class PageInfoController implements PageInfoMainController, ModalDialogPr
CharSequence title = mSubpageController.getSubpageTitle();
View subview = mSubpageController.createViewForSubpage(mContainer);
mContainer.showPage(subview, title, null);
controller.onSubPageAttached();
}
/**
......
......@@ -37,7 +37,7 @@ public class PageInfoCookiesController
private boolean mIsEnforced;
public PageInfoCookiesController(PageInfoMainController mainController, PageInfoRowView rowView,
PageInfoControllerDelegate delegate, boolean isVisible, String fullUrl) {
PageInfoControllerDelegate delegate, String fullUrl) {
mMainController = mainController;
mRowView = rowView;
mDelegate = delegate;
......@@ -45,7 +45,7 @@ public class PageInfoCookiesController
mTitle = mRowView.getContext().getResources().getString(R.string.cookies_title);
PageInfoRowView.ViewParams rowParams = new PageInfoRowView.ViewParams();
rowParams.visible = isVisible;
rowParams.visible = delegate.isSiteSettingsAvailable();
rowParams.title = mTitle;
rowParams.iconResId = R.drawable.permission_cookie;
rowParams.clickCallback = this::launchSubpage;
......@@ -65,25 +65,22 @@ 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();
PageInfoCookiesPreference.PageInfoCookiesViewParams params =
new PageInfoCookiesPreference.PageInfoCookiesViewParams();
params.thirdPartyCookieBlockingEnabled = mDelegate.cookieControlsShown();
params.onCheckedChangedCallback = this::onCheckedChangedCallback;
params.onClearCallback = this::clearData;
params.onCookieSettingsLinkClicked = mDelegate::showCookieSettings;
params.disableCookieDeletion = WebsitePreferenceBridge.isCookieDeletionDisabled(
mMainController.getBrowserContext(), mFullUrl);
mSubPage.setParams(params);
AppCompatActivity host = (AppCompatActivity) mRowView.getContext();
host.getSupportFragmentManager().beginTransaction().add(mSubPage, null).commitNow();
return mSubPage.requireView();
}
@Override
public void onSubPageAttached() {
// TODO(crbug.com/1077766): Get storage size.
mSubPage.setCookiesCount(mAllowedCookies, mBlockedCookies);
mSubPage.setCookieBlockingStatus(mStatus, mIsEnforced);
return mSubPage.requireView();
}
private void onCheckedChangedCallback(boolean state) {
......@@ -112,8 +109,8 @@ public class PageInfoCookiesController
String subtitle = blockedCookies > 0
? mRowView.getContext().getResources().getQuantityString(
R.plurals.cookie_controls_blocked_cookies, blockedCookies, blockedCookies)
: mRowView.getContext().getResources().getQuantityString(
R.plurals.page_info_cookies_in_use, allowedCookies, allowedCookies);
: null;
mRowView.updateSubtitle(subtitle);
if (mSubPage != null) {
......
......@@ -26,14 +26,13 @@ public class PageInfoCookiesPreference extends PreferenceFragmentCompat {
private static final String COOKIE_IN_USE_PREFERENCE = "cookie_in_use";
private static final String CLEAR_BUTTON_PREFERENCE = "clear_button";
private PageInfoCookiesViewParams mParams;
private ChromeSwitchPreference mCookieSwitch;
private ChromeBasePreference mCookieInUse;
/** Parameters to configure the cookie controls view. */
public static class PageInfoCookiesViewParams {
// Called when the toggle controlling third-party cookie blocking changes.
public boolean thirdPartyCookieBlockingEnabled;
public Callback<Boolean> onCheckedChangedCallback;
public Runnable onClearCallback;
public Runnable onCookieSettingsLinkClicked;
......@@ -43,39 +42,38 @@ public class PageInfoCookiesPreference extends PreferenceFragmentCompat {
@Override
public void onCreatePreferences(Bundle bundle, String s) {
SettingsUtils.addPreferencesFromResource(this, R.xml.page_info_cookie_preference);
mCookieSwitch = findPreference(COOKIE_SWITCH_PREFERENCE);
mCookieInUse = findPreference(COOKIE_IN_USE_PREFERENCE);
}
public void setParams(PageInfoCookiesViewParams params) {
Preference cookieSummary = findPreference(COOKIE_SUMMARY_PREFERENCE);
NoUnderlineClickableSpan linkSpan = new NoUnderlineClickableSpan(
getResources(), (view) -> { mParams.onCookieSettingsLinkClicked.run(); });
getResources(), (view) -> { params.onCookieSettingsLinkClicked.run(); });
cookieSummary.setSummary(
SpanApplier.applySpans(getString(R.string.page_info_cookies_description),
new SpanApplier.SpanInfo("<link>", "</link>", linkSpan)));
// TODO(crbug.com/1077766): Set a ManagedPreferenceDelegate?
mCookieSwitch = findPreference(COOKIE_SWITCH_PREFERENCE);
mCookieSwitch.setVisible(params.thirdPartyCookieBlockingEnabled);
mCookieSwitch.setOnPreferenceChangeListener((preference, newValue) -> {
mParams.onCheckedChangedCallback.onResult((Boolean) newValue);
params.onCheckedChangedCallback.onResult((Boolean) newValue);
return true;
});
mCookieInUse = findPreference(COOKIE_IN_USE_PREFERENCE);
mCookieInUse.setIcon(
SettingsUtils.getTintedIcon(getContext(), R.drawable.permission_cookie));
ButtonPreference clearButton = findPreference(CLEAR_BUTTON_PREFERENCE);
clearButton.setOnPreferenceClickListener(preference -> {
mParams.onClearCallback.run();
params.onClearCallback.run();
return true;
});
if (mParams.disableCookieDeletion) {
if (params.disableCookieDeletion) {
clearButton.setEnabled(false);
}
}
public void setParams(PageInfoCookiesViewParams params) {
mParams = params;
}
public void setCookieBlockingStatus(@CookieControlsStatus int status, boolean isEnforced) {
boolean visible = status != CookieControlsStatus.DISABLED;
boolean enabled = status == CookieControlsStatus.ENABLED;
......@@ -89,8 +87,10 @@ public class PageInfoCookiesPreference extends PreferenceFragmentCompat {
}
public void setCookiesCount(int allowedCookies, int blockedCookies) {
mCookieSwitch.setSummary(getContext().getResources().getQuantityString(
R.plurals.cookie_controls_blocked_cookies, blockedCookies, blockedCookies));
mCookieSwitch.setSummary(
blockedCookies > 0 ? getContext().getResources().getQuantityString(
R.plurals.cookie_controls_blocked_cookies, blockedCookies, blockedCookies)
: null);
mCookieInUse.setTitle(getContext().getResources().getQuantityString(
R.plurals.page_info_cookies_in_use, allowedCookies, allowedCookies));
}
......
......@@ -56,12 +56,9 @@ public class PageInfoPermissionsController implements PageInfoSubpageController
mSubpageFragment.setRefreshAfterReset(true);
AppCompatActivity host = (AppCompatActivity) mRowView.getContext();
host.getSupportFragmentManager().beginTransaction().add(mSubpageFragment, null).commitNow();
return mSubpageFragment.getView();
return mSubpageFragment.requireView();
}
@Override
public void onSubPageAttached() {}
@Override
public void onSubpageRemoved() {
assert mSubpageFragment != null;
......
......@@ -21,11 +21,6 @@ public interface PageInfoSubpageController {
*/
View createViewForSubpage(ViewGroup parent);
/**
* Called when the subpage was added to the view hierarchy.
*/
void onSubPageAttached();
/**
* Called after the subpage closes in order to perform any necessary cleanup.
*/
......
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