finish implementation of {secure:true} opt on protocol.registerStandardScehesm, and add working test
This commit is contained in:
parent
9d2e23413e
commit
99ea50649a
9 changed files with 46 additions and 14 deletions
|
@ -209,7 +209,7 @@ void AtomContentClient::AddSecureSchemesAndOrigins(
|
||||||
std::set<GURL>* secure_origins) {
|
std::set<GURL>* secure_origins) {
|
||||||
std::vector<std::string> schemes;
|
std::vector<std::string> schemes;
|
||||||
ConvertStringWithSeparatorToVector(&schemes, ",",
|
ConvertStringWithSeparatorToVector(&schemes, ",",
|
||||||
switches::kRegisterSecureSchemes);
|
switches::kSecureSchemes);
|
||||||
if (!schemes.empty()) {
|
if (!schemes.empty()) {
|
||||||
for (const std::string& scheme : schemes) {
|
for (const std::string& scheme : schemes) {
|
||||||
secure_schemes->insert(scheme);
|
secure_schemes->insert(scheme);
|
||||||
|
|
|
@ -64,7 +64,7 @@ void RegisterStandardSchemes(const std::vector<std::string>& schemes, mate::Argu
|
||||||
if (args->GetNext(&opts) && opts.Get("secure", &secure) && secure) {
|
if (args->GetNext(&opts) && opts.Get("secure", &secure) && secure) {
|
||||||
// add switches to register as secure
|
// add switches to register as secure
|
||||||
base::CommandLine::ForCurrentProcess()->AppendSwitchASCII(
|
base::CommandLine::ForCurrentProcess()->AppendSwitchASCII(
|
||||||
atom::switches::kRegisterSecureSchemes, base::JoinString(schemes, ","));
|
atom::switches::kSecureSchemes, base::JoinString(schemes, ","));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -234,7 +234,8 @@ void AtomBrowserClient::AppendExtraCommandLineSwitches(
|
||||||
// Copy following switches to child process.
|
// Copy following switches to child process.
|
||||||
static const char* const kCommonSwitchNames[] = {
|
static const char* const kCommonSwitchNames[] = {
|
||||||
switches::kStandardSchemes,
|
switches::kStandardSchemes,
|
||||||
switches::kEnableSandbox
|
switches::kEnableSandbox,
|
||||||
|
switches::kSecureSchemes
|
||||||
};
|
};
|
||||||
command_line->CopySwitchesFrom(
|
command_line->CopySwitchesFrom(
|
||||||
*base::CommandLine::ForCurrentProcess(),
|
*base::CommandLine::ForCurrentProcess(),
|
||||||
|
|
|
@ -145,7 +145,7 @@ const char kStandardSchemes[] = "standard-schemes";
|
||||||
const char kRegisterServiceWorkerSchemes[] = "register-service-worker-schemes";
|
const char kRegisterServiceWorkerSchemes[] = "register-service-worker-schemes";
|
||||||
|
|
||||||
// Register schemes as secure.
|
// Register schemes as secure.
|
||||||
const char kRegisterSecureSchemes[] = "register-secure-schemes";
|
const char kSecureSchemes[] = "secure-schemes";
|
||||||
|
|
||||||
// The minimum SSL/TLS version ("tls1", "tls1.1", or "tls1.2") that
|
// The minimum SSL/TLS version ("tls1", "tls1.1", or "tls1.2") that
|
||||||
// TLS fallback will accept.
|
// TLS fallback will accept.
|
||||||
|
|
|
@ -76,7 +76,7 @@ extern const char kPpapiFlashVersion[];
|
||||||
extern const char kDisableHttpCache[];
|
extern const char kDisableHttpCache[];
|
||||||
extern const char kStandardSchemes[];
|
extern const char kStandardSchemes[];
|
||||||
extern const char kRegisterServiceWorkerSchemes[];
|
extern const char kRegisterServiceWorkerSchemes[];
|
||||||
extern const char kRegisterSecureSchemes[];
|
extern const char kSecureSchemes[];
|
||||||
extern const char kSSLVersionFallbackMin[];
|
extern const char kSSLVersionFallbackMin[];
|
||||||
extern const char kCipherSuiteBlacklist[];
|
extern const char kCipherSuiteBlacklist[];
|
||||||
extern const char kAppUserModelId[];
|
extern const char kAppUserModelId[];
|
||||||
|
|
|
@ -121,19 +121,23 @@ bool IsDevToolsExtension(content::RenderFrame* render_frame) {
|
||||||
.SchemeIs("chrome-extension");
|
.SchemeIs("chrome-extension");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
std::vector<std::string> ParseSchemesCLISwitch(const char* switch_name) {
|
||||||
|
base::CommandLine* command_line = base::CommandLine::ForCurrentProcess();
|
||||||
|
std::string custom_schemes = command_line->GetSwitchValueASCII(switch_name);
|
||||||
|
if (!custom_schemes.empty()) {
|
||||||
|
return base::SplitString(custom_schemes, ",", base::TRIM_WHITESPACE, base::SPLIT_WANT_NONEMPTY);
|
||||||
|
}
|
||||||
|
return std::vector<std::string>();
|
||||||
|
}
|
||||||
|
|
||||||
} // namespace
|
} // namespace
|
||||||
|
|
||||||
AtomRendererClient::AtomRendererClient()
|
AtomRendererClient::AtomRendererClient()
|
||||||
: node_bindings_(NodeBindings::Create(false)),
|
: node_bindings_(NodeBindings::Create(false)),
|
||||||
atom_bindings_(new AtomBindings) {
|
atom_bindings_(new AtomBindings) {
|
||||||
// Parse --standard-schemes=scheme1,scheme2
|
// Parse --standard-schemes=scheme1,scheme2
|
||||||
base::CommandLine* command_line = base::CommandLine::ForCurrentProcess();
|
std::vector<std::string> standard_schemes_list = ParseSchemesCLISwitch(switches::kStandardSchemes);
|
||||||
std::string custom_schemes = command_line->GetSwitchValueASCII(
|
for (const std::string& scheme : standard_schemes_list) {
|
||||||
switches::kStandardSchemes);
|
|
||||||
if (!custom_schemes.empty()) {
|
|
||||||
std::vector<std::string> schemes_list = base::SplitString(
|
|
||||||
custom_schemes, ",", base::TRIM_WHITESPACE, base::SPLIT_WANT_NONEMPTY);
|
|
||||||
for (const std::string& scheme : schemes_list)
|
|
||||||
url::AddStandardScheme(scheme.c_str(), url::SCHEME_WITHOUT_PORT);
|
url::AddStandardScheme(scheme.c_str(), url::SCHEME_WITHOUT_PORT);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -182,6 +186,12 @@ void AtomRendererClient::RenderFrameCreated(
|
||||||
// Allow file scheme to handle service worker by default.
|
// Allow file scheme to handle service worker by default.
|
||||||
// FIXME(zcbenz): Can this be moved elsewhere?
|
// FIXME(zcbenz): Can this be moved elsewhere?
|
||||||
blink::WebSecurityPolicy::registerURLSchemeAsAllowingServiceWorkers("file");
|
blink::WebSecurityPolicy::registerURLSchemeAsAllowingServiceWorkers("file");
|
||||||
|
|
||||||
|
// Parse --secure-schemes=scheme1,scheme2
|
||||||
|
std::vector<std::string> secure_schemes_list = ParseSchemesCLISwitch(switches::kSecureSchemes);
|
||||||
|
for (const std::string& secure_scheme : secure_schemes_list) {
|
||||||
|
blink::WebSecurityPolicy::registerURLSchemeAsSecure(blink::WebString::fromUTF8(secure_scheme));
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void AtomRendererClient::RenderViewCreated(content::RenderView* render_view) {
|
void AtomRendererClient::RenderViewCreated(content::RenderView* render_view) {
|
||||||
|
|
|
@ -985,5 +985,19 @@ describe('protocol module', function () {
|
||||||
ipcMain.once('file-system-error', (event, err) => done(err))
|
ipcMain.once('file-system-error', (event, err) => done(err))
|
||||||
ipcMain.once('file-system-write-end', () => done())
|
ipcMain.once('file-system-write-end', () => done())
|
||||||
})
|
})
|
||||||
|
|
||||||
|
it('registers secure, when {secure: true}', function (done) {
|
||||||
|
// the CacheStorage API will only work if secure == true
|
||||||
|
let filePath = path.join(__dirname, 'fixtures', 'pages', 'cache-storage.html')
|
||||||
|
const handler = function (request, callback) {
|
||||||
|
callback({path: filePath})
|
||||||
|
}
|
||||||
|
ipcMain.once('success', () => done())
|
||||||
|
ipcMain.once('failure', (event, err) => done(err))
|
||||||
|
protocol.registerFileProtocol(standardScheme, handler, function (error) {
|
||||||
|
if (error) return done(error)
|
||||||
|
w.loadURL(origin)
|
||||||
|
})
|
||||||
|
})
|
||||||
})
|
})
|
||||||
})
|
})
|
||||||
|
|
7
spec/fixtures/pages/cache-storage.html
vendored
Normal file
7
spec/fixtures/pages/cache-storage.html
vendored
Normal file
|
@ -0,0 +1,7 @@
|
||||||
|
<script>
|
||||||
|
const ipcRenderer = require('electron').ipcRenderer;
|
||||||
|
caches.open('foo').then(
|
||||||
|
() => ipcRenderer.send('success'),
|
||||||
|
err => ipcRenderer.send('failure', err)
|
||||||
|
)
|
||||||
|
</script>
|
|
@ -92,7 +92,7 @@ if (global.isCi) {
|
||||||
|
|
||||||
// Register app as standard scheme.
|
// Register app as standard scheme.
|
||||||
global.standardScheme = 'app'
|
global.standardScheme = 'app'
|
||||||
protocol.registerStandardSchemes([global.standardScheme])
|
protocol.registerStandardSchemes([global.standardScheme], { secure: true })
|
||||||
|
|
||||||
app.on('window-all-closed', function () {
|
app.on('window-all-closed', function () {
|
||||||
app.quit()
|
app.quit()
|
||||||
|
|
Loading…
Reference in a new issue