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" |
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/thread_restrictions.h" | 15 #include "base/thread_restrictions.h" |
16 #include "build/build_config.h" | 16 #include "build/build_config.h" |
17 #include "chrome/browser/net/chrome_url_request_context.h" | 17 #include "chrome/browser/net/chrome_url_request_context.h" |
18 #include "chrome/browser/renderer_host/resource_dispatcher_host.h" | 18 #include "chrome/browser/renderer_host/resource_dispatcher_host.h" |
19 #include "chrome/browser/renderer_host/resource_dispatcher_host_request_info.h" | 19 #include "chrome/browser/renderer_host/resource_dispatcher_host_request_info.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 "googleurl/src/url_util.h" | 25 #include "googleurl/src/url_util.h" |
26 #include "grit/bookmark_manager_resources_map.h" | 26 #include "grit/component_extension_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 net::URLRequestSimpleJob { | 35 class URLRequestResourceBundleJob : public net::URLRequestSimpleJob { |
36 public: | 36 public: |
(...skipping 131 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
168 directory_path.DirName() == resources_path) { | 168 directory_path.DirName() == resources_path) { |
169 FilePath relative_path = directory_path.BaseName().Append( | 169 FilePath relative_path = directory_path.BaseName().Append( |
170 extension_file_util::ExtensionURLToRelativeFilePath(request->url())); | 170 extension_file_util::ExtensionURLToRelativeFilePath(request->url())); |
171 #if defined(OS_WIN) | 171 #if defined(OS_WIN) |
172 relative_path = relative_path.NormalizeWindowsPathSeparators(); | 172 relative_path = relative_path.NormalizeWindowsPathSeparators(); |
173 #endif | 173 #endif |
174 | 174 |
175 // TODO(tc): Make a map of FilePath -> resource ids so we don't have to | 175 // TODO(tc): Make a map of FilePath -> resource ids so we don't have to |
176 // covert to FilePaths all the time. This will be more useful as we add | 176 // covert to FilePaths all the time. This will be more useful as we add |
177 // more resources. | 177 // more resources. |
178 for (size_t i = 0; i < kBookmarkManagerResourcesSize; ++i) { | 178 for (size_t i = 0; i < kComponentExtensionResourcesSize; ++i) { |
179 FilePath bm_resource_path = | 179 FilePath bm_resource_path = |
180 FilePath().AppendASCII(kBookmarkManagerResources[i].name); | 180 FilePath().AppendASCII(kComponentExtensionResources[i].name); |
181 #if defined(OS_WIN) | 181 #if defined(OS_WIN) |
182 bm_resource_path = bm_resource_path.NormalizeWindowsPathSeparators(); | 182 bm_resource_path = bm_resource_path.NormalizeWindowsPathSeparators(); |
183 #endif | 183 #endif |
184 if (relative_path == bm_resource_path) { | 184 if (relative_path == bm_resource_path) { |
185 return new URLRequestResourceBundleJob(request, relative_path, | 185 return new URLRequestResourceBundleJob(request, relative_path, |
186 kBookmarkManagerResources[i].value); | 186 kComponentExtensionResources[i].value); |
187 } | 187 } |
188 } | 188 } |
189 } | 189 } |
190 // TODO(tc): Move all of these files into resources.pak so we don't break | 190 // TODO(tc): Move all of these files into resources.pak so we don't break |
191 // when updating on Linux. | 191 // when updating on Linux. |
192 ExtensionResource resource(extension_id, directory_path, | 192 ExtensionResource resource(extension_id, directory_path, |
193 extension_file_util::ExtensionURLToRelativeFilePath(request->url())); | 193 extension_file_util::ExtensionURLToRelativeFilePath(request->url())); |
194 | 194 |
195 FilePath resource_file_path; | 195 FilePath resource_file_path; |
196 { | 196 { |
(...skipping 21 matching lines...) Expand all 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 |