Merge pull request #6816 from deepak1556/webframe_scheme_patch
webFrame: enable privileged schemes to send CORS requests
This commit is contained in:
commit
d84098c4c1
2 changed files with 47 additions and 1 deletions
|
@ -146,6 +146,7 @@ void WebFrame::RegisterURLSchemeAsPrivileged(const std::string& scheme) {
|
||||||
privileged_scheme);
|
privileged_scheme);
|
||||||
blink::WebSecurityPolicy::registerURLSchemeAsSupportingFetchAPI(
|
blink::WebSecurityPolicy::registerURLSchemeAsSupportingFetchAPI(
|
||||||
privileged_scheme);
|
privileged_scheme);
|
||||||
|
blink::WebSecurityPolicy::registerURLSchemeAsCORSEnabled(privileged_scheme);
|
||||||
}
|
}
|
||||||
|
|
||||||
void WebFrame::InsertText(const std::string& text) {
|
void WebFrame::InsertText(const std::string& text) {
|
||||||
|
|
|
@ -1,6 +1,8 @@
|
||||||
const assert = require('assert')
|
const assert = require('assert')
|
||||||
const path = require('path')
|
const path = require('path')
|
||||||
const webFrame = require('electron').webFrame
|
const {closeWindow} = require('./window-helpers')
|
||||||
|
const {remote, webFrame} = require('electron')
|
||||||
|
const {BrowserWindow, protocol, ipcMain} = remote
|
||||||
|
|
||||||
describe('webFrame module', function () {
|
describe('webFrame module', function () {
|
||||||
var fixtures = path.resolve(__dirname, 'fixtures')
|
var fixtures = path.resolve(__dirname, 'fixtures')
|
||||||
|
@ -15,5 +17,48 @@ describe('webFrame module', function () {
|
||||||
done('unexpected error : ' + err)
|
done('unexpected error : ' + err)
|
||||||
})
|
})
|
||||||
})
|
})
|
||||||
|
|
||||||
|
it('allows CORS requests', function (done) {
|
||||||
|
const standardScheme = remote.getGlobal('standardScheme')
|
||||||
|
const url = standardScheme + '://fake-host'
|
||||||
|
const content = `<html>
|
||||||
|
<script>
|
||||||
|
const {ipcRenderer, webFrame} = require('electron')
|
||||||
|
webFrame.registerURLSchemeAsPrivileged('cors')
|
||||||
|
fetch('cors://myhost').then(function (response) {
|
||||||
|
ipcRenderer.send('response', response.status)
|
||||||
|
})
|
||||||
|
</script>
|
||||||
|
</html>`
|
||||||
|
var w = new BrowserWindow({show: false})
|
||||||
|
after(function (done) {
|
||||||
|
protocol.unregisterProtocol('cors', function () {
|
||||||
|
protocol.unregisterProtocol(standardScheme, function () {
|
||||||
|
closeWindow(w).then(function () {
|
||||||
|
w = null
|
||||||
|
done()
|
||||||
|
})
|
||||||
|
})
|
||||||
|
})
|
||||||
|
})
|
||||||
|
|
||||||
|
const handler = function (request, callback) {
|
||||||
|
callback({data: content, mimeType: 'text/html'})
|
||||||
|
}
|
||||||
|
protocol.registerStringProtocol(standardScheme, handler, function (error) {
|
||||||
|
if (error) return done(error)
|
||||||
|
})
|
||||||
|
|
||||||
|
protocol.registerStringProtocol('cors', function (request, callback) {
|
||||||
|
callback('')
|
||||||
|
}, function (error) {
|
||||||
|
if (error) return done(error)
|
||||||
|
ipcMain.once('response', function (event, status) {
|
||||||
|
assert.equal(status, 200)
|
||||||
|
done()
|
||||||
|
})
|
||||||
|
w.loadURL(url)
|
||||||
|
})
|
||||||
|
})
|
||||||
})
|
})
|
||||||
})
|
})
|
||||||
|
|
Loading…
Reference in a new issue