Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
Unreviewed, rolling out r199315.
https://bugs.webkit.org/show_bug.cgi?id=156482

This change broke the OS X Yosemite build. (Requested by jwtan
on #webkit).

Reverted changeset:

"When clearing cache, also clear AVFoundation cache."
https://bugs.webkit.org/show_bug.cgi?id=155783
http://trac.webkit.org/changeset/199315

Canonical link: https://commits.webkit.org/174577@main
git-svn-id: https://svn.webkit.org/repository/webkit/trunk@199321 268f45cc-cd09-0410-ab3c-d52691b4dbfc
  • Loading branch information
webkit-commit-queue committed Apr 11, 2016
1 parent 4a91546 commit b74c574
Show file tree
Hide file tree
Showing 28 changed files with 77 additions and 359 deletions.
14 changes: 14 additions & 0 deletions Source/WebCore/ChangeLog
@@ -1,3 +1,17 @@
2016-04-11 Commit Queue <commit-queue@webkit.org>

Unreviewed, rolling out r199315.
https://bugs.webkit.org/show_bug.cgi?id=156482

This change broke the OS X Yosemite build. (Requested by jwtan
on #webkit).

Reverted changeset:

"When clearing cache, also clear AVFoundation cache."
https://bugs.webkit.org/show_bug.cgi?id=155783
http://trac.webkit.org/changeset/199315

2016-04-11 Brian Burg <bburg@apple.com>

Web Inspector: get rid of InspectorBasicValue and InspectorString subclasses
Expand Down
34 changes: 7 additions & 27 deletions Source/WebCore/html/HTMLMediaElement.cpp
Expand Up @@ -5593,36 +5593,21 @@ void HTMLMediaElement::setShouldDelayLoadEvent(bool shouldDelay)
else
document().decrementLoadEventDelayCount();
}


static String& sharedMediaCacheDirectory()
{
static NeverDestroyed<String> sharedMediaCacheDirectory;
return sharedMediaCacheDirectory;
}

void HTMLMediaElement::setMediaCacheDirectory(const String& path)
{
sharedMediaCacheDirectory() = path;
}

const String& HTMLMediaElement::mediaCacheDirectory()
{
return sharedMediaCacheDirectory();
}

HashSet<RefPtr<SecurityOrigin>> HTMLMediaElement::originsInMediaCache(const String& path)
void HTMLMediaElement::getSitesInMediaCache(Vector<String>& sites)
{
return MediaPlayer::originsInMediaCache(path);
MediaPlayer::getSitesInMediaCache(sites);
}

void HTMLMediaElement::clearMediaCache(const String& path, std::chrono::system_clock::time_point modifiedSince)
void HTMLMediaElement::clearMediaCache()
{
MediaPlayer::clearMediaCache(path, modifiedSince);
MediaPlayer::clearMediaCache();
}

void HTMLMediaElement::clearMediaCacheForOrigins(const String& path, const HashSet<RefPtr<SecurityOrigin>>& origins)
void HTMLMediaElement::clearMediaCacheForSite(const String& site)
{
MediaPlayer::clearMediaCacheForOrigins(path, origins);
MediaPlayer::clearMediaCacheForSite(site);
}

void HTMLMediaElement::resetMediaEngines()
Expand Down Expand Up @@ -6207,11 +6192,6 @@ bool HTMLMediaElement::mediaPlayerShouldUsePersistentCache() const
return false;
}

const String& HTMLMediaElement::mediaPlayerMediaCacheDirectory() const
{
return mediaCacheDirectory();
}

