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