| OLD | NEW |
| 1 // Copyright (c) 2009 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2009 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/common/extensions/extension.h" | 5 #include "chrome/common/extensions/extension.h" |
| 6 | 6 |
| 7 #include "app/resource_bundle.h" | 7 #include "app/resource_bundle.h" |
| 8 #include "base/basictypes.h" | 8 #include "base/basictypes.h" |
| 9 #include "base/file_path.h" | 9 #include "base/file_path.h" |
| 10 #include "base/file_util.h" | 10 #include "base/file_util.h" |
| (...skipping 13 matching lines...) Expand all Loading... |
| 24 | 24 |
| 25 #if defined(OS_WIN) | 25 #if defined(OS_WIN) |
| 26 #include "base/registry.h" | 26 #include "base/registry.h" |
| 27 #endif | 27 #endif |
| 28 | 28 |
| 29 namespace keys = extension_manifest_keys; | 29 namespace keys = extension_manifest_keys; |
| 30 namespace values = extension_manifest_values; | 30 namespace values = extension_manifest_values; |
| 31 namespace errors = extension_manifest_errors; | 31 namespace errors = extension_manifest_errors; |
| 32 | 32 |
| 33 namespace { | 33 namespace { |
| 34 const int kPEMOutputColumns = 65; | 34 const int kPEMOutputColumns = 65; |
| 35 | 35 |
| 36 // KEY MARKERS | 36 // KEY MARKERS |
| 37 const char kKeyBeginHeaderMarker[] = "-----BEGIN"; | 37 const char kKeyBeginHeaderMarker[] = "-----BEGIN"; |
| 38 const char kKeyBeginFooterMarker[] = "-----END"; | 38 const char kKeyBeginFooterMarker[] = "-----END"; |
| 39 const char kKeyInfoEndMarker[] = "KEY-----"; | 39 const char kKeyInfoEndMarker[] = "KEY-----"; |
| 40 const char kPublic[] = "PUBLIC"; | 40 const char kPublic[] = "PUBLIC"; |
| 41 const char kPrivate[] = "PRIVATE"; | 41 const char kPrivate[] = "PRIVATE"; |
| 42 | 42 |
| 43 const int kRSAKeySize = 1024; | 43 const int kRSAKeySize = 1024; |
| 44 | 44 |
| 45 // Converts a normal hexadecimal string into the alphabet used by extensions. | 45 // Converts a normal hexadecimal string into the alphabet used by extensions. |
| 46 // We use the characters 'a'-'p' instead of '0'-'f' to avoid ever having a | 46 // We use the characters 'a'-'p' instead of '0'-'f' to avoid ever having a |
| 47 // completely numeric host, since some software interprets that as an IP | 47 // completely numeric host, since some software interprets that as an IP |
| 48 // address. | 48 // address. |
| 49 static void ConvertHexadecimalToIDAlphabet(std::string* id) { | 49 static void ConvertHexadecimalToIDAlphabet(std::string* id) { |
| 50 for (size_t i = 0; i < id->size(); ++i) | 50 for (size_t i = 0; i < id->size(); ++i) |
| 51 (*id)[i] = HexStringToInt(id->substr(i, 1)) + 'a'; | 51 (*id)[i] = HexStringToInt(id->substr(i, 1)) + 'a'; |
| 52 } |
| 53 |
| 54 // Returns true if the given string is an API permission (see kPermissionNames). |
| 55 static bool IsAPIPermission(const std::string& str) { |
| 56 for (size_t i = 0; i < Extension::kNumPermissions; ++i) { |
| 57 if (str == Extension::kPermissionNames[i]) |
| 58 return true; |
| 52 } | 59 } |
| 53 }; | 60 |
| 61 return false; |
| 62 } |
| 63 |
| 64 } // namespace |
| 54 | 65 |
| 55 // static | 66 // static |
| 56 int Extension::id_counter_ = 0; | 67 int Extension::id_counter_ = 0; |
| 57 | 68 |
| 58 const char Extension::kManifestFilename[] = "manifest.json"; | 69 const char Extension::kManifestFilename[] = "manifest.json"; |
| 59 | 70 |
| 60 // A list of all the keys allowed by themes. | 71 // A list of all the keys allowed by themes. |
| 61 static const wchar_t* kValidThemeKeys[] = { | 72 static const wchar_t* kValidThemeKeys[] = { |
| 62 keys::kDescription, | 73 keys::kDescription, |
| 63 keys::kName, | 74 keys::kName, |
| (...skipping 14 matching lines...) Expand all Loading... |
| 78 | 89 |
| 79 const char Extension::kMimeType[] = "application/x-chrome-extension"; | 90 const char Extension::kMimeType[] = "application/x-chrome-extension"; |
| 80 | 91 |
| 81 const int Extension::kIconSizes[] = { | 92 const int Extension::kIconSizes[] = { |
| 82 EXTENSION_ICON_LARGE, | 93 EXTENSION_ICON_LARGE, |
| 83 EXTENSION_ICON_MEDIUM, | 94 EXTENSION_ICON_MEDIUM, |
| 84 EXTENSION_ICON_SMALL, | 95 EXTENSION_ICON_SMALL, |
| 85 EXTENSION_ICON_BITTY | 96 EXTENSION_ICON_BITTY |
| 86 }; | 97 }; |
| 87 | 98 |
| 99 const char* Extension::kPermissionNames[] = { |
| 100 "tabs", |
| 101 "bookmarks", |
| 102 }; |
| 103 const size_t Extension::kNumPermissions = |
| 104 arraysize(Extension::kPermissionNames); |
| 105 |
| 88 Extension::~Extension() { | 106 Extension::~Extension() { |
| 89 for (PageActionMap::iterator i = page_actions_.begin(); | 107 for (PageActionMap::iterator i = page_actions_.begin(); |
| 90 i != page_actions_.end(); ++i) | 108 i != page_actions_.end(); ++i) |
| 91 delete i->second; | 109 delete i->second; |
| 92 } | 110 } |
| 93 | 111 |
| 94 const std::string Extension::VersionString() const { | 112 const std::string Extension::VersionString() const { |
| 95 return version_->GetString(); | 113 return version_->GetString(); |
| 96 } | 114 } |
| 97 | 115 |
| (...skipping 747 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 845 PageAction* page_action = | 863 PageAction* page_action = |
| 846 LoadPageActionHelper(page_action_value, i, error); | 864 LoadPageActionHelper(page_action_value, i, error); |
| 847 if (!page_action) | 865 if (!page_action) |
| 848 return false; // Failed to parse page action definition. | 866 return false; // Failed to parse page action definition. |
| 849 page_actions_[page_action->id()] = page_action; | 867 page_actions_[page_action->id()] = page_action; |
| 850 } | 868 } |
| 851 } | 869 } |
| 852 | 870 |
| 853 // Initialize the permissions (optional). | 871 // Initialize the permissions (optional). |
| 854 if (source.HasKey(keys::kPermissions)) { | 872 if (source.HasKey(keys::kPermissions)) { |
| 855 ListValue* hosts = NULL; | 873 ListValue* permissions = NULL; |
| 856 if (!source.GetList(keys::kPermissions, &hosts)) { | 874 if (!source.GetList(keys::kPermissions, &permissions)) { |
| 857 *error = ExtensionErrorUtils::FormatErrorMessage( | 875 *error = ExtensionErrorUtils::FormatErrorMessage( |
| 858 errors::kInvalidPermissions, ""); | 876 errors::kInvalidPermissions, ""); |
| 859 return false; | 877 return false; |
| 860 } | 878 } |
| 861 | 879 |
| 862 if (hosts->GetSize() == 0) { | 880 if (permissions->GetSize() == 0) { |
| 863 ExtensionErrorReporter::GetInstance()->ReportError( | 881 ExtensionErrorReporter::GetInstance()->ReportError( |
| 864 errors::kInvalidPermissionCountWarning, false); | 882 errors::kInvalidPermissionCountWarning, false); |
| 865 } | 883 } |
| 866 | 884 |
| 867 for (size_t i = 0; i < hosts->GetSize(); ++i) { | 885 for (size_t i = 0; i < permissions->GetSize(); ++i) { |
| 868 std::string host_str; | 886 std::string permission_str; |
| 869 if (!hosts->GetString(i, &host_str)) { | 887 if (!permissions->GetString(i, &permission_str)) { |
| 870 *error = ExtensionErrorUtils::FormatErrorMessage( | 888 *error = ExtensionErrorUtils::FormatErrorMessage( |
| 871 errors::kInvalidPermission, IntToString(i)); | 889 errors::kInvalidPermission, IntToString(i)); |
| 872 return false; | 890 return false; |
| 873 } | 891 } |
| 874 | 892 |
| 893 // Check if it's a module permission. If so, enable that permission. |
| 894 if (IsAPIPermission(permission_str)) { |
| 895 api_permissions_.push_back(permission_str); |
| 896 continue; |
| 897 } |
| 898 |
| 899 // Otherwise, it's a host pattern permission. |
| 875 URLPattern pattern; | 900 URLPattern pattern; |
| 876 if (!pattern.Parse(host_str)) { | 901 if (!pattern.Parse(permission_str)) { |
| 877 *error = ExtensionErrorUtils::FormatErrorMessage( | 902 *error = ExtensionErrorUtils::FormatErrorMessage( |
| 878 errors::kInvalidPermission, IntToString(i)); | 903 errors::kInvalidPermission, IntToString(i)); |
| 879 return false; | 904 return false; |
| 880 } | 905 } |
| 881 | 906 |
| 882 // Only accept http/https persmissions at the moment. | 907 // Only accept http/https persmissions at the moment. |
| 883 if ((pattern.scheme() != chrome::kHttpScheme) && | 908 if ((pattern.scheme() != chrome::kHttpScheme) && |
| 884 (pattern.scheme() != chrome::kHttpsScheme)) { | 909 (pattern.scheme() != chrome::kHttpsScheme)) { |
| 885 *error = ExtensionErrorUtils::FormatErrorMessage( | 910 *error = ExtensionErrorUtils::FormatErrorMessage( |
| 886 errors::kInvalidPermissionScheme, IntToString(i)); | 911 errors::kInvalidPermissionScheme, IntToString(i)); |
| 887 return false; | 912 return false; |
| 888 } | 913 } |
| 889 | 914 |
| 890 permissions_.push_back(pattern); | 915 host_permissions_.push_back(pattern); |
| 891 } | 916 } |
| 892 } | 917 } |
| 893 | 918 |
| 894 return true; | 919 return true; |
| 895 } | 920 } |
| 896 | 921 |
| 897 std::set<FilePath> Extension::GetBrowserImages() { | 922 std::set<FilePath> Extension::GetBrowserImages() { |
| 898 std::set<FilePath> image_paths; | 923 std::set<FilePath> image_paths; |
| 899 | 924 |
| 900 // extension icons | 925 // extension icons |
| (...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 933 } | 958 } |
| 934 | 959 |
| 935 void Extension::SetBackgroundPageReady() { | 960 void Extension::SetBackgroundPageReady() { |
| 936 DCHECK(!background_url().is_empty()); | 961 DCHECK(!background_url().is_empty()); |
| 937 background_page_ready_ = true; | 962 background_page_ready_ = true; |
| 938 NotificationService::current()->Notify( | 963 NotificationService::current()->Notify( |
| 939 NotificationType::EXTENSION_BACKGROUND_PAGE_READY, | 964 NotificationType::EXTENSION_BACKGROUND_PAGE_READY, |
| 940 Source<Extension>(this), | 965 Source<Extension>(this), |
| 941 NotificationService::NoDetails()); | 966 NotificationService::NoDetails()); |
| 942 } | 967 } |
| OLD | NEW |