bool HTMLMediaElement::mediaPlayerShouldWaitForResponseToAuthenticationChallenge(const AuthenticationChallenge& challenge)
{
Frame* frame = document().frame();
Expand Down
9 changes: 3 additions & 6 deletions Source/WebCore/html/HTMLMediaElement.h
Expand Up @@ -380,11 +380,9 @@ class HTMLMediaElement
void privateBrowsingStateDidChange() override;

// Media cache management.
WEBCORE_EXPORT static void setMediaCacheDirectory(const String&);
WEBCORE_EXPORT static const String& mediaCacheDirectory();
WEBCORE_EXPORT static HashSet<RefPtr<SecurityOrigin>> originsInMediaCache(const String&);
WEBCORE_EXPORT static void clearMediaCache(const String&, std::chrono::system_clock::time_point modifiedSince = { });
WEBCORE_EXPORT static void clearMediaCacheForOrigins(const String&, const HashSet<RefPtr<SecurityOrigin>>&);
WEBCORE_EXPORT static void getSitesInMediaCache(Vector<String>&);
WEBCORE_EXPORT static void clearMediaCache();
WEBCORE_EXPORT static void clearMediaCacheForSite(const String&);
static void resetMediaEngines();

bool isPlaying() const { return m_playing; }
Expand Down Expand Up @@ -599,7 +597,6 @@ class HTMLMediaElement
CachedResourceLoader* mediaPlayerCachedResourceLoader() override;
RefPtr<PlatformMediaResourceLoader> mediaPlayerCreateResourceLoader() override;
bool mediaPlayerShouldUsePersistentCache() const override;
const String& mediaPlayerMediaCacheDirectory() const override;

#if PLATFORM(WIN) && USE(AVFOUNDATION)
GraphicsDeviceAdapter* mediaPlayerGraphicsDeviceAdapter(const MediaPlayer*) const override;
Expand Down
39 changes: 15 additions & 24 deletions Source/WebCore/platform/graphics/MediaPlayer.cpp
Expand Up @@ -170,13 +170,13 @@ struct MediaPlayerFactory {
CreateMediaEnginePlayer constructor;
MediaEngineSupportedTypes getSupportedTypes;
MediaEngineSupportsType supportsTypeAndCodecs;
MediaEngineOriginsInMediaCache originsInMediaCache;
MediaEngineGetSitesInMediaCache getSitesInMediaCache;
MediaEngineClearMediaCache clearMediaCache;
MediaEngineClearMediaCacheForOrigins clearMediaCacheForOrigins;
MediaEngineClearMediaCacheForSite clearMediaCacheForSite;
MediaEngineSupportsKeySystem supportsKeySystem;
};

static void addMediaEngine(CreateMediaEnginePlayer, MediaEngineSupportedTypes, MediaEngineSupportsType, MediaEngineOriginsInMediaCache, MediaEngineClearMediaCache, MediaEngineClearMediaCacheForOrigins, MediaEngineSupportsKeySystem);
static void addMediaEngine(CreateMediaEnginePlayer, MediaEngineSupportedTypes, MediaEngineSupportsType, MediaEngineGetSitesInMediaCache, MediaEngineClearMediaCache, MediaEngineClearMediaCacheForSite, MediaEngineSupportsKeySystem);

static bool haveMediaEnginesVector;

Expand Down Expand Up @@ -234,13 +234,13 @@ static const Vector<MediaPlayerFactory>& installedMediaEngines()
}

static void addMediaEngine(CreateMediaEnginePlayer constructor, MediaEngineSupportedTypes getSupportedTypes, MediaEngineSupportsType supportsType,
MediaEngineOriginsInMediaCache originsInMediaCache, MediaEngineClearMediaCache clearMediaCache, MediaEngineClearMediaCacheForOrigins clearMediaCacheForOrigins, MediaEngineSupportsKeySystem supportsKeySystem)
MediaEngineGetSitesInMediaCache getSitesInMediaCache, MediaEngineClearMediaCache clearMediaCache, MediaEngineClearMediaCacheForSite clearMediaCacheForSite, MediaEngineSupportsKeySystem supportsKeySystem)
{
ASSERT(constructor);
ASSERT(getSupportedTypes);
ASSERT(supportsType);

mutableInstalledMediaEnginesVector().append(MediaPlayerFactory { constructor, getSupportedTypes, supportsType, originsInMediaCache, clearMediaCache, clearMediaCacheForOrigins, supportsKeySystem });
mutableInstalledMediaEnginesVector().append(MediaPlayerFactory { constructor, getSupportedTypes, supportsType, getSitesInMediaCache, clearMediaCache, clearMediaCacheForSite, supportsKeySystem });
}

