| OLD | NEW |
| 1 // Copyright (c) 2010 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2010 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 "app/resource_bundle.h" | 9 #include "app/resource_bundle.h" |
| 10 #include "base/file_path.h" | 10 #include "base/file_path.h" |
| (...skipping 14 matching lines...) Expand all Loading... |
| 25 #include "googleurl/src/url_util.h" | 25 #include "googleurl/src/url_util.h" |
| 26 #include "grit/bookmark_manager_resources_map.h" | 26 #include "grit/bookmark_manager_resources_map.h" |
| 27 #include "net/base/mime_util.h" | 27 #include "net/base/mime_util.h" |
| 28 #include "net/base/net_errors.h" | 28 #include "net/base/net_errors.h" |
| 29 #include "net/url_request/url_request_error_job.h" | 29 #include "net/url_request/url_request_error_job.h" |
| 30 #include "net/url_request/url_request_file_job.h" | 30 #include "net/url_request/url_request_file_job.h" |
| 31 #include "net/url_request/url_request_simple_job.h" | 31 #include "net/url_request/url_request_simple_job.h" |
| 32 | 32 |
| 33 namespace { | 33 namespace { |
| 34 | 34 |
| 35 class URLRequestResourceBundleJob : public URLRequestSimpleJob { | 35 class URLRequestResourceBundleJob : public net::URLRequestSimpleJob { |
| 36 public: | 36 public: |
| 37 explicit URLRequestResourceBundleJob(net::URLRequest* request, | 37 explicit URLRequestResourceBundleJob(net::URLRequest* request, |
| 38 const FilePath& filename, int resource_id) | 38 const FilePath& filename, int resource_id) |
| 39 : URLRequestSimpleJob(request), | 39 : net::URLRequestSimpleJob(request), |
| 40 filename_(filename), | 40 filename_(filename), |
| 41 resource_id_(resource_id) { } | 41 resource_id_(resource_id) { } |
| 42 | 42 |
| 43 // URLRequestSimpleJob method. | 43 // Overridden from URLRequestSimpleJob: |
| 44 virtual bool GetData(std::string* mime_type, | 44 virtual bool GetData(std::string* mime_type, |
| 45 std::string* charset, | 45 std::string* charset, |
| 46 std::string* data) const { | 46 std::string* data) const { |
| 47 const ResourceBundle& rb = ResourceBundle::GetSharedInstance(); | 47 const ResourceBundle& rb = ResourceBundle::GetSharedInstance(); |
| 48 *data = rb.GetRawDataResource(resource_id_).as_string(); | 48 *data = rb.GetRawDataResource(resource_id_).as_string(); |
| 49 bool result = net::GetMimeTypeFromFile(filename_, mime_type); | 49 bool result = net::GetMimeTypeFromFile(filename_, mime_type); |
| 50 if (StartsWithASCII(*mime_type, "text/", false)) { | 50 if (StartsWithASCII(*mime_type, "text/", false)) { |
| 51 // All of our HTML files should be UTF-8 and for other resource types | 51 // All of our HTML files should be UTF-8 and for other resource types |
| 52 // (like images), charset doesn't matter. | 52 // (like images), charset doesn't matter. |
| 53 DCHECK(IsStringUTF8(*data)); | 53 DCHECK(IsStringUTF8(*data)); |
| (...skipping 164 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 218 | 218 |
| 219 return new net::URLRequestFileJob(request, resource.GetFilePath()); | 219 return new net::URLRequestFileJob(request, resource.GetFilePath()); |
| 220 } | 220 } |
| 221 | 221 |
| 222 void RegisterExtensionProtocols() { | 222 void RegisterExtensionProtocols() { |
| 223 net::URLRequest::RegisterProtocolFactory(chrome::kExtensionScheme, | 223 net::URLRequest::RegisterProtocolFactory(chrome::kExtensionScheme, |
| 224 &CreateExtensionURLRequestJob); | 224 &CreateExtensionURLRequestJob); |
| 225 net::URLRequest::RegisterProtocolFactory(chrome::kUserScriptScheme, | 225 net::URLRequest::RegisterProtocolFactory(chrome::kUserScriptScheme, |
| 226 &CreateUserScriptURLRequestJob); | 226 &CreateUserScriptURLRequestJob); |
| 227 } | 227 } |
| OLD | NEW |