protocol: fix registerStandardSchemes api

This commit is contained in:
deepak1556 2016-05-06 00:04:16 +05:30
Родитель b05fa2ed5b
Коммит 1ff33b7c81
8 изменённых файлов: 83 добавлений и 29 удалений

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

@ -183,13 +183,6 @@ base::string16 AtomContentClient::GetLocalizedString(int message_id) const {
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});
}

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

@ -15,6 +15,7 @@
#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;
@ -31,7 +32,8 @@ Protocol::Protocol(v8::Isolate* isolate, AtomBrowserContext* browser_context)
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(

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

@ -49,8 +49,6 @@ namespace {
// 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 = "";
@ -61,11 +59,6 @@ void AtomBrowserClient::SuppressRendererProcessRestartForOnce() {
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, ",");
@ -153,11 +146,6 @@ void AtomBrowserClient::AppendExtraCommandLineSwitches(
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,

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

@ -36,8 +36,7 @@ class AtomBrowserClient : public brightray::BrowserClient,
// 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);

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

@ -125,9 +125,6 @@ const char kPpapiFlashVersion[] = "ppapi-flash-version";
// 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";

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

@ -70,7 +70,6 @@ extern const char kEnablePlugins[];
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[];

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

@ -3,6 +3,7 @@ const http = require('http')
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 () {
@ -344,6 +345,7 @@ describe('protocol module', function () {
})
})
})
it('sends object as response', function (done) {
var handler = function (request, callback) {
callback({
@ -394,7 +396,7 @@ describe('protocol module', function () {
var handler = function (request, callback) {
callback(fakeFilePath)
}
protocol.registerBufferProtocol(protocolName, handler, function (error) {
protocol.registerFileProtocol(protocolName, handler, function (error) {
if (error) {
return done(error)
}
@ -415,7 +417,7 @@ describe('protocol module', function () {
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)
}
@ -814,4 +816,78 @@ describe('protocol module', function () {
})
})
})
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)
})
})
})
})

2
spec/fixtures/pages/b.html поставляемый
Просмотреть файл

@ -1,8 +1,8 @@
<html>
<body>
<img src="./test.png" />
<script type="text/javascript" charset="utf-8">
console.log('b');
</script>
</body>
</html>