static const AtomicString& applicationOctetStream()
Expand Down Expand Up @@ -1042,39 +1042,30 @@ void MediaPlayer::reloadTimerFired()
loadWithNextMediaEngine(m_currentMediaEngine);
}

template<typename T>
static void addToHash(HashSet<T>& toHash, HashSet<T>&& fromHash)
void MediaPlayer::getSitesInMediaCache(Vector<String>& sites)
{
if (toHash.isEmpty())
toHash = WTFMove(fromHash);
else
toHash.add(fromHash.begin(), fromHash.end());
}

HashSet<RefPtr<SecurityOrigin>> MediaPlayer::originsInMediaCache(const String& path)
{
HashSet<RefPtr<SecurityOrigin>> origins;
for (auto& engine : installedMediaEngines()) {
if (!engine.originsInMediaCache)
if (!engine.getSitesInMediaCache)
continue;
addToHash(origins, engine.originsInMediaCache(path));
Vector<String> engineSites;
engine.getSitesInMediaCache(engineSites);
sites.appendVector(engineSites);
}
return origins;
}

void MediaPlayer::clearMediaCache(const String& path, std::chrono::system_clock::time_point modifiedSince)
void MediaPlayer::clearMediaCache()
{
for (auto& engine : installedMediaEngines()) {
if (engine.clearMediaCache)
engine.clearMediaCache(path, modifiedSince);
engine.clearMediaCache();
}
}

void MediaPlayer::clearMediaCacheForOrigins(const String& path, const HashSet<RefPtr<SecurityOrigin>>& origins)
void MediaPlayer::clearMediaCacheForSite(const String& site)
{
for (auto& engine : installedMediaEngines()) {
if (engine.clearMediaCacheForOrigins)
engine.clearMediaCacheForOrigins(path, origins);
if (engine.clearMediaCacheForSite)
engine.clearMediaCacheForSite(site);
}
}

