OLD | NEW |
---|---|
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 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/browser/extensions/api/developer_private/developer_private_api. h" | 5 #include "chrome/browser/extensions/api/developer_private/developer_private_api. h" |
6 | 6 |
7 #include "base/base64.h" | 7 #include "base/base64.h" |
8 #include "base/file_util.h" | 8 #include "base/file_util.h" |
9 #include "base/string_number_conversions.h" | 9 #include "base/string_number_conversions.h" |
10 #include "base/utf_string_conversions.h" | 10 #include "base/utf_string_conversions.h" |
(...skipping 92 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
103 bool DeveloperPrivateAutoUpdateFunction::RunImpl() { | 103 bool DeveloperPrivateAutoUpdateFunction::RunImpl() { |
104 extensions::ExtensionUpdater* updater = GetExtensionUpdater(profile()); | 104 extensions::ExtensionUpdater* updater = GetExtensionUpdater(profile()); |
105 if (updater) | 105 if (updater) |
106 updater->CheckNow(extensions::ExtensionUpdater::CheckParams()); | 106 updater->CheckNow(extensions::ExtensionUpdater::CheckParams()); |
107 SetResult(Value::CreateBooleanValue(true)); | 107 SetResult(Value::CreateBooleanValue(true)); |
108 return true; | 108 return true; |
109 } | 109 } |
110 | 110 |
111 DeveloperPrivateAutoUpdateFunction::~DeveloperPrivateAutoUpdateFunction() {} | 111 DeveloperPrivateAutoUpdateFunction::~DeveloperPrivateAutoUpdateFunction() {} |
112 | 112 |
113 scoped_ptr<developer::ItemInfo> | 113 scoped_ptr<developer::ItemInfo> DeveloperPrivateGetItemsInfoFunction:: |
114 DeveloperPrivateGetItemsInfoFunction::CreateItemInfo( | 114 CreateItemInfo( |
115 const Extension& item, | 115 const Extension& item, |
116 ExtensionSystem* system, | 116 ExtensionSystem* system, |
117 bool item_is_enabled) { | 117 bool item_is_enabled) { |
118 scoped_ptr<developer::ItemInfo> info(new developer::ItemInfo()); | 118 scoped_ptr<developer::ItemInfo> info(new developer::ItemInfo()); |
119 | 119 |
120 ExtensionService* service = profile()->GetExtensionService(); | 120 ExtensionService* service = profile()->GetExtensionService(); |
121 info->id = item.id(); | 121 info->id = item.id(); |
122 info->name = item.name(); | 122 info->name = item.name(); |
123 info->enabled = service->IsExtensionEnabled(info->id); | 123 info->enabled = service->IsExtensionEnabled(info->id); |
124 info->offline_enabled = item.offline_enabled(); | 124 info->offline_enabled = item.offline_enabled(); |
125 info->version = item.VersionString(); | 125 info->version = item.VersionString(); |
126 info->description = item.description(); | 126 info->description = item.description(); |
127 | 127 |
(...skipping 113 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
241 content::WebContents* web_contents = (*it)->web_contents(); | 241 content::WebContents* web_contents = (*it)->web_contents(); |
242 RenderViewHost* host = web_contents->GetRenderViewHost(); | 242 RenderViewHost* host = web_contents->GetRenderViewHost(); |
243 content::RenderProcessHost* process = host->GetProcess(); | 243 content::RenderProcessHost* process = host->GetProcess(); |
244 result->push_back( | 244 result->push_back( |
245 constructInspectView(web_contents->GetURL(), | 245 constructInspectView(web_contents->GetURL(), |
246 process->GetID(), | 246 process->GetID(), |
247 host->GetRoutingID(), | 247 host->GetRoutingID(), |
248 process->GetBrowserContext()->IsOffTheRecord())); | 248 process->GetBrowserContext()->IsOffTheRecord())); |
249 } | 249 } |
250 } | 250 } |
251 | 251 linked_ptr<developer::ItemInspectView> DeveloperPrivateGetItemsInfoFunction:: |
252 linked_ptr<developer::ItemInspectView> | 252 constructInspectView( |
253 DeveloperPrivateGetItemsInfoFunction::constructInspectView( | 253 const GURL& url, |
254 const GURL& url, | 254 int render_process_id, |
255 int render_process_id, | 255 int render_view_id, |
256 int render_view_id, | 256 bool incognito) { |
257 bool incognito) { | |
258 linked_ptr<developer::ItemInspectView> view(new developer::ItemInspectView()); | 257 linked_ptr<developer::ItemInspectView> view(new developer::ItemInspectView()); |
259 | 258 |
260 if (url.scheme() == extensions::kExtensionScheme) { | 259 if (url.scheme() == extensions::kExtensionScheme) { |
261 // No leading slash. | 260 // No leading slash. |
262 view->path = url.path().substr(1); | 261 view->path = url.path().substr(1); |
263 } else { | 262 } else { |
264 // For live pages, use the full URL. | 263 // For live pages, use the full URL. |
265 view->path = url.spec(); | 264 view->path = url.spec(); |
266 } | 265 } |
267 | 266 |
(...skipping 188 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
456 std::string extension_id, | 455 std::string extension_id, |
457 std::vector<std::string> requirements_errors) { | 456 std::vector<std::string> requirements_errors) { |
458 if (requirements_errors.empty()) { | 457 if (requirements_errors.empty()) { |
459 ExtensionService* service = profile()->GetExtensionService(); | 458 ExtensionService* service = profile()->GetExtensionService(); |
460 service->EnableExtension(extension_id); | 459 service->EnableExtension(extension_id); |
461 } else { | 460 } else { |
462 ExtensionErrorReporter::GetInstance()->ReportError( | 461 ExtensionErrorReporter::GetInstance()->ReportError( |
463 UTF8ToUTF16(JoinString(requirements_errors, ' ')), | 462 UTF8ToUTF16(JoinString(requirements_errors, ' ')), |
464 true /* be noisy */); | 463 true /* be noisy */); |
465 } | 464 } |
466 | |
467 Release(); | 465 Release(); |
468 } | 466 } |
469 | 467 |
470 DeveloperPrivateEnableFunction::~DeveloperPrivateEnableFunction() {} | 468 DeveloperPrivateEnableFunction::~DeveloperPrivateEnableFunction() {} |
471 | 469 |
472 bool DeveloperPrivateInspectFunction::RunImpl() { | 470 bool DeveloperPrivateInspectFunction::RunImpl() { |
473 scoped_ptr<developer::Inspect::Params> params( | 471 scoped_ptr<developer::Inspect::Params> params( |
474 developer::Inspect::Params::Create(*args_)); | 472 developer::Inspect::Params::Create(*args_)); |
475 EXTENSION_FUNCTION_VALIDATE(params.get() != NULL); | 473 EXTENSION_FUNCTION_VALIDATE(params.get() != NULL); |
476 const developer::InspectOptions& options = params->options; | 474 const developer::InspectOptions& options = params->options; |
(...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
508 DevToolsWindow::OpenDevToolsWindow(host); | 506 DevToolsWindow::OpenDevToolsWindow(host); |
509 return true; | 507 return true; |
510 } | 508 } |
511 | 509 |
512 DeveloperPrivateInspectFunction::~DeveloperPrivateInspectFunction() {} | 510 DeveloperPrivateInspectFunction::~DeveloperPrivateInspectFunction() {} |
513 | 511 |
514 bool DeveloperPrivateLoadUnpackedFunction::RunImpl() { | 512 bool DeveloperPrivateLoadUnpackedFunction::RunImpl() { |
515 string16 select_title = | 513 string16 select_title = |
516 l10n_util::GetStringUTF16(IDS_EXTENSION_LOAD_FROM_DIRECTORY); | 514 l10n_util::GetStringUTF16(IDS_EXTENSION_LOAD_FROM_DIRECTORY); |
517 | 515 |
518 const ui::SelectFileDialog::Type kSelectType = | |
519 ui::SelectFileDialog::SELECT_FOLDER; | |
520 const FilePath& last_unpacked_directory = | |
521 DeveloperPrivateAPI::Get(profile())->getLastUnpackedDirectory(); | |
522 SetResult(Value::CreateBooleanValue(true)); | 516 SetResult(Value::CreateBooleanValue(true)); |
523 // Balanced in FileSelected / FileSelectionCanceled. | 517 // Balanced in FileSelected / FileSelectionCanceled. |
524 AddRef(); | 518 AddRef(); |
525 bool result = ShowPicker(kSelectType, last_unpacked_directory, select_title); | 519 int result = |
520 ShowPicker( | |
asargent_no_longer_on_chrome
2013/02/09 00:38:45
style nit: collapse the first 2 lines here:
int r
Gaurav
2013/02/11 20:01:55
Done.
| |
521 ui::SelectFileDialog::SELECT_FOLDER, | |
522 DeveloperPrivateAPI::Get(profile())->GetLastUnpackedDirectory(), | |
523 select_title, | |
524 ui::SelectFileDialog::FileTypeInfo(), | |
525 0); | |
526 return result; | 526 return result; |
527 } | 527 } |
528 | 528 |
529 void DeveloperPrivateLoadUnpackedFunction::FileSelected(const FilePath& path) { | |
530 | |
asargent_no_longer_on_chrome
2013/02/09 00:38:45
style nit: no empty space at beginning of function
Gaurav
2013/02/11 20:01:55
Done.
| |
531 ExtensionService* service = profile()->GetExtensionService(); | |
532 extensions::UnpackedInstaller::Create(service)->Load(path); | |
533 DeveloperPrivateAPI::Get(profile())->SetLastUnpackedDirectory(path); | |
534 SendResponse(true); | |
535 Release(); | |
536 } | |
537 | |
538 void DeveloperPrivateLoadUnpackedFunction::FileSelectionCanceled() { | |
539 SendResponse(false); | |
540 Release(); | |
541 } | |
542 | |
529 bool DeveloperPrivateChooseEntryFunction::ShowPicker( | 543 bool DeveloperPrivateChooseEntryFunction::ShowPicker( |
530 ui::SelectFileDialog::Type picker_type, | 544 ui::SelectFileDialog::Type picker_type, |
531 const FilePath& last_directory, | 545 const FilePath& last_directory, |
532 const string16& select_title) { | 546 const string16& select_title, |
547 const ui::SelectFileDialog::FileTypeInfo& info, | |
548 int file_type_index) { | |
533 ShellWindowRegistry* registry = ShellWindowRegistry::Get(profile()); | 549 ShellWindowRegistry* registry = ShellWindowRegistry::Get(profile()); |
534 DCHECK(registry); | 550 DCHECK(registry); |
535 ShellWindow* shell_window = registry->GetShellWindowForRenderViewHost( | 551 ShellWindow* shell_window = registry->GetShellWindowForRenderViewHost( |
536 render_view_host()); | 552 render_view_host()); |
537 if (!shell_window) { | 553 if (!shell_window) { |
538 return false; | 554 return false; |
539 } | 555 } |
540 | 556 |
541 // The entry picker will hold a reference to this function instance, | 557 // The entry picker will hold a reference to this function instance, |
542 // and subsequent sending of the function response) until the user has | 558 // and subsequent sending of the function response) until the user has |
543 // selected a file or cancelled the picker. At that point, the picker will | 559 // selected a file or cancelled the picker. At that point, the picker will |
544 // delete itself. | 560 // delete itself. |
545 new EntryPicker(this, shell_window->web_contents(), picker_type, | 561 new EntryPicker(this, shell_window->web_contents(), picker_type, |
546 last_directory, select_title); | 562 last_directory, select_title, info, file_type_index); |
547 return true; | 563 return true; |
548 } | 564 } |
549 | 565 |
550 bool DeveloperPrivateChooseEntryFunction::RunImpl() { return false; } | 566 bool DeveloperPrivateChooseEntryFunction::RunImpl() { return false; } |
551 | 567 |
552 DeveloperPrivateChooseEntryFunction::~DeveloperPrivateChooseEntryFunction() {} | 568 DeveloperPrivateChooseEntryFunction::~DeveloperPrivateChooseEntryFunction() {} |
553 | 569 |
554 void DeveloperPrivateLoadUnpackedFunction::FileSelected(const FilePath& path) { | 570 void DeveloperPrivatePackDirectoryFunction::OnPackSuccess( |
555 | 571 const FilePath& crx_file, |
556 ExtensionService* service = profile()->GetExtensionService(); | 572 const FilePath& pem_file) { |
557 extensions::UnpackedInstaller::Create(service)->Load(path); | 573 developer::PackDirectoryResponse response; |
558 DeveloperPrivateAPI::Get(profile())->SetLastUnpackedDirectory(path); | 574 response.message = |
575 UTF16ToUTF8(extensions::PackExtensionJob::StandardSuccessMessage( | |
576 crx_file, pem_file)); | |
577 response.status = developer::PACK_STATUS_SUCCESS; | |
578 results_ = developer::PackDirectory::Results::Create(response); | |
559 SendResponse(true); | 579 SendResponse(true); |
560 Release(); | 580 Release(); |
561 } | 581 } |
562 | 582 |
563 void DeveloperPrivateLoadUnpackedFunction::FileSelectionCanceled() { | 583 void DeveloperPrivatePackDirectoryFunction::OnPackFailure( |
584 const std::string& error, | |
585 extensions::ExtensionCreator::ErrorType error_type) { | |
586 developer::PackDirectoryResponse response; | |
587 response.message = error; | |
588 if (error_type == extensions::ExtensionCreator::kCRXExists) { | |
589 response.item_path = item_path_str_; | |
590 response.pem_path = key_path_str_; | |
591 response.override_flags = extensions::ExtensionCreator::kOverwriteCRX; | |
592 response.status = developer::PACK_STATUS_WARNING; | |
593 } else { | |
594 response.status = developer::PACK_STATUS_ERROR; | |
595 } | |
596 results_ = developer::PackDirectory::Results::Create(response); | |
597 SendResponse(true); | |
598 Release(); | |
599 } | |
600 | |
601 bool DeveloperPrivatePackDirectoryFunction::RunImpl() { | |
602 int flags; | |
603 EXTENSION_FUNCTION_VALIDATE(args_->GetString(0, &item_path_str_)); | |
604 EXTENSION_FUNCTION_VALIDATE(args_->GetString(1, &key_path_str_)); | |
605 EXTENSION_FUNCTION_VALIDATE(args_->GetInteger(2, &flags)); | |
606 | |
607 FilePath root_directory = | |
608 FilePath::FromWStringHack(UTF8ToWide(item_path_str_)); | |
609 | |
610 FilePath key_file = | |
611 FilePath::FromWStringHack(UTF8ToWide(key_path_str_)); | |
612 | |
613 developer::PackDirectoryResponse response; | |
614 if (root_directory.empty()) { | |
615 if (item_path_str_.empty()) | |
616 response.message = l10n_util::GetStringUTF8( | |
617 IDS_EXTENSION_PACK_DIALOG_ERROR_ROOT_REQUIRED); | |
618 else | |
619 response.message = l10n_util::GetStringUTF8( | |
620 IDS_EXTENSION_PACK_DIALOG_ERROR_ROOT_INVALID); | |
621 | |
622 response.status = developer::PACK_STATUS_ERROR; | |
623 results_ = developer::PackDirectory::Results::Create(response); | |
624 SendResponse(true); | |
625 return true; | |
626 } | |
627 | |
628 if (!key_path_str_.empty() && key_file.empty()) { | |
629 response.message = l10n_util::GetStringUTF8( | |
630 IDS_EXTENSION_PACK_DIALOG_ERROR_KEY_INVALID); | |
631 response.status = developer::PACK_STATUS_ERROR; | |
632 results_ = developer::PackDirectory::Results::Create(response); | |
633 SendResponse(true); | |
634 return true; | |
635 } | |
636 | |
637 // Pack job will release the function instance. | |
asargent_no_longer_on_chrome
2013/02/09 00:38:45
nit: this comment is slightly misleading - better
Gaurav
2013/02/11 20:01:55
Done.
Gaurav
2013/02/11 20:01:55
Done.
| |
638 AddRef(); | |
639 | |
640 pack_job_ = new extensions::PackExtensionJob( | |
641 this, root_directory, key_file, flags); | |
642 pack_job_->Start(); | |
643 return true; | |
644 } | |
645 | |
646 DeveloperPrivatePackDirectoryFunction::DeveloperPrivatePackDirectoryFunction() | |
647 {} | |
648 | |
649 DeveloperPrivatePackDirectoryFunction::~DeveloperPrivatePackDirectoryFunction() | |
650 {} | |
651 | |
652 DeveloperPrivateLoadUnpackedFunction::~DeveloperPrivateLoadUnpackedFunction() {} | |
653 | |
654 bool DeveloperPrivateChoosePathFunction::RunImpl() { | |
655 | |
656 scoped_ptr<developer::ChoosePath::Params> params( | |
657 developer::ChoosePath::Params::Create(*args_)); | |
658 EXTENSION_FUNCTION_VALIDATE(params.get() != NULL); | |
659 | |
660 ui::SelectFileDialog::Type type = ui::SelectFileDialog::SELECT_FOLDER; | |
661 ui::SelectFileDialog::FileTypeInfo info; | |
662 if (params->select_type == developer::SELECT_TYPE_FILE) { | |
663 type = ui::SelectFileDialog::SELECT_OPEN_FILE; | |
664 } | |
665 string16 select_title; | |
666 | |
667 int file_type_index = 0; | |
668 if (params->file_type == developer::FILE_TYPE_LOAD) | |
669 select_title = l10n_util::GetStringUTF16(IDS_EXTENSION_LOAD_FROM_DIRECTORY); | |
670 else if (params->file_type== developer::FILE_TYPE_PEM) { | |
671 select_title = l10n_util::GetStringUTF16( | |
672 IDS_EXTENSION_PACK_DIALOG_SELECT_KEY); | |
673 info.extensions.push_back(std::vector<FilePath::StringType>()); | |
674 info.extensions.front().push_back(FILE_PATH_LITERAL("pem")); | |
675 info.extension_description_overrides.push_back( | |
676 l10n_util::GetStringUTF16( | |
677 IDS_EXTENSION_PACK_DIALOG_KEY_FILE_TYPE_DESCRIPTION)); | |
678 info.include_all_files = true; | |
679 file_type_index = 1; | |
680 } else { | |
681 NOTREACHED(); | |
682 } | |
683 | |
684 // Balanced by FileSelected / FileSelectionCanceled. | |
685 AddRef(); | |
686 int result = | |
687 ShowPicker( | |
asargent_no_longer_on_chrome
2013/02/09 00:38:45
nit: collapse first 2 lines, e.g.
int result = Sh
Gaurav
2013/02/11 20:01:55
Done.
| |
688 type, | |
689 DeveloperPrivateAPI::Get(profile())->GetLastUnpackedDirectory(), | |
690 select_title, | |
691 info, | |
692 file_type_index); | |
693 return result; | |
694 } | |
695 | |
696 void DeveloperPrivateChoosePathFunction::FileSelected(const FilePath& path) { | |
697 SetResult(base::Value::CreateStringValue( | |
698 UTF16ToUTF8(path.LossyDisplayName()))); | |
699 SendResponse(true); | |
700 Release(); | |
701 } | |
702 | |
703 void DeveloperPrivateChoosePathFunction::FileSelectionCanceled() { | |
564 SendResponse(false); | 704 SendResponse(false); |
565 Release(); | 705 Release(); |
566 } | 706 } |
567 | 707 |
568 DeveloperPrivateLoadUnpackedFunction::~DeveloperPrivateLoadUnpackedFunction() {} | 708 DeveloperPrivateChoosePathFunction::~DeveloperPrivateChoosePathFunction() {} |
569 | 709 |
570 bool DeveloperPrivateGetStringsFunction::RunImpl() { | 710 bool DeveloperPrivateGetStringsFunction::RunImpl() { |
571 DictionaryValue* dict = new DictionaryValue(); | 711 DictionaryValue* dict = new DictionaryValue(); |
572 SetResult(dict); | 712 SetResult(dict); |
573 | 713 |
574 #define SET_STRING(id, idr) \ | 714 #define SET_STRING(id, idr) \ |
575 dict->SetString(id, l10n_util::GetStringUTF16(idr)) | 715 dict->SetString(id, l10n_util::GetStringUTF16(idr)) |
576 SET_STRING("extensionSettings", IDS_MANAGE_EXTENSIONS_SETTING_WINDOWS_TITLE); | 716 SET_STRING("extensionSettings", IDS_MANAGE_EXTENSIONS_SETTING_WINDOWS_TITLE); |
577 | 717 |
578 SET_STRING("extensionSettingsNoExtensions", IDS_EXTENSIONS_NONE_INSTALLED); | 718 SET_STRING("extensionSettingsNoExtensions", IDS_EXTENSIONS_NONE_INSTALLED); |
(...skipping 54 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
633 | 773 |
634 #undef SET_STRING | 774 #undef SET_STRING |
635 return true; | 775 return true; |
636 } | 776 } |
637 | 777 |
638 DeveloperPrivateGetStringsFunction::~DeveloperPrivateGetStringsFunction() {} | 778 DeveloperPrivateGetStringsFunction::~DeveloperPrivateGetStringsFunction() {} |
639 | 779 |
640 } // namespace api | 780 } // namespace api |
641 | 781 |
642 } // namespace extensions | 782 } // namespace extensions |
OLD | NEW |