OLD | NEW |
1 // Copyright (c) 2013 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2013 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/common/extension.h" | 5 #include "extensions/common/extension.h" |
6 | 6 |
| 7 #include <algorithm> |
| 8 |
7 #include "base/base64.h" | 9 #include "base/base64.h" |
8 #include "base/basictypes.h" | 10 #include "base/basictypes.h" |
9 #include "base/command_line.h" | 11 #include "base/command_line.h" |
| 12 #include "base/files/file_enumerator.h" |
10 #include "base/files/file_path.h" | 13 #include "base/files/file_path.h" |
| 14 #include "base/files/file_util.h" |
11 #include "base/i18n/rtl.h" | 15 #include "base/i18n/rtl.h" |
12 #include "base/logging.h" | 16 #include "base/logging.h" |
13 #include "base/memory/singleton.h" | 17 #include "base/memory/singleton.h" |
14 #include "base/stl_util.h" | 18 #include "base/stl_util.h" |
15 #include "base/strings/string16.h" | 19 #include "base/strings/string16.h" |
16 #include "base/strings/string_number_conversions.h" | 20 #include "base/strings/string_number_conversions.h" |
17 #include "base/strings/string_piece.h" | 21 #include "base/strings/string_piece.h" |
18 #include "base/strings/string_util.h" | 22 #include "base/strings/string_util.h" |
19 #include "base/strings/stringprintf.h" | 23 #include "base/strings/stringprintf.h" |
20 #include "base/strings/utf_string_conversions.h" | 24 #include "base/strings/utf_string_conversions.h" |
(...skipping 37 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
58 // We should disallow backslash '\\' as file path separator even on Windows, | 62 // We should disallow backslash '\\' as file path separator even on Windows, |
59 // because the backslash is not regarded as file path separator on Linux/Mac. | 63 // because the backslash is not regarded as file path separator on Linux/Mac. |
60 // Extensions are cross-platform. | 64 // Extensions are cross-platform. |
61 // Since FilePath uses backslash '\\' as file path separator on Windows, so we | 65 // Since FilePath uses backslash '\\' as file path separator on Windows, so we |
62 // need to check manually. | 66 // need to check manually. |
63 if (path.value().find('\\') != path.value().npos) | 67 if (path.value().find('\\') != path.value().npos) |
64 return true; | 68 return true; |
65 return !net::IsSafePortableRelativePath(path); | 69 return !net::IsSafePortableRelativePath(path); |
66 } | 70 } |
67 | 71 |
| 72 void DetermineInstalledNaclArchs(const base::FilePath& extension_path, |
| 73 std::set<std::string>* archs) { |
| 74 archs->clear(); |
| 75 base::FilePath platform_specific_path = extension_path.Append( |
| 76 kPlatformSpecificFolder); |
| 77 if (!base::PathExists(platform_specific_path)) { |
| 78 return; |
| 79 } |
| 80 |
| 81 base::FileEnumerator all_archs(platform_specific_path, |
| 82 false, |
| 83 base::FileEnumerator::DIRECTORIES); |
| 84 base::FilePath arch; |
| 85 while (!(arch = all_archs.Next()).empty()) { |
| 86 std::string arch_name = arch.BaseName().AsUTF8Unsafe(); |
| 87 std::replace(arch_name.begin(), arch_name.end(), '_', '-'); |
| 88 archs->insert(arch_name); |
| 89 } |
| 90 } |
| 91 |
68 } // namespace | 92 } // namespace |
69 | 93 |
70 const int Extension::kInitFromValueFlagBits = 13; | 94 const int Extension::kInitFromValueFlagBits = 13; |
71 | 95 |
72 const char Extension::kMimeType[] = "application/x-chrome-extension"; | 96 const char Extension::kMimeType[] = "application/x-chrome-extension"; |
73 | 97 |
74 const int Extension::kValidWebExtentSchemes = | 98 const int Extension::kValidWebExtentSchemes = |
75 URLPattern::SCHEME_HTTP | URLPattern::SCHEME_HTTPS; | 99 URLPattern::SCHEME_HTTP | URLPattern::SCHEME_HTTPS; |
76 | 100 |
77 const int Extension::kValidHostPermissionSchemes = URLPattern::SCHEME_CHROMEUI | | 101 const int Extension::kValidHostPermissionSchemes = URLPattern::SCHEME_CHROMEUI | |
(...skipping 350 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
428 } | 452 } |
429 | 453 |
430 void Extension::AddWebExtentPattern(const URLPattern& pattern) { | 454 void Extension::AddWebExtentPattern(const URLPattern& pattern) { |
431 // Bookmark apps are permissionless. | 455 // Bookmark apps are permissionless. |
432 if (from_bookmark()) | 456 if (from_bookmark()) |
433 return; | 457 return; |
434 | 458 |
435 extent_.AddPattern(pattern); | 459 extent_.AddPattern(pattern); |
436 } | 460 } |
437 | 461 |
| 462 bool Extension::HasPlatformSpecificResources() const { |
| 463 return !installed_nacl_archs_.empty(); |
| 464 } |
| 465 |
| 466 bool Extension::HasResourcesForPlatform(const std::string& nacl_arch) const { |
| 467 return installed_nacl_archs_.find(nacl_arch) != installed_nacl_archs_.end(); |
| 468 } |
| 469 |
438 // static | 470 // static |
439 bool Extension::InitExtensionID(extensions::Manifest* manifest, | 471 bool Extension::InitExtensionID(extensions::Manifest* manifest, |
440 const base::FilePath& path, | 472 const base::FilePath& path, |
441 const std::string& explicit_id, | 473 const std::string& explicit_id, |
442 int creation_flags, | 474 int creation_flags, |
443 base::string16* error) { | 475 base::string16* error) { |
444 if (!explicit_id.empty()) { | 476 if (!explicit_id.empty()) { |
445 manifest->set_extension_id(explicit_id); | 477 manifest->set_extension_id(explicit_id); |
446 return true; | 478 return true; |
447 } | 479 } |
(...skipping 81 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
529 if (!LoadSharedFeatures(error)) | 561 if (!LoadSharedFeatures(error)) |
530 return false; | 562 return false; |
531 | 563 |
532 permissions_parser_->Finalize(this); | 564 permissions_parser_->Finalize(this); |
533 permissions_parser_.reset(); | 565 permissions_parser_.reset(); |
534 | 566 |
535 finished_parsing_manifest_ = true; | 567 finished_parsing_manifest_ = true; |
536 | 568 |
537 permissions_data_.reset(new PermissionsData(this)); | 569 permissions_data_.reset(new PermissionsData(this)); |
538 | 570 |
| 571 DetermineInstalledNaclArchs(path_, &installed_nacl_archs_); |
| 572 |
539 return true; | 573 return true; |
540 } | 574 } |
541 | 575 |
542 bool Extension::LoadRequiredFeatures(base::string16* error) { | 576 bool Extension::LoadRequiredFeatures(base::string16* error) { |
543 if (!LoadName(error) || | 577 if (!LoadName(error) || |
544 !LoadVersion(error)) | 578 !LoadVersion(error)) |
545 return false; | 579 return false; |
546 return true; | 580 return true; |
547 } | 581 } |
548 | 582 |
(...skipping 214 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
763 | 797 |
764 UpdatedExtensionPermissionsInfo::UpdatedExtensionPermissionsInfo( | 798 UpdatedExtensionPermissionsInfo::UpdatedExtensionPermissionsInfo( |
765 const Extension* extension, | 799 const Extension* extension, |
766 const PermissionSet* permissions, | 800 const PermissionSet* permissions, |
767 Reason reason) | 801 Reason reason) |
768 : reason(reason), | 802 : reason(reason), |
769 extension(extension), | 803 extension(extension), |
770 permissions(permissions) {} | 804 permissions(permissions) {} |
771 | 805 |
772 } // namespace extensions | 806 } // namespace extensions |
OLD | NEW |