Path: blob/trunk/third_party/closure/goog/fs/url.js
4164 views
/**1* @license2* Copyright The Closure Library Authors.3* SPDX-License-Identifier: Apache-2.04*/56/**7* @fileoverview Wrapper for URL and its createObjectUrl and revokeObjectUrl8* methods that are part of the HTML5 File API.9*/1011goog.provide('goog.fs.url');121314/**15* Creates a blob URL for a blob object.16* Throws an error if the browser does not support Object Urls.17*18* @param {!File|!Blob|!MediaSource|!MediaStream} obj The object for which19* to create the URL.20* @return {string} The URL for the object.21*/22goog.fs.url.createObjectUrl = function(obj) {23'use strict';24return goog.fs.url.getUrlObject_().createObjectURL(obj);25};262728/**29* Revokes a URL created by {@link goog.fs.url.createObjectUrl}.30* Throws an error if the browser does not support Object Urls.31*32* @param {string} url The URL to revoke.33* @return {void}34*/35goog.fs.url.revokeObjectUrl = function(url) {36'use strict';37goog.fs.url.getUrlObject_().revokeObjectURL(url);38};394041/**42* @record43* @private44*/45goog.fs.url.UrlObject_ = function() {};4647/**48* @param {!File|!Blob|!MediaSource|!MediaStream} arg49* @return {string}50*/51goog.fs.url.UrlObject_.prototype.createObjectURL = function(arg) {};5253/**54* @param {string} s55* @return {void}56*/57goog.fs.url.UrlObject_.prototype.revokeObjectURL = function(s) {};585960/**61* Get the object that has the createObjectURL and revokeObjectURL functions for62* this browser.63*64* @return {!goog.fs.url.UrlObject_} The object for this browser.65* @private66*/67goog.fs.url.getUrlObject_ = function() {68'use strict';69const urlObject = goog.fs.url.findUrlObject_();70if (urlObject != null) {71return urlObject;72} else {73throw new Error('This browser doesn\'t seem to support blob URLs');74}75};767778/**79* Finds the object that has the createObjectURL and revokeObjectURL functions80* for this browser.81*82* @return {?goog.fs.url.UrlObject_} The object for this browser or null if the83* browser does not support Object Urls.84* @private85*/86goog.fs.url.findUrlObject_ = function() {87'use strict';88// This is what the spec says to do89// http://dev.w3.org/2006/webapi/FileAPI/#dfn-createObjectURL90if (goog.global.URL !== undefined &&91goog.global.URL.createObjectURL !== undefined) {92return /** @type {!goog.fs.url.UrlObject_} */ (goog.global.URL);93// This is what the spec used to say to do94} else if (goog.global.createObjectURL !== undefined) {95return /** @type {!goog.fs.url.UrlObject_} */ (goog.global);96} else {97return null;98}99};100101102/**103* Checks whether this browser supports Object Urls. If not, calls to104* createObjectUrl and revokeObjectUrl will result in an error.105*106* @return {boolean} True if this browser supports Object Urls.107*/108goog.fs.url.browserSupportsObjectUrls = function() {109'use strict';110return goog.fs.url.findUrlObject_() != null;111};112113114