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" |
(...skipping 209 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
220 | 220 |
221 // | 221 // |
222 // Extension | 222 // Extension |
223 // | 223 // |
224 | 224 |
225 // static | 225 // static |
226 scoped_refptr<Extension> Extension::Create(const FilePath& path, | 226 scoped_refptr<Extension> Extension::Create(const FilePath& path, |
227 Location location, | 227 Location location, |
228 const DictionaryValue& value, | 228 const DictionaryValue& value, |
229 int flags, | 229 int flags, |
230 std::string* error) { | 230 std::string* utf8_error) { |
231 DCHECK(error); | 231 DCHECK(utf8_error); |
| 232 string16 error; |
232 scoped_refptr<Extension> extension = new Extension(path, location); | 233 scoped_refptr<Extension> extension = new Extension(path, location); |
233 | 234 |
234 if (!extension->InitFromValue(new extensions::Manifest(value.DeepCopy()), | 235 if (!extension->InitFromValue(new extensions::Manifest(value.DeepCopy()), |
235 flags, error)) | 236 flags, &error)) { |
| 237 *utf8_error = UTF16ToUTF8(error); |
236 return NULL; | 238 return NULL; |
| 239 } |
237 return extension; | 240 return extension; |
238 } | 241 } |
239 | 242 |
240 scoped_refptr<Extension> Extension::CreateWithId(const FilePath& path, | 243 scoped_refptr<Extension> Extension::CreateWithId(const FilePath& path, |
241 Location location, | 244 Location location, |
242 const DictionaryValue& value, | 245 const DictionaryValue& value, |
243 int flags, | 246 int flags, |
244 const std::string& explicit_id, | 247 const std::string& explicit_id, |
245 std::string* error) { | 248 std::string* error) { |
246 scoped_refptr<Extension> extension = Create( | 249 scoped_refptr<Extension> extension = Create( |
(...skipping 130 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
377 ConvertHexadecimalToIDAlphabet(output); | 380 ConvertHexadecimalToIDAlphabet(output); |
378 | 381 |
379 return true; | 382 return true; |
380 } | 383 } |
381 | 384 |
382 // Helper method that loads a UserScript object from a dictionary in the | 385 // Helper method that loads a UserScript object from a dictionary in the |
383 // content_script list of the manifest. | 386 // content_script list of the manifest. |
384 bool Extension::LoadUserScriptHelper(const DictionaryValue* content_script, | 387 bool Extension::LoadUserScriptHelper(const DictionaryValue* content_script, |
385 int definition_index, | 388 int definition_index, |
386 int flags, | 389 int flags, |
387 std::string* error, | 390 string16* error, |
388 UserScript* result) { | 391 UserScript* result) { |
389 // When strict error checks are enabled, make URL pattern parsing strict. | 392 // When strict error checks are enabled, make URL pattern parsing strict. |
390 URLPattern::ParseOption parse_option = | 393 URLPattern::ParseOption parse_option = |
391 (flags & STRICT_ERROR_CHECKS ? URLPattern::ERROR_ON_PORTS | 394 (flags & STRICT_ERROR_CHECKS ? URLPattern::ERROR_ON_PORTS |
392 : URLPattern::IGNORE_PORTS); | 395 : URLPattern::IGNORE_PORTS); |
393 | 396 |
394 // run_at | 397 // run_at |
395 if (content_script->HasKey(keys::kRunAt)) { | 398 if (content_script->HasKey(keys::kRunAt)) { |
396 std::string run_location; | 399 std::string run_location; |
397 if (!content_script->GetString(keys::kRunAt, &run_location)) { | 400 if (!content_script->GetString(keys::kRunAt, &run_location)) { |
398 *error = ExtensionErrorUtils::FormatErrorMessage(errors::kInvalidRunAt, | 401 *error = ExtensionErrorUtils::FormatErrorMessageUTF16( |
| 402 errors::kInvalidRunAt, |
399 base::IntToString(definition_index)); | 403 base::IntToString(definition_index)); |
400 return false; | 404 return false; |
401 } | 405 } |
402 | 406 |
403 if (run_location == values::kRunAtDocumentStart) { | 407 if (run_location == values::kRunAtDocumentStart) { |
404 result->set_run_location(UserScript::DOCUMENT_START); | 408 result->set_run_location(UserScript::DOCUMENT_START); |
405 } else if (run_location == values::kRunAtDocumentEnd) { | 409 } else if (run_location == values::kRunAtDocumentEnd) { |
406 result->set_run_location(UserScript::DOCUMENT_END); | 410 result->set_run_location(UserScript::DOCUMENT_END); |
407 } else if (run_location == values::kRunAtDocumentIdle) { | 411 } else if (run_location == values::kRunAtDocumentIdle) { |
408 result->set_run_location(UserScript::DOCUMENT_IDLE); | 412 result->set_run_location(UserScript::DOCUMENT_IDLE); |
409 } else { | 413 } else { |
410 *error = ExtensionErrorUtils::FormatErrorMessage(errors::kInvalidRunAt, | 414 *error = ExtensionErrorUtils::FormatErrorMessageUTF16( |
| 415 errors::kInvalidRunAt, |
411 base::IntToString(definition_index)); | 416 base::IntToString(definition_index)); |
412 return false; | 417 return false; |
413 } | 418 } |
414 } | 419 } |
415 | 420 |
416 // all frames | 421 // all frames |
417 if (content_script->HasKey(keys::kAllFrames)) { | 422 if (content_script->HasKey(keys::kAllFrames)) { |
418 bool all_frames = false; | 423 bool all_frames = false; |
419 if (!content_script->GetBoolean(keys::kAllFrames, &all_frames)) { | 424 if (!content_script->GetBoolean(keys::kAllFrames, &all_frames)) { |
420 *error = ExtensionErrorUtils::FormatErrorMessage( | 425 *error = ExtensionErrorUtils::FormatErrorMessageUTF16( |
421 errors::kInvalidAllFrames, base::IntToString(definition_index)); | 426 errors::kInvalidAllFrames, base::IntToString(definition_index)); |
422 return false; | 427 return false; |
423 } | 428 } |
424 result->set_match_all_frames(all_frames); | 429 result->set_match_all_frames(all_frames); |
425 } | 430 } |
426 | 431 |
427 // matches (required) | 432 // matches (required) |
428 ListValue* matches = NULL; | 433 ListValue* matches = NULL; |
429 if (!content_script->GetList(keys::kMatches, &matches)) { | 434 if (!content_script->GetList(keys::kMatches, &matches)) { |
430 *error = ExtensionErrorUtils::FormatErrorMessage(errors::kInvalidMatches, | 435 *error = ExtensionErrorUtils::FormatErrorMessageUTF16( |
| 436 errors::kInvalidMatches, |
431 base::IntToString(definition_index)); | 437 base::IntToString(definition_index)); |
432 return false; | 438 return false; |
433 } | 439 } |
434 | 440 |
435 if (matches->GetSize() == 0) { | 441 if (matches->GetSize() == 0) { |
436 *error = ExtensionErrorUtils::FormatErrorMessage(errors::kInvalidMatchCount, | 442 *error = ExtensionErrorUtils::FormatErrorMessageUTF16( |
| 443 errors::kInvalidMatchCount, |
437 base::IntToString(definition_index)); | 444 base::IntToString(definition_index)); |
438 return false; | 445 return false; |
439 } | 446 } |
440 for (size_t j = 0; j < matches->GetSize(); ++j) { | 447 for (size_t j = 0; j < matches->GetSize(); ++j) { |
441 std::string match_str; | 448 std::string match_str; |
442 if (!matches->GetString(j, &match_str)) { | 449 if (!matches->GetString(j, &match_str)) { |
443 *error = ExtensionErrorUtils::FormatErrorMessage( | 450 *error = ExtensionErrorUtils::FormatErrorMessageUTF16( |
444 errors::kInvalidMatch, | 451 errors::kInvalidMatch, |
445 base::IntToString(definition_index), | 452 base::IntToString(definition_index), |
446 base::IntToString(j), | 453 base::IntToString(j), |
447 errors::kExpectString); | 454 errors::kExpectString); |
448 return false; | 455 return false; |
449 } | 456 } |
450 | 457 |
451 URLPattern pattern(parse_option, UserScript::kValidUserScriptSchemes); | 458 URLPattern pattern(parse_option, UserScript::kValidUserScriptSchemes); |
452 if (CanExecuteScriptEverywhere()) | 459 if (CanExecuteScriptEverywhere()) |
453 pattern.SetValidSchemes(URLPattern::SCHEME_ALL); | 460 pattern.SetValidSchemes(URLPattern::SCHEME_ALL); |
454 | 461 |
455 URLPattern::ParseResult parse_result = pattern.Parse(match_str); | 462 URLPattern::ParseResult parse_result = pattern.Parse(match_str); |
456 if (parse_result != URLPattern::PARSE_SUCCESS) { | 463 if (parse_result != URLPattern::PARSE_SUCCESS) { |
457 *error = ExtensionErrorUtils::FormatErrorMessage( | 464 *error = ExtensionErrorUtils::FormatErrorMessageUTF16( |
458 errors::kInvalidMatch, | 465 errors::kInvalidMatch, |
459 base::IntToString(definition_index), | 466 base::IntToString(definition_index), |
460 base::IntToString(j), | 467 base::IntToString(j), |
461 URLPattern::GetParseResultString(parse_result)); | 468 URLPattern::GetParseResultString(parse_result)); |
462 return false; | 469 return false; |
463 } | 470 } |
464 | 471 |
465 if (pattern.MatchesScheme(chrome::kFileScheme) && | 472 if (pattern.MatchesScheme(chrome::kFileScheme) && |
466 !CanExecuteScriptEverywhere()) { | 473 !CanExecuteScriptEverywhere()) { |
467 wants_file_access_ = true; | 474 wants_file_access_ = true; |
468 if (!(flags & ALLOW_FILE_ACCESS)) | 475 if (!(flags & ALLOW_FILE_ACCESS)) |
469 pattern.SetValidSchemes( | 476 pattern.SetValidSchemes( |
470 pattern.valid_schemes() & ~URLPattern::SCHEME_FILE); | 477 pattern.valid_schemes() & ~URLPattern::SCHEME_FILE); |
471 } | 478 } |
472 | 479 |
473 result->add_url_pattern(pattern); | 480 result->add_url_pattern(pattern); |
474 } | 481 } |
475 | 482 |
476 // exclude_matches | 483 // exclude_matches |
477 if (content_script->HasKey(keys::kExcludeMatches)) { // optional | 484 if (content_script->HasKey(keys::kExcludeMatches)) { // optional |
478 ListValue* exclude_matches = NULL; | 485 ListValue* exclude_matches = NULL; |
479 if (!content_script->GetList(keys::kExcludeMatches, &exclude_matches)) { | 486 if (!content_script->GetList(keys::kExcludeMatches, &exclude_matches)) { |
480 *error = ExtensionErrorUtils::FormatErrorMessage( | 487 *error = ExtensionErrorUtils::FormatErrorMessageUTF16( |
481 errors::kInvalidExcludeMatches, | 488 errors::kInvalidExcludeMatches, |
482 base::IntToString(definition_index)); | 489 base::IntToString(definition_index)); |
483 return false; | 490 return false; |
484 } | 491 } |
485 | 492 |
486 for (size_t j = 0; j < exclude_matches->GetSize(); ++j) { | 493 for (size_t j = 0; j < exclude_matches->GetSize(); ++j) { |
487 std::string match_str; | 494 std::string match_str; |
488 if (!exclude_matches->GetString(j, &match_str)) { | 495 if (!exclude_matches->GetString(j, &match_str)) { |
489 *error = ExtensionErrorUtils::FormatErrorMessage( | 496 *error = ExtensionErrorUtils::FormatErrorMessageUTF16( |
490 errors::kInvalidExcludeMatch, | 497 errors::kInvalidExcludeMatch, |
491 base::IntToString(definition_index), | 498 base::IntToString(definition_index), |
492 base::IntToString(j), | 499 base::IntToString(j), |
493 errors::kExpectString); | 500 errors::kExpectString); |
494 return false; | 501 return false; |
495 } | 502 } |
496 | 503 |
497 URLPattern pattern(parse_option, UserScript::kValidUserScriptSchemes); | 504 URLPattern pattern(parse_option, UserScript::kValidUserScriptSchemes); |
498 if (CanExecuteScriptEverywhere()) | 505 if (CanExecuteScriptEverywhere()) |
499 pattern.SetValidSchemes(URLPattern::SCHEME_ALL); | 506 pattern.SetValidSchemes(URLPattern::SCHEME_ALL); |
500 URLPattern::ParseResult parse_result = pattern.Parse(match_str); | 507 URLPattern::ParseResult parse_result = pattern.Parse(match_str); |
501 if (parse_result != URLPattern::PARSE_SUCCESS) { | 508 if (parse_result != URLPattern::PARSE_SUCCESS) { |
502 *error = ExtensionErrorUtils::FormatErrorMessage( | 509 *error = ExtensionErrorUtils::FormatErrorMessageUTF16( |
503 errors::kInvalidExcludeMatch, | 510 errors::kInvalidExcludeMatch, |
504 base::IntToString(definition_index), base::IntToString(j), | 511 base::IntToString(definition_index), base::IntToString(j), |
505 URLPattern::GetParseResultString(parse_result)); | 512 URLPattern::GetParseResultString(parse_result)); |
506 return false; | 513 return false; |
507 } | 514 } |
508 | 515 |
509 result->add_exclude_url_pattern(pattern); | 516 result->add_exclude_url_pattern(pattern); |
510 } | 517 } |
511 } | 518 } |
512 | 519 |
513 // include/exclude globs (mostly for Greasemonkey compatibility) | 520 // include/exclude globs (mostly for Greasemonkey compatibility) |
514 if (!LoadGlobsHelper(content_script, definition_index, keys::kIncludeGlobs, | 521 if (!LoadGlobsHelper(content_script, definition_index, keys::kIncludeGlobs, |
515 error, &UserScript::add_glob, result)) { | 522 error, &UserScript::add_glob, result)) { |
516 return false; | 523 return false; |
517 } | 524 } |
518 | 525 |
519 if (!LoadGlobsHelper(content_script, definition_index, keys::kExcludeGlobs, | 526 if (!LoadGlobsHelper(content_script, definition_index, keys::kExcludeGlobs, |
520 error, &UserScript::add_exclude_glob, result)) { | 527 error, &UserScript::add_exclude_glob, result)) { |
521 return false; | 528 return false; |
522 } | 529 } |
523 | 530 |
524 // js and css keys | 531 // js and css keys |
525 ListValue* js = NULL; | 532 ListValue* js = NULL; |
526 if (content_script->HasKey(keys::kJs) && | 533 if (content_script->HasKey(keys::kJs) && |
527 !content_script->GetList(keys::kJs, &js)) { | 534 !content_script->GetList(keys::kJs, &js)) { |
528 *error = ExtensionErrorUtils::FormatErrorMessage(errors::kInvalidJsList, | 535 *error = ExtensionErrorUtils::FormatErrorMessageUTF16( |
| 536 errors::kInvalidJsList, |
529 base::IntToString(definition_index)); | 537 base::IntToString(definition_index)); |
530 return false; | 538 return false; |
531 } | 539 } |
532 | 540 |
533 ListValue* css = NULL; | 541 ListValue* css = NULL; |
534 if (content_script->HasKey(keys::kCss) && | 542 if (content_script->HasKey(keys::kCss) && |
535 !content_script->GetList(keys::kCss, &css)) { | 543 !content_script->GetList(keys::kCss, &css)) { |
536 *error = ExtensionErrorUtils::FormatErrorMessage(errors::kInvalidCssList, | 544 *error = ExtensionErrorUtils:: |
| 545 FormatErrorMessageUTF16(errors::kInvalidCssList, |
537 base::IntToString(definition_index)); | 546 base::IntToString(definition_index)); |
538 return false; | 547 return false; |
539 } | 548 } |
540 | 549 |
541 // The manifest needs to have at least one js or css user script definition. | 550 // The manifest needs to have at least one js or css user script definition. |
542 if (((js ? js->GetSize() : 0) + (css ? css->GetSize() : 0)) == 0) { | 551 if (((js ? js->GetSize() : 0) + (css ? css->GetSize() : 0)) == 0) { |
543 *error = ExtensionErrorUtils::FormatErrorMessage(errors::kMissingFile, | 552 *error = ExtensionErrorUtils::FormatErrorMessageUTF16( |
| 553 errors::kMissingFile, |
544 base::IntToString(definition_index)); | 554 base::IntToString(definition_index)); |
545 return false; | 555 return false; |
546 } | 556 } |
547 | 557 |
548 if (js) { | 558 if (js) { |
549 for (size_t script_index = 0; script_index < js->GetSize(); | 559 for (size_t script_index = 0; script_index < js->GetSize(); |
550 ++script_index) { | 560 ++script_index) { |
551 Value* value; | 561 Value* value; |
552 std::string relative; | 562 std::string relative; |
553 if (!js->Get(script_index, &value) || !value->GetAsString(&relative)) { | 563 if (!js->Get(script_index, &value) || !value->GetAsString(&relative)) { |
554 *error = ExtensionErrorUtils::FormatErrorMessage(errors::kInvalidJs, | 564 *error = ExtensionErrorUtils::FormatErrorMessageUTF16( |
| 565 errors::kInvalidJs, |
555 base::IntToString(definition_index), | 566 base::IntToString(definition_index), |
556 base::IntToString(script_index)); | 567 base::IntToString(script_index)); |
557 return false; | 568 return false; |
558 } | 569 } |
559 GURL url = GetResourceURL(relative); | 570 GURL url = GetResourceURL(relative); |
560 ExtensionResource resource = GetResource(relative); | 571 ExtensionResource resource = GetResource(relative); |
561 result->js_scripts().push_back(UserScript::File( | 572 result->js_scripts().push_back(UserScript::File( |
562 resource.extension_root(), resource.relative_path(), url)); | 573 resource.extension_root(), resource.relative_path(), url)); |
563 } | 574 } |
564 } | 575 } |
565 | 576 |
566 if (css) { | 577 if (css) { |
567 for (size_t script_index = 0; script_index < css->GetSize(); | 578 for (size_t script_index = 0; script_index < css->GetSize(); |
568 ++script_index) { | 579 ++script_index) { |
569 Value* value; | 580 Value* value; |
570 std::string relative; | 581 std::string relative; |
571 if (!css->Get(script_index, &value) || !value->GetAsString(&relative)) { | 582 if (!css->Get(script_index, &value) || !value->GetAsString(&relative)) { |
572 *error = ExtensionErrorUtils::FormatErrorMessage(errors::kInvalidCss, | 583 *error = ExtensionErrorUtils::FormatErrorMessageUTF16( |
| 584 errors::kInvalidCss, |
573 base::IntToString(definition_index), | 585 base::IntToString(definition_index), |
574 base::IntToString(script_index)); | 586 base::IntToString(script_index)); |
575 return false; | 587 return false; |
576 } | 588 } |
577 GURL url = GetResourceURL(relative); | 589 GURL url = GetResourceURL(relative); |
578 ExtensionResource resource = GetResource(relative); | 590 ExtensionResource resource = GetResource(relative); |
579 result->css_scripts().push_back(UserScript::File( | 591 result->css_scripts().push_back(UserScript::File( |
580 resource.extension_root(), resource.relative_path(), url)); | 592 resource.extension_root(), resource.relative_path(), url)); |
581 } | 593 } |
582 } | 594 } |
583 | 595 |
584 return true; | 596 return true; |
585 } | 597 } |
586 | 598 |
587 bool Extension::LoadGlobsHelper( | 599 bool Extension::LoadGlobsHelper( |
588 const DictionaryValue* content_script, | 600 const DictionaryValue* content_script, |
589 int content_script_index, | 601 int content_script_index, |
590 const char* globs_property_name, | 602 const char* globs_property_name, |
591 std::string* error, | 603 string16* error, |
592 void(UserScript::*add_method)(const std::string& glob), | 604 void(UserScript::*add_method)(const std::string& glob), |
593 UserScript *instance) { | 605 UserScript *instance) { |
594 if (!content_script->HasKey(globs_property_name)) | 606 if (!content_script->HasKey(globs_property_name)) |
595 return true; // they are optional | 607 return true; // they are optional |
596 | 608 |
597 ListValue* list = NULL; | 609 ListValue* list = NULL; |
598 if (!content_script->GetList(globs_property_name, &list)) { | 610 if (!content_script->GetList(globs_property_name, &list)) { |
599 *error = ExtensionErrorUtils::FormatErrorMessage(errors::kInvalidGlobList, | 611 *error = ExtensionErrorUtils::FormatErrorMessageUTF16( |
| 612 errors::kInvalidGlobList, |
600 base::IntToString(content_script_index), | 613 base::IntToString(content_script_index), |
601 globs_property_name); | 614 globs_property_name); |
602 return false; | 615 return false; |
603 } | 616 } |
604 | 617 |
605 for (size_t i = 0; i < list->GetSize(); ++i) { | 618 for (size_t i = 0; i < list->GetSize(); ++i) { |
606 std::string glob; | 619 std::string glob; |
607 if (!list->GetString(i, &glob)) { | 620 if (!list->GetString(i, &glob)) { |
608 *error = ExtensionErrorUtils::FormatErrorMessage(errors::kInvalidGlob, | 621 *error = ExtensionErrorUtils::FormatErrorMessageUTF16( |
| 622 errors::kInvalidGlob, |
609 base::IntToString(content_script_index), | 623 base::IntToString(content_script_index), |
610 globs_property_name, | 624 globs_property_name, |
611 base::IntToString(i)); | 625 base::IntToString(i)); |
612 return false; | 626 return false; |
613 } | 627 } |
614 | 628 |
615 (instance->*add_method)(glob); | 629 (instance->*add_method)(glob); |
616 } | 630 } |
617 | 631 |
618 return true; | 632 return true; |
619 } | 633 } |
620 | 634 |
621 ExtensionAction* Extension::LoadExtensionActionHelper( | 635 ExtensionAction* Extension::LoadExtensionActionHelper( |
622 const DictionaryValue* extension_action, std::string* error) { | 636 const DictionaryValue* extension_action, string16* error) { |
623 scoped_ptr<ExtensionAction> result(new ExtensionAction()); | 637 scoped_ptr<ExtensionAction> result(new ExtensionAction()); |
624 result->set_extension_id(id()); | 638 result->set_extension_id(id()); |
625 | 639 |
626 // Page actions are hidden by default, and browser actions ignore | 640 // Page actions are hidden by default, and browser actions ignore |
627 // visibility. | 641 // visibility. |
628 result->SetIsVisible(ExtensionAction::kDefaultTabId, false); | 642 result->SetIsVisible(ExtensionAction::kDefaultTabId, false); |
629 | 643 |
630 // TODO(EXTENSIONS_DEPRECATED): icons list is obsolete. | 644 // TODO(EXTENSIONS_DEPRECATED): icons list is obsolete. |
631 ListValue* icons = NULL; | 645 ListValue* icons = NULL; |
632 if (extension_action->HasKey(keys::kPageActionIcons) && | 646 if (extension_action->HasKey(keys::kPageActionIcons) && |
633 extension_action->GetList(keys::kPageActionIcons, &icons)) { | 647 extension_action->GetList(keys::kPageActionIcons, &icons)) { |
634 for (ListValue::const_iterator iter = icons->begin(); | 648 for (ListValue::const_iterator iter = icons->begin(); |
635 iter != icons->end(); ++iter) { | 649 iter != icons->end(); ++iter) { |
636 std::string path; | 650 std::string path; |
637 if (!(*iter)->GetAsString(&path) || path.empty()) { | 651 if (!(*iter)->GetAsString(&path) || path.empty()) { |
638 *error = errors::kInvalidPageActionIconPath; | 652 *error = ASCIIToUTF16(errors::kInvalidPageActionIconPath); |
639 return NULL; | 653 return NULL; |
640 } | 654 } |
641 | 655 |
642 result->icon_paths()->push_back(path); | 656 result->icon_paths()->push_back(path); |
643 } | 657 } |
644 } | 658 } |
645 | 659 |
646 // TODO(EXTENSIONS_DEPRECATED): Read the page action |id| (optional). | 660 // TODO(EXTENSIONS_DEPRECATED): Read the page action |id| (optional). |
647 std::string id; | 661 std::string id; |
648 if (extension_action->HasKey(keys::kPageActionId)) { | 662 if (extension_action->HasKey(keys::kPageActionId)) { |
649 if (!extension_action->GetString(keys::kPageActionId, &id)) { | 663 if (!extension_action->GetString(keys::kPageActionId, &id)) { |
650 *error = errors::kInvalidPageActionId; | 664 *error = ASCIIToUTF16(errors::kInvalidPageActionId); |
651 return NULL; | 665 return NULL; |
652 } | 666 } |
653 result->set_id(id); | 667 result->set_id(id); |
654 } | 668 } |
655 | 669 |
656 std::string default_icon; | 670 std::string default_icon; |
657 // Read the page action |default_icon| (optional). | 671 // Read the page action |default_icon| (optional). |
658 if (extension_action->HasKey(keys::kPageActionDefaultIcon)) { | 672 if (extension_action->HasKey(keys::kPageActionDefaultIcon)) { |
659 if (!extension_action->GetString(keys::kPageActionDefaultIcon, | 673 if (!extension_action->GetString(keys::kPageActionDefaultIcon, |
660 &default_icon) || | 674 &default_icon) || |
661 default_icon.empty()) { | 675 default_icon.empty()) { |
662 *error = errors::kInvalidPageActionIconPath; | 676 *error = ASCIIToUTF16(errors::kInvalidPageActionIconPath); |
663 return NULL; | 677 return NULL; |
664 } | 678 } |
665 result->set_default_icon_path(default_icon); | 679 result->set_default_icon_path(default_icon); |
666 } | 680 } |
667 | 681 |
668 // Read the page action title from |default_title| if present, |name| if not | 682 // Read the page action title from |default_title| if present, |name| if not |
669 // (both optional). | 683 // (both optional). |
670 std::string title; | 684 std::string title; |
671 if (extension_action->HasKey(keys::kPageActionDefaultTitle)) { | 685 if (extension_action->HasKey(keys::kPageActionDefaultTitle)) { |
672 if (!extension_action->GetString(keys::kPageActionDefaultTitle, &title)) { | 686 if (!extension_action->GetString(keys::kPageActionDefaultTitle, &title)) { |
673 *error = errors::kInvalidPageActionDefaultTitle; | 687 *error = ASCIIToUTF16(errors::kInvalidPageActionDefaultTitle); |
674 return NULL; | 688 return NULL; |
675 } | 689 } |
676 } else if (extension_action->HasKey(keys::kName)) { | 690 } else if (extension_action->HasKey(keys::kName)) { |
677 if (!extension_action->GetString(keys::kName, &title)) { | 691 if (!extension_action->GetString(keys::kName, &title)) { |
678 *error = errors::kInvalidPageActionName; | 692 *error = ASCIIToUTF16(errors::kInvalidPageActionName); |
679 return NULL; | 693 return NULL; |
680 } | 694 } |
681 } | 695 } |
682 result->SetTitle(ExtensionAction::kDefaultTabId, title); | 696 result->SetTitle(ExtensionAction::kDefaultTabId, title); |
683 | 697 |
684 // Read the action's |popup| (optional). | 698 // Read the action's |popup| (optional). |
685 const char* popup_key = NULL; | 699 const char* popup_key = NULL; |
686 if (extension_action->HasKey(keys::kPageActionDefaultPopup)) | 700 if (extension_action->HasKey(keys::kPageActionDefaultPopup)) |
687 popup_key = keys::kPageActionDefaultPopup; | 701 popup_key = keys::kPageActionDefaultPopup; |
688 | 702 |
689 // For backward compatibility, alias old key "popup" to new | 703 // For backward compatibility, alias old key "popup" to new |
690 // key "default_popup". | 704 // key "default_popup". |
691 if (extension_action->HasKey(keys::kPageActionPopup)) { | 705 if (extension_action->HasKey(keys::kPageActionPopup)) { |
692 if (popup_key) { | 706 if (popup_key) { |
693 *error = ExtensionErrorUtils::FormatErrorMessage( | 707 *error = ExtensionErrorUtils::FormatErrorMessageUTF16( |
694 errors::kInvalidPageActionOldAndNewKeys, | 708 errors::kInvalidPageActionOldAndNewKeys, |
695 keys::kPageActionDefaultPopup, | 709 keys::kPageActionDefaultPopup, |
696 keys::kPageActionPopup); | 710 keys::kPageActionPopup); |
697 return NULL; | 711 return NULL; |
698 } | 712 } |
699 popup_key = keys::kPageActionPopup; | 713 popup_key = keys::kPageActionPopup; |
700 } | 714 } |
701 | 715 |
702 if (popup_key) { | 716 if (popup_key) { |
703 DictionaryValue* popup = NULL; | 717 DictionaryValue* popup = NULL; |
704 std::string url_str; | 718 std::string url_str; |
705 | 719 |
706 if (extension_action->GetString(popup_key, &url_str)) { | 720 if (extension_action->GetString(popup_key, &url_str)) { |
707 // On success, |url_str| is set. Nothing else to do. | 721 // On success, |url_str| is set. Nothing else to do. |
708 } else if (extension_action->GetDictionary(popup_key, &popup)) { | 722 } else if (extension_action->GetDictionary(popup_key, &popup)) { |
709 // TODO(EXTENSIONS_DEPRECATED): popup is now a string only. | 723 // TODO(EXTENSIONS_DEPRECATED): popup is now a string only. |
710 // Support the old dictionary format for backward compatibility. | 724 // Support the old dictionary format for backward compatibility. |
711 if (!popup->GetString(keys::kPageActionPopupPath, &url_str)) { | 725 if (!popup->GetString(keys::kPageActionPopupPath, &url_str)) { |
712 *error = ExtensionErrorUtils::FormatErrorMessage( | 726 *error = ExtensionErrorUtils::FormatErrorMessageUTF16( |
713 errors::kInvalidPageActionPopupPath, "<missing>"); | 727 errors::kInvalidPageActionPopupPath, "<missing>"); |
714 return NULL; | 728 return NULL; |
715 } | 729 } |
716 } else { | 730 } else { |
717 *error = errors::kInvalidPageActionPopup; | 731 *error = ASCIIToUTF16(errors::kInvalidPageActionPopup); |
718 return NULL; | 732 return NULL; |
719 } | 733 } |
720 | 734 |
721 if (!url_str.empty()) { | 735 if (!url_str.empty()) { |
722 // An empty string is treated as having no popup. | 736 // An empty string is treated as having no popup. |
723 GURL url = GetResourceURL(url_str); | 737 GURL url = GetResourceURL(url_str); |
724 if (!url.is_valid()) { | 738 if (!url.is_valid()) { |
725 *error = ExtensionErrorUtils::FormatErrorMessage( | 739 *error = ExtensionErrorUtils::FormatErrorMessageUTF16( |
726 errors::kInvalidPageActionPopupPath, url_str); | 740 errors::kInvalidPageActionPopupPath, url_str); |
727 return NULL; | 741 return NULL; |
728 } | 742 } |
729 result->SetPopupUrl(ExtensionAction::kDefaultTabId, url); | 743 result->SetPopupUrl(ExtensionAction::kDefaultTabId, url); |
730 } else { | 744 } else { |
731 DCHECK(!result->HasPopup(ExtensionAction::kDefaultTabId)) | 745 DCHECK(!result->HasPopup(ExtensionAction::kDefaultTabId)) |
732 << "Shouldn't be possible for the popup to be set."; | 746 << "Shouldn't be possible for the popup to be set."; |
733 } | 747 } |
734 } | 748 } |
735 | 749 |
736 return result.release(); | 750 return result.release(); |
737 } | 751 } |
738 | 752 |
739 Extension::FileBrowserHandlerList* Extension::LoadFileBrowserHandlers( | 753 Extension::FileBrowserHandlerList* Extension::LoadFileBrowserHandlers( |
740 const ListValue* extension_actions, std::string* error) { | 754 const ListValue* extension_actions, string16* error) { |
741 scoped_ptr<FileBrowserHandlerList> result( | 755 scoped_ptr<FileBrowserHandlerList> result( |
742 new FileBrowserHandlerList()); | 756 new FileBrowserHandlerList()); |
743 for (ListValue::const_iterator iter = extension_actions->begin(); | 757 for (ListValue::const_iterator iter = extension_actions->begin(); |
744 iter != extension_actions->end(); | 758 iter != extension_actions->end(); |
745 ++iter) { | 759 ++iter) { |
746 if (!(*iter)->IsType(Value::TYPE_DICTIONARY)) { | 760 if (!(*iter)->IsType(Value::TYPE_DICTIONARY)) { |
747 *error = errors::kInvalidFileBrowserHandler; | 761 *error = ASCIIToUTF16(errors::kInvalidFileBrowserHandler); |
748 return NULL; | 762 return NULL; |
749 } | 763 } |
750 scoped_ptr<FileBrowserHandler> action( | 764 scoped_ptr<FileBrowserHandler> action( |
751 LoadFileBrowserHandler( | 765 LoadFileBrowserHandler( |
752 reinterpret_cast<DictionaryValue*>(*iter), error)); | 766 reinterpret_cast<DictionaryValue*>(*iter), error)); |
753 if (!action.get()) | 767 if (!action.get()) |
754 return NULL; // Failed to parse file browser action definition. | 768 return NULL; // Failed to parse file browser action definition. |
755 result->push_back(linked_ptr<FileBrowserHandler>(action.release())); | 769 result->push_back(linked_ptr<FileBrowserHandler>(action.release())); |
756 } | 770 } |
757 return result.release(); | 771 return result.release(); |
758 } | 772 } |
759 | 773 |
760 FileBrowserHandler* Extension::LoadFileBrowserHandler( | 774 FileBrowserHandler* Extension::LoadFileBrowserHandler( |
761 const DictionaryValue* file_browser_handler, std::string* error) { | 775 const DictionaryValue* file_browser_handler, string16* error) { |
762 scoped_ptr<FileBrowserHandler> result( | 776 scoped_ptr<FileBrowserHandler> result( |
763 new FileBrowserHandler()); | 777 new FileBrowserHandler()); |
764 result->set_extension_id(id()); | 778 result->set_extension_id(id()); |
765 | 779 |
766 std::string id; | 780 std::string id; |
767 // Read the file action |id| (mandatory). | 781 // Read the file action |id| (mandatory). |
768 if (!file_browser_handler->HasKey(keys::kPageActionId) || | 782 if (!file_browser_handler->HasKey(keys::kPageActionId) || |
769 !file_browser_handler->GetString(keys::kPageActionId, &id)) { | 783 !file_browser_handler->GetString(keys::kPageActionId, &id)) { |
770 *error = errors::kInvalidPageActionId; | 784 *error = ASCIIToUTF16(errors::kInvalidPageActionId); |
771 return NULL; | 785 return NULL; |
772 } | 786 } |
773 result->set_id(id); | 787 result->set_id(id); |
774 | 788 |
775 // Read the page action title from |default_title| (mandatory). | 789 // Read the page action title from |default_title| (mandatory). |
776 std::string title; | 790 std::string title; |
777 if (!file_browser_handler->HasKey(keys::kPageActionDefaultTitle) || | 791 if (!file_browser_handler->HasKey(keys::kPageActionDefaultTitle) || |
778 !file_browser_handler->GetString(keys::kPageActionDefaultTitle, &title)) { | 792 !file_browser_handler->GetString(keys::kPageActionDefaultTitle, &title)) { |
779 *error = errors::kInvalidPageActionDefaultTitle; | 793 *error = ASCIIToUTF16(errors::kInvalidPageActionDefaultTitle); |
780 return NULL; | 794 return NULL; |
781 } | 795 } |
782 result->set_title(title); | 796 result->set_title(title); |
783 | 797 |
784 // Initialize file filters (mandatory). | 798 // Initialize file filters (mandatory). |
785 ListValue* list_value = NULL; | 799 ListValue* list_value = NULL; |
786 if (!file_browser_handler->HasKey(keys::kFileFilters) || | 800 if (!file_browser_handler->HasKey(keys::kFileFilters) || |
787 !file_browser_handler->GetList(keys::kFileFilters, &list_value) || | 801 !file_browser_handler->GetList(keys::kFileFilters, &list_value) || |
788 list_value->empty()) { | 802 list_value->empty()) { |
789 *error = errors::kInvalidFileFiltersList; | 803 *error = ASCIIToUTF16(errors::kInvalidFileFiltersList); |
790 return NULL; | 804 return NULL; |
791 } | 805 } |
792 for (size_t i = 0; i < list_value->GetSize(); ++i) { | 806 for (size_t i = 0; i < list_value->GetSize(); ++i) { |
793 std::string filter; | 807 std::string filter; |
794 if (!list_value->GetString(i, &filter)) { | 808 if (!list_value->GetString(i, &filter)) { |
795 *error = ExtensionErrorUtils::FormatErrorMessage( | 809 *error = ExtensionErrorUtils::FormatErrorMessageUTF16( |
796 errors::kInvalidFileFilterValue, base::IntToString(i)); | 810 errors::kInvalidFileFilterValue, base::IntToString(i)); |
797 return NULL; | 811 return NULL; |
798 } | 812 } |
799 StringToLowerASCII(&filter); | 813 StringToLowerASCII(&filter); |
800 URLPattern pattern(URLPattern::USE_PORTS, URLPattern::SCHEME_FILESYSTEM); | 814 URLPattern pattern(URLPattern::USE_PORTS, URLPattern::SCHEME_FILESYSTEM); |
801 if (pattern.Parse(filter) != URLPattern::PARSE_SUCCESS) { | 815 if (pattern.Parse(filter) != URLPattern::PARSE_SUCCESS) { |
802 *error = ExtensionErrorUtils::FormatErrorMessage( | 816 *error = ExtensionErrorUtils::FormatErrorMessageUTF16( |
803 errors::kInvalidURLPatternError, filter); | 817 errors::kInvalidURLPatternError, filter); |
804 return NULL; | 818 return NULL; |
805 } | 819 } |
806 std::string path = pattern.path(); | 820 std::string path = pattern.path(); |
807 bool allowed = path == "*" || path == "*.*" || | 821 bool allowed = path == "*" || path == "*.*" || |
808 (path.compare(0, 2, "*.") == 0 && | 822 (path.compare(0, 2, "*.") == 0 && |
809 path.find_first_of('*', 2) == std::string::npos); | 823 path.find_first_of('*', 2) == std::string::npos); |
810 if (!allowed) { | 824 if (!allowed) { |
811 *error = ExtensionErrorUtils::FormatErrorMessage( | 825 *error = ExtensionErrorUtils::FormatErrorMessageUTF16( |
812 errors::kInvalidURLPatternError, filter); | 826 errors::kInvalidURLPatternError, filter); |
813 return NULL; | 827 return NULL; |
814 } | 828 } |
815 result->AddPattern(pattern); | 829 result->AddPattern(pattern); |
816 } | 830 } |
817 | 831 |
818 std::string default_icon; | 832 std::string default_icon; |
819 // Read the file browser action |default_icon| (optional). | 833 // Read the file browser action |default_icon| (optional). |
820 if (file_browser_handler->HasKey(keys::kPageActionDefaultIcon)) { | 834 if (file_browser_handler->HasKey(keys::kPageActionDefaultIcon)) { |
821 if (!file_browser_handler->GetString( | 835 if (!file_browser_handler->GetString( |
822 keys::kPageActionDefaultIcon,&default_icon) || | 836 keys::kPageActionDefaultIcon,&default_icon) || |
823 default_icon.empty()) { | 837 default_icon.empty()) { |
824 *error = errors::kInvalidPageActionIconPath; | 838 *error = ASCIIToUTF16(errors::kInvalidPageActionIconPath); |
825 return NULL; | 839 return NULL; |
826 } | 840 } |
827 result->set_icon_path(default_icon); | 841 result->set_icon_path(default_icon); |
828 } | 842 } |
829 | 843 |
830 return result.release(); | 844 return result.release(); |
831 } | 845 } |
832 | 846 |
833 ExtensionSidebarDefaults* Extension::LoadExtensionSidebarDefaults( | 847 ExtensionSidebarDefaults* Extension::LoadExtensionSidebarDefaults( |
834 const DictionaryValue* extension_sidebar, std::string* error) { | 848 const DictionaryValue* extension_sidebar, string16* error) { |
835 scoped_ptr<ExtensionSidebarDefaults> result(new ExtensionSidebarDefaults()); | 849 scoped_ptr<ExtensionSidebarDefaults> result(new ExtensionSidebarDefaults()); |
836 | 850 |
837 std::string default_icon; | 851 std::string default_icon; |
838 // Read sidebar's |default_icon| (optional). | 852 // Read sidebar's |default_icon| (optional). |
839 if (extension_sidebar->HasKey(keys::kSidebarDefaultIcon)) { | 853 if (extension_sidebar->HasKey(keys::kSidebarDefaultIcon)) { |
840 if (!extension_sidebar->GetString(keys::kSidebarDefaultIcon, | 854 if (!extension_sidebar->GetString(keys::kSidebarDefaultIcon, |
841 &default_icon) || | 855 &default_icon) || |
842 default_icon.empty()) { | 856 default_icon.empty()) { |
843 *error = errors::kInvalidSidebarDefaultIconPath; | 857 *error = ASCIIToUTF16(errors::kInvalidSidebarDefaultIconPath); |
844 return NULL; | 858 return NULL; |
845 } | 859 } |
846 result->set_default_icon_path(default_icon); | 860 result->set_default_icon_path(default_icon); |
847 } | 861 } |
848 | 862 |
849 // Read sidebar's |default_title| (optional). | 863 // Read sidebar's |default_title| (optional). |
850 string16 default_title; | 864 string16 default_title; |
851 if (extension_sidebar->HasKey(keys::kSidebarDefaultTitle)) { | 865 if (extension_sidebar->HasKey(keys::kSidebarDefaultTitle)) { |
852 if (!extension_sidebar->GetString(keys::kSidebarDefaultTitle, | 866 if (!extension_sidebar->GetString(keys::kSidebarDefaultTitle, |
853 &default_title)) { | 867 &default_title)) { |
854 *error = errors::kInvalidSidebarDefaultTitle; | 868 *error = ASCIIToUTF16(errors::kInvalidSidebarDefaultTitle); |
855 return NULL; | 869 return NULL; |
856 } | 870 } |
857 } | 871 } |
858 result->set_default_title(default_title); | 872 result->set_default_title(default_title); |
859 | 873 |
860 // Read sidebar's |default_page| (optional). | 874 // Read sidebar's |default_page| (optional). |
| 875 // TODO(rdevlin.cronin): Continue removing std::string errors and replace |
| 876 // with string16 |
861 std::string default_page; | 877 std::string default_page; |
| 878 std::string utf8_error; |
862 if (extension_sidebar->HasKey(keys::kSidebarDefaultPage)) { | 879 if (extension_sidebar->HasKey(keys::kSidebarDefaultPage)) { |
863 if (!extension_sidebar->GetString(keys::kSidebarDefaultPage, | 880 if (!extension_sidebar->GetString(keys::kSidebarDefaultPage, |
864 &default_page) || | 881 &default_page) || |
865 default_page.empty()) { | 882 default_page.empty()) { |
866 *error = errors::kInvalidSidebarDefaultPage; | 883 *error = ASCIIToUTF16(errors::kInvalidSidebarDefaultPage); |
867 return NULL; | 884 return NULL; |
868 } | 885 } |
869 GURL url = extension_sidebar_utils::ResolveRelativePath( | 886 GURL url = extension_sidebar_utils::ResolveRelativePath( |
870 default_page, this, error); | 887 default_page, this, &utf8_error); |
| 888 *error = UTF8ToUTF16(utf8_error); |
871 if (!url.is_valid()) | 889 if (!url.is_valid()) |
872 return NULL; | 890 return NULL; |
873 result->set_default_page(url); | 891 result->set_default_page(url); |
874 } | 892 } |
875 | 893 |
876 return result.release(); | 894 return result.release(); |
877 } | 895 } |
878 | 896 |
879 bool Extension::LoadExtent(const extensions::Manifest* manifest, | 897 bool Extension::LoadExtent(const extensions::Manifest* manifest, |
880 const char* key, | 898 const char* key, |
881 URLPatternSet* extent, | 899 URLPatternSet* extent, |
882 const char* list_error, | 900 const char* list_error, |
883 const char* value_error, | 901 const char* value_error, |
884 URLPattern::ParseOption parse_option, | 902 URLPattern::ParseOption parse_option, |
885 std::string* error) { | 903 string16* error) { |
886 Value* temp = NULL; | 904 Value* temp = NULL; |
887 if (!manifest->Get(key, &temp)) | 905 if (!manifest->Get(key, &temp)) |
888 return true; | 906 return true; |
889 | 907 |
890 if (temp->GetType() != Value::TYPE_LIST) { | 908 if (temp->GetType() != Value::TYPE_LIST) { |
891 *error = list_error; | 909 *error = ASCIIToUTF16(list_error); |
892 return false; | 910 return false; |
893 } | 911 } |
894 | 912 |
895 ListValue* pattern_list = static_cast<ListValue*>(temp); | 913 ListValue* pattern_list = static_cast<ListValue*>(temp); |
896 for (size_t i = 0; i < pattern_list->GetSize(); ++i) { | 914 for (size_t i = 0; i < pattern_list->GetSize(); ++i) { |
897 std::string pattern_string; | 915 std::string pattern_string; |
898 if (!pattern_list->GetString(i, &pattern_string)) { | 916 if (!pattern_list->GetString(i, &pattern_string)) { |
899 *error = ExtensionErrorUtils::FormatErrorMessage(value_error, | 917 *error = ExtensionErrorUtils::FormatErrorMessageUTF16(value_error, |
900 base::UintToString(i), | 918 base::UintToString(i), |
901 errors::kExpectString); | 919 errors::kExpectString); |
902 return false; | 920 return false; |
903 } | 921 } |
904 | 922 |
905 URLPattern pattern(parse_option, kValidWebExtentSchemes); | 923 URLPattern pattern(parse_option, kValidWebExtentSchemes); |
906 URLPattern::ParseResult parse_result = pattern.Parse(pattern_string); | 924 URLPattern::ParseResult parse_result = pattern.Parse(pattern_string); |
907 if (parse_result == URLPattern::PARSE_ERROR_EMPTY_PATH) { | 925 if (parse_result == URLPattern::PARSE_ERROR_EMPTY_PATH) { |
908 pattern_string += "/"; | 926 pattern_string += "/"; |
909 parse_result = pattern.Parse(pattern_string); | 927 parse_result = pattern.Parse(pattern_string); |
910 } | 928 } |
911 | 929 |
912 if (parse_result != URLPattern::PARSE_SUCCESS) { | 930 if (parse_result != URLPattern::PARSE_SUCCESS) { |
913 *error = ExtensionErrorUtils::FormatErrorMessage( | 931 *error = ExtensionErrorUtils::FormatErrorMessageUTF16( |
914 value_error, | 932 value_error, |
915 base::UintToString(i), | 933 base::UintToString(i), |
916 URLPattern::GetParseResultString(parse_result)); | 934 URLPattern::GetParseResultString(parse_result)); |
917 return false; | 935 return false; |
918 } | 936 } |
919 | 937 |
920 // Do not allow authors to claim "<all_urls>". | 938 // Do not allow authors to claim "<all_urls>". |
921 if (pattern.match_all_urls()) { | 939 if (pattern.match_all_urls()) { |
922 *error = ExtensionErrorUtils::FormatErrorMessage( | 940 *error = ExtensionErrorUtils::FormatErrorMessageUTF16( |
923 value_error, | 941 value_error, |
924 base::UintToString(i), | 942 base::UintToString(i), |
925 errors::kCannotClaimAllURLsInExtent); | 943 errors::kCannotClaimAllURLsInExtent); |
926 return false; | 944 return false; |
927 } | 945 } |
928 | 946 |
929 // Do not allow authors to claim "*" for host. | 947 // Do not allow authors to claim "*" for host. |
930 if (pattern.host().empty()) { | 948 if (pattern.host().empty()) { |
931 *error = ExtensionErrorUtils::FormatErrorMessage( | 949 *error = ExtensionErrorUtils::FormatErrorMessageUTF16( |
932 value_error, | 950 value_error, |
933 base::UintToString(i), | 951 base::UintToString(i), |
934 errors::kCannotClaimAllHostsInExtent); | 952 errors::kCannotClaimAllHostsInExtent); |
935 return false; | 953 return false; |
936 } | 954 } |
937 | 955 |
938 // We do not allow authors to put wildcards in their paths. Instead, we | 956 // We do not allow authors to put wildcards in their paths. Instead, we |
939 // imply one at the end. | 957 // imply one at the end. |
940 if (pattern.path().find('*') != std::string::npos) { | 958 if (pattern.path().find('*') != std::string::npos) { |
941 *error = ExtensionErrorUtils::FormatErrorMessage( | 959 *error = ExtensionErrorUtils::FormatErrorMessageUTF16( |
942 value_error, | 960 value_error, |
943 base::UintToString(i), | 961 base::UintToString(i), |
944 errors::kNoWildCardsInPaths); | 962 errors::kNoWildCardsInPaths); |
945 return false; | 963 return false; |
946 } | 964 } |
947 pattern.SetPath(pattern.path() + '*'); | 965 pattern.SetPath(pattern.path() + '*'); |
948 | 966 |
949 extent->AddPattern(pattern); | 967 extent->AddPattern(pattern); |
950 } | 968 } |
951 | 969 |
952 return true; | 970 return true; |
953 } | 971 } |
954 | 972 |
955 bool Extension::LoadLaunchURL(const extensions::Manifest* manifest, | 973 bool Extension::LoadLaunchURL(const extensions::Manifest* manifest, |
956 std::string* error) { | 974 string16* error) { |
957 Value* temp = NULL; | 975 Value* temp = NULL; |
958 | 976 |
959 // launch URL can be either local (to chrome-extension:// root) or an absolute | 977 // launch URL can be either local (to chrome-extension:// root) or an absolute |
960 // web URL. | 978 // web URL. |
961 if (manifest->Get(keys::kLaunchLocalPath, &temp)) { | 979 if (manifest->Get(keys::kLaunchLocalPath, &temp)) { |
962 if (manifest->Get(keys::kLaunchWebURL, NULL)) { | 980 if (manifest->Get(keys::kLaunchWebURL, NULL)) { |
963 *error = errors::kLaunchPathAndURLAreExclusive; | 981 *error = ASCIIToUTF16(errors::kLaunchPathAndURLAreExclusive); |
964 return false; | 982 return false; |
965 } | 983 } |
966 | 984 |
967 if (manifest->Get(keys::kWebURLs, NULL)) { | 985 if (manifest->Get(keys::kWebURLs, NULL)) { |
968 *error = errors::kLaunchPathAndExtentAreExclusive; | 986 *error = ASCIIToUTF16(errors::kLaunchPathAndExtentAreExclusive); |
969 return false; | 987 return false; |
970 } | 988 } |
971 | 989 |
972 std::string launch_path; | 990 std::string launch_path; |
973 if (!temp->GetAsString(&launch_path)) { | 991 if (!temp->GetAsString(&launch_path)) { |
974 *error = errors::kInvalidLaunchLocalPath; | 992 *error = ASCIIToUTF16(errors::kInvalidLaunchLocalPath); |
975 return false; | 993 return false; |
976 } | 994 } |
977 | 995 |
978 // Ensure the launch path is a valid relative URL. | 996 // Ensure the launch path is a valid relative URL. |
979 GURL resolved = url().Resolve(launch_path); | 997 GURL resolved = url().Resolve(launch_path); |
980 if (!resolved.is_valid() || resolved.GetOrigin() != url()) { | 998 if (!resolved.is_valid() || resolved.GetOrigin() != url()) { |
981 *error = errors::kInvalidLaunchLocalPath; | 999 *error = ASCIIToUTF16(errors::kInvalidLaunchLocalPath); |
982 return false; | 1000 return false; |
983 } | 1001 } |
984 | 1002 |
985 launch_local_path_ = launch_path; | 1003 launch_local_path_ = launch_path; |
986 } else if (manifest->Get(keys::kLaunchWebURL, &temp)) { | 1004 } else if (manifest->Get(keys::kLaunchWebURL, &temp)) { |
987 std::string launch_url; | 1005 std::string launch_url; |
988 if (!temp->GetAsString(&launch_url)) { | 1006 if (!temp->GetAsString(&launch_url)) { |
989 *error = errors::kInvalidLaunchWebURL; | 1007 *error = ASCIIToUTF16(errors::kInvalidLaunchWebURL); |
990 return false; | 1008 return false; |
991 } | 1009 } |
992 | 1010 |
993 // Ensure the launch URL is a valid absolute URL and web extent scheme. | 1011 // Ensure the launch URL is a valid absolute URL and web extent scheme. |
994 GURL url(launch_url); | 1012 GURL url(launch_url); |
995 URLPattern pattern(URLPattern::USE_PORTS, kValidWebExtentSchemes); | 1013 URLPattern pattern(URLPattern::USE_PORTS, kValidWebExtentSchemes); |
996 if (!url.is_valid() || !pattern.SetScheme(url.scheme())) { | 1014 if (!url.is_valid() || !pattern.SetScheme(url.scheme())) { |
997 *error = errors::kInvalidLaunchWebURL; | 1015 *error = ASCIIToUTF16(errors::kInvalidLaunchWebURL); |
998 return false; | 1016 return false; |
999 } | 1017 } |
1000 | 1018 |
1001 launch_web_url_ = launch_url; | 1019 launch_web_url_ = launch_url; |
1002 } else if (is_app()) { | 1020 } else if (is_app()) { |
1003 *error = errors::kLaunchURLRequired; | 1021 *error = ASCIIToUTF16(errors::kLaunchURLRequired); |
1004 return false; | 1022 return false; |
1005 } | 1023 } |
1006 | 1024 |
1007 // If there is no extent, we default the extent based on the launch URL. | 1025 // If there is no extent, we default the extent based on the launch URL. |
1008 if (web_extent().is_empty() && !launch_web_url().empty()) { | 1026 if (web_extent().is_empty() && !launch_web_url().empty()) { |
1009 GURL launch_url(launch_web_url()); | 1027 GURL launch_url(launch_web_url()); |
1010 URLPattern pattern(URLPattern::USE_PORTS, kValidWebExtentSchemes); | 1028 URLPattern pattern(URLPattern::USE_PORTS, kValidWebExtentSchemes); |
1011 if (!pattern.SetScheme("*")) { | 1029 if (!pattern.SetScheme("*")) { |
1012 *error = errors::kInvalidLaunchWebURL; | 1030 *error = ASCIIToUTF16(errors::kInvalidLaunchWebURL); |
1013 return false; | 1031 return false; |
1014 } | 1032 } |
1015 pattern.SetHost(launch_url.host()); | 1033 pattern.SetHost(launch_url.host()); |
1016 pattern.SetPath("/*"); | 1034 pattern.SetPath("/*"); |
1017 extent_.AddPattern(pattern); | 1035 extent_.AddPattern(pattern); |
1018 } | 1036 } |
1019 | 1037 |
1020 // In order for the --apps-gallery-url switch to work with the gallery | 1038 // In order for the --apps-gallery-url switch to work with the gallery |
1021 // process isolation, we must insert any provided value into the component | 1039 // process isolation, we must insert any provided value into the component |
1022 // app's launch url and web extent. | 1040 // app's launch url and web extent. |
(...skipping 21 matching lines...) Expand all Loading... |
1044 replacements.SetPathStr(path); | 1062 replacements.SetPathStr(path); |
1045 GURL cloud_print_enable_connector_url = | 1063 GURL cloud_print_enable_connector_url = |
1046 cloud_print_service_url.ReplaceComponents(replacements); | 1064 cloud_print_service_url.ReplaceComponents(replacements); |
1047 OverrideLaunchUrl(cloud_print_enable_connector_url); | 1065 OverrideLaunchUrl(cloud_print_enable_connector_url); |
1048 } | 1066 } |
1049 } | 1067 } |
1050 return true; | 1068 return true; |
1051 } | 1069 } |
1052 | 1070 |
1053 bool Extension::LoadLaunchContainer(const extensions::Manifest* manifest, | 1071 bool Extension::LoadLaunchContainer(const extensions::Manifest* manifest, |
1054 std::string* error) { | 1072 string16* error) { |
1055 Value* temp = NULL; | 1073 Value* temp = NULL; |
1056 if (!manifest->Get(keys::kLaunchContainer, &temp)) | 1074 if (!manifest->Get(keys::kLaunchContainer, &temp)) |
1057 return true; | 1075 return true; |
1058 | 1076 |
1059 std::string launch_container_string; | 1077 std::string launch_container_string; |
1060 if (!temp->GetAsString(&launch_container_string)) { | 1078 if (!temp->GetAsString(&launch_container_string)) { |
1061 *error = errors::kInvalidLaunchContainer; | 1079 *error = ASCIIToUTF16(errors::kInvalidLaunchContainer); |
1062 return false; | 1080 return false; |
1063 } | 1081 } |
1064 | 1082 |
1065 if (launch_container_string == values::kLaunchContainerShell) { | 1083 if (launch_container_string == values::kLaunchContainerShell) { |
1066 launch_container_ = extension_misc::LAUNCH_SHELL; | 1084 launch_container_ = extension_misc::LAUNCH_SHELL; |
1067 } else if (launch_container_string == values::kLaunchContainerPanel) { | 1085 } else if (launch_container_string == values::kLaunchContainerPanel) { |
1068 launch_container_ = extension_misc::LAUNCH_PANEL; | 1086 launch_container_ = extension_misc::LAUNCH_PANEL; |
1069 } else if (launch_container_string == values::kLaunchContainerTab) { | 1087 } else if (launch_container_string == values::kLaunchContainerTab) { |
1070 launch_container_ = extension_misc::LAUNCH_TAB; | 1088 launch_container_ = extension_misc::LAUNCH_TAB; |
1071 } else { | 1089 } else { |
1072 *error = errors::kInvalidLaunchContainer; | 1090 *error = ASCIIToUTF16(errors::kInvalidLaunchContainer); |
1073 return false; | 1091 return false; |
1074 } | 1092 } |
1075 | 1093 |
1076 // Validate the container width if present. | 1094 // Validate the container width if present. |
1077 if (manifest->Get(keys::kLaunchWidth, &temp)) { | 1095 if (manifest->Get(keys::kLaunchWidth, &temp)) { |
1078 if (launch_container() != extension_misc::LAUNCH_PANEL && | 1096 if (launch_container() != extension_misc::LAUNCH_PANEL && |
1079 launch_container() != extension_misc::LAUNCH_WINDOW) { | 1097 launch_container() != extension_misc::LAUNCH_WINDOW) { |
1080 *error = errors::kInvalidLaunchWidthContainer; | 1098 *error = ASCIIToUTF16(errors::kInvalidLaunchWidthContainer); |
1081 return false; | 1099 return false; |
1082 } | 1100 } |
1083 if (!temp->GetAsInteger(&launch_width_) || | 1101 if (!temp->GetAsInteger(&launch_width_) || |
1084 launch_width_ < 0) { | 1102 launch_width_ < 0) { |
1085 launch_width_ = 0; | 1103 launch_width_ = 0; |
1086 *error = errors::kInvalidLaunchWidth; | 1104 *error = ASCIIToUTF16(errors::kInvalidLaunchWidth); |
1087 return false; | 1105 return false; |
1088 } | 1106 } |
1089 } | 1107 } |
1090 | 1108 |
1091 // Validate container height if present. | 1109 // Validate container height if present. |
1092 if (manifest->Get(keys::kLaunchHeight, &temp)) { | 1110 if (manifest->Get(keys::kLaunchHeight, &temp)) { |
1093 if (launch_container() != extension_misc::LAUNCH_PANEL && | 1111 if (launch_container() != extension_misc::LAUNCH_PANEL && |
1094 launch_container() != extension_misc::LAUNCH_WINDOW) { | 1112 launch_container() != extension_misc::LAUNCH_WINDOW) { |
1095 *error = errors::kInvalidLaunchHeightContainer; | 1113 *error = ASCIIToUTF16(errors::kInvalidLaunchHeightContainer); |
1096 return false; | 1114 return false; |
1097 } | 1115 } |
1098 if (!temp->GetAsInteger(&launch_height_) || launch_height_ < 0) { | 1116 if (!temp->GetAsInteger(&launch_height_) || launch_height_ < 0) { |
1099 launch_height_ = 0; | 1117 launch_height_ = 0; |
1100 *error = errors::kInvalidLaunchHeight; | 1118 *error = ASCIIToUTF16(errors::kInvalidLaunchHeight); |
1101 return false; | 1119 return false; |
1102 } | 1120 } |
1103 } | 1121 } |
1104 | 1122 |
1105 return true; | 1123 return true; |
1106 } | 1124 } |
1107 | 1125 |
1108 bool Extension::LoadAppIsolation(const extensions::Manifest* manifest, | 1126 bool Extension::LoadAppIsolation(const extensions::Manifest* manifest, |
1109 std::string* error) { | 1127 string16* error) { |
1110 Value* temp = NULL; | 1128 Value* temp = NULL; |
1111 if (!manifest->Get(keys::kIsolation, &temp)) | 1129 if (!manifest->Get(keys::kIsolation, &temp)) |
1112 return true; | 1130 return true; |
1113 | 1131 |
1114 if (temp->GetType() != Value::TYPE_LIST) { | 1132 if (temp->GetType() != Value::TYPE_LIST) { |
1115 *error = errors::kInvalidIsolation; | 1133 *error = ASCIIToUTF16(errors::kInvalidIsolation); |
1116 return false; | 1134 return false; |
1117 } | 1135 } |
1118 | 1136 |
1119 ListValue* isolation_list = static_cast<ListValue*>(temp); | 1137 ListValue* isolation_list = static_cast<ListValue*>(temp); |
1120 for (size_t i = 0; i < isolation_list->GetSize(); ++i) { | 1138 for (size_t i = 0; i < isolation_list->GetSize(); ++i) { |
1121 std::string isolation_string; | 1139 std::string isolation_string; |
1122 if (!isolation_list->GetString(i, &isolation_string)) { | 1140 if (!isolation_list->GetString(i, &isolation_string)) { |
1123 *error = ExtensionErrorUtils::FormatErrorMessage( | 1141 *error = ExtensionErrorUtils::FormatErrorMessageUTF16( |
1124 errors::kInvalidIsolationValue, | 1142 errors::kInvalidIsolationValue, |
1125 base::UintToString(i)); | 1143 base::UintToString(i)); |
1126 return false; | 1144 return false; |
1127 } | 1145 } |
1128 | 1146 |
1129 // Check for isolated storage. | 1147 // Check for isolated storage. |
1130 if (isolation_string == values::kIsolatedStorage) { | 1148 if (isolation_string == values::kIsolatedStorage) { |
1131 is_storage_isolated_ = true; | 1149 is_storage_isolated_ = true; |
1132 } else { | 1150 } else { |
1133 DLOG(WARNING) << "Did not recognize isolation type: " | 1151 DLOG(WARNING) << "Did not recognize isolation type: " |
1134 << isolation_string; | 1152 << isolation_string; |
1135 } | 1153 } |
1136 } | 1154 } |
1137 return true; | 1155 return true; |
1138 } | 1156 } |
1139 | 1157 |
1140 bool Extension::LoadWebIntentServices(const extensions::Manifest* manifest, | 1158 bool Extension::LoadWebIntentServices(const extensions::Manifest* manifest, |
1141 std::string* error) { | 1159 string16* error) { |
1142 DCHECK(error); | 1160 DCHECK(error); |
1143 | 1161 |
1144 if (!CommandLine::ForCurrentProcess()->HasSwitch(switches::kEnableWebIntents)) | 1162 if (!CommandLine::ForCurrentProcess()->HasSwitch(switches::kEnableWebIntents)) |
1145 return true; | 1163 return true; |
1146 | 1164 |
1147 if (!manifest->HasKey(keys::kIntents)) | 1165 if (!manifest->HasKey(keys::kIntents)) |
1148 return true; | 1166 return true; |
1149 | 1167 |
1150 DictionaryValue* all_services = NULL; | 1168 DictionaryValue* all_services = NULL; |
1151 if (!manifest->GetDictionary(keys::kIntents, &all_services)) { | 1169 if (!manifest->GetDictionary(keys::kIntents, &all_services)) { |
1152 *error = errors::kInvalidIntents; | 1170 *error = ASCIIToUTF16(errors::kInvalidIntents); |
1153 return false; | 1171 return false; |
1154 } | 1172 } |
1155 | 1173 |
1156 std::string value; | 1174 std::string value; |
1157 for (DictionaryValue::key_iterator iter(all_services->begin_keys()); | 1175 for (DictionaryValue::key_iterator iter(all_services->begin_keys()); |
1158 iter != all_services->end_keys(); ++iter) { | 1176 iter != all_services->end_keys(); ++iter) { |
1159 webkit_glue::WebIntentServiceData service; | 1177 webkit_glue::WebIntentServiceData service; |
1160 | 1178 |
1161 DictionaryValue* one_service = NULL; | 1179 DictionaryValue* one_service = NULL; |
1162 if (!all_services->GetDictionaryWithoutPathExpansion(*iter, &one_service)) { | 1180 if (!all_services->GetDictionaryWithoutPathExpansion(*iter, &one_service)) { |
1163 *error = errors::kInvalidIntent; | 1181 *error = ASCIIToUTF16(errors::kInvalidIntent); |
1164 return false; | 1182 return false; |
1165 } | 1183 } |
1166 service.action = UTF8ToUTF16(*iter); | 1184 service.action = UTF8ToUTF16(*iter); |
1167 | 1185 |
1168 // TODO(groby): Support an array of types. | 1186 // TODO(groby): Support an array of types. |
1169 if (one_service->HasKey(keys::kIntentType) && | 1187 if (one_service->HasKey(keys::kIntentType) && |
1170 !one_service->GetString(keys::kIntentType, &service.type)) { | 1188 !one_service->GetString(keys::kIntentType, &service.type)) { |
1171 *error = errors::kInvalidIntentType; | 1189 *error = ASCIIToUTF16(errors::kInvalidIntentType); |
1172 return false; | 1190 return false; |
1173 } | 1191 } |
1174 | 1192 |
1175 if (one_service->HasKey(keys::kIntentPath)) { | 1193 if (one_service->HasKey(keys::kIntentPath)) { |
1176 if (!one_service->GetString(keys::kIntentPath, &value)) { | 1194 if (!one_service->GetString(keys::kIntentPath, &value)) { |
1177 *error = errors::kInvalidIntentPath; | 1195 *error = ASCIIToUTF16(errors::kInvalidIntentPath); |
1178 return false; | 1196 return false; |
1179 } | 1197 } |
1180 service.service_url = GetResourceURL(value); | 1198 service.service_url = GetResourceURL(value); |
1181 } | 1199 } |
1182 | 1200 |
1183 if (one_service->HasKey(keys::kIntentTitle) && | 1201 if (one_service->HasKey(keys::kIntentTitle) && |
1184 !one_service->GetString(keys::kIntentTitle, &service.title)) { | 1202 !one_service->GetString(keys::kIntentTitle, &service.title)) { |
1185 *error = errors::kInvalidIntentTitle; | 1203 *error = ASCIIToUTF16(errors::kInvalidIntentTitle); |
1186 return false; | 1204 return false; |
1187 } | 1205 } |
1188 | 1206 |
1189 if (one_service->HasKey(keys::kIntentDisposition)) { | 1207 if (one_service->HasKey(keys::kIntentDisposition)) { |
1190 if (!one_service->GetString(keys::kIntentDisposition, &value) || | 1208 if (!one_service->GetString(keys::kIntentDisposition, &value) || |
1191 (value != values::kIntentDispositionWindow && | 1209 (value != values::kIntentDispositionWindow && |
1192 value != values::kIntentDispositionInline)) { | 1210 value != values::kIntentDispositionInline)) { |
1193 *error = errors::kInvalidIntentDisposition; | 1211 *error = ASCIIToUTF16(errors::kInvalidIntentDisposition); |
1194 return false; | 1212 return false; |
1195 } | 1213 } |
1196 if (value == values::kIntentDispositionInline) { | 1214 if (value == values::kIntentDispositionInline) { |
1197 service.disposition = | 1215 service.disposition = |
1198 webkit_glue::WebIntentServiceData::DISPOSITION_INLINE; | 1216 webkit_glue::WebIntentServiceData::DISPOSITION_INLINE; |
1199 } else { | 1217 } else { |
1200 service.disposition = | 1218 service.disposition = |
1201 webkit_glue::WebIntentServiceData::DISPOSITION_WINDOW; | 1219 webkit_glue::WebIntentServiceData::DISPOSITION_WINDOW; |
1202 } | 1220 } |
1203 } | 1221 } |
(...skipping 167 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1371 IDR_EXTENSION_DEFAULT_ICON); | 1389 IDR_EXTENSION_DEFAULT_ICON); |
1372 } | 1390 } |
1373 } | 1391 } |
1374 | 1392 |
1375 GURL Extension::GetBaseURLFromExtensionId(const std::string& extension_id) { | 1393 GURL Extension::GetBaseURLFromExtensionId(const std::string& extension_id) { |
1376 return GURL(std::string(chrome::kExtensionScheme) + | 1394 return GURL(std::string(chrome::kExtensionScheme) + |
1377 chrome::kStandardSchemeSeparator + extension_id + "/"); | 1395 chrome::kStandardSchemeSeparator + extension_id + "/"); |
1378 } | 1396 } |
1379 | 1397 |
1380 bool Extension::InitFromValue(extensions::Manifest* manifest, int flags, | 1398 bool Extension::InitFromValue(extensions::Manifest* manifest, int flags, |
1381 std::string* error) { | 1399 string16* error) { |
1382 DCHECK(error); | 1400 DCHECK(error); |
1383 base::AutoLock auto_lock(runtime_data_lock_); | 1401 base::AutoLock auto_lock(runtime_data_lock_); |
1384 manifest_.reset(manifest); | 1402 manifest_.reset(manifest); |
1385 | 1403 |
1386 if (!manifest->ValidateManifest(error)) | 1404 if (!manifest->ValidateManifest(error)) |
1387 return false; | 1405 return false; |
1388 | 1406 |
1389 // When strict error checks are enabled, make URL pattern parsing strict. | 1407 // When strict error checks are enabled, make URL pattern parsing strict. |
1390 URLPattern::ParseOption parse_option = | 1408 URLPattern::ParseOption parse_option = |
1391 (flags & STRICT_ERROR_CHECKS ? URLPattern::ERROR_ON_PORTS | 1409 (flags & STRICT_ERROR_CHECKS ? URLPattern::ERROR_ON_PORTS |
1392 : URLPattern::IGNORE_PORTS); | 1410 : URLPattern::IGNORE_PORTS); |
1393 | 1411 |
1394 // Initialize permissions with an empty, default permission set. | 1412 // Initialize permissions with an empty, default permission set. |
1395 runtime_data_.SetActivePermissions(new ExtensionPermissionSet()); | 1413 runtime_data_.SetActivePermissions(new ExtensionPermissionSet()); |
1396 optional_permission_set_ = new ExtensionPermissionSet(); | 1414 optional_permission_set_ = new ExtensionPermissionSet(); |
1397 required_permission_set_ = new ExtensionPermissionSet(); | 1415 required_permission_set_ = new ExtensionPermissionSet(); |
1398 | 1416 |
1399 if (manifest->HasKey(keys::kManifestVersion)) { | 1417 if (manifest->HasKey(keys::kManifestVersion)) { |
1400 int manifest_version = 0; | 1418 int manifest_version = 0; |
1401 if (!manifest->GetInteger(keys::kManifestVersion, &manifest_version) || | 1419 if (!manifest->GetInteger(keys::kManifestVersion, &manifest_version) || |
1402 manifest_version < 1) { | 1420 manifest_version < 1) { |
1403 *error = errors::kInvalidManifestVersion; | 1421 *error = ASCIIToUTF16(errors::kInvalidManifestVersion); |
1404 return false; | 1422 return false; |
1405 } | 1423 } |
1406 manifest_version_ = manifest_version; | 1424 manifest_version_ = manifest_version; |
1407 } else { | 1425 } else { |
1408 // Version 1 was the original version, which lacked a version indicator. | 1426 // Version 1 was the original version, which lacked a version indicator. |
1409 manifest_version_ = 1; | 1427 manifest_version_ = 1; |
1410 } | 1428 } |
1411 | 1429 |
1412 if (flags & REQUIRE_MODERN_MANIFEST_VERSION && | 1430 if (flags & REQUIRE_MODERN_MANIFEST_VERSION && |
1413 manifest_version() < kModernManifestVersion && | 1431 manifest_version() < kModernManifestVersion && |
1414 !CommandLine::ForCurrentProcess()->HasSwitch( | 1432 !CommandLine::ForCurrentProcess()->HasSwitch( |
1415 switches::kAllowLegacyExtensionManifests)) { | 1433 switches::kAllowLegacyExtensionManifests)) { |
1416 *error = errors::kInvalidManifestVersion; | 1434 *error = ASCIIToUTF16(errors::kInvalidManifestVersion); |
1417 return false; | 1435 return false; |
1418 } | 1436 } |
1419 | 1437 |
1420 if (manifest->HasKey(keys::kPublicKey)) { | 1438 if (manifest->HasKey(keys::kPublicKey)) { |
1421 std::string public_key_bytes; | 1439 std::string public_key_bytes; |
1422 if (!manifest->GetString(keys::kPublicKey, | 1440 if (!manifest->GetString(keys::kPublicKey, |
1423 &public_key_) || | 1441 &public_key_) || |
1424 !ParsePEMKeyBytes(public_key_, | 1442 !ParsePEMKeyBytes(public_key_, |
1425 &public_key_bytes) || | 1443 &public_key_bytes) || |
1426 !GenerateId(public_key_bytes, &id_)) { | 1444 !GenerateId(public_key_bytes, &id_)) { |
1427 *error = errors::kInvalidKey; | 1445 *error = ASCIIToUTF16(errors::kInvalidKey); |
1428 return false; | 1446 return false; |
1429 } | 1447 } |
1430 } else if (flags & REQUIRE_KEY) { | 1448 } else if (flags & REQUIRE_KEY) { |
1431 *error = errors::kInvalidKey; | 1449 *error = ASCIIToUTF16(errors::kInvalidKey); |
1432 return false; | 1450 return false; |
1433 } else { | 1451 } else { |
1434 // If there is a path, we generate the ID from it. This is useful for | 1452 // If there is a path, we generate the ID from it. This is useful for |
1435 // development mode, because it keeps the ID stable across restarts and | 1453 // development mode, because it keeps the ID stable across restarts and |
1436 // reloading the extension. | 1454 // reloading the extension. |
1437 id_ = Extension::GenerateIdForPath(path()); | 1455 id_ = Extension::GenerateIdForPath(path()); |
1438 if (id_.empty()) { | 1456 if (id_.empty()) { |
1439 NOTREACHED() << "Could not create ID from path."; | 1457 NOTREACHED() << "Could not create ID from path."; |
1440 return false; | 1458 return false; |
1441 } | 1459 } |
1442 } | 1460 } |
1443 | 1461 |
1444 creation_flags_ = flags; | 1462 creation_flags_ = flags; |
1445 | 1463 |
1446 // Initialize the URL. | 1464 // Initialize the URL. |
1447 extension_url_ = Extension::GetBaseURLFromExtensionId(id()); | 1465 extension_url_ = Extension::GetBaseURLFromExtensionId(id()); |
1448 | 1466 |
1449 // Initialize version. | 1467 // Initialize version. |
1450 std::string version_str; | 1468 std::string version_str; |
1451 if (!manifest->GetString(keys::kVersion, &version_str)) { | 1469 if (!manifest->GetString(keys::kVersion, &version_str)) { |
1452 *error = errors::kInvalidVersion; | 1470 *error = ASCIIToUTF16(errors::kInvalidVersion); |
1453 return false; | 1471 return false; |
1454 } | 1472 } |
1455 version_.reset(Version::GetVersionFromString(version_str)); | 1473 version_.reset(Version::GetVersionFromString(version_str)); |
1456 if (!version_.get() || | 1474 if (!version_.get() || |
1457 version_->components().size() > 4) { | 1475 version_->components().size() > 4) { |
1458 *error = errors::kInvalidVersion; | 1476 *error = ASCIIToUTF16(errors::kInvalidVersion); |
1459 return false; | 1477 return false; |
1460 } | 1478 } |
1461 | 1479 |
1462 // Initialize name. | 1480 // Initialize name. |
1463 string16 localized_name; | 1481 string16 localized_name; |
1464 if (!manifest->GetString(keys::kName, &localized_name)) { | 1482 if (!manifest->GetString(keys::kName, &localized_name)) { |
1465 *error = errors::kInvalidName; | 1483 *error = ASCIIToUTF16(errors::kInvalidName); |
1466 return false; | 1484 return false; |
1467 } | 1485 } |
1468 base::i18n::AdjustStringForLocaleDirection(&localized_name); | 1486 base::i18n::AdjustStringForLocaleDirection(&localized_name); |
1469 name_ = UTF16ToUTF8(localized_name); | 1487 name_ = UTF16ToUTF8(localized_name); |
1470 | 1488 |
1471 // Load App settings. LoadExtent at least has to be done before | 1489 // Load App settings. LoadExtent at least has to be done before |
1472 // ParsePermissions(), because the valid permissions depend on what type of | 1490 // ParsePermissions(), because the valid permissions depend on what type of |
1473 // package this is. | 1491 // package this is. |
1474 if (is_app() && | 1492 if (is_app() && |
1475 (!LoadExtent(manifest_.get(), keys::kWebURLs, | 1493 (!LoadExtent(manifest_.get(), keys::kWebURLs, |
1476 &extent_, | 1494 &extent_, |
1477 errors::kInvalidWebURLs, errors::kInvalidWebURL, | 1495 errors::kInvalidWebURLs, errors::kInvalidWebURL, |
1478 parse_option, error) || | 1496 parse_option, error) || |
1479 !LoadLaunchURL(manifest_.get(), error) || | 1497 !LoadLaunchURL(manifest_.get(), error) || |
1480 !LoadLaunchContainer(manifest_.get(), error))) { | 1498 !LoadLaunchContainer(manifest_.get(), error))) { |
1481 return false; | 1499 return false; |
1482 } | 1500 } |
1483 | 1501 |
1484 if (is_platform_app()) { | 1502 if (is_platform_app()) { |
1485 if (launch_container() != extension_misc::LAUNCH_SHELL) { | 1503 if (launch_container() != extension_misc::LAUNCH_SHELL) { |
1486 *error = errors::kInvalidLaunchContainerForPlatform; | 1504 *error = ASCIIToUTF16(errors::kInvalidLaunchContainerForPlatform); |
1487 return false; | 1505 return false; |
1488 } | 1506 } |
1489 } else if (launch_container() == extension_misc::LAUNCH_SHELL) { | 1507 } else if (launch_container() == extension_misc::LAUNCH_SHELL) { |
1490 *error = errors::kInvalidLaunchContainerForNonPlatform; | 1508 *error = ASCIIToUTF16(errors::kInvalidLaunchContainerForNonPlatform); |
1491 return false; | 1509 return false; |
1492 } | 1510 } |
1493 | 1511 |
1494 // Initialize the permissions (optional). | 1512 // Initialize the permissions (optional). |
1495 ExtensionAPIPermissionSet api_permissions; | 1513 ExtensionAPIPermissionSet api_permissions; |
1496 URLPatternSet host_permissions; | 1514 URLPatternSet host_permissions; |
1497 if (!ParsePermissions(manifest_.get(), | 1515 if (!ParsePermissions(manifest_.get(), |
1498 keys::kPermissions, | 1516 keys::kPermissions, |
1499 flags, | 1517 flags, |
1500 error, | 1518 error, |
(...skipping 11 matching lines...) Expand all Loading... |
1512 error, | 1530 error, |
1513 &optional_api_permissions, | 1531 &optional_api_permissions, |
1514 &optional_host_permissions)) { | 1532 &optional_host_permissions)) { |
1515 return false; | 1533 return false; |
1516 } | 1534 } |
1517 | 1535 |
1518 // Initialize description (if present). | 1536 // Initialize description (if present). |
1519 if (manifest->HasKey(keys::kDescription)) { | 1537 if (manifest->HasKey(keys::kDescription)) { |
1520 if (!manifest->GetString(keys::kDescription, | 1538 if (!manifest->GetString(keys::kDescription, |
1521 &description_)) { | 1539 &description_)) { |
1522 *error = errors::kInvalidDescription; | 1540 *error = ASCIIToUTF16(errors::kInvalidDescription); |
1523 return false; | 1541 return false; |
1524 } | 1542 } |
1525 } | 1543 } |
1526 | 1544 |
1527 // Initialize homepage url (if present). | 1545 // Initialize homepage url (if present). |
1528 if (manifest->HasKey(keys::kHomepageURL)) { | 1546 if (manifest->HasKey(keys::kHomepageURL)) { |
1529 std::string tmp; | 1547 std::string tmp; |
1530 if (!manifest->GetString(keys::kHomepageURL, &tmp)) { | 1548 if (!manifest->GetString(keys::kHomepageURL, &tmp)) { |
1531 *error = ExtensionErrorUtils::FormatErrorMessage( | 1549 *error = ExtensionErrorUtils::FormatErrorMessageUTF16( |
1532 errors::kInvalidHomepageURL, ""); | 1550 errors::kInvalidHomepageURL, ""); |
1533 return false; | 1551 return false; |
1534 } | 1552 } |
1535 homepage_url_ = GURL(tmp); | 1553 homepage_url_ = GURL(tmp); |
1536 if (!homepage_url_.is_valid() || | 1554 if (!homepage_url_.is_valid() || |
1537 (!homepage_url_.SchemeIs("http") && | 1555 (!homepage_url_.SchemeIs("http") && |
1538 !homepage_url_.SchemeIs("https"))) { | 1556 !homepage_url_.SchemeIs("https"))) { |
1539 *error = ExtensionErrorUtils::FormatErrorMessage( | 1557 *error = ExtensionErrorUtils::FormatErrorMessageUTF16( |
1540 errors::kInvalidHomepageURL, tmp); | 1558 errors::kInvalidHomepageURL, tmp); |
1541 return false; | 1559 return false; |
1542 } | 1560 } |
1543 } | 1561 } |
1544 | 1562 |
1545 // Initialize update url (if present). | 1563 // Initialize update url (if present). |
1546 if (manifest->HasKey(keys::kUpdateURL)) { | 1564 if (manifest->HasKey(keys::kUpdateURL)) { |
1547 std::string tmp; | 1565 std::string tmp; |
1548 if (!manifest->GetString(keys::kUpdateURL, &tmp)) { | 1566 if (!manifest->GetString(keys::kUpdateURL, &tmp)) { |
1549 *error = ExtensionErrorUtils::FormatErrorMessage( | 1567 *error = ExtensionErrorUtils::FormatErrorMessageUTF16( |
1550 errors::kInvalidUpdateURL, ""); | 1568 errors::kInvalidUpdateURL, ""); |
1551 return false; | 1569 return false; |
1552 } | 1570 } |
1553 update_url_ = GURL(tmp); | 1571 update_url_ = GURL(tmp); |
1554 if (!update_url_.is_valid() || | 1572 if (!update_url_.is_valid() || |
1555 update_url_.has_ref()) { | 1573 update_url_.has_ref()) { |
1556 *error = ExtensionErrorUtils::FormatErrorMessage( | 1574 *error = ExtensionErrorUtils::FormatErrorMessageUTF16( |
1557 errors::kInvalidUpdateURL, tmp); | 1575 errors::kInvalidUpdateURL, tmp); |
1558 return false; | 1576 return false; |
1559 } | 1577 } |
1560 } | 1578 } |
1561 | 1579 |
1562 // Validate minimum Chrome version (if present). We don't need to store this, | 1580 // Validate minimum Chrome version (if present). We don't need to store this, |
1563 // since the extension is not valid if it is incorrect. | 1581 // since the extension is not valid if it is incorrect. |
1564 if (manifest->HasKey(keys::kMinimumChromeVersion)) { | 1582 if (manifest->HasKey(keys::kMinimumChromeVersion)) { |
1565 std::string minimum_version_string; | 1583 std::string minimum_version_string; |
1566 if (!manifest->GetString(keys::kMinimumChromeVersion, | 1584 if (!manifest->GetString(keys::kMinimumChromeVersion, |
1567 &minimum_version_string)) { | 1585 &minimum_version_string)) { |
1568 *error = errors::kInvalidMinimumChromeVersion; | 1586 *error = ASCIIToUTF16(errors::kInvalidMinimumChromeVersion); |
1569 return false; | 1587 return false; |
1570 } | 1588 } |
1571 | 1589 |
1572 scoped_ptr<Version> minimum_version( | 1590 scoped_ptr<Version> minimum_version( |
1573 Version::GetVersionFromString(minimum_version_string)); | 1591 Version::GetVersionFromString(minimum_version_string)); |
1574 if (!minimum_version.get()) { | 1592 if (!minimum_version.get()) { |
1575 *error = errors::kInvalidMinimumChromeVersion; | 1593 *error = ASCIIToUTF16(errors::kInvalidMinimumChromeVersion); |
1576 return false; | 1594 return false; |
1577 } | 1595 } |
1578 | 1596 |
1579 chrome::VersionInfo current_version_info; | 1597 chrome::VersionInfo current_version_info; |
1580 if (!current_version_info.is_valid()) { | 1598 if (!current_version_info.is_valid()) { |
1581 NOTREACHED(); | 1599 NOTREACHED(); |
1582 return false; | 1600 return false; |
1583 } | 1601 } |
1584 | 1602 |
1585 scoped_ptr<Version> current_version( | 1603 scoped_ptr<Version> current_version( |
1586 Version::GetVersionFromString(current_version_info.Version())); | 1604 Version::GetVersionFromString(current_version_info.Version())); |
1587 if (!current_version.get()) { | 1605 if (!current_version.get()) { |
1588 DCHECK(false); | 1606 DCHECK(false); |
1589 return false; | 1607 return false; |
1590 } | 1608 } |
1591 | 1609 |
1592 if (current_version->CompareTo(*minimum_version) < 0) { | 1610 if (current_version->CompareTo(*minimum_version) < 0) { |
1593 *error = ExtensionErrorUtils::FormatErrorMessage( | 1611 *error = ExtensionErrorUtils::FormatErrorMessageUTF16( |
1594 errors::kChromeVersionTooLow, | 1612 errors::kChromeVersionTooLow, |
1595 l10n_util::GetStringUTF8(IDS_PRODUCT_NAME), | 1613 l10n_util::GetStringUTF8(IDS_PRODUCT_NAME), |
1596 minimum_version_string); | 1614 minimum_version_string); |
1597 return false; | 1615 return false; |
1598 } | 1616 } |
1599 } | 1617 } |
1600 | 1618 |
1601 // Initialize converted_from_user_script (if present) | 1619 // Initialize converted_from_user_script (if present) |
1602 if (manifest->HasKey(keys::kConvertedFromUserScript)) | 1620 if (manifest->HasKey(keys::kConvertedFromUserScript)) |
1603 manifest->GetBoolean(keys::kConvertedFromUserScript, | 1621 manifest->GetBoolean(keys::kConvertedFromUserScript, |
1604 &converted_from_user_script_); | 1622 &converted_from_user_script_); |
1605 | 1623 |
1606 // Initialize icons (if present). | 1624 // Initialize icons (if present). |
1607 if (manifest->HasKey(keys::kIcons)) { | 1625 if (manifest->HasKey(keys::kIcons)) { |
1608 DictionaryValue* icons_value = NULL; | 1626 DictionaryValue* icons_value = NULL; |
1609 if (!manifest->GetDictionary(keys::kIcons, &icons_value)) { | 1627 if (!manifest->GetDictionary(keys::kIcons, &icons_value)) { |
1610 *error = errors::kInvalidIcons; | 1628 *error = ASCIIToUTF16(errors::kInvalidIcons); |
1611 return false; | 1629 return false; |
1612 } | 1630 } |
1613 | 1631 |
1614 for (size_t i = 0; i < arraysize(kIconSizes); ++i) { | 1632 for (size_t i = 0; i < arraysize(kIconSizes); ++i) { |
1615 std::string key = base::IntToString(kIconSizes[i]); | 1633 std::string key = base::IntToString(kIconSizes[i]); |
1616 if (icons_value->HasKey(key)) { | 1634 if (icons_value->HasKey(key)) { |
1617 std::string icon_path; | 1635 std::string icon_path; |
1618 if (!icons_value->GetString(key, &icon_path)) { | 1636 if (!icons_value->GetString(key, &icon_path)) { |
1619 *error = ExtensionErrorUtils::FormatErrorMessage( | 1637 *error = ExtensionErrorUtils::FormatErrorMessageUTF16( |
1620 errors::kInvalidIconPath, key); | 1638 errors::kInvalidIconPath, key); |
1621 return false; | 1639 return false; |
1622 } | 1640 } |
1623 | 1641 |
1624 if (!icon_path.empty() && icon_path[0] == '/') | 1642 if (!icon_path.empty() && icon_path[0] == '/') |
1625 icon_path = icon_path.substr(1); | 1643 icon_path = icon_path.substr(1); |
1626 | 1644 |
1627 if (icon_path.empty()) { | 1645 if (icon_path.empty()) { |
1628 *error = ExtensionErrorUtils::FormatErrorMessage( | 1646 *error = ExtensionErrorUtils::FormatErrorMessageUTF16( |
1629 errors::kInvalidIconPath, key); | 1647 errors::kInvalidIconPath, key); |
1630 return false; | 1648 return false; |
1631 } | 1649 } |
1632 | 1650 |
1633 icons_.Add(kIconSizes[i], icon_path); | 1651 icons_.Add(kIconSizes[i], icon_path); |
1634 } | 1652 } |
1635 } | 1653 } |
1636 } | 1654 } |
1637 | 1655 |
1638 // Initialize themes (if present). | 1656 // Initialize themes (if present). |
1639 if (manifest->HasKey(keys::kTheme)) { | 1657 if (manifest->HasKey(keys::kTheme)) { |
1640 DictionaryValue* theme_value = NULL; | 1658 DictionaryValue* theme_value = NULL; |
1641 if (!manifest->GetDictionary(keys::kTheme, &theme_value)) { | 1659 if (!manifest->GetDictionary(keys::kTheme, &theme_value)) { |
1642 *error = errors::kInvalidTheme; | 1660 *error = ASCIIToUTF16(errors::kInvalidTheme); |
1643 return false; | 1661 return false; |
1644 } | 1662 } |
1645 | 1663 |
1646 DictionaryValue* images_value = NULL; | 1664 DictionaryValue* images_value = NULL; |
1647 if (theme_value->GetDictionary(keys::kThemeImages, &images_value)) { | 1665 if (theme_value->GetDictionary(keys::kThemeImages, &images_value)) { |
1648 // Validate that the images are all strings | 1666 // Validate that the images are all strings |
1649 for (DictionaryValue::key_iterator iter = images_value->begin_keys(); | 1667 for (DictionaryValue::key_iterator iter = images_value->begin_keys(); |
1650 iter != images_value->end_keys(); ++iter) { | 1668 iter != images_value->end_keys(); ++iter) { |
1651 std::string val; | 1669 std::string val; |
1652 if (!images_value->GetString(*iter, &val)) { | 1670 if (!images_value->GetString(*iter, &val)) { |
1653 *error = errors::kInvalidThemeImages; | 1671 *error = ASCIIToUTF16(errors::kInvalidThemeImages); |
1654 return false; | 1672 return false; |
1655 } | 1673 } |
1656 } | 1674 } |
1657 theme_images_.reset(images_value->DeepCopy()); | 1675 theme_images_.reset(images_value->DeepCopy()); |
1658 } | 1676 } |
1659 | 1677 |
1660 DictionaryValue* colors_value = NULL; | 1678 DictionaryValue* colors_value = NULL; |
1661 if (theme_value->GetDictionary(keys::kThemeColors, &colors_value)) { | 1679 if (theme_value->GetDictionary(keys::kThemeColors, &colors_value)) { |
1662 // Validate that the colors are RGB or RGBA lists | 1680 // Validate that the colors are RGB or RGBA lists |
1663 for (DictionaryValue::key_iterator iter = colors_value->begin_keys(); | 1681 for (DictionaryValue::key_iterator iter = colors_value->begin_keys(); |
1664 iter != colors_value->end_keys(); ++iter) { | 1682 iter != colors_value->end_keys(); ++iter) { |
1665 ListValue* color_list = NULL; | 1683 ListValue* color_list = NULL; |
1666 double alpha = 0.0; | 1684 double alpha = 0.0; |
1667 int color = 0; | 1685 int color = 0; |
1668 // The color must be a list | 1686 // The color must be a list |
1669 if (!colors_value->GetListWithoutPathExpansion(*iter, &color_list) || | 1687 if (!colors_value->GetListWithoutPathExpansion(*iter, &color_list) || |
1670 // And either 3 items (RGB) or 4 (RGBA) | 1688 // And either 3 items (RGB) or 4 (RGBA) |
1671 ((color_list->GetSize() != 3) && | 1689 ((color_list->GetSize() != 3) && |
1672 ((color_list->GetSize() != 4) || | 1690 ((color_list->GetSize() != 4) || |
1673 // For RGBA, the fourth item must be a real or int alpha value. | 1691 // For RGBA, the fourth item must be a real or int alpha value. |
1674 // Note that GetDouble() can get an integer value. | 1692 // Note that GetDouble() can get an integer value. |
1675 !color_list->GetDouble(3, &alpha))) || | 1693 !color_list->GetDouble(3, &alpha))) || |
1676 // For both RGB and RGBA, the first three items must be ints (R,G,B) | 1694 // For both RGB and RGBA, the first three items must be ints (R,G,B) |
1677 !color_list->GetInteger(0, &color) || | 1695 !color_list->GetInteger(0, &color) || |
1678 !color_list->GetInteger(1, &color) || | 1696 !color_list->GetInteger(1, &color) || |
1679 !color_list->GetInteger(2, &color)) { | 1697 !color_list->GetInteger(2, &color)) { |
1680 *error = errors::kInvalidThemeColors; | 1698 *error = ASCIIToUTF16(errors::kInvalidThemeColors); |
1681 return false; | 1699 return false; |
1682 } | 1700 } |
1683 } | 1701 } |
1684 theme_colors_.reset(colors_value->DeepCopy()); | 1702 theme_colors_.reset(colors_value->DeepCopy()); |
1685 } | 1703 } |
1686 | 1704 |
1687 DictionaryValue* tints_value = NULL; | 1705 DictionaryValue* tints_value = NULL; |
1688 if (theme_value->GetDictionary(keys::kThemeTints, &tints_value)) { | 1706 if (theme_value->GetDictionary(keys::kThemeTints, &tints_value)) { |
1689 // Validate that the tints are all reals. | 1707 // Validate that the tints are all reals. |
1690 for (DictionaryValue::key_iterator iter = tints_value->begin_keys(); | 1708 for (DictionaryValue::key_iterator iter = tints_value->begin_keys(); |
1691 iter != tints_value->end_keys(); ++iter) { | 1709 iter != tints_value->end_keys(); ++iter) { |
1692 ListValue* tint_list = NULL; | 1710 ListValue* tint_list = NULL; |
1693 double v = 0.0; | 1711 double v = 0.0; |
1694 if (!tints_value->GetListWithoutPathExpansion(*iter, &tint_list) || | 1712 if (!tints_value->GetListWithoutPathExpansion(*iter, &tint_list) || |
1695 tint_list->GetSize() != 3 || | 1713 tint_list->GetSize() != 3 || |
1696 !tint_list->GetDouble(0, &v) || | 1714 !tint_list->GetDouble(0, &v) || |
1697 !tint_list->GetDouble(1, &v) || | 1715 !tint_list->GetDouble(1, &v) || |
1698 !tint_list->GetDouble(2, &v)) { | 1716 !tint_list->GetDouble(2, &v)) { |
1699 *error = errors::kInvalidThemeTints; | 1717 *error = ASCIIToUTF16(errors::kInvalidThemeTints); |
1700 return false; | 1718 return false; |
1701 } | 1719 } |
1702 } | 1720 } |
1703 theme_tints_.reset(tints_value->DeepCopy()); | 1721 theme_tints_.reset(tints_value->DeepCopy()); |
1704 } | 1722 } |
1705 | 1723 |
1706 DictionaryValue* display_properties_value = NULL; | 1724 DictionaryValue* display_properties_value = NULL; |
1707 if (theme_value->GetDictionary(keys::kThemeDisplayProperties, | 1725 if (theme_value->GetDictionary(keys::kThemeDisplayProperties, |
1708 &display_properties_value)) { | 1726 &display_properties_value)) { |
1709 theme_display_properties_.reset( | 1727 theme_display_properties_.reset( |
1710 display_properties_value->DeepCopy()); | 1728 display_properties_value->DeepCopy()); |
1711 } | 1729 } |
1712 | 1730 |
1713 return true; | 1731 return true; |
1714 } | 1732 } |
1715 | 1733 |
1716 // Initialize plugins (optional). | 1734 // Initialize plugins (optional). |
1717 if (manifest->HasKey(keys::kPlugins)) { | 1735 if (manifest->HasKey(keys::kPlugins)) { |
1718 ListValue* list_value = NULL; | 1736 ListValue* list_value = NULL; |
1719 if (!manifest->GetList(keys::kPlugins, &list_value)) { | 1737 if (!manifest->GetList(keys::kPlugins, &list_value)) { |
1720 *error = errors::kInvalidPlugins; | 1738 *error = ASCIIToUTF16(errors::kInvalidPlugins); |
1721 return false; | 1739 return false; |
1722 } | 1740 } |
1723 | 1741 |
1724 for (size_t i = 0; i < list_value->GetSize(); ++i) { | 1742 for (size_t i = 0; i < list_value->GetSize(); ++i) { |
1725 DictionaryValue* plugin_value = NULL; | 1743 DictionaryValue* plugin_value = NULL; |
1726 std::string path_str; | 1744 std::string path_str; |
1727 bool is_public = false; | 1745 bool is_public = false; |
1728 | 1746 |
1729 if (!list_value->GetDictionary(i, &plugin_value)) { | 1747 if (!list_value->GetDictionary(i, &plugin_value)) { |
1730 *error = errors::kInvalidPlugins; | 1748 *error = ASCIIToUTF16(errors::kInvalidPlugins); |
1731 return false; | 1749 return false; |
1732 } | 1750 } |
1733 | 1751 |
1734 // Get plugins[i].path. | 1752 // Get plugins[i].path. |
1735 if (!plugin_value->GetString(keys::kPluginsPath, &path_str)) { | 1753 if (!plugin_value->GetString(keys::kPluginsPath, &path_str)) { |
1736 *error = ExtensionErrorUtils::FormatErrorMessage( | 1754 *error = ExtensionErrorUtils::FormatErrorMessageUTF16( |
1737 errors::kInvalidPluginsPath, base::IntToString(i)); | 1755 errors::kInvalidPluginsPath, base::IntToString(i)); |
1738 return false; | 1756 return false; |
1739 } | 1757 } |
1740 | 1758 |
1741 // Get plugins[i].content (optional). | 1759 // Get plugins[i].content (optional). |
1742 if (plugin_value->HasKey(keys::kPluginsPublic)) { | 1760 if (plugin_value->HasKey(keys::kPluginsPublic)) { |
1743 if (!plugin_value->GetBoolean(keys::kPluginsPublic, &is_public)) { | 1761 if (!plugin_value->GetBoolean(keys::kPluginsPublic, &is_public)) { |
1744 *error = ExtensionErrorUtils::FormatErrorMessage( | 1762 *error = ExtensionErrorUtils::FormatErrorMessageUTF16( |
1745 errors::kInvalidPluginsPublic, base::IntToString(i)); | 1763 errors::kInvalidPluginsPublic, base::IntToString(i)); |
1746 return false; | 1764 return false; |
1747 } | 1765 } |
1748 } | 1766 } |
1749 | 1767 |
1750 // We don't allow extension plugins to run on Chrome OS. We still | 1768 // We don't allow extension plugins to run on Chrome OS. We still |
1751 // parse the manifest entry so that error messages are consistently | 1769 // parse the manifest entry so that error messages are consistently |
1752 // displayed across platforms. | 1770 // displayed across platforms. |
1753 #if !defined(OS_CHROMEOS) | 1771 #if !defined(OS_CHROMEOS) |
1754 plugins_.push_back(PluginInfo()); | 1772 plugins_.push_back(PluginInfo()); |
1755 plugins_.back().path = path().Append(FilePath::FromUTF8Unsafe(path_str)); | 1773 plugins_.back().path = path().Append(FilePath::FromUTF8Unsafe(path_str)); |
1756 plugins_.back().is_public = is_public; | 1774 plugins_.back().is_public = is_public; |
1757 #endif | 1775 #endif |
1758 } | 1776 } |
1759 } | 1777 } |
1760 | 1778 |
1761 if (manifest->HasKey(keys::kNaClModules)) { | 1779 if (manifest->HasKey(keys::kNaClModules)) { |
1762 ListValue* list_value = NULL; | 1780 ListValue* list_value = NULL; |
1763 if (!manifest->GetList(keys::kNaClModules, &list_value)) { | 1781 if (!manifest->GetList(keys::kNaClModules, &list_value)) { |
1764 *error = errors::kInvalidNaClModules; | 1782 *error = ASCIIToUTF16(errors::kInvalidNaClModules); |
1765 return false; | 1783 return false; |
1766 } | 1784 } |
1767 | 1785 |
1768 for (size_t i = 0; i < list_value->GetSize(); ++i) { | 1786 for (size_t i = 0; i < list_value->GetSize(); ++i) { |
1769 DictionaryValue* module_value = NULL; | 1787 DictionaryValue* module_value = NULL; |
1770 std::string path_str; | 1788 std::string path_str; |
1771 std::string mime_type; | 1789 std::string mime_type; |
1772 | 1790 |
1773 if (!list_value->GetDictionary(i, &module_value)) { | 1791 if (!list_value->GetDictionary(i, &module_value)) { |
1774 *error = errors::kInvalidNaClModules; | 1792 *error = ASCIIToUTF16(errors::kInvalidNaClModules); |
1775 return false; | 1793 return false; |
1776 } | 1794 } |
1777 | 1795 |
1778 // Get nacl_modules[i].path. | 1796 // Get nacl_modules[i].path. |
1779 if (!module_value->GetString(keys::kNaClModulesPath, &path_str)) { | 1797 if (!module_value->GetString(keys::kNaClModulesPath, &path_str)) { |
1780 *error = ExtensionErrorUtils::FormatErrorMessage( | 1798 *error = ExtensionErrorUtils::FormatErrorMessageUTF16( |
1781 errors::kInvalidNaClModulesPath, base::IntToString(i)); | 1799 errors::kInvalidNaClModulesPath, base::IntToString(i)); |
1782 return false; | 1800 return false; |
1783 } | 1801 } |
1784 | 1802 |
1785 // Get nacl_modules[i].mime_type. | 1803 // Get nacl_modules[i].mime_type. |
1786 if (!module_value->GetString(keys::kNaClModulesMIMEType, &mime_type)) { | 1804 if (!module_value->GetString(keys::kNaClModulesMIMEType, &mime_type)) { |
1787 *error = ExtensionErrorUtils::FormatErrorMessage( | 1805 *error = ExtensionErrorUtils::FormatErrorMessageUTF16( |
1788 errors::kInvalidNaClModulesMIMEType, base::IntToString(i)); | 1806 errors::kInvalidNaClModulesMIMEType, base::IntToString(i)); |
1789 return false; | 1807 return false; |
1790 } | 1808 } |
1791 | 1809 |
1792 nacl_modules_.push_back(NaClModuleInfo()); | 1810 nacl_modules_.push_back(NaClModuleInfo()); |
1793 nacl_modules_.back().url = GetResourceURL(path_str); | 1811 nacl_modules_.back().url = GetResourceURL(path_str); |
1794 nacl_modules_.back().mime_type = mime_type; | 1812 nacl_modules_.back().mime_type = mime_type; |
1795 } | 1813 } |
1796 } | 1814 } |
1797 | 1815 |
1798 // Initialize content scripts (optional). | 1816 // Initialize content scripts (optional). |
1799 if (manifest->HasKey(keys::kContentScripts)) { | 1817 if (manifest->HasKey(keys::kContentScripts)) { |
1800 ListValue* list_value; | 1818 ListValue* list_value; |
1801 if (!manifest->GetList(keys::kContentScripts, &list_value)) { | 1819 if (!manifest->GetList(keys::kContentScripts, &list_value)) { |
1802 *error = errors::kInvalidContentScriptsList; | 1820 *error = ASCIIToUTF16(errors::kInvalidContentScriptsList); |
1803 return false; | 1821 return false; |
1804 } | 1822 } |
1805 | 1823 |
1806 for (size_t i = 0; i < list_value->GetSize(); ++i) { | 1824 for (size_t i = 0; i < list_value->GetSize(); ++i) { |
1807 DictionaryValue* content_script = NULL; | 1825 DictionaryValue* content_script = NULL; |
1808 if (!list_value->GetDictionary(i, &content_script)) { | 1826 if (!list_value->GetDictionary(i, &content_script)) { |
1809 *error = ExtensionErrorUtils::FormatErrorMessage( | 1827 *error = ExtensionErrorUtils::FormatErrorMessageUTF16( |
1810 errors::kInvalidContentScript, base::IntToString(i)); | 1828 errors::kInvalidContentScript, base::IntToString(i)); |
1811 return false; | 1829 return false; |
1812 } | 1830 } |
1813 | 1831 |
1814 UserScript script; | 1832 UserScript script; |
1815 if (!LoadUserScriptHelper(content_script, i, flags, error, &script)) | 1833 if (!LoadUserScriptHelper(content_script, i, flags, error, &script)) |
1816 return false; // Failed to parse script context definition. | 1834 return false; // Failed to parse script context definition. |
1817 script.set_extension_id(id()); | 1835 script.set_extension_id(id()); |
1818 if (converted_from_user_script_) { | 1836 if (converted_from_user_script_) { |
1819 script.set_emulate_greasemonkey(true); | 1837 script.set_emulate_greasemonkey(true); |
1820 script.set_match_all_frames(true); // Greasemonkey matches all frames. | 1838 script.set_match_all_frames(true); // Greasemonkey matches all frames. |
1821 } | 1839 } |
1822 content_scripts_.push_back(script); | 1840 content_scripts_.push_back(script); |
1823 } | 1841 } |
1824 } | 1842 } |
1825 | 1843 |
1826 // Initialize page action (optional). | 1844 // Initialize page action (optional). |
1827 DictionaryValue* page_action_value = NULL; | 1845 DictionaryValue* page_action_value = NULL; |
1828 | 1846 |
1829 if (manifest->HasKey(keys::kPageActions)) { | 1847 if (manifest->HasKey(keys::kPageActions)) { |
1830 ListValue* list_value = NULL; | 1848 ListValue* list_value = NULL; |
1831 if (!manifest->GetList(keys::kPageActions, &list_value)) { | 1849 if (!manifest->GetList(keys::kPageActions, &list_value)) { |
1832 *error = errors::kInvalidPageActionsList; | 1850 *error = ASCIIToUTF16(errors::kInvalidPageActionsList); |
1833 return false; | 1851 return false; |
1834 } | 1852 } |
1835 | 1853 |
1836 size_t list_value_length = list_value->GetSize(); | 1854 size_t list_value_length = list_value->GetSize(); |
1837 | 1855 |
1838 if (list_value_length == 0u) { | 1856 if (list_value_length == 0u) { |
1839 // A list with zero items is allowed, and is equivalent to not having | 1857 // A list with zero items is allowed, and is equivalent to not having |
1840 // a page_actions key in the manifest. Don't set |page_action_value|. | 1858 // a page_actions key in the manifest. Don't set |page_action_value|. |
1841 } else if (list_value_length == 1u) { | 1859 } else if (list_value_length == 1u) { |
1842 if (!list_value->GetDictionary(0, &page_action_value)) { | 1860 if (!list_value->GetDictionary(0, &page_action_value)) { |
1843 *error = errors::kInvalidPageAction; | 1861 *error = ASCIIToUTF16(errors::kInvalidPageAction); |
1844 return false; | 1862 return false; |
1845 } | 1863 } |
1846 } else { // list_value_length > 1u. | 1864 } else { // list_value_length > 1u. |
1847 *error = errors::kInvalidPageActionsListSize; | 1865 *error = ASCIIToUTF16(errors::kInvalidPageActionsListSize); |
1848 return false; | 1866 return false; |
1849 } | 1867 } |
1850 } else if (manifest->HasKey(keys::kPageAction)) { | 1868 } else if (manifest->HasKey(keys::kPageAction)) { |
1851 if (!manifest->GetDictionary(keys::kPageAction, &page_action_value)) { | 1869 if (!manifest->GetDictionary(keys::kPageAction, &page_action_value)) { |
1852 *error = errors::kInvalidPageAction; | 1870 *error = ASCIIToUTF16(errors::kInvalidPageAction); |
1853 return false; | 1871 return false; |
1854 } | 1872 } |
1855 } | 1873 } |
1856 | 1874 |
1857 // If page_action_value is not NULL, then there was a valid page action. | 1875 // If page_action_value is not NULL, then there was a valid page action. |
1858 if (page_action_value) { | 1876 if (page_action_value) { |
1859 page_action_.reset( | 1877 page_action_.reset( |
1860 LoadExtensionActionHelper(page_action_value, error)); | 1878 LoadExtensionActionHelper(page_action_value, error)); |
1861 if (!page_action_.get()) | 1879 if (!page_action_.get()) |
1862 return false; // Failed to parse page action definition. | 1880 return false; // Failed to parse page action definition. |
1863 } | 1881 } |
1864 | 1882 |
1865 // Initialize browser action (optional). | 1883 // Initialize browser action (optional). |
1866 if (manifest->HasKey(keys::kBrowserAction)) { | 1884 if (manifest->HasKey(keys::kBrowserAction)) { |
1867 DictionaryValue* browser_action_value = NULL; | 1885 DictionaryValue* browser_action_value = NULL; |
1868 if (!manifest->GetDictionary(keys::kBrowserAction, &browser_action_value)) { | 1886 if (!manifest->GetDictionary(keys::kBrowserAction, &browser_action_value)) { |
1869 *error = errors::kInvalidBrowserAction; | 1887 *error = ASCIIToUTF16(errors::kInvalidBrowserAction); |
1870 return false; | 1888 return false; |
1871 } | 1889 } |
1872 | 1890 |
1873 browser_action_.reset( | 1891 browser_action_.reset( |
1874 LoadExtensionActionHelper(browser_action_value, error)); | 1892 LoadExtensionActionHelper(browser_action_value, error)); |
1875 if (!browser_action_.get()) | 1893 if (!browser_action_.get()) |
1876 return false; // Failed to parse browser action definition. | 1894 return false; // Failed to parse browser action definition. |
1877 } | 1895 } |
1878 | 1896 |
1879 // Initialize file browser actions (optional). | 1897 // Initialize file browser actions (optional). |
1880 if (manifest->HasKey(keys::kFileBrowserHandlers)) { | 1898 if (manifest->HasKey(keys::kFileBrowserHandlers)) { |
1881 ListValue* file_browser_handlers_value = NULL; | 1899 ListValue* file_browser_handlers_value = NULL; |
1882 if (!manifest->GetList(keys::kFileBrowserHandlers, | 1900 if (!manifest->GetList(keys::kFileBrowserHandlers, |
1883 &file_browser_handlers_value)) { | 1901 &file_browser_handlers_value)) { |
1884 *error = errors::kInvalidFileBrowserHandler; | 1902 *error = ASCIIToUTF16(errors::kInvalidFileBrowserHandler); |
1885 return false; | 1903 return false; |
1886 } | 1904 } |
1887 | 1905 |
1888 file_browser_handlers_.reset( | 1906 file_browser_handlers_.reset( |
1889 LoadFileBrowserHandlers(file_browser_handlers_value, error)); | 1907 LoadFileBrowserHandlers(file_browser_handlers_value, error)); |
1890 if (!file_browser_handlers_.get()) | 1908 if (!file_browser_handlers_.get()) |
1891 return false; // Failed to parse file browser actions definition. | 1909 return false; // Failed to parse file browser actions definition. |
1892 } | 1910 } |
1893 | 1911 |
1894 // App isolation. | 1912 // App isolation. |
1895 if (api_permissions.count(ExtensionAPIPermission::kExperimental)) { | 1913 if (api_permissions.count(ExtensionAPIPermission::kExperimental)) { |
1896 if (is_app() && !LoadAppIsolation(manifest_.get(), error)) | 1914 if (is_app() && !LoadAppIsolation(manifest_.get(), error)) |
1897 return false; | 1915 return false; |
1898 } | 1916 } |
1899 | 1917 |
1900 // Initialize options page url (optional). | 1918 // Initialize options page url (optional). |
1901 if (manifest->HasKey(keys::kOptionsPage)) { | 1919 if (manifest->HasKey(keys::kOptionsPage)) { |
1902 std::string options_str; | 1920 std::string options_str; |
1903 if (!manifest->GetString(keys::kOptionsPage, &options_str)) { | 1921 if (!manifest->GetString(keys::kOptionsPage, &options_str)) { |
1904 *error = errors::kInvalidOptionsPage; | 1922 *error = ASCIIToUTF16(errors::kInvalidOptionsPage); |
1905 return false; | 1923 return false; |
1906 } | 1924 } |
1907 | 1925 |
1908 if (is_hosted_app()) { | 1926 if (is_hosted_app()) { |
1909 // hosted apps require an absolute URL. | 1927 // hosted apps require an absolute URL. |
1910 GURL options_url(options_str); | 1928 GURL options_url(options_str); |
1911 if (!options_url.is_valid() || | 1929 if (!options_url.is_valid() || |
1912 !(options_url.SchemeIs("http") || options_url.SchemeIs("https"))) { | 1930 !(options_url.SchemeIs("http") || options_url.SchemeIs("https"))) { |
1913 *error = errors::kInvalidOptionsPageInHostedApp; | 1931 *error = ASCIIToUTF16(errors::kInvalidOptionsPageInHostedApp); |
1914 return false; | 1932 return false; |
1915 } | 1933 } |
1916 options_url_ = options_url; | 1934 options_url_ = options_url; |
1917 } else { | 1935 } else { |
1918 GURL absolute(options_str); | 1936 GURL absolute(options_str); |
1919 if (absolute.is_valid()) { | 1937 if (absolute.is_valid()) { |
1920 *error = errors::kInvalidOptionsPageExpectUrlInPackage; | 1938 *error = ASCIIToUTF16(errors::kInvalidOptionsPageExpectUrlInPackage); |
1921 return false; | 1939 return false; |
1922 } | 1940 } |
1923 options_url_ = GetResourceURL(options_str); | 1941 options_url_ = GetResourceURL(options_str); |
1924 if (!options_url_.is_valid()) { | 1942 if (!options_url_.is_valid()) { |
1925 *error = errors::kInvalidOptionsPage; | 1943 *error = ASCIIToUTF16(errors::kInvalidOptionsPage); |
1926 return false; | 1944 return false; |
1927 } | 1945 } |
1928 } | 1946 } |
1929 } | 1947 } |
1930 | 1948 |
1931 // Initialize background url (optional). | 1949 // Initialize background url (optional). |
1932 if (manifest->HasKey(keys::kBackground)) { | 1950 if (manifest->HasKey(keys::kBackground)) { |
1933 std::string background_str; | 1951 std::string background_str; |
1934 if (!manifest->GetString(keys::kBackground, &background_str)) { | 1952 if (!manifest->GetString(keys::kBackground, &background_str)) { |
1935 *error = errors::kInvalidBackground; | 1953 *error = ASCIIToUTF16(errors::kInvalidBackground); |
1936 return false; | 1954 return false; |
1937 } | 1955 } |
1938 | 1956 |
1939 if (is_hosted_app()) { | 1957 if (is_hosted_app()) { |
1940 // Make sure "background" permission is set. | 1958 // Make sure "background" permission is set. |
1941 if (!api_permissions.count(ExtensionAPIPermission::kBackground)) { | 1959 if (!api_permissions.count(ExtensionAPIPermission::kBackground)) { |
1942 *error = errors::kBackgroundPermissionNeeded; | 1960 *error = ASCIIToUTF16(errors::kBackgroundPermissionNeeded); |
1943 return false; | 1961 return false; |
1944 } | 1962 } |
1945 // Hosted apps require an absolute URL. | 1963 // Hosted apps require an absolute URL. |
1946 GURL bg_page(background_str); | 1964 GURL bg_page(background_str); |
1947 if (!bg_page.is_valid()) { | 1965 if (!bg_page.is_valid()) { |
1948 *error = errors::kInvalidBackgroundInHostedApp; | 1966 *error = ASCIIToUTF16(errors::kInvalidBackgroundInHostedApp); |
1949 return false; | 1967 return false; |
1950 } | 1968 } |
1951 | 1969 |
1952 if (!(bg_page.SchemeIs("https") || | 1970 if (!(bg_page.SchemeIs("https") || |
1953 (CommandLine::ForCurrentProcess()->HasSwitch( | 1971 (CommandLine::ForCurrentProcess()->HasSwitch( |
1954 switches::kAllowHTTPBackgroundPage) && | 1972 switches::kAllowHTTPBackgroundPage) && |
1955 bg_page.SchemeIs("http")))) { | 1973 bg_page.SchemeIs("http")))) { |
1956 *error = errors::kInvalidBackgroundInHostedApp; | 1974 *error = ASCIIToUTF16(errors::kInvalidBackgroundInHostedApp); |
1957 return false; | 1975 return false; |
1958 } | 1976 } |
1959 background_url_ = bg_page; | 1977 background_url_ = bg_page; |
1960 } else { | 1978 } else { |
1961 background_url_ = GetResourceURL(background_str); | 1979 background_url_ = GetResourceURL(background_str); |
1962 } | 1980 } |
1963 } | 1981 } |
1964 | 1982 |
1965 if (manifest->HasKey(keys::kDefaultLocale)) { | 1983 if (manifest->HasKey(keys::kDefaultLocale)) { |
1966 if (!manifest->GetString(keys::kDefaultLocale, &default_locale_) || | 1984 if (!manifest->GetString(keys::kDefaultLocale, &default_locale_) || |
1967 !l10n_util::IsValidLocaleSyntax(default_locale_)) { | 1985 !l10n_util::IsValidLocaleSyntax(default_locale_)) { |
1968 *error = errors::kInvalidDefaultLocale; | 1986 *error = ASCIIToUTF16(errors::kInvalidDefaultLocale); |
1969 return false; | 1987 return false; |
1970 } | 1988 } |
1971 } | 1989 } |
1972 | 1990 |
1973 // Chrome URL overrides (optional) | 1991 // Chrome URL overrides (optional) |
1974 if (manifest->HasKey(keys::kChromeURLOverrides)) { | 1992 if (manifest->HasKey(keys::kChromeURLOverrides)) { |
1975 DictionaryValue* overrides = NULL; | 1993 DictionaryValue* overrides = NULL; |
1976 if (!manifest->GetDictionary(keys::kChromeURLOverrides, &overrides)) { | 1994 if (!manifest->GetDictionary(keys::kChromeURLOverrides, &overrides)) { |
1977 *error = errors::kInvalidChromeURLOverrides; | 1995 *error = ASCIIToUTF16(errors::kInvalidChromeURLOverrides); |
1978 return false; | 1996 return false; |
1979 } | 1997 } |
1980 | 1998 |
1981 // Validate that the overrides are all strings | 1999 // Validate that the overrides are all strings |
1982 for (DictionaryValue::key_iterator iter = overrides->begin_keys(); | 2000 for (DictionaryValue::key_iterator iter = overrides->begin_keys(); |
1983 iter != overrides->end_keys(); ++iter) { | 2001 iter != overrides->end_keys(); ++iter) { |
1984 std::string page = *iter; | 2002 std::string page = *iter; |
1985 std::string val; | 2003 std::string val; |
1986 // Restrict override pages to a list of supported URLs. | 2004 // Restrict override pages to a list of supported URLs. |
1987 if ((page != chrome::kChromeUINewTabHost && | 2005 if ((page != chrome::kChromeUINewTabHost && |
1988 #if defined(USE_VIRTUAL_KEYBOARD) | 2006 #if defined(USE_VIRTUAL_KEYBOARD) |
1989 page != chrome::kChromeUIKeyboardHost && | 2007 page != chrome::kChromeUIKeyboardHost && |
1990 #endif | 2008 #endif |
1991 #if defined(OS_CHROMEOS) | 2009 #if defined(OS_CHROMEOS) |
1992 page != chrome::kChromeUIActivationMessageHost && | 2010 page != chrome::kChromeUIActivationMessageHost && |
1993 #endif | 2011 #endif |
1994 page != chrome::kChromeUIBookmarksHost && | 2012 page != chrome::kChromeUIBookmarksHost && |
1995 page != chrome::kChromeUIHistoryHost | 2013 page != chrome::kChromeUIHistoryHost |
1996 #if defined(FILE_MANAGER_EXTENSION) | 2014 #if defined(FILE_MANAGER_EXTENSION) |
1997 && | 2015 && |
1998 !(location() == COMPONENT && | 2016 !(location() == COMPONENT && |
1999 page == chrome::kChromeUIFileManagerHost) | 2017 page == chrome::kChromeUIFileManagerHost) |
2000 #endif | 2018 #endif |
2001 ) || | 2019 ) || |
2002 !overrides->GetStringWithoutPathExpansion(*iter, &val)) { | 2020 !overrides->GetStringWithoutPathExpansion(*iter, &val)) { |
2003 *error = errors::kInvalidChromeURLOverrides; | 2021 *error = ASCIIToUTF16(errors::kInvalidChromeURLOverrides); |
2004 return false; | 2022 return false; |
2005 } | 2023 } |
2006 // Replace the entry with a fully qualified chrome-extension:// URL. | 2024 // Replace the entry with a fully qualified chrome-extension:// URL. |
2007 chrome_url_overrides_[page] = GetResourceURL(val); | 2025 chrome_url_overrides_[page] = GetResourceURL(val); |
2008 } | 2026 } |
2009 | 2027 |
2010 // An extension may override at most one page. | 2028 // An extension may override at most one page. |
2011 if (overrides->size() > 1) { | 2029 if (overrides->size() > 1) { |
2012 *error = errors::kMultipleOverrides; | 2030 *error = ASCIIToUTF16(errors::kMultipleOverrides); |
2013 return false; | 2031 return false; |
2014 } | 2032 } |
2015 } | 2033 } |
2016 | 2034 |
2017 if (api_permissions.count(ExtensionAPIPermission::kExperimental) && | 2035 if (api_permissions.count(ExtensionAPIPermission::kExperimental) && |
2018 manifest->HasKey(keys::kInputComponents)) { | 2036 manifest->HasKey(keys::kInputComponents)) { |
2019 ListValue* list_value = NULL; | 2037 ListValue* list_value = NULL; |
2020 if (!manifest->GetList(keys::kInputComponents, &list_value)) { | 2038 if (!manifest->GetList(keys::kInputComponents, &list_value)) { |
2021 *error = errors::kInvalidInputComponents; | 2039 *error = ASCIIToUTF16(errors::kInvalidInputComponents); |
2022 return false; | 2040 return false; |
2023 } | 2041 } |
2024 | 2042 |
2025 for (size_t i = 0; i < list_value->GetSize(); ++i) { | 2043 for (size_t i = 0; i < list_value->GetSize(); ++i) { |
2026 DictionaryValue* module_value = NULL; | 2044 DictionaryValue* module_value = NULL; |
2027 std::string name_str; | 2045 std::string name_str; |
2028 InputComponentType type; | 2046 InputComponentType type; |
2029 std::string id_str; | 2047 std::string id_str; |
2030 std::string description_str; | 2048 std::string description_str; |
2031 std::string language_str; | 2049 std::string language_str; |
2032 std::set<std::string> layouts; | 2050 std::set<std::string> layouts; |
2033 std::string shortcut_keycode_str; | 2051 std::string shortcut_keycode_str; |
2034 bool shortcut_alt = false; | 2052 bool shortcut_alt = false; |
2035 bool shortcut_ctrl = false; | 2053 bool shortcut_ctrl = false; |
2036 bool shortcut_shift = false; | 2054 bool shortcut_shift = false; |
2037 | 2055 |
2038 if (!list_value->GetDictionary(i, &module_value)) { | 2056 if (!list_value->GetDictionary(i, &module_value)) { |
2039 *error = errors::kInvalidInputComponents; | 2057 *error = ASCIIToUTF16(errors::kInvalidInputComponents); |
2040 return false; | 2058 return false; |
2041 } | 2059 } |
2042 | 2060 |
2043 // Get input_components[i].name. | 2061 // Get input_components[i].name. |
2044 if (!module_value->GetString(keys::kName, &name_str)) { | 2062 if (!module_value->GetString(keys::kName, &name_str)) { |
2045 *error = ExtensionErrorUtils::FormatErrorMessage( | 2063 *error = ExtensionErrorUtils::FormatErrorMessageUTF16( |
2046 errors::kInvalidInputComponentName, base::IntToString(i)); | 2064 errors::kInvalidInputComponentName, base::IntToString(i)); |
2047 return false; | 2065 return false; |
2048 } | 2066 } |
2049 | 2067 |
2050 // Get input_components[i].type. | 2068 // Get input_components[i].type. |
2051 std::string type_str; | 2069 std::string type_str; |
2052 if (module_value->GetString(keys::kType, &type_str)) { | 2070 if (module_value->GetString(keys::kType, &type_str)) { |
2053 if (type_str == "ime") { | 2071 if (type_str == "ime") { |
2054 type = INPUT_COMPONENT_TYPE_IME; | 2072 type = INPUT_COMPONENT_TYPE_IME; |
2055 } else if (type_str == "virtual_keyboard") { | 2073 } else if (type_str == "virtual_keyboard") { |
2056 type = INPUT_COMPONENT_TYPE_VIRTUAL_KEYBOARD; | 2074 type = INPUT_COMPONENT_TYPE_VIRTUAL_KEYBOARD; |
2057 } else { | 2075 } else { |
2058 *error = ExtensionErrorUtils::FormatErrorMessage( | 2076 *error = ExtensionErrorUtils::FormatErrorMessageUTF16( |
2059 errors::kInvalidInputComponentType, base::IntToString(i)); | 2077 errors::kInvalidInputComponentType, base::IntToString(i)); |
2060 return false; | 2078 return false; |
2061 } | 2079 } |
2062 } else { | 2080 } else { |
2063 *error = ExtensionErrorUtils::FormatErrorMessage( | 2081 *error = ExtensionErrorUtils::FormatErrorMessageUTF16( |
2064 errors::kInvalidInputComponentType, base::IntToString(i)); | 2082 errors::kInvalidInputComponentType, base::IntToString(i)); |
2065 return false; | 2083 return false; |
2066 } | 2084 } |
2067 | 2085 |
2068 // Get input_components[i].id. | 2086 // Get input_components[i].id. |
2069 if (!module_value->GetString(keys::kId, &id_str)) { | 2087 if (!module_value->GetString(keys::kId, &id_str)) { |
2070 id_str = ""; | 2088 id_str = ""; |
2071 } | 2089 } |
2072 | 2090 |
2073 // Get input_components[i].description. | 2091 // Get input_components[i].description. |
2074 if (!module_value->GetString(keys::kDescription, &description_str)) { | 2092 if (!module_value->GetString(keys::kDescription, &description_str)) { |
2075 *error = ExtensionErrorUtils::FormatErrorMessage( | 2093 *error = ExtensionErrorUtils::FormatErrorMessageUTF16( |
2076 errors::kInvalidInputComponentDescription, base::IntToString(i)); | 2094 errors::kInvalidInputComponentDescription, base::IntToString(i)); |
2077 return false; | 2095 return false; |
2078 } | 2096 } |
2079 | 2097 |
2080 // Get input_components[i].language. | 2098 // Get input_components[i].language. |
2081 if (!module_value->GetString(keys::kLanguage, &language_str)) { | 2099 if (!module_value->GetString(keys::kLanguage, &language_str)) { |
2082 language_str = ""; | 2100 language_str = ""; |
2083 } | 2101 } |
2084 | 2102 |
2085 // Get input_components[i].layouts. | 2103 // Get input_components[i].layouts. |
2086 ListValue* layouts_value = NULL; | 2104 ListValue* layouts_value = NULL; |
2087 if (!module_value->GetList(keys::kLayouts, &layouts_value)) { | 2105 if (!module_value->GetList(keys::kLayouts, &layouts_value)) { |
2088 *error = errors::kInvalidInputComponentLayouts; | 2106 *error = ASCIIToUTF16(errors::kInvalidInputComponentLayouts); |
2089 return false; | 2107 return false; |
2090 } | 2108 } |
2091 | 2109 |
2092 for (size_t j = 0; j < layouts_value->GetSize(); ++j) { | 2110 for (size_t j = 0; j < layouts_value->GetSize(); ++j) { |
2093 std::string layout_name_str; | 2111 std::string layout_name_str; |
2094 if (!layouts_value->GetString(j, &layout_name_str)) { | 2112 if (!layouts_value->GetString(j, &layout_name_str)) { |
2095 *error = ExtensionErrorUtils::FormatErrorMessage( | 2113 *error = ExtensionErrorUtils::FormatErrorMessageUTF16( |
2096 errors::kInvalidInputComponentLayoutName, base::IntToString(i), | 2114 errors::kInvalidInputComponentLayoutName, base::IntToString(i), |
2097 base::IntToString(j)); | 2115 base::IntToString(j)); |
2098 return false; | 2116 return false; |
2099 } | 2117 } |
2100 layouts.insert(layout_name_str); | 2118 layouts.insert(layout_name_str); |
2101 } | 2119 } |
2102 | 2120 |
2103 if (module_value->HasKey(keys::kShortcutKey)) { | 2121 if (module_value->HasKey(keys::kShortcutKey)) { |
2104 DictionaryValue* shortcut_value = NULL; | 2122 DictionaryValue* shortcut_value = NULL; |
2105 if (!module_value->GetDictionary(keys::kShortcutKey, &shortcut_value)) { | 2123 if (!module_value->GetDictionary(keys::kShortcutKey, &shortcut_value)) { |
2106 *error = ExtensionErrorUtils::FormatErrorMessage( | 2124 *error = ExtensionErrorUtils::FormatErrorMessageUTF16( |
2107 errors::kInvalidInputComponentShortcutKey, base::IntToString(i)); | 2125 errors::kInvalidInputComponentShortcutKey, base::IntToString(i)); |
2108 return false; | 2126 return false; |
2109 } | 2127 } |
2110 | 2128 |
2111 // Get input_components[i].shortcut_keycode. | 2129 // Get input_components[i].shortcut_keycode. |
2112 if (!shortcut_value->GetString(keys::kKeycode, &shortcut_keycode_str)) { | 2130 if (!shortcut_value->GetString(keys::kKeycode, &shortcut_keycode_str)) { |
2113 *error = ExtensionErrorUtils::FormatErrorMessage( | 2131 *error = ExtensionErrorUtils::FormatErrorMessageUTF16( |
2114 errors::kInvalidInputComponentShortcutKeycode, | 2132 errors::kInvalidInputComponentShortcutKeycode, |
2115 base::IntToString(i)); | 2133 base::IntToString(i)); |
2116 return false; | 2134 return false; |
2117 } | 2135 } |
2118 | 2136 |
2119 // Get input_components[i].shortcut_alt. | 2137 // Get input_components[i].shortcut_alt. |
2120 if (!shortcut_value->GetBoolean(keys::kAltKey, &shortcut_alt)) { | 2138 if (!shortcut_value->GetBoolean(keys::kAltKey, &shortcut_alt)) { |
2121 shortcut_alt = false; | 2139 shortcut_alt = false; |
2122 } | 2140 } |
2123 | 2141 |
(...skipping 18 matching lines...) Expand all Loading... |
2142 input_components_.back().shortcut_keycode = shortcut_keycode_str; | 2160 input_components_.back().shortcut_keycode = shortcut_keycode_str; |
2143 input_components_.back().shortcut_alt = shortcut_alt; | 2161 input_components_.back().shortcut_alt = shortcut_alt; |
2144 input_components_.back().shortcut_ctrl = shortcut_ctrl; | 2162 input_components_.back().shortcut_ctrl = shortcut_ctrl; |
2145 input_components_.back().shortcut_shift = shortcut_shift; | 2163 input_components_.back().shortcut_shift = shortcut_shift; |
2146 } | 2164 } |
2147 } | 2165 } |
2148 | 2166 |
2149 if (manifest->HasKey(keys::kOmnibox)) { | 2167 if (manifest->HasKey(keys::kOmnibox)) { |
2150 if (!manifest->GetString(keys::kOmniboxKeyword, &omnibox_keyword_) || | 2168 if (!manifest->GetString(keys::kOmniboxKeyword, &omnibox_keyword_) || |
2151 omnibox_keyword_.empty()) { | 2169 omnibox_keyword_.empty()) { |
2152 *error = errors::kInvalidOmniboxKeyword; | 2170 *error = ASCIIToUTF16(errors::kInvalidOmniboxKeyword); |
2153 return false; | 2171 return false; |
2154 } | 2172 } |
2155 } | 2173 } |
2156 | 2174 |
2157 if (manifest->HasKey(keys::kContentSecurityPolicy)) { | 2175 if (manifest->HasKey(keys::kContentSecurityPolicy)) { |
2158 std::string content_security_policy; | 2176 std::string content_security_policy; |
2159 if (!manifest->GetString(keys::kContentSecurityPolicy, | 2177 if (!manifest->GetString(keys::kContentSecurityPolicy, |
2160 &content_security_policy)) { | 2178 &content_security_policy)) { |
2161 *error = errors::kInvalidContentSecurityPolicy; | 2179 *error = ASCIIToUTF16(errors::kInvalidContentSecurityPolicy); |
2162 return false; | 2180 return false; |
2163 } | 2181 } |
2164 if (!ContentSecurityPolicyIsLegal(content_security_policy)) { | 2182 if (!ContentSecurityPolicyIsLegal(content_security_policy)) { |
2165 *error = errors::kInvalidContentSecurityPolicy; | 2183 *error = ASCIIToUTF16(errors::kInvalidContentSecurityPolicy); |
2166 return false; | 2184 return false; |
2167 } | 2185 } |
2168 if (manifest_version_ >= 2 && | 2186 if (manifest_version_ >= 2 && |
2169 !ContentSecurityPolicyIsSecure(content_security_policy)) { | 2187 !ContentSecurityPolicyIsSecure(content_security_policy)) { |
2170 *error = errors::kInvalidContentSecurityPolicy; | 2188 *error = ASCIIToUTF16(errors::kInvalidContentSecurityPolicy); |
2171 return false; | 2189 return false; |
2172 } | 2190 } |
2173 | 2191 |
2174 content_security_policy_ = content_security_policy; | 2192 content_security_policy_ = content_security_policy; |
2175 } else if (manifest_version_ >= 2) { | 2193 } else if (manifest_version_ >= 2) { |
2176 // Manifest version 2 introduced a default Content-Security-Policy. | 2194 // Manifest version 2 introduced a default Content-Security-Policy. |
2177 // TODO(abarth): Should we continue to let extensions override the | 2195 // TODO(abarth): Should we continue to let extensions override the |
2178 // default Content-Security-Policy? | 2196 // default Content-Security-Policy? |
2179 content_security_policy_ = kDefaultContentSecurityPolicy; | 2197 content_security_policy_ = kDefaultContentSecurityPolicy; |
2180 CHECK(ContentSecurityPolicyIsSecure(content_security_policy_)); | 2198 CHECK(ContentSecurityPolicyIsSecure(content_security_policy_)); |
2181 } | 2199 } |
2182 | 2200 |
2183 // Initialize devtools page url (optional). | 2201 // Initialize devtools page url (optional). |
2184 if (manifest->HasKey(keys::kDevToolsPage)) { | 2202 if (manifest->HasKey(keys::kDevToolsPage)) { |
2185 std::string devtools_str; | 2203 std::string devtools_str; |
2186 if (!manifest->GetString(keys::kDevToolsPage, &devtools_str)) { | 2204 if (!manifest->GetString(keys::kDevToolsPage, &devtools_str)) { |
2187 *error = errors::kInvalidDevToolsPage; | 2205 *error = ASCIIToUTF16(errors::kInvalidDevToolsPage); |
2188 return false; | 2206 return false; |
2189 } | 2207 } |
2190 if (!api_permissions.count(ExtensionAPIPermission::kExperimental)) { | 2208 if (!api_permissions.count(ExtensionAPIPermission::kExperimental)) { |
2191 *error = errors::kDevToolsExperimental; | 2209 *error = ASCIIToUTF16(errors::kDevToolsExperimental); |
2192 return false; | 2210 return false; |
2193 } | 2211 } |
2194 devtools_url_ = GetResourceURL(devtools_str); | 2212 devtools_url_ = GetResourceURL(devtools_str); |
2195 } | 2213 } |
2196 | 2214 |
2197 // Initialize sidebar action (optional). | 2215 // Initialize sidebar action (optional). |
2198 if (manifest->HasKey(keys::kSidebar)) { | 2216 if (manifest->HasKey(keys::kSidebar)) { |
2199 DictionaryValue* sidebar_value = NULL; | 2217 DictionaryValue* sidebar_value = NULL; |
2200 if (!manifest->GetDictionary(keys::kSidebar, &sidebar_value)) { | 2218 if (!manifest->GetDictionary(keys::kSidebar, &sidebar_value)) { |
2201 *error = errors::kInvalidSidebar; | 2219 *error = ASCIIToUTF16(errors::kInvalidSidebar); |
2202 return false; | 2220 return false; |
2203 } | 2221 } |
2204 if (!api_permissions.count(ExtensionAPIPermission::kExperimental)) { | 2222 if (!api_permissions.count(ExtensionAPIPermission::kExperimental)) { |
2205 *error = errors::kSidebarExperimental; | 2223 *error = ASCIIToUTF16(errors::kSidebarExperimental); |
2206 return false; | 2224 return false; |
2207 } | 2225 } |
2208 sidebar_defaults_.reset(LoadExtensionSidebarDefaults(sidebar_value, error)); | 2226 sidebar_defaults_.reset(LoadExtensionSidebarDefaults(sidebar_value, error)); |
2209 if (!sidebar_defaults_.get()) | 2227 if (!sidebar_defaults_.get()) |
2210 return false; // Failed to parse sidebar definition. | 2228 return false; // Failed to parse sidebar definition. |
2211 } | 2229 } |
2212 | 2230 |
2213 // Initialize text-to-speech voices (optional). | 2231 // Initialize text-to-speech voices (optional). |
2214 if (manifest->HasKey(keys::kTtsEngine)) { | 2232 if (manifest->HasKey(keys::kTtsEngine)) { |
2215 DictionaryValue* tts_dict = NULL; | 2233 DictionaryValue* tts_dict = NULL; |
2216 if (!manifest->GetDictionary(keys::kTtsEngine, &tts_dict)) { | 2234 if (!manifest->GetDictionary(keys::kTtsEngine, &tts_dict)) { |
2217 *error = errors::kInvalidTts; | 2235 *error = ASCIIToUTF16(errors::kInvalidTts); |
2218 return false; | 2236 return false; |
2219 } | 2237 } |
2220 | 2238 |
2221 if (tts_dict->HasKey(keys::kTtsVoices)) { | 2239 if (tts_dict->HasKey(keys::kTtsVoices)) { |
2222 ListValue* tts_voices = NULL; | 2240 ListValue* tts_voices = NULL; |
2223 if (!tts_dict->GetList(keys::kTtsVoices, &tts_voices)) { | 2241 if (!tts_dict->GetList(keys::kTtsVoices, &tts_voices)) { |
2224 *error = errors::kInvalidTtsVoices; | 2242 *error = ASCIIToUTF16(errors::kInvalidTtsVoices); |
2225 return false; | 2243 return false; |
2226 } | 2244 } |
2227 | 2245 |
2228 for (size_t i = 0; i < tts_voices->GetSize(); i++) { | 2246 for (size_t i = 0; i < tts_voices->GetSize(); i++) { |
2229 DictionaryValue* one_tts_voice = NULL; | 2247 DictionaryValue* one_tts_voice = NULL; |
2230 if (!tts_voices->GetDictionary(i, &one_tts_voice)) { | 2248 if (!tts_voices->GetDictionary(i, &one_tts_voice)) { |
2231 *error = errors::kInvalidTtsVoices; | 2249 *error = ASCIIToUTF16(errors::kInvalidTtsVoices); |
2232 return false; | 2250 return false; |
2233 } | 2251 } |
2234 | 2252 |
2235 TtsVoice voice_data; | 2253 TtsVoice voice_data; |
2236 if (one_tts_voice->HasKey(keys::kTtsVoicesVoiceName)) { | 2254 if (one_tts_voice->HasKey(keys::kTtsVoicesVoiceName)) { |
2237 if (!one_tts_voice->GetString( | 2255 if (!one_tts_voice->GetString( |
2238 keys::kTtsVoicesVoiceName, &voice_data.voice_name)) { | 2256 keys::kTtsVoicesVoiceName, &voice_data.voice_name)) { |
2239 *error = errors::kInvalidTtsVoicesVoiceName; | 2257 *error = ASCIIToUTF16(errors::kInvalidTtsVoicesVoiceName); |
2240 return false; | 2258 return false; |
2241 } | 2259 } |
2242 } | 2260 } |
2243 if (one_tts_voice->HasKey(keys::kTtsVoicesLang)) { | 2261 if (one_tts_voice->HasKey(keys::kTtsVoicesLang)) { |
2244 if (!one_tts_voice->GetString( | 2262 if (!one_tts_voice->GetString( |
2245 keys::kTtsVoicesLang, &voice_data.lang) || | 2263 keys::kTtsVoicesLang, &voice_data.lang) || |
2246 !l10n_util::IsValidLocaleSyntax(voice_data.lang)) { | 2264 !l10n_util::IsValidLocaleSyntax(voice_data.lang)) { |
2247 *error = errors::kInvalidTtsVoicesLang; | 2265 *error = ASCIIToUTF16(errors::kInvalidTtsVoicesLang); |
2248 return false; | 2266 return false; |
2249 } | 2267 } |
2250 } | 2268 } |
2251 if (one_tts_voice->HasKey(keys::kTtsVoicesGender)) { | 2269 if (one_tts_voice->HasKey(keys::kTtsVoicesGender)) { |
2252 if (!one_tts_voice->GetString( | 2270 if (!one_tts_voice->GetString( |
2253 keys::kTtsVoicesGender, &voice_data.gender) || | 2271 keys::kTtsVoicesGender, &voice_data.gender) || |
2254 (voice_data.gender != keys::kTtsGenderMale && | 2272 (voice_data.gender != keys::kTtsGenderMale && |
2255 voice_data.gender != keys::kTtsGenderFemale)) { | 2273 voice_data.gender != keys::kTtsGenderFemale)) { |
2256 *error = errors::kInvalidTtsVoicesGender; | 2274 *error = ASCIIToUTF16(errors::kInvalidTtsVoicesGender); |
2257 return false; | 2275 return false; |
2258 } | 2276 } |
2259 } | 2277 } |
2260 if (one_tts_voice->HasKey(keys::kTtsVoicesEventTypes)) { | 2278 if (one_tts_voice->HasKey(keys::kTtsVoicesEventTypes)) { |
2261 ListValue* event_types_list; | 2279 ListValue* event_types_list; |
2262 if (!one_tts_voice->GetList( | 2280 if (!one_tts_voice->GetList( |
2263 keys::kTtsVoicesEventTypes, &event_types_list)) { | 2281 keys::kTtsVoicesEventTypes, &event_types_list)) { |
2264 *error = errors::kInvalidTtsVoicesEventTypes; | 2282 *error = ASCIIToUTF16(errors::kInvalidTtsVoicesEventTypes); |
2265 return false; | 2283 return false; |
2266 } | 2284 } |
2267 for (size_t i = 0; i < event_types_list->GetSize(); i++) { | 2285 for (size_t i = 0; i < event_types_list->GetSize(); i++) { |
2268 std::string event_type; | 2286 std::string event_type; |
2269 if (!event_types_list->GetString(i, &event_type)) { | 2287 if (!event_types_list->GetString(i, &event_type)) { |
2270 *error = errors::kInvalidTtsVoicesEventTypes; | 2288 *error = ASCIIToUTF16(errors::kInvalidTtsVoicesEventTypes); |
2271 return false; | 2289 return false; |
2272 } | 2290 } |
2273 if (event_type != keys::kTtsVoicesEventTypeEnd && | 2291 if (event_type != keys::kTtsVoicesEventTypeEnd && |
2274 event_type != keys::kTtsVoicesEventTypeError && | 2292 event_type != keys::kTtsVoicesEventTypeError && |
2275 event_type != keys::kTtsVoicesEventTypeMarker && | 2293 event_type != keys::kTtsVoicesEventTypeMarker && |
2276 event_type != keys::kTtsVoicesEventTypeSentence && | 2294 event_type != keys::kTtsVoicesEventTypeSentence && |
2277 event_type != keys::kTtsVoicesEventTypeStart && | 2295 event_type != keys::kTtsVoicesEventTypeStart && |
2278 event_type != keys::kTtsVoicesEventTypeWord) { | 2296 event_type != keys::kTtsVoicesEventTypeWord) { |
2279 *error = errors::kInvalidTtsVoicesEventTypes; | 2297 *error = ASCIIToUTF16(errors::kInvalidTtsVoicesEventTypes); |
2280 return false; | 2298 return false; |
2281 } | 2299 } |
2282 if (voice_data.event_types.find(event_type) != | 2300 if (voice_data.event_types.find(event_type) != |
2283 voice_data.event_types.end()) { | 2301 voice_data.event_types.end()) { |
2284 *error = errors::kInvalidTtsVoicesEventTypes; | 2302 *error = ASCIIToUTF16(errors::kInvalidTtsVoicesEventTypes); |
2285 return false; | 2303 return false; |
2286 } | 2304 } |
2287 voice_data.event_types.insert(event_type); | 2305 voice_data.event_types.insert(event_type); |
2288 } | 2306 } |
2289 } | 2307 } |
2290 | 2308 |
2291 tts_voices_.push_back(voice_data); | 2309 tts_voices_.push_back(voice_data); |
2292 } | 2310 } |
2293 } | 2311 } |
2294 } | 2312 } |
2295 | 2313 |
2296 // Initialize web intents (optional). | 2314 // Initialize web intents (optional). |
2297 if (!LoadWebIntentServices(manifest, error)) | 2315 if (!LoadWebIntentServices(manifest, error)) |
2298 return false; | 2316 return false; |
2299 | 2317 |
2300 // Initialize incognito behavior. Apps default to split mode, extensions | 2318 // Initialize incognito behavior. Apps default to split mode, extensions |
2301 // default to spanning. | 2319 // default to spanning. |
2302 incognito_split_mode_ = is_app(); | 2320 incognito_split_mode_ = is_app(); |
2303 if (manifest->HasKey(keys::kIncognito)) { | 2321 if (manifest->HasKey(keys::kIncognito)) { |
2304 std::string value; | 2322 std::string value; |
2305 if (!manifest->GetString(keys::kIncognito, &value)) { | 2323 if (!manifest->GetString(keys::kIncognito, &value)) { |
2306 *error = errors::kInvalidIncognitoBehavior; | 2324 *error = ASCIIToUTF16(errors::kInvalidIncognitoBehavior); |
2307 return false; | 2325 return false; |
2308 } | 2326 } |
2309 if (value == values::kIncognitoSpanning) { | 2327 if (value == values::kIncognitoSpanning) { |
2310 incognito_split_mode_ = false; | 2328 incognito_split_mode_ = false; |
2311 } else if (value == values::kIncognitoSplit) { | 2329 } else if (value == values::kIncognitoSplit) { |
2312 incognito_split_mode_ = true; | 2330 incognito_split_mode_ = true; |
2313 } else { | 2331 } else { |
2314 *error = errors::kInvalidIncognitoBehavior; | 2332 *error = ASCIIToUTF16(errors::kInvalidIncognitoBehavior); |
2315 return false; | 2333 return false; |
2316 } | 2334 } |
2317 } | 2335 } |
2318 | 2336 |
2319 // Initialize offline-enabled status. Defaults to false. | 2337 // Initialize offline-enabled status. Defaults to false. |
2320 if (manifest->HasKey(keys::kOfflineEnabled)) { | 2338 if (manifest->HasKey(keys::kOfflineEnabled)) { |
2321 if (!manifest->GetBoolean(keys::kOfflineEnabled, &offline_enabled_)) { | 2339 if (!manifest->GetBoolean(keys::kOfflineEnabled, &offline_enabled_)) { |
2322 *error = errors::kInvalidOfflineEnabled; | 2340 *error = ASCIIToUTF16(errors::kInvalidOfflineEnabled); |
2323 return false; | 2341 return false; |
2324 } | 2342 } |
2325 } | 2343 } |
2326 | 2344 |
2327 // Initialize requirements (optional). Not actually persisted (they're only | 2345 // Initialize requirements (optional). Not actually persisted (they're only |
2328 // used by the store), but still validated. | 2346 // used by the store), but still validated. |
2329 if (manifest->HasKey(keys::kRequirements)) { | 2347 if (manifest->HasKey(keys::kRequirements)) { |
2330 DictionaryValue* requirements_value = NULL; | 2348 DictionaryValue* requirements_value = NULL; |
2331 if (!manifest->GetDictionary(keys::kRequirements, &requirements_value)) { | 2349 if (!manifest->GetDictionary(keys::kRequirements, &requirements_value)) { |
2332 *error = errors::kInvalidRequirements; | 2350 *error = ASCIIToUTF16(errors::kInvalidRequirements); |
2333 return false; | 2351 return false; |
2334 } | 2352 } |
2335 | 2353 |
2336 for (DictionaryValue::key_iterator it = requirements_value->begin_keys(); | 2354 for (DictionaryValue::key_iterator it = requirements_value->begin_keys(); |
2337 it != requirements_value->end_keys(); ++it) { | 2355 it != requirements_value->end_keys(); ++it) { |
2338 DictionaryValue* requirement_value; | 2356 DictionaryValue* requirement_value; |
2339 if (!requirements_value->GetDictionaryWithoutPathExpansion( | 2357 if (!requirements_value->GetDictionaryWithoutPathExpansion( |
2340 *it, &requirement_value)) { | 2358 *it, &requirement_value)) { |
2341 *error = ExtensionErrorUtils::FormatErrorMessage( | 2359 *error = ExtensionErrorUtils::FormatErrorMessageUTF16( |
2342 errors::kInvalidRequirement, *it); | 2360 errors::kInvalidRequirement, *it); |
2343 return false; | 2361 return false; |
2344 } | 2362 } |
2345 } | 2363 } |
2346 } | 2364 } |
2347 | 2365 |
2348 if (HasMultipleUISurfaces()) { | 2366 if (HasMultipleUISurfaces()) { |
2349 *error = errors::kOneUISurfaceOnly; | 2367 *error = ASCIIToUTF16(errors::kOneUISurfaceOnly); |
2350 return false; | 2368 return false; |
2351 } | 2369 } |
2352 | 2370 |
2353 runtime_data_.SetActivePermissions(new ExtensionPermissionSet( | 2371 runtime_data_.SetActivePermissions(new ExtensionPermissionSet( |
2354 this, api_permissions, host_permissions)); | 2372 this, api_permissions, host_permissions)); |
2355 required_permission_set_ = new ExtensionPermissionSet( | 2373 required_permission_set_ = new ExtensionPermissionSet( |
2356 this, api_permissions, host_permissions); | 2374 this, api_permissions, host_permissions); |
2357 optional_permission_set_ = new ExtensionPermissionSet( | 2375 optional_permission_set_ = new ExtensionPermissionSet( |
2358 optional_api_permissions, optional_host_permissions, URLPatternSet()); | 2376 optional_api_permissions, optional_host_permissions, URLPatternSet()); |
2359 | 2377 |
(...skipping 148 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2508 std::string path = icons().Get(size, match_type); | 2526 std::string path = icons().Get(size, match_type); |
2509 if (path.empty()) | 2527 if (path.empty()) |
2510 return GURL(); | 2528 return GURL(); |
2511 else | 2529 else |
2512 return GetResourceURL(path); | 2530 return GetResourceURL(path); |
2513 } | 2531 } |
2514 | 2532 |
2515 bool Extension::ParsePermissions(const extensions::Manifest* source, | 2533 bool Extension::ParsePermissions(const extensions::Manifest* source, |
2516 const char* key, | 2534 const char* key, |
2517 int flags, | 2535 int flags, |
2518 std::string* error, | 2536 string16* error, |
2519 ExtensionAPIPermissionSet* api_permissions, | 2537 ExtensionAPIPermissionSet* api_permissions, |
2520 URLPatternSet* host_permissions) { | 2538 URLPatternSet* host_permissions) { |
2521 if (source->HasKey(key)) { | 2539 if (source->HasKey(key)) { |
2522 // When strict error checks are enabled, make URL pattern parsing strict. | 2540 // When strict error checks are enabled, make URL pattern parsing strict. |
2523 URLPattern::ParseOption parse_option = | 2541 URLPattern::ParseOption parse_option = |
2524 (flags & STRICT_ERROR_CHECKS ? URLPattern::ERROR_ON_PORTS | 2542 (flags & STRICT_ERROR_CHECKS ? URLPattern::ERROR_ON_PORTS |
2525 : URLPattern::IGNORE_PORTS); | 2543 : URLPattern::IGNORE_PORTS); |
2526 ListValue* permissions = NULL; | 2544 ListValue* permissions = NULL; |
2527 if (!source->GetList(key, &permissions)) { | 2545 if (!source->GetList(key, &permissions)) { |
2528 *error = ExtensionErrorUtils::FormatErrorMessage( | 2546 *error = ExtensionErrorUtils::FormatErrorMessageUTF16( |
2529 errors::kInvalidPermissions, ""); | 2547 errors::kInvalidPermissions, ""); |
2530 return false; | 2548 return false; |
2531 } | 2549 } |
2532 | 2550 |
2533 for (size_t i = 0; i < permissions->GetSize(); ++i) { | 2551 for (size_t i = 0; i < permissions->GetSize(); ++i) { |
2534 std::string permission_str; | 2552 std::string permission_str; |
2535 if (!permissions->GetString(i, &permission_str)) { | 2553 if (!permissions->GetString(i, &permission_str)) { |
2536 *error = ExtensionErrorUtils::FormatErrorMessage( | 2554 *error = ExtensionErrorUtils::FormatErrorMessageUTF16( |
2537 errors::kInvalidPermission, base::IntToString(i)); | 2555 errors::kInvalidPermission, base::IntToString(i)); |
2538 return false; | 2556 return false; |
2539 } | 2557 } |
2540 | 2558 |
2541 ExtensionAPIPermission* permission = | 2559 ExtensionAPIPermission* permission = |
2542 ExtensionPermissionsInfo::GetInstance()->GetByName(permission_str); | 2560 ExtensionPermissionsInfo::GetInstance()->GetByName(permission_str); |
2543 | 2561 |
2544 if (permission != NULL) { | 2562 if (permission != NULL) { |
2545 if (CanSpecifyAPIPermission(permission, error)) | 2563 if (CanSpecifyAPIPermission(permission, error)) |
2546 api_permissions->insert(permission->id()); | 2564 api_permissions->insert(permission->id()); |
2547 if (!error->empty()) | 2565 if (!error->empty()) |
2548 return false; | 2566 return false; |
2549 continue; | 2567 continue; |
2550 } | 2568 } |
2551 | 2569 |
2552 // Check if it's a host pattern permission. | 2570 // Check if it's a host pattern permission. |
2553 const int kAllowedSchemes = CanExecuteScriptEverywhere() ? | 2571 const int kAllowedSchemes = CanExecuteScriptEverywhere() ? |
2554 URLPattern::SCHEME_ALL : kValidHostPermissionSchemes; | 2572 URLPattern::SCHEME_ALL : kValidHostPermissionSchemes; |
2555 | 2573 |
2556 URLPattern pattern = URLPattern(parse_option, kAllowedSchemes); | 2574 URLPattern pattern = URLPattern(parse_option, kAllowedSchemes); |
2557 URLPattern::ParseResult parse_result = pattern.Parse(permission_str); | 2575 URLPattern::ParseResult parse_result = pattern.Parse(permission_str); |
2558 if (parse_result == URLPattern::PARSE_SUCCESS) { | 2576 if (parse_result == URLPattern::PARSE_SUCCESS) { |
2559 if (!CanSpecifyHostPermission(pattern, *api_permissions)) { | 2577 if (!CanSpecifyHostPermission(pattern, *api_permissions)) { |
2560 *error = ExtensionErrorUtils::FormatErrorMessage( | 2578 *error = ExtensionErrorUtils::FormatErrorMessageUTF16( |
2561 errors::kInvalidPermissionScheme, base::IntToString(i)); | 2579 errors::kInvalidPermissionScheme, base::IntToString(i)); |
2562 return false; | 2580 return false; |
2563 } | 2581 } |
2564 | 2582 |
2565 // The path component is not used for host permissions, so we force it | 2583 // The path component is not used for host permissions, so we force it |
2566 // to match all paths. | 2584 // to match all paths. |
2567 pattern.SetPath("/*"); | 2585 pattern.SetPath("/*"); |
2568 | 2586 |
2569 if (pattern.MatchesScheme(chrome::kFileScheme) && | 2587 if (pattern.MatchesScheme(chrome::kFileScheme) && |
2570 !CanExecuteScriptEverywhere()) { | 2588 !CanExecuteScriptEverywhere()) { |
(...skipping 183 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2754 } | 2772 } |
2755 | 2773 |
2756 bool Extension::ImplicitlyDelaysNetworkStartup() const { | 2774 bool Extension::ImplicitlyDelaysNetworkStartup() const { |
2757 // Network requests should be deferred until any extensions that might want | 2775 // Network requests should be deferred until any extensions that might want |
2758 // to observe and modify them are loaded. | 2776 // to observe and modify them are loaded. |
2759 return HasAPIPermission(ExtensionAPIPermission::kWebRequestBlocking); | 2777 return HasAPIPermission(ExtensionAPIPermission::kWebRequestBlocking); |
2760 } | 2778 } |
2761 | 2779 |
2762 bool Extension::CanSpecifyAPIPermission( | 2780 bool Extension::CanSpecifyAPIPermission( |
2763 const ExtensionAPIPermission* permission, | 2781 const ExtensionAPIPermission* permission, |
2764 std::string* error) const { | 2782 string16* error) const { |
2765 if (permission->is_component_only()) { | 2783 if (permission->is_component_only()) { |
2766 if (!CanSpecifyComponentOnlyPermission()) { | 2784 if (!CanSpecifyComponentOnlyPermission()) { |
2767 *error = ExtensionErrorUtils::FormatErrorMessage( | 2785 *error = ExtensionErrorUtils::FormatErrorMessageUTF16( |
2768 errors::kPermissionNotAllowed, permission->name()); | 2786 errors::kPermissionNotAllowed, permission->name()); |
2769 return false; | 2787 return false; |
2770 } | 2788 } |
2771 } | 2789 } |
2772 | 2790 |
2773 if (permission->id() == ExtensionAPIPermission::kExperimental) { | 2791 if (permission->id() == ExtensionAPIPermission::kExperimental) { |
2774 if (!CanSpecifyExperimentalPermission()) { | 2792 if (!CanSpecifyExperimentalPermission()) { |
2775 *error = errors::kExperimentalFlagRequired; | 2793 *error = ASCIIToUTF16(errors::kExperimentalFlagRequired); |
2776 return false; | 2794 return false; |
2777 } | 2795 } |
2778 } | 2796 } |
2779 | 2797 |
2780 if (location_ == Extension::COMPONENT) | 2798 if (location_ == Extension::COMPONENT) |
2781 return true; | 2799 return true; |
2782 | 2800 |
2783 bool supports_type = false; | 2801 bool supports_type = false; |
2784 switch (GetType()) { | 2802 switch (GetType()) { |
2785 case TYPE_USER_SCRIPT: // Pass through. | 2803 case TYPE_USER_SCRIPT: // Pass through. |
(...skipping 17 matching lines...) Expand all Loading... |
2803 if (!supports_type) { | 2821 if (!supports_type) { |
2804 // We special case hosted apps because some old versions of Chrome did not | 2822 // We special case hosted apps because some old versions of Chrome did not |
2805 // return errors here and we ended up with extensions in the store | 2823 // return errors here and we ended up with extensions in the store |
2806 // containing bad data: crbug.com/101993. | 2824 // containing bad data: crbug.com/101993. |
2807 // | 2825 // |
2808 // TODO(aa): Consider just being a lot looser when loading and installing | 2826 // TODO(aa): Consider just being a lot looser when loading and installing |
2809 // extensions. We can be strict when packing and in development mode. Then | 2827 // extensions. We can be strict when packing and in development mode. Then |
2810 // we won't have to maintain all these tricky backward compat issues: | 2828 // we won't have to maintain all these tricky backward compat issues: |
2811 // crbug.com/102328. | 2829 // crbug.com/102328. |
2812 if (!is_hosted_app() || creation_flags_ & STRICT_ERROR_CHECKS) { | 2830 if (!is_hosted_app() || creation_flags_ & STRICT_ERROR_CHECKS) { |
2813 *error = ExtensionErrorUtils::FormatErrorMessage( | 2831 *error = ExtensionErrorUtils::FormatErrorMessageUTF16( |
2814 errors::kPermissionNotAllowed, permission->name()); | 2832 errors::kPermissionNotAllowed, permission->name()); |
2815 } | 2833 } |
2816 return false; | 2834 return false; |
2817 } | 2835 } |
2818 | 2836 |
2819 return true; | 2837 return true; |
2820 } | 2838 } |
2821 | 2839 |
2822 bool Extension::CanSpecifyComponentOnlyPermission() const { | 2840 bool Extension::CanSpecifyComponentOnlyPermission() const { |
2823 // Only COMPONENT extensions can use private APIs. | 2841 // Only COMPONENT extensions can use private APIs. |
(...skipping 156 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2980 already_disabled(false), | 2998 already_disabled(false), |
2981 extension(extension) {} | 2999 extension(extension) {} |
2982 | 3000 |
2983 UpdatedExtensionPermissionsInfo::UpdatedExtensionPermissionsInfo( | 3001 UpdatedExtensionPermissionsInfo::UpdatedExtensionPermissionsInfo( |
2984 const Extension* extension, | 3002 const Extension* extension, |
2985 const ExtensionPermissionSet* permissions, | 3003 const ExtensionPermissionSet* permissions, |
2986 Reason reason) | 3004 Reason reason) |
2987 : reason(reason), | 3005 : reason(reason), |
2988 extension(extension), | 3006 extension(extension), |
2989 permissions(permissions) {} | 3007 permissions(permissions) {} |
OLD | NEW |