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_XWALK_BROWSER_CONTEXT_H_
7 #define XWALK_RUNTIME_BROWSER_XWALK_BROWSER_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;
41 class XWalkBrowserContext
42 : public content::BrowserContext
43 #if defined(OS_ANDROID)
44 , public visitedlink::VisitedLinkDelegate
48 XWalkBrowserContext();
49 virtual ~XWalkBrowserContext();
51 // Convenience method to returns the XWalkBrowserContext corresponding to the
53 static XWalkBrowserContext* FromWebContents(
54 content::WebContents* web_contents);
56 // BrowserContext implementation.
57 virtual base::FilePath GetPath() const OVERRIDE;
58 virtual bool IsOffTheRecord() const OVERRIDE;
59 virtual content::DownloadManagerDelegate*
60 GetDownloadManagerDelegate() OVERRIDE;
61 virtual net::URLRequestContextGetter* GetRequestContext() OVERRIDE;
62 virtual net::URLRequestContextGetter* GetRequestContextForRenderProcess(
63 int renderer_child_id) OVERRIDE;
64 virtual net::URLRequestContextGetter* GetMediaRequestContext() OVERRIDE;
65 virtual net::URLRequestContextGetter* GetMediaRequestContextForRenderProcess(
66 int renderer_child_id) OVERRIDE;
67 virtual net::URLRequestContextGetter*
68 GetMediaRequestContextForStoragePartition(
69 const base::FilePath& partition_path,
70 bool in_memory) OVERRIDE;
71 virtual content::ResourceContext* GetResourceContext() OVERRIDE;
72 virtual content::BrowserPluginGuestManager*
73 GetGuestManager() OVERRIDE;
74 virtual storage::SpecialStoragePolicy* GetSpecialStoragePolicy() OVERRIDE;
75 virtual content::PushMessagingService* GetPushMessagingService() OVERRIDE;
76 virtual content::SSLHostStateDelegate* GetSSLHostStateDelegate() OVERRIDE;
78 RuntimeURLRequestContextGetter* GetURLRequestContextGetterById(
79 const std::string& pkg_id);
80 net::URLRequestContextGetter* CreateRequestContext(
81 content::ProtocolHandlerMap* protocol_handlers,
82 content::URLRequestInterceptorScopedVector request_interceptors);
83 net::URLRequestContextGetter* CreateRequestContextForStoragePartition(
84 const base::FilePath& partition_path,
86 content::ProtocolHandlerMap* protocol_handlers,
87 content::URLRequestInterceptorScopedVector request_interceptors);
88 #if defined(OS_ANDROID)
89 void SetCSPString(const std::string& csp);
90 std::string GetCSPString() const;
91 // These methods map to Add methods in visitedlink::VisitedLinkMaster.
92 void AddVisitedURLs(const std::vector<GURL>& urls);
93 // visitedlink::VisitedLinkDelegate implementation.
94 virtual void RebuildTable(
95 const scoped_refptr<URLEnumerator>& enumerator) OVERRIDE;
99 class RuntimeResourceContext;
101 // Performs initialization of the XWalkBrowserContext while IO is still
102 // allowed on the current thread.
103 void InitWhileIOAllowed();
105 #if defined(OS_ANDROID)
106 // Reset visitedlink master and initialize it.
107 void InitVisitedLinkMaster();
110 scoped_ptr<RuntimeResourceContext> resource_context_;
111 scoped_refptr<RuntimeDownloadManagerDelegate> download_manager_delegate_;
112 scoped_refptr<RuntimeURLRequestContextGetter> url_request_getter_;
113 #if defined(OS_ANDROID)
115 scoped_ptr<visitedlink::VisitedLinkMaster> visitedlink_master_;
118 typedef std::map<base::FilePath::StringType,
119 scoped_refptr<RuntimeURLRequestContextGetter> >
120 PartitionPathContextGetterMap;
121 PartitionPathContextGetterMap context_getters_;
123 DISALLOW_COPY_AND_ASSIGN(XWalkBrowserContext);
128 #endif // XWALK_RUNTIME_BROWSER_XWALK_BROWSER_CONTEXT_H_