Skip to content

Commit

Permalink
[Cocoa] Tell AVFoundation to not log urls in private browsing mode
Browse files Browse the repository at this point in the history
https://bugs.webkit.org/show_bug.cgi?id=270476
rdar://118855410

Reviewed by Jer Noble.

Add a key to the options dictionary passed to the AVURLAsset constructor when WebKit
is in private browsing mode so it knows to never log urls.

* Source/WebCore/PAL/pal/cocoa/AVFoundationSoftLink.h: Define new constant string.
* Source/WebCore/PAL/pal/cocoa/AVFoundationSoftLink.mm:

* Source/WebCore/html/HTMLMediaElement.cpp:
(WebCore::HTMLMediaElement::privateBrowsingStateDidChange): Make the code the same on iOS
as on every other platform.

* Source/WebCore/platform/graphics/MediaPlayer.cpp:
(WebCore::MediaPlayer::loadWithNextMediaEngine): Update name of instance variable.
(WebCore::MediaPlayer::setPrivateBrowsingMode): Ditto.
* Source/WebCore/platform/graphics/MediaPlayer.h:

* Source/WebCore/platform/graphics/avfoundation/objc/MediaPlayerPrivateAVFoundationObjC.mm:
(WebCore::MediaPlayerPrivateAVFoundationObjC::createAVAssetForURL): Add new key to options
dictionary when in private browsing mode.

Canonical link: https://commits.webkit.org/275691@main
  • Loading branch information
eric-carlson committed Mar 5, 2024
1 parent e66ebfa commit b39a838
Show file tree
Hide file tree
Showing 6 changed files with 13 additions and 9 deletions.
3 changes: 3 additions & 0 deletions Source/WebCore/PAL/pal/cocoa/AVFoundationSoftLink.h
Original file line number Diff line number Diff line change
Expand Up @@ -387,6 +387,9 @@ SOFT_LINK_CONSTANT_FOR_HEADER(PAL, AVFoundation, AVAssetExportPresetHighestQuali
SOFT_LINK_CONSTANT_MAY_FAIL_FOR_HEADER(PAL, AVFoundation, AVURLAssetExtendedMIMETypePlayabilityTreatPlaylistMIMETypesAsISOBMFFMediaDataContainersKey, NSString *)
#define AVURLAssetExtendedMIMETypePlayabilityTreatPlaylistMIMETypesAsISOBMFFMediaDataContainersKey PAL::get_AVFoundation_AVURLAssetExtendedMIMETypePlayabilityTreatPlaylistMIMETypesAsISOBMFFMediaDataContainersKey()

SOFT_LINK_CONSTANT_MAY_FAIL_FOR_HEADER(PAL, AVFoundation, AVURLAssetDoNotLogURLsKey, NSString *)
#define AVURLAssetDoNotLogURLsKey PAL::get_AVFoundation_AVURLAssetDoNotLogURLsKey()

#if HAVE(AVAUDIOSESSION)
SOFT_LINK_CONSTANT_FOR_HEADER(PAL, AVFoundation, AVAudioSessionPortCarAudio, NSString *)
#define AVAudioSessionPortCarAudio PAL::get_AVFoundation_AVAudioSessionPortCarAudio()
Expand Down
2 changes: 2 additions & 0 deletions Source/WebCore/PAL/pal/cocoa/AVFoundationSoftLink.mm
Original file line number Diff line number Diff line change
Expand Up @@ -282,6 +282,8 @@ static BOOL justReturnsNO()

SOFT_LINK_CONSTANT_MAY_FAIL_FOR_SOURCE_WITH_EXPORT(PAL, AVFoundation, AVURLAssetExtendedMIMETypePlayabilityTreatPlaylistMIMETypesAsISOBMFFMediaDataContainersKey, NSString *, PAL_EXPORT)

SOFT_LINK_CONSTANT_MAY_FAIL_FOR_SOURCE_WITH_EXPORT(PAL, AVFoundation, AVURLAssetDoNotLogURLsKey, NSString *, PAL_EXPORT)

#if HAVE(AVAUDIOSESSION)
SOFT_LINK_CONSTANT_FOR_SOURCE_WITH_EXPORT(PAL, AVFoundation, AVAudioSessionPortCarAudio, NSString *, PAL_EXPORT)
SOFT_LINK_CONSTANT_FOR_SOURCE_WITH_EXPORT(PAL, AVFoundation, AVAudioSessionSpatialPlaybackCapabilitiesChangedNotification, NSString *, PAL_EXPORT)
Expand Down
5 changes: 0 additions & 5 deletions Source/WebCore/html/HTMLMediaElement.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -7389,13 +7389,8 @@ void HTMLMediaElement::clearMediaCacheForOrigins(const String& path, const HashS

void HTMLMediaElement::privateBrowsingStateDidChange(PAL::SessionID sessionID)
{
// FIXME: We should try to reconcile this so there's no difference for PLATFORM(IOS_FAMILY).
#if PLATFORM(IOS_FAMILY)
UNUSED_PARAM(sessionID);
#else
if (RefPtr player = m_player)
player->setPrivateBrowsingMode(sessionID.isEphemeral());
#endif
}

bool HTMLMediaElement::shouldForceControlsDisplay() const
Expand Down
6 changes: 3 additions & 3 deletions Source/WebCore/platform/graphics/MediaPlayer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -643,7 +643,7 @@ void MediaPlayer::loadWithNextMediaEngine(const MediaPlayerFactory* current)
if (m_shouldContinueAfterKeyNeeded)
m_private->setShouldContinueAfterKeyNeeded(m_shouldContinueAfterKeyNeeded);
#endif
m_private->prepareForPlayback(m_privateBrowsing, m_preload, m_preservesPitch, m_shouldPrepareToRender);
m_private->prepareForPlayback(m_inPrivateBrowsingMode, m_preload, m_preservesPitch, m_shouldPrepareToRender);
}
}

