blob: 2590ee8806b0842ae293cf5a38fca3aab29907d3 [file] [log] [blame]
[email protected]5cba3bf2012-01-14 02:40:351// Copyright (c) 2012 The Chromium Authors. All rights reserved.
[email protected]b0f146f2011-09-15 22:14:252// Use of this source code is governed by a BSD-style license that can be
3// found in the LICENSE file.
4
5#include "content/shell/shell_browser_context.h"
6
[email protected]037edb52011-11-15 21:14:067#include "base/bind.h"
[email protected]5cba3bf2012-01-14 02:40:358#include "base/environment.h"
[email protected]b0f146f2011-09-15 22:14:259#include "base/file_util.h"
10#include "base/logging.h"
11#include "base/path_service.h"
[email protected]2e5b60a22011-11-28 15:56:4112#include "base/threading/thread.h"
[email protected]b0f146f2011-09-15 22:14:2513#include "content/browser/appcache/chrome_appcache_service.h"
[email protected]b0f146f2011-09-15 22:14:2514#include "content/browser/chrome_blob_storage_context.h"
[email protected]2909e342011-10-29 00:46:5315#include "content/browser/download/download_id_factory.h"
[email protected]5656f8a2011-11-17 16:12:5816#include "content/browser/download/download_manager_impl.h"
[email protected]b0f146f2011-09-15 22:14:2517#include "content/browser/download/download_status_updater.h"
[email protected]b0f146f2011-09-15 22:14:2518#include "content/browser/file_system/browser_file_system_helper.h"
[email protected]b0f146f2011-09-15 22:14:2519#include "content/browser/host_zoom_map.h"
20#include "content/browser/in_process_webkit/webkit_context.h"
[email protected]8238dd62011-09-29 15:13:0121#include "content/browser/speech/speech_input_preferences.h"
[email protected]c38831a12011-10-28 12:44:4922#include "content/browser/ssl/ssl_host_state.h"
23#include "content/public/browser/browser_thread.h"
[email protected]810ddc52012-01-24 01:00:3524#include "content/public/browser/geolocation_permission_context.h"
[email protected]b0f146f2011-09-15 22:14:2525#include "content/shell/shell_browser_main.h"
[email protected]98d6f152011-09-29 19:35:5126#include "content/shell/shell_download_manager_delegate.h"
[email protected]c5f1e332011-09-27 01:08:0327#include "content/shell/shell_resource_context.h"
28#include "content/shell/shell_url_request_context_getter.h"
[email protected]b0f146f2011-09-15 22:14:2529#include "webkit/database/database_tracker.h"
30#include "webkit/quota/quota_manager.h"
31
32#if defined(OS_WIN)
33#include "base/base_paths_win.h"
[email protected]5cba3bf2012-01-14 02:40:3534#elif defined(OS_LINUX)
35#include "base/nix/xdg_util.h"
[email protected]b0f146f2011-09-15 22:14:2536#endif
37
[email protected]631bb742011-11-02 11:29:3938using content::BrowserThread;
39
[email protected]810ddc52012-01-24 01:00:3540namespace content {
41
[email protected]b0f146f2011-09-15 22:14:2542namespace {
43
[email protected]5cba3bf2012-01-14 02:40:3544#if defined(OS_LINUX)
45const char kDotConfigDir[] = ".config";
46const char kXdgConfigHomeEnvVar[] = "XDG_CONFIG_HOME";
47#endif
48
[email protected]b0f146f2011-09-15 22:14:2549class ShellGeolocationPermissionContext : public GeolocationPermissionContext {
50 public:
51 ShellGeolocationPermissionContext() {
52 }
53
54 // GeolocationPermissionContext implementation).
55 virtual void RequestGeolocationPermission(
56 int render_process_id,
57 int render_view_id,
58 int bridge_id,
[email protected]138d966c2011-11-30 00:49:2159 const GURL& requesting_frame,
60 base::Callback<void(bool)> callback) OVERRIDE {
[email protected]b0f146f2011-09-15 22:14:2561 NOTIMPLEMENTED();
62 }
63
64 virtual void CancelGeolocationPermissionRequest(
65 int render_process_id,
66 int render_view_id,
67 int bridge_id,
68 const GURL& requesting_frame) OVERRIDE {
69 NOTIMPLEMENTED();
70 }
71
72 private:
73 DISALLOW_COPY_AND_ASSIGN(ShellGeolocationPermissionContext);
74};
75
[email protected]8238dd62011-09-29 15:13:0176class ShellSpeechInputPreferences : public SpeechInputPreferences {
77 public:
78 ShellSpeechInputPreferences() {
79 }
80
81 // SpeechInputPreferences implementation.
[email protected]9af487d42011-10-08 11:04:5982 virtual bool filter_profanities() const OVERRIDE {
[email protected]8238dd62011-09-29 15:13:0183 return false;
84 }
85
[email protected]9af487d42011-10-08 11:04:5986 virtual void set_filter_profanities(bool filter_profanities) OVERRIDE {
[email protected]8238dd62011-09-29 15:13:0187 }
88
89 private:
90 DISALLOW_COPY_AND_ASSIGN(ShellSpeechInputPreferences);
91};
92
[email protected]b0f146f2011-09-15 22:14:2593} // namespace
94
[email protected]b0f146f2011-09-15 22:14:2595ShellBrowserContext::ShellBrowserContext(
96 ShellBrowserMainParts* shell_main_parts)
[email protected]2909e342011-10-29 00:46:5397 : download_id_factory_(new DownloadIdFactory(this)),
98 shell_main_parts_(shell_main_parts) {
[email protected]b0f146f2011-09-15 22:14:2599}
100
101ShellBrowserContext::~ShellBrowserContext() {
[email protected]e99ca5112011-09-26 17:22:54102 if (resource_context_.get()) {
103 BrowserThread::DeleteSoon(
104 BrowserThread::IO, FROM_HERE, resource_context_.release());
105 }
[email protected]b0f146f2011-09-15 22:14:25106}
107
108FilePath ShellBrowserContext::GetPath() {
[email protected]e99ca5112011-09-26 17:22:54109 if (!path_.empty())
110 return path_;
[email protected]b0f146f2011-09-15 22:14:25111
112#if defined(OS_WIN)
[email protected]e99ca5112011-09-26 17:22:54113 CHECK(PathService::Get(base::DIR_LOCAL_APP_DATA, &path_));
114 path_ = path_.Append(std::wstring(L"content_shell"));
[email protected]5cba3bf2012-01-14 02:40:35115#elif defined(OS_LINUX)
116 scoped_ptr<base::Environment> env(base::Environment::Create());
117 FilePath config_dir(base::nix::GetXDGDirectory(env.get(),
118 kXdgConfigHomeEnvVar,
119 kDotConfigDir));
120 path_ = config_dir.Append("content_shell");
[email protected]b0f146f2011-09-15 22:14:25121#else
122 NOTIMPLEMENTED();
123#endif
124
[email protected]e99ca5112011-09-26 17:22:54125 if (!file_util::PathExists(path_))
126 file_util::CreateDirectory(path_);
[email protected]b0f146f2011-09-15 22:14:25127
[email protected]e99ca5112011-09-26 17:22:54128 return path_;
[email protected]b0f146f2011-09-15 22:14:25129}
130
131bool ShellBrowserContext::IsOffTheRecord() {
132 return false;
133}
134
135SSLHostState* ShellBrowserContext::GetSSLHostState() {
136 if (!ssl_host_state_.get())
137 ssl_host_state_.reset(new SSLHostState());
138 return ssl_host_state_.get();
139}
140
141DownloadManager* ShellBrowserContext::GetDownloadManager() {
142 if (!download_manager_.get()) {
143 download_status_updater_.reset(new DownloadStatusUpdater());
144
[email protected]98d6f152011-09-29 19:35:51145 download_manager_delegate_ = new ShellDownloadManagerDelegate();
[email protected]5656f8a2011-11-17 16:12:58146 download_manager_ = new DownloadManagerImpl(download_manager_delegate_,
147 download_id_factory_,
148 download_status_updater_.get());
[email protected]98d6f152011-09-29 19:35:51149 download_manager_delegate_->SetDownloadManager(download_manager_.get());
[email protected]b0f146f2011-09-15 22:14:25150 download_manager_->Init(this);
151 }
152 return download_manager_.get();
153}
154
[email protected]b0f146f2011-09-15 22:14:25155net::URLRequestContextGetter* ShellBrowserContext::GetRequestContext() {
156 if (!url_request_getter_) {
157 url_request_getter_ = new ShellURLRequestContextGetter(
158 GetPath(),
[email protected]ed10dd12011-12-07 12:03:42159 BrowserThread::UnsafeGetMessageLoopForThread(BrowserThread::IO),
160 BrowserThread::UnsafeGetMessageLoopForThread(BrowserThread::FILE));
[email protected]b0f146f2011-09-15 22:14:25161 }
162 return url_request_getter_;
163}
164
165net::URLRequestContextGetter*
166 ShellBrowserContext::GetRequestContextForRenderProcess(
167 int renderer_child_id) {
168 return GetRequestContext();
169}
170
171net::URLRequestContextGetter*
172 ShellBrowserContext::GetRequestContextForMedia() {
173 return GetRequestContext();
174}
175
176const ResourceContext& ShellBrowserContext::GetResourceContext() {
177 if (!resource_context_.get()) {
178 resource_context_.reset(new ShellResourceContext(
[email protected]26b8c692011-09-19 23:29:52179 static_cast<ShellURLRequestContextGetter*>(GetRequestContext()),
[email protected]98d6f152011-09-29 19:35:51180 GetBlobStorageContext(),
[email protected]2909e342011-10-29 00:46:53181 download_id_factory_));
[email protected]b0f146f2011-09-15 22:14:25182 }
183 return *resource_context_.get();
184}
185
186HostZoomMap* ShellBrowserContext::GetHostZoomMap() {
187 if (!host_zoom_map_)
188 host_zoom_map_ = new HostZoomMap();
189 return host_zoom_map_.get();
190}
191
192GeolocationPermissionContext*
193 ShellBrowserContext::GetGeolocationPermissionContext() {
194 if (!geolocation_permission_context_) {
195 geolocation_permission_context_ =
196 new ShellGeolocationPermissionContext();
197 }
198 return geolocation_permission_context_;
199}
200
[email protected]8238dd62011-09-29 15:13:01201SpeechInputPreferences* ShellBrowserContext::GetSpeechInputPreferences() {
202 if (!speech_input_preferences_.get())
203 speech_input_preferences_ = new ShellSpeechInputPreferences();
204 return speech_input_preferences_.get();
205}
206
[email protected]b0f146f2011-09-15 22:14:25207bool ShellBrowserContext::DidLastSessionExitCleanly() {
208 return true;
209}
210
211quota::QuotaManager* ShellBrowserContext::GetQuotaManager() {
212 CreateQuotaManagerAndClients();
213 return quota_manager_.get();
214}
215
216WebKitContext* ShellBrowserContext::GetWebKitContext() {
217 CreateQuotaManagerAndClients();
218 return webkit_context_.get();
219}
220
221webkit_database::DatabaseTracker* ShellBrowserContext::GetDatabaseTracker() {
222 CreateQuotaManagerAndClients();
223 return db_tracker_;
224}
225
226ChromeBlobStorageContext* ShellBrowserContext::GetBlobStorageContext() {
227 if (!blob_storage_context_) {
228 blob_storage_context_ = new ChromeBlobStorageContext();
229 BrowserThread::PostTask(
230 BrowserThread::IO, FROM_HERE,
[email protected]037edb52011-11-15 21:14:06231 base::Bind(
232 &ChromeBlobStorageContext::InitializeOnIOThread,
233 blob_storage_context_.get()));
[email protected]b0f146f2011-09-15 22:14:25234 }
235 return blob_storage_context_;
236}
237
238ChromeAppCacheService* ShellBrowserContext::GetAppCacheService() {
239 CreateQuotaManagerAndClients();
240 return appcache_service_;
241}
242
243fileapi::FileSystemContext* ShellBrowserContext::GetFileSystemContext() {
244 CreateQuotaManagerAndClients();
245 return file_system_context_.get();
246}
247
248void ShellBrowserContext::CreateQuotaManagerAndClients() {
[email protected]e99ca5112011-09-26 17:22:54249 if (quota_manager_.get())
250 return;
[email protected]b0f146f2011-09-15 22:14:25251 quota_manager_ = new quota::QuotaManager(
252 IsOffTheRecord(),
253 GetPath(),
254 BrowserThread::GetMessageLoopProxyForThread(BrowserThread::IO),
255 BrowserThread::GetMessageLoopProxyForThread(BrowserThread::DB),
256 NULL);
257
258 file_system_context_ = CreateFileSystemContext(
259 GetPath(), IsOffTheRecord(), NULL, quota_manager_->proxy());
260 db_tracker_ = new webkit_database::DatabaseTracker(
261 GetPath(), IsOffTheRecord(), false, NULL, quota_manager_->proxy(),
262 BrowserThread::GetMessageLoopProxyForThread(BrowserThread::FILE));
263 webkit_context_ = new WebKitContext(
264 IsOffTheRecord(), GetPath(), NULL, false, quota_manager_->proxy(),
[email protected]e1dd5622011-12-20 12:28:58265 BrowserThread::GetMessageLoopProxyForThread(
266 BrowserThread::WEBKIT_DEPRECATED));
[email protected]b0f146f2011-09-15 22:14:25267 appcache_service_ = new ChromeAppCacheService(quota_manager_->proxy());
268 scoped_refptr<quota::SpecialStoragePolicy> special_storage_policy;
269 BrowserThread::PostTask(
270 BrowserThread::IO, FROM_HERE,
[email protected]037edb52011-11-15 21:14:06271 base::Bind(
[email protected]b0f146f2011-09-15 22:14:25272 &ChromeAppCacheService::InitializeOnIOThread,
[email protected]037edb52011-11-15 21:14:06273 appcache_service_.get(),
[email protected]b0f146f2011-09-15 22:14:25274 IsOffTheRecord()
275 ? FilePath() : GetPath().Append(FILE_PATH_LITERAL("AppCache")),
276 &GetResourceContext(),
277 special_storage_policy));
278}
279
280} // namespace content