diff --git a/content/browser/cookie_deprecation_label/cookie_deprecation_label_browsertest.cc b/content/browser/cookie_deprecation_label/cookie_deprecation_label_browsertest.cc index b2e110ad1dce0..554180dc37bfd 100644 --- a/content/browser/cookie_deprecation_label/cookie_deprecation_label_browsertest.cc +++ b/content/browser/cookie_deprecation_label/cookie_deprecation_label_browsertest.cc @@ -520,6 +520,21 @@ IN_PROC_BROWSER_TEST_F(CookieDeprecationLabelEnabledBrowserTest, "label_test"); } +IN_PROC_BROWSER_TEST_F(CookieDeprecationLabelEnabledBrowserTest, + Incognito_LabelError) { + auto https_server = CreateTestServer(EmbeddedTestServer::TYPE_HTTPS); + ASSERT_TRUE(https_server->Start()); + + auto* incognito_shell = CreateOffTheRecordBrowser(); + + EXPECT_TRUE(NavigateToURL(incognito_shell, + https_server->GetURL("a.test", "/hello.html"))); + EXPECT_EQ(EvalJs(incognito_shell, R"((async () => { + return await navigator.cookieDeprecationLabel.getValue() + .catch(() => 'error'); })())"), + "error"); +} + } // namespace } // namespace content diff --git a/content/browser/storage_partition_impl.cc b/content/browser/storage_partition_impl.cc index 9b55d24de7dfb..f8b70b7f48b27 100644 --- a/content/browser/storage_partition_impl.cc +++ b/content/browser/storage_partition_impl.cc @@ -1452,8 +1452,10 @@ void StoragePartitionImpl::Initialize( std::make_unique<BluetoothAllowedDevicesMap>(); // Must be initialized before the `url_loader_factory_getter_`. + // Cookie deprecation traffic labels should not be sent in incognito mode. if (base::FeatureList::IsEnabled( - features::kCookieDeprecationFacilitatedTesting)) { + features::kCookieDeprecationFacilitatedTesting) && + !is_in_memory()) { cookie_deprecation_label_manager_ = std::make_unique<CookieDeprecationLabelManagerImpl>(browser_context_); } diff --git a/content/public/browser/content_browser_client.cc b/content/public/browser/content_browser_client.cc index 4d84a23408720..ecbd03ae61018 100644 --- a/content/public/browser/content_browser_client.cc +++ b/content/public/browser/content_browser_client.cc @@ -598,14 +598,14 @@ bool ContentBrowserClient::IsPrivateAggregationDebugModeAllowed( bool ContentBrowserClient::IsCookieDeprecationLabelAllowed( content::BrowserContext* browser_context) { - return true; + return false; } bool ContentBrowserClient::IsCookieDeprecationLabelAllowedForContext( content::BrowserContext* browser_context, const url::Origin& top_frame_origin, const url::Origin& context_origin) { - return true; + return false; } bool ContentBrowserClient::CanSendSCTAuditingReport( diff --git a/content/public/browser/content_browser_client.h b/content/public/browser/content_browser_client.h index 56057fe8c0b0f..049ab9f00d12d 100644 --- a/content/public/browser/content_browser_client.h +++ b/content/public/browser/content_browser_client.h @@ -985,12 +985,13 @@ class CONTENT_EXPORT ContentBrowserClient { const url::Origin& reporting_origin); // Returns whether cookie deprecation label should be allowed for the - // profile. + // profile. Defaults to false to ensure no traffic label is sent by default. virtual bool IsCookieDeprecationLabelAllowed( content::BrowserContext* browser_context); // Returns whether cookie deprecation label should be allowed for the - // profile in a given context. + // profile in a given context. Defaults to false to ensure no traffic label + // is sent by default. virtual bool IsCookieDeprecationLabelAllowedForContext( content::BrowserContext* browser_context, const url::Origin& top_frame_origin, diff --git a/content/shell/browser/shell_content_browser_client.cc b/content/shell/browser/shell_content_browser_client.cc index 1330f709ef8fb..0008e3c7c9600 100644 --- a/content/shell/browser/shell_content_browser_client.cc +++ b/content/shell/browser/shell_content_browser_client.cc @@ -481,6 +481,18 @@ bool ShellContentBrowserClient::IsSharedStorageSelectURLAllowed( return true; } +bool ShellContentBrowserClient::IsCookieDeprecationLabelAllowed( + content::BrowserContext* browser_context) { + return true; +} + +bool ShellContentBrowserClient::IsCookieDeprecationLabelAllowedForContext( + content::BrowserContext* browser_context, + const url::Origin& top_frame_origin, + const url::Origin& context_origin) { + return true; +} + GeneratedCodeCacheSettings ShellContentBrowserClient::GetGeneratedCodeCacheSettings( content::BrowserContext* context) { diff --git a/content/shell/browser/shell_content_browser_client.h b/content/shell/browser/shell_content_browser_client.h index 259626b007502..b33300b6da3ea 100644 --- a/content/shell/browser/shell_content_browser_client.h +++ b/content/shell/browser/shell_content_browser_client.h @@ -75,6 +75,12 @@ class ShellContentBrowserClient : public ContentBrowserClient { content::BrowserContext* browser_context, const url::Origin& top_frame_origin, const url::Origin& accessing_origin) override; + bool IsCookieDeprecationLabelAllowed( + content::BrowserContext* browser_context) override; + bool IsCookieDeprecationLabelAllowedForContext( + content::BrowserContext* browser_context, + const url::Origin& top_frame_origin, + const url::Origin& context_origin) override; GeneratedCodeCacheSettings GetGeneratedCodeCacheSettings( content::BrowserContext* context) override; base::OnceClosure SelectClientCertificate(