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 126 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
137 << "access to the requesting page."; | 137 << "access to the requesting page."; |
138 return false; | 138 return false; |
139 } | 139 } |
140 } | 140 } |
141 } | 141 } |
142 | 142 |
143 } // namespace | 143 } // namespace |
144 | 144 |
145 // Factory registered with net::URLRequest to create URLRequestJobs for | 145 // Factory registered with net::URLRequest to create URLRequestJobs for |
146 // extension:// URLs. | 146 // extension:// URLs. |
147 static URLRequestJob* CreateExtensionURLRequestJob(net::URLRequest* request, | 147 static net::URLRequestJob* CreateExtensionURLRequestJob( |
148 const std::string& scheme) { | 148 net::URLRequest* request, |
| 149 const std::string& scheme) { |
149 ChromeURLRequestContext* context = | 150 ChromeURLRequestContext* context = |
150 static_cast<ChromeURLRequestContext*>(request->context()); | 151 static_cast<ChromeURLRequestContext*>(request->context()); |
151 | 152 |
152 // TODO(mpcomplete): better error code. | 153 // TODO(mpcomplete): better error code. |
153 if (!AllowExtensionResourceLoad(request, context, scheme)) | 154 if (!AllowExtensionResourceLoad(request, context, scheme)) |
154 return new URLRequestErrorJob(request, net::ERR_ADDRESS_UNREACHABLE); | 155 return new URLRequestErrorJob(request, net::ERR_ADDRESS_UNREACHABLE); |
155 | 156 |
156 // chrome-extension://extension-id/resource/path.js | 157 // chrome-extension://extension-id/resource/path.js |
157 const std::string& extension_id = request->url().host(); | 158 const std::string& extension_id = request->url().host(); |
158 FilePath directory_path = context->extension_info_map()-> | 159 FilePath directory_path = context->extension_info_map()-> |
(...skipping 37 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
196 // Getting the file path will touch the file system. Fixing | 197 // Getting the file path will touch the file system. Fixing |
197 // crbug.com/59849 would also fix this. Suppress the error for now. | 198 // crbug.com/59849 would also fix this. Suppress the error for now. |
198 base::ThreadRestrictions::ScopedAllowIO allow_io; | 199 base::ThreadRestrictions::ScopedAllowIO allow_io; |
199 resource_file_path = resource.GetFilePath(); | 200 resource_file_path = resource.GetFilePath(); |
200 } | 201 } |
201 return new URLRequestFileJob(request, resource_file_path); | 202 return new URLRequestFileJob(request, resource_file_path); |
202 } | 203 } |
203 | 204 |
204 // Factory registered with net::URLRequest to create URLRequestJobs for | 205 // Factory registered with net::URLRequest to create URLRequestJobs for |
205 // chrome-user-script:/ URLs. | 206 // chrome-user-script:/ URLs. |
206 static URLRequestJob* CreateUserScriptURLRequestJob(net::URLRequest* request, | 207 static net::URLRequestJob* CreateUserScriptURLRequestJob( |
207 const std::string& scheme) { | 208 net::URLRequest* request, |
| 209 const std::string& scheme) { |
208 ChromeURLRequestContext* context = | 210 ChromeURLRequestContext* context = |
209 static_cast<ChromeURLRequestContext*>(request->context()); | 211 static_cast<ChromeURLRequestContext*>(request->context()); |
210 | 212 |
211 // chrome-user-script:/user-script-name.user.js | 213 // chrome-user-script:/user-script-name.user.js |
212 FilePath directory_path = context->user_script_dir_path(); | 214 FilePath directory_path = context->user_script_dir_path(); |
213 | 215 |
214 ExtensionResource resource(request->url().host(), directory_path, | 216 ExtensionResource resource(request->url().host(), directory_path, |
215 extension_file_util::ExtensionURLToRelativeFilePath(request->url())); | 217 extension_file_util::ExtensionURLToRelativeFilePath(request->url())); |
216 | 218 |
217 return new URLRequestFileJob(request, resource.GetFilePath()); | 219 return new URLRequestFileJob(request, resource.GetFilePath()); |
218 } | 220 } |
219 | 221 |
220 void RegisterExtensionProtocols() { | 222 void RegisterExtensionProtocols() { |
221 net::URLRequest::RegisterProtocolFactory(chrome::kExtensionScheme, | 223 net::URLRequest::RegisterProtocolFactory(chrome::kExtensionScheme, |
222 &CreateExtensionURLRequestJob); | 224 &CreateExtensionURLRequestJob); |
223 net::URLRequest::RegisterProtocolFactory(chrome::kUserScriptScheme, | 225 net::URLRequest::RegisterProtocolFactory(chrome::kUserScriptScheme, |
224 &CreateUserScriptURLRequestJob); | 226 &CreateUserScriptURLRequestJob); |
225 } | 227 } |
OLD | NEW |