Expand Down Expand Up @@ -1417,9 +1417,9 @@ bool MediaPlayer::supportsKeySystem(const String& keySystem, const String& mimeT

void MediaPlayer::setPrivateBrowsingMode(bool privateBrowsingMode)
{
m_privateBrowsing = privateBrowsingMode;
m_inPrivateBrowsingMode = privateBrowsingMode;
if (m_private)
m_private->setPrivateBrowsingMode(m_privateBrowsing);
m_private->setPrivateBrowsingMode(m_inPrivateBrowsingMode);
}

// Client callbacks.
Expand Down
3 changes: 2 additions & 1 deletion Source/WebCore/platform/graphics/MediaPlayer.h
Original file line number Diff line number Diff line change
Expand Up @@ -576,6 +576,7 @@ class WEBCORE_EXPORT MediaPlayer : public MediaPlayerEnums, public ThreadSafeRef
unsigned videoDecodedByteCount() const;

void setPrivateBrowsingMode(bool);
bool inPrivateBrowsingMode() const { return m_inPrivateBrowsingMode; }

#if ENABLE(WEB_AUDIO)
AudioSourceProvider* audioSourceProvider();
Expand Down Expand Up @@ -767,7 +768,7 @@ class WEBCORE_EXPORT MediaPlayer : public MediaPlayerEnums, public ThreadSafeRef
bool m_visibleInViewport { false };
bool m_muted { false };
bool m_preservesPitch { true };
bool m_privateBrowsing { false };
bool m_inPrivateBrowsingMode { false };
bool m_shouldPrepareToRender { false };
bool m_contentMIMETypeWasInferredFromExtension { false };
bool m_initializingMediaEngine { false };
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -933,6 +933,9 @@ static URL conformFragmentIdentifierForURL(const URL& url)
if (player->prefersSandboxedParsing() && PAL::canLoad_AVFoundation_AVAssetPrefersSandboxedParsingOptionKey())
[options setObject:@YES forKey:AVAssetPrefersSandboxedParsingOptionKey];

if (player->inPrivateBrowsingMode() && PAL::canLoad_AVFoundation_AVURLAssetDoNotLogURLsKey())
[options setObject:@YES forKey:AVURLAssetDoNotLogURLsKey];

auto type = player->contentMIMEType();

// Don't advertise WebM MIME types or the format reader won't be loaded until rdar://72405127 is fixed.
Expand Down

0 comments on commit b39a838

Please sign in to comment.