From fd297722a82001599b0ba55b4ea2743399de4932 Mon Sep 17 00:00:00 2001 From: deepak1556 Date: Mon, 18 Dec 2017 14:59:28 +0530 Subject: [PATCH] Note about incorrect usage of blink::SchemeRegistry methods --- atom/renderer/api/atom_api_web_frame.cc | 4 ++++ atom/renderer/renderer_client_base.cc | 1 + spec/api-web-frame-spec.js | 1 - spec/chromium-spec.js | 9 +-------- 4 files changed, 6 insertions(+), 9 deletions(-) diff --git a/atom/renderer/api/atom_api_web_frame.cc b/atom/renderer/api/atom_api_web_frame.cc index a91f7019251a..2d1ebd288dfc 100644 --- a/atom/renderer/api/atom_api_web_frame.cc +++ b/atom/renderer/api/atom_api_web_frame.cc @@ -215,6 +215,10 @@ void WebFrame::RegisterURLSchemeAsBypassingCSP(const std::string& scheme) { void WebFrame::RegisterURLSchemeAsPrivileged(const std::string& scheme, mate::Arguments* args) { + // TODO(deepak1556): blink::SchemeRegistry methods should be called + // before any renderer threads are created. Fixing this would break + // current api. Change it with 2.0. + // Read optional flags bool secure = true; bool bypassCSP = true; diff --git a/atom/renderer/renderer_client_base.cc b/atom/renderer/renderer_client_base.cc index 81bf0efd5377..1086e6182893 100644 --- a/atom/renderer/renderer_client_base.cc +++ b/atom/renderer/renderer_client_base.cc @@ -116,6 +116,7 @@ void RendererClientBase::RenderThreadStarted() { // Allow file scheme to handle service worker by default. // FIXME(zcbenz): Can this be moved elsewhere? blink::WebSecurityPolicy::RegisterURLSchemeAsAllowingServiceWorkers("file"); + blink::SchemeRegistry::RegisterURLSchemeAsSupportingFetchAPI("file"); preferences_manager_.reset(new PreferencesManager); diff --git a/spec/api-web-frame-spec.js b/spec/api-web-frame-spec.js index a62c075d8e86..776b6efcebfe 100644 --- a/spec/api-web-frame-spec.js +++ b/spec/api-web-frame-spec.js @@ -17,7 +17,6 @@ describe('webFrame module', function () { describe('webFrame.registerURLSchemeAsPrivileged', function () { it('supports fetch api by default', function (done) { - webFrame.registerURLSchemeAsPrivileged('file') var url = 'file://' + fixtures + '/assets/logo.png' window.fetch(url).then(function (response) { assert(response.ok) diff --git a/spec/chromium-spec.js b/spec/chromium-spec.js index db577ab4578c..204cd111b48e 100644 --- a/spec/chromium-spec.js +++ b/spec/chromium-spec.js @@ -4,7 +4,7 @@ const http = require('http') const path = require('path') const ws = require('ws') const url = require('url') -const {ipcRenderer, remote, webFrame} = require('electron') +const {ipcRenderer, remote} = require('electron') const {closeWindow} = require('./window-helpers') const {app, BrowserWindow, ipcMain, protocol, session, webContents} = remote @@ -1043,13 +1043,6 @@ describe('chromium feature', () => { }) it('should not open when pdf is requested as sub resource', (done) => { - createBrowserWindow({plugins: true, preload: 'preload-pdf-loaded.js'}) - webFrame.registerURLSchemeAsPrivileged('file', { - secure: false, - bypassCSP: false, - allowServiceWorkers: false, - corsEnabled: false - }) fetch(pdfSource).then((res) => { assert.equal(res.status, 200) assert.notEqual(document.title, 'cat.pdf')