| 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/extension_install_dialog.h" | 5 #include "chrome/browser/extensions/extension_install_dialog.h" |
| 6 | 6 |
| 7 #include "base/bind.h" | 7 #include "base/bind.h" |
| 8 #include "base/command_line.h" | 8 #include "base/command_line.h" |
| 9 #include "base/file_path.h" | 9 #include "base/file_path.h" |
| 10 #include "base/message_loop.h" | 10 #include "base/message_loop.h" |
| (...skipping 35 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 46 AutoConfirmForTest CheckAutoConfirmCommandLineSwitch() { | 46 AutoConfirmForTest CheckAutoConfirmCommandLineSwitch() { |
| 47 const CommandLine* cmdline = CommandLine::ForCurrentProcess(); | 47 const CommandLine* cmdline = CommandLine::ForCurrentProcess(); |
| 48 if (!cmdline->HasSwitch(switches::kAppsGalleryInstallAutoConfirmForTests)) | 48 if (!cmdline->HasSwitch(switches::kAppsGalleryInstallAutoConfirmForTests)) |
| 49 return DO_NOT_SKIP; | 49 return DO_NOT_SKIP; |
| 50 std::string value = cmdline->GetSwitchValueASCII( | 50 std::string value = cmdline->GetSwitchValueASCII( |
| 51 switches::kAppsGalleryInstallAutoConfirmForTests); | 51 switches::kAppsGalleryInstallAutoConfirmForTests); |
| 52 if (value == "accept") | 52 if (value == "accept") |
| 53 return PROCEED; | 53 return PROCEED; |
| 54 else if (value == "cancel") | 54 else if (value == "cancel") |
| 55 return ABORT; | 55 return ABORT; |
| 56 else if (value == "default") |
| 57 return DO_NOT_SKIP; |
| 56 else | 58 else |
| 57 NOTREACHED(); | 59 NOTREACHED(); |
| 58 return DO_NOT_SKIP; | 60 return DO_NOT_SKIP; |
| 59 } | 61 } |
| 60 | 62 |
| 61 } // namespace | 63 } // namespace |
| 62 | 64 |
| 63 void ShowExtensionInstallDialog(Profile* profile, | 65 void ShowExtensionInstallDialog(Profile* profile, |
| 64 ExtensionInstallUI::Delegate* delegate, | 66 ExtensionInstallUI::Delegate* delegate, |
| 65 const ExtensionInstallUI::Prompt& prompt) { | 67 const ExtensionInstallUI::Prompt& prompt) { |
| 66 AutoConfirmForTest auto_confirm = CheckAutoConfirmCommandLineSwitch(); | 68 AutoConfirmForTest auto_confirm = CheckAutoConfirmCommandLineSwitch(); |
| 67 if (auto_confirm != DO_NOT_SKIP) { | 69 if (auto_confirm != DO_NOT_SKIP) { |
| 68 DoAutoConfirm(auto_confirm, delegate); | 70 DoAutoConfirm(auto_confirm, delegate); |
| 69 return; | 71 return; |
| 70 } | 72 } |
| 71 ShowExtensionInstallDialogImpl(profile, delegate, prompt); | 73 ShowExtensionInstallDialogImpl(profile, delegate, prompt); |
| 72 } | 74 } |
| 73 | |
| 74 bool ShowExtensionInstallDialogForManifest( | |
| 75 Profile* profile, | |
| 76 ExtensionInstallUI::Delegate* delegate, | |
| 77 const DictionaryValue* manifest, | |
| 78 const std::string& id, | |
| 79 const std::string& localized_name, | |
| 80 const std::string& localized_description, | |
| 81 SkBitmap* icon, | |
| 82 const ExtensionInstallUI::Prompt& prompt, | |
| 83 scoped_refptr<Extension>* dummy_extension) { | |
| 84 scoped_ptr<DictionaryValue> localized_manifest; | |
| 85 if (!localized_name.empty() || !localized_description.empty()) { | |
| 86 localized_manifest.reset(manifest->DeepCopy()); | |
| 87 if (!localized_name.empty()) { | |
| 88 localized_manifest->SetString(extension_manifest_keys::kName, | |
| 89 localized_name); | |
| 90 } | |
| 91 if (!localized_description.empty()) { | |
| 92 localized_manifest->SetString(extension_manifest_keys::kDescription, | |
| 93 localized_description); | |
| 94 } | |
| 95 } | |
| 96 | |
| 97 std::string init_errors; | |
| 98 *dummy_extension = Extension::Create( | |
| 99 FilePath(), | |
| 100 Extension::INTERNAL, | |
| 101 localized_manifest.get() ? *localized_manifest.get() : *manifest, | |
| 102 Extension::NO_FLAGS, | |
| 103 id, | |
| 104 &init_errors); | |
| 105 if (!dummy_extension->get()) { | |
| 106 return false; | |
| 107 } | |
| 108 | |
| 109 if (icon->empty()) | |
| 110 icon = const_cast<SkBitmap*>(&Extension::GetDefaultIcon( | |
| 111 (*dummy_extension)->is_app())); | |
| 112 | |
| 113 // In tests, we may have setup to proceed or abort without putting up the real | |
| 114 // confirmation dialog. | |
| 115 AutoConfirmForTest auto_confirm = CheckAutoConfirmCommandLineSwitch(); | |
| 116 if (auto_confirm != DO_NOT_SKIP) { | |
| 117 DoAutoConfirm(auto_confirm, delegate); | |
| 118 return true; | |
| 119 } | |
| 120 | |
| 121 ExtensionInstallUI::Prompt filled_out_prompt = prompt; | |
| 122 filled_out_prompt.SetPermissions( | |
| 123 (*dummy_extension)->GetPermissionMessageStrings()); | |
| 124 filled_out_prompt.set_extension(*dummy_extension); | |
| 125 filled_out_prompt.set_icon(gfx::Image(new SkBitmap(*icon))); | |
| 126 | |
| 127 ShowExtensionInstallDialog(profile, delegate, filled_out_prompt); | |
| 128 return true; | |
| 129 } | |
| OLD | NEW |