Title: [258795] trunk/Source
- Revision
- 258795
- Author
- [email protected]
- Date
- 2020-03-20 15:36:45 -0700 (Fri, 20 Mar 2020)
Log Message
Ensure media cache directory is created before passing to AVURLAsset.
https://bugs.webkit.org/show_bug.cgi?id=209341
Reviewed by Eric Carlson.
Source/WebCore:
Sandbox changes require the media cache directory to be created before passing to
AVFoundation, to ensure that a sandbox extension is allowed to be created for that
directory.
When the mediaCacheDirectory is empty or null, no longer specify a temporary directory. This
allows clients to disable caching by specifying an empty string for the cache directory.
Since now assetCacheForPath() can return nil, update all the call sites to handle that
possibility. Add a new method, ensureAssetCacheExistsAtPath() which tries to create a
directory at the specified path, and returns nil if that is not possible. This ensures the
cache path exists before adding the AVAssetCache to the AVURLAsset options dictionary.
* platform/graphics/avfoundation/objc/MediaPlayerPrivateAVFoundationObjC.mm:
(WebCore::assetCacheForPath):
(WebCore::ensureAssetCacheExistsForPath):
(WebCore::MediaPlayerPrivateAVFoundationObjC::originsInMediaCache):
(WebCore::MediaPlayerPrivateAVFoundationObjC::clearMediaCache):
(WebCore::MediaPlayerPrivateAVFoundationObjC::clearMediaCacheForOrigins):
(WebCore::MediaPlayerPrivateAVFoundationObjC::createAVAssetForURL):
Source/WebKitLegacy/mac:
MediaPlayerPrivateAVFoundaionObjC will no longer create an asset cache in a temporary
directory by default; ensure that it's media cache directory is set during initialization.
* WebView/WebView.mm:
(-[WebView _commonInitializationWithFrameName:groupName:]):
Modified Paths
Diff
Modified: trunk/Source/WebCore/ChangeLog (258794 => 258795)
--- trunk/Source/WebCore/ChangeLog 2020-03-20 22:31:03 UTC (rev 258794)
+++ trunk/Source/WebCore/ChangeLog 2020-03-20 22:36:45 UTC (rev 258795)
@@ -1,3 +1,29 @@
+2020-03-20 Jer Noble <[email protected]>
+
+ Ensure media cache directory is created before passing to AVURLAsset.
+ https://bugs.webkit.org/show_bug.cgi?id=209341
+
+ Reviewed by Eric Carlson.
+
+ Sandbox changes require the media cache directory to be created before passing to
+ AVFoundation, to ensure that a sandbox extension is allowed to be created for that
+ directory.
+
+ When the mediaCacheDirectory is empty or null, no longer specify a temporary directory. This
+ allows clients to disable caching by specifying an empty string for the cache directory.
+ Since now assetCacheForPath() can return nil, update all the call sites to handle that
+ possibility. Add a new method, ensureAssetCacheExistsAtPath() which tries to create a
+ directory at the specified path, and returns nil if that is not possible. This ensures the
+ cache path exists before adding the AVAssetCache to the AVURLAsset options dictionary.
+
+ * platform/graphics/avfoundation/objc/MediaPlayerPrivateAVFoundationObjC.mm:
+ (WebCore::assetCacheForPath):
+ (WebCore::ensureAssetCacheExistsForPath):
+ (WebCore::MediaPlayerPrivateAVFoundationObjC::originsInMediaCache):
+ (WebCore::MediaPlayerPrivateAVFoundationObjC::clearMediaCache):
+ (WebCore::MediaPlayerPrivateAVFoundationObjC::clearMediaCacheForOrigins):
+ (WebCore::MediaPlayerPrivateAVFoundationObjC::createAVAssetForURL):
+
2020-03-20 David Kilzer <[email protected]>
Fix name of "X-Content-Type:" HTTP header in console logging
Modified: trunk/Source/WebCore/platform/graphics/avfoundation/objc/MediaPlayerPrivateAVFoundationObjC.mm (258794 => 258795)
--- trunk/Source/WebCore/platform/graphics/avfoundation/objc/MediaPlayerPrivateAVFoundationObjC.mm 2020-03-20 22:31:03 UTC (rev 258794)
+++ trunk/Source/WebCore/platform/graphics/avfoundation/objc/MediaPlayerPrivateAVFoundationObjC.mm 2020-03-20 22:36:45 UTC (rev 258795)
@@ -79,6 +79,7 @@
#import <pal/spi/cocoa/AVFoundationSPI.h>
#import <pal/spi/cocoa/QuartzCoreSPI.h>
#import <wtf/BlockObjCExceptions.h>
+#import <wtf/FileSystem.h>
#import <wtf/ListHashSet.h>
#import <wtf/NeverDestroyed.h>
#import <wtf/OSObjectPtr.h>
@@ -323,20 +324,42 @@
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 nil;
- return [PAL::getAVAssetCacheClass() assetCacheWithURL:assetCacheURL];
+ return [PAL::getAVAssetCacheClass() assetCacheWithURL:[NSURL fileURLWithPath:path isDirectory:YES]];
}
+static AVAssetCache *ensureAssetCacheExistsForPath(const String& path)
+{
+ if (path.isEmpty())
+ return nil;
+
+ auto fileExistsAtPath = FileSystem::fileExists(path);
+
+ if (fileExistsAtPath && !FileSystem::fileIsDirectory(path, FileSystem::ShouldFollowSymbolicLinks::Yes)) {
+ // Non-directory file already exists at the path location; bail.
+ ASSERT_NOT_REACHED();
+ return nil;
+ }
+
+ if (!fileExistsAtPath && !FileSystem::makeAllDirectories(path)) {
+ // Could not create a directory at the specified location; bail.
+ ASSERT_NOT_REACHED();
+ return nil;
+ }
+
+ return assetCacheForPath(path);
+}
+
HashSet<RefPtr<SecurityOrigin>> MediaPlayerPrivateAVFoundationObjC::originsInMediaCache(const String& path)
{
HashSet<RefPtr<SecurityOrigin>> origins;
- for (NSString *key in [assetCacheForPath(path) allKeys]) {
+ AVAssetCache* assetCache = assetCacheForPath(path);
+ if (!assetCache)
+ return origins;
+
+ for (NSString *key in [assetCache allKeys]) {
URL keyAsURL = URL(URL(), key);
if (keyAsURL.isValid())
origins.add(SecurityOrigin::create(keyAsURL));
@@ -353,6 +376,8 @@
void MediaPlayerPrivateAVFoundationObjC::clearMediaCache(const String& path, WallTime modifiedSince)
{
AVAssetCache* assetCache = assetCacheForPath(path);
+ if (!assetCache)
+ return;
for (NSString *key in [assetCache allKeys]) {
if (toSystemClockTime([assetCache lastModifiedDateOfEntryForKey:key]) > modifiedSince)
@@ -395,6 +420,9 @@
void MediaPlayerPrivateAVFoundationObjC::clearMediaCacheForOrigins(const String& path, const HashSet<RefPtr<SecurityOrigin>>& origins)
{
AVAssetCache* assetCache = assetCacheForPath(path);
+ if (!assetCache)
+ return;
+
for (NSString *key in [assetCache allKeys]) {
URL keyAsURL = URL(URL(), key);
if (keyAsURL.isValid()) {
@@ -840,8 +868,12 @@
bool usePersistentCache = player()->shouldUsePersistentCache();
[options setObject:@(!usePersistentCache) forKey:AVURLAssetUsesNoPersistentCacheKey];
- if (usePersistentCache)
- [options setObject:assetCacheForPath(player()->mediaCacheDirectory()) forKey:AVURLAssetCacheKey];
+ if (usePersistentCache) {
+ if (auto* assetCache = ensureAssetCacheExistsForPath(player()->mediaCacheDirectory()))
+ [options setObject:assetCache forKey:AVURLAssetCacheKey];
+ else
+ [options setObject:@NO forKey:AVURLAssetUsesNoPersistentCacheKey];
+ }
NSURL *cocoaURL = canonicalURL(url);
m_avAsset = adoptNS([PAL::allocAVURLAssetInstance() initWithURL:cocoaURL options:options.get()]);
Modified: trunk/Source/WebKitLegacy/mac/ChangeLog (258794 => 258795)
--- trunk/Source/WebKitLegacy/mac/ChangeLog 2020-03-20 22:31:03 UTC (rev 258794)
+++ trunk/Source/WebKitLegacy/mac/ChangeLog 2020-03-20 22:36:45 UTC (rev 258795)
@@ -1,3 +1,16 @@
+2020-03-20 Jer Noble <[email protected]>
+
+ Ensure media cache directory is created before passing to AVURLAsset.
+ https://bugs.webkit.org/show_bug.cgi?id=209341
+
+ Reviewed by Eric Carlson.
+
+ MediaPlayerPrivateAVFoundaionObjC will no longer create an asset cache in a temporary
+ directory by default; ensure that it's media cache directory is set during initialization.
+
+ * WebView/WebView.mm:
+ (-[WebView _commonInitializationWithFrameName:groupName:]):
+
2020-03-20 Timothy Horton <[email protected]>
Improve the previous build fix.
Modified: trunk/Source/WebKitLegacy/mac/WebView/WebView.mm (258794 => 258795)
--- trunk/Source/WebKitLegacy/mac/WebView/WebView.mm 2020-03-20 22:31:03 UTC (rev 258794)
+++ trunk/Source/WebKitLegacy/mac/WebView/WebView.mm 2020-03-20 22:36:45 UTC (rev 258795)
@@ -1427,6 +1427,10 @@
if (WebCore::IOSApplication::isMobileSafari())
WebCore::DeprecatedGlobalSettings::setShouldManageAudioSessionCategory(true);
#endif
+
+#if ENABLE(VIDEO)
+ WebCore::HTMLMediaElement::setMediaCacheDirectory(FileSystem::pathByAppendingComponent(NSTemporaryDirectory(), "MediaCache/"_s));
+#endif
didOneTimeInitialization = true;
}
_______________________________________________
webkit-changes mailing list
[email protected]
https://lists.webkit.org/mailman/listinfo/webkit-changes