| 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/compiler_specific.h" | 9 #include "base/compiler_specific.h" |
| 10 #include "base/file_path.h" | 10 #include "base/file_path.h" |
| 11 #include "base/logging.h" | 11 #include "base/logging.h" |
| 12 #include "base/message_loop.h" | 12 #include "base/message_loop.h" |
| 13 #include "base/path_service.h" | 13 #include "base/path_service.h" |
| 14 #include "base/string_util.h" | 14 #include "base/string_util.h" |
| 15 #include "base/stringprintf.h" | 15 #include "base/stringprintf.h" |
| 16 #include "base/threading/thread_restrictions.h" | 16 #include "base/threading/thread_restrictions.h" |
| 17 #include "build/build_config.h" | 17 #include "build/build_config.h" |
| 18 #include "chrome/browser/extensions/extension_info_map.h" | 18 #include "chrome/browser/extensions/extension_info_map.h" |
| 19 #include "chrome/browser/net/chrome_url_request_context.h" | 19 #include "chrome/browser/net/chrome_url_request_context.h" |
| 20 #include "chrome/common/chrome_paths.h" | 20 #include "chrome/common/chrome_paths.h" |
| 21 #include "chrome/common/extensions/extension.h" | 21 #include "chrome/common/extensions/extension.h" |
| 22 #include "chrome/common/extensions/extension_file_util.h" | 22 #include "chrome/common/extensions/extension_file_util.h" |
| 23 #include "chrome/common/extensions/extension_resource.h" | 23 #include "chrome/common/extensions/extension_resource.h" |
| 24 #include "chrome/common/url_constants.h" | 24 #include "chrome/common/url_constants.h" |
| 25 #include "content/public/browser/resource_request_info.h" | 25 #include "content/public/browser/resource_request_info.h" |
| 26 #include "googleurl/src/url_util.h" | 26 #include "googleurl/src/url_util.h" |
| 27 #include "grit/component_extension_resources_map.h" | 27 #include "grit/component_extension_resources_map.h" |
| 28 #include "net/base/mime_util.h" | 28 #include "net/base/mime_util.h" |
| 29 #include "net/base/net_errors.h" | 29 #include "net/base/net_errors.h" |
| 30 #include "net/http/http_response_headers.h" |
| 30 #include "net/http/http_response_info.h" | 31 #include "net/http/http_response_info.h" |
| 31 #include "net/http/http_response_headers.h" | |
| 32 #include "net/url_request/url_request_error_job.h" | 32 #include "net/url_request/url_request_error_job.h" |
| 33 #include "net/url_request/url_request_file_job.h" | 33 #include "net/url_request/url_request_file_job.h" |
| 34 #include "net/url_request/url_request_simple_job.h" | 34 #include "net/url_request/url_request_simple_job.h" |
| 35 #include "ui/base/layout.h" |
| 35 #include "ui/base/resource/resource_bundle.h" | 36 #include "ui/base/resource/resource_bundle.h" |
| 36 | 37 |
| 37 using content::ResourceRequestInfo; | 38 using content::ResourceRequestInfo; |
| 38 using extensions::Extension; | 39 using extensions::Extension; |
| 39 | 40 |
| 40 namespace { | 41 namespace { |
| 41 | 42 |
| 42 net::HttpResponseHeaders* BuildHttpHeaders( | 43 net::HttpResponseHeaders* BuildHttpHeaders( |
| 43 const std::string& content_security_policy, bool send_cors_header) { | 44 const std::string& content_security_policy, bool send_cors_header) { |
| 44 std::string raw_headers; | 45 std::string raw_headers; |
| (...skipping 22 matching lines...) Expand all Loading... |
| 67 resource_id_(resource_id) { | 68 resource_id_(resource_id) { |
| 68 response_info_.headers = BuildHttpHeaders(content_security_policy, | 69 response_info_.headers = BuildHttpHeaders(content_security_policy, |
| 69 send_cors_header); | 70 send_cors_header); |
| 70 } | 71 } |
| 71 | 72 |
| 72 // Overridden from URLRequestSimpleJob: | 73 // Overridden from URLRequestSimpleJob: |
| 73 virtual bool GetData(std::string* mime_type, | 74 virtual bool GetData(std::string* mime_type, |
| 74 std::string* charset, | 75 std::string* charset, |
| 75 std::string* data) const OVERRIDE { | 76 std::string* data) const OVERRIDE { |
| 76 const ResourceBundle& rb = ResourceBundle::GetSharedInstance(); | 77 const ResourceBundle& rb = ResourceBundle::GetSharedInstance(); |
| 77 *data = rb.GetRawDataResource(resource_id_).as_string(); | 78 *data = rb.GetRawDataResource( |
| 79 resource_id_, ui::SCALE_FACTOR_NONE).as_string(); |
| 78 | 80 |
| 79 // Requests should not block on the disk! On Windows this goes to the | 81 // Requests should not block on the disk! On Windows this goes to the |
| 80 // registry. | 82 // registry. |
| 81 // http://code.google.com/p/chromium/issues/detail?id=59849 | 83 // http://code.google.com/p/chromium/issues/detail?id=59849 |
| 82 bool result; | 84 bool result; |
| 83 { | 85 { |
| 84 base::ThreadRestrictions::ScopedAllowIO allow_io; | 86 base::ThreadRestrictions::ScopedAllowIO allow_io; |
| 85 result = net::GetMimeTypeFromFile(filename_, mime_type); | 87 result = net::GetMimeTypeFromFile(filename_, mime_type); |
| 86 } | 88 } |
| 87 | 89 |
| (...skipping 240 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 328 content_security_policy, send_cors_header); | 330 content_security_policy, send_cors_header); |
| 329 } | 331 } |
| 330 | 332 |
| 331 } // namespace | 333 } // namespace |
| 332 | 334 |
| 333 net::URLRequestJobFactory::ProtocolHandler* CreateExtensionProtocolHandler( | 335 net::URLRequestJobFactory::ProtocolHandler* CreateExtensionProtocolHandler( |
| 334 bool is_incognito, | 336 bool is_incognito, |
| 335 ExtensionInfoMap* extension_info_map) { | 337 ExtensionInfoMap* extension_info_map) { |
| 336 return new ExtensionProtocolHandler(is_incognito, extension_info_map); | 338 return new ExtensionProtocolHandler(is_incognito, extension_info_map); |
| 337 } | 339 } |
| OLD | NEW |