Changeset 258795 in webkit


Ignore:
Timestamp:
Mar 20, 2020 3:36:45 PM (4 years ago)
Author:
jer.noble@apple.com
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:]):

Location:
trunk/Source
Files:
4 edited

Legend:

Unmodified
Added
Removed
  • trunk/Source/WebCore/ChangeLog

    r258789 r258795  
     12020-03-20  Jer Noble  <jer.noble@apple.com>
     2
     3        Ensure media cache directory is created before passing to AVURLAsset.
     4        https://bugs.webkit.org/show_bug.cgi?id=209341
     5
     6        Reviewed by Eric Carlson.
     7
     8        Sandbox changes require the media cache directory to be created before passing to
     9        AVFoundation, to ensure that a sandbox extension is allowed to be created for that
     10        directory.
     11
     12        When the mediaCacheDirectory is empty or null, no longer specify a temporary directory. This
     13        allows clients to disable caching by specifying an empty string for the cache directory.
     14        Since now assetCacheForPath() can return nil, update all the call sites to handle that
     15        possibility. Add a new method, ensureAssetCacheExistsAtPath() which tries to create a
     16        directory at the specified path, and returns nil if that is not possible. This ensures the
     17        cache path exists before adding the AVAssetCache to the AVURLAsset options dictionary.
     18
     19        * platform/graphics/avfoundation/objc/MediaPlayerPrivateAVFoundationObjC.mm:
     20        (WebCore::assetCacheForPath):
     21        (WebCore::ensureAssetCacheExistsForPath):
     22        (WebCore::MediaPlayerPrivateAVFoundationObjC::originsInMediaCache):
     23        (WebCore::MediaPlayerPrivateAVFoundationObjC::clearMediaCache):
     24        (WebCore::MediaPlayerPrivateAVFoundationObjC::clearMediaCacheForOrigins):
     25        (WebCore::MediaPlayerPrivateAVFoundationObjC::createAVAssetForURL):
     26
    1272020-03-20  David Kilzer  <ddkilzer@apple.com>
    228
  • trunk/Source/WebCore/platform/graphics/avfoundation/objc/MediaPlayerPrivateAVFoundationObjC.mm

    r258082 r258795  
    8080#import <pal/spi/cocoa/QuartzCoreSPI.h>
    8181#import <wtf/BlockObjCExceptions.h>
     82#import <wtf/FileSystem.h>
    8283#import <wtf/ListHashSet.h>
    8384#import <wtf/NeverDestroyed.h>
     
    324325static AVAssetCache *assetCacheForPath(const String& path)
    325326{
    326     NSURL *assetCacheURL;
    327    
    328327    if (path.isEmpty())
    329         assetCacheURL = [[NSURL fileURLWithPath:NSTemporaryDirectory()] URLByAppendingPathComponent:@"MediaCache" isDirectory:YES];
    330     else
    331         assetCacheURL = [NSURL fileURLWithPath:path isDirectory:YES];
    332 
    333     return [PAL::getAVAssetCacheClass() assetCacheWithURL:assetCacheURL];
     328        return nil;
     329
     330    return [PAL::getAVAssetCacheClass() assetCacheWithURL:[NSURL fileURLWithPath:path isDirectory:YES]];
     331}
     332
     333static AVAssetCache *ensureAssetCacheExistsForPath(const String& path)
     334{
     335    if (path.isEmpty())
     336        return nil;
     337
     338    auto fileExistsAtPath = FileSystem::fileExists(path);
     339
     340    if (fileExistsAtPath && !FileSystem::fileIsDirectory(path, FileSystem::ShouldFollowSymbolicLinks::Yes)) {
     341        // Non-directory file already exists at the path location; bail.
     342        ASSERT_NOT_REACHED();
     343        return nil;
     344    }
     345
     346    if (!fileExistsAtPath && !FileSystem::makeAllDirectories(path)) {
     347        // Could not create a directory at the specified location; bail.
     348        ASSERT_NOT_REACHED();
     349        return nil;
     350    }
     351
     352    return assetCacheForPath(path);
    334353}
    335354
     
    337356{
    338357    HashSet<RefPtr<SecurityOrigin>> origins;
    339     for (NSString *key in [assetCacheForPath(path) allKeys]) {
     358    AVAssetCache* assetCache = assetCacheForPath(path);
     359    if (!assetCache)
     360        return origins;
     361
     362    for (NSString *key in [assetCache allKeys]) {
    340363        URL keyAsURL = URL(URL(), key);
    341364        if (keyAsURL.isValid())
     
    354377{
    355378    AVAssetCache* assetCache = assetCacheForPath(path);
     379    if (!assetCache)
     380        return;
    356381   
    357382    for (NSString *key in [assetCache allKeys]) {
     
    396421{
    397422    AVAssetCache* assetCache = assetCacheForPath(path);
     423    if (!assetCache)
     424        return;
     425
    398426    for (NSString *key in [assetCache allKeys]) {
    399427        URL keyAsURL = URL(URL(), key);
     
    841869    [options setObject:@(!usePersistentCache) forKey:AVURLAssetUsesNoPersistentCacheKey];
    842870   
    843     if (usePersistentCache)
    844         [options setObject:assetCacheForPath(player()->mediaCacheDirectory()) forKey:AVURLAssetCacheKey];
     871    if (usePersistentCache) {
     872        if (auto* assetCache = ensureAssetCacheExistsForPath(player()->mediaCacheDirectory()))
     873            [options setObject:assetCache forKey:AVURLAssetCacheKey];
     874        else
     875            [options setObject:@NO forKey:AVURLAssetUsesNoPersistentCacheKey];
     876    }
    845877
    846878    NSURL *cocoaURL = canonicalURL(url);
  • trunk/Source/WebKitLegacy/mac/ChangeLog

    r258782 r258795  
     12020-03-20  Jer Noble  <jer.noble@apple.com>
     2
     3        Ensure media cache directory is created before passing to AVURLAsset.
     4        https://bugs.webkit.org/show_bug.cgi?id=209341
     5
     6        Reviewed by Eric Carlson.
     7
     8        MediaPlayerPrivateAVFoundaionObjC will no longer create an asset cache in a temporary
     9        directory by default; ensure that it's media cache directory is set during initialization.
     10
     11        * WebView/WebView.mm:
     12        (-[WebView _commonInitializationWithFrameName:groupName:]):
     13
    1142020-03-20  Timothy Horton  <timothy_horton@apple.com>
    215
  • trunk/Source/WebKitLegacy/mac/WebView/WebView.mm

    r258628 r258795  
    14281428            WebCore::DeprecatedGlobalSettings::setShouldManageAudioSessionCategory(true);
    14291429#endif
     1430
     1431#if ENABLE(VIDEO)
     1432        WebCore::HTMLMediaElement::setMediaCacheDirectory(FileSystem::pathByAppendingComponent(NSTemporaryDirectory(), "MediaCache/"_s));
     1433#endif
    14301434        didOneTimeInitialization = true;
    14311435    }
Note: See TracChangeset for help on using the changeset viewer.