diff --git a/content/browser/devtools/protocol/emulation_handler.cc b/content/browser/devtools/protocol/emulation_handler.cc index 4e75ecc093222..45ca225a38ae9 100644 --- a/content/browser/devtools/protocol/emulation_handler.cc +++ b/content/browser/devtools/protocol/emulation_handler.cc @@ -194,6 +194,9 @@ Response EmulationHandler::Disable() { pressure_overrides_.clear(); #endif // BUILDFLAG(ENABLE_COMPUTE_PRESSURE) ClearDevicePostureOverride(); + if (geolocation_override_set_) { + ClearGeolocationOverride(); + } return Response::Success(); } @@ -600,10 +603,12 @@ Response EmulationHandler::SetGeolocationOverride( /*error_message=*/"", /*error_technical=*/"")); } geolocation_context->SetOverride(std::move(override_result)); + geolocation_override_set_ = true; return Response::Success(); } Response EmulationHandler::ClearGeolocationOverride() { + geolocation_override_set_ = false; if (!host_) return Response::InternalError(); diff --git a/content/browser/devtools/protocol/emulation_handler.h b/content/browser/devtools/protocol/emulation_handler.h index ea99118bcc230..c7d2bb2df953c 100644 --- a/content/browser/devtools/protocol/emulation_handler.h +++ b/content/browser/devtools/protocol/emulation_handler.h @@ -214,6 +214,12 @@ class EmulationHandler : public DevToolsDomainHandler, // Enable/disable screen orientation lock emulation on the provider. void UpdateScreenOrientationEmulation(bool enabled); + // True when SetGeolocationOverride() has been called without a matching + // ClearGeolocationOverride(). Tracked so Disable() can revert the override + // on session detach (the override is stored on the WebContents-scoped + // GeolocationContext and would otherwise leak across origins). + bool geolocation_override_set_ = false; + // True when SetDevicePostureOverride() has been called. bool device_posture_emulation_enabled_ = false;