From 2e78aba09038fadc785e65a23aceae3dae492776 Mon Sep 17 00:00:00 2001 From: Robo Date: Tue, 29 Dec 2015 15:56:19 +0530 Subject: [PATCH] webFrame: support fetch api for schemes that are privileged. --- atom/renderer/api/atom_api_web_frame.cc | 2 ++ docs/api/web-frame.md | 4 ++-- spec/api-web-frame-spec.coffee | 18 ++++++++++++++++++ 3 files changed, 22 insertions(+), 2 deletions(-) create mode 100644 spec/api-web-frame-spec.coffee diff --git a/atom/renderer/api/atom_api_web_frame.cc b/atom/renderer/api/atom_api_web_frame.cc index e9b2b03055e6..83d67a8b6635 100644 --- a/atom/renderer/api/atom_api_web_frame.cc +++ b/atom/renderer/api/atom_api_web_frame.cc @@ -112,6 +112,8 @@ void WebFrame::RegisterURLSchemeAsPrivileged(const std::string& scheme) { privileged_scheme); blink::WebSecurityPolicy::registerURLSchemeAsAllowingServiceWorkers( privileged_scheme); + blink::WebSecurityPolicy::registerURLSchemeAsSupportingFetchAPI( + privileged_scheme); } mate::ObjectTemplateBuilder WebFrame::GetObjectTemplateBuilder( diff --git a/docs/api/web-frame.md b/docs/api/web-frame.md index 38c5e30db43f..114afd041cd0 100644 --- a/docs/api/web-frame.md +++ b/docs/api/web-frame.md @@ -87,7 +87,7 @@ Content Security Policy. * `scheme` String -Registers the `scheme` as secure, bypasses content security policy for resources and -allows registering ServiceWorker. +Registers the `scheme` as secure, bypasses content security policy for resources, +allows registering ServiceWorker and supports fetch API. [spellchecker]: https://github.com/atom/node-spellchecker diff --git a/spec/api-web-frame-spec.coffee b/spec/api-web-frame-spec.coffee new file mode 100644 index 000000000000..cece329084e1 --- /dev/null +++ b/spec/api-web-frame-spec.coffee @@ -0,0 +1,18 @@ +assert = require 'assert' +path = require 'path' + +{webFrame} = require 'electron' + +describe 'webFrame module', -> + fixtures = path.resolve __dirname, 'fixtures' + + describe 'webFrame.registerURLSchemeAsPrivileged', -> + it 'supports fetch api', (done) -> + webFrame.registerURLSchemeAsPrivileged 'file' + url = "file://#{fixtures}/assets/logo.png" + + fetch(url).then((response) -> + assert response.ok + done() + ).catch (err) -> + done('unexpected error : ' + err)