Skip to content

Commit 266a907

Browse files
authored
Merge pull request mailru#378 from number213/master
Fallback to flash camera capture in case of insecure origin in Chromium
2 parents 3f1e6ac + 779a687 commit 266a907

File tree

8 files changed

+89
-17
lines changed

8 files changed

+89
-17
lines changed

dist/FileAPI.html5.js

Lines changed: 38 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
/*! FileAPI 2.0.19 - BSD | git://github.com/mailru/FileAPI.git
1+
/*! FileAPI 2.0.20 - BSD | git://github.com/mailru/FileAPI.git
22
* FileAPI — a set of javascript tools for working with files. Multiupload, drag'n'drop and chunked file upload. Images: crop, resize and auto orientation by EXIF.
33
*/
44

@@ -107,6 +107,7 @@
107107
userAgent = window.navigator.userAgent,
108108
safari = /safari\//i.test(userAgent) && !/chrome\//i.test(userAgent),
109109
iemobile = /iemobile\//i.test(userAgent),
110+
insecureChrome = !safari && /chrome\//i.test(userAgent) && window.location.protocol === 'http:',
110111

111112
// https://github.com/blueimp/JavaScript-Load-Image/blob/master/load-image.js#L48
112113
apiURL = (window.createObjectURL && window) || (window.URL && URL.revokeObjectURL && URL) || (window.webkitURL && webkitURL),
@@ -286,13 +287,14 @@
286287
* FileAPI (core object)
287288
*/
288289
api = {
289-
version: '2.0.19',
290+
version: '2.0.20',
290291

291292
cors: false,
292293
html5: true,
293294
media: false,
294295
formData: true,
295296
multiPassResize: true,
297+
insecureChrome: insecureChrome,
296298

297299
debug: false,
298300
pingUrl: false,
@@ -3373,7 +3375,7 @@
33733375
el.style.height= _px(options.height);
33743376

33753377

3376-
if( api.html5 && html5 ){
3378+
if( api.html5 && html5 && !api.insecureChrome ){
33773379
// Create video element
33783380
var video = document.createElement('video');
33793381

@@ -3404,6 +3406,38 @@
34043406
callback('not_support_camera');
34053407
};
34063408

3409+
Camera.checkAlreadyCaptured = (function () {
3410+
varmediaDevices = navigator.mediaDevices,
3411+
MediaStreamTrack = window.MediaStreamTrack,
3412+
navigatorEnumerateDevices = navigator.enumerateDevices,
3413+
enumerateDevices;
3414+
3415+
if (mediaDevices && mediaDevices.enumerateDevices) {
3416+
enumerateDevices = function (callback) {
3417+
mediaDevices.enumerateDevices().then(callback);
3418+
};
3419+
} else if (MediaStreamTrack && MediaStreamTrack.getSources) {
3420+
enumerateDevices = MediaStreamTrack.getSources.bind(MediaStreamTrack);
3421+
} else if (navigatorEnumerateDevices) {
3422+
enumerateDevices = navigatorEnumerateDevices.bind(navigator);
3423+
} else {
3424+
enumerateDevices = function (fn) {
3425+
fn([]);
3426+
};
3427+
}
3428+
3429+
return function (callback) {
3430+
enumerateDevices(function (devices) {
3431+
var deviceExists = devices.some(function (device) {
3432+
return (device.kind === 'videoinput' || device.kind === 'video') && device.label;
3433+
});
3434+
3435+
callback(deviceExists);
3436+
});
3437+
};
3438+
3439+
})();
3440+
34073441

34083442
/**
34093443
* @classFileAPI.Camera.Shot
@@ -3468,7 +3502,7 @@
34683502
var _each = api.each,
34693503
_cameraQueue = [];
34703504

3471-
if (api.support.flash && (api.media && (!api.support.media || !api.html5))) {
3505+
if (api.support.flash && (api.media && (!api.support.media || !api.html5 || api.insecureChrome))) {
34723506
(function () {
34733507
function _wrap(fn) {
34743508
var id = fn.wid = api.uid();

dist/FileAPI.html5.min.js

Lines changed: 3 additions & 3 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

dist/FileAPI.js

Lines changed: 39 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
/*! FileAPI 2.0.19 - BSD | git://github.com/mailru/FileAPI.git
1+
/*! FileAPI 2.0.20 - BSD | git://github.com/mailru/FileAPI.git
22
* FileAPI — a set of javascript tools for working with files. Multiupload, drag'n'drop and chunked file upload. Images: crop, resize and auto orientation by EXIF.
33
*/
44

@@ -107,6 +107,7 @@
107107
userAgent = window.navigator.userAgent,
108108
safari = /safari\//i.test(userAgent) && !/chrome\//i.test(userAgent),
109109
iemobile = /iemobile\//i.test(userAgent),
110+
insecureChrome = !safari && /chrome\//i.test(userAgent) && window.location.protocol === 'http:',
110111

111112
// https://github.com/blueimp/JavaScript-Load-Image/blob/master/load-image.js#L48
112113
apiURL = (window.createObjectURL && window) || (window.URL && URL.revokeObjectURL && URL) || (window.webkitURL && webkitURL),
@@ -286,13 +287,14 @@
286287
* FileAPI (core object)
287288
*/
288289
api = {
289-
version: '2.0.19',
290+
version: '2.0.20',
290291

291292
cors: false,
292293
html5: true,
293294
media: false,
294295
formData: true,
295296
multiPassResize: true,
297+
insecureChrome: insecureChrome,
296298

297299
debug: false,
298300
pingUrl: false,
@@ -3373,7 +3375,7 @@
33733375
el.style.height= _px(options.height);
33743376

33753377

3376-
if( api.html5 && html5 ){
3378+
if( api.html5 && html5 && !api.insecureChrome ){
33773379
// Create video element
33783380
var video = document.createElement('video');
33793381

@@ -3404,6 +3406,38 @@
34043406
callback('not_support_camera');
34053407
};
34063408

3409+
Camera.checkAlreadyCaptured = (function () {
3410+
varmediaDevices = navigator.mediaDevices,
3411+
MediaStreamTrack = window.MediaStreamTrack,
3412+
navigatorEnumerateDevices = navigator.enumerateDevices,
3413+
enumerateDevices;
3414+
3415+
if (mediaDevices && mediaDevices.enumerateDevices) {
3416+
enumerateDevices = function (callback) {
3417+
mediaDevices.enumerateDevices().then(callback);
3418+
};
3419+
} else if (MediaStreamTrack && MediaStreamTrack.getSources) {
3420+
enumerateDevices = MediaStreamTrack.getSources.bind(MediaStreamTrack);
3421+
} else if (navigatorEnumerateDevices) {
3422+
enumerateDevices = navigatorEnumerateDevices.bind(navigator);
3423+
} else {
3424+
enumerateDevices = function (fn) {
3425+
fn([]);
3426+
};
3427+
}
3428+
3429+
return function (callback) {
3430+
enumerateDevices(function (devices) {
3431+
var deviceExists = devices.some(function (device) {
3432+
return (device.kind === 'videoinput' || device.kind === 'video') && device.label;
3433+
});
3434+
3435+
callback(deviceExists);
3436+
});
3437+
};
3438+
3439+
})();
3440+
34073441

34083442
/**
34093443
* @classFileAPI.Camera.Shot
@@ -3501,6 +3535,7 @@
35013535
|| !api.html5 || !api.support.html5
35023536
|| (api.cors && !api.support.cors)
35033537
|| (api.media && !api.support.media)
3538+
|| api.insecureChrome
35043539
)
35053540
&& (function (){
35063541
var
@@ -4260,7 +4295,7 @@
42604295
var _each = api.each,
42614296
_cameraQueue = [];
42624297

4263-
if (api.support.flash && (api.media && (!api.support.media || !api.html5))) {
4298+
if (api.support.flash && (api.media && (!api.support.media || !api.html5 || api.insecureChrome))) {
42644299
(function () {
42654300
function _wrap(fn) {
42664301
var id = fn.wid = api.uid();

dist/FileAPI.min.js

Lines changed: 3 additions & 3 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

lib/FileAPI.Camera.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -178,7 +178,7 @@
178178
el.style.height= _px(options.height);
179179

180180

181-
if( api.html5 && html5 ){
181+
if( api.html5 && html5 && !api.insecureChrome ){
182182
// Create video element
183183
var video = document.createElement('video');
184184

lib/FileAPI.Flash.Camera.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@
1111
var _each = api.each,
1212
_cameraQueue = [];
1313

14-
if (api.support.flash && (api.media && (!api.support.media || !api.html5))) {
14+
if (api.support.flash && (api.media && (!api.support.media || !api.html5 || api.insecureChrome))) {
1515
(function () {
1616
function _wrap(fn) {
1717
var id = fn.wid = api.uid();

lib/FileAPI.Flash.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,7 @@
4444
|| !api.html5 || !api.support.html5
4545
|| (api.cors && !api.support.cors)
4646
|| (api.media && !api.support.media)
47+
|| api.insecureChrome
4748
)
4849
&& (function (){
4950
var

lib/FileAPI.core.js

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@
1313
userAgent = window.navigator.userAgent,
1414
safari = /safari\//i.test(userAgent) && !/chrome\//i.test(userAgent),
1515
iemobile = /iemobile\//i.test(userAgent),
16+
insecureChrome = !safari && /chrome\//i.test(userAgent) && window.location.protocol === 'http:',
1617

1718
// https://github.com/blueimp/JavaScript-Load-Image/blob/master/load-image.js#L48
1819
apiURL = (window.createObjectURL && window) || (window.URL && URL.revokeObjectURL && URL) || (window.webkitURL && webkitURL),
@@ -192,13 +193,14 @@
192193
* FileAPI (core object)
193194
*/
194195
api = {
195-
version: '2.0.19',
196+
version: '2.0.20',
196197

197198
cors: false,
198199
html5: true,
199200
media: false,
200201
formData: true,
201202
multiPassResize: true,
203+
insecureChrome: insecureChrome,
202204

203205
debug: false,
204206
pingUrl: false,

0 commit comments

Comments
 (0)