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 19 matching lines...) Expand all Loading... |
30 #include "extensions/browser/install/extension_install_ui.h" | 30 #include "extensions/browser/install/extension_install_ui.h" |
31 #include "extensions/common/constants.h" | 31 #include "extensions/common/constants.h" |
32 #include "extensions/common/extension.h" | 32 #include "extensions/common/extension.h" |
33 #include "extensions/common/extension_icon_set.h" | 33 #include "extensions/common/extension_icon_set.h" |
34 #include "extensions/common/extension_resource.h" | 34 #include "extensions/common/extension_resource.h" |
35 #include "extensions/common/feature_switch.h" | 35 #include "extensions/common/feature_switch.h" |
36 #include "extensions/common/manifest.h" | 36 #include "extensions/common/manifest.h" |
37 #include "extensions/common/manifest_constants.h" | 37 #include "extensions/common/manifest_constants.h" |
38 #include "extensions/common/manifest_handlers/icons_handler.h" | 38 #include "extensions/common/manifest_handlers/icons_handler.h" |
39 #include "extensions/common/manifest_handlers/permissions_parser.h" | 39 #include "extensions/common/manifest_handlers/permissions_parser.h" |
40 #include "extensions/common/permissions/permission_message_provider.h" | |
41 #include "extensions/common/permissions/permission_set.h" | 40 #include "extensions/common/permissions/permission_set.h" |
42 #include "extensions/common/permissions/permissions_data.h" | 41 #include "extensions/common/permissions/permissions_data.h" |
43 #include "extensions/common/url_pattern.h" | 42 #include "extensions/common/url_pattern.h" |
44 #include "grit/theme_resources.h" | 43 #include "grit/theme_resources.h" |
45 #include "ui/base/l10n/l10n_util.h" | 44 #include "ui/base/l10n/l10n_util.h" |
46 #include "ui/base/resource/resource_bundle.h" | 45 #include "ui/base/resource/resource_bundle.h" |
47 #include "ui/base/ui_base_types.h" | 46 #include "ui/base/ui_base_types.h" |
48 #include "ui/gfx/image/image.h" | 47 #include "ui/gfx/image/image.h" |
49 | 48 |
50 using extensions::BundleInstaller; | 49 using extensions::BundleInstaller; |
51 using extensions::Extension; | 50 using extensions::Extension; |
52 using extensions::Manifest; | 51 using extensions::Manifest; |
| 52 using extensions::PermissionMessageString; |
| 53 using extensions::PermissionMessageStrings; |
53 using extensions::PermissionSet; | 54 using extensions::PermissionSet; |
54 | 55 |
55 namespace { | 56 namespace { |
56 | 57 |
57 bool AllowWebstoreData(ExtensionInstallPrompt::PromptType type) { | 58 bool AllowWebstoreData(ExtensionInstallPrompt::PromptType type) { |
58 return type == ExtensionInstallPrompt::INLINE_INSTALL_PROMPT || | 59 return type == ExtensionInstallPrompt::INLINE_INSTALL_PROMPT || |
59 type == ExtensionInstallPrompt::EXTERNAL_INSTALL_PROMPT || | 60 type == ExtensionInstallPrompt::EXTERNAL_INSTALL_PROMPT || |
60 type == ExtensionInstallPrompt::REPAIR_PROMPT; | 61 type == ExtensionInstallPrompt::REPAIR_PROMPT; |
61 } | 62 } |
62 | 63 |
(...skipping 179 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
242 average_rating_(0.0), | 243 average_rating_(0.0), |
243 rating_count_(0), | 244 rating_count_(0), |
244 show_user_count_(false), | 245 show_user_count_(false), |
245 has_webstore_data_(false) { | 246 has_webstore_data_(false) { |
246 } | 247 } |
247 | 248 |
248 ExtensionInstallPrompt::Prompt::~Prompt() { | 249 ExtensionInstallPrompt::Prompt::~Prompt() { |
249 } | 250 } |
250 | 251 |
251 void ExtensionInstallPrompt::Prompt::SetPermissions( | 252 void ExtensionInstallPrompt::Prompt::SetPermissions( |
252 const std::vector<base::string16>& permissions, | 253 const PermissionMessageStrings& permissions, |
253 PermissionsType permissions_type) { | |
254 GetPermissionsForType(permissions_type).permissions = permissions; | |
255 } | |
256 | |
257 void ExtensionInstallPrompt::Prompt::SetPermissionsDetails( | |
258 const std::vector<base::string16>& details, | |
259 PermissionsType permissions_type) { | 254 PermissionsType permissions_type) { |
260 InstallPromptPermissions& install_permissions = | 255 InstallPromptPermissions& install_permissions = |
261 GetPermissionsForType(permissions_type); | 256 GetPermissionsForType(permissions_type); |
262 | 257 |
263 // Add a dash to the front of each permission detail. | 258 install_permissions.permissions.clear(); |
264 for (const auto& details_entry : details) { | 259 install_permissions.details.clear(); |
265 if (!details_entry.empty()) { | 260 install_permissions.is_showing_details.clear(); |
266 std::vector<base::string16> detail_lines; | |
267 base::SplitString(details_entry, base::char16('\n'), &detail_lines); | |
268 | 261 |
| 262 for (const PermissionMessageString& str : permissions) { |
| 263 install_permissions.permissions.push_back(str.message); |
| 264 // Add a dash to the front of each permission detail. |
| 265 base::string16 details; |
| 266 if (!str.submessages.empty()) { |
269 std::vector<base::string16> detail_lines_with_bullets; | 267 std::vector<base::string16> detail_lines_with_bullets; |
270 for (const auto& detail_line : detail_lines) | 268 for (const auto& detail_line : str.submessages) { |
271 detail_lines_with_bullets.push_back(base::ASCIIToUTF16("- ") + | 269 detail_lines_with_bullets.push_back(base::ASCIIToUTF16("- ") + |
272 detail_line); | 270 detail_line); |
| 271 } |
273 | 272 |
274 install_permissions.details.push_back( | 273 details = JoinString(detail_lines_with_bullets, '\n'); |
275 JoinString(detail_lines_with_bullets, '\n')); | |
276 } else { | |
277 install_permissions.details.push_back(details_entry); | |
278 } | 274 } |
| 275 install_permissions.details.push_back(details); |
| 276 install_permissions.is_showing_details.push_back(false); |
279 } | 277 } |
280 | |
281 install_permissions.is_showing_details.clear(); | |
282 install_permissions.is_showing_details.insert( | |
283 install_permissions.is_showing_details.begin(), details.size(), false); | |
284 } | 278 } |
285 | 279 |
286 void ExtensionInstallPrompt::Prompt::SetIsShowingDetails( | 280 void ExtensionInstallPrompt::Prompt::SetIsShowingDetails( |
287 DetailsType type, | 281 DetailsType type, |
288 size_t index, | 282 size_t index, |
289 bool is_showing_details) { | 283 bool is_showing_details) { |
290 switch (type) { | 284 switch (type) { |
291 case PERMISSIONS_DETAILS: | 285 case PERMISSIONS_DETAILS: |
292 prompt_permissions_.is_showing_details[index] = is_showing_details; | 286 prompt_permissions_.is_showing_details[index] = is_showing_details; |
293 break; | 287 break; |
(...skipping 627 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
921 } | 915 } |
922 | 916 |
923 if (permissions_to_display.get() && | 917 if (permissions_to_display.get() && |
924 (!extension_ || | 918 (!extension_ || |
925 !extensions::PermissionsData::ShouldSkipPermissionWarnings( | 919 !extensions::PermissionsData::ShouldSkipPermissionWarnings( |
926 extension_->id()))) { | 920 extension_->id()))) { |
927 Manifest::Type type = | 921 Manifest::Type type = |
928 extension_ ? extension_->GetType() : Manifest::TYPE_UNKNOWN; | 922 extension_ ? extension_->GetType() : Manifest::TYPE_UNKNOWN; |
929 const extensions::PermissionMessageProvider* message_provider = | 923 const extensions::PermissionMessageProvider* message_provider = |
930 extensions::PermissionMessageProvider::Get(); | 924 extensions::PermissionMessageProvider::Get(); |
931 prompt_->SetPermissions(message_provider->GetLegacyWarningMessages( | 925 |
| 926 prompt_->SetPermissions(message_provider->GetPermissionMessageStrings( |
932 permissions_to_display.get(), type), | 927 permissions_to_display.get(), type), |
933 REGULAR_PERMISSIONS); | 928 REGULAR_PERMISSIONS); |
934 prompt_->SetPermissionsDetails( | |
935 message_provider->GetLegacyWarningMessagesDetails( | |
936 permissions_to_display.get(), type), | |
937 REGULAR_PERMISSIONS); | |
938 | 929 |
939 scoped_refptr<const extensions::PermissionSet> withheld = | 930 scoped_refptr<const extensions::PermissionSet> withheld = |
940 extension_->permissions_data()->withheld_permissions(); | 931 extension_->permissions_data()->withheld_permissions(); |
941 if (!withheld->IsEmpty()) { | 932 if (!withheld->IsEmpty()) { |
942 prompt_->SetPermissions( | 933 prompt_->SetPermissions( |
943 message_provider->GetLegacyWarningMessages(withheld.get(), type), | 934 message_provider->GetPermissionMessageStrings(withheld.get(), type), |
944 PermissionsType::WITHHELD_PERMISSIONS); | |
945 prompt_->SetPermissionsDetails( | |
946 message_provider->GetLegacyWarningMessagesDetails(withheld.get(), | |
947 type), | |
948 PermissionsType::WITHHELD_PERMISSIONS); | 935 PermissionsType::WITHHELD_PERMISSIONS); |
949 } | 936 } |
950 } | 937 } |
951 | 938 |
952 switch (prompt_->type()) { | 939 switch (prompt_->type()) { |
953 case PERMISSIONS_PROMPT: | 940 case PERMISSIONS_PROMPT: |
954 case RE_ENABLE_PROMPT: | 941 case RE_ENABLE_PROMPT: |
955 case INLINE_INSTALL_PROMPT: | 942 case INLINE_INSTALL_PROMPT: |
956 case EXTERNAL_INSTALL_PROMPT: | 943 case EXTERNAL_INSTALL_PROMPT: |
957 case INSTALL_PROMPT: | 944 case INSTALL_PROMPT: |
(...skipping 24 matching lines...) Expand all Loading... |
982 if (show_params_->WasParentDestroyed()) { | 969 if (show_params_->WasParentDestroyed()) { |
983 delegate_->InstallUIAbort(false); | 970 delegate_->InstallUIAbort(false); |
984 return; | 971 return; |
985 } | 972 } |
986 | 973 |
987 if (show_dialog_callback_.is_null()) | 974 if (show_dialog_callback_.is_null()) |
988 GetDefaultShowDialogCallback().Run(show_params_.get(), delegate_, prompt_); | 975 GetDefaultShowDialogCallback().Run(show_params_.get(), delegate_, prompt_); |
989 else | 976 else |
990 show_dialog_callback_.Run(show_params_.get(), delegate_, prompt_); | 977 show_dialog_callback_.Run(show_params_.get(), delegate_, prompt_); |
991 } | 978 } |
OLD | NEW |