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