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/strings/string_number_conversions.h" | 9 #include "base/strings/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 base::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 = ShowPicker( |
| 520 ui::SelectFileDialog::SELECT_FOLDER, |
| 521 DeveloperPrivateAPI::Get(profile())->GetLastUnpackedDirectory(), |
| 522 select_title, |
| 523 ui::SelectFileDialog::FileTypeInfo(), |
| 524 0); |
526 return result; | 525 return result; |
527 } | 526 } |
528 | 527 |
| 528 void DeveloperPrivateLoadUnpackedFunction::FileSelected(const FilePath& path) { |
| 529 ExtensionService* service = profile()->GetExtensionService(); |
| 530 extensions::UnpackedInstaller::Create(service)->Load(path); |
| 531 DeveloperPrivateAPI::Get(profile())->SetLastUnpackedDirectory(path); |
| 532 SendResponse(true); |
| 533 Release(); |
| 534 } |
| 535 |
| 536 void DeveloperPrivateLoadUnpackedFunction::FileSelectionCanceled() { |
| 537 SendResponse(false); |
| 538 Release(); |
| 539 } |
| 540 |
529 bool DeveloperPrivateChooseEntryFunction::ShowPicker( | 541 bool DeveloperPrivateChooseEntryFunction::ShowPicker( |
530 ui::SelectFileDialog::Type picker_type, | 542 ui::SelectFileDialog::Type picker_type, |
531 const base::FilePath& last_directory, | 543 const FilePath& last_directory, |
532 const string16& select_title) { | 544 const string16& select_title, |
| 545 const ui::SelectFileDialog::FileTypeInfo& info, |
| 546 int file_type_index) { |
533 ShellWindowRegistry* registry = ShellWindowRegistry::Get(profile()); | 547 ShellWindowRegistry* registry = ShellWindowRegistry::Get(profile()); |
534 DCHECK(registry); | 548 DCHECK(registry); |
535 ShellWindow* shell_window = registry->GetShellWindowForRenderViewHost( | 549 ShellWindow* shell_window = registry->GetShellWindowForRenderViewHost( |
536 render_view_host()); | 550 render_view_host()); |
537 if (!shell_window) { | 551 if (!shell_window) { |
538 return false; | 552 return false; |
539 } | 553 } |
540 | 554 |
541 // The entry picker will hold a reference to this function instance, | 555 // The entry picker will hold a reference to this function instance, |
542 // and subsequent sending of the function response) until the user has | 556 // 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 | 557 // selected a file or cancelled the picker. At that point, the picker will |
544 // delete itself. | 558 // delete itself. |
545 new EntryPicker(this, shell_window->web_contents(), picker_type, | 559 new EntryPicker(this, shell_window->web_contents(), picker_type, |
546 last_directory, select_title); | 560 last_directory, select_title, info, file_type_index); |
547 return true; | 561 return true; |
548 } | 562 } |
549 | 563 |
550 bool DeveloperPrivateChooseEntryFunction::RunImpl() { return false; } | 564 bool DeveloperPrivateChooseEntryFunction::RunImpl() { return false; } |
551 | 565 |
552 DeveloperPrivateChooseEntryFunction::~DeveloperPrivateChooseEntryFunction() {} | 566 DeveloperPrivateChooseEntryFunction::~DeveloperPrivateChooseEntryFunction() {} |
553 | 567 |
554 void DeveloperPrivateLoadUnpackedFunction::FileSelected( | 568 void DeveloperPrivatePackDirectoryFunction::OnPackSuccess( |
555 const base::FilePath& path) { | 569 const FilePath& crx_file, |
556 ExtensionService* service = profile()->GetExtensionService(); | 570 const FilePath& pem_file) { |
557 extensions::UnpackedInstaller::Create(service)->Load(path); | 571 developer::PackDirectoryResponse response; |
558 DeveloperPrivateAPI::Get(profile())->SetLastUnpackedDirectory(path); | 572 response.message = |
| 573 UTF16ToUTF8(extensions::PackExtensionJob::StandardSuccessMessage( |
| 574 crx_file, pem_file)); |
| 575 response.status = developer::PACK_STATUS_SUCCESS; |
| 576 results_ = developer::PackDirectory::Results::Create(response); |
559 SendResponse(true); | 577 SendResponse(true); |
560 Release(); | 578 Release(); |
561 } | 579 } |
562 | 580 |
563 void DeveloperPrivateLoadUnpackedFunction::FileSelectionCanceled() { | 581 void DeveloperPrivatePackDirectoryFunction::OnPackFailure( |
| 582 const std::string& error, |
| 583 extensions::ExtensionCreator::ErrorType error_type) { |
| 584 developer::PackDirectoryResponse response; |
| 585 response.message = error; |
| 586 if (error_type == extensions::ExtensionCreator::kCRXExists) { |
| 587 response.item_path = item_path_str_; |
| 588 response.pem_path = key_path_str_; |
| 589 response.override_flags = extensions::ExtensionCreator::kOverwriteCRX; |
| 590 response.status = developer::PACK_STATUS_WARNING; |
| 591 } else { |
| 592 response.status = developer::PACK_STATUS_ERROR; |
| 593 } |
| 594 results_ = developer::PackDirectory::Results::Create(response); |
| 595 SendResponse(true); |
| 596 Release(); |
| 597 } |
| 598 |
| 599 bool DeveloperPrivatePackDirectoryFunction::RunImpl() { |
| 600 int flags; |
| 601 EXTENSION_FUNCTION_VALIDATE(args_->GetString(0, &item_path_str_)); |
| 602 EXTENSION_FUNCTION_VALIDATE(args_->GetString(1, &key_path_str_)); |
| 603 EXTENSION_FUNCTION_VALIDATE(args_->GetInteger(2, &flags)); |
| 604 |
| 605 FilePath root_directory = |
| 606 FilePath::FromWStringHack(UTF8ToWide(item_path_str_)); |
| 607 |
| 608 FilePath key_file = |
| 609 FilePath::FromWStringHack(UTF8ToWide(key_path_str_)); |
| 610 |
| 611 developer::PackDirectoryResponse response; |
| 612 if (root_directory.empty()) { |
| 613 if (item_path_str_.empty()) |
| 614 response.message = l10n_util::GetStringUTF8( |
| 615 IDS_EXTENSION_PACK_DIALOG_ERROR_ROOT_REQUIRED); |
| 616 else |
| 617 response.message = l10n_util::GetStringUTF8( |
| 618 IDS_EXTENSION_PACK_DIALOG_ERROR_ROOT_INVALID); |
| 619 |
| 620 response.status = developer::PACK_STATUS_ERROR; |
| 621 results_ = developer::PackDirectory::Results::Create(response); |
| 622 SendResponse(true); |
| 623 return true; |
| 624 } |
| 625 |
| 626 if (!key_path_str_.empty() && key_file.empty()) { |
| 627 response.message = l10n_util::GetStringUTF8( |
| 628 IDS_EXTENSION_PACK_DIALOG_ERROR_KEY_INVALID); |
| 629 response.status = developer::PACK_STATUS_ERROR; |
| 630 results_ = developer::PackDirectory::Results::Create(response); |
| 631 SendResponse(true); |
| 632 return true; |
| 633 } |
| 634 |
| 635 // Balanced in OnPackSuccess / OnPackFailure. |
| 636 AddRef(); |
| 637 |
| 638 pack_job_ = new extensions::PackExtensionJob( |
| 639 this, root_directory, key_file, flags); |
| 640 pack_job_->Start(); |
| 641 return true; |
| 642 } |
| 643 |
| 644 DeveloperPrivatePackDirectoryFunction::DeveloperPrivatePackDirectoryFunction() |
| 645 {} |
| 646 |
| 647 DeveloperPrivatePackDirectoryFunction::~DeveloperPrivatePackDirectoryFunction() |
| 648 {} |
| 649 |
| 650 DeveloperPrivateLoadUnpackedFunction::~DeveloperPrivateLoadUnpackedFunction() {} |
| 651 |
| 652 bool DeveloperPrivateChoosePathFunction::RunImpl() { |
| 653 |
| 654 scoped_ptr<developer::ChoosePath::Params> params( |
| 655 developer::ChoosePath::Params::Create(*args_)); |
| 656 EXTENSION_FUNCTION_VALIDATE(params.get() != NULL); |
| 657 |
| 658 ui::SelectFileDialog::Type type = ui::SelectFileDialog::SELECT_FOLDER; |
| 659 ui::SelectFileDialog::FileTypeInfo info; |
| 660 if (params->select_type == developer::SELECT_TYPE_FILE) { |
| 661 type = ui::SelectFileDialog::SELECT_OPEN_FILE; |
| 662 } |
| 663 string16 select_title; |
| 664 |
| 665 int file_type_index = 0; |
| 666 if (params->file_type == developer::FILE_TYPE_LOAD) |
| 667 select_title = l10n_util::GetStringUTF16(IDS_EXTENSION_LOAD_FROM_DIRECTORY); |
| 668 else if (params->file_type== developer::FILE_TYPE_PEM) { |
| 669 select_title = l10n_util::GetStringUTF16( |
| 670 IDS_EXTENSION_PACK_DIALOG_SELECT_KEY); |
| 671 info.extensions.push_back(std::vector<FilePath::StringType>()); |
| 672 info.extensions.front().push_back(FILE_PATH_LITERAL("pem")); |
| 673 info.extension_description_overrides.push_back( |
| 674 l10n_util::GetStringUTF16( |
| 675 IDS_EXTENSION_PACK_DIALOG_KEY_FILE_TYPE_DESCRIPTION)); |
| 676 info.include_all_files = true; |
| 677 file_type_index = 1; |
| 678 } else { |
| 679 NOTREACHED(); |
| 680 } |
| 681 |
| 682 // Balanced by FileSelected / FileSelectionCanceled. |
| 683 AddRef(); |
| 684 int result = ShowPicker( |
| 685 type, |
| 686 DeveloperPrivateAPI::Get(profile())->GetLastUnpackedDirectory(), |
| 687 select_title, |
| 688 info, |
| 689 file_type_index); |
| 690 return result; |
| 691 } |
| 692 |
| 693 void DeveloperPrivateChoosePathFunction::FileSelected(const FilePath& path) { |
| 694 SetResult(base::Value::CreateStringValue( |
| 695 UTF16ToUTF8(path.LossyDisplayName()))); |
| 696 SendResponse(true); |
| 697 Release(); |
| 698 } |
| 699 |
| 700 void DeveloperPrivateChoosePathFunction::FileSelectionCanceled() { |
564 SendResponse(false); | 701 SendResponse(false); |
565 Release(); | 702 Release(); |
566 } | 703 } |
567 | 704 |
568 DeveloperPrivateLoadUnpackedFunction::~DeveloperPrivateLoadUnpackedFunction() {} | 705 DeveloperPrivateChoosePathFunction::~DeveloperPrivateChoosePathFunction() {} |
569 | 706 |
570 bool DeveloperPrivateGetStringsFunction::RunImpl() { | 707 bool DeveloperPrivateGetStringsFunction::RunImpl() { |
571 DictionaryValue* dict = new DictionaryValue(); | 708 DictionaryValue* dict = new DictionaryValue(); |
572 SetResult(dict); | 709 SetResult(dict); |
573 | 710 |
574 #define SET_STRING(id, idr) \ | 711 #define SET_STRING(id, idr) \ |
575 dict->SetString(id, l10n_util::GetStringUTF16(idr)) | 712 dict->SetString(id, l10n_util::GetStringUTF16(idr)) |
576 SET_STRING("extensionSettings", IDS_MANAGE_EXTENSIONS_SETTING_WINDOWS_TITLE); | 713 SET_STRING("extensionSettings", IDS_MANAGE_EXTENSIONS_SETTING_WINDOWS_TITLE); |
577 | 714 |
578 SET_STRING("extensionSettingsNoExtensions", IDS_EXTENSIONS_NONE_INSTALLED); | 715 SET_STRING("extensionSettingsNoExtensions", IDS_EXTENSIONS_NONE_INSTALLED); |
(...skipping 54 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
633 | 770 |
634 #undef SET_STRING | 771 #undef SET_STRING |
635 return true; | 772 return true; |
636 } | 773 } |
637 | 774 |
638 DeveloperPrivateGetStringsFunction::~DeveloperPrivateGetStringsFunction() {} | 775 DeveloperPrivateGetStringsFunction::~DeveloperPrivateGetStringsFunction() {} |
639 | 776 |
640 } // namespace api | 777 } // namespace api |
641 | 778 |
642 } // namespace extensions | 779 } // namespace extensions |
OLD | NEW |