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 base::FilePath GetPath() const override;
58 bool IsOffTheRecord() const override;
59 content::DownloadManagerDelegate* GetDownloadManagerDelegate() override;
60 net::URLRequestContextGetter* GetRequestContext() override;
61 net::URLRequestContextGetter* GetRequestContextForRenderProcess(
62 int renderer_child_id) override;
63 net::URLRequestContextGetter* GetMediaRequestContext() override;
64 net::URLRequestContextGetter* GetMediaRequestContextForRenderProcess(
65 int renderer_child_id) override;
66 net::URLRequestContextGetter* GetMediaRequestContextForStoragePartition(
67 const base::FilePath& partition_path,
68 bool in_memory) override;
69 content::ResourceContext* GetResourceContext() override;
70 content::BrowserPluginGuestManager* GetGuestManager() override;
71 storage::SpecialStoragePolicy* GetSpecialStoragePolicy() override;
72 content::PushMessagingService* GetPushMessagingService() override;
73 content::SSLHostStateDelegate* GetSSLHostStateDelegate() override;
75 RuntimeURLRequestContextGetter* GetURLRequestContextGetterById(
76 const std::string& pkg_id);
77 net::URLRequestContextGetter* CreateRequestContext(
78 content::ProtocolHandlerMap* protocol_handlers,
79 content::URLRequestInterceptorScopedVector request_interceptors);
80 net::URLRequestContextGetter* CreateRequestContextForStoragePartition(
81 const base::FilePath& partition_path,
83 content::ProtocolHandlerMap* protocol_handlers,
84 content::URLRequestInterceptorScopedVector request_interceptors);
85 #if defined(OS_ANDROID)
86 void SetCSPString(const std::string& csp);
87 std::string GetCSPString() const;
88 // These methods map to Add methods in visitedlink::VisitedLinkMaster.
89 void AddVisitedURLs(const std::vector<GURL>& urls);
90 // visitedlink::VisitedLinkDelegate implementation.
92 const scoped_refptr<URLEnumerator>& enumerator) override;
96 class RuntimeResourceContext;
98 // Performs initialization of the XWalkBrowserContext while IO is still
99 // allowed on the current thread.
100 void InitWhileIOAllowed();
102 #if defined(OS_ANDROID)
103 // Reset visitedlink master and initialize it.
104 void InitVisitedLinkMaster();
107 scoped_ptr<RuntimeResourceContext> resource_context_;
108 scoped_refptr<RuntimeDownloadManagerDelegate> download_manager_delegate_;
109 scoped_refptr<RuntimeURLRequestContextGetter> url_request_getter_;
110 #if defined(OS_ANDROID)
112 scoped_ptr<visitedlink::VisitedLinkMaster> visitedlink_master_;
115 typedef std::map<base::FilePath::StringType,
116 scoped_refptr<RuntimeURLRequestContextGetter> >
117 PartitionPathContextGetterMap;
118 PartitionPathContextGetterMap context_getters_;
120 DISALLOW_COPY_AND_ASSIGN(XWalkBrowserContext);
125 #endif // XWALK_RUNTIME_BROWSER_XWALK_BROWSER_CONTEXT_H_