2013-03-13 19:12:05 +00:00
|
|
|
// Copyright (c) 2012 The Chromium Authors. All rights reserved.
|
|
|
|
// Use of this source code is governed by a BSD-style license that can be
|
|
|
|
// found in the LICENSE-CHROMIUM file.
|
|
|
|
|
2013-03-13 19:42:16 +00:00
|
|
|
#ifndef BRIGHTRAY_BROWSER_BROWSER_CONTEXT_H_
|
|
|
|
#define BRIGHTRAY_BROWSER_BROWSER_CONTEXT_H_
|
2013-03-13 19:12:05 +00:00
|
|
|
|
2015-09-05 12:52:50 +00:00
|
|
|
#include <map>
|
|
|
|
|
2016-04-14 01:29:14 +00:00
|
|
|
#include "browser/net/devtools_network_controller_handle.h"
|
2015-05-22 06:50:41 +00:00
|
|
|
#include "browser/permission_manager.h"
|
2014-08-13 08:09:32 +00:00
|
|
|
#include "browser/url_request_context_getter.h"
|
|
|
|
|
2015-09-05 12:03:18 +00:00
|
|
|
#include "base/memory/ref_counted.h"
|
2015-09-05 14:34:42 +00:00
|
|
|
#include "base/memory/weak_ptr.h"
|
2013-03-13 19:12:05 +00:00
|
|
|
#include "content/public/browser/browser_context.h"
|
|
|
|
|
2013-03-29 21:28:49 +00:00
|
|
|
class PrefRegistrySimple;
|
|
|
|
class PrefService;
|
|
|
|
|
2015-10-12 13:09:39 +00:00
|
|
|
namespace storage {
|
|
|
|
class SpecialStoragePolicy;
|
|
|
|
}
|
|
|
|
|
2013-03-13 19:12:05 +00:00
|
|
|
namespace brightray {
|
|
|
|
|
2015-05-22 06:50:41 +00:00
|
|
|
class PermissionManager;
|
|
|
|
|
2015-09-05 12:03:18 +00:00
|
|
|
class BrowserContext : public base::RefCounted<BrowserContext>,
|
|
|
|
public content::BrowserContext,
|
2014-08-20 06:39:09 +00:00
|
|
|
public brightray::URLRequestContextGetter::Delegate {
|
2013-11-17 23:15:10 +00:00
|
|
|
public:
|
2015-09-05 12:52:50 +00:00
|
|
|
// Get or Create the BrowserContext according to its |partition| and |in_memory|.
|
2015-09-05 14:34:42 +00:00
|
|
|
static scoped_refptr<BrowserContext> From(
|
|
|
|
const std::string& partition, bool in_memory);
|
2013-03-13 19:12:05 +00:00
|
|
|
|
2015-09-05 12:52:50 +00:00
|
|
|
// Create a new BrowserContext, embedders should implement it on their own.
|
2015-09-05 14:34:42 +00:00
|
|
|
static scoped_refptr<BrowserContext> Create(
|
|
|
|
const std::string& partition, bool in_memory);
|
2013-08-15 20:07:14 +00:00
|
|
|
|
2015-06-26 02:58:06 +00:00
|
|
|
// content::BrowserContext:
|
|
|
|
scoped_ptr<content::ZoomLevelDelegate> CreateZoomLevelDelegate(
|
|
|
|
const base::FilePath& partition_path) override;
|
|
|
|
bool IsOffTheRecord() const override;
|
|
|
|
net::URLRequestContextGetter* GetRequestContext() override;
|
|
|
|
net::URLRequestContextGetter* GetRequestContextForRenderProcess(
|
2015-06-26 09:39:41 +00:00
|
|
|
int renderer_child_id) override;
|
2015-06-26 02:58:06 +00:00
|
|
|
net::URLRequestContextGetter* GetMediaRequestContext() override;
|
|
|
|
net::URLRequestContextGetter* GetMediaRequestContextForRenderProcess(
|
|
|
|
int renderer_child_id) override;
|
|
|
|
net::URLRequestContextGetter* GetMediaRequestContextForStoragePartition(
|
|
|
|
const base::FilePath& partition_path, bool in_memory) override;
|
|
|
|
content::ResourceContext* GetResourceContext() override;
|
|
|
|
content::DownloadManagerDelegate* GetDownloadManagerDelegate() override;
|
|
|
|
content::BrowserPluginGuestManager* GetGuestManager() override;
|
|
|
|
storage::SpecialStoragePolicy* GetSpecialStoragePolicy() override;
|
|
|
|
content::PushMessagingService* GetPushMessagingService() override;
|
|
|
|
content::SSLHostStateDelegate* GetSSLHostStateDelegate() override;
|
|
|
|
content::PermissionManager* GetPermissionManager() override;
|
2016-03-08 14:28:28 +00:00
|
|
|
content::BackgroundSyncController* GetBackgroundSyncController() override;
|
2015-06-26 02:58:06 +00:00
|
|
|
|
2013-11-17 23:15:10 +00:00
|
|
|
net::URLRequestContextGetter* CreateRequestContext(
|
2015-08-11 10:29:55 +00:00
|
|
|
NetLog* net_log,
|
2014-06-26 20:27:22 +00:00
|
|
|
content::ProtocolHandlerMap* protocol_handlers,
|
2014-08-31 10:43:01 +00:00
|
|
|
content::URLRequestInterceptorScopedVector protocol_interceptors);
|
2013-03-13 19:12:05 +00:00
|
|
|
|
2014-08-13 08:09:32 +00:00
|
|
|
net::URLRequestContextGetter* url_request_context_getter() const {
|
|
|
|
return url_request_getter_.get();
|
|
|
|
}
|
|
|
|
|
2016-04-14 01:29:14 +00:00
|
|
|
DevToolsNetworkControllerHandle* network_controller_handle() {
|
|
|
|
return &network_controller_handle_;
|
|
|
|
}
|
|
|
|
|
2015-10-06 07:19:38 +00:00
|
|
|
void InitPrefs();
|
2013-03-29 21:28:49 +00:00
|
|
|
PrefService* prefs() { return prefs_.get(); }
|
|
|
|
|
2013-11-17 23:15:10 +00:00
|
|
|
protected:
|
2015-09-05 12:52:50 +00:00
|
|
|
BrowserContext(const std::string& partition, bool in_memory);
|
|
|
|
~BrowserContext() override;
|
|
|
|
|
2013-03-29 21:28:49 +00:00
|
|
|
// Subclasses should override this to register custom preferences.
|
2013-11-17 23:15:10 +00:00
|
|
|
virtual void RegisterPrefs(PrefRegistrySimple* pref_registry) {}
|
2013-03-29 21:28:49 +00:00
|
|
|
|
2014-08-20 06:39:09 +00:00
|
|
|
// URLRequestContextGetter::Delegate:
|
2015-06-05 04:07:27 +00:00
|
|
|
net::NetworkDelegate* CreateNetworkDelegate() override;
|
2014-08-13 07:48:16 +00:00
|
|
|
|
2015-06-05 04:07:27 +00:00
|
|
|
base::FilePath GetPath() const override;
|
2013-06-06 22:50:37 +00:00
|
|
|
|
2013-11-17 23:15:10 +00:00
|
|
|
private:
|
2015-09-05 12:03:18 +00:00
|
|
|
friend class base::RefCounted<BrowserContext>;
|
2013-03-13 19:12:05 +00:00
|
|
|
class ResourceContext;
|
|
|
|
|
2013-11-17 23:15:10 +00:00
|
|
|
void RegisterInternalPrefs(PrefRegistrySimple* pref_registry);
|
2013-04-08 17:53:53 +00:00
|
|
|
|
2015-09-05 12:52:50 +00:00
|
|
|
// partition_id => browser_context
|
|
|
|
struct PartitionKey {
|
|
|
|
std::string partition;
|
|
|
|
bool in_memory;
|
|
|
|
|
|
|
|
PartitionKey(const std::string& partition, bool in_memory)
|
|
|
|
: partition(partition), in_memory(in_memory) {}
|
|
|
|
|
|
|
|
bool operator<(const PartitionKey& other) const {
|
2015-09-06 02:29:59 +00:00
|
|
|
if (partition == other.partition)
|
2015-09-05 12:52:50 +00:00
|
|
|
return in_memory < other.in_memory;
|
|
|
|
return partition < other.partition;
|
|
|
|
}
|
|
|
|
|
|
|
|
bool operator==(const PartitionKey& other) const {
|
|
|
|
return (partition == other.partition) && (in_memory == other.in_memory);
|
|
|
|
}
|
|
|
|
};
|
|
|
|
using BrowserContextMap =
|
2015-09-05 14:34:42 +00:00
|
|
|
std::map<PartitionKey, base::WeakPtr<brightray::BrowserContext>>;
|
2015-09-05 12:52:50 +00:00
|
|
|
static BrowserContextMap browser_context_map_;
|
|
|
|
|
2013-06-04 18:17:16 +00:00
|
|
|
base::FilePath path_;
|
2015-08-26 21:40:02 +00:00
|
|
|
bool in_memory_;
|
2016-04-14 01:29:14 +00:00
|
|
|
|
|
|
|
DevToolsNetworkControllerHandle network_controller_handle_;
|
|
|
|
|
2013-03-13 19:12:05 +00:00
|
|
|
scoped_ptr<ResourceContext> resource_context_;
|
2013-03-27 12:53:53 +00:00
|
|
|
scoped_refptr<URLRequestContextGetter> url_request_getter_;
|
2015-10-12 13:09:39 +00:00
|
|
|
scoped_refptr<storage::SpecialStoragePolicy> storage_policy_;
|
2013-03-29 21:28:49 +00:00
|
|
|
scoped_ptr<PrefService> prefs_;
|
2015-05-22 06:50:41 +00:00
|
|
|
scoped_ptr<PermissionManager> permission_manager_;
|
2013-03-13 19:12:05 +00:00
|
|
|
|
2015-09-05 14:34:42 +00:00
|
|
|
base::WeakPtrFactory<BrowserContext> weak_factory_;
|
|
|
|
|
2013-03-13 19:12:05 +00:00
|
|
|
DISALLOW_COPY_AND_ASSIGN(BrowserContext);
|
|
|
|
};
|
|
|
|
|
2013-11-17 23:15:10 +00:00
|
|
|
} // namespace brightray
|
2013-03-13 19:12:05 +00:00
|
|
|
|
2013-03-13 19:42:16 +00:00
|
|
|
#endif
|