fix: wrong cause and removed flag in cookie change listener (#49103)

This commit is contained in:
Mr.Chaofan
2026-02-03 01:19:35 -08:00
committed by GitHub
parent 3776731f4a
commit 4413a0f642
4 changed files with 33 additions and 4 deletions

View File

@@ -80,6 +80,11 @@ struct Converter<net::CookieChangeCause> {
const net::CookieChangeCause& val) {
switch (val) {
case net::CookieChangeCause::INSERTED:
return gin::StringToV8(isolate, "inserted");
case net::CookieChangeCause::INSERTED_NO_CHANGE_OVERWRITE:
return gin::StringToV8(isolate, "inserted-no-change-overwrite");
case net::CookieChangeCause::INSERTED_NO_VALUE_CHANGE_OVERWRITE:
return gin::StringToV8(isolate, "inserted-no-value-change-overwrite");
case net::CookieChangeCause::EXPLICIT:
return gin::StringToV8(isolate, "explicit");
case net::CookieChangeCause::OVERWRITE:
@@ -272,6 +277,17 @@ std::string StringToCookieSameSite(const std::string* str_ptr,
return "";
}
bool IsDeletion(net::CookieChangeCause cause) {
switch (cause) {
case net::CookieChangeCause::INSERTED:
case net::CookieChangeCause::INSERTED_NO_CHANGE_OVERWRITE:
case net::CookieChangeCause::INSERTED_NO_VALUE_CHANGE_OVERWRITE:
return false;
default:
return true;
}
}
} // namespace
gin::DeprecatedWrapperInfo Cookies::kWrapperInfo = {gin::kEmbedderNativeGin};
@@ -435,10 +451,10 @@ v8::Local<v8::Promise> Cookies::FlushStore(v8::Isolate* isolate) {
void Cookies::OnCookieChanged(const net::CookieChangeInfo& change) {
v8::Isolate* isolate = JavascriptEnvironment::GetIsolate();
v8::HandleScope scope(isolate);
bool is_deletion = IsDeletion(change.cause);
Emit("changed", gin::ConvertToV8(isolate, change.cookie),
gin::ConvertToV8(isolate, change.cause),
gin::ConvertToV8(isolate,
change.cause != net::CookieChangeCause::INSERTED));
gin::ConvertToV8(isolate, is_deletion));
}
// static