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 "base/base64.h" | 7 #include "base/base64.h" |
8 #include "base/basictypes.h" | 8 #include "base/basictypes.h" |
9 #include "base/command_line.h" | 9 #include "base/command_line.h" |
10 #include "base/file_util.h" | 10 #include "base/file_util.h" |
(...skipping 165 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
176 if ((*i)->ManifestEntryForbidden()) { | 176 if ((*i)->ManifestEntryForbidden()) { |
177 *error = ErrorUtils::FormatErrorMessageUTF16( | 177 *error = ErrorUtils::FormatErrorMessageUTF16( |
178 errors::kPermissionNotAllowedInManifest, | 178 errors::kPermissionNotAllowedInManifest, |
179 (*i)->info()->name()); | 179 (*i)->info()->name()); |
180 return true; | 180 return true; |
181 } | 181 } |
182 } | 182 } |
183 return false; | 183 return false; |
184 } | 184 } |
185 | 185 |
186 // Helper method to load an ExtensionAction from the page_action, script_badge, | |
187 // browser_action, or system_indicator entries in the manifest. | |
188 // TODO(rdevlin.cronin): Remove this once PageAction, BrowserAction, and | |
189 // SystemIndicator have been moved out of Extension. | |
190 scoped_ptr<ActionInfo> LoadExtensionActionInfoHelper( | |
191 const Extension* extension, | |
192 const DictionaryValue* extension_action, | |
193 string16* error) { | |
194 return manifest_handler_helpers::LoadActionInfo( | |
195 extension, extension_action, error); | |
196 } | |
197 | |
198 } // namespace | 186 } // namespace |
199 | 187 |
200 const base::FilePath::CharType Extension::kManifestFilename[] = | 188 const base::FilePath::CharType Extension::kManifestFilename[] = |
201 FILE_PATH_LITERAL("manifest.json"); | 189 FILE_PATH_LITERAL("manifest.json"); |
202 const base::FilePath::CharType Extension::kLocaleFolder[] = | 190 const base::FilePath::CharType Extension::kLocaleFolder[] = |
203 FILE_PATH_LITERAL("_locales"); | 191 FILE_PATH_LITERAL("_locales"); |
204 const base::FilePath::CharType Extension::kMessagesFilename[] = | 192 const base::FilePath::CharType Extension::kMessagesFilename[] = |
205 FILE_PATH_LITERAL("messages.json"); | 193 FILE_PATH_LITERAL("messages.json"); |
206 | 194 |
207 #if defined(OS_WIN) | 195 #if defined(OS_WIN) |
(...skipping 1737 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1945 } | 1933 } |
1946 return true; | 1934 return true; |
1947 } | 1935 } |
1948 | 1936 |
1949 bool Extension::LoadExtensionFeatures(string16* error) { | 1937 bool Extension::LoadExtensionFeatures(string16* error) { |
1950 if (manifest_->HasKey(keys::kConvertedFromUserScript)) | 1938 if (manifest_->HasKey(keys::kConvertedFromUserScript)) |
1951 manifest_->GetBoolean(keys::kConvertedFromUserScript, | 1939 manifest_->GetBoolean(keys::kConvertedFromUserScript, |
1952 &converted_from_user_script_); | 1940 &converted_from_user_script_); |
1953 | 1941 |
1954 if (!LoadContentScripts(error) || | 1942 if (!LoadContentScripts(error) || |
1955 !LoadSystemIndicator(error) || | |
1956 !LoadIncognitoMode(error)) | 1943 !LoadIncognitoMode(error)) |
1957 return false; | 1944 return false; |
1958 | 1945 |
1959 return true; | 1946 return true; |
1960 } | 1947 } |
1961 | 1948 |
1962 bool Extension::LoadContentScripts(string16* error) { | 1949 bool Extension::LoadContentScripts(string16* error) { |
1963 if (!manifest_->HasKey(keys::kContentScripts)) | 1950 if (!manifest_->HasKey(keys::kContentScripts)) |
1964 return true; | 1951 return true; |
1965 const ListValue* list_value; | 1952 const ListValue* list_value; |
(...skipping 16 matching lines...) Expand all Loading... |
1982 script.set_extension_id(id()); | 1969 script.set_extension_id(id()); |
1983 if (converted_from_user_script_) { | 1970 if (converted_from_user_script_) { |
1984 script.set_emulate_greasemonkey(true); | 1971 script.set_emulate_greasemonkey(true); |
1985 script.set_match_all_frames(true); // Greasemonkey matches all frames. | 1972 script.set_match_all_frames(true); // Greasemonkey matches all frames. |
1986 } | 1973 } |
1987 content_scripts_.push_back(script); | 1974 content_scripts_.push_back(script); |
1988 } | 1975 } |
1989 return true; | 1976 return true; |
1990 } | 1977 } |
1991 | 1978 |
1992 bool Extension::LoadSystemIndicator(string16* error) { | |
1993 if (!manifest_->HasKey(keys::kSystemIndicator)) { | |
1994 // There was no manifest entry for the system indicator. | |
1995 return true; | |
1996 } | |
1997 | |
1998 const DictionaryValue* system_indicator_value = NULL; | |
1999 if (!manifest_->GetDictionary(keys::kSystemIndicator, | |
2000 &system_indicator_value)) { | |
2001 *error = ASCIIToUTF16(errors::kInvalidSystemIndicator); | |
2002 return false; | |
2003 } | |
2004 | |
2005 system_indicator_info_ = LoadExtensionActionInfoHelper( | |
2006 this, system_indicator_value, error); | |
2007 | |
2008 if (!system_indicator_info_.get()) { | |
2009 return false; | |
2010 } | |
2011 | |
2012 // Because the manifest was successfully parsed, auto-grant the permission. | |
2013 // TODO(dewittj) Add this for all extension action APIs. | |
2014 initial_api_permissions()->insert(APIPermission::kSystemIndicator); | |
2015 | |
2016 return true; | |
2017 } | |
2018 | |
2019 bool Extension::LoadIncognitoMode(string16* error) { | 1979 bool Extension::LoadIncognitoMode(string16* error) { |
2020 // Apps default to split mode, extensions default to spanning. | 1980 // Apps default to split mode, extensions default to spanning. |
2021 incognito_split_mode_ = is_app(); | 1981 incognito_split_mode_ = is_app(); |
2022 if (!manifest_->HasKey(keys::kIncognito)) | 1982 if (!manifest_->HasKey(keys::kIncognito)) |
2023 return true; | 1983 return true; |
2024 std::string value; | 1984 std::string value; |
2025 if (!manifest_->GetString(keys::kIncognito, &value)) { | 1985 if (!manifest_->GetString(keys::kIncognito, &value)) { |
2026 *error = ASCIIToUTF16(errors::kInvalidIncognitoBehavior); | 1986 *error = ASCIIToUTF16(errors::kInvalidIncognitoBehavior); |
2027 return false; | 1987 return false; |
2028 } | 1988 } |
(...skipping 422 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2451 | 2411 |
2452 UpdatedExtensionPermissionsInfo::UpdatedExtensionPermissionsInfo( | 2412 UpdatedExtensionPermissionsInfo::UpdatedExtensionPermissionsInfo( |
2453 const Extension* extension, | 2413 const Extension* extension, |
2454 const PermissionSet* permissions, | 2414 const PermissionSet* permissions, |
2455 Reason reason) | 2415 Reason reason) |
2456 : reason(reason), | 2416 : reason(reason), |
2457 extension(extension), | 2417 extension(extension), |
2458 permissions(permissions) {} | 2418 permissions(permissions) {} |
2459 | 2419 |
2460 } // namespace extensions | 2420 } // namespace extensions |
OLD | NEW |