OLD | NEW |
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. |
2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 | 4 |
5 #include "content/shell/shell_browser_context.h" | 5 #include "content/shell/shell_browser_context.h" |
6 | 6 |
7 #include "base/bind.h" | 7 #include "base/bind.h" |
8 #include "base/command_line.h" | 8 #include "base/command_line.h" |
9 #include "base/environment.h" | 9 #include "base/environment.h" |
10 #include "base/file_util.h" | 10 #include "base/file_util.h" |
11 #include "base/logging.h" | 11 #include "base/logging.h" |
12 #include "base/path_service.h" | 12 #include "base/path_service.h" |
13 #include "base/threading/thread.h" | 13 #include "base/threading/thread.h" |
14 #include "content/public/browser/browser_thread.h" | 14 #include "content/public/browser/browser_thread.h" |
| 15 #include "content/public/browser/resource_context.h" |
| 16 #include "content/public/browser/storage_partition.h" |
| 17 #include "content/public/common/content_switches.h" |
15 #include "content/shell/shell_download_manager_delegate.h" | 18 #include "content/shell/shell_download_manager_delegate.h" |
16 #include "content/shell/shell_resource_context.h" | |
17 #include "content/shell/shell_switches.h" | 19 #include "content/shell/shell_switches.h" |
18 #include "content/shell/shell_url_request_context_getter.h" | 20 #include "content/shell/shell_url_request_context_getter.h" |
19 #include "content/public/common/content_switches.h" | |
20 | 21 |
21 #if defined(OS_WIN) | 22 #if defined(OS_WIN) |
22 #include "base/base_paths_win.h" | 23 #include "base/base_paths_win.h" |
23 #elif defined(OS_LINUX) | 24 #elif defined(OS_LINUX) |
24 #include "base/nix/xdg_util.h" | 25 #include "base/nix/xdg_util.h" |
25 #elif defined(OS_MACOSX) | 26 #elif defined(OS_MACOSX) |
26 #include "base/base_paths_mac.h" | 27 #include "base/base_paths_mac.h" |
27 #endif | 28 #endif |
28 | 29 |
29 namespace content { | 30 namespace content { |
30 | 31 |
| 32 class ShellBrowserContext::ShellResourceContext : public ResourceContext { |
| 33 public: |
| 34 ShellResourceContext() : getter_(NULL) {} |
| 35 virtual ~ShellResourceContext() {} |
| 36 |
| 37 // ResourceContext implementation: |
| 38 virtual net::HostResolver* GetHostResolver() OVERRIDE { |
| 39 CHECK(getter_); |
| 40 return getter_->host_resolver(); |
| 41 } |
| 42 virtual net::URLRequestContext* GetRequestContext() OVERRIDE { |
| 43 CHECK(getter_); |
| 44 return getter_->GetURLRequestContext(); |
| 45 } |
| 46 |
| 47 void set_url_request_context_getter(ShellURLRequestContextGetter* getter) { |
| 48 getter_ = getter; |
| 49 } |
| 50 |
| 51 private: |
| 52 ShellURLRequestContextGetter* getter_; |
| 53 |
| 54 DISALLOW_COPY_AND_ASSIGN(ShellResourceContext); |
| 55 }; |
| 56 |
31 ShellBrowserContext::ShellBrowserContext(bool off_the_record) | 57 ShellBrowserContext::ShellBrowserContext(bool off_the_record) |
32 : off_the_record_(off_the_record), | 58 : off_the_record_(off_the_record), |
33 ignore_certificate_errors_(false) { | 59 ignore_certificate_errors_(false), |
| 60 resource_context_(new ShellResourceContext) { |
34 InitWhileIOAllowed(); | 61 InitWhileIOAllowed(); |
35 } | 62 } |
36 | 63 |
37 ShellBrowserContext::~ShellBrowserContext() { | 64 ShellBrowserContext::~ShellBrowserContext() { |
38 if (resource_context_.get()) { | 65 if (resource_context_.get()) { |
39 BrowserThread::DeleteSoon( | 66 BrowserThread::DeleteSoon( |
40 BrowserThread::IO, FROM_HERE, resource_context_.release()); | 67 BrowserThread::IO, FROM_HERE, resource_context_.release()); |
41 } | 68 } |
42 } | 69 } |
43 | 70 |
(...skipping 49 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
93 if (cmd_line->HasSwitch(switches::kDumpRenderTree)) { | 120 if (cmd_line->HasSwitch(switches::kDumpRenderTree)) { |
94 download_manager_delegate_->SetDownloadBehaviorForTesting( | 121 download_manager_delegate_->SetDownloadBehaviorForTesting( |
95 path_.Append(FILE_PATH_LITERAL("downloads"))); | 122 path_.Append(FILE_PATH_LITERAL("downloads"))); |
96 } | 123 } |
97 } | 124 } |
98 | 125 |
99 return download_manager_delegate_.get(); | 126 return download_manager_delegate_.get(); |
100 } | 127 } |
101 | 128 |
102 net::URLRequestContextGetter* ShellBrowserContext::GetRequestContext() { | 129 net::URLRequestContextGetter* ShellBrowserContext::GetRequestContext() { |
103 if (!url_request_getter_) { | 130 return GetDefaultStoragePartition(this)->GetURLRequestContext(); |
104 url_request_getter_ = new ShellURLRequestContextGetter( | 131 } |
105 ignore_certificate_errors_, | 132 |
106 GetPath(), | 133 net::URLRequestContextGetter* ShellBrowserContext::CreateRequestContext( |
107 BrowserThread::UnsafeGetMessageLoopForThread(BrowserThread::IO), | 134 scoped_ptr<net::URLRequestJobFactory::ProtocolHandler> |
108 BrowserThread::UnsafeGetMessageLoopForThread(BrowserThread::FILE)); | 135 blob_protocol_handler, |
109 } | 136 scoped_ptr<net::URLRequestJobFactory::ProtocolHandler> |
110 return url_request_getter_; | 137 file_system_protocol_handler, |
| 138 scoped_ptr<net::URLRequestJobFactory::ProtocolHandler> |
| 139 developer_protocol_handler, |
| 140 scoped_ptr<net::URLRequestJobFactory::ProtocolHandler> |
| 141 chrome_protocol_handler, |
| 142 scoped_ptr<net::URLRequestJobFactory::ProtocolHandler> |
| 143 chrome_devtools_protocol_handler) { |
| 144 DCHECK(!url_request_getter_); |
| 145 url_request_getter_ = new ShellURLRequestContextGetter( |
| 146 ignore_certificate_errors_, |
| 147 GetPath(), |
| 148 BrowserThread::UnsafeGetMessageLoopForThread(BrowserThread::IO), |
| 149 BrowserThread::UnsafeGetMessageLoopForThread(BrowserThread::FILE), |
| 150 blob_protocol_handler.Pass(), |
| 151 file_system_protocol_handler.Pass(), |
| 152 developer_protocol_handler.Pass(), |
| 153 chrome_protocol_handler.Pass(), |
| 154 chrome_devtools_protocol_handler.Pass()); |
| 155 resource_context_->set_url_request_context_getter(url_request_getter_.get()); |
| 156 return url_request_getter_.get(); |
111 } | 157 } |
112 | 158 |
113 net::URLRequestContextGetter* | 159 net::URLRequestContextGetter* |
114 ShellBrowserContext::GetRequestContextForRenderProcess( | 160 ShellBrowserContext::GetRequestContextForRenderProcess( |
115 int renderer_child_id) { | 161 int renderer_child_id) { |
116 return GetRequestContext(); | 162 return GetRequestContext(); |
117 } | 163 } |
118 | 164 |
119 net::URLRequestContextGetter* | 165 net::URLRequestContextGetter* |
120 ShellBrowserContext::GetMediaRequestContext() { | 166 ShellBrowserContext::GetMediaRequestContext() { |
121 return GetRequestContext(); | 167 return GetRequestContext(); |
122 } | 168 } |
123 | 169 |
124 net::URLRequestContextGetter* | 170 net::URLRequestContextGetter* |
125 ShellBrowserContext::GetMediaRequestContextForRenderProcess( | 171 ShellBrowserContext::GetMediaRequestContextForRenderProcess( |
126 int renderer_child_id) { | 172 int renderer_child_id) { |
127 return GetRequestContext(); | 173 return GetRequestContext(); |
128 } | 174 } |
129 | 175 |
130 net::URLRequestContextGetter* | 176 net::URLRequestContextGetter* |
131 ShellBrowserContext::GetMediaRequestContextForStoragePartition( | 177 ShellBrowserContext::GetMediaRequestContextForStoragePartition( |
132 const base::FilePath& partition_path, | 178 const base::FilePath& partition_path, |
133 bool in_memory) { | 179 bool in_memory) { |
134 return GetRequestContext(); | 180 return GetRequestContext(); |
135 } | 181 } |
136 | 182 |
137 net::URLRequestContextGetter* | 183 net::URLRequestContextGetter* |
138 ShellBrowserContext::GetRequestContextForStoragePartition( | 184 ShellBrowserContext::CreateRequestContextForStoragePartition( |
139 const base::FilePath& partition_path, | 185 const base::FilePath& partition_path, |
140 bool in_memory) { | 186 bool in_memory, |
| 187 scoped_ptr<net::URLRequestJobFactory::ProtocolHandler> |
| 188 blob_protocol_handler, |
| 189 scoped_ptr<net::URLRequestJobFactory::ProtocolHandler> |
| 190 file_system_protocol_handler, |
| 191 scoped_ptr<net::URLRequestJobFactory::ProtocolHandler> |
| 192 developer_protocol_handler, |
| 193 scoped_ptr<net::URLRequestJobFactory::ProtocolHandler> |
| 194 chrome_protocol_handler, |
| 195 scoped_ptr<net::URLRequestJobFactory::ProtocolHandler> |
| 196 chrome_devtools_protocol_handler) { |
141 return NULL; | 197 return NULL; |
142 } | 198 } |
143 | 199 |
144 ResourceContext* ShellBrowserContext::GetResourceContext() { | 200 ResourceContext* ShellBrowserContext::GetResourceContext() { |
145 if (!resource_context_.get()) { | |
146 resource_context_.reset(new ShellResourceContext( | |
147 static_cast<ShellURLRequestContextGetter*>(GetRequestContext()))); | |
148 } | |
149 return resource_context_.get(); | 201 return resource_context_.get(); |
150 } | 202 } |
151 | 203 |
152 GeolocationPermissionContext* | 204 GeolocationPermissionContext* |
153 ShellBrowserContext::GetGeolocationPermissionContext() { | 205 ShellBrowserContext::GetGeolocationPermissionContext() { |
154 return NULL; | 206 return NULL; |
155 } | 207 } |
156 | 208 |
157 SpeechRecognitionPreferences* | 209 SpeechRecognitionPreferences* |
158 ShellBrowserContext::GetSpeechRecognitionPreferences() { | 210 ShellBrowserContext::GetSpeechRecognitionPreferences() { |
159 return NULL; | 211 return NULL; |
160 } | 212 } |
161 | 213 |
162 quota::SpecialStoragePolicy* ShellBrowserContext::GetSpecialStoragePolicy() { | 214 quota::SpecialStoragePolicy* ShellBrowserContext::GetSpecialStoragePolicy() { |
163 return NULL; | 215 return NULL; |
164 } | 216 } |
165 | 217 |
166 } // namespace content | 218 } // namespace content |
OLD | NEW |