Expand Down
16 changes: 7 additions & 9 deletions Source/WebCore/platform/graphics/MediaPlayer.h
Expand Up @@ -40,7 +40,6 @@
#include "PlatformLayer.h"
#include "PlatformMediaResourceLoader.h"
#include "PlatformMediaSession.h"
#include "SecurityOriginHash.h"
#include "Timer.h"
#include "VideoTrackPrivate.h"
#include <runtime/Uint8Array.h>
Expand Down Expand Up @@ -237,7 +236,6 @@ class MediaPlayerClient {
virtual RefPtr<PlatformMediaResourceLoader> mediaPlayerCreateResourceLoader() { return nullptr; }
virtual bool doesHaveAttribute(const AtomicString&, AtomicString* = 0) const { return false; }
virtual bool mediaPlayerShouldUsePersistentCache() const { return true; }
virtual const String& mediaPlayerMediaCacheDirectory() const { return emptyString(); }

#if ENABLE(VIDEO_TRACK)
virtual void mediaPlayerDidAddAudioTrack(PassRefPtr<AudioTrackPrivate>) { }
Expand Down Expand Up @@ -294,9 +292,9 @@ class MediaPlayer : public MediaPlayerEnums {
static MediaPlayer::SupportsType supportsType(const MediaEngineSupportParameters&, const MediaPlayerSupportsTypeClient*);
static void getSupportedTypes(HashSet<String, ASCIICaseInsensitiveHash>&);
static bool isAvailable();
static HashSet<RefPtr<SecurityOrigin>> originsInMediaCache(const String& path);
static void clearMediaCache(const String& path, std::chrono::system_clock::time_point modifiedSince);
static void clearMediaCacheForOrigins(const String& path, const HashSet<RefPtr<SecurityOrigin>>&);
static void getSitesInMediaCache(Vector<String>&);
static void clearMediaCache();
static void clearMediaCacheForSite(const String&);
static bool supportsKeySystem(const String& keySystem, const String& mimeType);

bool supportsFullscreen() const;
Expand Down Expand Up @@ -632,13 +630,13 @@ class MediaPlayer : public MediaPlayerEnums {
typedef std::function<std::unique_ptr<MediaPlayerPrivateInterface> (MediaPlayer*)> CreateMediaEnginePlayer;
typedef void (*MediaEngineSupportedTypes)(HashSet<String, ASCIICaseInsensitiveHash>& types);
typedef MediaPlayer::SupportsType (*MediaEngineSupportsType)(const MediaEngineSupportParameters& parameters);
typedef HashSet<RefPtr<SecurityOrigin>> (*MediaEngineOriginsInMediaCache)(const String& path);
typedef void (*MediaEngineClearMediaCache)(const String& path, std::chrono::system_clock::time_point modifiedSince);
typedef void (*MediaEngineClearMediaCacheForOrigins)(const String& path, const HashSet<RefPtr<SecurityOrigin>>&);
typedef void (*MediaEngineGetSitesInMediaCache)(Vector<String>&);
typedef void (*MediaEngineClearMediaCache)();
typedef void (*MediaEngineClearMediaCacheForSite)(const String&);
typedef bool (*MediaEngineSupportsKeySystem)(const String& keySystem, const String& mimeType);

typedef void (*MediaEngineRegistrar)(CreateMediaEnginePlayer, MediaEngineSupportedTypes, MediaEngineSupportsType,
MediaEngineOriginsInMediaCache, MediaEngineClearMediaCache, MediaEngineClearMediaCacheForOrigins, MediaEngineSupportsKeySystem);
MediaEngineGetSitesInMediaCache, MediaEngineClearMediaCache, MediaEngineClearMediaCacheForSite, MediaEngineSupportsKeySystem);
typedef void (*MediaEngineRegister)(MediaEngineRegistrar);

class MediaPlayerFactorySupport {
Expand Down
6 changes: 3 additions & 3 deletions Source/WebCore/platform/graphics/MediaPlayerPrivate.h
Expand Up @@ -214,9 +214,9 @@ class MediaPlayerPrivateInterface {
virtual unsigned audioDecodedByteCount() const { return 0; }
virtual unsigned videoDecodedByteCount() const { return 0; }

HashSet<RefPtr<SecurityOrigin>> originsInMediaCache(const String&) { return { }; }
void clearMediaCache(const String&, std::chrono::system_clock::time_point) { }
void clearMediaCacheForOrigins(const String&, const HashSet<RefPtr<SecurityOrigin>>&) { }
void getSitesInMediaCache(Vector<String>&) { }
void clearMediaCache() { }
void clearMediaCacheForSite(const String&) { }

virtual void setPrivateBrowsingMode(bool) { }

Expand Down
Expand Up @@ -87,10 +87,6 @@ class MediaPlayerPrivateAVFoundationObjC : public MediaPlayerPrivateAVFoundation

static void registerMediaEngine(MediaEngineRegistrar);

static HashSet<RefPtr<SecurityOrigin>> originsInMediaCache(const String&);
static void clearMediaCache(const String&, std::chrono::system_clock::time_point modifiedSince);
static void clearMediaCacheForOrigins(const String&, const HashSet<RefPtr<SecurityOrigin>>&);

void setAsset(RetainPtr<id>);
void tracksChanged() override;

Expand Down
Expand Up @@ -158,7 +158,6 @@ @interface AVURLAsset (WebKitExtensions)
SOFT_LINK_CLASS(AVFoundation, AVURLAsset)
SOFT_LINK_CLASS(AVFoundation, AVAssetImageGenerator)
SOFT_LINK_CLASS(AVFoundation, AVMetadataItem)
SOFT_LINK_CLASS(AVFoundation, AVAssetCache)

SOFT_LINK_CLASS(CoreImage, CIContext)
SOFT_LINK_CLASS(CoreImage, CIImage)
Expand Down Expand Up @@ -228,7 +227,6 @@ @interface AVURLAsset (WebKitExtensions)
#endif

#if ENABLE(AVF_CAPTIONS)
SOFT_LINK_POINTER(AVFoundation, AVURLAssetCacheKey, NSString*)
SOFT_LINK_POINTER(AVFoundation, AVURLAssetHTTPCookiesKey, NSString*)
SOFT_LINK_POINTER(AVFoundation, AVURLAssetOutOfBandAlternateTracksKey, NSString*)
SOFT_LINK_POINTER(AVFoundation, AVURLAssetUsesNoPersistentCacheKey, NSString*)
Expand All @@ -244,7 +242,6 @@ @interface AVURLAsset (WebKitExtensions)

#define AVURLAssetHTTPCookiesKey getAVURLAssetHTTPCookiesKey()
#define AVURLAssetOutOfBandAlternateTracksKey getAVURLAssetOutOfBandAlternateTracksKey()
#define AVURLAssetCacheKey getAVURLAssetCacheKey()
#define AVURLAssetUsesNoPersistentCacheKey getAVURLAssetUsesNoPersistentCacheKey()
#define AVOutOfBandAlternateTrackDisplayNameKey getAVOutOfBandAlternateTrackDisplayNameKey()
#define AVOutOfBandAlternateTrackExtendedLanguageTagKey getAVOutOfBandAlternateTrackExtendedLanguageTagKey()
Expand Down Expand Up @@ -425,95 +422,7 @@ void receivedChallengeRejection(const AuthenticationChallenge&) override
{
if (isAvailable())
registrar([](MediaPlayer* player) { return std::make_unique<MediaPlayerPrivateAVFoundationObjC>(player); },
getSupportedTypes, supportsType, originsInMediaCache, clearMediaCache, clearMediaCacheForOrigins, supportsKeySystem);
}

static AVAssetCache *assetCacheForPath(const String& path)
{
NSURL *assetCacheURL;

if (path.isEmpty())
assetCacheURL = [[NSURL fileURLWithPath:NSTemporaryDirectory()] URLByAppendingPathComponent:@"MediaCache" isDirectory:YES];
else
assetCacheURL = [NSURL fileURLWithPath:path isDirectory:YES];

return [getAVAssetCacheClass() assetCacheWithURL:assetCacheURL];
}

HashSet<RefPtr<SecurityOrigin>> MediaPlayerPrivateAVFoundationObjC::originsInMediaCache(const String& path)
{
HashSet<RefPtr<SecurityOrigin>> origins;
for (NSString *key in [assetCacheForPath(path) allKeys]) {
URL keyAsURL = URL(URL(), key);
if (keyAsURL.isValid())
origins.add(SecurityOrigin::create(keyAsURL));
}
return origins;
}

static std::chrono::system_clock::time_point toSystemClockTime(NSDate *date)
{
ASSERT(date);
using namespace std::chrono;

return system_clock::time_point(duration_cast<system_clock::duration>(duration<double>(date.timeIntervalSince1970)));
}

void MediaPlayerPrivateAVFoundationObjC::clearMediaCache(const String& path, std::chrono::system_clock::time_point modifiedSince)
{
LOG(Media, "MediaPlayerPrivateAVFoundationObjC::clearMediaCache()");

AVAssetCache* assetCache = assetCacheForPath(path);

for (NSString *key in [assetCache allKeys]) {
if (toSystemClockTime([assetCache lastModifiedDateOfEntryForKey:key]) > modifiedSince)
[assetCache removeEntryForKey:key];
}

NSFileManager *fileManager = [NSFileManager defaultManager];
NSURL *baseURL = [assetCache URL];

if (modifiedSince <= std::chrono::system_clock::time_point { }) {
[fileManager removeItemAtURL:baseURL error:nil];
return;
}

NSArray *propertyKeys = @[NSURLNameKey, NSURLContentModificationDateKey, NSURLIsRegularFileKey];
NSDirectoryEnumerator *enumerator = [fileManager enumeratorAtURL:baseURL includingPropertiesForKeys:
propertyKeys options:NSDirectoryEnumerationSkipsSubdirectoryDescendants
errorHandler:nil];

RetainPtr<NSMutableArray<NSURL *>> urlsToDelete = adoptNS([[NSMutableArray alloc] init]);
for (NSURL *fileURL : enumerator) {
NSDictionary<NSString *, id> *fileAttributes = [fileURL resourceValuesForKeys:propertyKeys error:nil];

if (![fileAttributes[NSURLNameKey] hasPrefix:@"CachedMedia-"])
continue;

if (![fileAttributes[NSURLIsRegularFileKey] boolValue])
continue;

if (toSystemClockTime(fileAttributes[NSURLContentModificationDateKey]) <= modifiedSince)
continue;

[urlsToDelete addObject:fileURL];
}

for (NSURL *fileURL in urlsToDelete.get())
[fileManager removeItemAtURL:fileURL error:nil];
}

void MediaPlayerPrivateAVFoundationObjC::clearMediaCacheForOrigins(const String& path, const HashSet<RefPtr<SecurityOrigin>>& origins)
{
LOG(Media, "MediaPlayerPrivateAVFoundationObjC::clearMediaCacheForOrigins()");
AVAssetCache* assetCache = assetCacheForPath(path);
for (NSString *key in [assetCache allKeys]) {
URL keyAsURL = URL(URL(), key);
if (keyAsURL.isValid()) {
if (origins.contains(SecurityOrigin::create(keyAsURL)))
[assetCache removeEntryForKey:key];
}
}
getSupportedTypes, supportsType, 0, 0, 0, supportsKeySystem);
}

MediaPlayerPrivateAVFoundationObjC::MediaPlayerPrivateAVFoundationObjC(MediaPlayer* player)
Expand Down Expand Up @@ -965,11 +874,7 @@ void receivedChallengeRejection(const AuthenticationChallenge&) override
}
#endif

bool usePersistentCache = player()->client().mediaPlayerShouldUsePersistentCache();
[options setObject:@(!usePersistentCache) forKey:AVURLAssetUsesNoPersistentCacheKey];

if (usePersistentCache)
[options setObject:assetCacheForPath(player()->client().mediaPlayerMediaCacheDirectory()) forKey:AVURLAssetCacheKey];
[options setObject:[NSNumber numberWithBool:!player()->client().mediaPlayerShouldUsePersistentCache()] forKey:AVURLAssetUsesNoPersistentCacheKey];

NSURL *cocoaURL = canonicalURL(url);
m_avAsset = adoptNS([allocAVURLAssetInstance() initWithURL:cocoaURL options:options.get()]);
Expand Down
Expand Up @@ -68,9 +68,9 @@ class MediaPlayerPrivateQTKit : public MediaPlayerPrivateInterface {
static void getSupportedTypes(HashSet<String, ASCIICaseInsensitiveHash>& types);
static MediaPlayer::SupportsType supportsType(const MediaEngineSupportParameters&);

static HashSet<RefPtr<SecurityOrigin>> originsInMediaCache(const String&);
static void clearMediaCache(const String&, std::chrono::system_clock::time_point modifiedSince);
static void clearMediaCacheForOrigins(const String&, const HashSet<RefPtr<SecurityOrigin>>&);
static void getSitesInMediaCache(Vector<String>&);
static void clearMediaCache();
static void clearMediaCacheForSite(const String&);
static bool isAvailable();

PlatformMedia platformMedia() const override;
Expand Down

0 comments on commit b74c574

Please sign in to comment.