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/shell/shell_download_manager_delegate.h" | 15 #include "content/shell/shell_download_manager_delegate.h" |
16 #include "content/shell/shell_resource_context.h" | |
17 #include "content/shell/shell_switches.h" | 16 #include "content/shell/shell_switches.h" |
18 #include "content/shell/shell_url_request_context_getter.h" | 17 #include "content/shell/shell_url_request_context_getter.h" |
19 #include "content/public/common/content_switches.h" | 18 #include "content/public/common/content_switches.h" |
20 | 19 |
21 #if defined(OS_WIN) | 20 #if defined(OS_WIN) |
22 #include "base/base_paths_win.h" | 21 #include "base/base_paths_win.h" |
23 #elif defined(OS_LINUX) | 22 #elif defined(OS_LINUX) |
24 #include "base/nix/xdg_util.h" | 23 #include "base/nix/xdg_util.h" |
25 #elif defined(OS_MACOSX) | 24 #elif defined(OS_MACOSX) |
26 #include "base/base_paths_mac.h" | 25 #include "base/base_paths_mac.h" |
27 #endif | 26 #endif |
28 | 27 |
29 namespace content { | 28 namespace content { |
30 | 29 |
| 30 class ShellResourceContext : public ResourceContext { |
| 31 public: |
| 32 ShellResourceContext() : getter_(NULL) {} |
| 33 virtual ~ShellResourceContext() {} |
| 34 |
| 35 private: |
| 36 friend class ShellBrowserContext; |
| 37 |
| 38 // ResourceContext implementation: |
| 39 virtual net::HostResolver* GetHostResolver() OVERRIDE { |
| 40 DCHECK(getter_); |
| 41 return getter_->host_resolver(); |
| 42 } |
| 43 virtual net::URLRequestContext* GetRequestContext() OVERRIDE { |
| 44 DCHECK(getter_); |
| 45 return getter_->GetURLRequestContext(); |
| 46 } |
| 47 |
| 48 ShellURLRequestContextGetter* getter_; |
| 49 |
| 50 DISALLOW_COPY_AND_ASSIGN(ShellResourceContext); |
| 51 }; |
| 52 |
31 ShellBrowserContext::ShellBrowserContext(bool off_the_record) | 53 ShellBrowserContext::ShellBrowserContext(bool off_the_record) |
32 : off_the_record_(off_the_record), | 54 : off_the_record_(off_the_record), |
33 ignore_certificate_errors_(false) { | 55 ignore_certificate_errors_(false), |
| 56 resource_context_(new ShellResourceContext()) { |
34 InitWhileIOAllowed(); | 57 InitWhileIOAllowed(); |
35 } | 58 } |
36 | 59 |
37 ShellBrowserContext::~ShellBrowserContext() { | 60 ShellBrowserContext::~ShellBrowserContext() { |
38 if (resource_context_.get()) { | 61 if (resource_context_.get()) { |
39 BrowserThread::DeleteSoon( | 62 BrowserThread::DeleteSoon( |
40 BrowserThread::IO, FROM_HERE, resource_context_.release()); | 63 BrowserThread::IO, FROM_HERE, resource_context_.release()); |
41 } | 64 } |
42 } | 65 } |
43 | 66 |
(...skipping 49 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
93 | 116 |
94 if (!download_manager_delegate_.get()) { | 117 if (!download_manager_delegate_.get()) { |
95 download_manager_delegate_ = new ShellDownloadManagerDelegate(); | 118 download_manager_delegate_ = new ShellDownloadManagerDelegate(); |
96 download_manager_delegate_->SetDownloadManager(manager); | 119 download_manager_delegate_->SetDownloadManager(manager); |
97 } | 120 } |
98 | 121 |
99 return download_manager_delegate_.get(); | 122 return download_manager_delegate_.get(); |
100 } | 123 } |
101 | 124 |
102 net::URLRequestContextGetter* ShellBrowserContext::GetRequestContext() { | 125 net::URLRequestContextGetter* ShellBrowserContext::GetRequestContext() { |
103 if (!url_request_getter_) { | 126 DCHECK(url_request_getter_.get()); |
104 url_request_getter_ = new ShellURLRequestContextGetter( | 127 return url_request_getter_.get(); |
105 ignore_certificate_errors_, | 128 } |
106 GetPath(), | 129 |
107 BrowserThread::UnsafeGetMessageLoopForThread(BrowserThread::IO), | 130 net::URLRequestContextGetter* ShellBrowserContext::CreateRequestContext( |
108 BrowserThread::UnsafeGetMessageLoopForThread(BrowserThread::FILE)); | 131 scoped_ptr<net::URLRequestJobFactory::ProtocolHandler> |
109 } | 132 blob_protocol_handler, |
110 return url_request_getter_; | 133 scoped_ptr<net::URLRequestJobFactory::ProtocolHandler> |
| 134 file_system_protocol_handler, |
| 135 scoped_ptr<net::URLRequestJobFactory::Interceptor> |
| 136 developer_protocol_handler) { |
| 137 DCHECK(!url_request_getter_.get()); |
| 138 url_request_getter_ = new ShellURLRequestContextGetter( |
| 139 ignore_certificate_errors_, |
| 140 GetPath(), |
| 141 BrowserThread::UnsafeGetMessageLoopForThread(BrowserThread::IO), |
| 142 BrowserThread::UnsafeGetMessageLoopForThread(BrowserThread::FILE), |
| 143 blob_protocol_handler.Pass(), |
| 144 file_system_protocol_handler.Pass(), |
| 145 developer_protocol_handler.Pass()); |
| 146 resource_context_->getter_ = url_request_getter_.get(); |
| 147 return url_request_getter_.get(); |
111 } | 148 } |
112 | 149 |
113 net::URLRequestContextGetter* | 150 net::URLRequestContextGetter* |
114 ShellBrowserContext::GetRequestContextForRenderProcess( | 151 ShellBrowserContext::GetRequestContextForRenderProcess( |
115 int renderer_child_id) { | 152 int renderer_child_id) { |
116 return GetRequestContext(); | 153 return GetRequestContext(); |
117 } | 154 } |
118 | 155 |
119 net::URLRequestContextGetter* | 156 net::URLRequestContextGetter* |
120 ShellBrowserContext::GetMediaRequestContext() { | 157 ShellBrowserContext::GetMediaRequestContext() { |
121 return GetRequestContext(); | 158 return GetRequestContext(); |
122 } | 159 } |
123 | 160 |
124 net::URLRequestContextGetter* | 161 net::URLRequestContextGetter* |
125 ShellBrowserContext::GetMediaRequestContextForRenderProcess( | 162 ShellBrowserContext::GetMediaRequestContextForRenderProcess( |
126 int renderer_child_id) { | 163 int renderer_child_id) { |
127 return GetRequestContext(); | 164 return GetRequestContext(); |
128 } | 165 } |
129 | 166 |
130 net::URLRequestContextGetter* | 167 net::URLRequestContextGetter* |
131 ShellBrowserContext::GetMediaRequestContextForStoragePartition( | 168 ShellBrowserContext::GetMediaRequestContextForStoragePartition( |
132 const FilePath& partition_path, | 169 const FilePath& partition_path, |
133 bool in_memory) { | 170 bool in_memory) { |
134 return GetRequestContext(); | 171 return GetRequestContext(); |
135 } | 172 } |
136 | 173 |
137 net::URLRequestContextGetter* | 174 net::URLRequestContextGetter* |
138 ShellBrowserContext::GetRequestContextForStoragePartition( | 175 ShellBrowserContext::CreateRequestContextForStoragePartition( |
139 const FilePath& partition_path, | 176 const FilePath& partition_path, |
140 bool in_memory) { | 177 bool in_memory, |
| 178 scoped_ptr<net::URLRequestJobFactory::ProtocolHandler> |
| 179 blob_protocol_handler, |
| 180 scoped_ptr<net::URLRequestJobFactory::ProtocolHandler> |
| 181 file_system_protocol_handler, |
| 182 scoped_ptr<net::URLRequestJobFactory::Interceptor> |
| 183 developer_protocol_handler) { |
141 return NULL; | 184 return NULL; |
142 } | 185 } |
143 | 186 |
144 ResourceContext* ShellBrowserContext::GetResourceContext() { | 187 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(); | 188 return resource_context_.get(); |
150 } | 189 } |
151 | 190 |
152 GeolocationPermissionContext* | 191 GeolocationPermissionContext* |
153 ShellBrowserContext::GetGeolocationPermissionContext() { | 192 ShellBrowserContext::GetGeolocationPermissionContext() { |
154 return NULL; | 193 return NULL; |
155 } | 194 } |
156 | 195 |
157 SpeechRecognitionPreferences* | 196 SpeechRecognitionPreferences* |
158 ShellBrowserContext::GetSpeechRecognitionPreferences() { | 197 ShellBrowserContext::GetSpeechRecognitionPreferences() { |
159 return NULL; | 198 return NULL; |
160 } | 199 } |
161 | 200 |
162 quota::SpecialStoragePolicy* ShellBrowserContext::GetSpecialStoragePolicy() { | 201 quota::SpecialStoragePolicy* ShellBrowserContext::GetSpecialStoragePolicy() { |
163 return NULL; | 202 return NULL; |
164 } | 203 } |
165 | 204 |
166 } // namespace content | 205 } // namespace content |
OLD | NEW |