| 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 "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 1899 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1910 } | 1910 } |
| 1911 | 1911 |
| 1912 return true; | 1912 return true; |
| 1913 } | 1913 } |
| 1914 | 1914 |
| 1915 bool Extension::LoadSharedFeatures( | 1915 bool Extension::LoadSharedFeatures( |
| 1916 const APIPermissionSet& api_permissions, | 1916 const APIPermissionSet& api_permissions, |
| 1917 string16* error) { | 1917 string16* error) { |
| 1918 if (!LoadDescription(error) || | 1918 if (!LoadDescription(error) || |
| 1919 !LoadIcons(error) || | 1919 !LoadIcons(error) || |
| 1920 !LoadCommands(error) || | |
| 1921 !LoadPlugins(error) || | 1920 !LoadPlugins(error) || |
| 1922 !LoadNaClModules(error) || | 1921 !LoadNaClModules(error) || |
| 1923 !LoadSandboxedPages(error) || | 1922 !LoadSandboxedPages(error) || |
| 1924 !LoadRequirements(error) || | 1923 !LoadRequirements(error) || |
| 1925 !LoadDefaultLocale(error) || | 1924 !LoadDefaultLocale(error) || |
| 1926 !LoadOfflineEnabled(error) || | 1925 !LoadOfflineEnabled(error) || |
| 1927 // LoadBackgroundScripts() must be called before LoadBackgroundPage(). | 1926 // LoadBackgroundScripts() must be called before LoadBackgroundPage(). |
| 1928 !LoadBackgroundScripts(error) || | 1927 !LoadBackgroundScripts(error) || |
| 1929 !LoadBackgroundPage(api_permissions, error) || | 1928 !LoadBackgroundPage(api_permissions, error) || |
| 1930 !LoadBackgroundPersistent(api_permissions, error) || | 1929 !LoadBackgroundPersistent(api_permissions, error) || |
| (...skipping 49 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1980 } | 1979 } |
| 1981 | 1980 |
| 1982 return manifest_handler_helpers::LoadIconsFromDictionary( | 1981 return manifest_handler_helpers::LoadIconsFromDictionary( |
| 1983 icons_value, | 1982 icons_value, |
| 1984 extension_misc::kExtensionIconSizes, | 1983 extension_misc::kExtensionIconSizes, |
| 1985 extension_misc::kNumExtensionIconSizes, | 1984 extension_misc::kNumExtensionIconSizes, |
| 1986 &icons_, | 1985 &icons_, |
| 1987 error); | 1986 error); |
| 1988 } | 1987 } |
| 1989 | 1988 |
| 1990 bool Extension::LoadCommands(string16* error) { | |
| 1991 if (manifest_->HasKey(keys::kCommands)) { | |
| 1992 DictionaryValue* commands = NULL; | |
| 1993 if (!manifest_->GetDictionary(keys::kCommands, &commands)) { | |
| 1994 *error = ASCIIToUTF16(errors::kInvalidCommandsKey); | |
| 1995 return false; | |
| 1996 } | |
| 1997 | |
| 1998 if (commands->size() > kMaxCommandsPerExtension) { | |
| 1999 *error = ErrorUtils::FormatErrorMessageUTF16( | |
| 2000 errors::kInvalidKeyBindingTooMany, | |
| 2001 base::IntToString(kMaxCommandsPerExtension)); | |
| 2002 return false; | |
| 2003 } | |
| 2004 | |
| 2005 int command_index = 0; | |
| 2006 for (DictionaryValue::Iterator iter(*commands); !iter.IsAtEnd(); | |
| 2007 iter.Advance()) { | |
| 2008 ++command_index; | |
| 2009 | |
| 2010 const DictionaryValue* command = NULL; | |
| 2011 if (!iter.value().GetAsDictionary(&command)) { | |
| 2012 *error = ErrorUtils::FormatErrorMessageUTF16( | |
| 2013 errors::kInvalidKeyBindingDictionary, | |
| 2014 base::IntToString(command_index)); | |
| 2015 return false; | |
| 2016 } | |
| 2017 | |
| 2018 scoped_ptr<extensions::Command> binding(new extensions::Command()); | |
| 2019 if (!binding->Parse(command, iter.key(), command_index, error)) | |
| 2020 return false; // |error| already set. | |
| 2021 | |
| 2022 std::string command_name = binding->command_name(); | |
| 2023 if (command_name == values::kPageActionCommandEvent) { | |
| 2024 page_action_command_.reset(binding.release()); | |
| 2025 } else if (command_name == values::kBrowserActionCommandEvent) { | |
| 2026 browser_action_command_.reset(binding.release()); | |
| 2027 } else if (command_name == values::kScriptBadgeCommandEvent) { | |
| 2028 script_badge_command_.reset(binding.release()); | |
| 2029 } else { | |
| 2030 if (command_name[0] != '_') // All commands w/underscore are reserved. | |
| 2031 named_commands_[command_name] = *binding.get(); | |
| 2032 } | |
| 2033 } | |
| 2034 } | |
| 2035 | |
| 2036 if (manifest_->HasKey(keys::kBrowserAction) && | |
| 2037 !browser_action_command_.get()) { | |
| 2038 // If the extension defines a browser action, but no command for it, then | |
| 2039 // we synthesize a generic one, so the user can configure a shortcut for it. | |
| 2040 // No keyboard shortcut will be assigned to it, until the user selects one. | |
| 2041 browser_action_command_.reset( | |
| 2042 new extensions::Command( | |
| 2043 values::kBrowserActionCommandEvent, string16(), "")); | |
| 2044 } | |
| 2045 | |
| 2046 return true; | |
| 2047 } | |
| 2048 | |
| 2049 bool Extension::LoadPlugins(string16* error) { | 1989 bool Extension::LoadPlugins(string16* error) { |
| 2050 if (!manifest_->HasKey(keys::kPlugins)) | 1990 if (!manifest_->HasKey(keys::kPlugins)) |
| 2051 return true; | 1991 return true; |
| 2052 | 1992 |
| 2053 ListValue* list_value = NULL; | 1993 ListValue* list_value = NULL; |
| 2054 if (!manifest_->GetList(keys::kPlugins, &list_value)) { | 1994 if (!manifest_->GetList(keys::kPlugins, &list_value)) { |
| 2055 *error = ASCIIToUTF16(errors::kInvalidPlugins); | 1995 *error = ASCIIToUTF16(errors::kInvalidPlugins); |
| 2056 return false; | 1996 return false; |
| 2057 } | 1997 } |
| 2058 | 1998 |
| (...skipping 1155 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 3214 | 3154 |
| 3215 UpdatedExtensionPermissionsInfo::UpdatedExtensionPermissionsInfo( | 3155 UpdatedExtensionPermissionsInfo::UpdatedExtensionPermissionsInfo( |
| 3216 const Extension* extension, | 3156 const Extension* extension, |
| 3217 const PermissionSet* permissions, | 3157 const PermissionSet* permissions, |
| 3218 Reason reason) | 3158 Reason reason) |
| 3219 : reason(reason), | 3159 : reason(reason), |
| 3220 extension(extension), | 3160 extension(extension), |
| 3221 permissions(permissions) {} | 3161 permissions(permissions) {} |
| 3222 | 3162 |
| 3223 } // namespace extensions | 3163 } // namespace extensions |
| OLD | NEW |