void AtomContentClient::AddAdditionalSchemes(
std::vector<url::SchemeWithType>* standard_schemes,
std::vector<std::string>* savable_schemes) {
- std::vector<std::string> schemes;
- ConvertStringWithSeparatorToVector(&schemes, ",",
- switches::kRegisterStandardSchemes);
- if (!schemes.empty()) {
- for (const std::string& scheme : schemes)
- standard_schemes->push_back({scheme.c_str(), url::SCHEME_WITHOUT_PORT});
- }
standard_schemes->push_back({"chrome-extension", url::SCHEME_WITHOUT_PORT});
}
#include "atom/common/native_mate_converters/net_converter.h"
#include "atom/common/node_includes.h"
#include "native_mate/dictionary.h"
+#include "url/url_util.h"
using content::BrowserThread;
void Protocol::RegisterStandardSchemes(
const std::vector<std::string>& schemes) {
- atom::AtomBrowserClient::SetCustomSchemes(schemes);
+ for (const auto& scheme : schemes)
+ url::AddStandardScheme(scheme.c_str(), url::SCHEME_WITHOUT_PORT);
}
void Protocol::RegisterServiceWorkerSchemes(
// Next navigation should not restart renderer process.
bool g_suppress_renderer_process_restart = false;
-// Custom schemes to be registered to standard.
-std::string g_custom_schemes = "";
// Custom schemes to be registered to handle service worker.
std::string g_custom_service_worker_schemes = "";
g_suppress_renderer_process_restart = true;
}
-void AtomBrowserClient::SetCustomSchemes(
- const std::vector<std::string>& schemes) {
- g_custom_schemes = base::JoinString(schemes, ",");
-}
-
void AtomBrowserClient::SetCustomServiceWorkerSchemes(
const std::vector<std::string>& schemes) {
g_custom_service_worker_schemes = base::JoinString(schemes, ",");
if (process_type != "renderer")
return;
- // The registered standard schemes.
- if (!g_custom_schemes.empty())
- command_line->AppendSwitchASCII(switches::kRegisterStandardSchemes,
- g_custom_schemes);
-
// The registered service worker schemes.
if (!g_custom_service_worker_schemes.empty())
command_line->AppendSwitchASCII(switches::kRegisterServiceWorkerSchemes,
// Don't force renderer process to restart for once.
static void SuppressRendererProcessRestartForOnce();
- // Custom schemes to be registered to standard.
- static void SetCustomSchemes(const std::vector<std::string>& schemes);
+
// Custom schemes to be registered to handle service worker.
static void SetCustomServiceWorkerSchemes(
const std::vector<std::string>& schemes);
// Disable HTTP cache.
const char kDisableHttpCache[] = "disable-http-cache";
-// Register schemes to standard.
-const char kRegisterStandardSchemes[] = "register-standard-schemes";
-
// Register schemes to handle service worker.
const char kRegisterServiceWorkerSchemes[] = "register-service-worker-schemes";
extern const char kPpapiFlashPath[];
extern const char kPpapiFlashVersion[];
extern const char kDisableHttpCache[];
-extern const char kRegisterStandardSchemes[];
extern const char kRegisterServiceWorkerSchemes[];
extern const char kSSLVersionFallbackMin[];
extern const char kCipherSuiteBlacklist[];
const path = require('path')
const qs = require('querystring')
const remote = require('electron').remote
+const BrowserWindow = remote.require('electron').BrowserWindow
const protocol = remote.require('electron').protocol
describe('protocol module', function () {
})
})
})
+
it('sends object as response', function (done) {
var handler = function (request, callback) {
callback({
var handler = function (request, callback) {
callback(fakeFilePath)
}
- protocol.registerBufferProtocol(protocolName, handler, function (error) {
+ protocol.registerFileProtocol(protocolName, handler, function (error) {
if (error) {
return done(error)
}
var handler = function (request, callback) {
callback(new Date())
}
- protocol.registerBufferProtocol(protocolName, handler, function (error) {
+ protocol.registerFileProtocol(protocolName, handler, function (error) {
if (error) {
return done(error)
}
})
})
})
+
+ describe('protocol.registerStandardSchemes', function () {
+ const standardScheme = 'app'
+ const origin = standardScheme + '://fake-host'
+ const imageURL = origin + '/test.png'
+ const filePath = path.join(__dirname, 'fixtures', 'pages', 'b.html')
+ const fileContent = '<img src="/test.png" />'
+ var w = null
+ var success = null
+
+ before(function () {
+ protocol.registerStandardSchemes([standardScheme])
+ })
+
+ beforeEach(function () {
+ w = new BrowserWindow({show: false})
+ success = false
+ })
+
+ afterEach(function (done) {
+ protocol.unregisterProtocol(standardScheme, function () {
+ if (w != null) {
+ w.destroy()
+ }
+ w = null
+ done()
+ })
+ })
+
+ it('resolves relative resources', function (done) {
+ var handler = function (request, callback) {
+ if (request.url === imageURL) {
+ success = true
+ callback()
+ } else {
+ callback(filePath)
+ }
+ }
+ protocol.registerFileProtocol(standardScheme, handler, function (error) {
+ if (error) {
+ return done(error)
+ }
+ w.webContents.on('did-finish-load', function () {
+ assert(success)
+ done()
+ })
+ w.loadURL(origin)
+ })
+ })
+
+ it('resolves absolute resources', function (done) {
+ var handler = function (request, callback) {
+ if (request.url === imageURL) {
+ success = true
+ callback()
+ } else {
+ callback({
+ data: fileContent,
+ mimeType: 'text/html'
+ })
+ }
+ }
+ protocol.registerStringProtocol(standardScheme, handler, function (error) {
+ if (error) {
+ return done(error)
+ }
+ w.webContents.on('did-finish-load', function () {
+ assert(success)
+ done()
+ })
+ w.loadURL(origin)
+ })
+ })
+ })
})
<html>
<body>
+<img src="./test.png" />
<script type="text/javascript" charset="utf-8">
console.log('b');
</script>
</body>
</html>
-