| OLD | NEW |
| 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 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 <ostream> | 7 #include <ostream> |
| 8 | 8 |
| 9 #include "base/base64.h" | 9 #include "base/base64.h" |
| 10 #include "base/basictypes.h" | 10 #include "base/basictypes.h" |
| (...skipping 1891 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1902 return true; | 1902 return true; |
| 1903 } | 1903 } |
| 1904 | 1904 |
| 1905 bool Extension::LoadSharedFeatures( | 1905 bool Extension::LoadSharedFeatures( |
| 1906 const APIPermissionSet& api_permissions, | 1906 const APIPermissionSet& api_permissions, |
| 1907 string16* error) { | 1907 string16* error) { |
| 1908 if (!LoadDescription(error) || | 1908 if (!LoadDescription(error) || |
| 1909 !LoadHomepageURL(error) || | 1909 !LoadHomepageURL(error) || |
| 1910 !LoadUpdateURL(error) || | 1910 !LoadUpdateURL(error) || |
| 1911 !LoadIcons(error) || | 1911 !LoadIcons(error) || |
| 1912 !LoadCommands(error) || | |
| 1913 !LoadPlugins(error) || | 1912 !LoadPlugins(error) || |
| 1914 !LoadNaClModules(error) || | 1913 !LoadNaClModules(error) || |
| 1915 !LoadWebAccessibleResources(error) || | 1914 !LoadWebAccessibleResources(error) || |
| 1916 !LoadSandboxedPages(error) || | 1915 !LoadSandboxedPages(error) || |
| 1917 !LoadRequirements(error) || | 1916 !LoadRequirements(error) || |
| 1918 !LoadDefaultLocale(error) || | 1917 !LoadDefaultLocale(error) || |
| 1919 !LoadOfflineEnabled(error) || | 1918 !LoadOfflineEnabled(error) || |
| 1920 !LoadOptionsPage(error) || | 1919 !LoadOptionsPage(error) || |
| 1921 // LoadBackgroundScripts() must be called before LoadBackgroundPage(). | 1920 // LoadBackgroundScripts() must be called before LoadBackgroundPage(). |
| 1922 !LoadBackgroundScripts(error) || | 1921 !LoadBackgroundScripts(error) || |
| (...skipping 91 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 2014 } | 2013 } |
| 2015 | 2014 |
| 2016 return manifest_handler_helpers::LoadIconsFromDictionary( | 2015 return manifest_handler_helpers::LoadIconsFromDictionary( |
| 2017 icons_value, | 2016 icons_value, |
| 2018 extension_misc::kExtensionIconSizes, | 2017 extension_misc::kExtensionIconSizes, |
| 2019 extension_misc::kNumExtensionIconSizes, | 2018 extension_misc::kNumExtensionIconSizes, |
| 2020 &icons_, | 2019 &icons_, |
| 2021 error); | 2020 error); |
| 2022 } | 2021 } |
| 2023 | 2022 |
| 2024 bool Extension::LoadCommands(string16* error) { | |
| 2025 if (manifest_->HasKey(keys::kCommands)) { | |
| 2026 DictionaryValue* commands = NULL; | |
| 2027 if (!manifest_->GetDictionary(keys::kCommands, &commands)) { | |
| 2028 *error = ASCIIToUTF16(errors::kInvalidCommandsKey); | |
| 2029 return false; | |
| 2030 } | |
| 2031 | |
| 2032 if (commands->size() > kMaxCommandsPerExtension) { | |
| 2033 *error = ErrorUtils::FormatErrorMessageUTF16( | |
| 2034 errors::kInvalidKeyBindingTooMany, | |
| 2035 base::IntToString(kMaxCommandsPerExtension)); | |
| 2036 return false; | |
| 2037 } | |
| 2038 | |
| 2039 int command_index = 0; | |
| 2040 for (DictionaryValue::key_iterator iter = commands->begin_keys(); | |
| 2041 iter != commands->end_keys(); ++iter) { | |
| 2042 ++command_index; | |
| 2043 | |
| 2044 DictionaryValue* command = NULL; | |
| 2045 if (!commands->GetDictionary(*iter, &command)) { | |
| 2046 *error = ErrorUtils::FormatErrorMessageUTF16( | |
| 2047 errors::kInvalidKeyBindingDictionary, | |
| 2048 base::IntToString(command_index)); | |
| 2049 return false; | |
| 2050 } | |
| 2051 | |
| 2052 scoped_ptr<extensions::Command> binding(new extensions::Command()); | |
| 2053 if (!binding->Parse(command, *iter, command_index, error)) | |
| 2054 return false; // |error| already set. | |
| 2055 | |
| 2056 std::string command_name = binding->command_name(); | |
| 2057 if (command_name == values::kPageActionCommandEvent) { | |
| 2058 page_action_command_.reset(binding.release()); | |
| 2059 } else if (command_name == values::kBrowserActionCommandEvent) { | |
| 2060 browser_action_command_.reset(binding.release()); | |
| 2061 } else if (command_name == values::kScriptBadgeCommandEvent) { | |
| 2062 script_badge_command_.reset(binding.release()); | |
| 2063 } else { | |
| 2064 if (command_name[0] != '_') // All commands w/underscore are reserved. | |
| 2065 named_commands_[command_name] = *binding.get(); | |
| 2066 } | |
| 2067 } | |
| 2068 } | |
| 2069 | |
| 2070 if (manifest_->HasKey(keys::kBrowserAction) && | |
| 2071 !browser_action_command_.get()) { | |
| 2072 // If the extension defines a browser action, but no command for it, then | |
| 2073 // we synthesize a generic one, so the user can configure a shortcut for it. | |
| 2074 // No keyboard shortcut will be assigned to it, until the user selects one. | |
| 2075 browser_action_command_.reset( | |
| 2076 new extensions::Command( | |
| 2077 values::kBrowserActionCommandEvent, string16(), "")); | |
| 2078 } | |
| 2079 | |
| 2080 return true; | |
| 2081 } | |
| 2082 | |
| 2083 bool Extension::LoadPlugins(string16* error) { | 2023 bool Extension::LoadPlugins(string16* error) { |
| 2084 if (!manifest_->HasKey(keys::kPlugins)) | 2024 if (!manifest_->HasKey(keys::kPlugins)) |
| 2085 return true; | 2025 return true; |
| 2086 | 2026 |
| 2087 ListValue* list_value = NULL; | 2027 ListValue* list_value = NULL; |
| 2088 if (!manifest_->GetList(keys::kPlugins, &list_value)) { | 2028 if (!manifest_->GetList(keys::kPlugins, &list_value)) { |
| 2089 *error = ASCIIToUTF16(errors::kInvalidPlugins); | 2029 *error = ASCIIToUTF16(errors::kInvalidPlugins); |
| 2090 return false; | 2030 return false; |
| 2091 } | 2031 } |
| 2092 | 2032 |
| (...skipping 1744 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 3837 | 3777 |
| 3838 UpdatedExtensionPermissionsInfo::UpdatedExtensionPermissionsInfo( | 3778 UpdatedExtensionPermissionsInfo::UpdatedExtensionPermissionsInfo( |
| 3839 const Extension* extension, | 3779 const Extension* extension, |
| 3840 const PermissionSet* permissions, | 3780 const PermissionSet* permissions, |
| 3841 Reason reason) | 3781 Reason reason) |
| 3842 : reason(reason), | 3782 : reason(reason), |
| 3843 extension(extension), | 3783 extension(extension), |
| 3844 permissions(permissions) {} | 3784 permissions(permissions) {} |
| 3845 | 3785 |
| 3846 } // namespace extensions | 3786 } // namespace extensions |
| OLD | NEW |