1 // Copyright 2014 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file.
5 #include "chromecast/shell/browser/cast_browser_context.h"
7 #include "base/command_line.h"
8 #include "base/macros.h"
9 #include "base/path_service.h"
10 #include "chromecast/common/cast_paths.h"
11 #include "chromecast/shell/browser/url_request_context_factory.h"
12 #include "content/public/browser/browser_thread.h"
13 #include "content/public/browser/resource_context.h"
14 #include "content/public/browser/storage_partition.h"
15 #include "content/public/common/content_switches.h"
16 #include "net/url_request/url_request_context.h"
17 #include "net/url_request/url_request_context_getter.h"
19 namespace chromecast
{
22 class CastBrowserContext::CastResourceContext
:
23 public content::ResourceContext
{
25 CastResourceContext(URLRequestContextFactory
* url_request_context_factory
) :
26 url_request_context_factory_(url_request_context_factory
) {}
27 virtual ~CastResourceContext() {}
29 // ResourceContext implementation:
30 virtual net::HostResolver
* GetHostResolver() OVERRIDE
{
31 return url_request_context_factory_
->GetMainGetter()->
32 GetURLRequestContext()->host_resolver();
35 virtual net::URLRequestContext
* GetRequestContext() OVERRIDE
{
36 return url_request_context_factory_
->GetMainGetter()->
37 GetURLRequestContext();
40 virtual bool AllowMicAccess(const GURL
& origin
) OVERRIDE
{
44 virtual bool AllowCameraAccess(const GURL
& origin
) OVERRIDE
{
49 URLRequestContextFactory
* url_request_context_factory_
;
51 DISALLOW_COPY_AND_ASSIGN(CastResourceContext
);
54 CastBrowserContext::CastBrowserContext(
55 URLRequestContextFactory
* url_request_context_factory
)
56 : url_request_context_factory_(url_request_context_factory
),
57 resource_context_(new CastResourceContext(url_request_context_factory
)) {
61 CastBrowserContext::~CastBrowserContext() {
64 void CastBrowserContext::InitWhileIOAllowed() {
65 // Chromecast doesn't support user profiles nor does it have
66 // incognito mode. This means that all of the persistent
67 // data (currently only cookies and local storage) will be
68 // shared in a single location as defined here.
69 CHECK(PathService::Get(DIR_CAST_HOME
, &path_
));
72 base::FilePath
CastBrowserContext::GetPath() const {
76 bool CastBrowserContext::IsOffTheRecord() const {
80 net::URLRequestContextGetter
* CastBrowserContext::GetRequestContext() {
81 return GetDefaultStoragePartition(this)->GetURLRequestContext();
84 net::URLRequestContextGetter
*
85 CastBrowserContext::GetRequestContextForRenderProcess(int renderer_child_id
) {
86 return GetRequestContext();
89 net::URLRequestContextGetter
* CastBrowserContext::GetMediaRequestContext() {
90 return url_request_context_factory_
->GetMediaGetter();
93 net::URLRequestContextGetter
*
94 CastBrowserContext::GetMediaRequestContextForRenderProcess(
95 int renderer_child_id
) {
96 return GetMediaRequestContext();
99 net::URLRequestContextGetter
*
100 CastBrowserContext::GetMediaRequestContextForStoragePartition(
101 const base::FilePath
& partition_path
, bool in_memory
) {
102 return GetMediaRequestContext();
105 content::ResourceContext
* CastBrowserContext::GetResourceContext() {
106 return resource_context_
.get();
109 content::DownloadManagerDelegate
*
110 CastBrowserContext::GetDownloadManagerDelegate() {
115 content::BrowserPluginGuestManager
* CastBrowserContext::GetGuestManager() {
120 storage::SpecialStoragePolicy
* CastBrowserContext::GetSpecialStoragePolicy() {
125 content::PushMessagingService
* CastBrowserContext::GetPushMessagingService() {
130 content::SSLHostStateDelegate
* CastBrowserContext::GetSSLHostStateDelegate() {
136 } // namespace chromecast