-
-
Notifications
You must be signed in to change notification settings - Fork 742
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Fix Raster DEM decoding in safari private browsing mode (#3185)
* working * tests * rm force * rm debug * convert promise to callback and some tricks to reduce bundle size * fix test * back to async/await * mangle test * indent * fix mangle test * update changelog * changelog tweak * respond to comments * fixes * changelog * comments * comment * fix test * handle html image decoding in main thread * tweak * bump size * comments * refactor getImage call
- Loading branch information
Showing
8 changed files
with
404 additions
and
36 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
import {isOffscreenCanvasDistorted} from './offscreen_canvas_distorted'; | ||
import {Canvas} from 'canvas'; | ||
import {offscreenCanvasSupported} from './offscreen_canvas_supported'; | ||
|
||
test('normal operation does not mangle canvas', () => { | ||
const OffscreenCanvas = (window as any).OffscreenCanvas = jest.fn((width:number, height: number) => { | ||
return new Canvas(width, height); | ||
}); | ||
expect(offscreenCanvasSupported()).toBeTruthy(); | ||
OffscreenCanvas.mockClear(); | ||
expect(isOffscreenCanvasDistorted()).toBeFalsy(); | ||
expect(OffscreenCanvas).toHaveBeenCalledTimes(1); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,39 @@ | ||
import {offscreenCanvasSupported} from './offscreen_canvas_supported'; | ||
|
||
let offscreenCanvasDistorted: boolean; | ||
|
||
/** | ||
* Some browsers don't return the exact pixels from a canvas to prevent user fingerprinting (see #3185). | ||
* This function writes pixels to an OffscreenCanvas and reads them back using getImageData, returning false | ||
* if they don't match. | ||
* | ||
* @returns true if the browser supports OffscreenCanvas but it distorts getImageData results, false otherwise. | ||
*/ | ||
export function isOffscreenCanvasDistorted(): boolean { | ||
if (offscreenCanvasDistorted == null) { | ||
offscreenCanvasDistorted = false; | ||
if (offscreenCanvasSupported()) { | ||
const size = 5; | ||
const canvas = new OffscreenCanvas(size, size); | ||
const context = canvas.getContext('2d', {willReadFrequently: true}); | ||
if (context) { | ||
// fill each pixel with an RGB value that should make the byte at index i equal to i (except alpha channel): | ||
// [0, 1, 2, 255, 4, 5, 6, 255, 8, 9, 10, 255, ...] | ||
for (let i = 0; i < size * size; i++) { | ||
const base = i * 4; | ||
context.fillStyle = `rgb(${base},${base + 1},${base + 2})`; | ||
context.fillRect(i % size, Math.floor(i / size), 1, 1); | ||
} | ||
const data = context.getImageData(0, 0, size, size).data; | ||
for (let i = 0; i < size * size * 4; i++) { | ||
if (i % 4 !== 3 && data[i] !== i) { | ||
offscreenCanvasDistorted = true; | ||
break; | ||
} | ||
} | ||
} | ||
} | ||
} | ||
|
||
return offscreenCanvasDistorted || false; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.