}
void SerializedNavigationEntry::Sanitize() {
- // Store original referrer so we can later see whether it was actually
- // changed during sanitization, and we need to strip the referrer from the
- // page state as well.
- content::Referrer old_referrer = referrer_;
+ content::Referrer new_referrer =
+ content::Referrer::SanitizeForRequest(virtual_url_, referrer_);
- if (!referrer_.url.SchemeIsHTTPOrHTTPS())
- referrer_ = content::Referrer();
- switch (referrer_.policy) {
- case blink::WebReferrerPolicyNever:
- referrer_.url = GURL();
- break;
- case blink::WebReferrerPolicyAlways:
- break;
- case blink::WebReferrerPolicyOrigin:
- referrer_.url = referrer_.url.GetWithEmptyPath();
- break;
- case blink::WebReferrerPolicyDefault:
- // Fall through.
- default:
- referrer_.policy = blink::WebReferrerPolicyDefault;
- if (referrer_.url.SchemeIsSecure() && !virtual_url_.SchemeIsSecure())
- referrer_.url = GURL();
- }
-
- if (referrer_.url != old_referrer.url ||
- referrer_.policy != old_referrer.policy) {
+ // No need to compare the policy, as it doesn't change during
+ // sanitization. If there has been a change, the referrer needs to be
+ // stripped from the page state as well.
+ if (referrer_.url != new_referrer.url) {
referrer_ = content::Referrer();
page_state_ = page_state_.RemoveReferrer();
}