2013-04-15 16:25:08 +00:00
|
|
|
// Copyright (c) 2013 GitHub, Inc. All rights reserved.
|
2014-04-25 09:49:37 +00:00
|
|
|
// Use of this source code is governed by the MIT license that can be
|
2013-04-15 16:25:08 +00:00
|
|
|
// found in the LICENSE file.
|
|
|
|
|
2014-03-16 00:30:26 +00:00
|
|
|
#include "atom/browser/atom_browser_context.h"
|
2013-04-15 16:25:08 +00:00
|
|
|
|
2014-03-16 00:30:26 +00:00
|
|
|
#include "atom/browser/atom_browser_main_parts.h"
|
2014-08-13 09:40:31 +00:00
|
|
|
#include "atom/browser/net/atom_url_request_job_factory.h"
|
|
|
|
#include "base/threading/sequenced_worker_pool.h"
|
|
|
|
#include "base/threading/worker_pool.h"
|
2014-08-21 07:45:34 +00:00
|
|
|
#include "chrome/browser/browser_process.h"
|
2013-09-20 08:47:47 +00:00
|
|
|
#include "content/public/browser/browser_thread.h"
|
2014-08-13 09:40:31 +00:00
|
|
|
#include "content/public/common/url_constants.h"
|
|
|
|
#include "net/url_request/data_protocol_handler.h"
|
|
|
|
#include "net/url_request/file_protocol_handler.h"
|
|
|
|
#include "net/url_request/protocol_intercept_job_factory.h"
|
2013-04-15 16:25:08 +00:00
|
|
|
|
2013-09-20 08:47:47 +00:00
|
|
|
using content::BrowserThread;
|
|
|
|
|
2014-08-13 09:40:31 +00:00
|
|
|
namespace atom {
|
2013-09-20 08:47:47 +00:00
|
|
|
|
|
|
|
AtomBrowserContext::AtomBrowserContext()
|
2014-08-21 07:45:34 +00:00
|
|
|
: fake_browser_process_(new BrowserProcess),
|
|
|
|
job_factory_(new AtomURLRequestJobFactory) {
|
2013-04-15 16:25:08 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
AtomBrowserContext::~AtomBrowserContext() {
|
|
|
|
}
|
|
|
|
|
2014-08-20 07:30:32 +00:00
|
|
|
net::URLRequestJobFactory* AtomBrowserContext::CreateURLRequestJobFactory(
|
2014-08-13 09:40:31 +00:00
|
|
|
content::ProtocolHandlerMap* handlers,
|
|
|
|
content::ProtocolHandlerScopedVector* interceptors) {
|
|
|
|
scoped_ptr<AtomURLRequestJobFactory> job_factory(job_factory_);
|
|
|
|
|
|
|
|
for (content::ProtocolHandlerMap::iterator it = handlers->begin();
|
|
|
|
it != handlers->end(); ++it)
|
|
|
|
job_factory->SetProtocolHandler(it->first, it->second.release());
|
|
|
|
handlers->clear();
|
|
|
|
|
|
|
|
job_factory->SetProtocolHandler(
|
|
|
|
content::kDataScheme, new net::DataProtocolHandler);
|
|
|
|
job_factory->SetProtocolHandler(
|
|
|
|
content::kFileScheme, new net::FileProtocolHandler(
|
|
|
|
BrowserThread::GetBlockingPool()->GetTaskRunnerWithShutdownBehavior(
|
|
|
|
base::SequencedWorkerPool::SKIP_ON_SHUTDOWN)));
|
|
|
|
|
|
|
|
// Set up interceptors in the reverse order.
|
|
|
|
scoped_ptr<net::URLRequestJobFactory> top_job_factory =
|
|
|
|
job_factory.PassAs<net::URLRequestJobFactory>();
|
|
|
|
content::ProtocolHandlerScopedVector::reverse_iterator it;
|
|
|
|
for (it = interceptors->rbegin(); it != interceptors->rend(); ++it)
|
|
|
|
top_job_factory.reset(new net::ProtocolInterceptJobFactory(
|
|
|
|
top_job_factory.Pass(), make_scoped_ptr(*it)));
|
|
|
|
interceptors->weak_clear();
|
|
|
|
|
2014-08-20 07:30:32 +00:00
|
|
|
return top_job_factory.release();
|
2013-09-20 08:47:47 +00:00
|
|
|
}
|
|
|
|
|
2013-04-15 16:25:08 +00:00
|
|
|
// static
|
|
|
|
AtomBrowserContext* AtomBrowserContext::Get() {
|
2013-04-22 13:32:48 +00:00
|
|
|
return static_cast<AtomBrowserContext*>(
|
|
|
|
AtomBrowserMainParts::Get()->browser_context());
|
2013-04-15 16:25:08 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
} // namespace atom
|