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 "chrome/browser/extensions/extension_protocols.h" | 5 #include "chrome/browser/extensions/extension_protocols.h" |
6 | 6 |
7 #include <algorithm> | 7 #include <algorithm> |
8 | 8 |
9 #include "base/base64.h" | 9 #include "base/base64.h" |
10 #include "base/compiler_specific.h" | 10 #include "base/compiler_specific.h" |
11 #include "base/file_util.h" | 11 #include "base/file_util.h" |
12 #include "base/files/file_path.h" | 12 #include "base/files/file_path.h" |
13 #include "base/format_macros.h" | 13 #include "base/format_macros.h" |
14 #include "base/logging.h" | 14 #include "base/logging.h" |
15 #include "base/memory/weak_ptr.h" | 15 #include "base/memory/weak_ptr.h" |
16 #include "base/message_loop/message_loop.h" | 16 #include "base/message_loop/message_loop.h" |
17 #include "base/path_service.h" | 17 #include "base/path_service.h" |
18 #include "base/sha1.h" | 18 #include "base/sha1.h" |
19 #include "base/strings/string_util.h" | 19 #include "base/strings/string_util.h" |
20 #include "base/strings/stringprintf.h" | 20 #include "base/strings/stringprintf.h" |
21 #include "base/strings/utf_string_conversions.h" | 21 #include "base/strings/utf_string_conversions.h" |
| 22 #include "base/threading/sequenced_worker_pool.h" |
22 #include "base/threading/thread_restrictions.h" | 23 #include "base/threading/thread_restrictions.h" |
23 #include "base/threading/worker_pool.h" | |
24 #include "build/build_config.h" | 24 #include "build/build_config.h" |
25 #include "chrome/browser/extensions/extension_info_map.h" | 25 #include "chrome/browser/extensions/extension_info_map.h" |
26 #include "chrome/browser/extensions/image_loader.h" | 26 #include "chrome/browser/extensions/image_loader.h" |
27 #include "chrome/common/chrome_paths.h" | 27 #include "chrome/common/chrome_paths.h" |
28 #include "chrome/common/extensions/background_info.h" | 28 #include "chrome/common/extensions/background_info.h" |
29 #include "chrome/common/extensions/csp_handler.h" | 29 #include "chrome/common/extensions/csp_handler.h" |
30 #include "chrome/common/extensions/extension.h" | 30 #include "chrome/common/extensions/extension.h" |
31 #include "chrome/common/extensions/extension_file_util.h" | 31 #include "chrome/common/extensions/extension_file_util.h" |
32 #include "chrome/common/extensions/incognito_handler.h" | 32 #include "chrome/common/extensions/incognito_handler.h" |
33 #include "chrome/common/extensions/manifest_handlers/icons_handler.h" | 33 #include "chrome/common/extensions/manifest_handlers/icons_handler.h" |
34 #include "chrome/common/extensions/manifest_handlers/shared_module_info.h" | 34 #include "chrome/common/extensions/manifest_handlers/shared_module_info.h" |
35 #include "chrome/common/extensions/manifest_url_handler.h" | 35 #include "chrome/common/extensions/manifest_url_handler.h" |
36 #include "chrome/common/extensions/web_accessible_resources_handler.h" | 36 #include "chrome/common/extensions/web_accessible_resources_handler.h" |
37 #include "chrome/common/url_constants.h" | 37 #include "chrome/common/url_constants.h" |
| 38 #include "content/public/browser/browser_thread.h" |
38 #include "content/public/browser/resource_request_info.h" | 39 #include "content/public/browser/resource_request_info.h" |
39 #include "extensions/common/constants.h" | 40 #include "extensions/common/constants.h" |
40 #include "extensions/common/extension_resource.h" | 41 #include "extensions/common/extension_resource.h" |
41 #include "grit/component_extension_resources_map.h" | 42 #include "grit/component_extension_resources_map.h" |
42 #include "net/base/mime_util.h" | 43 #include "net/base/mime_util.h" |
43 #include "net/base/net_errors.h" | 44 #include "net/base/net_errors.h" |
44 #include "net/http/http_response_headers.h" | 45 #include "net/http/http_response_headers.h" |
45 #include "net/http/http_response_info.h" | 46 #include "net/http/http_response_info.h" |
46 #include "net/url_request/url_request_error_job.h" | 47 #include "net/url_request/url_request_error_job.h" |
47 #include "net/url_request/url_request_file_job.h" | 48 #include "net/url_request/url_request_file_job.h" |
(...skipping 81 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
129 // Overridden from URLRequestSimpleJob: | 130 // Overridden from URLRequestSimpleJob: |
130 virtual int GetData(std::string* mime_type, | 131 virtual int GetData(std::string* mime_type, |
131 std::string* charset, | 132 std::string* charset, |
132 std::string* data, | 133 std::string* data, |
133 const net::CompletionCallback& callback) const OVERRIDE { | 134 const net::CompletionCallback& callback) const OVERRIDE { |
134 const ResourceBundle& rb = ResourceBundle::GetSharedInstance(); | 135 const ResourceBundle& rb = ResourceBundle::GetSharedInstance(); |
135 *data = rb.GetRawDataResource(resource_id_).as_string(); | 136 *data = rb.GetRawDataResource(resource_id_).as_string(); |
136 | 137 |
137 std::string* read_mime_type = new std::string; | 138 std::string* read_mime_type = new std::string; |
138 bool* read_result = new bool; | 139 bool* read_result = new bool; |
139 bool posted = base::WorkerPool::PostTaskAndReply( | 140 bool posted = content::BrowserThread::PostBlockingPoolTaskAndReply( |
140 FROM_HERE, | 141 FROM_HERE, |
141 base::Bind(&ReadMimeTypeFromFile, filename_, | 142 base::Bind(&ReadMimeTypeFromFile, filename_, |
142 base::Unretained(read_mime_type), | 143 base::Unretained(read_mime_type), |
143 base::Unretained(read_result)), | 144 base::Unretained(read_result)), |
144 base::Bind(&URLRequestResourceBundleJob::OnMimeTypeRead, | 145 base::Bind(&URLRequestResourceBundleJob::OnMimeTypeRead, |
145 weak_factory_.GetWeakPtr(), | 146 weak_factory_.GetWeakPtr(), |
146 mime_type, charset, data, | 147 mime_type, charset, data, |
147 base::Owned(read_mime_type), | 148 base::Owned(read_mime_type), |
148 base::Owned(read_result), | 149 base::Owned(read_result), |
149 callback), | 150 callback)); |
150 true /* task is slow */); | |
151 DCHECK(posted); | 151 DCHECK(posted); |
152 | 152 |
153 return net::ERR_IO_PENDING; | 153 return net::ERR_IO_PENDING; |
154 } | 154 } |
155 | 155 |
156 virtual void GetResponseInfo(net::HttpResponseInfo* info) OVERRIDE { | 156 virtual void GetResponseInfo(net::HttpResponseInfo* info) OVERRIDE { |
157 *info = response_info_; | 157 *info = response_info_; |
158 } | 158 } |
159 | 159 |
160 private: | 160 private: |
(...skipping 83 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
244 | 244 |
245 class URLRequestExtensionJob : public net::URLRequestFileJob { | 245 class URLRequestExtensionJob : public net::URLRequestFileJob { |
246 public: | 246 public: |
247 URLRequestExtensionJob(net::URLRequest* request, | 247 URLRequestExtensionJob(net::URLRequest* request, |
248 net::NetworkDelegate* network_delegate, | 248 net::NetworkDelegate* network_delegate, |
249 const std::string& extension_id, | 249 const std::string& extension_id, |
250 const base::FilePath& directory_path, | 250 const base::FilePath& directory_path, |
251 const base::FilePath& relative_path, | 251 const base::FilePath& relative_path, |
252 const std::string& content_security_policy, | 252 const std::string& content_security_policy, |
253 bool send_cors_header) | 253 bool send_cors_header) |
254 : net::URLRequestFileJob(request, network_delegate, base::FilePath()), | 254 : net::URLRequestFileJob( |
| 255 request, network_delegate, base::FilePath(), |
| 256 content::BrowserThread::GetBlockingPool()-> |
| 257 GetTaskRunnerWithShutdownBehavior( |
| 258 base::SequencedWorkerPool::SKIP_ON_SHUTDOWN)), |
255 // TODO(tc): Move all of these files into resources.pak so we don't break | 259 // TODO(tc): Move all of these files into resources.pak so we don't break |
256 // when updating on Linux. | 260 // when updating on Linux. |
257 resource_(extension_id, directory_path, relative_path), | 261 resource_(extension_id, directory_path, relative_path), |
258 content_security_policy_(content_security_policy), | 262 content_security_policy_(content_security_policy), |
259 send_cors_header_(send_cors_header), | 263 send_cors_header_(send_cors_header), |
260 weak_factory_(this) { | 264 weak_factory_(this) { |
261 } | 265 } |
262 | 266 |
263 virtual void GetResponseInfo(net::HttpResponseInfo* info) OVERRIDE { | 267 virtual void GetResponseInfo(net::HttpResponseInfo* info) OVERRIDE { |
264 *info = response_info_; | 268 *info = response_info_; |
265 } | 269 } |
266 | 270 |
267 virtual void Start() OVERRIDE { | 271 virtual void Start() OVERRIDE { |
268 base::FilePath* read_file_path = new base::FilePath; | 272 base::FilePath* read_file_path = new base::FilePath; |
269 base::Time* last_modified_time = new base::Time(); | 273 base::Time* last_modified_time = new base::Time(); |
270 bool posted = base::WorkerPool::PostTaskAndReply( | 274 bool posted = content::BrowserThread::PostBlockingPoolTaskAndReply( |
271 FROM_HERE, | 275 FROM_HERE, |
272 base::Bind(&ReadResourceFilePathAndLastModifiedTime, resource_, | 276 base::Bind(&ReadResourceFilePathAndLastModifiedTime, resource_, |
273 base::Unretained(read_file_path), | 277 base::Unretained(read_file_path), |
274 base::Unretained(last_modified_time)), | 278 base::Unretained(last_modified_time)), |
275 base::Bind(&URLRequestExtensionJob::OnFilePathAndLastModifiedTimeRead, | 279 base::Bind(&URLRequestExtensionJob::OnFilePathAndLastModifiedTimeRead, |
276 weak_factory_.GetWeakPtr(), | 280 weak_factory_.GetWeakPtr(), |
277 base::Owned(read_file_path), | 281 base::Owned(read_file_path), |
278 base::Owned(last_modified_time)), | 282 base::Owned(last_modified_time))); |
279 true /* task is slow */); | |
280 DCHECK(posted); | 283 DCHECK(posted); |
281 } | 284 } |
282 | 285 |
283 private: | 286 private: |
284 virtual ~URLRequestExtensionJob() {} | 287 virtual ~URLRequestExtensionJob() {} |
285 | 288 |
286 void OnFilePathAndLastModifiedTimeRead(base::FilePath* read_file_path, | 289 void OnFilePathAndLastModifiedTimeRead(base::FilePath* read_file_path, |
287 base::Time* last_modified_time) { | 290 base::Time* last_modified_time) { |
288 file_path_ = *read_file_path; | 291 file_path_ = *read_file_path; |
289 response_info_.headers = BuildHttpHeaders( | 292 response_info_.headers = BuildHttpHeaders( |
(...skipping 272 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
562 send_cors_header); | 565 send_cors_header); |
563 } | 566 } |
564 | 567 |
565 } // namespace | 568 } // namespace |
566 | 569 |
567 net::URLRequestJobFactory::ProtocolHandler* CreateExtensionProtocolHandler( | 570 net::URLRequestJobFactory::ProtocolHandler* CreateExtensionProtocolHandler( |
568 bool is_incognito, | 571 bool is_incognito, |
569 ExtensionInfoMap* extension_info_map) { | 572 ExtensionInfoMap* extension_info_map) { |
570 return new ExtensionProtocolHandler(is_incognito, extension_info_map); | 573 return new ExtensionProtocolHandler(is_incognito, extension_info_map); |
571 } | 574 } |
OLD | NEW |