[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] | 2f2b951 | 2012-06-08 17:31:00 | [diff] [blame] | 8 | #include "base/command_line.h" |
[email protected] | 5cba3bf | 2012-01-14 02:40:35 | [diff] [blame] | 9 | #include "base/environment.h" |
[email protected] | b0f146f | 2011-09-15 22:14:25 | [diff] [blame] | 10 | #include "base/file_util.h" |
| 11 | #include "base/logging.h" |
| 12 | #include "base/path_service.h" |
[email protected] | 2e5b60a2 | 2011-11-28 15:56:41 | [diff] [blame] | 13 | #include "base/threading/thread.h" |
[email protected] | c38831a1 | 2011-10-28 12:44:49 | [diff] [blame] | 14 | #include "content/public/browser/browser_thread.h" |
[email protected] | 98d6f15 | 2011-09-29 19:35:51 | [diff] [blame] | 15 | #include "content/shell/shell_download_manager_delegate.h" |
[email protected] | c5f1e33 | 2011-09-27 01:08:03 | [diff] [blame] | 16 | #include "content/shell/shell_resource_context.h" |
[email protected] | 2f2b951 | 2012-06-08 17:31:00 | [diff] [blame] | 17 | #include "content/shell/shell_switches.h" |
[email protected] | c5f1e33 | 2011-09-27 01:08:03 | [diff] [blame] | 18 | #include "content/shell/shell_url_request_context_getter.h" |
[email protected] | c280aeb4 | 2012-10-17 19:45:42 | [diff] [blame] | 19 | #include "content/public/common/content_switches.h" |
[email protected] | b0f146f | 2011-09-15 22:14:25 | [diff] [blame] | 20 | |
| 21 | #if defined(OS_WIN) |
| 22 | #include "base/base_paths_win.h" |
[email protected] | 5cba3bf | 2012-01-14 02:40:35 | [diff] [blame] | 23 | #elif defined(OS_LINUX) |
| 24 | #include "base/nix/xdg_util.h" |
[email protected] | 80ec0b7 | 2012-03-22 22:45:27 | [diff] [blame] | 25 | #elif defined(OS_MACOSX) |
| 26 | #include "base/base_paths_mac.h" |
[email protected] | b0f146f | 2011-09-15 22:14:25 | [diff] [blame] | 27 | #endif |
| 28 | |
[email protected] | 810ddc5 | 2012-01-24 01:00:35 | [diff] [blame] | 29 | namespace content { |
| 30 | |
[email protected] | 71d504f | 2012-07-25 17:15:28 | [diff] [blame] | 31 | ShellBrowserContext::ShellBrowserContext(bool off_the_record) |
[email protected] | c2dad29 | 2012-09-07 21:27:35 | [diff] [blame] | 32 | : off_the_record_(off_the_record), |
| 33 | ignore_certificate_errors_(false) { |
[email protected] | 11a65b69 | 2012-03-30 11:29:16 | [diff] [blame] | 34 | InitWhileIOAllowed(); |
[email protected] | b0f146f | 2011-09-15 22:14:25 | [diff] [blame] | 35 | } |
| 36 | |
| 37 | ShellBrowserContext::~ShellBrowserContext() { |
[email protected] | e99ca511 | 2011-09-26 17:22:54 | [diff] [blame] | 38 | if (resource_context_.get()) { |
| 39 | BrowserThread::DeleteSoon( |
| 40 | BrowserThread::IO, FROM_HERE, resource_context_.release()); |
| 41 | } |
[email protected] | b0f146f | 2011-09-15 22:14:25 | [diff] [blame] | 42 | } |
| 43 | |
[email protected] | 11a65b69 | 2012-03-30 11:29:16 | [diff] [blame] | 44 | void ShellBrowserContext::InitWhileIOAllowed() { |
[email protected] | aae3406 | 2012-07-19 15:52:15 | [diff] [blame] | 45 | CommandLine* cmd_line = CommandLine::ForCurrentProcess(); |
[email protected] | d22dc09 | 2012-11-19 20:35:56 | [diff] [blame] | 46 | if (cmd_line->HasSwitch(switches::kIgnoreCertificateErrors) || |
| 47 | cmd_line->HasSwitch(switches::kDumpRenderTree)) { |
[email protected] | c2dad29 | 2012-09-07 21:27:35 | [diff] [blame] | 48 | ignore_certificate_errors_ = true; |
[email protected] | d22dc09 | 2012-11-19 20:35:56 | [diff] [blame] | 49 | } |
[email protected] | e1cf85a2 | 2012-08-17 22:39:23 | [diff] [blame] | 50 | if (cmd_line->HasSwitch(switches::kContentShellDataPath)) { |
| 51 | path_ = cmd_line->GetSwitchValuePath(switches::kContentShellDataPath); |
| 52 | return; |
| 53 | } |
[email protected] | b0f146f | 2011-09-15 22:14:25 | [diff] [blame] | 54 | #if defined(OS_WIN) |
[email protected] | e99ca511 | 2011-09-26 17:22:54 | [diff] [blame] | 55 | CHECK(PathService::Get(base::DIR_LOCAL_APP_DATA, &path_)); |
| 56 | path_ = path_.Append(std::wstring(L"content_shell")); |
[email protected] | 5cba3bf | 2012-01-14 02:40:35 | [diff] [blame] | 57 | #elif defined(OS_LINUX) |
| 58 | scoped_ptr<base::Environment> env(base::Environment::Create()); |
[email protected] | 9528c9a | 2012-06-13 23:20:22 | [diff] [blame] | 59 | FilePath config_dir( |
| 60 | base::nix::GetXDGDirectory(env.get(), |
| 61 | base::nix::kXdgConfigHomeEnvVar, |
| 62 | base::nix::kDotConfigDir)); |
[email protected] | 5cba3bf | 2012-01-14 02:40:35 | [diff] [blame] | 63 | path_ = config_dir.Append("content_shell"); |
[email protected] | 80ec0b7 | 2012-03-22 22:45:27 | [diff] [blame] | 64 | #elif defined(OS_MACOSX) |
| 65 | CHECK(PathService::Get(base::DIR_APP_DATA, &path_)); |
| 66 | path_ = path_.Append("Chromium Content Shell"); |
[email protected] | 70a7f119 | 2012-06-08 01:31:34 | [diff] [blame] | 67 | #elif defined(OS_ANDROID) |
| 68 | DCHECK(PathService::Get(base::DIR_ANDROID_APP_DATA, &path_)); |
| 69 | path_ = path_.Append(FILE_PATH_LITERAL("content_shell")); |
[email protected] | b0f146f | 2011-09-15 22:14:25 | [diff] [blame] | 70 | #else |
| 71 | NOTIMPLEMENTED(); |
| 72 | #endif |
| 73 | |
[email protected] | e99ca511 | 2011-09-26 17:22:54 | [diff] [blame] | 74 | if (!file_util::PathExists(path_)) |
| 75 | file_util::CreateDirectory(path_); |
[email protected] | 11a65b69 | 2012-03-30 11:29:16 | [diff] [blame] | 76 | } |
[email protected] | b0f146f | 2011-09-15 22:14:25 | [diff] [blame] | 77 | |
[email protected] | 11a65b69 | 2012-03-30 11:29:16 | [diff] [blame] | 78 | FilePath ShellBrowserContext::GetPath() { |
[email protected] | e99ca511 | 2011-09-26 17:22:54 | [diff] [blame] | 79 | return path_; |
[email protected] | b0f146f | 2011-09-15 22:14:25 | [diff] [blame] | 80 | } |
| 81 | |
[email protected] | 27d6e85 | 2012-03-02 21:31:32 | [diff] [blame] | 82 | bool ShellBrowserContext::IsOffTheRecord() const { |
[email protected] | 71d504f | 2012-07-25 17:15:28 | [diff] [blame] | 83 | return off_the_record_; |
[email protected] | b0f146f | 2011-09-15 22:14:25 | [diff] [blame] | 84 | } |
| 85 | |
[email protected] | b441a849 | 2012-06-06 14:55:57 | [diff] [blame] | 86 | DownloadManagerDelegate* ShellBrowserContext::GetDownloadManagerDelegate() { |
[email protected] | 08c92ac | 2012-08-21 23:41:40 | [diff] [blame] | 87 | DownloadManager* manager = BrowserContext::GetDownloadManager(this); |
| 88 | |
[email protected] | 5900209 | 2012-08-27 19:42:56 | [diff] [blame] | 89 | if (!download_manager_delegate_.get()) { |
| 90 | download_manager_delegate_ = new ShellDownloadManagerDelegate(); |
| 91 | download_manager_delegate_->SetDownloadManager(manager); |
[email protected] | 17bc408b2 | 2013-01-10 18:40:08 | [diff] [blame^] | 92 | CommandLine* cmd_line = CommandLine::ForCurrentProcess(); |
| 93 | if (cmd_line->HasSwitch(switches::kDumpRenderTree)) { |
| 94 | download_manager_delegate_->SetDownloadBehaviorForTesting( |
| 95 | path_.Append(FILE_PATH_LITERAL("downloads"))); |
| 96 | } |
[email protected] | 5900209 | 2012-08-27 19:42:56 | [diff] [blame] | 97 | } |
[email protected] | 08c92ac | 2012-08-21 23:41:40 | [diff] [blame] | 98 | |
[email protected] | b441a849 | 2012-06-06 14:55:57 | [diff] [blame] | 99 | return download_manager_delegate_.get(); |
[email protected] | b0f146f | 2011-09-15 22:14:25 | [diff] [blame] | 100 | } |
| 101 | |
[email protected] | b0f146f | 2011-09-15 22:14:25 | [diff] [blame] | 102 | net::URLRequestContextGetter* ShellBrowserContext::GetRequestContext() { |
| 103 | if (!url_request_getter_) { |
| 104 | url_request_getter_ = new ShellURLRequestContextGetter( |
[email protected] | c2dad29 | 2012-09-07 21:27:35 | [diff] [blame] | 105 | ignore_certificate_errors_, |
[email protected] | b0f146f | 2011-09-15 22:14:25 | [diff] [blame] | 106 | GetPath(), |
[email protected] | ed10dd1 | 2011-12-07 12:03:42 | [diff] [blame] | 107 | BrowserThread::UnsafeGetMessageLoopForThread(BrowserThread::IO), |
| 108 | BrowserThread::UnsafeGetMessageLoopForThread(BrowserThread::FILE)); |
[email protected] | b0f146f | 2011-09-15 22:14:25 | [diff] [blame] | 109 | } |
| 110 | return url_request_getter_; |
| 111 | } |
| 112 | |
| 113 | net::URLRequestContextGetter* |
| 114 | ShellBrowserContext::GetRequestContextForRenderProcess( |
| 115 | int renderer_child_id) { |
| 116 | return GetRequestContext(); |
| 117 | } |
| 118 | |
| 119 | net::URLRequestContextGetter* |
[email protected] | 10705a7b | 2012-08-21 19:07:08 | [diff] [blame] | 120 | ShellBrowserContext::GetMediaRequestContext() { |
| 121 | return GetRequestContext(); |
| 122 | } |
| 123 | |
| 124 | net::URLRequestContextGetter* |
| 125 | ShellBrowserContext::GetMediaRequestContextForRenderProcess( |
| 126 | int renderer_child_id) { |
[email protected] | b0f146f | 2011-09-15 22:14:25 | [diff] [blame] | 127 | return GetRequestContext(); |
| 128 | } |
| 129 | |
[email protected] | 55c0eca | 2012-09-15 05:12:34 | [diff] [blame] | 130 | net::URLRequestContextGetter* |
[email protected] | 10eb2816 | 2012-09-18 03:04:09 | [diff] [blame] | 131 | ShellBrowserContext::GetMediaRequestContextForStoragePartition( |
[email protected] | 27ddfed2 | 2012-10-30 23:22:43 | [diff] [blame] | 132 | const FilePath& partition_path, |
| 133 | bool in_memory) { |
[email protected] | 10eb2816 | 2012-09-18 03:04:09 | [diff] [blame] | 134 | return GetRequestContext(); |
| 135 | } |
| 136 | |
| 137 | net::URLRequestContextGetter* |
[email protected] | 55c0eca | 2012-09-15 05:12:34 | [diff] [blame] | 138 | ShellBrowserContext::GetRequestContextForStoragePartition( |
[email protected] | 27ddfed2 | 2012-10-30 23:22:43 | [diff] [blame] | 139 | const FilePath& partition_path, |
| 140 | bool in_memory) { |
[email protected] | 55c0eca | 2012-09-15 05:12:34 | [diff] [blame] | 141 | return NULL; |
| 142 | } |
| 143 | |
[email protected] | df02aca | 2012-02-09 21:03:20 | [diff] [blame] | 144 | ResourceContext* ShellBrowserContext::GetResourceContext() { |
[email protected] | b0f146f | 2011-09-15 22:14:25 | [diff] [blame] | 145 | if (!resource_context_.get()) { |
| 146 | resource_context_.reset(new ShellResourceContext( |
[email protected] | 314c3e2 | 2012-02-21 03:57:42 | [diff] [blame] | 147 | static_cast<ShellURLRequestContextGetter*>(GetRequestContext()))); |
[email protected] | b0f146f | 2011-09-15 22:14:25 | [diff] [blame] | 148 | } |
[email protected] | df02aca | 2012-02-09 21:03:20 | [diff] [blame] | 149 | return resource_context_.get(); |
[email protected] | b0f146f | 2011-09-15 22:14:25 | [diff] [blame] | 150 | } |
| 151 | |
[email protected] | b0f146f | 2011-09-15 22:14:25 | [diff] [blame] | 152 | GeolocationPermissionContext* |
| 153 | ShellBrowserContext::GetGeolocationPermissionContext() { |
[email protected] | 30e3e9a6 | 2012-06-07 20:46:57 | [diff] [blame] | 154 | return NULL; |
[email protected] | b0f146f | 2011-09-15 22:14:25 | [diff] [blame] | 155 | } |
| 156 | |
[email protected] | c52b289 | 2012-03-07 11:01:02 | [diff] [blame] | 157 | SpeechRecognitionPreferences* |
| 158 | ShellBrowserContext::GetSpeechRecognitionPreferences() { |
[email protected] | 30e3e9a6 | 2012-06-07 20:46:57 | [diff] [blame] | 159 | return NULL; |
[email protected] | 8238dd6 | 2011-09-29 15:13:01 | [diff] [blame] | 160 | } |
| 161 | |
[email protected] | 55eb70e76 | 2012-02-20 17:38:39 | [diff] [blame] | 162 | quota::SpecialStoragePolicy* ShellBrowserContext::GetSpecialStoragePolicy() { |
| 163 | return NULL; |
[email protected] | b0f146f | 2011-09-15 22:14:25 | [diff] [blame] | 164 | } |
| 165 | |
| 166 | } // namespace content |