OLD | NEW |
1 // Copyright (c) 2010 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2010 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 "app/l10n_util.h" | 9 #include "app/l10n_util.h" |
10 #include "base/base64.h" | 10 #include "base/base64.h" |
11 #include "base/basictypes.h" | 11 #include "base/basictypes.h" |
12 #include "base/command_line.h" | 12 #include "base/command_line.h" |
13 #include "base/file_path.h" | 13 #include "base/file_path.h" |
14 #include "base/file_util.h" | 14 #include "base/file_util.h" |
15 #include "base/file_version_info.h" | 15 #include "base/file_version_info.h" |
16 #include "base/i18n/rtl.h" | 16 #include "base/i18n/rtl.h" |
17 #include "base/logging.h" | 17 #include "base/logging.h" |
18 #include "base/stl_util-inl.h" | 18 #include "base/stl_util-inl.h" |
19 #include "base/third_party/nss/blapi.h" | 19 #include "base/third_party/nss/blapi.h" |
20 #include "base/third_party/nss/sha256.h" | 20 #include "base/third_party/nss/sha256.h" |
| 21 #include "base/string_number_conversions.h" |
21 #include "base/utf_string_conversions.h" | 22 #include "base/utf_string_conversions.h" |
22 #include "chrome/common/chrome_constants.h" | 23 #include "chrome/common/chrome_constants.h" |
23 #include "chrome/common/chrome_switches.h" | 24 #include "chrome/common/chrome_switches.h" |
24 #include "chrome/common/chrome_version_info.h" | 25 #include "chrome/common/chrome_version_info.h" |
25 #include "chrome/common/extensions/extension_action.h" | 26 #include "chrome/common/extensions/extension_action.h" |
26 #include "chrome/common/extensions/extension_constants.h" | 27 #include "chrome/common/extensions/extension_constants.h" |
27 #include "chrome/common/extensions/extension_error_utils.h" | 28 #include "chrome/common/extensions/extension_error_utils.h" |
28 #include "chrome/common/extensions/extension_l10n_util.h" | 29 #include "chrome/common/extensions/extension_l10n_util.h" |
29 #include "chrome/common/extensions/extension_resource.h" | 30 #include "chrome/common/extensions/extension_resource.h" |
30 #include "chrome/common/extensions/user_script.h" | 31 #include "chrome/common/extensions/user_script.h" |
(...skipping 23 matching lines...) Expand all Loading... |
54 const char kPublic[] = "PUBLIC"; | 55 const char kPublic[] = "PUBLIC"; |
55 const char kPrivate[] = "PRIVATE"; | 56 const char kPrivate[] = "PRIVATE"; |
56 | 57 |
57 const int kRSAKeySize = 1024; | 58 const int kRSAKeySize = 1024; |
58 | 59 |
59 // Converts a normal hexadecimal string into the alphabet used by extensions. | 60 // Converts a normal hexadecimal string into the alphabet used by extensions. |
60 // We use the characters 'a'-'p' instead of '0'-'f' to avoid ever having a | 61 // We use the characters 'a'-'p' instead of '0'-'f' to avoid ever having a |
61 // completely numeric host, since some software interprets that as an IP | 62 // completely numeric host, since some software interprets that as an IP |
62 // address. | 63 // address. |
63 static void ConvertHexadecimalToIDAlphabet(std::string* id) { | 64 static void ConvertHexadecimalToIDAlphabet(std::string* id) { |
64 for (size_t i = 0; i < id->size(); ++i) | 65 for (size_t i = 0; i < id->size(); ++i) { |
65 (*id)[i] = HexStringToInt(id->substr(i, 1)) + 'a'; | 66 int val; |
| 67 if (base::HexStringToInt(id->substr(i, 1), &val)) |
| 68 (*id)[i] = val + 'a'; |
| 69 else |
| 70 (*id)[i] = 'a'; |
| 71 } |
66 } | 72 } |
67 | 73 |
68 const int kValidWebExtentSchemes = | 74 const int kValidWebExtentSchemes = |
69 URLPattern::SCHEME_HTTP | URLPattern::SCHEME_HTTPS; | 75 URLPattern::SCHEME_HTTP | URLPattern::SCHEME_HTTPS; |
70 | 76 |
71 } // namespace | 77 } // namespace |
72 | 78 |
73 const FilePath::CharType Extension::kManifestFilename[] = | 79 const FilePath::CharType Extension::kManifestFilename[] = |
74 FILE_PATH_LITERAL("manifest.json"); | 80 FILE_PATH_LITERAL("manifest.json"); |
75 const FilePath::CharType Extension::kLocaleFolder[] = | 81 const FilePath::CharType Extension::kLocaleFolder[] = |
(...skipping 138 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
214 // Helper method that loads a UserScript object from a dictionary in the | 220 // Helper method that loads a UserScript object from a dictionary in the |
215 // content_script list of the manifest. | 221 // content_script list of the manifest. |
216 bool Extension::LoadUserScriptHelper(const DictionaryValue* content_script, | 222 bool Extension::LoadUserScriptHelper(const DictionaryValue* content_script, |
217 int definition_index, std::string* error, | 223 int definition_index, std::string* error, |
218 UserScript* result) { | 224 UserScript* result) { |
219 // run_at | 225 // run_at |
220 if (content_script->HasKey(keys::kRunAt)) { | 226 if (content_script->HasKey(keys::kRunAt)) { |
221 std::string run_location; | 227 std::string run_location; |
222 if (!content_script->GetString(keys::kRunAt, &run_location)) { | 228 if (!content_script->GetString(keys::kRunAt, &run_location)) { |
223 *error = ExtensionErrorUtils::FormatErrorMessage(errors::kInvalidRunAt, | 229 *error = ExtensionErrorUtils::FormatErrorMessage(errors::kInvalidRunAt, |
224 IntToString(definition_index)); | 230 base::IntToString(definition_index)); |
225 return false; | 231 return false; |
226 } | 232 } |
227 | 233 |
228 if (run_location == values::kRunAtDocumentStart) { | 234 if (run_location == values::kRunAtDocumentStart) { |
229 result->set_run_location(UserScript::DOCUMENT_START); | 235 result->set_run_location(UserScript::DOCUMENT_START); |
230 } else if (run_location == values::kRunAtDocumentEnd) { | 236 } else if (run_location == values::kRunAtDocumentEnd) { |
231 result->set_run_location(UserScript::DOCUMENT_END); | 237 result->set_run_location(UserScript::DOCUMENT_END); |
232 } else if (run_location == values::kRunAtDocumentIdle) { | 238 } else if (run_location == values::kRunAtDocumentIdle) { |
233 result->set_run_location(UserScript::DOCUMENT_IDLE); | 239 result->set_run_location(UserScript::DOCUMENT_IDLE); |
234 } else { | 240 } else { |
235 *error = ExtensionErrorUtils::FormatErrorMessage(errors::kInvalidRunAt, | 241 *error = ExtensionErrorUtils::FormatErrorMessage(errors::kInvalidRunAt, |
236 IntToString(definition_index)); | 242 base::IntToString(definition_index)); |
237 return false; | 243 return false; |
238 } | 244 } |
239 } | 245 } |
240 | 246 |
241 // all frames | 247 // all frames |
242 if (content_script->HasKey(keys::kAllFrames)) { | 248 if (content_script->HasKey(keys::kAllFrames)) { |
243 bool all_frames = false; | 249 bool all_frames = false; |
244 if (!content_script->GetBoolean(keys::kAllFrames, &all_frames)) { | 250 if (!content_script->GetBoolean(keys::kAllFrames, &all_frames)) { |
245 *error = ExtensionErrorUtils::FormatErrorMessage( | 251 *error = ExtensionErrorUtils::FormatErrorMessage( |
246 errors::kInvalidAllFrames, IntToString(definition_index)); | 252 errors::kInvalidAllFrames, base::IntToString(definition_index)); |
247 return false; | 253 return false; |
248 } | 254 } |
249 result->set_match_all_frames(all_frames); | 255 result->set_match_all_frames(all_frames); |
250 } | 256 } |
251 | 257 |
252 // matches | 258 // matches |
253 ListValue* matches = NULL; | 259 ListValue* matches = NULL; |
254 if (!content_script->GetList(keys::kMatches, &matches)) { | 260 if (!content_script->GetList(keys::kMatches, &matches)) { |
255 *error = ExtensionErrorUtils::FormatErrorMessage(errors::kInvalidMatches, | 261 *error = ExtensionErrorUtils::FormatErrorMessage(errors::kInvalidMatches, |
256 IntToString(definition_index)); | 262 base::IntToString(definition_index)); |
257 return false; | 263 return false; |
258 } | 264 } |
259 | 265 |
260 if (matches->GetSize() == 0) { | 266 if (matches->GetSize() == 0) { |
261 *error = ExtensionErrorUtils::FormatErrorMessage(errors::kInvalidMatchCount, | 267 *error = ExtensionErrorUtils::FormatErrorMessage(errors::kInvalidMatchCount, |
262 IntToString(definition_index)); | 268 base::IntToString(definition_index)); |
263 return false; | 269 return false; |
264 } | 270 } |
265 for (size_t j = 0; j < matches->GetSize(); ++j) { | 271 for (size_t j = 0; j < matches->GetSize(); ++j) { |
266 std::string match_str; | 272 std::string match_str; |
267 if (!matches->GetString(j, &match_str)) { | 273 if (!matches->GetString(j, &match_str)) { |
268 *error = ExtensionErrorUtils::FormatErrorMessage(errors::kInvalidMatch, | 274 *error = ExtensionErrorUtils::FormatErrorMessage(errors::kInvalidMatch, |
269 IntToString(definition_index), IntToString(j)); | 275 base::IntToString(definition_index), base::IntToString(j)); |
270 return false; | 276 return false; |
271 } | 277 } |
272 | 278 |
273 URLPattern pattern(UserScript::kValidUserScriptSchemes); | 279 URLPattern pattern(UserScript::kValidUserScriptSchemes); |
274 if (!pattern.Parse(match_str)) { | 280 if (!pattern.Parse(match_str)) { |
275 *error = ExtensionErrorUtils::FormatErrorMessage(errors::kInvalidMatch, | 281 *error = ExtensionErrorUtils::FormatErrorMessage(errors::kInvalidMatch, |
276 IntToString(definition_index), IntToString(j)); | 282 base::IntToString(definition_index), base::IntToString(j)); |
277 return false; | 283 return false; |
278 } | 284 } |
279 | 285 |
280 result->add_url_pattern(pattern); | 286 result->add_url_pattern(pattern); |
281 } | 287 } |
282 | 288 |
283 // include/exclude globs (mostly for Greasemonkey compatibility) | 289 // include/exclude globs (mostly for Greasemonkey compatibility) |
284 if (!LoadGlobsHelper(content_script, definition_index, keys::kIncludeGlobs, | 290 if (!LoadGlobsHelper(content_script, definition_index, keys::kIncludeGlobs, |
285 error, &UserScript::add_glob, result)) { | 291 error, &UserScript::add_glob, result)) { |
286 return false; | 292 return false; |
287 } | 293 } |
288 | 294 |
289 if (!LoadGlobsHelper(content_script, definition_index, keys::kExcludeGlobs, | 295 if (!LoadGlobsHelper(content_script, definition_index, keys::kExcludeGlobs, |
290 error, &UserScript::add_exclude_glob, result)) { | 296 error, &UserScript::add_exclude_glob, result)) { |
291 return false; | 297 return false; |
292 } | 298 } |
293 | 299 |
294 // js and css keys | 300 // js and css keys |
295 ListValue* js = NULL; | 301 ListValue* js = NULL; |
296 if (content_script->HasKey(keys::kJs) && | 302 if (content_script->HasKey(keys::kJs) && |
297 !content_script->GetList(keys::kJs, &js)) { | 303 !content_script->GetList(keys::kJs, &js)) { |
298 *error = ExtensionErrorUtils::FormatErrorMessage(errors::kInvalidJsList, | 304 *error = ExtensionErrorUtils::FormatErrorMessage(errors::kInvalidJsList, |
299 IntToString(definition_index)); | 305 base::IntToString(definition_index)); |
300 return false; | 306 return false; |
301 } | 307 } |
302 | 308 |
303 ListValue* css = NULL; | 309 ListValue* css = NULL; |
304 if (content_script->HasKey(keys::kCss) && | 310 if (content_script->HasKey(keys::kCss) && |
305 !content_script->GetList(keys::kCss, &css)) { | 311 !content_script->GetList(keys::kCss, &css)) { |
306 *error = ExtensionErrorUtils::FormatErrorMessage(errors::kInvalidCssList, | 312 *error = ExtensionErrorUtils::FormatErrorMessage(errors::kInvalidCssList, |
307 IntToString(definition_index)); | 313 base::IntToString(definition_index)); |
308 return false; | 314 return false; |
309 } | 315 } |
310 | 316 |
311 // The manifest needs to have at least one js or css user script definition. | 317 // The manifest needs to have at least one js or css user script definition. |
312 if (((js ? js->GetSize() : 0) + (css ? css->GetSize() : 0)) == 0) { | 318 if (((js ? js->GetSize() : 0) + (css ? css->GetSize() : 0)) == 0) { |
313 *error = ExtensionErrorUtils::FormatErrorMessage(errors::kMissingFile, | 319 *error = ExtensionErrorUtils::FormatErrorMessage(errors::kMissingFile, |
314 IntToString(definition_index)); | 320 base::IntToString(definition_index)); |
315 return false; | 321 return false; |
316 } | 322 } |
317 | 323 |
318 if (js) { | 324 if (js) { |
319 for (size_t script_index = 0; script_index < js->GetSize(); | 325 for (size_t script_index = 0; script_index < js->GetSize(); |
320 ++script_index) { | 326 ++script_index) { |
321 Value* value; | 327 Value* value; |
322 std::string relative; | 328 std::string relative; |
323 if (!js->Get(script_index, &value) || !value->GetAsString(&relative)) { | 329 if (!js->Get(script_index, &value) || !value->GetAsString(&relative)) { |
324 *error = ExtensionErrorUtils::FormatErrorMessage(errors::kInvalidJs, | 330 *error = ExtensionErrorUtils::FormatErrorMessage(errors::kInvalidJs, |
325 IntToString(definition_index), IntToString(script_index)); | 331 base::IntToString(definition_index), |
| 332 base::IntToString(script_index)); |
326 return false; | 333 return false; |
327 } | 334 } |
328 GURL url = GetResourceURL(relative); | 335 GURL url = GetResourceURL(relative); |
329 ExtensionResource resource = GetResource(relative); | 336 ExtensionResource resource = GetResource(relative); |
330 result->js_scripts().push_back(UserScript::File( | 337 result->js_scripts().push_back(UserScript::File( |
331 resource.extension_root(), resource.relative_path(), url)); | 338 resource.extension_root(), resource.relative_path(), url)); |
332 } | 339 } |
333 } | 340 } |
334 | 341 |
335 if (css) { | 342 if (css) { |
336 for (size_t script_index = 0; script_index < css->GetSize(); | 343 for (size_t script_index = 0; script_index < css->GetSize(); |
337 ++script_index) { | 344 ++script_index) { |
338 Value* value; | 345 Value* value; |
339 std::string relative; | 346 std::string relative; |
340 if (!css->Get(script_index, &value) || !value->GetAsString(&relative)) { | 347 if (!css->Get(script_index, &value) || !value->GetAsString(&relative)) { |
341 *error = ExtensionErrorUtils::FormatErrorMessage(errors::kInvalidCss, | 348 *error = ExtensionErrorUtils::FormatErrorMessage(errors::kInvalidCss, |
342 IntToString(definition_index), IntToString(script_index)); | 349 base::IntToString(definition_index), |
| 350 base::IntToString(script_index)); |
343 return false; | 351 return false; |
344 } | 352 } |
345 GURL url = GetResourceURL(relative); | 353 GURL url = GetResourceURL(relative); |
346 ExtensionResource resource = GetResource(relative); | 354 ExtensionResource resource = GetResource(relative); |
347 result->css_scripts().push_back(UserScript::File( | 355 result->css_scripts().push_back(UserScript::File( |
348 resource.extension_root(), resource.relative_path(), url)); | 356 resource.extension_root(), resource.relative_path(), url)); |
349 } | 357 } |
350 } | 358 } |
351 | 359 |
352 return true; | 360 return true; |
353 } | 361 } |
354 | 362 |
355 bool Extension::LoadGlobsHelper( | 363 bool Extension::LoadGlobsHelper( |
356 const DictionaryValue* content_script, | 364 const DictionaryValue* content_script, |
357 int content_script_index, | 365 int content_script_index, |
358 const wchar_t* globs_property_name, | 366 const wchar_t* globs_property_name, |
359 std::string* error, | 367 std::string* error, |
360 void(UserScript::*add_method)(const std::string& glob), | 368 void(UserScript::*add_method)(const std::string& glob), |
361 UserScript *instance) { | 369 UserScript *instance) { |
362 if (!content_script->HasKey(globs_property_name)) | 370 if (!content_script->HasKey(globs_property_name)) |
363 return true; // they are optional | 371 return true; // they are optional |
364 | 372 |
365 ListValue* list = NULL; | 373 ListValue* list = NULL; |
366 if (!content_script->GetList(globs_property_name, &list)) { | 374 if (!content_script->GetList(globs_property_name, &list)) { |
367 *error = ExtensionErrorUtils::FormatErrorMessage(errors::kInvalidGlobList, | 375 *error = ExtensionErrorUtils::FormatErrorMessage(errors::kInvalidGlobList, |
368 IntToString(content_script_index), WideToASCII(globs_property_name)); | 376 base::IntToString(content_script_index), |
| 377 WideToUTF8(globs_property_name)); |
369 return false; | 378 return false; |
370 } | 379 } |
371 | 380 |
372 for (size_t i = 0; i < list->GetSize(); ++i) { | 381 for (size_t i = 0; i < list->GetSize(); ++i) { |
373 std::string glob; | 382 std::string glob; |
374 if (!list->GetString(i, &glob)) { | 383 if (!list->GetString(i, &glob)) { |
375 *error = ExtensionErrorUtils::FormatErrorMessage(errors::kInvalidGlob, | 384 *error = ExtensionErrorUtils::FormatErrorMessage(errors::kInvalidGlob, |
376 IntToString(content_script_index), WideToASCII(globs_property_name), | 385 base::IntToString(content_script_index), |
377 IntToString(i)); | 386 WideToUTF8(globs_property_name), |
| 387 base::IntToString(i)); |
378 return false; | 388 return false; |
379 } | 389 } |
380 | 390 |
381 (instance->*add_method)(glob); | 391 (instance->*add_method)(glob); |
382 } | 392 } |
383 | 393 |
384 return true; | 394 return true; |
385 } | 395 } |
386 | 396 |
387 ExtensionAction* Extension::LoadExtensionActionHelper( | 397 ExtensionAction* Extension::LoadExtensionActionHelper( |
(...skipping 163 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
551 if (temp->GetType() != Value::TYPE_LIST) { | 561 if (temp->GetType() != Value::TYPE_LIST) { |
552 *error = list_error; | 562 *error = list_error; |
553 return false; | 563 return false; |
554 } | 564 } |
555 | 565 |
556 ListValue* pattern_list = static_cast<ListValue*>(temp); | 566 ListValue* pattern_list = static_cast<ListValue*>(temp); |
557 for (size_t i = 0; i < pattern_list->GetSize(); ++i) { | 567 for (size_t i = 0; i < pattern_list->GetSize(); ++i) { |
558 std::string pattern_string; | 568 std::string pattern_string; |
559 if (!pattern_list->GetString(i, &pattern_string)) { | 569 if (!pattern_list->GetString(i, &pattern_string)) { |
560 *error = ExtensionErrorUtils::FormatErrorMessage(value_error, | 570 *error = ExtensionErrorUtils::FormatErrorMessage(value_error, |
561 UintToString(i)); | 571 base::UintToString(i)); |
562 return false; | 572 return false; |
563 } | 573 } |
564 | 574 |
565 URLPattern pattern(kValidWebExtentSchemes); | 575 URLPattern pattern(kValidWebExtentSchemes); |
566 if (!pattern.Parse(pattern_string)) { | 576 if (!pattern.Parse(pattern_string)) { |
567 *error = ExtensionErrorUtils::FormatErrorMessage(value_error, | 577 *error = ExtensionErrorUtils::FormatErrorMessage(value_error, |
568 UintToString(i)); | 578 base::UintToString(i)); |
569 return false; | 579 return false; |
570 } | 580 } |
571 | 581 |
572 // We do not allow authors to put wildcards in their paths. Instead, we | 582 // We do not allow authors to put wildcards in their paths. Instead, we |
573 // imply one at the end. | 583 // imply one at the end. |
574 if (pattern.path().find('*') != std::string::npos) { | 584 if (pattern.path().find('*') != std::string::npos) { |
575 *error = ExtensionErrorUtils::FormatErrorMessage(value_error, | 585 *error = ExtensionErrorUtils::FormatErrorMessage(value_error, |
576 UintToString(i)); | 586 base::UintToString(i)); |
577 return false; | 587 return false; |
578 } | 588 } |
579 pattern.set_path(pattern.path() + '*'); | 589 pattern.set_path(pattern.path() + '*'); |
580 | 590 |
581 extent->AddPattern(pattern); | 591 extent->AddPattern(pattern); |
582 } | 592 } |
583 | 593 |
584 return true; | 594 return true; |
585 } | 595 } |
586 | 596 |
(...skipping 331 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
918 scoped_ptr<SkBitmap> decoded(new SkBitmap()); | 928 scoped_ptr<SkBitmap> decoded(new SkBitmap()); |
919 *decoded = decoder.Decode(data, file_contents.length()); | 929 *decoded = decoder.Decode(data, file_contents.length()); |
920 if (decoded->empty()) { | 930 if (decoded->empty()) { |
921 LOG(ERROR) << "Could not decode icon file: " | 931 LOG(ERROR) << "Could not decode icon file: " |
922 << WideToUTF8(icon_path.ToWStringHack()); | 932 << WideToUTF8(icon_path.ToWStringHack()); |
923 return; | 933 return; |
924 } | 934 } |
925 | 935 |
926 if (decoded->width() != icon_size || decoded->height() != icon_size) { | 936 if (decoded->width() != icon_size || decoded->height() != icon_size) { |
927 LOG(ERROR) << "Icon file has unexpected size: " | 937 LOG(ERROR) << "Icon file has unexpected size: " |
928 << IntToString(decoded->width()) << "x" | 938 << base::IntToString(decoded->width()) << "x" |
929 << IntToString(decoded->height()); | 939 << base::IntToString(decoded->height()); |
930 return; | 940 return; |
931 } | 941 } |
932 | 942 |
933 result->swap(decoded); | 943 result->swap(decoded); |
934 } | 944 } |
935 | 945 |
936 GURL Extension::GetBaseURLFromExtensionId(const std::string& extension_id) { | 946 GURL Extension::GetBaseURLFromExtensionId(const std::string& extension_id) { |
937 return GURL(std::string(chrome::kExtensionScheme) + | 947 return GURL(std::string(chrome::kExtensionScheme) + |
938 chrome::kStandardSchemeSeparator + extension_id + "/"); | 948 chrome::kStandardSchemeSeparator + extension_id + "/"); |
939 } | 949 } |
(...skipping 127 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1067 | 1077 |
1068 // Initialize icons (if present). | 1078 // Initialize icons (if present). |
1069 if (source.HasKey(keys::kIcons)) { | 1079 if (source.HasKey(keys::kIcons)) { |
1070 DictionaryValue* icons_value = NULL; | 1080 DictionaryValue* icons_value = NULL; |
1071 if (!source.GetDictionary(keys::kIcons, &icons_value)) { | 1081 if (!source.GetDictionary(keys::kIcons, &icons_value)) { |
1072 *error = errors::kInvalidIcons; | 1082 *error = errors::kInvalidIcons; |
1073 return false; | 1083 return false; |
1074 } | 1084 } |
1075 | 1085 |
1076 for (size_t i = 0; i < arraysize(kIconSizes); ++i) { | 1086 for (size_t i = 0; i < arraysize(kIconSizes); ++i) { |
1077 std::wstring key = ASCIIToWide(IntToString(kIconSizes[i])); | 1087 std::wstring key = ASCIIToWide(base::IntToString(kIconSizes[i])); |
1078 if (icons_value->HasKey(key)) { | 1088 if (icons_value->HasKey(key)) { |
1079 std::string icon_path; | 1089 std::string icon_path; |
1080 if (!icons_value->GetString(key, &icon_path)) { | 1090 if (!icons_value->GetString(key, &icon_path)) { |
1081 *error = ExtensionErrorUtils::FormatErrorMessage( | 1091 *error = ExtensionErrorUtils::FormatErrorMessage( |
1082 errors::kInvalidIconPath, WideToASCII(key)); | 1092 errors::kInvalidIconPath, WideToASCII(key)); |
1083 return false; | 1093 return false; |
1084 } | 1094 } |
1085 icons_[kIconSizes[i]] = icon_path; | 1095 icons_[kIconSizes[i]] = icon_path; |
1086 } | 1096 } |
1087 } | 1097 } |
(...skipping 104 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1192 bool is_public = false; | 1202 bool is_public = false; |
1193 | 1203 |
1194 if (!list_value->GetDictionary(i, &plugin_value)) { | 1204 if (!list_value->GetDictionary(i, &plugin_value)) { |
1195 *error = errors::kInvalidPlugins; | 1205 *error = errors::kInvalidPlugins; |
1196 return false; | 1206 return false; |
1197 } | 1207 } |
1198 | 1208 |
1199 // Get plugins[i].path. | 1209 // Get plugins[i].path. |
1200 if (!plugin_value->GetString(keys::kPluginsPath, &path)) { | 1210 if (!plugin_value->GetString(keys::kPluginsPath, &path)) { |
1201 *error = ExtensionErrorUtils::FormatErrorMessage( | 1211 *error = ExtensionErrorUtils::FormatErrorMessage( |
1202 errors::kInvalidPluginsPath, IntToString(i)); | 1212 errors::kInvalidPluginsPath, base::IntToString(i)); |
1203 return false; | 1213 return false; |
1204 } | 1214 } |
1205 | 1215 |
1206 // Get plugins[i].content (optional). | 1216 // Get plugins[i].content (optional). |
1207 if (plugin_value->HasKey(keys::kPluginsPublic)) { | 1217 if (plugin_value->HasKey(keys::kPluginsPublic)) { |
1208 if (!plugin_value->GetBoolean(keys::kPluginsPublic, &is_public)) { | 1218 if (!plugin_value->GetBoolean(keys::kPluginsPublic, &is_public)) { |
1209 *error = ExtensionErrorUtils::FormatErrorMessage( | 1219 *error = ExtensionErrorUtils::FormatErrorMessage( |
1210 errors::kInvalidPluginsPublic, IntToString(i)); | 1220 errors::kInvalidPluginsPublic, base::IntToString(i)); |
1211 return false; | 1221 return false; |
1212 } | 1222 } |
1213 } | 1223 } |
1214 | 1224 |
1215 plugins_.push_back(PluginInfo()); | 1225 plugins_.push_back(PluginInfo()); |
1216 plugins_.back().path = path_.AppendASCII(path); | 1226 plugins_.back().path = path_.AppendASCII(path); |
1217 plugins_.back().is_public = is_public; | 1227 plugins_.back().is_public = is_public; |
1218 } | 1228 } |
1219 } | 1229 } |
1220 | 1230 |
(...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1253 ToolstripInfo toolstrip; | 1263 ToolstripInfo toolstrip; |
1254 DictionaryValue* toolstrip_value; | 1264 DictionaryValue* toolstrip_value; |
1255 std::string toolstrip_path; | 1265 std::string toolstrip_path; |
1256 if (list_value->GetString(i, &toolstrip_path)) { | 1266 if (list_value->GetString(i, &toolstrip_path)) { |
1257 // Support a simple URL value for backwards compatibility. | 1267 // Support a simple URL value for backwards compatibility. |
1258 toolstrip.toolstrip = GetResourceURL(toolstrip_path); | 1268 toolstrip.toolstrip = GetResourceURL(toolstrip_path); |
1259 } else if (list_value->GetDictionary(i, &toolstrip_value)) { | 1269 } else if (list_value->GetDictionary(i, &toolstrip_value)) { |
1260 if (!toolstrip_value->GetString(keys::kToolstripPath, | 1270 if (!toolstrip_value->GetString(keys::kToolstripPath, |
1261 &toolstrip_path)) { | 1271 &toolstrip_path)) { |
1262 *error = ExtensionErrorUtils::FormatErrorMessage( | 1272 *error = ExtensionErrorUtils::FormatErrorMessage( |
1263 errors::kInvalidToolstrip, IntToString(i)); | 1273 errors::kInvalidToolstrip, base::IntToString(i)); |
1264 return false; | 1274 return false; |
1265 } | 1275 } |
1266 toolstrip.toolstrip = GetResourceURL(toolstrip_path); | 1276 toolstrip.toolstrip = GetResourceURL(toolstrip_path); |
1267 if (toolstrip_value->HasKey(keys::kToolstripMolePath)) { | 1277 if (toolstrip_value->HasKey(keys::kToolstripMolePath)) { |
1268 std::string mole_path; | 1278 std::string mole_path; |
1269 if (!toolstrip_value->GetString(keys::kToolstripMolePath, | 1279 if (!toolstrip_value->GetString(keys::kToolstripMolePath, |
1270 &mole_path)) { | 1280 &mole_path)) { |
1271 *error = ExtensionErrorUtils::FormatErrorMessage( | 1281 *error = ExtensionErrorUtils::FormatErrorMessage( |
1272 errors::kInvalidToolstrip, IntToString(i)); | 1282 errors::kInvalidToolstrip, base::IntToString(i)); |
1273 return false; | 1283 return false; |
1274 } | 1284 } |
1275 int height; | 1285 int height; |
1276 if (!toolstrip_value->GetInteger(keys::kToolstripMoleHeight, | 1286 if (!toolstrip_value->GetInteger(keys::kToolstripMoleHeight, |
1277 &height) || (height < 0)) { | 1287 &height) || (height < 0)) { |
1278 *error = ExtensionErrorUtils::FormatErrorMessage( | 1288 *error = ExtensionErrorUtils::FormatErrorMessage( |
1279 errors::kInvalidToolstrip, IntToString(i)); | 1289 errors::kInvalidToolstrip, base::IntToString(i)); |
1280 return false; | 1290 return false; |
1281 } | 1291 } |
1282 toolstrip.mole = GetResourceURL(mole_path); | 1292 toolstrip.mole = GetResourceURL(mole_path); |
1283 toolstrip.mole_height = height; | 1293 toolstrip.mole_height = height; |
1284 } | 1294 } |
1285 } else { | 1295 } else { |
1286 *error = ExtensionErrorUtils::FormatErrorMessage( | 1296 *error = ExtensionErrorUtils::FormatErrorMessage( |
1287 errors::kInvalidToolstrip, IntToString(i)); | 1297 errors::kInvalidToolstrip, base::IntToString(i)); |
1288 return false; | 1298 return false; |
1289 } | 1299 } |
1290 toolstrips_.push_back(toolstrip); | 1300 toolstrips_.push_back(toolstrip); |
1291 } | 1301 } |
1292 } | 1302 } |
1293 | 1303 |
1294 // Initialize content scripts (optional). | 1304 // Initialize content scripts (optional). |
1295 if (source.HasKey(keys::kContentScripts)) { | 1305 if (source.HasKey(keys::kContentScripts)) { |
1296 ListValue* list_value; | 1306 ListValue* list_value; |
1297 if (!source.GetList(keys::kContentScripts, &list_value)) { | 1307 if (!source.GetList(keys::kContentScripts, &list_value)) { |
1298 *error = errors::kInvalidContentScriptsList; | 1308 *error = errors::kInvalidContentScriptsList; |
1299 return false; | 1309 return false; |
1300 } | 1310 } |
1301 | 1311 |
1302 for (size_t i = 0; i < list_value->GetSize(); ++i) { | 1312 for (size_t i = 0; i < list_value->GetSize(); ++i) { |
1303 DictionaryValue* content_script; | 1313 DictionaryValue* content_script; |
1304 if (!list_value->GetDictionary(i, &content_script)) { | 1314 if (!list_value->GetDictionary(i, &content_script)) { |
1305 *error = ExtensionErrorUtils::FormatErrorMessage( | 1315 *error = ExtensionErrorUtils::FormatErrorMessage( |
1306 errors::kInvalidContentScript, IntToString(i)); | 1316 errors::kInvalidContentScript, base::IntToString(i)); |
1307 return false; | 1317 return false; |
1308 } | 1318 } |
1309 | 1319 |
1310 UserScript script; | 1320 UserScript script; |
1311 if (!LoadUserScriptHelper(content_script, i, error, &script)) | 1321 if (!LoadUserScriptHelper(content_script, i, error, &script)) |
1312 return false; // Failed to parse script context definition | 1322 return false; // Failed to parse script context definition |
1313 script.set_extension_id(id()); | 1323 script.set_extension_id(id()); |
1314 if (converted_from_user_script_) { | 1324 if (converted_from_user_script_) { |
1315 script.set_emulate_greasemonkey(true); | 1325 script.set_emulate_greasemonkey(true); |
1316 script.set_match_all_frames(true); // greasemonkey matches all frames | 1326 script.set_match_all_frames(true); // greasemonkey matches all frames |
(...skipping 67 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1384 if (!source.GetList(keys::kPermissions, &permissions)) { | 1394 if (!source.GetList(keys::kPermissions, &permissions)) { |
1385 *error = ExtensionErrorUtils::FormatErrorMessage( | 1395 *error = ExtensionErrorUtils::FormatErrorMessage( |
1386 errors::kInvalidPermissions, ""); | 1396 errors::kInvalidPermissions, ""); |
1387 return false; | 1397 return false; |
1388 } | 1398 } |
1389 | 1399 |
1390 for (size_t i = 0; i < permissions->GetSize(); ++i) { | 1400 for (size_t i = 0; i < permissions->GetSize(); ++i) { |
1391 std::string permission_str; | 1401 std::string permission_str; |
1392 if (!permissions->GetString(i, &permission_str)) { | 1402 if (!permissions->GetString(i, &permission_str)) { |
1393 *error = ExtensionErrorUtils::FormatErrorMessage( | 1403 *error = ExtensionErrorUtils::FormatErrorMessage( |
1394 errors::kInvalidPermission, IntToString(i)); | 1404 errors::kInvalidPermission, base::IntToString(i)); |
1395 return false; | 1405 return false; |
1396 } | 1406 } |
1397 | 1407 |
1398 // Check if it's a module permission. If so, enable that permission. | 1408 // Check if it's a module permission. If so, enable that permission. |
1399 if (IsAPIPermission(permission_str)) { | 1409 if (IsAPIPermission(permission_str)) { |
1400 api_permissions_.push_back(permission_str); | 1410 api_permissions_.push_back(permission_str); |
1401 continue; | 1411 continue; |
1402 } | 1412 } |
1403 | 1413 |
1404 // Otherwise, it's a host pattern permission. | 1414 // Otherwise, it's a host pattern permission. |
1405 URLPattern pattern(URLPattern::SCHEME_HTTP | | 1415 URLPattern pattern(URLPattern::SCHEME_HTTP | |
1406 URLPattern::SCHEME_HTTPS | | 1416 URLPattern::SCHEME_HTTPS | |
1407 URLPattern::SCHEME_CHROMEUI); | 1417 URLPattern::SCHEME_CHROMEUI); |
1408 if (!pattern.Parse(permission_str)) { | 1418 if (!pattern.Parse(permission_str)) { |
1409 *error = ExtensionErrorUtils::FormatErrorMessage( | 1419 *error = ExtensionErrorUtils::FormatErrorMessage( |
1410 errors::kInvalidPermission, IntToString(i)); | 1420 errors::kInvalidPermission, base::IntToString(i)); |
1411 return false; | 1421 return false; |
1412 } | 1422 } |
1413 | 1423 |
1414 if (!CanAccessURL(pattern)) { | 1424 if (!CanAccessURL(pattern)) { |
1415 *error = ExtensionErrorUtils::FormatErrorMessage( | 1425 *error = ExtensionErrorUtils::FormatErrorMessage( |
1416 errors::kInvalidPermissionScheme, IntToString(i)); | 1426 errors::kInvalidPermissionScheme, base::IntToString(i)); |
1417 return false; | 1427 return false; |
1418 } | 1428 } |
1419 | 1429 |
1420 // The path component is not used for host permissions, so we force it to | 1430 // The path component is not used for host permissions, so we force it to |
1421 // match all paths. | 1431 // match all paths. |
1422 pattern.set_path("/*"); | 1432 pattern.set_path("/*"); |
1423 | 1433 |
1424 host_permissions_.push_back(pattern); | 1434 host_permissions_.push_back(pattern); |
1425 } | 1435 } |
1426 } | 1436 } |
(...skipping 145 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1572 void Extension::SetBackgroundPageReady() { | 1582 void Extension::SetBackgroundPageReady() { |
1573 DCHECK(!background_url().is_empty()); | 1583 DCHECK(!background_url().is_empty()); |
1574 background_page_ready_ = true; | 1584 background_page_ready_ = true; |
1575 NotificationService::current()->Notify( | 1585 NotificationService::current()->Notify( |
1576 NotificationType::EXTENSION_BACKGROUND_PAGE_READY, | 1586 NotificationType::EXTENSION_BACKGROUND_PAGE_READY, |
1577 Source<Extension>(this), | 1587 Source<Extension>(this), |
1578 NotificationService::NoDetails()); | 1588 NotificationService::NoDetails()); |
1579 } | 1589 } |
1580 | 1590 |
1581 static std::string SizeToString(const gfx::Size& max_size) { | 1591 static std::string SizeToString(const gfx::Size& max_size) { |
1582 return IntToString(max_size.width()) + "x" + IntToString(max_size.height()); | 1592 return base::IntToString(max_size.width()) + "x" + |
| 1593 base::IntToString(max_size.height()); |
1583 } | 1594 } |
1584 | 1595 |
1585 void Extension::SetCachedImage(const ExtensionResource& source, | 1596 void Extension::SetCachedImage(const ExtensionResource& source, |
1586 const SkBitmap& image, | 1597 const SkBitmap& image, |
1587 const gfx::Size& original_size) { | 1598 const gfx::Size& original_size) { |
1588 DCHECK(source.extension_root() == path()); // The resource must come from | 1599 DCHECK(source.extension_root() == path()); // The resource must come from |
1589 // this extension. | 1600 // this extension. |
1590 const FilePath& path = source.relative_path(); | 1601 const FilePath& path = source.relative_path(); |
1591 gfx::Size actual_size(image.width(), image.height()); | 1602 gfx::Size actual_size(image.width(), image.height()); |
1592 if (actual_size == original_size) { | 1603 if (actual_size == original_size) { |
(...skipping 136 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1729 } else { | 1740 } else { |
1730 return false; | 1741 return false; |
1731 } | 1742 } |
1732 } else { | 1743 } else { |
1733 return true; | 1744 return true; |
1734 } | 1745 } |
1735 } | 1746 } |
1736 } | 1747 } |
1737 return false; | 1748 return false; |
1738 } | 1749 } |
OLD | NEW |