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