Commit dc37aa25 authored by Evan Stade's avatar Evan Stade Committed by Commit Bot

Reland "WebLayer: hook up CookieControlsBridge."

This relands commit 0b009d85.

Original change's description:
> WebLayer: hook up CookieControlsBridge.
>
> When enabled, and when third party cookies are being blocked, this will
> show an extra toggle in the page info bubble.
>
> Test: run_weblayer_shell example.com --args="--enable-features=\"ImprovedCookieControls\""
> Bug: 1071775
>
> Change-Id: Ib0a6d6a1c80cafa4b8aeeea19cb9919df55a7f83
> Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/2240011
> Reviewed-by: Mugdha Lakhani <nator@chromium.org>
> Reviewed-by: Ted Choc <tedchoc@chromium.org>
> Reviewed-by: Christian Dullweber <dullweber@chromium.org>
> Commit-Queue: Evan Stade <estade@chromium.org>
> Cr-Commit-Position: refs/heads/master@{#781552}

Bug: 1071775
Change-Id: I6233d790786d4445df0f57406f1143701eebda2e
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/2264793Reviewed-by: default avatarChristian Dullweber <dullweber@chromium.org>
Reviewed-by: default avatarTed Choc <tedchoc@chromium.org>
Commit-Queue: Evan Stade <estade@chromium.org>
Cr-Commit-Position: refs/heads/master@{#781927}
parent 1b15a718
...@@ -9,6 +9,7 @@ import android.content.Intent; ...@@ -9,6 +9,7 @@ import android.content.Intent;
import android.text.SpannableString; import android.text.SpannableString;
import android.text.TextUtils; import android.text.TextUtils;
import androidx.annotation.NonNull;
import androidx.annotation.Nullable; import androidx.annotation.Nullable;
import androidx.annotation.VisibleForTesting; import androidx.annotation.VisibleForTesting;
...@@ -56,9 +57,6 @@ public class ChromePageInfoControllerDelegate extends PageInfoControllerDelegate ...@@ -56,9 +57,6 @@ public class ChromePageInfoControllerDelegate extends PageInfoControllerDelegate
private String mOfflinePageCreationDate; private String mOfflinePageCreationDate;
private OfflinePageLoadUrlDelegate mOfflinePageLoadUrlDelegate; private OfflinePageLoadUrlDelegate mOfflinePageLoadUrlDelegate;
// Bridge updating the CookieControlsView when cookie settings change.
private CookieControlsBridge mBridge;
public ChromePageInfoControllerDelegate(Context context, WebContents webContents, public ChromePageInfoControllerDelegate(Context context, WebContents webContents,
Supplier<ModalDialogManager> modalDialogManagerSupplier, Supplier<ModalDialogManager> modalDialogManagerSupplier,
OfflinePageLoadUrlDelegate offlinePageLoadUrlDelegate) { OfflinePageLoadUrlDelegate offlinePageLoadUrlDelegate) {
...@@ -254,28 +252,13 @@ public class ChromePageInfoControllerDelegate extends PageInfoControllerDelegate ...@@ -254,28 +252,13 @@ public class ChromePageInfoControllerDelegate extends PageInfoControllerDelegate
* {@inheritDoc} * {@inheritDoc}
*/ */
@Override @Override
public void createCookieControlsBridge(CookieControlsObserver observer) { @NonNull
public CookieControlsBridge createCookieControlsBridge(CookieControlsObserver observer) {
Profile profile = Profile.fromWebContents(mWebContents); Profile profile = Profile.fromWebContents(mWebContents);
mBridge = new CookieControlsBridge(observer, mWebContents, return new CookieControlsBridge(observer, mWebContents,
profile.isOffTheRecord() ? profile.getOriginalProfile() : null); profile.isOffTheRecord() ? profile.getOriginalProfile() : null);
} }
/**
* {@inheritDoc}
*/
@Override
public void onUiClosing() {
mBridge.onUiClosing();
}
/**
* {@inheritDoc}
*/
@Override
public void setThirdPartyCookieBlockingEnabledForSite(boolean blockCookies) {
mBridge.setThirdPartyCookieBlockingEnabledForSite(blockCookies);
}
@VisibleForTesting @VisibleForTesting
void setOfflinePageStateForTesting(@OfflinePageState int offlinePageState) { void setOfflinePageStateForTesting(@OfflinePageState int offlinePageState) {
mOfflinePageState = offlinePageState; mOfflinePageState = offlinePageState;
......
...@@ -32,6 +32,7 @@ import org.chromium.base.annotations.CalledByNative; ...@@ -32,6 +32,7 @@ import org.chromium.base.annotations.CalledByNative;
import org.chromium.base.annotations.NativeMethods; import org.chromium.base.annotations.NativeMethods;
import org.chromium.base.metrics.RecordUserAction; import org.chromium.base.metrics.RecordUserAction;
import org.chromium.components.content_settings.ContentSettingValues; import org.chromium.components.content_settings.ContentSettingValues;
import org.chromium.components.content_settings.CookieControlsBridge;
import org.chromium.components.content_settings.CookieControlsEnforcement; import org.chromium.components.content_settings.CookieControlsEnforcement;
import org.chromium.components.content_settings.CookieControlsObserver; import org.chromium.components.content_settings.CookieControlsObserver;
import org.chromium.components.content_settings.CookieControlsStatus; import org.chromium.components.content_settings.CookieControlsStatus;
...@@ -144,6 +145,9 @@ public class PageInfoController implements ModalDialogProperties.Controller, ...@@ -144,6 +145,9 @@ public class PageInfoController implements ModalDialogProperties.Controller,
// The controller for the cookies section of the page info. // The controller for the cookies section of the page info.
private PageInfoCookiesController mCookiesController; private PageInfoCookiesController mCookiesController;
// Bridge updating the CookieControlsView when cookie settings change.
private CookieControlsBridge mCookieBridge;
/** /**
* Creates the PageInfoController, but does not display it. Also initializes the corresponding * Creates the PageInfoController, but does not display it. Also initializes the corresponding
* C++ object and saves a pointer to it. * C++ object and saves a pointer to it.
...@@ -240,7 +244,10 @@ public class PageInfoController implements ModalDialogProperties.Controller, ...@@ -240,7 +244,10 @@ public class PageInfoController implements ModalDialogProperties.Controller,
viewParams.siteSettingsButtonShown = false; viewParams.siteSettingsButtonShown = false;
viewParams.cookieControlsShown = false; viewParams.cookieControlsShown = false;
} }
viewParams.onUiClosingCallback = mDelegate::onUiClosing; viewParams.onUiClosingCallback = () -> {
// |this| may have already been destroyed by the time this is called.
if (mCookieBridge != null) mCookieBridge.onUiClosing();
};
mDelegate.initPreviewUiParams(viewParams, mRunAfterDismissConsumer); mDelegate.initPreviewUiParams(viewParams, mRunAfterDismissConsumer);
mDelegate.initOfflinePageUiParams(viewParams, mRunAfterDismissConsumer); mDelegate.initOfflinePageUiParams(viewParams, mRunAfterDismissConsumer);
...@@ -279,7 +286,7 @@ public class PageInfoController implements ModalDialogProperties.Controller, ...@@ -279,7 +286,7 @@ public class PageInfoController implements ModalDialogProperties.Controller,
cookieControlsParams.onCheckedChangedCallback = (Boolean blockCookies) -> { cookieControlsParams.onCheckedChangedCallback = (Boolean blockCookies) -> {
recordAction(blockCookies ? PageInfoAction.PAGE_INFO_COOKIE_BLOCKED_FOR_SITE recordAction(blockCookies ? PageInfoAction.PAGE_INFO_COOKIE_BLOCKED_FOR_SITE
: PageInfoAction.PAGE_INFO_COOKIE_ALLOWED_FOR_SITE); : PageInfoAction.PAGE_INFO_COOKIE_ALLOWED_FOR_SITE);
mDelegate.setThirdPartyCookieBlockingEnabledForSite(blockCookies); mCookieBridge.setThirdPartyCookieBlockingEnabledForSite(blockCookies);
}; };
mView.getCookieControlsView().setParams(cookieControlsParams); mView.getCookieControlsView().setParams(cookieControlsParams);
} }
...@@ -290,7 +297,7 @@ public class PageInfoController implements ModalDialogProperties.Controller, ...@@ -290,7 +297,7 @@ public class PageInfoController implements ModalDialogProperties.Controller,
new PermissionParamsListBuilder(mContext, mWindowAndroid, mFullUrl, showTitle, this, new PermissionParamsListBuilder(mContext, mWindowAndroid, mFullUrl, showTitle, this,
mView::setPermissions, mPermissionParamsListBuilderDelegate); mView::setPermissions, mPermissionParamsListBuilderDelegate);
mNativePageInfoController = PageInfoControllerJni.get().init(this, mWebContents); mNativePageInfoController = PageInfoControllerJni.get().init(this, mWebContents);
mDelegate.createCookieControlsBridge(this); mCookieBridge = mDelegate.createCookieControlsBridge(this);
mWebContentsObserver = new WebContentsObserver(webContents) { mWebContentsObserver = new WebContentsObserver(webContents) {
@Override @Override
...@@ -333,6 +340,10 @@ public class PageInfoController implements ModalDialogProperties.Controller, ...@@ -333,6 +340,10 @@ public class PageInfoController implements ModalDialogProperties.Controller,
mDialog.destroy(); mDialog.destroy();
mDialog = null; mDialog = null;
} }
if (mCookieBridge != null) {
mCookieBridge.destroy();
mCookieBridge = null;
}
} }
/** /**
......
...@@ -7,10 +7,12 @@ package org.chromium.components.page_info; ...@@ -7,10 +7,12 @@ package org.chromium.components.page_info;
import android.content.Intent; import android.content.Intent;
import androidx.annotation.IntDef; import androidx.annotation.IntDef;
import androidx.annotation.NonNull;
import androidx.annotation.Nullable; import androidx.annotation.Nullable;
import org.chromium.base.Consumer; import org.chromium.base.Consumer;
import org.chromium.base.supplier.Supplier; import org.chromium.base.supplier.Supplier;
import org.chromium.components.content_settings.CookieControlsBridge;
import org.chromium.components.content_settings.CookieControlsObserver; import org.chromium.components.content_settings.CookieControlsObserver;
import org.chromium.components.omnibox.AutocompleteSchemeClassifier; import org.chromium.components.omnibox.AutocompleteSchemeClassifier;
import org.chromium.components.page_info.PageInfoView.PageInfoViewParams; import org.chromium.components.page_info.PageInfoView.PageInfoViewParams;
...@@ -22,7 +24,7 @@ import java.lang.annotation.RetentionPolicy; ...@@ -22,7 +24,7 @@ import java.lang.annotation.RetentionPolicy;
/** /**
* Provides embedder-level information to PageInfoController. * Provides embedder-level information to PageInfoController.
*/ */
public class PageInfoControllerDelegate { public abstract class PageInfoControllerDelegate {
@IntDef({OfflinePageState.NOT_OFFLINE_PAGE, OfflinePageState.TRUSTED_OFFLINE_PAGE, @IntDef({OfflinePageState.NOT_OFFLINE_PAGE, OfflinePageState.TRUSTED_OFFLINE_PAGE,
OfflinePageState.UNTRUSTED_OFFLINE_PAGE}) OfflinePageState.UNTRUSTED_OFFLINE_PAGE})
@Retention(RetentionPolicy.SOURCE) @Retention(RetentionPolicy.SOURCE)
...@@ -193,23 +195,14 @@ public class PageInfoControllerDelegate { ...@@ -193,23 +195,14 @@ public class PageInfoControllerDelegate {
* Show site settings for the URL passed in. * Show site settings for the URL passed in.
* @param url The URL to show site settings for. * @param url The URL to show site settings for.
*/ */
public void showSiteSettings(String url) {} public abstract void showSiteSettings(String url);
// TODO(crbug.com/1052375): Remove the next three methods when cookie controls UI
// has been componentized.
/** /**
* Creates Cookie Controls Bridge. * Creates Cookie Controls Bridge.
* @param The CookieControlsObserver to create the bridge with. * @param observer The CookieControlsObserver to create the bridge with.
* @return the object that facilitates interfacing with native code.
*/ */
public void createCookieControlsBridge(CookieControlsObserver observer) {} @NonNull
public abstract CookieControlsBridge createCookieControlsBridge(
/** CookieControlsObserver observer);
* Called when cookie controls UI is closed.
*/
public void onUiClosing() {}
/**
* Notes whether third party cookies should be blocked for the site.
*/
public void setThirdPartyCookieBlockingEnabledForSite(boolean blockCookies) {}
} }
...@@ -7,10 +7,15 @@ package org.chromium.weblayer_private; ...@@ -7,10 +7,15 @@ package org.chromium.weblayer_private;
import android.content.Context; import android.content.Context;
import android.content.Intent; import android.content.Intent;
import androidx.annotation.NonNull;
import org.chromium.base.StrictModeContext; import org.chromium.base.StrictModeContext;
import org.chromium.base.supplier.Supplier; import org.chromium.base.supplier.Supplier;
import org.chromium.components.content_settings.CookieControlsBridge;
import org.chromium.components.content_settings.CookieControlsObserver;
import org.chromium.components.embedder_support.util.UrlConstants; import org.chromium.components.embedder_support.util.UrlConstants;
import org.chromium.components.page_info.PageInfoControllerDelegate; import org.chromium.components.page_info.PageInfoControllerDelegate;
import org.chromium.content_public.browser.WebContents;
import org.chromium.ui.modaldialog.ModalDialogManager; import org.chromium.ui.modaldialog.ModalDialogManager;
import org.chromium.url.GURL; import org.chromium.url.GURL;
import org.chromium.weblayer_private.interfaces.SiteSettingsIntentHelper; import org.chromium.weblayer_private.interfaces.SiteSettingsIntentHelper;
...@@ -20,18 +25,27 @@ import org.chromium.weblayer_private.interfaces.SiteSettingsIntentHelper; ...@@ -20,18 +25,27 @@ import org.chromium.weblayer_private.interfaces.SiteSettingsIntentHelper;
*/ */
public class PageInfoControllerDelegateImpl extends PageInfoControllerDelegate { public class PageInfoControllerDelegateImpl extends PageInfoControllerDelegate {
private final Context mContext; private final Context mContext;
private final WebContents mWebContents;
private final String mProfileName; private final String mProfileName;
public PageInfoControllerDelegateImpl(Context context, String profileName, GURL url, static PageInfoControllerDelegateImpl create(WebContents webContents) {
Supplier<ModalDialogManager> modalDialogManager) { TabImpl tab = TabImpl.fromWebContents(webContents);
assert tab != null;
return new PageInfoControllerDelegateImpl(tab.getBrowser().getContext(), webContents,
tab.getProfile(), tab.getBrowser().getWindowAndroid()::getModalDialogManager);
}
private PageInfoControllerDelegateImpl(Context context, WebContents webContents,
ProfileImpl profile, Supplier<ModalDialogManager> modalDialogManager) {
super(modalDialogManager, new AutocompleteSchemeClassifierImpl(), super(modalDialogManager, new AutocompleteSchemeClassifierImpl(),
/** vrHandler= */ null, /** vrHandler= */ null,
/** isSiteSettingsAvailable= */ /** isSiteSettingsAvailable= */
UrlConstants.HTTP_SCHEME.equals(url.getScheme()) isHttpOrHttps(webContents.getVisibleUrl()),
|| UrlConstants.HTTPS_SCHEME.equals(url.getScheme()), /** cookieControlsShown= */
/** cookieControlsShown= */ false); CookieControlsBridge.isCookieControlsEnabled(profile));
mContext = context; mContext = context;
mProfileName = profileName; mWebContents = webContents;
mProfileName = profile.getName();
} }
/** /**
...@@ -47,4 +61,18 @@ public class PageInfoControllerDelegateImpl extends PageInfoControllerDelegate { ...@@ -47,4 +61,18 @@ public class PageInfoControllerDelegateImpl extends PageInfoControllerDelegate {
mContext.startActivity(intent); mContext.startActivity(intent);
} }
} }
/**
* {@inheritDoc}
*/
@Override
@NonNull
public CookieControlsBridge createCookieControlsBridge(CookieControlsObserver observer) {
return new CookieControlsBridge(observer, mWebContents, null);
}
private static boolean isHttpOrHttps(GURL url) {
String scheme = url.getScheme();
return UrlConstants.HTTP_SCHEME.equals(scheme) || UrlConstants.HTTPS_SCHEME.equals(scheme);
}
} }
...@@ -28,6 +28,7 @@ import org.chromium.components.omnibox.SecurityButtonAnimationDelegate; ...@@ -28,6 +28,7 @@ import org.chromium.components.omnibox.SecurityButtonAnimationDelegate;
import org.chromium.components.omnibox.SecurityStatusIcon; import org.chromium.components.omnibox.SecurityStatusIcon;
import org.chromium.components.page_info.PageInfoController; import org.chromium.components.page_info.PageInfoController;
import org.chromium.components.page_info.PermissionParamsListBuilderDelegate; import org.chromium.components.page_info.PermissionParamsListBuilderDelegate;
import org.chromium.content_public.browser.WebContents;
import org.chromium.weblayer_private.interfaces.IObjectWrapper; import org.chromium.weblayer_private.interfaces.IObjectWrapper;
import org.chromium.weblayer_private.interfaces.IUrlBarController; import org.chromium.weblayer_private.interfaces.IUrlBarController;
import org.chromium.weblayer_private.interfaces.ObjectWrapper; import org.chromium.weblayer_private.interfaces.ObjectWrapper;
...@@ -166,13 +167,11 @@ public class UrlBarControllerImpl extends IUrlBarController.Stub { ...@@ -166,13 +167,11 @@ public class UrlBarControllerImpl extends IUrlBarController.Stub {
} }
private void showPageInfoUi(View v) { private void showPageInfoUi(View v) {
WebContents webContents = mBrowserImpl.getActiveTab().getWebContents();
PageInfoController.show(mBrowserImpl.getWindowAndroid().getActivity().get(), PageInfoController.show(mBrowserImpl.getWindowAndroid().getActivity().get(),
mBrowserImpl.getActiveTab().getWebContents(), webContents,
/* contentPublisher= */ null, PageInfoController.OpenedFromSource.TOOLBAR, /* contentPublisher= */ null, PageInfoController.OpenedFromSource.TOOLBAR,
new PageInfoControllerDelegateImpl(mBrowserImpl.getContext(), PageInfoControllerDelegateImpl.create(webContents),
mBrowserImpl.getProfile().getName(),
mBrowserImpl.getActiveTab().getWebContents().getVisibleUrl(),
mBrowserImpl.getWindowAndroid()::getModalDialogManager),
new PermissionParamsListBuilderDelegate(mBrowserImpl.getProfile())); new PermissionParamsListBuilderDelegate(mBrowserImpl.getProfile()));
} }
......
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