Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
SeleniumHQ
GitHub Repository: SeleniumHQ/Selenium
Path: blob/trunk/third_party/closure/goog/fs/url.js
4164 views
1
/**
2
* @license
3
* Copyright The Closure Library Authors.
4
* SPDX-License-Identifier: Apache-2.0
5
*/
6
7
/**
8
* @fileoverview Wrapper for URL and its createObjectUrl and revokeObjectUrl
9
* methods that are part of the HTML5 File API.
10
*/
11
12
goog.provide('goog.fs.url');
13
14
15
/**
16
* Creates a blob URL for a blob object.
17
* Throws an error if the browser does not support Object Urls.
18
*
19
* @param {!File|!Blob|!MediaSource|!MediaStream} obj The object for which
20
* to create the URL.
21
* @return {string} The URL for the object.
22
*/
23
goog.fs.url.createObjectUrl = function(obj) {
24
'use strict';
25
return goog.fs.url.getUrlObject_().createObjectURL(obj);
26
};
27
28
29
/**
30
* Revokes a URL created by {@link goog.fs.url.createObjectUrl}.
31
* Throws an error if the browser does not support Object Urls.
32
*
33
* @param {string} url The URL to revoke.
34
* @return {void}
35
*/
36
goog.fs.url.revokeObjectUrl = function(url) {
37
'use strict';
38
goog.fs.url.getUrlObject_().revokeObjectURL(url);
39
};
40
41
42
/**
43
* @record
44
* @private
45
*/
46
goog.fs.url.UrlObject_ = function() {};
47
48
/**
49
* @param {!File|!Blob|!MediaSource|!MediaStream} arg
50
* @return {string}
51
*/
52
goog.fs.url.UrlObject_.prototype.createObjectURL = function(arg) {};
53
54
/**
55
* @param {string} s
56
* @return {void}
57
*/
58
goog.fs.url.UrlObject_.prototype.revokeObjectURL = function(s) {};
59
60
61
/**
62
* Get the object that has the createObjectURL and revokeObjectURL functions for
63
* this browser.
64
*
65
* @return {!goog.fs.url.UrlObject_} The object for this browser.
66
* @private
67
*/
68
goog.fs.url.getUrlObject_ = function() {
69
'use strict';
70
const urlObject = goog.fs.url.findUrlObject_();
71
if (urlObject != null) {
72
return urlObject;
73
} else {
74
throw new Error('This browser doesn\'t seem to support blob URLs');
75
}
76
};
77
78
79
/**
80
* Finds the object that has the createObjectURL and revokeObjectURL functions
81
* for this browser.
82
*
83
* @return {?goog.fs.url.UrlObject_} The object for this browser or null if the
84
* browser does not support Object Urls.
85
* @private
86
*/
87
goog.fs.url.findUrlObject_ = function() {
88
'use strict';
89
// This is what the spec says to do
90
// http://dev.w3.org/2006/webapi/FileAPI/#dfn-createObjectURL
91
if (goog.global.URL !== undefined &&
92
goog.global.URL.createObjectURL !== undefined) {
93
return /** @type {!goog.fs.url.UrlObject_} */ (goog.global.URL);
94
// This is what the spec used to say to do
95
} else if (goog.global.createObjectURL !== undefined) {
96
return /** @type {!goog.fs.url.UrlObject_} */ (goog.global);
97
} else {
98
return null;
99
}
100
};
101
102
103
/**
104
* Checks whether this browser supports Object Urls. If not, calls to
105
* createObjectUrl and revokeObjectUrl will result in an error.
106
*
107
* @return {boolean} True if this browser supports Object Urls.
108
*/
109
goog.fs.url.browserSupportsObjectUrls = function() {
110
'use strict';
111
return goog.fs.url.findUrlObject_() != null;
112
};
113
114