Chromium Code Reviews| 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" | |
| 8 #include "apps/saved_files_service.h" | |
| 9 #include "base/base64.h" | 7 #include "base/base64.h" |
| 10 #include "base/bind.h" | 8 #include "base/bind.h" |
| 11 #include "base/files/file_util.h" | 9 #include "base/files/file_util.h" |
| 12 #include "base/lazy_instance.h" | 10 #include "base/lazy_instance.h" |
| 13 #include "base/strings/string_number_conversions.h" | 11 #include "base/strings/string_number_conversions.h" |
| 14 #include "base/strings/stringprintf.h" | 12 #include "base/strings/stringprintf.h" |
| 15 #include "base/strings/utf_string_conversions.h" | 13 #include "base/strings/utf_string_conversions.h" |
| 16 #include "chrome/browser/devtools/devtools_window.h" | 14 #include "chrome/browser/devtools/devtools_window.h" |
| 17 #include "chrome/browser/extensions/api/developer_private/developer_private_mang le.h" | 15 #include "chrome/browser/extensions/api/developer_private/developer_private_mang le.h" |
| 18 #include "chrome/browser/extensions/api/developer_private/entry_picker.h" | 16 #include "chrome/browser/extensions/api/developer_private/entry_picker.h" |
| 19 #include "chrome/browser/extensions/api/developer_private/extension_info_generat or.h" | 17 #include "chrome/browser/extensions/api/developer_private/extension_info_generat or.h" |
| 18 #include "chrome/browser/extensions/api/developer_private/show_permissions_dialo g_helper.h" | |
| 20 #include "chrome/browser/extensions/api/file_handlers/app_file_handler_util.h" | 19 #include "chrome/browser/extensions/api/file_handlers/app_file_handler_util.h" |
| 21 #include "chrome/browser/extensions/devtools_util.h" | 20 #include "chrome/browser/extensions/devtools_util.h" |
| 22 #include "chrome/browser/extensions/extension_service.h" | 21 #include "chrome/browser/extensions/extension_service.h" |
| 23 #include "chrome/browser/extensions/extension_ui_util.h" | 22 #include "chrome/browser/extensions/extension_ui_util.h" |
| 24 #include "chrome/browser/extensions/extension_util.h" | 23 #include "chrome/browser/extensions/extension_util.h" |
| 25 #include "chrome/browser/extensions/shared_module_service.h" | 24 #include "chrome/browser/extensions/shared_module_service.h" |
| 26 #include "chrome/browser/extensions/unpacked_installer.h" | 25 #include "chrome/browser/extensions/unpacked_installer.h" |
| 27 #include "chrome/browser/extensions/updater/extension_updater.h" | 26 #include "chrome/browser/extensions/updater/extension_updater.h" |
| 28 #include "chrome/browser/profiles/profile.h" | 27 #include "chrome/browser/profiles/profile.h" |
| 29 #include "chrome/browser/ui/browser_finder.h" | 28 #include "chrome/browser/ui/browser_finder.h" |
| 30 #include "chrome/browser/ui/tabs/tab_strip_model.h" | 29 #include "chrome/browser/ui/tabs/tab_strip_model.h" |
| 31 #include "chrome/common/extensions/api/developer_private.h" | 30 #include "chrome/common/extensions/api/developer_private.h" |
| 32 #include "chrome/common/extensions/manifest_handlers/app_launch_info.h" | 31 #include "chrome/common/extensions/manifest_handlers/app_launch_info.h" |
| 33 #include "chrome/common/url_constants.h" | 32 #include "chrome/common/url_constants.h" |
| 34 #include "chrome/grit/generated_resources.h" | 33 #include "chrome/grit/generated_resources.h" |
| 35 #include "content/public/browser/browser_thread.h" | 34 #include "content/public/browser/browser_thread.h" |
| 36 #include "content/public/browser/notification_service.h" | 35 #include "content/public/browser/notification_service.h" |
| 37 #include "content/public/browser/render_process_host.h" | 36 #include "content/public/browser/render_process_host.h" |
| 38 #include "content/public/browser/render_view_host.h" | 37 #include "content/public/browser/render_view_host.h" |
| 39 #include "content/public/browser/site_instance.h" | 38 #include "content/public/browser/site_instance.h" |
| 40 #include "content/public/browser/storage_partition.h" | 39 #include "content/public/browser/storage_partition.h" |
| 41 #include "content/public/browser/web_contents.h" | 40 #include "content/public/browser/web_contents.h" |
| 42 #include "extensions/browser/api/device_permissions_manager.h" | |
| 43 #include "extensions/browser/app_window/app_window.h" | 41 #include "extensions/browser/app_window/app_window.h" |
| 44 #include "extensions/browser/app_window/app_window_registry.h" | 42 #include "extensions/browser/app_window/app_window_registry.h" |
| 45 #include "extensions/browser/extension_error.h" | 43 #include "extensions/browser/extension_error.h" |
| 46 #include "extensions/browser/extension_prefs.h" | 44 #include "extensions/browser/extension_prefs.h" |
| 47 #include "extensions/browser/extension_registry.h" | 45 #include "extensions/browser/extension_registry.h" |
| 48 #include "extensions/browser/extension_system.h" | 46 #include "extensions/browser/extension_system.h" |
| 49 #include "extensions/browser/file_highlighter.h" | 47 #include "extensions/browser/file_highlighter.h" |
| 50 #include "extensions/browser/management_policy.h" | 48 #include "extensions/browser/management_policy.h" |
| 51 #include "extensions/browser/notification_types.h" | 49 #include "extensions/browser/notification_types.h" |
| 52 #include "extensions/browser/warning_service.h" | 50 #include "extensions/browser/warning_service.h" |
| (...skipping 28 matching lines...) Expand all Loading... | |
| 81 const char kRequiresUserGestureError[] = | 79 const char kRequiresUserGestureError[] = |
| 82 "This action requires a user gesture."; | 80 "This action requires a user gesture."; |
| 83 const char kCouldNotShowSelectFileDialogError[] = | 81 const char kCouldNotShowSelectFileDialogError[] = |
| 84 "Could not show a file chooser."; | 82 "Could not show a file chooser."; |
| 85 const char kFileSelectionCanceled[] = | 83 const char kFileSelectionCanceled[] = |
| 86 "File selection was canceled."; | 84 "File selection was canceled."; |
| 87 const char kNoSuchRendererError[] = "No such renderer."; | 85 const char kNoSuchRendererError[] = "No such renderer."; |
| 88 const char kInvalidPathError[] = "Invalid path."; | 86 const char kInvalidPathError[] = "Invalid path."; |
| 89 const char kManifestKeyIsRequiredError[] = | 87 const char kManifestKeyIsRequiredError[] = |
| 90 "The 'manifestKey' argument is required for manifest files."; | 88 "The 'manifestKey' argument is required for manifest files."; |
| 89 const char kCouldNotFindWebContentsError[] = | |
| 90 "Could not find a valid web contents."; | |
| 91 | 91 |
| 92 const char kUnpackedAppsFolder[] = "apps_target"; | 92 const char kUnpackedAppsFolder[] = "apps_target"; |
| 93 const char kManifestFile[] = "manifest.json"; | 93 const char kManifestFile[] = "manifest.json"; |
| 94 | 94 |
| 95 ExtensionService* GetExtensionService(content::BrowserContext* context) { | 95 ExtensionService* GetExtensionService(content::BrowserContext* context) { |
| 96 return ExtensionSystem::Get(context)->extension_service(); | 96 return ExtensionSystem::Get(context)->extension_service(); |
| 97 } | 97 } |
| 98 | 98 |
| 99 ExtensionUpdater* GetExtensionUpdater(Profile* profile) { | 99 ExtensionUpdater* GetExtensionUpdater(Profile* profile) { |
| 100 return GetExtensionService(profile)->updater(); | 100 return GetExtensionService(profile)->updater(); |
| (...skipping 432 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 533 // Should this take into account policy settings? | 533 // Should this take into account policy settings? |
| 534 util::SetIsIncognitoEnabled( | 534 util::SetIsIncognitoEnabled( |
| 535 extension->id(), browser_context(), params->allow); | 535 extension->id(), browser_context(), params->allow); |
| 536 | 536 |
| 537 return RespondNow(NoArguments()); | 537 return RespondNow(NoArguments()); |
| 538 } | 538 } |
| 539 | 539 |
| 540 DeveloperPrivateAllowIncognitoFunction:: | 540 DeveloperPrivateAllowIncognitoFunction:: |
| 541 ~DeveloperPrivateAllowIncognitoFunction() {} | 541 ~DeveloperPrivateAllowIncognitoFunction() {} |
| 542 | 542 |
| 543 DeveloperPrivateReloadFunction::~DeveloperPrivateReloadFunction() {} | |
| 544 | |
| 543 ExtensionFunction::ResponseAction DeveloperPrivateReloadFunction::Run() { | 545 ExtensionFunction::ResponseAction DeveloperPrivateReloadFunction::Run() { |
| 544 scoped_ptr<Reload::Params> params(Reload::Params::Create(*args_)); | 546 scoped_ptr<Reload::Params> params(Reload::Params::Create(*args_)); |
| 545 EXTENSION_FUNCTION_VALIDATE(params.get()); | 547 EXTENSION_FUNCTION_VALIDATE(params.get()); |
| 546 | 548 |
| 547 const Extension* extension = GetExtensionById(params->extension_id); | 549 const Extension* extension = GetExtensionById(params->extension_id); |
| 548 if (!extension) | 550 if (!extension) |
| 549 return RespondNow(Error(kNoSuchExtensionError)); | 551 return RespondNow(Error(kNoSuchExtensionError)); |
| 550 | 552 |
| 551 bool fail_quietly = params->options && | 553 bool fail_quietly = params->options && |
| 552 params->options->fail_quietly && | 554 params->options->fail_quietly && |
| 553 *params->options->fail_quietly; | 555 *params->options->fail_quietly; |
| 554 | 556 |
| 555 ExtensionService* service = GetExtensionService(browser_context()); | 557 ExtensionService* service = GetExtensionService(browser_context()); |
| 556 if (fail_quietly) | 558 if (fail_quietly) |
| 557 service->ReloadExtensionWithQuietFailure(params->extension_id); | 559 service->ReloadExtensionWithQuietFailure(params->extension_id); |
| 558 else | 560 else |
| 559 service->ReloadExtension(params->extension_id); | 561 service->ReloadExtension(params->extension_id); |
| 560 | 562 |
| 561 // TODO(devlin): We shouldn't return until the extension has finished trying | 563 // TODO(devlin): We shouldn't return until the extension has finished trying |
| 562 // to reload (and then we could also return the error). | 564 // to reload (and then we could also return the error). |
| 563 return RespondNow(NoArguments()); | 565 return RespondNow(NoArguments()); |
| 564 } | 566 } |
| 565 | 567 |
| 566 bool DeveloperPrivateShowPermissionsDialogFunction::RunSync() { | 568 DeveloperPrivateShowPermissionsDialogFunction:: |
| 567 EXTENSION_FUNCTION_VALIDATE(args_->GetString(0, &extension_id_)); | 569 DeveloperPrivateShowPermissionsDialogFunction() {} |
| 568 CHECK(!extension_id_.empty()); | |
| 569 AppWindowRegistry* registry = AppWindowRegistry::Get(GetProfile()); | |
| 570 DCHECK(registry); | |
| 571 AppWindow* app_window = | |
| 572 registry->GetAppWindowForRenderViewHost(render_view_host()); | |
| 573 prompt_.reset(new ExtensionInstallPrompt(app_window->web_contents())); | |
| 574 const Extension* extension = | |
| 575 ExtensionRegistry::Get(GetProfile()) | |
| 576 ->GetExtensionById(extension_id_, ExtensionRegistry::EVERYTHING); | |
| 577 | 570 |
| 578 if (!extension) | 571 DeveloperPrivateShowPermissionsDialogFunction:: |
| 579 return false; | 572 ~DeveloperPrivateShowPermissionsDialogFunction() {} |
| 580 | 573 |
| 581 // Released by InstallUIAbort or InstallUIProceed. | 574 ExtensionFunction::ResponseAction |
| 582 AddRef(); | 575 DeveloperPrivateShowPermissionsDialogFunction::Run() { |
| 583 std::vector<base::FilePath> retained_file_paths; | 576 scoped_ptr<developer::ShowPermissionsDialog::Params> params( |
| 584 if (extension->permissions_data()->HasAPIPermission( | 577 developer::ShowPermissionsDialog::Params::Create(*args_)); |
| 585 APIPermission::kFileSystem)) { | 578 EXTENSION_FUNCTION_VALIDATE(params); |
| 586 std::vector<apps::SavedFileEntry> retained_file_entries = | 579 |
| 587 apps::SavedFilesService::Get(GetProfile()) | 580 const Extension* target_extension = GetExtensionById(params->extension_id); |
| 588 ->GetAllFileEntries(extension_id_); | 581 if (!target_extension) |
| 589 for (size_t i = 0; i < retained_file_entries.size(); i++) { | 582 return RespondNow(Error(kNoSuchExtensionError)); |
| 590 retained_file_paths.push_back(retained_file_entries[i].path); | 583 |
| 591 } | 584 content::WebContents* web_contents = GetSenderWebContents(); |
| 592 } | 585 if (!web_contents) |
| 593 std::vector<base::string16> retained_device_messages; | 586 return RespondNow(Error(kCouldNotFindWebContentsError)); |
| 594 if (extension->permissions_data()->HasAPIPermission(APIPermission::kUsb)) { | 587 |
| 595 retained_device_messages = | 588 show_permissions_dialog_helper_.reset(new ShowPermissionsDialogHelper()); |
|
not at google - send to devlin
2015/03/13 23:52:31
Is this a leak?
- This class holds onto a (the) re
Devlin
2015/03/16 16:42:17
Done.
| |
| 596 extensions::DevicePermissionsManager::Get(GetProfile()) | 589 show_permissions_dialog_helper_->Show( |
| 597 ->GetPermissionMessageStrings(extension_id_); | 590 web_contents, |
| 598 } | 591 browser_context(), |
| 599 prompt_->ReviewPermissions( | 592 target_extension, |
| 600 this, extension, retained_file_paths, retained_device_messages); | 593 extension() == nullptr, // From extensions page if no calling extension. |
| 601 return true; | 594 base::Bind(&DeveloperPrivateShowPermissionsDialogFunction::Finish, this)); |
| 595 return RespondLater(); | |
| 602 } | 596 } |
| 603 | 597 |
| 604 DeveloperPrivateReloadFunction::~DeveloperPrivateReloadFunction() {} | 598 void DeveloperPrivateShowPermissionsDialogFunction::Finish() { |
| 605 | 599 Respond(NoArguments()); |
| 606 // This is called when the user clicks "Revoke File Access." | |
| 607 void DeveloperPrivateShowPermissionsDialogFunction::InstallUIProceed() { | |
| 608 Profile* profile = GetProfile(); | |
| 609 extensions::DevicePermissionsManager::Get(profile)->Clear(extension_id_); | |
| 610 const Extension* extension = ExtensionRegistry::Get( | |
| 611 profile)->GetExtensionById(extension_id_, ExtensionRegistry::EVERYTHING); | |
| 612 apps::SavedFilesService::Get(profile)->ClearQueue(extension); | |
| 613 apps::AppLoadService::Get(profile) | |
| 614 ->RestartApplicationIfRunning(extension_id_); | |
| 615 SendResponse(true); | |
| 616 Release(); | |
| 617 } | 600 } |
| 618 | 601 |
| 619 void DeveloperPrivateShowPermissionsDialogFunction::InstallUIAbort( | |
| 620 bool user_initiated) { | |
| 621 SendResponse(true); | |
| 622 Release(); | |
| 623 } | |
| 624 | |
| 625 DeveloperPrivateShowPermissionsDialogFunction:: | |
| 626 DeveloperPrivateShowPermissionsDialogFunction() {} | |
| 627 | |
| 628 DeveloperPrivateShowPermissionsDialogFunction:: | |
| 629 ~DeveloperPrivateShowPermissionsDialogFunction() {} | |
| 630 | |
| 631 ExtensionFunction::ResponseAction DeveloperPrivateInspectFunction::Run() { | 602 ExtensionFunction::ResponseAction DeveloperPrivateInspectFunction::Run() { |
| 632 scoped_ptr<developer::Inspect::Params> params( | 603 scoped_ptr<developer::Inspect::Params> params( |
| 633 developer::Inspect::Params::Create(*args_)); | 604 developer::Inspect::Params::Create(*args_)); |
| 634 EXTENSION_FUNCTION_VALIDATE(params); | 605 EXTENSION_FUNCTION_VALIDATE(params); |
| 635 const developer::InspectOptions& options = params->options; | 606 const developer::InspectOptions& options = params->options; |
| 636 | 607 |
| 637 int render_process_id = 0; | 608 int render_process_id = 0; |
| 638 if (options.render_process_id.as_string && | 609 if (options.render_process_id.as_string && |
| 639 !base::StringToInt(*options.render_process_id.as_string, | 610 !base::StringToInt(*options.render_process_id.as_string, |
| 640 &render_process_id)) { | 611 &render_process_id)) { |
| (...skipping 614 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 1255 | 1226 |
| 1256 TabStripModel* tab_strip = browser->tab_strip_model(); | 1227 TabStripModel* tab_strip = browser->tab_strip_model(); |
| 1257 tab_strip->ActivateTabAt(tab_strip->GetIndexOfWebContents(web_contents), | 1228 tab_strip->ActivateTabAt(tab_strip->GetIndexOfWebContents(web_contents), |
| 1258 false); // Not through direct user gesture. | 1229 false); // Not through direct user gesture. |
| 1259 return RespondNow(NoArguments()); | 1230 return RespondNow(NoArguments()); |
| 1260 } | 1231 } |
| 1261 | 1232 |
| 1262 } // namespace api | 1233 } // namespace api |
| 1263 | 1234 |
| 1264 } // namespace extensions | 1235 } // namespace extensions |
| OLD | NEW |