[email protected] | 5cba3bf | 2012-01-14 02:40:35 | [diff] [blame] | 1 | // Copyright (c) 2012 The Chromium Authors. All rights reserved. |
[email protected] | b0f146f | 2011-09-15 22:14:25 | [diff] [blame] | 2 | // 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] | 037edb5 | 2011-11-15 21:14:06 | [diff] [blame] | 7 | #include "base/bind.h" |
[email protected] | 5cba3bf | 2012-01-14 02:40:35 | [diff] [blame] | 8 | #include "base/environment.h" |
[email protected] | b0f146f | 2011-09-15 22:14:25 | [diff] [blame] | 9 | #include "base/file_util.h" |
| 10 | #include "base/logging.h" |
| 11 | #include "base/path_service.h" |
[email protected] | 2e5b60a2 | 2011-11-28 15:56:41 | [diff] [blame] | 12 | #include "base/threading/thread.h" |
[email protected] | b0f146f | 2011-09-15 22:14:25 | [diff] [blame] | 13 | #include "content/browser/appcache/chrome_appcache_service.h" |
[email protected] | b0f146f | 2011-09-15 22:14:25 | [diff] [blame] | 14 | #include "content/browser/chrome_blob_storage_context.h" |
[email protected] | 2909e34 | 2011-10-29 00:46:53 | [diff] [blame] | 15 | #include "content/browser/download/download_id_factory.h" |
[email protected] | 5656f8a | 2011-11-17 16:12:58 | [diff] [blame] | 16 | #include "content/browser/download/download_manager_impl.h" |
[email protected] | b0f146f | 2011-09-15 22:14:25 | [diff] [blame] | 17 | #include "content/browser/download/download_status_updater.h" |
[email protected] | b0f146f | 2011-09-15 22:14:25 | [diff] [blame] | 18 | #include "content/browser/file_system/browser_file_system_helper.h" |
[email protected] | b0f146f | 2011-09-15 22:14:25 | [diff] [blame] | 19 | #include "content/browser/host_zoom_map.h" |
| 20 | #include "content/browser/in_process_webkit/webkit_context.h" |
[email protected] | 8238dd6 | 2011-09-29 15:13:01 | [diff] [blame] | 21 | #include "content/browser/speech/speech_input_preferences.h" |
[email protected] | c38831a1 | 2011-10-28 12:44:49 | [diff] [blame] | 22 | #include "content/browser/ssl/ssl_host_state.h" |
| 23 | #include "content/public/browser/browser_thread.h" |
[email protected] | 810ddc5 | 2012-01-24 01:00:35 | [diff] [blame^] | 24 | #include "content/public/browser/geolocation_permission_context.h" |
[email protected] | b0f146f | 2011-09-15 22:14:25 | [diff] [blame] | 25 | #include "content/shell/shell_browser_main.h" |
[email protected] | 98d6f15 | 2011-09-29 19:35:51 | [diff] [blame] | 26 | #include "content/shell/shell_download_manager_delegate.h" |
[email protected] | c5f1e33 | 2011-09-27 01:08:03 | [diff] [blame] | 27 | #include "content/shell/shell_resource_context.h" |
| 28 | #include "content/shell/shell_url_request_context_getter.h" |
[email protected] | b0f146f | 2011-09-15 22:14:25 | [diff] [blame] | 29 | #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] | 5cba3bf | 2012-01-14 02:40:35 | [diff] [blame] | 34 | #elif defined(OS_LINUX) |
| 35 | #include "base/nix/xdg_util.h" |
[email protected] | b0f146f | 2011-09-15 22:14:25 | [diff] [blame] | 36 | #endif |
| 37 | |
[email protected] | 631bb74 | 2011-11-02 11:29:39 | [diff] [blame] | 38 | using content::BrowserThread; |
| 39 | |
[email protected] | 810ddc5 | 2012-01-24 01:00:35 | [diff] [blame^] | 40 | namespace content { |
| 41 | |
[email protected] | b0f146f | 2011-09-15 22:14:25 | [diff] [blame] | 42 | namespace { |
| 43 | |
[email protected] | 5cba3bf | 2012-01-14 02:40:35 | [diff] [blame] | 44 | #if defined(OS_LINUX) |
| 45 | const char kDotConfigDir[] = ".config"; |
| 46 | const char kXdgConfigHomeEnvVar[] = "XDG_CONFIG_HOME"; |
| 47 | #endif |
| 48 | |
[email protected] | b0f146f | 2011-09-15 22:14:25 | [diff] [blame] | 49 | class 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] | 138d966c | 2011-11-30 00:49:21 | [diff] [blame] | 59 | const GURL& requesting_frame, |
| 60 | base::Callback<void(bool)> callback) OVERRIDE { |
[email protected] | b0f146f | 2011-09-15 22:14:25 | [diff] [blame] | 61 | 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] | 8238dd6 | 2011-09-29 15:13:01 | [diff] [blame] | 76 | class ShellSpeechInputPreferences : public SpeechInputPreferences { |
| 77 | public: |
| 78 | ShellSpeechInputPreferences() { |
| 79 | } |
| 80 | |
| 81 | // SpeechInputPreferences implementation. |
[email protected] | 9af487d4 | 2011-10-08 11:04:59 | [diff] [blame] | 82 | virtual bool filter_profanities() const OVERRIDE { |
[email protected] | 8238dd6 | 2011-09-29 15:13:01 | [diff] [blame] | 83 | return false; |
| 84 | } |
| 85 | |
[email protected] | 9af487d4 | 2011-10-08 11:04:59 | [diff] [blame] | 86 | virtual void set_filter_profanities(bool filter_profanities) OVERRIDE { |
[email protected] | 8238dd6 | 2011-09-29 15:13:01 | [diff] [blame] | 87 | } |
| 88 | |
| 89 | private: |
| 90 | DISALLOW_COPY_AND_ASSIGN(ShellSpeechInputPreferences); |
| 91 | }; |
| 92 | |
[email protected] | b0f146f | 2011-09-15 22:14:25 | [diff] [blame] | 93 | } // namespace |
| 94 | |
[email protected] | b0f146f | 2011-09-15 22:14:25 | [diff] [blame] | 95 | ShellBrowserContext::ShellBrowserContext( |
| 96 | ShellBrowserMainParts* shell_main_parts) |
[email protected] | 2909e34 | 2011-10-29 00:46:53 | [diff] [blame] | 97 | : download_id_factory_(new DownloadIdFactory(this)), |
| 98 | shell_main_parts_(shell_main_parts) { |
[email protected] | b0f146f | 2011-09-15 22:14:25 | [diff] [blame] | 99 | } |
| 100 | |
| 101 | ShellBrowserContext::~ShellBrowserContext() { |
[email protected] | e99ca511 | 2011-09-26 17:22:54 | [diff] [blame] | 102 | if (resource_context_.get()) { |
| 103 | BrowserThread::DeleteSoon( |
| 104 | BrowserThread::IO, FROM_HERE, resource_context_.release()); |
| 105 | } |
[email protected] | b0f146f | 2011-09-15 22:14:25 | [diff] [blame] | 106 | } |
| 107 | |
| 108 | FilePath ShellBrowserContext::GetPath() { |
[email protected] | e99ca511 | 2011-09-26 17:22:54 | [diff] [blame] | 109 | if (!path_.empty()) |
| 110 | return path_; |
[email protected] | b0f146f | 2011-09-15 22:14:25 | [diff] [blame] | 111 | |
| 112 | #if defined(OS_WIN) |
[email protected] | e99ca511 | 2011-09-26 17:22:54 | [diff] [blame] | 113 | CHECK(PathService::Get(base::DIR_LOCAL_APP_DATA, &path_)); |
| 114 | path_ = path_.Append(std::wstring(L"content_shell")); |
[email protected] | 5cba3bf | 2012-01-14 02:40:35 | [diff] [blame] | 115 | #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] | b0f146f | 2011-09-15 22:14:25 | [diff] [blame] | 121 | #else |
| 122 | NOTIMPLEMENTED(); |
| 123 | #endif |
| 124 | |
[email protected] | e99ca511 | 2011-09-26 17:22:54 | [diff] [blame] | 125 | if (!file_util::PathExists(path_)) |
| 126 | file_util::CreateDirectory(path_); |
[email protected] | b0f146f | 2011-09-15 22:14:25 | [diff] [blame] | 127 | |
[email protected] | e99ca511 | 2011-09-26 17:22:54 | [diff] [blame] | 128 | return path_; |
[email protected] | b0f146f | 2011-09-15 22:14:25 | [diff] [blame] | 129 | } |
| 130 | |
| 131 | bool ShellBrowserContext::IsOffTheRecord() { |
| 132 | return false; |
| 133 | } |
| 134 | |
| 135 | SSLHostState* ShellBrowserContext::GetSSLHostState() { |
| 136 | if (!ssl_host_state_.get()) |
| 137 | ssl_host_state_.reset(new SSLHostState()); |
| 138 | return ssl_host_state_.get(); |
| 139 | } |
| 140 | |
| 141 | DownloadManager* ShellBrowserContext::GetDownloadManager() { |
| 142 | if (!download_manager_.get()) { |
| 143 | download_status_updater_.reset(new DownloadStatusUpdater()); |
| 144 | |
[email protected] | 98d6f15 | 2011-09-29 19:35:51 | [diff] [blame] | 145 | download_manager_delegate_ = new ShellDownloadManagerDelegate(); |
[email protected] | 5656f8a | 2011-11-17 16:12:58 | [diff] [blame] | 146 | download_manager_ = new DownloadManagerImpl(download_manager_delegate_, |
| 147 | download_id_factory_, |
| 148 | download_status_updater_.get()); |
[email protected] | 98d6f15 | 2011-09-29 19:35:51 | [diff] [blame] | 149 | download_manager_delegate_->SetDownloadManager(download_manager_.get()); |
[email protected] | b0f146f | 2011-09-15 22:14:25 | [diff] [blame] | 150 | download_manager_->Init(this); |
| 151 | } |
| 152 | return download_manager_.get(); |
| 153 | } |
| 154 | |
[email protected] | b0f146f | 2011-09-15 22:14:25 | [diff] [blame] | 155 | net::URLRequestContextGetter* ShellBrowserContext::GetRequestContext() { |
| 156 | if (!url_request_getter_) { |
| 157 | url_request_getter_ = new ShellURLRequestContextGetter( |
| 158 | GetPath(), |
[email protected] | ed10dd1 | 2011-12-07 12:03:42 | [diff] [blame] | 159 | BrowserThread::UnsafeGetMessageLoopForThread(BrowserThread::IO), |
| 160 | BrowserThread::UnsafeGetMessageLoopForThread(BrowserThread::FILE)); |
[email protected] | b0f146f | 2011-09-15 22:14:25 | [diff] [blame] | 161 | } |
| 162 | return url_request_getter_; |
| 163 | } |
| 164 | |
| 165 | net::URLRequestContextGetter* |
| 166 | ShellBrowserContext::GetRequestContextForRenderProcess( |
| 167 | int renderer_child_id) { |
| 168 | return GetRequestContext(); |
| 169 | } |
| 170 | |
| 171 | net::URLRequestContextGetter* |
| 172 | ShellBrowserContext::GetRequestContextForMedia() { |
| 173 | return GetRequestContext(); |
| 174 | } |
| 175 | |
| 176 | const ResourceContext& ShellBrowserContext::GetResourceContext() { |
| 177 | if (!resource_context_.get()) { |
| 178 | resource_context_.reset(new ShellResourceContext( |
[email protected] | 26b8c69 | 2011-09-19 23:29:52 | [diff] [blame] | 179 | static_cast<ShellURLRequestContextGetter*>(GetRequestContext()), |
[email protected] | 98d6f15 | 2011-09-29 19:35:51 | [diff] [blame] | 180 | GetBlobStorageContext(), |
[email protected] | 2909e34 | 2011-10-29 00:46:53 | [diff] [blame] | 181 | download_id_factory_)); |
[email protected] | b0f146f | 2011-09-15 22:14:25 | [diff] [blame] | 182 | } |
| 183 | return *resource_context_.get(); |
| 184 | } |
| 185 | |
| 186 | HostZoomMap* ShellBrowserContext::GetHostZoomMap() { |
| 187 | if (!host_zoom_map_) |
| 188 | host_zoom_map_ = new HostZoomMap(); |
| 189 | return host_zoom_map_.get(); |
| 190 | } |
| 191 | |
| 192 | GeolocationPermissionContext* |
| 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] | 8238dd6 | 2011-09-29 15:13:01 | [diff] [blame] | 201 | SpeechInputPreferences* ShellBrowserContext::GetSpeechInputPreferences() { |
| 202 | if (!speech_input_preferences_.get()) |
| 203 | speech_input_preferences_ = new ShellSpeechInputPreferences(); |
| 204 | return speech_input_preferences_.get(); |
| 205 | } |
| 206 | |
[email protected] | b0f146f | 2011-09-15 22:14:25 | [diff] [blame] | 207 | bool ShellBrowserContext::DidLastSessionExitCleanly() { |
| 208 | return true; |
| 209 | } |
| 210 | |
| 211 | quota::QuotaManager* ShellBrowserContext::GetQuotaManager() { |
| 212 | CreateQuotaManagerAndClients(); |
| 213 | return quota_manager_.get(); |
| 214 | } |
| 215 | |
| 216 | WebKitContext* ShellBrowserContext::GetWebKitContext() { |
| 217 | CreateQuotaManagerAndClients(); |
| 218 | return webkit_context_.get(); |
| 219 | } |
| 220 | |
| 221 | webkit_database::DatabaseTracker* ShellBrowserContext::GetDatabaseTracker() { |
| 222 | CreateQuotaManagerAndClients(); |
| 223 | return db_tracker_; |
| 224 | } |
| 225 | |
| 226 | ChromeBlobStorageContext* ShellBrowserContext::GetBlobStorageContext() { |
| 227 | if (!blob_storage_context_) { |
| 228 | blob_storage_context_ = new ChromeBlobStorageContext(); |
| 229 | BrowserThread::PostTask( |
| 230 | BrowserThread::IO, FROM_HERE, |
[email protected] | 037edb5 | 2011-11-15 21:14:06 | [diff] [blame] | 231 | base::Bind( |
| 232 | &ChromeBlobStorageContext::InitializeOnIOThread, |
| 233 | blob_storage_context_.get())); |
[email protected] | b0f146f | 2011-09-15 22:14:25 | [diff] [blame] | 234 | } |
| 235 | return blob_storage_context_; |
| 236 | } |
| 237 | |
| 238 | ChromeAppCacheService* ShellBrowserContext::GetAppCacheService() { |
| 239 | CreateQuotaManagerAndClients(); |
| 240 | return appcache_service_; |
| 241 | } |
| 242 | |
| 243 | fileapi::FileSystemContext* ShellBrowserContext::GetFileSystemContext() { |
| 244 | CreateQuotaManagerAndClients(); |
| 245 | return file_system_context_.get(); |
| 246 | } |
| 247 | |
| 248 | void ShellBrowserContext::CreateQuotaManagerAndClients() { |
[email protected] | e99ca511 | 2011-09-26 17:22:54 | [diff] [blame] | 249 | if (quota_manager_.get()) |
| 250 | return; |
[email protected] | b0f146f | 2011-09-15 22:14:25 | [diff] [blame] | 251 | 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] | e1dd562 | 2011-12-20 12:28:58 | [diff] [blame] | 265 | BrowserThread::GetMessageLoopProxyForThread( |
| 266 | BrowserThread::WEBKIT_DEPRECATED)); |
[email protected] | b0f146f | 2011-09-15 22:14:25 | [diff] [blame] | 267 | 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] | 037edb5 | 2011-11-15 21:14:06 | [diff] [blame] | 271 | base::Bind( |
[email protected] | b0f146f | 2011-09-15 22:14:25 | [diff] [blame] | 272 | &ChromeAppCacheService::InitializeOnIOThread, |
[email protected] | 037edb5 | 2011-11-15 21:14:06 | [diff] [blame] | 273 | appcache_service_.get(), |
[email protected] | b0f146f | 2011-09-15 22:14:25 | [diff] [blame] | 274 | IsOffTheRecord() |
| 275 | ? FilePath() : GetPath().Append(FILE_PATH_LITERAL("AppCache")), |
| 276 | &GetResourceContext(), |
| 277 | special_storage_policy)); |
| 278 | } |
| 279 | |
| 280 | } // namespace content |