allow protocol module initialization before app ready.
* ensure registerStandardSchemes can only be called before app ready * ensure other protocol methods can only be used after app ready
This commit is contained in:
parent
1ff33b7c81
commit
0f2ae385ed
5 changed files with 66 additions and 25 deletions
|
@ -9,6 +9,7 @@
|
|||
#include <map>
|
||||
#include <vector>
|
||||
|
||||
#include "atom/browser/browser_observer.h"
|
||||
#include "atom/browser/net/atom_url_request_job_factory.h"
|
||||
#include "base/callback.h"
|
||||
#include "base/containers/scoped_ptr_hash_map.h"
|
||||
|
@ -30,21 +31,25 @@ class AtomURLRequestJobFactory;
|
|||
|
||||
namespace api {
|
||||
|
||||
class Protocol : public mate::Wrappable<Protocol> {
|
||||
class Protocol : public mate::Wrappable<Protocol>,
|
||||
public BrowserObserver {
|
||||
public:
|
||||
using Handler =
|
||||
base::Callback<void(const net::URLRequest*, v8::Local<v8::Value>)>;
|
||||
using CompletionCallback = base::Callback<void(v8::Local<v8::Value>)>;
|
||||
using BooleanCallback = base::Callback<void(bool)>;
|
||||
|
||||
static mate::Handle<Protocol> Create(
|
||||
v8::Isolate* isolate, AtomBrowserContext* browser_context);
|
||||
static mate::Handle<Protocol> Create(v8::Isolate* isolate);
|
||||
|
||||
static void BuildPrototype(v8::Isolate* isolate,
|
||||
v8::Local<v8::ObjectTemplate> prototype);
|
||||
|
||||
protected:
|
||||
Protocol(v8::Isolate* isolate, AtomBrowserContext* browser_context);
|
||||
explicit Protocol(v8::Isolate* isolate);
|
||||
~Protocol();
|
||||
|
||||
// BrowserObserver:
|
||||
void OnWillFinishLaunching() override;
|
||||
|
||||
private:
|
||||
// Possible errors.
|
||||
|
@ -101,6 +106,10 @@ class Protocol : public mate::Wrappable<Protocol> {
|
|||
mate::Arguments* args) {
|
||||
CompletionCallback callback;
|
||||
args->GetNext(&callback);
|
||||
if (!job_factory_) {
|
||||
OnIOCompleted(callback, PROTOCOL_FAIL);
|
||||
return;
|
||||
}
|
||||
content::BrowserThread::PostTaskAndReplyWithResult(
|
||||
content::BrowserThread::IO, FROM_HERE,
|
||||
base::Bind(&Protocol::RegisterProtocolInIO<RequestJob>,
|
||||
|
@ -138,6 +147,10 @@ class Protocol : public mate::Wrappable<Protocol> {
|
|||
mate::Arguments* args) {
|
||||
CompletionCallback callback;
|
||||
args->GetNext(&callback);
|
||||
if (!job_factory_) {
|
||||
OnIOCompleted(callback, PROTOCOL_FAIL);
|
||||
return;
|
||||
}
|
||||
content::BrowserThread::PostTaskAndReplyWithResult(
|
||||
content::BrowserThread::IO, FROM_HERE,
|
||||
base::Bind(&Protocol::InterceptProtocolInIO<RequestJob>,
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue