| OLD | NEW |
| 1 // Copyright 2014 The Chromium Authors. All rights reserved. | 1 // Copyright 2014 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 "extensions/browser/extension_protocols.h" | 5 #include "extensions/browser/extension_protocols.h" |
| 6 | 6 |
| 7 #include <stddef.h> | 7 #include <stddef.h> |
| 8 #include <stdint.h> | 8 #include <stdint.h> |
| 9 | 9 |
| 10 #include <algorithm> | 10 #include <algorithm> |
| (...skipping 374 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 385 return false; | 385 return false; |
| 386 } | 386 } |
| 387 | 387 |
| 388 // Returns true if the given URL references an icon in the given extension. | 388 // Returns true if the given URL references an icon in the given extension. |
| 389 bool URLIsForExtensionIcon(const GURL& url, const Extension* extension) { | 389 bool URLIsForExtensionIcon(const GURL& url, const Extension* extension) { |
| 390 DCHECK(url.SchemeIs(extensions::kExtensionScheme)); | 390 DCHECK(url.SchemeIs(extensions::kExtensionScheme)); |
| 391 | 391 |
| 392 if (!extension) | 392 if (!extension) |
| 393 return false; | 393 return false; |
| 394 | 394 |
| 395 std::string path = url.path(); | 395 std::string path = url.path().as_string(); |
| 396 DCHECK_EQ(url.host(), extension->id()); | 396 DCHECK_EQ(url.host(), extension->id()); |
| 397 DCHECK(path.length() > 0 && path[0] == '/'); | 397 DCHECK(path.length() > 0 && path[0] == '/'); |
| 398 path = path.substr(1); | 398 path = path.substr(1); |
| 399 return extensions::IconsInfo::GetIcons(extension).ContainsPath(path); | 399 return extensions::IconsInfo::GetIcons(extension).ContainsPath(path); |
| 400 } | 400 } |
| 401 | 401 |
| 402 class ExtensionProtocolHandler | 402 class ExtensionProtocolHandler |
| 403 : public net::URLRequestJobFactory::ProtocolHandler { | 403 : public net::URLRequestJobFactory::ProtocolHandler { |
| 404 public: | 404 public: |
| 405 ExtensionProtocolHandler(bool is_incognito, | 405 ExtensionProtocolHandler(bool is_incognito, |
| (...skipping 41 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 447 return NULL; | 447 return NULL; |
| 448 } | 448 } |
| 449 } | 449 } |
| 450 | 450 |
| 451 // Set up content security policy. | 451 // Set up content security policy. |
| 452 std::string content_security_policy; | 452 std::string content_security_policy; |
| 453 bool send_cors_header = false; | 453 bool send_cors_header = false; |
| 454 bool follow_symlinks_anywhere = false; | 454 bool follow_symlinks_anywhere = false; |
| 455 | 455 |
| 456 if (extension) { | 456 if (extension) { |
| 457 std::string resource_path = request->url().path(); | 457 std::string resource_path = request->url().path().as_string(); |
| 458 | 458 |
| 459 // Use default CSP for <webview>. | 459 // Use default CSP for <webview>. |
| 460 if (!url_request_util::IsWebViewRequest(request)) { | 460 if (!url_request_util::IsWebViewRequest(request)) { |
| 461 content_security_policy = | 461 content_security_policy = |
| 462 extensions::CSPInfo::GetResourceContentSecurityPolicy(extension, | 462 extensions::CSPInfo::GetResourceContentSecurityPolicy(extension, |
| 463 resource_path); | 463 resource_path); |
| 464 } | 464 } |
| 465 | 465 |
| 466 if ((extension->manifest_version() >= 2 || | 466 if ((extension->manifest_version() >= 2 || |
| 467 extensions::WebAccessibleResourcesInfo::HasWebAccessibleResources( | 467 extensions::WebAccessibleResourcesInfo::HasWebAccessibleResources( |
| 468 extension)) && | 468 extension)) && |
| 469 extensions::WebAccessibleResourcesInfo::IsResourceWebAccessible( | 469 extensions::WebAccessibleResourcesInfo::IsResourceWebAccessible( |
| 470 extension, resource_path)) { | 470 extension, resource_path)) { |
| 471 send_cors_header = true; | 471 send_cors_header = true; |
| 472 } | 472 } |
| 473 | 473 |
| 474 follow_symlinks_anywhere = | 474 follow_symlinks_anywhere = |
| 475 (extension->creation_flags() & Extension::FOLLOW_SYMLINKS_ANYWHERE) | 475 (extension->creation_flags() & Extension::FOLLOW_SYMLINKS_ANYWHERE) |
| 476 != 0; | 476 != 0; |
| 477 } | 477 } |
| 478 | 478 |
| 479 // Create a job for a generated background page. | 479 // Create a job for a generated background page. |
| 480 std::string path = request->url().path(); | 480 std::string path = request->url().path().as_string(); |
| 481 if (path.size() > 1 && | 481 if (path.size() > 1 && |
| 482 path.substr(1) == extensions::kGeneratedBackgroundPageFilename) { | 482 path.substr(1) == extensions::kGeneratedBackgroundPageFilename) { |
| 483 return new GeneratedBackgroundPageJob( | 483 return new GeneratedBackgroundPageJob( |
| 484 request, network_delegate, extension, content_security_policy); | 484 request, network_delegate, extension, content_security_policy); |
| 485 } | 485 } |
| 486 | 486 |
| 487 // Component extension resources may be part of the embedder's resource files, | 487 // Component extension resources may be part of the embedder's resource files, |
| 488 // for example component_extension_resources.pak in Chrome. | 488 // for example component_extension_resources.pak in Chrome. |
| 489 net::URLRequestJob* resource_bundle_job = | 489 net::URLRequestJob* resource_bundle_job = |
| 490 extensions::ExtensionsBrowserClient::Get() | 490 extensions::ExtensionsBrowserClient::Get() |
| (...skipping 93 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 584 } | 584 } |
| 585 | 585 |
| 586 std::unique_ptr<net::URLRequestJobFactory::ProtocolHandler> | 586 std::unique_ptr<net::URLRequestJobFactory::ProtocolHandler> |
| 587 CreateExtensionProtocolHandler(bool is_incognito, | 587 CreateExtensionProtocolHandler(bool is_incognito, |
| 588 extensions::InfoMap* extension_info_map) { | 588 extensions::InfoMap* extension_info_map) { |
| 589 return base::MakeUnique<ExtensionProtocolHandler>(is_incognito, | 589 return base::MakeUnique<ExtensionProtocolHandler>(is_incognito, |
| 590 extension_info_map); | 590 extension_info_map); |
| 591 } | 591 } |
| 592 | 592 |
| 593 } // namespace extensions | 593 } // namespace extensions |
| OLD | NEW |