| 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::g_auto_confirm_install_for_testing) { |
| 158 case ExtensionInstallPrompt::NONE: | 159 case extensions::AUTO_CONFIRM_NONE: |
| 159 return false; | 160 return false; |
| 160 // We use PostTask instead of calling the delegate directly here, because in | 161 // 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 | 162 // the real implementations it's highly likely the message loop will be |
| 162 // pumping a few times before the user clicks accept or cancel. | 163 // pumping a few times before the user clicks accept or cancel. |
| 163 case ExtensionInstallPrompt::ACCEPT: | 164 case extensions::AUTO_CONFIRM_ACCEPT: |
| 164 base::MessageLoop::current()->PostTask( | 165 base::MessageLoop::current()->PostTask( |
| 165 FROM_HERE, | 166 FROM_HERE, |
| 166 base::Bind(&ExtensionInstallPrompt::Delegate::InstallUIProceed, | 167 base::Bind(&ExtensionInstallPrompt::Delegate::InstallUIProceed, |
| 167 base::Unretained(delegate))); | 168 base::Unretained(delegate))); |
| 168 return true; | 169 return true; |
| 169 case ExtensionInstallPrompt::CANCEL: | 170 case extensions::AUTO_CONFIRM_CANCEL: |
| 170 base::MessageLoop::current()->PostTask( | 171 base::MessageLoop::current()->PostTask( |
| 171 FROM_HERE, | 172 FROM_HERE, |
| 172 base::Bind(&ExtensionInstallPrompt::Delegate::InstallUIAbort, | 173 base::Bind(&ExtensionInstallPrompt::Delegate::InstallUIAbort, |
| 173 base::Unretained(delegate), | 174 base::Unretained(delegate), |
| 174 true)); | 175 true)); |
| 175 return true; | 176 return true; |
| 176 } | 177 } |
| 177 | 178 |
| 178 NOTREACHED(); | 179 NOTREACHED(); |
| 179 return false; | 180 return false; |
| 180 } | 181 } |
| 181 | 182 |
| 182 Profile* ProfileForWebContents(content::WebContents* web_contents) { | 183 Profile* ProfileForWebContents(content::WebContents* web_contents) { |
| 183 if (!web_contents) | 184 if (!web_contents) |
| 184 return NULL; | 185 return NULL; |
| 185 return Profile::FromBrowserContext(web_contents->GetBrowserContext()); | 186 return Profile::FromBrowserContext(web_contents->GetBrowserContext()); |
| 186 } | 187 } |
| 187 | 188 |
| 188 } // namespace | 189 } // namespace |
| 189 | 190 |
| 190 ExtensionInstallPrompt::Prompt::InstallPromptPermissions:: | 191 ExtensionInstallPrompt::Prompt::InstallPromptPermissions:: |
| 191 InstallPromptPermissions() { | 192 InstallPromptPermissions() { |
| 192 } | 193 } |
| 193 ExtensionInstallPrompt::Prompt::InstallPromptPermissions:: | 194 ExtensionInstallPrompt::Prompt::InstallPromptPermissions:: |
| 194 ~InstallPromptPermissions() { | 195 ~InstallPromptPermissions() { |
| 195 } | 196 } |
| 196 | 197 |
| 197 // static | |
| 198 ExtensionInstallPrompt::AutoConfirmForTests | |
| 199 ExtensionInstallPrompt::g_auto_confirm_for_tests = ExtensionInstallPrompt::NONE; | |
| 200 | |
| 201 ExtensionInstallPrompt::PromptType | 198 ExtensionInstallPrompt::PromptType |
| 202 ExtensionInstallPrompt::g_last_prompt_type_for_tests = | 199 ExtensionInstallPrompt::g_last_prompt_type_for_tests = |
| 203 ExtensionInstallPrompt::UNSET_PROMPT_TYPE; | 200 ExtensionInstallPrompt::UNSET_PROMPT_TYPE; |
| 204 | 201 |
| 205 // This should match the PromptType enum. | 202 // This should match the PromptType enum. |
| 206 std::string ExtensionInstallPrompt::PromptTypeToString(PromptType type) { | 203 std::string ExtensionInstallPrompt::PromptTypeToString(PromptType type) { |
| 207 switch (type) { | 204 switch (type) { |
| 208 case ExtensionInstallPrompt::INSTALL_PROMPT: | 205 case ExtensionInstallPrompt::INSTALL_PROMPT: |
| 209 return "INSTALL_PROMPT"; | 206 return "INSTALL_PROMPT"; |
| 210 case ExtensionInstallPrompt::INLINE_INSTALL_PROMPT: | 207 case ExtensionInstallPrompt::INLINE_INSTALL_PROMPT: |
| (...skipping 739 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 950 if (show_params_->WasParentDestroyed()) { | 947 if (show_params_->WasParentDestroyed()) { |
| 951 delegate_->InstallUIAbort(false); | 948 delegate_->InstallUIAbort(false); |
| 952 return; | 949 return; |
| 953 } | 950 } |
| 954 | 951 |
| 955 if (show_dialog_callback_.is_null()) | 952 if (show_dialog_callback_.is_null()) |
| 956 GetDefaultShowDialogCallback().Run(show_params_.get(), delegate_, prompt_); | 953 GetDefaultShowDialogCallback().Run(show_params_.get(), delegate_, prompt_); |
| 957 else | 954 else |
| 958 show_dialog_callback_.Run(show_params_.get(), delegate_, prompt_); | 955 show_dialog_callback_.Run(show_params_.get(), delegate_, prompt_); |
| 959 } | 956 } |
| OLD | NEW |