base::JoinString(schemes, ","));
}
-mate::Handle<atom::api::Protocol> CreateProtocol(v8::Isolate* isolate) {
- auto browser_context = static_cast<atom::AtomBrowserContext*>(
- atom::AtomBrowserMainParts::Get()->browser_context());
- return atom::api::Protocol::Create(isolate, browser_context);
-}
-
void Initialize(v8::Local<v8::Object> exports, v8::Local<v8::Value> unused,
v8::Local<v8::Context> context, void* priv) {
v8::Isolate* isolate = context->GetIsolate();
mate::Dictionary dict(isolate, exports);
- dict.SetMethod("createProtocolObject", base::Bind(&CreateProtocol, isolate));
dict.SetMethod("registerStandardSchemes", &RegisterStandardSchemes);
}
#include <map>
#include <vector>
+#include "atom/browser/api/trackable_object.h"
#include "atom/browser/net/atom_url_request_job_factory.h"
#include "base/callback.h"
#include "base/containers/scoped_ptr_hash_map.h"
#include "native_mate/arguments.h"
#include "native_mate/dictionary.h"
#include "native_mate/handle.h"
-#include "native_mate/wrappable.h"
namespace base {
class DictionaryValue;
namespace api {
-class Protocol : public mate::Wrappable<Protocol> {
+class Protocol : public mate::TrackableObject<Protocol> {
public:
using Handler =
base::Callback<void(const base::DictionaryValue&, v8::Local<v8::Value>)>;
#include "atom/browser/api/atom_api_cookies.h"
#include "atom/browser/api/atom_api_download_item.h"
+#include "atom/browser/api/atom_api_protocol.h"
#include "atom/browser/api/atom_api_web_request.h"
#include "atom/browser/atom_browser_context.h"
#include "atom/browser/atom_browser_main_parts.h"
return v8::Local<v8::Value>::New(isolate, cookies_);
}
+v8::Local<v8::Value> Session::Protocol(v8::Isolate* isolate) {
+ if (protocol_.IsEmpty()) {
+ auto handle = atom::api::Protocol::Create(isolate, browser_context());
+ protocol_.Reset(isolate, handle.ToV8());
+ }
+ return v8::Local<v8::Value>::New(isolate, protocol_);
+}
+
v8::Local<v8::Value> Session::WebRequest(v8::Isolate* isolate) {
if (web_request_.IsEmpty()) {
auto handle = atom::api::WebRequest::Create(isolate, browser_context());
.SetMethod("allowNTLMCredentialsForDomains",
&Session::AllowNTLMCredentialsForDomains)
.SetProperty("cookies", &Session::Cookies)
+ .SetProperty("protocol", &Session::Protocol)
.SetProperty("webRequest", &Session::WebRequest);
}
void ClearHostResolverCache(mate::Arguments* args);
void AllowNTLMCredentialsForDomains(const std::string& domains);
v8::Local<v8::Value> Cookies(v8::Isolate* isolate);
+ v8::Local<v8::Value> Protocol(v8::Isolate* isolate);
v8::Local<v8::Value> WebRequest(v8::Isolate* isolate);
// Cached object.
v8::Global<v8::Value> cookies_;
+ v8::Global<v8::Value> protocol_;
v8::Global<v8::Value> web_request_;
// The X-DevTools-Emulate-Network-Conditions-Client-Id.
-const {app} = require('electron')
-const {createProtocolObject, registerStandardSchemes} = process.atomBinding('protocol')
+const {app, session} = require('electron')
+const {registerStandardSchemes} = process.atomBinding('protocol')
exports.registerStandardSchemes = function (schemes) {
if (app.isReady()) {
}
app.once('ready', function () {
- let protocol = createProtocolObject()
+ let protocol = session.defaultSession.protocol
for (let method in protocol) {
exports[method] = protocol[method].bind(protocol)
}
var fixtures = path.resolve(__dirname, 'fixtures')
var w = null
var url = 'http://127.0.0.1'
+ var partitionName = 'temp'
+ var protocolName = 'sp'
+ const tempProtocol = session.fromPartition(partitionName).protocol
+ const protocol = session.defaultSession.protocol
beforeEach(function () {
+ if (w != null) {
+ w.destroy()
+ }
w = new BrowserWindow({
show: false,
width: 400,
})
afterEach(function () {
- w.destroy()
+ if (w != null) {
+ w.destroy()
+ }
+ w = null
})
describe('session.cookies', function () {
})
})
})
+
+ describe('session.protocol', function () {
+ beforeEach(function () {
+ if (w != null) {
+ w.destroy()
+ }
+ w = new BrowserWindow({
+ show: false,
+ width: 400,
+ height: 400,
+ webPreferences: {
+ partition: partitionName
+ }
+ })
+ })
+
+ afterEach(function () {
+ if (w != null) {
+ w.destroy()
+ }
+ w = null
+ })
+
+ it('handles requests from a partition', function (done) {
+ var handler = function (error, callback) {
+ callback({
+ data: 'test'
+ })
+ }
+ tempProtocol.registerStringProtocol(protocolName, handler, function (error) {
+ if (error) {
+ return done(error)
+ }
+ protocol.isProtocolHandled(protocolName, function (result) {
+ assert.equal(result, false)
+ tempProtocol.isProtocolHandled(protocolName, function (result) {
+ assert.equal(result, true)
+ w.webContents.on('did-finish-load', function () {
+ done()
+ })
+ w.loadURL(protocolName + "://fake-host")
+ })
+ })
+ })
+ })
+ })
})