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" |
11 #include "base/prefs/pref_service.h" | 11 #include "base/prefs/pref_service.h" |
12 #include "base/strings/string_number_conversions.h" | 12 #include "base/strings/string_number_conversions.h" |
13 #include "base/strings/string_split.h" | 13 #include "base/strings/string_split.h" |
14 #include "base/strings/string_util.h" | 14 #include "base/strings/string_util.h" |
15 #include "base/strings/stringprintf.h" | 15 #include "base/strings/stringprintf.h" |
16 #include "base/strings/utf_string_conversions.h" | 16 #include "base/strings/utf_string_conversions.h" |
17 #include "chrome/browser/extensions/bundle_installer.h" | 17 #include "chrome/browser/extensions/bundle_installer.h" |
18 #include "chrome/browser/extensions/extension_install_prompt_show_params.h" | 18 #include "chrome/browser/extensions/extension_install_prompt_show_params.h" |
19 #include "chrome/browser/extensions/extension_util.h" | 19 #include "chrome/browser/extensions/extension_util.h" |
20 #include "chrome/browser/extensions/permissions_updater.h" | 20 #include "chrome/browser/extensions/permissions_updater.h" |
21 #include "chrome/browser/profiles/profile.h" | 21 #include "chrome/browser/profiles/profile.h" |
22 #include "chrome/browser/ui/extensions/extension_install_ui_factory.h" | 22 #include "chrome/browser/ui/extensions/extension_install_ui_factory.h" |
23 #include "chrome/common/chrome_switches.h" | 23 #include "chrome/common/chrome_switches.h" |
24 #include "chrome/grit/chromium_strings.h" | 24 #include "chrome/grit/chromium_strings.h" |
25 #include "chrome/grit/generated_resources.h" | 25 #include "chrome/grit/generated_resources.h" |
26 #include "content/public/browser/web_contents.h" | 26 #include "content/public/browser/web_contents.h" |
| 27 #include "extensions/browser/extension_dialog_auto_confirm.h" |
27 #include "extensions/browser/extension_prefs.h" | 28 #include "extensions/browser/extension_prefs.h" |
28 #include "extensions/browser/extension_util.h" | 29 #include "extensions/browser/extension_util.h" |
29 #include "extensions/browser/image_loader.h" | 30 #include "extensions/browser/image_loader.h" |
30 #include "extensions/browser/install/extension_install_ui.h" | 31 #include "extensions/browser/install/extension_install_ui.h" |
31 #include "extensions/common/constants.h" | 32 #include "extensions/common/constants.h" |
32 #include "extensions/common/extension.h" | 33 #include "extensions/common/extension.h" |
33 #include "extensions/common/extension_icon_set.h" | 34 #include "extensions/common/extension_icon_set.h" |
34 #include "extensions/common/extension_resource.h" | 35 #include "extensions/common/extension_resource.h" |
35 #include "extensions/common/feature_switch.h" | 36 #include "extensions/common/feature_switch.h" |
36 #include "extensions/common/manifest.h" | 37 #include "extensions/common/manifest.h" |
(...skipping 110 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
147 const gfx::ImageSkia& image = is_app ? | 148 const gfx::ImageSkia& image = is_app ? |
148 extensions::util::GetDefaultAppIcon() : | 149 extensions::util::GetDefaultAppIcon() : |
149 extensions::util::GetDefaultExtensionIcon(); | 150 extensions::util::GetDefaultExtensionIcon(); |
150 return image.GetRepresentation( | 151 return image.GetRepresentation( |
151 gfx::ImageSkia::GetMaxSupportedScale()).sk_bitmap(); | 152 gfx::ImageSkia::GetMaxSupportedScale()).sk_bitmap(); |
152 } | 153 } |
153 | 154 |
154 // If auto confirm is enabled then posts a task to proceed with or cancel the | 155 // If auto confirm is enabled then posts a task to proceed with or cancel the |
155 // install and returns true. Otherwise returns false. | 156 // install and returns true. Otherwise returns false. |
156 bool AutoConfirmPrompt(ExtensionInstallPrompt::Delegate* delegate) { | 157 bool AutoConfirmPrompt(ExtensionInstallPrompt::Delegate* delegate) { |
157 switch (ExtensionInstallPrompt::g_auto_confirm_for_tests) { | 158 switch (extensions::ScopedTestDialogAutoConfirm::GetAutoConfirmValue()) { |
158 case ExtensionInstallPrompt::NONE: | 159 case extensions::ScopedTestDialogAutoConfirm::NONE: |
| 160 LOG(WARNING) << "None!"; |
159 return false; | 161 return false; |
160 // We use PostTask instead of calling the delegate directly here, because in | 162 // We use PostTask instead of calling the delegate directly here, because in |
161 // the real implementations it's highly likely the message loop will be | 163 // the real implementations it's highly likely the message loop will be |
162 // pumping a few times before the user clicks accept or cancel. | 164 // pumping a few times before the user clicks accept or cancel. |
163 case ExtensionInstallPrompt::ACCEPT: | 165 case extensions::ScopedTestDialogAutoConfirm::ACCEPT: |
| 166 LOG(WARNING) << "Proceeding!"; |
164 base::MessageLoop::current()->PostTask( | 167 base::MessageLoop::current()->PostTask( |
165 FROM_HERE, | 168 FROM_HERE, |
166 base::Bind(&ExtensionInstallPrompt::Delegate::InstallUIProceed, | 169 base::Bind(&ExtensionInstallPrompt::Delegate::InstallUIProceed, |
167 base::Unretained(delegate))); | 170 base::Unretained(delegate))); |
168 return true; | 171 return true; |
169 case ExtensionInstallPrompt::CANCEL: | 172 case extensions::ScopedTestDialogAutoConfirm::CANCEL: |
| 173 LOG(WARNING) << "Canceling!"; |
170 base::MessageLoop::current()->PostTask( | 174 base::MessageLoop::current()->PostTask( |
171 FROM_HERE, | 175 FROM_HERE, |
172 base::Bind(&ExtensionInstallPrompt::Delegate::InstallUIAbort, | 176 base::Bind(&ExtensionInstallPrompt::Delegate::InstallUIAbort, |
173 base::Unretained(delegate), | 177 base::Unretained(delegate), |
174 true)); | 178 true)); |
175 return true; | 179 return true; |
176 } | 180 } |
177 | 181 |
178 NOTREACHED(); | 182 NOTREACHED(); |
179 return false; | 183 return false; |
180 } | 184 } |
181 | 185 |
182 Profile* ProfileForWebContents(content::WebContents* web_contents) { | 186 Profile* ProfileForWebContents(content::WebContents* web_contents) { |
183 if (!web_contents) | 187 if (!web_contents) |
184 return NULL; | 188 return NULL; |
185 return Profile::FromBrowserContext(web_contents->GetBrowserContext()); | 189 return Profile::FromBrowserContext(web_contents->GetBrowserContext()); |
186 } | 190 } |
187 | 191 |
188 } // namespace | 192 } // namespace |
189 | 193 |
190 ExtensionInstallPrompt::Prompt::InstallPromptPermissions:: | 194 ExtensionInstallPrompt::Prompt::InstallPromptPermissions:: |
191 InstallPromptPermissions() { | 195 InstallPromptPermissions() { |
192 } | 196 } |
193 ExtensionInstallPrompt::Prompt::InstallPromptPermissions:: | 197 ExtensionInstallPrompt::Prompt::InstallPromptPermissions:: |
194 ~InstallPromptPermissions() { | 198 ~InstallPromptPermissions() { |
195 } | 199 } |
196 | 200 |
197 // static | |
198 ExtensionInstallPrompt::AutoConfirmForTests | |
199 ExtensionInstallPrompt::g_auto_confirm_for_tests = ExtensionInstallPrompt::NONE; | |
200 | |
201 ExtensionInstallPrompt::PromptType | 201 ExtensionInstallPrompt::PromptType |
202 ExtensionInstallPrompt::g_last_prompt_type_for_tests = | 202 ExtensionInstallPrompt::g_last_prompt_type_for_tests = |
203 ExtensionInstallPrompt::UNSET_PROMPT_TYPE; | 203 ExtensionInstallPrompt::UNSET_PROMPT_TYPE; |
204 | 204 |
205 // This should match the PromptType enum. | 205 // This should match the PromptType enum. |
206 std::string ExtensionInstallPrompt::PromptTypeToString(PromptType type) { | 206 std::string ExtensionInstallPrompt::PromptTypeToString(PromptType type) { |
207 switch (type) { | 207 switch (type) { |
208 case ExtensionInstallPrompt::INSTALL_PROMPT: | 208 case ExtensionInstallPrompt::INSTALL_PROMPT: |
209 return "INSTALL_PROMPT"; | 209 return "INSTALL_PROMPT"; |
210 case ExtensionInstallPrompt::INLINE_INSTALL_PROMPT: | 210 case ExtensionInstallPrompt::INLINE_INSTALL_PROMPT: |
(...skipping 739 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
950 if (show_params_->WasParentDestroyed()) { | 950 if (show_params_->WasParentDestroyed()) { |
951 delegate_->InstallUIAbort(false); | 951 delegate_->InstallUIAbort(false); |
952 return; | 952 return; |
953 } | 953 } |
954 | 954 |
955 if (show_dialog_callback_.is_null()) | 955 if (show_dialog_callback_.is_null()) |
956 GetDefaultShowDialogCallback().Run(show_params_.get(), delegate_, prompt_); | 956 GetDefaultShowDialogCallback().Run(show_params_.get(), delegate_, prompt_); |
957 else | 957 else |
958 show_dialog_callback_.Run(show_params_.get(), delegate_, prompt_); | 958 show_dialog_callback_.Run(show_params_.get(), delegate_, prompt_); |
959 } | 959 } |
OLD | NEW |