2014-10-31 18:17:05 +00:00
|
|
|
// Copyright (c) 2013 GitHub, Inc.
|
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"
|
2014-09-23 04:13:46 +00:00
|
|
|
#include "atom/browser/net/asar/asar_protocol_handler.h"
|
2015-05-06 20:15:56 +00:00
|
|
|
#include "atom/browser/net/http_protocol_handler.h"
|
2015-02-04 23:17:28 +00:00
|
|
|
#include "atom/browser/web_view_manager.h"
|
2015-01-05 21:40:38 +00:00
|
|
|
#include "atom/common/options_switches.h"
|
|
|
|
#include "base/command_line.h"
|
2014-08-13 09:40:31 +00:00
|
|
|
#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"
|
2014-09-01 07:36:37 +00:00
|
|
|
#include "net/url_request/url_request_intercepting_job_factory.h"
|
|
|
|
#include "url/url_constants.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
|
|
|
|
2014-09-23 04:13:46 +00:00
|
|
|
namespace {
|
|
|
|
|
2015-01-05 21:40:38 +00:00
|
|
|
class NoCacheBackend : public net::HttpCache::BackendFactory {
|
|
|
|
int CreateBackend(net::NetLog* net_log,
|
|
|
|
scoped_ptr<disk_cache::Backend>* backend,
|
|
|
|
const net::CompletionCallback& callback) override {
|
|
|
|
return net::ERR_FAILED;
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
2014-09-23 04:13:46 +00:00
|
|
|
} // namespace
|
|
|
|
|
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,
|
2014-09-01 07:36:37 +00:00
|
|
|
content::URLRequestInterceptorScopedVector* interceptors) {
|
2014-08-13 09:40:31 +00:00
|
|
|
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(
|
2014-09-01 07:36:37 +00:00
|
|
|
url::kDataScheme, new net::DataProtocolHandler);
|
2014-08-13 09:40:31 +00:00
|
|
|
job_factory->SetProtocolHandler(
|
2015-01-31 01:45:22 +00:00
|
|
|
url::kFileScheme, new asar::AsarProtocolHandler(
|
2014-08-13 09:40:31 +00:00
|
|
|
BrowserThread::GetBlockingPool()->GetTaskRunnerWithShutdownBehavior(
|
|
|
|
base::SequencedWorkerPool::SKIP_ON_SHUTDOWN)));
|
2015-05-06 20:15:56 +00:00
|
|
|
job_factory->SetProtocolHandler(
|
2015-05-11 07:26:36 +00:00
|
|
|
url::kHttpScheme, new HttpProtocolHandler(url::kHttpScheme));
|
|
|
|
job_factory->SetProtocolHandler(
|
|
|
|
url::kHttpsScheme, new HttpProtocolHandler(url::kHttpsScheme));
|
|
|
|
job_factory->SetProtocolHandler(
|
|
|
|
url::kWsScheme, new HttpProtocolHandler(url::kWsScheme));
|
|
|
|
job_factory->SetProtocolHandler(
|
|
|
|
url::kWssScheme, new HttpProtocolHandler(url::kWssScheme));
|
2014-08-13 09:40:31 +00:00
|
|
|
|
|
|
|
// Set up interceptors in the reverse order.
|
2015-01-10 01:42:48 +00:00
|
|
|
scoped_ptr<net::URLRequestJobFactory> top_job_factory = job_factory.Pass();
|
2014-09-01 07:36:37 +00:00
|
|
|
content::URLRequestInterceptorScopedVector::reverse_iterator it;
|
2014-08-13 09:40:31 +00:00
|
|
|
for (it = interceptors->rbegin(); it != interceptors->rend(); ++it)
|
2014-09-01 07:36:37 +00:00
|
|
|
top_job_factory.reset(new net::URLRequestInterceptingJobFactory(
|
2014-08-13 09:40:31 +00:00
|
|
|
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
|
|
|
}
|
|
|
|
|
2015-01-05 21:40:38 +00:00
|
|
|
net::HttpCache::BackendFactory*
|
|
|
|
AtomBrowserContext::CreateHttpCacheBackendFactory(
|
|
|
|
const base::FilePath& base_path) {
|
|
|
|
base::CommandLine* command_line = base::CommandLine::ForCurrentProcess();
|
|
|
|
if (command_line->HasSwitch(switches::kDisableHttpCache))
|
|
|
|
return new NoCacheBackend;
|
|
|
|
else
|
|
|
|
return brightray::BrowserContext::CreateHttpCacheBackendFactory(base_path);
|
|
|
|
}
|
|
|
|
|
2014-10-22 14:55:13 +00:00
|
|
|
content::BrowserPluginGuestManager* AtomBrowserContext::GetGuestManager() {
|
|
|
|
if (!guest_manager_)
|
|
|
|
guest_manager_.reset(new WebViewManager(this));
|
|
|
|
return guest_manager_.get();
|
|
|
|
}
|
|
|
|
|
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
|