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;
import android.text.SpannableString;
import android.text.TextUtils;
import androidx.annotation.NonNull;
import androidx.annotation.Nullable;
import androidx.annotation.VisibleForTesting;
......@@ -56,9 +57,6 @@ public class ChromePageInfoControllerDelegate extends PageInfoControllerDelegate
private String mOfflinePageCreationDate;
private OfflinePageLoadUrlDelegate mOfflinePageLoadUrlDelegate;
// Bridge updating the CookieControlsView when cookie settings change.
private CookieControlsBridge mBridge;
public ChromePageInfoControllerDelegate(Context context, WebContents webContents,
Supplier<ModalDialogManager> modalDialogManagerSupplier,
OfflinePageLoadUrlDelegate offlinePageLoadUrlDelegate) {
......@@ -254,28 +252,13 @@ public class ChromePageInfoControllerDelegate extends PageInfoControllerDelegate
* {@inheritDoc}
*/
@Override
public void createCookieControlsBridge(CookieControlsObserver observer) {
@NonNull
public CookieControlsBridge createCookieControlsBridge(CookieControlsObserver observer) {
Profile profile = Profile.fromWebContents(mWebContents);
mBridge = new CookieControlsBridge(observer, mWebContents,
return new CookieControlsBridge(observer, mWebContents,
profile.isOffTheRecord() ? profile.getOriginalProfile() : null);
}
/**
* {@inheritDoc}
*/
@Override
public void onUiClosing() {
mBridge.onUiClosing();
}
/**
* {@inheritDoc}
*/
@Override
public void setThirdPartyCookieBlockingEnabledForSite(boolean blockCookies) {
mBridge.setThirdPartyCookieBlockingEnabledForSite(blockCookies);
}
@VisibleForTesting
void setOfflinePageStateForTesting(@OfflinePageState int offlinePageState) {
mOfflinePageState = offlinePageState;
......
......@@ -32,6 +32,7 @@ import org.chromium.base.annotations.CalledByNative;
import org.chromium.base.annotations.NativeMethods;
import org.chromium.base.metrics.RecordUserAction;
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.CookieControlsObserver;
import org.chromium.components.content_settings.CookieControlsStatus;
......@@ -144,6 +145,9 @@ public class PageInfoController implements ModalDialogProperties.Controller,
// The controller for the cookies section of the page info.
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
* C++ object and saves a pointer to it.
......@@ -240,7 +244,10 @@ public class PageInfoController implements ModalDialogProperties.Controller,
viewParams.siteSettingsButtonShown = 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.initOfflinePageUiParams(viewParams, mRunAfterDismissConsumer);
......@@ -279,7 +286,7 @@ public class PageInfoController implements ModalDialogProperties.Controller,
cookieControlsParams.onCheckedChangedCallback = (Boolean blockCookies) -> {
recordAction(blockCookies ? PageInfoAction.PAGE_INFO_COOKIE_BLOCKED_FOR_SITE
: PageInfoAction.PAGE_INFO_COOKIE_ALLOWED_FOR_SITE);
mDelegate.setThirdPartyCookieBlockingEnabledForSite(blockCookies);
mCookieBridge.setThirdPartyCookieBlockingEnabledForSite(blockCookies);
};
mView.getCookieControlsView().setParams(cookieControlsParams);
}
......@@ -290,7 +297,7 @@ public class PageInfoController implements ModalDialogProperties.Controller,
new PermissionParamsListBuilder(mContext, mWindowAndroid, mFullUrl, showTitle, this,
mView::setPermissions, mPermissionParamsListBuilderDelegate);
mNativePageInfoController = PageInfoControllerJni.get().init(this, mWebContents);
mDelegate.createCookieControlsBridge(this);
mCookieBridge = mDelegate.createCookieControlsBridge(this);
mWebContentsObserver = new WebContentsObserver(webContents) {
@Override
......@@ -333,6 +340,10 @@ public class PageInfoController implements ModalDialogProperties.Controller,
mDialog.destroy();
mDialog = null;
}
if (mCookieBridge != null) {
mCookieBridge.destroy();
mCookieBridge = null;
}
}
/**
......
......@@ -7,10 +7,12 @@ package org.chromium.components.page_info;
import android.content.Intent;
import androidx.annotation.IntDef;
import androidx.annotation.NonNull;
import androidx.annotation.Nullable;
import org.chromium.base.Consumer;
import org.chromium.base.supplier.Supplier;
import org.chromium.components.content_settings.CookieControlsBridge;
import org.chromium.components.content_settings.CookieControlsObserver;
import org.chromium.components.omnibox.AutocompleteSchemeClassifier;
import org.chromium.components.page_info.PageInfoView.PageInfoViewParams;
......@@ -22,7 +24,7 @@ import java.lang.annotation.RetentionPolicy;
/**
* Provides embedder-level information to PageInfoController.
*/
public class PageInfoControllerDelegate {
public abstract class PageInfoControllerDelegate {
@IntDef({OfflinePageState.NOT_OFFLINE_PAGE, OfflinePageState.TRUSTED_OFFLINE_PAGE,
OfflinePageState.UNTRUSTED_OFFLINE_PAGE})
@Retention(RetentionPolicy.SOURCE)
......@@ -193,23 +195,14 @@ public class PageInfoControllerDelegate {
* Show site settings for the URL passed in.
* @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.
* @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) {}
/**
* 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) {}
@NonNull
public abstract CookieControlsBridge createCookieControlsBridge(
CookieControlsObserver observer);
}
......@@ -7,10 +7,15 @@ package org.chromium.weblayer_private;
import android.content.Context;
import android.content.Intent;
import androidx.annotation.NonNull;
import org.chromium.base.StrictModeContext;
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.page_info.PageInfoControllerDelegate;
import org.chromium.content_public.browser.WebContents;
import org.chromium.ui.modaldialog.ModalDialogManager;
import org.chromium.url.GURL;
import org.chromium.weblayer_private.interfaces.SiteSettingsIntentHelper;
......@@ -20,18 +25,27 @@ import org.chromium.weblayer_private.interfaces.SiteSettingsIntentHelper;
*/
public class PageInfoControllerDelegateImpl extends PageInfoControllerDelegate {
private final Context mContext;
private final WebContents mWebContents;
private final String mProfileName;
public PageInfoControllerDelegateImpl(Context context, String profileName, GURL url,
Supplier<ModalDialogManager> modalDialogManager) {
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);
}
private PageInfoControllerDelegateImpl(Context context, WebContents webContents,
ProfileImpl profile, Supplier<ModalDialogManager> modalDialogManager) {
super(modalDialogManager, new AutocompleteSchemeClassifierImpl(),
/** vrHandler= */ null,
/** isSiteSettingsAvailable= */
UrlConstants.HTTP_SCHEME.equals(url.getScheme())
|| UrlConstants.HTTPS_SCHEME.equals(url.getScheme()),
/** cookieControlsShown= */ false);
isHttpOrHttps(webContents.getVisibleUrl()),
/** cookieControlsShown= */
CookieControlsBridge.isCookieControlsEnabled(profile));
mContext = context;
mProfileName = profileName;
mWebContents = webContents;
mProfileName = profile.getName();
}
/**
......@@ -47,4 +61,18 @@ public class PageInfoControllerDelegateImpl extends PageInfoControllerDelegate {
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;
import org.chromium.components.omnibox.SecurityStatusIcon;
import org.chromium.components.page_info.PageInfoController;
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.IUrlBarController;
import org.chromium.weblayer_private.interfaces.ObjectWrapper;
......@@ -166,13 +167,11 @@ public class UrlBarControllerImpl extends IUrlBarController.Stub {
}
private void showPageInfoUi(View v) {
WebContents webContents = mBrowserImpl.getActiveTab().getWebContents();
PageInfoController.show(mBrowserImpl.getWindowAndroid().getActivity().get(),
mBrowserImpl.getActiveTab().getWebContents(),
webContents,
/* contentPublisher= */ null, PageInfoController.OpenedFromSource.TOOLBAR,
new PageInfoControllerDelegateImpl(mBrowserImpl.getContext(),
mBrowserImpl.getProfile().getName(),
mBrowserImpl.getActiveTab().getWebContents().getVisibleUrl(),
mBrowserImpl.getWindowAndroid()::getModalDialogManager),
PageInfoControllerDelegateImpl.create(webContents),
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