finish implementation of {secure:true} opt on protocol.registerStandardScehesm, and add working test

This commit is contained in:
Paul Frazee 2016-11-14 10:20:04 -06:00 коммит произвёл Kevin Sawicki
Родитель 9d2e23413e
Коммит 99ea50649a
9 изменённых файлов: 46 добавлений и 14 удалений

Просмотреть файл

@ -209,7 +209,7 @@ void AtomContentClient::AddSecureSchemesAndOrigins(
std::set<GURL>* secure_origins) {
std::vector<std::string> schemes;
ConvertStringWithSeparatorToVector(&schemes, ",",
switches::kRegisterSecureSchemes);
switches::kSecureSchemes);
if (!schemes.empty()) {
for (const std::string& scheme : schemes) {
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) {
// add switches to register as secure
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.
static const char* const kCommonSwitchNames[] = {
switches::kStandardSchemes,
switches::kEnableSandbox
switches::kEnableSandbox,
switches::kSecureSchemes
};
command_line->CopySwitchesFrom(
*base::CommandLine::ForCurrentProcess(),

Просмотреть файл

@ -145,7 +145,7 @@ const char kStandardSchemes[] = "standard-schemes";
const char kRegisterServiceWorkerSchemes[] = "register-service-worker-schemes";
// 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
// TLS fallback will accept.

Просмотреть файл

@ -76,7 +76,7 @@ extern const char kPpapiFlashVersion[];
extern const char kDisableHttpCache[];
extern const char kStandardSchemes[];
extern const char kRegisterServiceWorkerSchemes[];
extern const char kRegisterSecureSchemes[];
extern const char kSecureSchemes[];
extern const char kSSLVersionFallbackMin[];
extern const char kCipherSuiteBlacklist[];
extern const char kAppUserModelId[];

Просмотреть файл

@ -121,20 +121,24 @@ bool IsDevToolsExtension(content::RenderFrame* render_frame) {
.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
AtomRendererClient::AtomRendererClient()
: node_bindings_(NodeBindings::Create(false)),
atom_bindings_(new AtomBindings) {
// Parse --standard-schemes=scheme1,scheme2
base::CommandLine* command_line = base::CommandLine::ForCurrentProcess();
std::string custom_schemes = command_line->GetSwitchValueASCII(
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);
std::vector<std::string> standard_schemes_list = ParseSchemesCLISwitch(switches::kStandardSchemes);
for (const std::string& scheme : standard_schemes_list) {
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.
// FIXME(zcbenz): Can this be moved elsewhere?
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) {

Просмотреть файл

@ -985,5 +985,19 @@ describe('protocol module', function () {
ipcMain.once('file-system-error', (event, err) => done(err))
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 поставляемый 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.
global.standardScheme = 'app'
protocol.registerStandardSchemes([global.standardScheme])
protocol.registerStandardSchemes([global.standardScheme], { secure: true })
app.on('window-all-closed', function () {
app.quit()