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

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

Issue 13971005: Basic multi-module support (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 7 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/files/file_path.h" 10 #include "base/files/file_path.h"
(...skipping 187 matching lines...) Expand 10 before | Expand all | Expand 10 after
198 base::FilePath* file_path) { 198 base::FilePath* file_path) {
199 *file_path = resource.GetFilePath(); 199 *file_path = resource.GetFilePath();
200 } 200 }
201 201
202 class URLRequestExtensionJob : public net::URLRequestFileJob { 202 class URLRequestExtensionJob : public net::URLRequestFileJob {
203 public: 203 public:
204 URLRequestExtensionJob(net::URLRequest* request, 204 URLRequestExtensionJob(net::URLRequest* request,
205 net::NetworkDelegate* network_delegate, 205 net::NetworkDelegate* network_delegate,
206 const std::string& extension_id, 206 const std::string& extension_id,
207 const base::FilePath& directory_path, 207 const base::FilePath& directory_path,
208 const base::FilePath& relative_path,
208 const std::string& content_security_policy, 209 const std::string& content_security_policy,
209 bool send_cors_header) 210 bool send_cors_header)
210 : net::URLRequestFileJob(request, network_delegate, base::FilePath()), 211 : net::URLRequestFileJob(request, network_delegate, base::FilePath()),
211 // TODO(tc): Move all of these files into resources.pak so we don't break 212 // TODO(tc): Move all of these files into resources.pak so we don't break
212 // when updating on Linux. 213 // when updating on Linux.
213 resource_(extension_id, directory_path, 214 resource_(extension_id, directory_path, relative_path),
214 extension_file_util::ExtensionURLToRelativeFilePath(
215 request->url())),
216 weak_factory_(ALLOW_THIS_IN_INITIALIZER_LIST(this)) { 215 weak_factory_(ALLOW_THIS_IN_INITIALIZER_LIST(this)) {
217 response_info_.headers = BuildHttpHeaders(content_security_policy, 216 response_info_.headers = BuildHttpHeaders(content_security_policy,
218 send_cors_header); 217 send_cors_header);
219 } 218 }
220 219
221 virtual void GetResponseInfo(net::HttpResponseInfo* info) OVERRIDE { 220 virtual void GetResponseInfo(net::HttpResponseInfo* info) OVERRIDE {
222 *info = response_info_; 221 *info = response_info_;
223 } 222 }
224 223
225 virtual void Start() OVERRIDE { 224 virtual void Start() OVERRIDE {
(...skipping 155 matching lines...) Expand 10 before | Expand all | Expand 10 after
381 const bool is_incognito_; 380 const bool is_incognito_;
382 ExtensionInfoMap* const extension_info_map_; 381 ExtensionInfoMap* const extension_info_map_;
383 DISALLOW_COPY_AND_ASSIGN(ExtensionProtocolHandler); 382 DISALLOW_COPY_AND_ASSIGN(ExtensionProtocolHandler);
384 }; 383 };
385 384
386 // Creates URLRequestJobs for extension:// URLs. 385 // Creates URLRequestJobs for extension:// URLs.
387 net::URLRequestJob* 386 net::URLRequestJob*
388 ExtensionProtocolHandler::MaybeCreateJob( 387 ExtensionProtocolHandler::MaybeCreateJob(
389 net::URLRequest* request, net::NetworkDelegate* network_delegate) const { 388 net::URLRequest* request, net::NetworkDelegate* network_delegate) const {
390 // chrome-extension://extension-id/resource/path.js 389 // chrome-extension://extension-id/resource/path.js
391 const std::string& extension_id = request->url().host(); 390 std::string extension_id = request->url().host();
392 const Extension* extension = 391 const Extension* extension =
393 extension_info_map_->extensions().GetByID(extension_id); 392 extension_info_map_->extensions().GetByID(extension_id);
394 393
395 // TODO(mpcomplete): better error code. 394 // TODO(mpcomplete): better error code.
396 if (!AllowExtensionResourceLoad( 395 if (!AllowExtensionResourceLoad(
397 request, is_incognito_, extension, extension_info_map_)) { 396 request, is_incognito_, extension, extension_info_map_)) {
398 return new net::URLRequestErrorJob( 397 return new net::URLRequestErrorJob(
399 request, network_delegate, net::ERR_ADDRESS_UNREACHABLE); 398 request, network_delegate, net::ERR_ADDRESS_UNREACHABLE);
400 } 399 }
401 400
(...skipping 53 matching lines...) Expand 10 before | Expand all | Expand 10 after
455 return new URLRequestResourceBundleJob( 454 return new URLRequestResourceBundleJob(
456 request, 455 request,
457 network_delegate, 456 network_delegate,
458 relative_path, 457 relative_path,
459 resource_id, 458 resource_id,
460 content_security_policy, 459 content_security_policy,
461 send_cors_header); 460 send_cors_header);
462 } 461 }
463 } 462 }
464 463
464 relative_path =
465 extension_file_util::ExtensionURLToRelativeFilePath(request->url());
466
467 if (Extension::IsImportedPath(path)) {
468 std::string new_extension_id;
469 std::string new_relative_path;
470 Extension::ParseImportedPath(path, &new_extension_id, &new_relative_path);
471 const Extension* new_extension =
472 extension_info_map_->extensions().GetByID(new_extension_id);
473
474 bool first_party_in_import = false;
475 // NB: This first_party_for_cookies call is not for security, it is only
476 // used so an exported extension can limit the visible surface to the
477 // extension that imports it, more or less constituting its API.
478 const std::string& first_party_path =
479 request->first_party_for_cookies().path();
480 if (Extension::IsImportedPath(first_party_path)) {
481 std::string first_party_id;
482 std::string dummy;
483 Extension::ParseImportedPath(first_party_path, &first_party_id, &dummy);
484 if (first_party_id == new_extension_id) {
485 first_party_in_import = true;
486 }
487 }
488
489 if (extension->Imports(new_extension_id) &&
490 new_extension &&
491 (first_party_in_import ||
492 new_extension->IsExportAllowed(new_relative_path))) {
493 directory_path = new_extension->path();
494 extension_id = new_extension_id;
495 relative_path = base::FilePath(new_relative_path);
496 } else {
497 return NULL;
498 }
499 }
500
465 return new URLRequestExtensionJob(request, 501 return new URLRequestExtensionJob(request,
466 network_delegate, 502 network_delegate,
467 extension_id, 503 extension_id,
468 directory_path, 504 directory_path,
505 relative_path,
469 content_security_policy, 506 content_security_policy,
470 send_cors_header); 507 send_cors_header);
471 } 508 }
472 509
473 } // namespace 510 } // namespace
474 511
475 net::URLRequestJobFactory::ProtocolHandler* CreateExtensionProtocolHandler( 512 net::URLRequestJobFactory::ProtocolHandler* CreateExtensionProtocolHandler(
476 bool is_incognito, 513 bool is_incognito,
477 ExtensionInfoMap* extension_info_map) { 514 ExtensionInfoMap* extension_info_map) {
478 return new ExtensionProtocolHandler(is_incognito, extension_info_map); 515 return new ExtensionProtocolHandler(is_incognito, extension_info_map);
479 } 516 }
OLDNEW
« no previous file with comments | « no previous file | chrome/common/extensions/api/_manifest_features.json » ('j') | chrome/common/extensions/extension.h » ('J')

Powered by Google App Engine
This is Rietveld 408576698