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