OLD | NEW |
---|---|
1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2011 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 <algorithm> | 7 #include <algorithm> |
8 | 8 |
9 #include "base/base64.h" | 9 #include "base/base64.h" |
10 #include "base/basictypes.h" | 10 #include "base/basictypes.h" |
11 #include "base/command_line.h" | 11 #include "base/command_line.h" |
12 #include "base/file_path.h" | 12 #include "base/file_path.h" |
13 #include "base/file_util.h" | 13 #include "base/file_util.h" |
14 #include "base/i18n/rtl.h" | 14 #include "base/i18n/rtl.h" |
15 #include "base/logging.h" | 15 #include "base/logging.h" |
16 #include "base/memory/singleton.h" | 16 #include "base/memory/singleton.h" |
17 #include "base/stl_util.h" | 17 #include "base/stl_util.h" |
18 #include "base/string16.h" | 18 #include "base/string16.h" |
19 #include "base/string_number_conversions.h" | 19 #include "base/string_number_conversions.h" |
20 #include "base/string_util.h" | 20 #include "base/string_util.h" |
21 #include "base/utf_string_conversions.h" | 21 #include "base/utf_string_conversions.h" |
22 #include "base/values.h" | 22 #include "base/values.h" |
23 #include "base/version.h" | 23 #include "base/version.h" |
24 #include "crypto/sha2.h" | 24 #include "crypto/sha2.h" |
25 #include "chrome/browser/intents/web_intent_data.h" | |
25 #include "chrome/common/chrome_constants.h" | 26 #include "chrome/common/chrome_constants.h" |
26 #include "chrome/common/chrome_switches.h" | 27 #include "chrome/common/chrome_switches.h" |
27 #include "chrome/common/chrome_version_info.h" | 28 #include "chrome/common/chrome_version_info.h" |
28 #include "chrome/common/extensions/extension_action.h" | 29 #include "chrome/common/extensions/extension_action.h" |
29 #include "chrome/common/extensions/extension_constants.h" | 30 #include "chrome/common/extensions/extension_constants.h" |
30 #include "chrome/common/extensions/extension_error_utils.h" | 31 #include "chrome/common/extensions/extension_error_utils.h" |
31 #include "chrome/common/extensions/extension_l10n_util.h" | 32 #include "chrome/common/extensions/extension_l10n_util.h" |
32 #include "chrome/common/extensions/extension_resource.h" | 33 #include "chrome/common/extensions/extension_resource.h" |
33 #include "chrome/common/extensions/extension_sidebar_defaults.h" | 34 #include "chrome/common/extensions/extension_sidebar_defaults.h" |
34 #include "chrome/common/extensions/extension_sidebar_utils.h" | 35 #include "chrome/common/extensions/extension_sidebar_utils.h" |
(...skipping 131 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
166 rank = 0; | 167 rank = 0; |
167 break; | 168 break; |
168 | 169 |
169 default: | 170 default: |
170 NOTREACHED() << "Need to add new extension locaton " << location; | 171 NOTREACHED() << "Need to add new extension locaton " << location; |
171 } | 172 } |
172 | 173 |
173 CHECK(rank != kInvalidRank); | 174 CHECK(rank != kInvalidRank); |
174 return rank; | 175 return rank; |
175 } | 176 } |
176 | |
James Hawkins
2011/09/19 18:51:40
Keep this blank line.
groby-ooo-7-16
2011/09/19 21:33:59
Done.
| |
177 } // namespace | 177 } // namespace |
178 | 178 |
179 const FilePath::CharType Extension::kManifestFilename[] = | 179 const FilePath::CharType Extension::kManifestFilename[] = |
180 FILE_PATH_LITERAL("manifest.json"); | 180 FILE_PATH_LITERAL("manifest.json"); |
181 const FilePath::CharType Extension::kLocaleFolder[] = | 181 const FilePath::CharType Extension::kLocaleFolder[] = |
182 FILE_PATH_LITERAL("_locales"); | 182 FILE_PATH_LITERAL("_locales"); |
183 const FilePath::CharType Extension::kMessagesFilename[] = | 183 const FilePath::CharType Extension::kMessagesFilename[] = |
184 FILE_PATH_LITERAL("messages.json"); | 184 FILE_PATH_LITERAL("messages.json"); |
185 | 185 |
186 #if defined(OS_WIN) | 186 #if defined(OS_WIN) |
(...skipping 968 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
1155 if (isolation_string == values::kIsolatedStorage) { | 1155 if (isolation_string == values::kIsolatedStorage) { |
1156 is_storage_isolated_ = true; | 1156 is_storage_isolated_ = true; |
1157 } else { | 1157 } else { |
1158 LOG(WARNING) << "Did not recognize isolation type: " | 1158 LOG(WARNING) << "Did not recognize isolation type: " |
1159 << isolation_string; | 1159 << isolation_string; |
1160 } | 1160 } |
1161 } | 1161 } |
1162 return true; | 1162 return true; |
1163 } | 1163 } |
1164 | 1164 |
1165 bool Extension::LoadWebIntents(const base::DictionaryValue& manifest, | |
1166 std::string* error) { | |
1167 DCHECK(error); | |
1168 | |
1169 if (!CommandLine::ForCurrentProcess()->HasSwitch(switches::kEnableWebIntents)) | |
1170 return true; | |
1171 | |
1172 if (!manifest.HasKey(keys::kIntents)) | |
1173 return true; | |
1174 | |
1175 DictionaryValue* all_intents = NULL; | |
1176 if (!manifest.GetDictionary(keys::kIntents, &all_intents)) { | |
1177 *error = errors::kInvalidIntents; | |
1178 return false; | |
1179 } | |
1180 | |
1181 std::string value; | |
1182 DictionaryValue::key_iterator iter(all_intents->begin_keys()); | |
James Hawkins
2011/09/19 18:51:40
iter must be defined in the scope of the for loop,
groby-ooo-7-16
2011/09/19 21:33:59
Done.
| |
1183 for (; iter != all_intents->end_keys(); ++iter) { | |
1184 WebIntentData intent; | |
1185 | |
1186 DictionaryValue* one_intent = NULL; | |
1187 if (!all_intents->GetDictionaryWithoutPathExpansion(*iter, &one_intent)) { | |
1188 *error = errors::kInvalidIntent; | |
1189 return false; | |
1190 } | |
1191 intent.action = UTF8ToUTF16(*iter); | |
1192 | |
1193 // TODO(groby): Support an array of types | |
James Hawkins
2011/09/19 18:51:40
Append period.
groby-ooo-7-16
2011/09/19 21:33:59
Done.
| |
1194 if (one_intent->HasKey(keys::kIntentType)) { | |
1195 if (!one_intent->GetString(keys::kIntentType, &intent.type)) { | |
James Hawkins
2011/09/19 18:51:40
Save indentation: combine these two ifs.
Here and
groby-ooo-7-16
2011/09/19 21:33:59
That's inconsistent with the entire rest of the fi
| |
1196 *error = errors::kInvalidIntentType; | |
1197 return false; | |
1198 } | |
1199 } | |
1200 | |
1201 if (one_intent->HasKey(keys::kIntentPath)) { | |
1202 if (!one_intent->GetString(keys::kIntentPath, &value)) { | |
1203 *error = errors::kInvalidIntentPath; | |
1204 return false; | |
1205 } | |
1206 intent.service_url = GetResourceURL(value); | |
1207 } | |
1208 | |
1209 if (one_intent->HasKey(keys::kIntentTitle)) { | |
1210 if (!one_intent->GetString(keys::kIntentTitle, &intent.title)) { | |
1211 *error = errors::kInvalidIntentTitle; | |
1212 return false; | |
1213 } | |
1214 } | |
1215 | |
1216 if (one_intent->HasKey(keys::kIntentDisposition)) { | |
1217 if (!one_intent->GetString(keys::kIntentDisposition, &value) || | |
1218 (value != values::kIntentDispositionWindow && | |
1219 value != values::kIntentDispositionInline)) { | |
1220 *error = errors::kInvalidIntentDisposition; | |
1221 return false; | |
1222 } | |
1223 if (value == values::kIntentDispositionInline) | |
1224 intent.disposition = WebIntentData::DISPOSITION_INLINE; | |
1225 else | |
1226 intent.disposition = WebIntentData::DISPOSITION_WINDOW; | |
1227 } | |
1228 | |
1229 intents_.push_back(intent); | |
1230 } | |
1231 return true; | |
1232 } | |
1233 | |
1234 | |
1165 bool Extension::EnsureNotHybridApp(const DictionaryValue* manifest, | 1235 bool Extension::EnsureNotHybridApp(const DictionaryValue* manifest, |
1166 std::string* error) { | 1236 std::string* error) { |
1167 if (web_extent().is_empty()) | 1237 if (web_extent().is_empty()) |
1168 return true; | 1238 return true; |
1169 | 1239 |
1170 for (DictionaryValue::key_iterator key = manifest->begin_keys(); | 1240 for (DictionaryValue::key_iterator key = manifest->begin_keys(); |
1171 key != manifest->end_keys(); ++key) { | 1241 key != manifest->end_keys(); ++key) { |
1172 if (!IsBaseCrxKey(*key) && | 1242 if (!IsBaseCrxKey(*key) && |
1173 *key != keys::kApp && | 1243 *key != keys::kApp && |
1174 *key != keys::kPermissions && | 1244 *key != keys::kPermissions && |
(...skipping 1090 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
2265 } | 2335 } |
2266 voice_data.event_types.insert(event_type); | 2336 voice_data.event_types.insert(event_type); |
2267 } | 2337 } |
2268 } | 2338 } |
2269 | 2339 |
2270 tts_voices_.push_back(voice_data); | 2340 tts_voices_.push_back(voice_data); |
2271 } | 2341 } |
2272 } | 2342 } |
2273 } | 2343 } |
2274 | 2344 |
2345 // Initialize web intents (optional). | |
2346 if (!LoadWebIntents(source, error)) | |
2347 return false; | |
2348 | |
2275 // Initialize incognito behavior. Apps default to split mode, extensions | 2349 // Initialize incognito behavior. Apps default to split mode, extensions |
2276 // default to spanning. | 2350 // default to spanning. |
2277 incognito_split_mode_ = is_app(); | 2351 incognito_split_mode_ = is_app(); |
2278 if (source.HasKey(keys::kIncognito)) { | 2352 if (source.HasKey(keys::kIncognito)) { |
2279 std::string value; | 2353 std::string value; |
2280 if (!source.GetString(keys::kIncognito, &value)) { | 2354 if (!source.GetString(keys::kIncognito, &value)) { |
2281 *error = errors::kInvalidIncognitoBehavior; | 2355 *error = errors::kInvalidIncognitoBehavior; |
2282 return false; | 2356 return false; |
2283 } | 2357 } |
2284 if (value == values::kIncognitoSpanning) { | 2358 if (value == values::kIncognitoSpanning) { |
(...skipping 612 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
2897 already_disabled(false), | 2971 already_disabled(false), |
2898 extension(extension) {} | 2972 extension(extension) {} |
2899 | 2973 |
2900 UpdatedExtensionPermissionsInfo::UpdatedExtensionPermissionsInfo( | 2974 UpdatedExtensionPermissionsInfo::UpdatedExtensionPermissionsInfo( |
2901 const Extension* extension, | 2975 const Extension* extension, |
2902 const ExtensionPermissionSet* permissions, | 2976 const ExtensionPermissionSet* permissions, |
2903 Reason reason) | 2977 Reason reason) |
2904 : reason(reason), | 2978 : reason(reason), |
2905 extension(extension), | 2979 extension(extension), |
2906 permissions(permissions) {} | 2980 permissions(permissions) {} |
OLD | NEW |