diff --git a/build/types/polyfill b/build/types/polyfill index 312fed509b..1476a2cdd0 100644 --- a/build/types/polyfill +++ b/build/types/polyfill @@ -13,6 +13,7 @@ +../../lib/polyfill/patchedmediakeys_nop.js +../../lib/polyfill/patchedmediakeys_webkit.js +../../lib/polyfill/pip_webkit.js ++../../lib/polyfill/storage_estimate.js +../../lib/polyfill/video_play_promise.js +../../lib/polyfill/videoplaybackquality.js +../../lib/polyfill/vttcue.js diff --git a/lib/polyfill/storage_estimate.js b/lib/polyfill/storage_estimate.js new file mode 100644 index 0000000000..1143ecc69b --- /dev/null +++ b/lib/polyfill/storage_estimate.js @@ -0,0 +1,55 @@ +/*! @license + * Shaka Player + * Copyright 2016 Google LLC + * SPDX-License-Identifier: Apache-2.0 + */ + +goog.provide('shaka.polyfill.StorageEstimate'); + +goog.require('shaka.polyfill'); + + +/** + * @summary A polyfill to provide navigator.storage.estimate in old + * webkit browsers. + * See: https://developers.google.com/web/updates/2017/08/estimating-available-storage-space#the-present + */ +shaka.polyfill.StorageEstimate = class { + /** + * Install the polyfill if needed. + */ + static install() { + if (navigator.storage && navigator.storage.estimate) { + // No need. + return; + } + + if (navigator.webkitTemporaryStorage && + navigator.webkitTemporaryStorage.queryUsageAndQuota) { + if (!('storage' in navigator)) { + navigator.storage = /** @type {!StorageManager} */ ({}); + } + navigator.storage.estimate = + shaka.polyfill.StorageEstimate.storageEstimate_; + } + } + + /** + * @this {StorageManager} + * @return {!Promise} + * @private + */ + static storageEstimate_() { + return new Promise((resolve, reject) => { + navigator.webkitTemporaryStorage.queryUsageAndQuota( + (usage, quota) => { + resolve({usage: usage, quota: quota}); + }, + reject, + ); + }); + } +}; + + +shaka.polyfill.register(shaka.polyfill.StorageEstimate.install);