diff --git a/docs/api/protocol.md b/docs/api/protocol.md index 97e37d3c4ba2..7000b4f2a874 100644 --- a/docs/api/protocol.md +++ b/docs/api/protocol.md @@ -47,9 +47,10 @@ non-standard schemes can not recognize relative URLs: ``` - -So if you want to register a custom protocol to replace the `http` protocol, you -have to register it as standard scheme: +Registering a scheme as standard, will allow access of files through +the FileSystem API. Otherwise the renderer will throw a security error for the +scheme. So in general if you want to register a custom protocol to replace the +`http` protocol, you have to register it as standard scheme: ```javascript const {app, protocol} = require('electron') diff --git a/spec/api-protocol-spec.js b/spec/api-protocol-spec.js index b27663590aa5..5caec616201d 100644 --- a/spec/api-protocol-spec.js +++ b/spec/api-protocol-spec.js @@ -4,7 +4,7 @@ const path = require('path') const qs = require('querystring') const {closeWindow} = require('./window-helpers') const remote = require('electron').remote -const {BrowserWindow, protocol, webContents} = remote +const {BrowserWindow, ipcMain, protocol, webContents} = remote describe('protocol module', function () { var protocolName = 'sp' @@ -965,5 +965,18 @@ describe('protocol module', function () { w.loadURL(origin) }) }) + + it('can access files through FileSystem API', function (done) { + let filePath = path.join(__dirname, 'fixtures', 'pages', 'filesystem.html') + const handler = function (request, callback) { + callback({path: filePath}) + } + protocol.registerFileProtocol(standardScheme, handler, function (error) { + if (error) return done(error) + w.loadURL(origin) + }) + ipcMain.once('file-system-error', (event, err) => done(err)) + ipcMain.once('file-system-write-end', () => done()) + }) }) }) diff --git a/spec/fixtures/pages/filesystem.html b/spec/fixtures/pages/filesystem.html new file mode 100644 index 000000000000..f8555c56340f --- /dev/null +++ b/spec/fixtures/pages/filesystem.html @@ -0,0 +1,24 @@ +