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 375 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
386 return false; | 386 return false; |
387 } | 387 } |
388 | 388 |
389 // Returns true if the given URL references an icon in the given extension. | 389 // Returns true if the given URL references an icon in the given extension. |
390 bool URLIsForExtensionIcon(const GURL& url, const Extension* extension) { | 390 bool URLIsForExtensionIcon(const GURL& url, const Extension* extension) { |
391 DCHECK(url.SchemeIs(extensions::kExtensionScheme)); | 391 DCHECK(url.SchemeIs(extensions::kExtensionScheme)); |
392 | 392 |
393 if (!extension) | 393 if (!extension) |
394 return false; | 394 return false; |
395 | 395 |
396 std::string path = url.path(); | |
397 DCHECK_EQ(url.host(), extension->id()); | 396 DCHECK_EQ(url.host(), extension->id()); |
| 397 base::StringPiece path = url.path_piece(); |
398 DCHECK(path.length() > 0 && path[0] == '/'); | 398 DCHECK(path.length() > 0 && path[0] == '/'); |
399 path = path.substr(1); | 399 base::StringPiece path_without_slash = path.substr(1); |
400 return extensions::IconsInfo::GetIcons(extension).ContainsPath(path); | 400 return extensions::IconsInfo::GetIcons(extension).ContainsPath( |
| 401 path_without_slash); |
401 } | 402 } |
402 | 403 |
403 class ExtensionProtocolHandler | 404 class ExtensionProtocolHandler |
404 : public net::URLRequestJobFactory::ProtocolHandler { | 405 : public net::URLRequestJobFactory::ProtocolHandler { |
405 public: | 406 public: |
406 ExtensionProtocolHandler(bool is_incognito, | 407 ExtensionProtocolHandler(bool is_incognito, |
407 extensions::InfoMap* extension_info_map) | 408 extensions::InfoMap* extension_info_map) |
408 : is_incognito_(is_incognito), extension_info_map_(extension_info_map) {} | 409 : is_incognito_(is_incognito), extension_info_map_(extension_info_map) {} |
409 | 410 |
410 ~ExtensionProtocolHandler() override {} | 411 ~ExtensionProtocolHandler() override {} |
(...skipping 186 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
597 extensions::InfoMap* extension_info_map) { | 598 extensions::InfoMap* extension_info_map) { |
598 return base::MakeUnique<ExtensionProtocolHandler>(is_incognito, | 599 return base::MakeUnique<ExtensionProtocolHandler>(is_incognito, |
599 extension_info_map); | 600 extension_info_map); |
600 } | 601 } |
601 | 602 |
602 void SetExtensionProtocolTestHandler(ExtensionProtocolTestHandler* handler) { | 603 void SetExtensionProtocolTestHandler(ExtensionProtocolTestHandler* handler) { |
603 g_test_handler = handler; | 604 g_test_handler = handler; |
604 } | 605 } |
605 | 606 |
606 } // namespace extensions | 607 } // namespace extensions |
OLD | NEW |