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 "apps/app_load_service.h" | 7 #include "apps/app_load_service.h" |
8 #include "apps/app_restore_service.h" | 8 #include "apps/app_restore_service.h" |
| 9 #include "apps/app_window.h" |
| 10 #include "apps/app_window_registry.h" |
9 #include "apps/saved_files_service.h" | 11 #include "apps/saved_files_service.h" |
10 #include "apps/shell_window.h" | |
11 #include "apps/shell_window_registry.h" | |
12 #include "base/base64.h" | 12 #include "base/base64.h" |
13 #include "base/bind.h" | 13 #include "base/bind.h" |
14 #include "base/command_line.h" | 14 #include "base/command_line.h" |
15 #include "base/file_util.h" | 15 #include "base/file_util.h" |
16 #include "base/files/file_enumerator.h" | 16 #include "base/files/file_enumerator.h" |
17 #include "base/i18n/file_util_icu.h" | 17 #include "base/i18n/file_util_icu.h" |
18 #include "base/strings/string_number_conversions.h" | 18 #include "base/strings/string_number_conversions.h" |
19 #include "base/strings/utf_string_conversions.h" | 19 #include "base/strings/utf_string_conversions.h" |
20 #include "base/values.h" | 20 #include "base/values.h" |
21 #include "chrome/browser/chrome_notification_types.h" | 21 #include "chrome/browser/chrome_notification_types.h" |
(...skipping 47 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
69 #include "net/base/net_util.h" | 69 #include "net/base/net_util.h" |
70 #include "ui/base/l10n/l10n_util.h" | 70 #include "ui/base/l10n/l10n_util.h" |
71 #include "ui/base/resource/resource_bundle.h" | 71 #include "ui/base/resource/resource_bundle.h" |
72 #include "ui/base/webui/web_ui_util.h" | 72 #include "ui/base/webui/web_ui_util.h" |
73 #include "webkit/browser/fileapi/external_mount_points.h" | 73 #include "webkit/browser/fileapi/external_mount_points.h" |
74 #include "webkit/browser/fileapi/file_system_context.h" | 74 #include "webkit/browser/fileapi/file_system_context.h" |
75 #include "webkit/browser/fileapi/file_system_operation.h" | 75 #include "webkit/browser/fileapi/file_system_operation.h" |
76 #include "webkit/browser/fileapi/file_system_operation_runner.h" | 76 #include "webkit/browser/fileapi/file_system_operation_runner.h" |
77 #include "webkit/common/blob/shareable_file_reference.h" | 77 #include "webkit/common/blob/shareable_file_reference.h" |
78 | 78 |
79 using apps::ShellWindow; | 79 using apps::AppWindow; |
80 using apps::ShellWindowRegistry; | 80 using apps::AppWindowRegistry; |
81 using content::RenderViewHost; | 81 using content::RenderViewHost; |
82 | 82 |
83 namespace extensions { | 83 namespace extensions { |
84 | 84 |
85 namespace developer_private = api::developer_private; | 85 namespace developer_private = api::developer_private; |
86 | 86 |
87 namespace { | 87 namespace { |
88 | 88 |
89 const base::FilePath::CharType kUnpackedAppsFolder[] | 89 const base::FilePath::CharType kUnpackedAppsFolder[] |
90 = FILE_PATH_LITERAL("apps_target"); | 90 = FILE_PATH_LITERAL("apps_target"); |
(...skipping 375 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
466 (web_contents->GetURL() == BackgroundInfo::GetBackgroundURL(extension)); | 466 (web_contents->GetURL() == BackgroundInfo::GetBackgroundURL(extension)); |
467 result->push_back(constructInspectView( | 467 result->push_back(constructInspectView( |
468 web_contents->GetURL(), | 468 web_contents->GetURL(), |
469 process->GetID(), | 469 process->GetID(), |
470 host->GetRoutingID(), | 470 host->GetRoutingID(), |
471 process->GetBrowserContext()->IsOffTheRecord(), | 471 process->GetBrowserContext()->IsOffTheRecord(), |
472 is_background_page && has_generated_background_page)); | 472 is_background_page && has_generated_background_page)); |
473 } | 473 } |
474 } | 474 } |
475 | 475 |
476 void DeveloperPrivateGetItemsInfoFunction:: | 476 void DeveloperPrivateGetItemsInfoFunction::GetAppWindowPagesForExtensionProfile( |
477 GetShellWindowPagesForExtensionProfile( | 477 const Extension* extension, |
478 const Extension* extension, | 478 ItemInspectViewList* result) { |
479 ItemInspectViewList* result) { | 479 AppWindowRegistry* registry = AppWindowRegistry::Get(GetProfile()); |
480 ShellWindowRegistry* registry = ShellWindowRegistry::Get(GetProfile()); | |
481 if (!registry) return; | 480 if (!registry) return; |
482 | 481 |
483 const ShellWindowRegistry::ShellWindowList windows = | 482 const AppWindowRegistry::AppWindowList windows = |
484 registry->GetShellWindowsForApp(extension->id()); | 483 registry->GetAppWindowsForApp(extension->id()); |
485 | 484 |
486 bool has_generated_background_page = | 485 bool has_generated_background_page = |
487 BackgroundInfo::HasGeneratedBackgroundPage(extension); | 486 BackgroundInfo::HasGeneratedBackgroundPage(extension); |
488 for (ShellWindowRegistry::const_iterator it = windows.begin(); | 487 for (AppWindowRegistry::const_iterator it = windows.begin(); |
489 it != windows.end(); ++it) { | 488 it != windows.end(); |
| 489 ++it) { |
490 content::WebContents* web_contents = (*it)->web_contents(); | 490 content::WebContents* web_contents = (*it)->web_contents(); |
491 RenderViewHost* host = web_contents->GetRenderViewHost(); | 491 RenderViewHost* host = web_contents->GetRenderViewHost(); |
492 content::RenderProcessHost* process = host->GetProcess(); | 492 content::RenderProcessHost* process = host->GetProcess(); |
493 bool is_background_page = | 493 bool is_background_page = |
494 (web_contents->GetURL() == BackgroundInfo::GetBackgroundURL(extension)); | 494 (web_contents->GetURL() == BackgroundInfo::GetBackgroundURL(extension)); |
495 result->push_back(constructInspectView( | 495 result->push_back(constructInspectView( |
496 web_contents->GetURL(), | 496 web_contents->GetURL(), |
497 process->GetID(), | 497 process->GetID(), |
498 host->GetRoutingID(), | 498 host->GetRoutingID(), |
499 process->GetBrowserContext()->IsOffTheRecord(), | 499 process->GetBrowserContext()->IsOffTheRecord(), |
(...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
532 | 532 |
533 ItemInspectViewList result; | 533 ItemInspectViewList result; |
534 // Get the extension process's active views. | 534 // Get the extension process's active views. |
535 extensions::ProcessManager* process_manager = | 535 extensions::ProcessManager* process_manager = |
536 ExtensionSystem::Get(GetProfile())->process_manager(); | 536 ExtensionSystem::Get(GetProfile())->process_manager(); |
537 GetInspectablePagesForExtensionProcess( | 537 GetInspectablePagesForExtensionProcess( |
538 extension, | 538 extension, |
539 process_manager->GetRenderViewHostsForExtension(extension->id()), | 539 process_manager->GetRenderViewHostsForExtension(extension->id()), |
540 &result); | 540 &result); |
541 | 541 |
542 // Get shell window views | 542 // Get app window views |
543 GetShellWindowPagesForExtensionProfile(extension, &result); | 543 GetAppWindowPagesForExtensionProfile(extension, &result); |
544 | 544 |
545 // Include a link to start the lazy background page, if applicable. | 545 // Include a link to start the lazy background page, if applicable. |
546 if (BackgroundInfo::HasLazyBackgroundPage(extension) && | 546 if (BackgroundInfo::HasLazyBackgroundPage(extension) && |
547 extension_is_enabled && | 547 extension_is_enabled && |
548 !process_manager->GetBackgroundHostForExtension(extension->id())) { | 548 !process_manager->GetBackgroundHostForExtension(extension->id())) { |
549 result.push_back(constructInspectView( | 549 result.push_back(constructInspectView( |
550 BackgroundInfo::GetBackgroundURL(extension), | 550 BackgroundInfo::GetBackgroundURL(extension), |
551 -1, | 551 -1, |
552 -1, | 552 -1, |
553 false, | 553 false, |
554 BackgroundInfo::HasGeneratedBackgroundPage(extension))); | 554 BackgroundInfo::HasGeneratedBackgroundPage(extension))); |
555 } | 555 } |
556 | 556 |
557 ExtensionService* service = GetProfile()->GetExtensionService(); | 557 ExtensionService* service = GetProfile()->GetExtensionService(); |
558 // Repeat for the incognito process, if applicable. Don't try to get | 558 // Repeat for the incognito process, if applicable. Don't try to get |
559 // shell windows for incognito process. | 559 // app windows for incognito process. |
560 if (service->profile()->HasOffTheRecordProfile() && | 560 if (service->profile()->HasOffTheRecordProfile() && |
561 IncognitoInfo::IsSplitMode(extension)) { | 561 IncognitoInfo::IsSplitMode(extension)) { |
562 process_manager = ExtensionSystem::Get( | 562 process_manager = ExtensionSystem::Get( |
563 service->profile()->GetOffTheRecordProfile())->process_manager(); | 563 service->profile()->GetOffTheRecordProfile())->process_manager(); |
564 GetInspectablePagesForExtensionProcess( | 564 GetInspectablePagesForExtensionProcess( |
565 extension, | 565 extension, |
566 process_manager->GetRenderViewHostsForExtension(extension->id()), | 566 process_manager->GetRenderViewHostsForExtension(extension->id()), |
567 &result); | 567 &result); |
568 | 568 |
569 if (BackgroundInfo::HasLazyBackgroundPage(extension) && | 569 if (BackgroundInfo::HasLazyBackgroundPage(extension) && |
(...skipping 127 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
697 ExtensionService* service = GetProfile()->GetExtensionService(); | 697 ExtensionService* service = GetProfile()->GetExtensionService(); |
698 CHECK(!params->item_id.empty()); | 698 CHECK(!params->item_id.empty()); |
699 service->ReloadExtension(params->item_id); | 699 service->ReloadExtension(params->item_id); |
700 return true; | 700 return true; |
701 } | 701 } |
702 | 702 |
703 bool DeveloperPrivateShowPermissionsDialogFunction::RunImpl() { | 703 bool DeveloperPrivateShowPermissionsDialogFunction::RunImpl() { |
704 EXTENSION_FUNCTION_VALIDATE(args_->GetString(0, &extension_id_)); | 704 EXTENSION_FUNCTION_VALIDATE(args_->GetString(0, &extension_id_)); |
705 ExtensionService* service = GetProfile()->GetExtensionService(); | 705 ExtensionService* service = GetProfile()->GetExtensionService(); |
706 CHECK(!extension_id_.empty()); | 706 CHECK(!extension_id_.empty()); |
707 ShellWindowRegistry* registry = ShellWindowRegistry::Get(GetProfile()); | 707 AppWindowRegistry* registry = AppWindowRegistry::Get(GetProfile()); |
708 DCHECK(registry); | 708 DCHECK(registry); |
709 ShellWindow* shell_window = registry->GetShellWindowForRenderViewHost( | 709 AppWindow* app_window = |
710 render_view_host()); | 710 registry->GetAppWindowForRenderViewHost(render_view_host()); |
711 prompt_.reset(new ExtensionInstallPrompt(shell_window->web_contents())); | 711 prompt_.reset(new ExtensionInstallPrompt(app_window->web_contents())); |
712 const Extension* extension = service->GetInstalledExtension(extension_id_); | 712 const Extension* extension = service->GetInstalledExtension(extension_id_); |
713 | 713 |
714 if (!extension) | 714 if (!extension) |
715 return false; | 715 return false; |
716 | 716 |
717 // Released by InstallUIAbort or InstallUIProceed. | 717 // Released by InstallUIAbort or InstallUIProceed. |
718 AddRef(); | 718 AddRef(); |
719 std::vector<base::FilePath> retained_file_paths; | 719 std::vector<base::FilePath> retained_file_paths; |
720 if (extension->HasAPIPermission(extensions::APIPermission::kFileSystem)) { | 720 if (extension->HasAPIPermission(extensions::APIPermission::kFileSystem)) { |
721 std::vector<apps::SavedFileEntry> retained_file_entries = | 721 std::vector<apps::SavedFileEntry> retained_file_entries = |
(...skipping 55 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
777 (!enable && policy->MustRemainEnabled(extension, NULL)) || | 777 (!enable && policy->MustRemainEnabled(extension, NULL)) || |
778 (enable && policy->MustRemainDisabled(extension, NULL, NULL))) { | 778 (enable && policy->MustRemainDisabled(extension, NULL, NULL))) { |
779 LOG(ERROR) << "Attempt to change enable state denied by management policy. " | 779 LOG(ERROR) << "Attempt to change enable state denied by management policy. " |
780 << "Extension id: " << extension_id.c_str(); | 780 << "Extension id: " << extension_id.c_str(); |
781 return false; | 781 return false; |
782 } | 782 } |
783 | 783 |
784 if (enable) { | 784 if (enable) { |
785 ExtensionPrefs* prefs = service->extension_prefs(); | 785 ExtensionPrefs* prefs = service->extension_prefs(); |
786 if (prefs->DidExtensionEscalatePermissions(extension_id)) { | 786 if (prefs->DidExtensionEscalatePermissions(extension_id)) { |
787 ShellWindowRegistry* registry = ShellWindowRegistry::Get(GetProfile()); | 787 AppWindowRegistry* registry = AppWindowRegistry::Get(GetProfile()); |
788 CHECK(registry); | 788 CHECK(registry); |
789 ShellWindow* shell_window = registry->GetShellWindowForRenderViewHost( | 789 AppWindow* app_window = |
790 render_view_host()); | 790 registry->GetAppWindowForRenderViewHost(render_view_host()); |
791 if (!shell_window) { | 791 if (!app_window) { |
792 return false; | 792 return false; |
793 } | 793 } |
794 | 794 |
795 ShowExtensionDisabledDialog( | 795 ShowExtensionDisabledDialog( |
796 service, shell_window->web_contents(), extension); | 796 service, app_window->web_contents(), extension); |
797 } else if ((prefs->GetDisableReasons(extension_id) & | 797 } else if ((prefs->GetDisableReasons(extension_id) & |
798 Extension::DISABLE_UNSUPPORTED_REQUIREMENT) && | 798 Extension::DISABLE_UNSUPPORTED_REQUIREMENT) && |
799 !requirements_checker_.get()) { | 799 !requirements_checker_.get()) { |
800 // Recheck the requirements. | 800 // Recheck the requirements. |
801 scoped_refptr<const Extension> extension = | 801 scoped_refptr<const Extension> extension = |
802 service->GetExtensionById(extension_id, | 802 service->GetExtensionById(extension_id, |
803 true );// include_disabled | 803 true );// include_disabled |
804 requirements_checker_.reset(new RequirementsChecker); | 804 requirements_checker_.reset(new RequirementsChecker); |
805 // Released by OnRequirementsChecked. | 805 // Released by OnRequirementsChecked. |
806 AddRef(); | 806 AddRef(); |
(...skipping 98 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
905 SendResponse(false); | 905 SendResponse(false); |
906 Release(); | 906 Release(); |
907 } | 907 } |
908 | 908 |
909 bool DeveloperPrivateChooseEntryFunction::ShowPicker( | 909 bool DeveloperPrivateChooseEntryFunction::ShowPicker( |
910 ui::SelectFileDialog::Type picker_type, | 910 ui::SelectFileDialog::Type picker_type, |
911 const base::FilePath& last_directory, | 911 const base::FilePath& last_directory, |
912 const base::string16& select_title, | 912 const base::string16& select_title, |
913 const ui::SelectFileDialog::FileTypeInfo& info, | 913 const ui::SelectFileDialog::FileTypeInfo& info, |
914 int file_type_index) { | 914 int file_type_index) { |
915 ShellWindowRegistry* registry = ShellWindowRegistry::Get(GetProfile()); | 915 AppWindowRegistry* registry = AppWindowRegistry::Get(GetProfile()); |
916 DCHECK(registry); | 916 DCHECK(registry); |
917 ShellWindow* shell_window = registry->GetShellWindowForRenderViewHost( | 917 AppWindow* app_window = |
918 render_view_host()); | 918 registry->GetAppWindowForRenderViewHost(render_view_host()); |
919 if (!shell_window) { | 919 if (!app_window) { |
920 return false; | 920 return false; |
921 } | 921 } |
922 | 922 |
923 // The entry picker will hold a reference to this function instance, | 923 // The entry picker will hold a reference to this function instance, |
924 // and subsequent sending of the function response) until the user has | 924 // and subsequent sending of the function response) until the user has |
925 // selected a file or cancelled the picker. At that point, the picker will | 925 // selected a file or cancelled the picker. At that point, the picker will |
926 // delete itself. | 926 // delete itself. |
927 new EntryPicker(this, shell_window->web_contents(), picker_type, | 927 new EntryPicker(this, |
928 last_directory, select_title, info, file_type_index); | 928 app_window->web_contents(), |
| 929 picker_type, |
| 930 last_directory, |
| 931 select_title, |
| 932 info, |
| 933 file_type_index); |
929 return true; | 934 return true; |
930 } | 935 } |
931 | 936 |
932 bool DeveloperPrivateChooseEntryFunction::RunImpl() { return false; } | 937 bool DeveloperPrivateChooseEntryFunction::RunImpl() { return false; } |
933 | 938 |
934 DeveloperPrivateChooseEntryFunction::~DeveloperPrivateChooseEntryFunction() {} | 939 DeveloperPrivateChooseEntryFunction::~DeveloperPrivateChooseEntryFunction() {} |
935 | 940 |
936 void DeveloperPrivatePackDirectoryFunction::OnPackSuccess( | 941 void DeveloperPrivatePackDirectoryFunction::OnPackSuccess( |
937 const base::FilePath& crx_file, | 942 const base::FilePath& crx_file, |
938 const base::FilePath& pem_file) { | 943 const base::FilePath& pem_file) { |
(...skipping 398 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1337 } | 1342 } |
1338 | 1343 |
1339 error_ui_util::HandleOpenDevTools(dict); | 1344 error_ui_util::HandleOpenDevTools(dict); |
1340 | 1345 |
1341 return true; | 1346 return true; |
1342 } | 1347 } |
1343 | 1348 |
1344 } // namespace api | 1349 } // namespace api |
1345 | 1350 |
1346 } // namespace extensions | 1351 } // namespace extensions |
OLD | NEW |