| OLD | NEW |
| (Empty) |
| 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 | |
| 3 // found in the LICENSE file. | |
| 4 | |
| 5 #include "chrome/browser/extensions/extension_install_dialog.h" | |
| 6 | |
| 7 #include "base/bind.h" | |
| 8 #include "base/command_line.h" | |
| 9 #include "base/file_path.h" | |
| 10 #include "base/memory/scoped_ptr.h" | |
| 11 #include "base/message_loop.h" | |
| 12 #include "base/values.h" | |
| 13 #include "chrome/common/chrome_switches.h" | |
| 14 #include "chrome/common/extensions/extension.h" | |
| 15 #include "chrome/common/extensions/extension_manifest_constants.h" | |
| 16 #include "ui/gfx/image/image.h" | |
| 17 | |
| 18 namespace { | |
| 19 | |
| 20 // A flag used for SetExtensionInstallDialogAutoConfirmForTests | |
| 21 enum AutoConfirmForTest { | |
| 22 DO_NOT_SKIP = 0, | |
| 23 PROCEED, | |
| 24 ABORT | |
| 25 }; | |
| 26 | |
| 27 void AutoConfirmTask(ExtensionInstallPrompt::Delegate* delegate, bool proceed) { | |
| 28 if (proceed) | |
| 29 delegate->InstallUIProceed(); | |
| 30 else | |
| 31 delegate->InstallUIAbort(true); | |
| 32 } | |
| 33 | |
| 34 void DoAutoConfirm(AutoConfirmForTest setting, | |
| 35 ExtensionInstallPrompt::Delegate* delegate) { | |
| 36 bool proceed = (setting == PROCEED); | |
| 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 | |
| 39 // pumping a few times before the user clicks accept or cancel. | |
| 40 MessageLoop::current()->PostTask( | |
| 41 FROM_HERE, | |
| 42 base::Bind(&AutoConfirmTask, delegate, proceed)); | |
| 43 } | |
| 44 | |
| 45 AutoConfirmForTest CheckAutoConfirmCommandLineSwitch() { | |
| 46 const CommandLine* cmdline = CommandLine::ForCurrentProcess(); | |
| 47 if (!cmdline->HasSwitch(switches::kAppsGalleryInstallAutoConfirmForTests)) | |
| 48 return DO_NOT_SKIP; | |
| 49 std::string value = cmdline->GetSwitchValueASCII( | |
| 50 switches::kAppsGalleryInstallAutoConfirmForTests); | |
| 51 if (value == "accept") | |
| 52 return PROCEED; | |
| 53 else if (value == "cancel") | |
| 54 return ABORT; | |
| 55 else | |
| 56 NOTREACHED(); | |
| 57 return DO_NOT_SKIP; | |
| 58 } | |
| 59 | |
| 60 } // namespace | |
| 61 | |
| 62 void ShowExtensionInstallDialog(gfx::NativeWindow parent, | |
| 63 content::PageNavigator* navigator, | |
| 64 ExtensionInstallPrompt::Delegate* delegate, | |
| 65 const ExtensionInstallPrompt::Prompt& prompt) { | |
| 66 AutoConfirmForTest auto_confirm = CheckAutoConfirmCommandLineSwitch(); | |
| 67 if (auto_confirm != DO_NOT_SKIP) { | |
| 68 DoAutoConfirm(auto_confirm, delegate); | |
| 69 return; | |
| 70 } | |
| 71 ShowExtensionInstallDialogImpl(parent, navigator, delegate, prompt); | |
| 72 } | |
| OLD | NEW |