Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(8)

Side by Side Diff: chrome/browser/extensions/extension_protocols.cc

Issue 9909019: Add schema chrome-extension-resource:// for extension resources (Closed) Base URL: http://git.chromium.org/chromium/src.git@master
Patch Set: Update Created 8 years, 8 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
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"
(...skipping 222 matching lines...) Expand 10 before | Expand all | Expand 10 after
233 233
234 virtual net::URLRequestJob* MaybeCreateJob( 234 virtual net::URLRequestJob* MaybeCreateJob(
235 net::URLRequest* request) const OVERRIDE; 235 net::URLRequest* request) const OVERRIDE;
236 236
237 private: 237 private:
238 const bool is_incognito_; 238 const bool is_incognito_;
239 ExtensionInfoMap* const extension_info_map_; 239 ExtensionInfoMap* const extension_info_map_;
240 DISALLOW_COPY_AND_ASSIGN(ExtensionProtocolHandler); 240 DISALLOW_COPY_AND_ASSIGN(ExtensionProtocolHandler);
241 }; 241 };
242 242
243 // Creates URLRequestJobs for extension:// URLs. 243 // Creates URLRequestJobs for chrome-extension:// URLs.
244 net::URLRequestJob* 244 net::URLRequestJob*
245 ExtensionProtocolHandler::MaybeCreateJob(net::URLRequest* request) const { 245 ExtensionProtocolHandler::MaybeCreateJob(net::URLRequest* request) const {
246 // TODO(mpcomplete): better error code. 246 // TODO(mpcomplete): better error code.
247 if (!AllowExtensionResourceLoad( 247 if (!AllowExtensionResourceLoad(
248 request, is_incognito_, extension_info_map_)) { 248 request, is_incognito_, extension_info_map_)) {
249 return new net::URLRequestErrorJob(request, net::ERR_ADDRESS_UNREACHABLE); 249 return new net::URLRequestErrorJob(request, net::ERR_ADDRESS_UNREACHABLE);
250 } 250 }
251 251
252 // chrome-extension://extension-id/resource/path.js 252 // chrome-extension://extension-id/resource/path.js
253 const std::string& extension_id = request->url().host(); 253 const std::string& extension_id = request->url().host();
(...skipping 61 matching lines...) Expand 10 before | Expand all | Expand 10 after
315 // Getting the file path will touch the file system. Fixing 315 // Getting the file path will touch the file system. Fixing
316 // crbug.com/59849 would also fix this. Suppress the error for now. 316 // crbug.com/59849 would also fix this. Suppress the error for now.
317 base::ThreadRestrictions::ScopedAllowIO allow_io; 317 base::ThreadRestrictions::ScopedAllowIO allow_io;
318 resource_file_path = resource.GetFilePath(); 318 resource_file_path = resource.GetFilePath();
319 } 319 }
320 320
321 return new URLRequestExtensionJob(request, resource_file_path, 321 return new URLRequestExtensionJob(request, resource_file_path,
322 content_security_policy, send_cors_header); 322 content_security_policy, send_cors_header);
323 } 323 }
324 324
325 class ExtensionResourceProtocolHandler
326 : public net::URLRequestJobFactory::ProtocolHandler {
327 public:
328 ExtensionResourceProtocolHandler() {}
329 virtual ~ExtensionResourceProtocolHandler() {}
330
331 virtual net::URLRequestJob* MaybeCreateJob(
332 net::URLRequest* request) const OVERRIDE;
333
334 private:
335 DISALLOW_COPY_AND_ASSIGN(ExtensionResourceProtocolHandler);
336 };
337
338 // Creates URLRequestJobs for chrome-extension-resource:// URLs.
339 net::URLRequestJob*
340 ExtensionResourceProtocolHandler::MaybeCreateJob(
341 net::URLRequest* request) const {
342 if (!request->url().has_host() || !request->url().has_path())
343 return NULL;
344
345 FilePath path;
346 PathService::Get(chrome::DIR_RESOURCES_EXTENSION, &path);
miket_OOO 2012/04/12 18:38:39 Is this the EXT from the other CL? Did you want it
Peng 2012/04/12 20:13:22 I renamed it from EXT to extension. Because it is
347 path = path.Append(request->url().host()).Append(request->url().path());
miket_OOO 2012/04/12 18:38:39 I'm not sure whether request has already been sani
Peng 2012/04/12 20:13:22 Done
348
349 return new net::URLRequestFileJob(request, path);
350 }
351
325 } // namespace 352 } // namespace
326 353
327 net::URLRequestJobFactory::ProtocolHandler* CreateExtensionProtocolHandler( 354 net::URLRequestJobFactory::ProtocolHandler* CreateExtensionProtocolHandler(
328 bool is_incognito, 355 bool is_incognito,
329 ExtensionInfoMap* extension_info_map) { 356 ExtensionInfoMap* extension_info_map) {
330 return new ExtensionProtocolHandler(is_incognito, extension_info_map); 357 return new ExtensionProtocolHandler(is_incognito, extension_info_map);
331 } 358 }
359
360 net::URLRequestJobFactory::ProtocolHandler*
361 CreateExtensionResourceProtocolHandler(
362 bool is_incognito,
363 ExtensionInfoMap* extension_info_map) {
364 return new ExtensionResourceProtocolHandler();
miket_OOO 2012/04/12 18:38:39 Is there a reason these arguments need to be in th
Peng 2012/04/12 20:13:22 I copied & pasted it. I think it may be useful in
365 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698