1 // Copyright (c) 2013 Intel Corporation. All rights reserved.
2 // Copyright (c) 2014 Samsung Electronics Co., Ltd All Rights Reserved
3 // Use of this source code is governed by a BSD-style license that can be
4 // found in the LICENSE file.
6 #ifndef XWALK_RUNTIME_BROWSER_RUNTIME_CONTEXT_H_
7 #define XWALK_RUNTIME_BROWSER_RUNTIME_CONTEXT_H_
9 #if defined(OS_ANDROID)
16 #include "base/compiler_specific.h"
17 #include "base/files/file_path.h"
18 #include "base/memory/ref_counted.h"
19 #include "base/memory/scoped_ptr.h"
20 #include "components/visitedlink/browser/visitedlink_delegate.h"
21 #include "content/public/browser/browser_context.h"
22 #include "content/public/browser/content_browser_client.h"
25 class URLRequestContextGetter;
29 class DownloadManagerDelegate;
32 namespace visitedlink {
33 class VisitedLinkMaster;
38 class RuntimeDownloadManagerDelegate;
39 class RuntimeURLRequestContextGetter;
42 : public content::BrowserContext
43 #if defined(OS_ANDROID)
44 , public visitedlink::VisitedLinkDelegate
49 virtual ~RuntimeContext();
51 // Convenience method to returns the RuntimeContext corresponding to the
53 static RuntimeContext* FromWebContents(content::WebContents* web_contents);
55 // BrowserContext implementation.
56 virtual base::FilePath GetPath() const OVERRIDE;
57 virtual bool IsOffTheRecord() const OVERRIDE;
58 virtual content::DownloadManagerDelegate*
59 GetDownloadManagerDelegate() OVERRIDE;
60 virtual net::URLRequestContextGetter* GetRequestContext() OVERRIDE;
61 virtual net::URLRequestContextGetter* GetRequestContextForRenderProcess(
62 int renderer_child_id) OVERRIDE;
63 virtual net::URLRequestContextGetter* GetMediaRequestContext() OVERRIDE;
64 virtual net::URLRequestContextGetter* GetMediaRequestContextForRenderProcess(
65 int renderer_child_id) OVERRIDE;
66 virtual net::URLRequestContextGetter*
67 GetMediaRequestContextForStoragePartition(
68 const base::FilePath& partition_path,
69 bool in_memory) OVERRIDE;
70 virtual content::ResourceContext* GetResourceContext() OVERRIDE;
71 virtual content::BrowserPluginGuestManager*
72 GetGuestManager() OVERRIDE;
73 virtual quota::SpecialStoragePolicy* GetSpecialStoragePolicy() OVERRIDE;
74 virtual content::PushMessagingService* GetPushMessagingService() OVERRIDE;
75 virtual content::SSLHostStateDelegate* GetSSLHostStateDelegate() OVERRIDE;
77 RuntimeURLRequestContextGetter* GetURLRequestContextGetterById(
78 const std::string& pkg_id);
79 net::URLRequestContextGetter* CreateRequestContext(
80 content::ProtocolHandlerMap* protocol_handlers,
81 content::URLRequestInterceptorScopedVector request_interceptors);
82 net::URLRequestContextGetter* CreateRequestContextForStoragePartition(
83 const base::FilePath& partition_path,
85 content::ProtocolHandlerMap* protocol_handlers,
86 content::URLRequestInterceptorScopedVector request_interceptors);
87 #if defined(OS_ANDROID)
88 void SetCSPString(const std::string& csp);
89 std::string GetCSPString() const;
90 // These methods map to Add methods in visitedlink::VisitedLinkMaster.
91 void AddVisitedURLs(const std::vector<GURL>& urls);
92 // visitedlink::VisitedLinkDelegate implementation.
93 virtual void RebuildTable(
94 const scoped_refptr<URLEnumerator>& enumerator) OVERRIDE;
98 class RuntimeResourceContext;
100 // Performs initialization of the RuntimeContext while IO is still
101 // allowed on the current thread.
102 void InitWhileIOAllowed();
104 #if defined(OS_ANDROID)
105 // Reset visitedlink master and initialize it.
106 void InitVisitedLinkMaster();
109 scoped_ptr<RuntimeResourceContext> resource_context_;
110 scoped_refptr<RuntimeDownloadManagerDelegate> download_manager_delegate_;
111 scoped_refptr<RuntimeURLRequestContextGetter> url_request_getter_;
112 #if defined(OS_ANDROID)
114 scoped_ptr<visitedlink::VisitedLinkMaster> visitedlink_master_;
117 typedef std::map<base::FilePath::StringType,
118 scoped_refptr<RuntimeURLRequestContextGetter> >
119 PartitionPathContextGetterMap;
120 PartitionPathContextGetterMap context_getters_;
122 DISALLOW_COPY_AND_ASSIGN(RuntimeContext);
127 #endif // XWALK_RUNTIME_BROWSER_RUNTIME_CONTEXT_H_