Actually set and remove protocol handlers in IO thread..
This commit is contained in:
parent
96c173217f
commit
33279b1a2f
1 changed files with 37 additions and 1 deletions
|
@ -4,14 +4,46 @@
|
|||
|
||||
#include "browser/api/atom_api_protocol.h"
|
||||
|
||||
#include "browser/atom_browser_context.h"
|
||||
#include "content/public/browser/browser_thread.h"
|
||||
#include "net/url_request/url_request_job_manager.h"
|
||||
#include "net/url_request/url_request_context.h"
|
||||
#include "net/url_request/url_request_context_getter.h"
|
||||
#include "net/url_request/url_request_job_factory_impl.h"
|
||||
#include "vendor/node/src/node.h"
|
||||
|
||||
namespace atom {
|
||||
|
||||
namespace api {
|
||||
|
||||
namespace {
|
||||
|
||||
net::URLRequestJobFactoryImpl* GetRequestJobFactory() {
|
||||
DCHECK(content::BrowserThread::CurrentlyOn(content::BrowserThread::IO));
|
||||
// Get the job factory.
|
||||
net::URLRequestJobFactoryImpl* job_factory =
|
||||
static_cast<net::URLRequestJobFactoryImpl*>(
|
||||
const_cast<net::URLRequestJobFactory*>(
|
||||
static_cast<content::BrowserContext*>(AtomBrowserContext::Get())->
|
||||
GetRequestContext()->GetURLRequestContext()->job_factory()));
|
||||
return job_factory;
|
||||
}
|
||||
|
||||
class AdapterProtocolHandler
|
||||
: public net::URLRequestJobFactory::ProtocolHandler {
|
||||
public:
|
||||
AdapterProtocolHandler() {}
|
||||
virtual net::URLRequestJob* MaybeCreateJob(
|
||||
net::URLRequest* request,
|
||||
net::NetworkDelegate* network_delegate) const OVERRIDE {
|
||||
return NULL;
|
||||
}
|
||||
|
||||
private:
|
||||
DISALLOW_COPY_AND_ASSIGN(AdapterProtocolHandler);
|
||||
};
|
||||
|
||||
} // namespace
|
||||
|
||||
Protocol::HandlersMap Protocol::handlers_;
|
||||
|
||||
// static
|
||||
|
@ -53,11 +85,15 @@ v8::Handle<v8::Value> Protocol::UnregisterProtocol(const v8::Arguments& args) {
|
|||
// static
|
||||
void Protocol::RegisterProtocolInIO(const std::string& scheme) {
|
||||
DCHECK(content::BrowserThread::CurrentlyOn(content::BrowserThread::IO));
|
||||
net::URLRequestJobFactoryImpl* job_factory(GetRequestJobFactory());
|
||||
job_factory->SetProtocolHandler(scheme, new AdapterProtocolHandler);
|
||||
}
|
||||
|
||||
// static
|
||||
void Protocol::UnregisterProtocolInIO(const std::string& scheme) {
|
||||
DCHECK(content::BrowserThread::CurrentlyOn(content::BrowserThread::IO));
|
||||
net::URLRequestJobFactoryImpl* job_factory(GetRequestJobFactory());
|
||||
job_factory->SetProtocolHandler(scheme, NULL);
|
||||
}
|
||||
|
||||
// static
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue