| 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/memory/scoped_ptr.h" | 10 #include "base/memory/scoped_ptr.h" |
| 11 #include "base/message_loop.h" | 11 #include "base/message_loop.h" |
| 12 #include "base/values.h" | 12 #include "base/values.h" |
| 13 #include "chrome/common/chrome_switches.h" | 13 #include "chrome/common/chrome_switches.h" |
| 14 #include "chrome/common/extensions/extension.h" | 14 #include "chrome/common/extensions/extension.h" |
| 15 #include "chrome/common/extensions/extension_manifest_constants.h" | 15 #include "chrome/common/extensions/extension_manifest_constants.h" |
| 16 #include "ui/gfx/image/image.h" | 16 #include "ui/gfx/image/image.h" |
| 17 | 17 |
| 18 namespace { | 18 namespace { |
| 19 | 19 |
| 20 // A flag used for SetExtensionInstallDialogAutoConfirmForTests | 20 // A flag used for SetExtensionInstallDialogAutoConfirmForTests |
| 21 enum AutoConfirmForTest { | 21 enum AutoConfirmForTest { |
| 22 DO_NOT_SKIP = 0, | 22 DO_NOT_SKIP = 0, |
| 23 PROCEED, | 23 PROCEED, |
| 24 ABORT | 24 ABORT |
| 25 }; | 25 }; |
| 26 | 26 |
| 27 void AutoConfirmTask(ExtensionInstallUI::Delegate* delegate, bool proceed) { | 27 void AutoConfirmTask(ExtensionInstallPrompt::Delegate* delegate, bool proceed) { |
| 28 if (proceed) | 28 if (proceed) |
| 29 delegate->InstallUIProceed(); | 29 delegate->InstallUIProceed(); |
| 30 else | 30 else |
| 31 delegate->InstallUIAbort(true); | 31 delegate->InstallUIAbort(true); |
| 32 } | 32 } |
| 33 | 33 |
| 34 void DoAutoConfirm(AutoConfirmForTest setting, | 34 void DoAutoConfirm(AutoConfirmForTest setting, |
| 35 ExtensionInstallUI::Delegate* delegate) { | 35 ExtensionInstallPrompt::Delegate* delegate) { |
| 36 bool proceed = (setting == PROCEED); | 36 bool proceed = (setting == PROCEED); |
| 37 // We use PostTask instead of calling the delegate directly here, because in | 37 // We use PostTask instead of calling the delegate directly here, because in |
| 38 // the real implementations it's highly likely the message loop will be | 38 // the real implementations it's highly likely the message loop will be |
| 39 // pumping a few times before the user clicks accept or cancel. | 39 // pumping a few times before the user clicks accept or cancel. |
| 40 MessageLoop::current()->PostTask( | 40 MessageLoop::current()->PostTask( |
| 41 FROM_HERE, | 41 FROM_HERE, |
| 42 base::Bind(&AutoConfirmTask, delegate, proceed)); | 42 base::Bind(&AutoConfirmTask, delegate, proceed)); |
| 43 } | 43 } |
| 44 | 44 |
| 45 AutoConfirmForTest CheckAutoConfirmCommandLineSwitch() { | 45 AutoConfirmForTest CheckAutoConfirmCommandLineSwitch() { |
| 46 const CommandLine* cmdline = CommandLine::ForCurrentProcess(); | 46 const CommandLine* cmdline = CommandLine::ForCurrentProcess(); |
| 47 if (!cmdline->HasSwitch(switches::kAppsGalleryInstallAutoConfirmForTests)) | 47 if (!cmdline->HasSwitch(switches::kAppsGalleryInstallAutoConfirmForTests)) |
| 48 return DO_NOT_SKIP; | 48 return DO_NOT_SKIP; |
| 49 std::string value = cmdline->GetSwitchValueASCII( | 49 std::string value = cmdline->GetSwitchValueASCII( |
| 50 switches::kAppsGalleryInstallAutoConfirmForTests); | 50 switches::kAppsGalleryInstallAutoConfirmForTests); |
| 51 if (value == "accept") | 51 if (value == "accept") |
| 52 return PROCEED; | 52 return PROCEED; |
| 53 else if (value == "cancel") | 53 else if (value == "cancel") |
| 54 return ABORT; | 54 return ABORT; |
| 55 else | 55 else |
| 56 NOTREACHED(); | 56 NOTREACHED(); |
| 57 return DO_NOT_SKIP; | 57 return DO_NOT_SKIP; |
| 58 } | 58 } |
| 59 | 59 |
| 60 } // namespace | 60 } // namespace |
| 61 | 61 |
| 62 void ShowExtensionInstallDialog(Profile* profile, | 62 void ShowExtensionInstallDialog(Profile* profile, |
| 63 ExtensionInstallUI::Delegate* delegate, | 63 ExtensionInstallPrompt::Delegate* delegate, |
| 64 const ExtensionInstallUI::Prompt& prompt) { | 64 const ExtensionInstallPrompt::Prompt& prompt) { |
| 65 AutoConfirmForTest auto_confirm = CheckAutoConfirmCommandLineSwitch(); | 65 AutoConfirmForTest auto_confirm = CheckAutoConfirmCommandLineSwitch(); |
| 66 if (auto_confirm != DO_NOT_SKIP) { | 66 if (auto_confirm != DO_NOT_SKIP) { |
| 67 DoAutoConfirm(auto_confirm, delegate); | 67 DoAutoConfirm(auto_confirm, delegate); |
| 68 return; | 68 return; |
| 69 } | 69 } |
| 70 ShowExtensionInstallDialogImpl(profile, delegate, prompt); | 70 ShowExtensionInstallDialogImpl(profile, delegate, prompt); |
| 71 } | 71 } |
| OLD | NEW |