Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(275)

Side by Side Diff: chrome/browser/extensions/api/developer_private/developer_private_api.cc

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

Powered by Google App Engine
This is Rietveld 408576698