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 StoragePartition* storage_partition = |
104 url_request_getter_ = new ShellURLRequestContextGetter( | 131 BrowserContext::GetStoragePartition(this, NULL); |
awong
2013/02/02 03:26:12
GetDefaultStoragePartition()
| |
105 ignore_certificate_errors_, | 132 return storage_partition->GetURLRequestContext(); |
106 GetPath(), | 133 } |
107 BrowserThread::UnsafeGetMessageLoopForThread(BrowserThread::IO), | 134 |
108 BrowserThread::UnsafeGetMessageLoopForThread(BrowserThread::FILE)); | 135 net::URLRequestContextGetter* ShellBrowserContext::CreateRequestContext( |
109 } | 136 scoped_ptr<net::URLRequestJobFactory::ProtocolHandler> |
110 return url_request_getter_; | 137 blob_protocol_handler, |
138 scoped_ptr<net::URLRequestJobFactory::ProtocolHandler> | |
139 file_system_protocol_handler, | |
140 scoped_ptr<net::URLRequestJobFactory::ProtocolHandler> | |
141 developer_protocol_handler, | |
142 scoped_ptr<net::URLRequestJobFactory::ProtocolHandler> | |
143 chrome_protocol_handler, | |
144 scoped_ptr<net::URLRequestJobFactory::ProtocolHandler> | |
145 chrome_devtools_protocol_handler) { | |
146 DCHECK(!url_request_getter_); | |
147 url_request_getter_ = new ShellURLRequestContextGetter( | |
148 ignore_certificate_errors_, | |
149 GetPath(), | |
150 BrowserThread::UnsafeGetMessageLoopForThread(BrowserThread::IO), | |
151 BrowserThread::UnsafeGetMessageLoopForThread(BrowserThread::FILE), | |
152 blob_protocol_handler.Pass(), | |
153 file_system_protocol_handler.Pass(), | |
154 developer_protocol_handler.Pass(), | |
155 chrome_protocol_handler.Pass(), | |
156 chrome_devtools_protocol_handler.Pass()); | |
157 resource_context_->set_url_request_context_getter(url_request_getter_.get()); | |
158 return url_request_getter_.get(); | |
111 } | 159 } |
112 | 160 |
113 net::URLRequestContextGetter* | 161 net::URLRequestContextGetter* |
114 ShellBrowserContext::GetRequestContextForRenderProcess( | 162 ShellBrowserContext::GetRequestContextForRenderProcess( |
115 int renderer_child_id) { | 163 int renderer_child_id) { |
116 return GetRequestContext(); | 164 return GetRequestContext(); |
117 } | 165 } |
118 | 166 |
119 net::URLRequestContextGetter* | 167 net::URLRequestContextGetter* |
120 ShellBrowserContext::GetMediaRequestContext() { | 168 ShellBrowserContext::GetMediaRequestContext() { |
121 return GetRequestContext(); | 169 return GetRequestContext(); |
122 } | 170 } |
123 | 171 |
124 net::URLRequestContextGetter* | 172 net::URLRequestContextGetter* |
125 ShellBrowserContext::GetMediaRequestContextForRenderProcess( | 173 ShellBrowserContext::GetMediaRequestContextForRenderProcess( |
126 int renderer_child_id) { | 174 int renderer_child_id) { |
127 return GetRequestContext(); | 175 return GetRequestContext(); |
128 } | 176 } |
129 | 177 |
130 net::URLRequestContextGetter* | 178 net::URLRequestContextGetter* |
131 ShellBrowserContext::GetMediaRequestContextForStoragePartition( | 179 ShellBrowserContext::GetMediaRequestContextForStoragePartition( |
132 const FilePath& partition_path, | 180 const FilePath& partition_path, |
133 bool in_memory) { | 181 bool in_memory) { |
134 return GetRequestContext(); | 182 return GetRequestContext(); |
135 } | 183 } |
136 | 184 |
137 net::URLRequestContextGetter* | 185 net::URLRequestContextGetter* |
138 ShellBrowserContext::GetRequestContextForStoragePartition( | 186 ShellBrowserContext::CreateRequestContextForStoragePartition( |
139 const FilePath& partition_path, | 187 const FilePath& partition_path, |
140 bool in_memory) { | 188 bool in_memory, |
189 scoped_ptr<net::URLRequestJobFactory::ProtocolHandler> | |
190 blob_protocol_handler, | |
191 scoped_ptr<net::URLRequestJobFactory::ProtocolHandler> | |
192 file_system_protocol_handler, | |
193 scoped_ptr<net::URLRequestJobFactory::ProtocolHandler> | |
194 developer_protocol_handler, | |
195 scoped_ptr<net::URLRequestJobFactory::ProtocolHandler> | |
196 chrome_protocol_handler, | |
197 scoped_ptr<net::URLRequestJobFactory::ProtocolHandler> | |
198 chrome_devtools_protocol_handler) { | |
141 return NULL; | 199 return NULL; |
142 } | 200 } |
143 | 201 |
144 ResourceContext* ShellBrowserContext::GetResourceContext() { | 202 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(); | 203 return resource_context_.get(); |
150 } | 204 } |
151 | 205 |
152 GeolocationPermissionContext* | 206 GeolocationPermissionContext* |
153 ShellBrowserContext::GetGeolocationPermissionContext() { | 207 ShellBrowserContext::GetGeolocationPermissionContext() { |
154 return NULL; | 208 return NULL; |
155 } | 209 } |
156 | 210 |
157 SpeechRecognitionPreferences* | 211 SpeechRecognitionPreferences* |
158 ShellBrowserContext::GetSpeechRecognitionPreferences() { | 212 ShellBrowserContext::GetSpeechRecognitionPreferences() { |
159 return NULL; | 213 return NULL; |
160 } | 214 } |
161 | 215 |
162 quota::SpecialStoragePolicy* ShellBrowserContext::GetSpecialStoragePolicy() { | 216 quota::SpecialStoragePolicy* ShellBrowserContext::GetSpecialStoragePolicy() { |
163 return NULL; | 217 return NULL; |
164 } | 218 } |
165 | 219 |
166 } // namespace content | 220 } // namespace content |
OLD | NEW |