Make api::Protocol per-context
This commit is contained in:
parent
e6341ceaaa
commit
b47fae7393
2 changed files with 15 additions and 7 deletions
|
@ -5,6 +5,7 @@
|
||||||
#include "atom/browser/api/atom_api_protocol.h"
|
#include "atom/browser/api/atom_api_protocol.h"
|
||||||
|
|
||||||
#include "atom/browser/atom_browser_context.h"
|
#include "atom/browser/atom_browser_context.h"
|
||||||
|
#include "atom/browser/atom_browser_main_parts.h"
|
||||||
#include "atom/browser/net/adapter_request_job.h"
|
#include "atom/browser/net/adapter_request_job.h"
|
||||||
#include "atom/browser/net/atom_url_request_job_factory.h"
|
#include "atom/browser/net/atom_url_request_job_factory.h"
|
||||||
#include "atom/common/native_mate_converters/file_path_converter.h"
|
#include "atom/common/native_mate_converters/file_path_converter.h"
|
||||||
|
@ -190,8 +191,9 @@ class CustomProtocolHandler : public ProtocolHandler {
|
||||||
|
|
||||||
} // namespace
|
} // namespace
|
||||||
|
|
||||||
Protocol::Protocol()
|
Protocol::Protocol(AtomBrowserContext* browser_context)
|
||||||
: job_factory_(AtomBrowserContext::Get()->job_factory()) {
|
: browser_context_(browser_context),
|
||||||
|
job_factory_(browser_context->job_factory()) {
|
||||||
CHECK(job_factory_);
|
CHECK(job_factory_);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -343,8 +345,9 @@ void Protocol::EmitEventInUI(const std::string& event,
|
||||||
}
|
}
|
||||||
|
|
||||||
// static
|
// static
|
||||||
mate::Handle<Protocol> Protocol::Create(v8::Isolate* isolate) {
|
mate::Handle<Protocol> Protocol::Create(
|
||||||
return CreateHandle(isolate, new Protocol);
|
v8::Isolate* isolate, AtomBrowserContext* browser_context) {
|
||||||
|
return CreateHandle(isolate, new Protocol(browser_context));
|
||||||
}
|
}
|
||||||
|
|
||||||
} // namespace api
|
} // namespace api
|
||||||
|
@ -357,7 +360,9 @@ void Initialize(v8::Local<v8::Object> exports, v8::Local<v8::Value> unused,
|
||||||
v8::Local<v8::Context> context, void* priv) {
|
v8::Local<v8::Context> context, void* priv) {
|
||||||
v8::Isolate* isolate = context->GetIsolate();
|
v8::Isolate* isolate = context->GetIsolate();
|
||||||
mate::Dictionary dict(isolate, exports);
|
mate::Dictionary dict(isolate, exports);
|
||||||
dict.Set("protocol", atom::api::Protocol::Create(isolate));
|
auto browser_context = static_cast<atom::AtomBrowserContext*>(
|
||||||
|
atom::AtomBrowserMainParts::Get()->browser_context());
|
||||||
|
dict.Set("protocol", atom::api::Protocol::Create(isolate, browser_context));
|
||||||
}
|
}
|
||||||
|
|
||||||
} // namespace
|
} // namespace
|
||||||
|
|
|
@ -18,6 +18,7 @@ class URLRequest;
|
||||||
|
|
||||||
namespace atom {
|
namespace atom {
|
||||||
|
|
||||||
|
class AtomBrowserContext;
|
||||||
class AtomURLRequestJobFactory;
|
class AtomURLRequestJobFactory;
|
||||||
|
|
||||||
namespace api {
|
namespace api {
|
||||||
|
@ -27,12 +28,13 @@ class Protocol : public mate::EventEmitter {
|
||||||
typedef base::Callback<v8::Local<v8::Value>(const net::URLRequest*)>
|
typedef base::Callback<v8::Local<v8::Value>(const net::URLRequest*)>
|
||||||
JsProtocolHandler;
|
JsProtocolHandler;
|
||||||
|
|
||||||
static mate::Handle<Protocol> Create(v8::Isolate* isolate);
|
static mate::Handle<Protocol> Create(
|
||||||
|
v8::Isolate* isolate, AtomBrowserContext* browser_context);
|
||||||
|
|
||||||
JsProtocolHandler GetProtocolHandler(const std::string& scheme);
|
JsProtocolHandler GetProtocolHandler(const std::string& scheme);
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
Protocol();
|
explicit Protocol(AtomBrowserContext* browser_context);
|
||||||
|
|
||||||
// mate::Wrappable implementations:
|
// mate::Wrappable implementations:
|
||||||
virtual mate::ObjectTemplateBuilder GetObjectTemplateBuilder(
|
virtual mate::ObjectTemplateBuilder GetObjectTemplateBuilder(
|
||||||
|
@ -68,6 +70,7 @@ class Protocol : public mate::EventEmitter {
|
||||||
// Do protocol.emit(event, parameter) under UI thread.
|
// Do protocol.emit(event, parameter) under UI thread.
|
||||||
void EmitEventInUI(const std::string& event, const std::string& parameter);
|
void EmitEventInUI(const std::string& event, const std::string& parameter);
|
||||||
|
|
||||||
|
AtomBrowserContext* browser_context_;
|
||||||
AtomURLRequestJobFactory* job_factory_;
|
AtomURLRequestJobFactory* job_factory_;
|
||||||
ProtocolHandlersMap protocol_handlers_;
|
ProtocolHandlersMap protocol_handlers_;
|
||||||
|
|
||||||
|
|
Loading…
Add table
Reference in a new issue