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