2013-04-15 16:25:08 +00:00
|
|
|
// Copyright (c) 2013 GitHub, Inc. All rights reserved.
|
|
|
|
// Use of this source code is governed by a BSD-style license that can be
|
|
|
|
// found in the LICENSE file.
|
|
|
|
|
|
|
|
#include "browser/atom_browser_context.h"
|
|
|
|
|
2013-04-22 13:32:48 +00:00
|
|
|
#include "browser/atom_browser_main_parts.h"
|
2013-09-20 08:47:47 +00:00
|
|
|
#include "browser/net/atom_url_request_context_getter.h"
|
|
|
|
#include "content/public/browser/browser_thread.h"
|
|
|
|
#include "content/public/browser/resource_context.h"
|
|
|
|
#include "vendor/brightray/browser/network_delegate.h"
|
2013-04-20 13:52:46 +00:00
|
|
|
|
2013-04-15 16:25:08 +00:00
|
|
|
namespace atom {
|
|
|
|
|
2013-09-20 08:47:47 +00:00
|
|
|
using content::BrowserThread;
|
|
|
|
|
|
|
|
class AtomResourceContext : public content::ResourceContext {
|
|
|
|
public:
|
|
|
|
AtomResourceContext() : getter_(NULL) {}
|
|
|
|
|
|
|
|
void set_url_request_context_getter(AtomURLRequestContextGetter* getter) {
|
|
|
|
getter_ = getter;
|
|
|
|
}
|
|
|
|
|
|
|
|
protected:
|
|
|
|
virtual net::HostResolver* GetHostResolver() OVERRIDE {
|
|
|
|
DCHECK(getter_);
|
|
|
|
return getter_->host_resolver();
|
|
|
|
}
|
|
|
|
|
|
|
|
virtual net::URLRequestContext* GetRequestContext() OVERRIDE {
|
|
|
|
DCHECK(getter_);
|
|
|
|
return getter_->GetURLRequestContext();
|
|
|
|
}
|
|
|
|
|
2013-12-11 07:48:19 +00:00
|
|
|
virtual bool AllowMicAccess(const GURL& origin) OVERRIDE {
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
virtual bool AllowCameraAccess(const GURL& origin) OVERRIDE {
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2013-09-20 08:47:47 +00:00
|
|
|
private:
|
|
|
|
AtomURLRequestContextGetter* getter_;
|
|
|
|
|
|
|
|
DISALLOW_COPY_AND_ASSIGN(AtomResourceContext);
|
|
|
|
};
|
|
|
|
|
|
|
|
AtomBrowserContext::AtomBrowserContext()
|
|
|
|
: resource_context_(new AtomResourceContext) {
|
2013-04-15 16:25:08 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
AtomBrowserContext::~AtomBrowserContext() {
|
|
|
|
}
|
|
|
|
|
2013-09-20 08:47:47 +00:00
|
|
|
AtomURLRequestContextGetter* AtomBrowserContext::CreateRequestContext(
|
|
|
|
content::ProtocolHandlerMap* protocol_handlers) {
|
|
|
|
DCHECK(!url_request_getter_);
|
|
|
|
url_request_getter_ = new AtomURLRequestContextGetter(
|
|
|
|
GetPath(),
|
|
|
|
BrowserThread::UnsafeGetMessageLoopForThread(BrowserThread::IO),
|
|
|
|
BrowserThread::UnsafeGetMessageLoopForThread(BrowserThread::FILE),
|
2014-02-05 03:18:32 +00:00
|
|
|
base::Bind(&AtomBrowserContext::CreateNetworkDelegate,
|
|
|
|
base::Unretained(this)),
|
2013-09-20 08:47:47 +00:00
|
|
|
protocol_handlers);
|
|
|
|
|
|
|
|
resource_context_->set_url_request_context_getter(url_request_getter_.get());
|
|
|
|
return url_request_getter_.get();
|
|
|
|
}
|
|
|
|
|
|
|
|
content::ResourceContext* AtomBrowserContext::GetResourceContext() {
|
|
|
|
return resource_context_.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
|