|
1 | 1 | import {BrowserWindow, Menu, app, dialog, ipcMain, systemPreferences} from 'electron';
|
2 | 2 | import fs from 'fs';
|
3 | 3 | import path from 'path';
|
4 |
| -import {format as formatUrl} from 'url'; |
| 4 | +import {URL} from 'url'; |
5 | 5 |
|
6 | 6 | import {getFilterForExtension} from './FileFilters';
|
7 | 7 | import telemetry from './ScratchDesktopTelemetry';
|
@@ -58,22 +58,17 @@ const displayPermissionDeniedWarning = (browserWindow, permissionType) => {
|
58 | 58 | * @param {*} search - the optional "search" parameters (the part of the URL after '?'), like "route=about"
|
59 | 59 | * @returns {string} - an absolute URL as a string
|
60 | 60 | */
|
61 |
| -const makeFullUrl = (url, search = null) => |
62 |
| - encodeURI(formatUrl(isDevelopment ? |
63 |
| - { // Webpack Dev Server |
64 |
| - hostname: 'localhost', |
65 |
| - pathname: url, |
66 |
| - port: process.env.ELECTRON_WEBPACK_WDS_PORT, |
67 |
| - protocol: 'http', |
68 |
| - search, |
69 |
| - slashes: true |
70 |
| - } : { // production / bundled |
71 |
| - pathname: path.join(__dirname, url), |
72 |
| - protocol: 'file', |
73 |
| - search, |
74 |
| - slashes: true |
75 |
| - } |
76 |
| - )); |
| 61 | +const makeFullUrl = (url, search = null) => { |
| 62 | + const baseUrl = (isDevelopment ? |
| 63 | + `http://localhost:${process.env.ELECTRON_WEBPACK_WDS_PORT}/` : |
| 64 | + `file://${__dirname}/` |
| 65 | + ); |
| 66 | + const fullUrl = new URL(url, baseUrl); |
| 67 | + if (search) { |
| 68 | + fullUrl.search = search; // automatically percent-encodes anything that needs it |
| 69 | + } |
| 70 | + return fullUrl.toString(); |
| 71 | +}; |
77 | 72 |
|
78 | 73 | /**
|
79 | 74 | * Prompt in a platform-specific way for permission to access the microphone or camera, if Electron supports doing so.
|
@@ -105,7 +100,7 @@ const handlePermissionRequest = async (webContents, permission, callback, detail
|
105 | 100 | // deny: request is for some other kind of access like notifications or pointerLock
|
106 | 101 | return callback(false);
|
107 | 102 | }
|
108 |
| - const requiredBase = makeFullUrl('/'); |
| 103 | + const requiredBase = makeFullUrl(''); |
109 | 104 | if (details.requestingUrl.indexOf(requiredBase) !== 0) {
|
110 | 105 | // deny: request came from a URL outside of our "sandbox"
|
111 | 106 | return callback(false);
|
|
0 commit comments