From 31f399b7cd8851ad5e18fac6b7f73c95726d1adb Mon Sep 17 00:00:00 2001 From: Shuran Huang Date: Fri, 17 Jan 2025 02:38:28 +0000 Subject: [PATCH] Invoke setCookieControls CDP before iframe network agent auto attach This makes sure the iframe network handler has the correct cookie controls settings after reloading the page. Bug: 375352611 Change-Id: Ia39df476823ed78d14db9e5493b3250474a19912 Reviewed-on: https://chromium-review.googlesource.com/c/devtools/devtools-frontend/+/6175282 Reviewed-by: Danil Somsikov Commit-Queue: Shuran Huang --- front_end/core/sdk/NetworkManager.test.ts | 25 +++++++++++++++++++++++ front_end/core/sdk/NetworkManager.ts | 5 +++++ 2 files changed, 30 insertions(+) diff --git a/front_end/core/sdk/NetworkManager.test.ts b/front_end/core/sdk/NetworkManager.test.ts index 6aede4b1407..99fffeb16db 100644 --- a/front_end/core/sdk/NetworkManager.test.ts +++ b/front_end/core/sdk/NetworkManager.test.ts @@ -19,6 +19,31 @@ const {urlString} = Platform.DevToolsPath; const LONG_URL_PART = 'LoremIpsumDolorSitAmetConsecteturAdipiscingElitPhasellusVitaeOrciInAugueCondimentumTinciduntUtEgetDolorQuisqueEfficiturUltricesTinciduntVivamusVelitPurusCommodoQuisErosSitAmetTemporMalesuadaNislNullamTtempusVulputateAugueEgetScelerisqueLacusVestibulumNon/index.html'; +describeWithMockConnection('NetworkManager', () => { + it('setCookieControls gets invoked when network agent auto attach', () => { + const enableThirdPartyCookieRestrictionSetting = + Common.Settings.Settings.instance().createSetting('cookie-control-override-enabled', true); + const disableThirdPartyCookieMetadataSetting = + Common.Settings.Settings.instance().createSetting('grace-period-mitigation-disabled', false); + const disableThirdPartyCookieHeuristicsSetting = + Common.Settings.Settings.instance().createSetting('heuristic-mitigation-disabled', false); + assert.isTrue(enableThirdPartyCookieRestrictionSetting.get()); + assert.isFalse(disableThirdPartyCookieMetadataSetting.get()); + assert.isFalse(disableThirdPartyCookieHeuristicsSetting.get()); + + const target = createTarget(); + const expectedCall = sinon.spy(target.networkAgent(), 'invoke_setCookieControls'); + + new SDK.NetworkManager.NetworkManager(target); + + assert.isTrue(expectedCall.calledOnceWith({ + enableThirdPartyCookieRestriction: true, + disableThirdPartyCookieMetadata: false, + disableThirdPartyCookieHeuristics: false + })); + }); +}); + describeWithMockConnection('MultitargetNetworkManager', () => { describe('Trust Token done event', () => { it('is not lost when arriving before the corresponding requestWillBeSent event', () => { diff --git a/front_end/core/sdk/NetworkManager.ts b/front_end/core/sdk/NetworkManager.ts index bf902f06505..330577d8c10 100644 --- a/front_end/core/sdk/NetworkManager.ts +++ b/front_end/core/sdk/NetworkManager.ts @@ -147,6 +147,11 @@ export class NetworkManager extends SDKModel { if (Common.Settings.Settings.instance().moduleSetting('cache-disabled').get()) { void this.#networkAgent.invoke_setCacheDisabled({cacheDisabled: true}); } + if (Common.Settings.Settings.instance().createSetting('cookie-control-override-enabled', undefined).get() || + Common.Settings.Settings.instance().createSetting('grace-period-mitigation-disabled', undefined).get() || + Common.Settings.Settings.instance().createSetting('heuristic-mitigation-disabled', undefined).get()) { + this.cookieControlFlagsSettingChanged(); + } void this.#networkAgent.invoke_enable({maxPostDataSize: MAX_EAGER_POST_REQUEST_BODY_LENGTH}); void this.#networkAgent.invoke_setAttachDebugStack({enabled: true});