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_prompt.h" | 5 #include "chrome/browser/extensions/extension_install_prompt.h" |
6 | 6 |
7 #include <map> | 7 #include <map> |
8 | 8 |
9 #include "base/command_line.h" | 9 #include "base/command_line.h" |
10 #include "base/message_loop/message_loop.h" | 10 #include "base/message_loop/message_loop.h" |
(...skipping 114 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
125 const gfx::ImageSkia& image = is_app ? | 125 const gfx::ImageSkia& image = is_app ? |
126 extensions::util::GetDefaultAppIcon() : | 126 extensions::util::GetDefaultAppIcon() : |
127 extensions::util::GetDefaultExtensionIcon(); | 127 extensions::util::GetDefaultExtensionIcon(); |
128 return image.GetRepresentation( | 128 return image.GetRepresentation( |
129 gfx::ImageSkia::GetMaxSupportedScale()).sk_bitmap(); | 129 gfx::ImageSkia::GetMaxSupportedScale()).sk_bitmap(); |
130 } | 130 } |
131 | 131 |
132 // If auto confirm is enabled then posts a task to proceed with or cancel the | 132 // If auto confirm is enabled then posts a task to proceed with or cancel the |
133 // install and returns true. Otherwise returns false. | 133 // install and returns true. Otherwise returns false. |
134 bool AutoConfirmPrompt(ExtensionInstallPrompt::Delegate* delegate) { | 134 bool AutoConfirmPrompt(ExtensionInstallPrompt::Delegate* delegate) { |
135 const CommandLine* cmdline = CommandLine::ForCurrentProcess(); | 135 switch (ExtensionInstallPrompt::g_auto_confirm_for_tests) { |
136 if (!cmdline->HasSwitch(switches::kAppsGalleryInstallAutoConfirmForTests)) | 136 case ExtensionInstallPrompt::NONE: |
137 return false; | 137 return false; |
138 std::string value = cmdline->GetSwitchValueASCII( | 138 // We use PostTask instead of calling the delegate directly here, because in |
139 switches::kAppsGalleryInstallAutoConfirmForTests); | 139 // the real implementations it's highly likely the message loop will be |
140 | 140 // pumping a few times before the user clicks accept or cancel. |
141 // We use PostTask instead of calling the delegate directly here, because in | 141 case ExtensionInstallPrompt::ACCEPT: |
142 // the real implementations it's highly likely the message loop will be | 142 base::MessageLoop::current()->PostTask( |
143 // pumping a few times before the user clicks accept or cancel. | 143 FROM_HERE, |
144 if (value == "accept") { | 144 base::Bind(&ExtensionInstallPrompt::Delegate::InstallUIProceed, |
145 base::MessageLoop::current()->PostTask( | 145 base::Unretained(delegate))); |
146 FROM_HERE, | 146 return true; |
147 base::Bind(&ExtensionInstallPrompt::Delegate::InstallUIProceed, | 147 case ExtensionInstallPrompt::CANCEL: |
148 base::Unretained(delegate))); | 148 base::MessageLoop::current()->PostTask( |
149 return true; | 149 FROM_HERE, |
150 } | 150 base::Bind(&ExtensionInstallPrompt::Delegate::InstallUIAbort, |
151 | 151 base::Unretained(delegate), |
152 if (value == "cancel") { | 152 true)); |
153 base::MessageLoop::current()->PostTask( | 153 return true; |
154 FROM_HERE, | |
155 base::Bind(&ExtensionInstallPrompt::Delegate::InstallUIAbort, | |
156 base::Unretained(delegate), | |
157 true)); | |
158 return true; | |
159 } | 154 } |
160 | 155 |
161 NOTREACHED(); | 156 NOTREACHED(); |
162 return false; | 157 return false; |
163 } | 158 } |
164 | 159 |
165 Profile* ProfileForWebContents(content::WebContents* web_contents) { | 160 Profile* ProfileForWebContents(content::WebContents* web_contents) { |
166 if (!web_contents) | 161 if (!web_contents) |
167 return NULL; | 162 return NULL; |
168 return Profile::FromBrowserContext(web_contents->GetBrowserContext()); | 163 return Profile::FromBrowserContext(web_contents->GetBrowserContext()); |
169 } | 164 } |
170 | 165 |
171 gfx::NativeWindow NativeWindowForWebContents(content::WebContents* contents) { | 166 gfx::NativeWindow NativeWindowForWebContents(content::WebContents* contents) { |
172 if (!contents) | 167 if (!contents) |
173 return NULL; | 168 return NULL; |
174 | 169 |
175 return contents->GetTopLevelNativeWindow(); | 170 return contents->GetTopLevelNativeWindow(); |
176 } | 171 } |
177 | 172 |
178 } // namespace | 173 } // namespace |
179 | 174 |
| 175 // static |
| 176 ExtensionInstallPrompt::AutoConfirmForTests |
| 177 ExtensionInstallPrompt::g_auto_confirm_for_tests = ExtensionInstallPrompt::NONE; |
| 178 |
180 ExtensionInstallPrompt::Prompt::Prompt(PromptType type) | 179 ExtensionInstallPrompt::Prompt::Prompt(PromptType type) |
181 : type_(type), | 180 : type_(type), |
182 is_showing_details_for_retained_files_(false), | 181 is_showing_details_for_retained_files_(false), |
183 extension_(NULL), | 182 extension_(NULL), |
184 bundle_(NULL), | 183 bundle_(NULL), |
185 average_rating_(0.0), | 184 average_rating_(0.0), |
186 rating_count_(0), | 185 rating_count_(0), |
187 show_user_count_(false), | 186 show_user_count_(false), |
188 has_webstore_data_(false) { | 187 has_webstore_data_(false) { |
189 } | 188 } |
(...skipping 563 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
753 } | 752 } |
754 | 753 |
755 if (AutoConfirmPrompt(delegate_)) | 754 if (AutoConfirmPrompt(delegate_)) |
756 return; | 755 return; |
757 | 756 |
758 if (show_dialog_callback_.is_null()) | 757 if (show_dialog_callback_.is_null()) |
759 GetDefaultShowDialogCallback().Run(show_params_, delegate_, prompt_); | 758 GetDefaultShowDialogCallback().Run(show_params_, delegate_, prompt_); |
760 else | 759 else |
761 show_dialog_callback_.Run(show_params_, delegate_, prompt_); | 760 show_dialog_callback_.Run(show_params_, delegate_, prompt_); |
762 } | 761 } |
OLD | NEW |