1 // Copyright 2013 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file.
5 #include "extensions/common/permissions/permission_message_provider.h"
7 #include "base/metrics/field_trial.h"
8 #include "base/strings/string_split.h"
9 #include "extensions/common/extensions_client.h"
11 namespace extensions
{
15 ForceForTesting g_force_permission_system_for_testing
=
16 ForceForTesting::DONT_FORCE
;
18 bool IsNewPermissionMessageSystemEnabled() {
19 if (g_force_permission_system_for_testing
!= ForceForTesting::DONT_FORCE
)
20 return g_force_permission_system_for_testing
== ForceForTesting::FORCE_NEW
;
21 const std::string group_name
=
22 base::FieldTrialList::FindFullName("PermissionMessageSystem");
23 return group_name
== "NewSystem";
28 void ForcePermissionMessageSystemForTesting(
29 ForceForTesting force
) {
30 g_force_permission_system_for_testing
= force
;
33 PermissionMessageString::PermissionMessageString(
34 const CoalescedPermissionMessage
& message
)
35 : message(message
.message()), submessages(message
.submessages()) {
38 PermissionMessageString::PermissionMessageString(const base::string16
& message
)
42 PermissionMessageString::PermissionMessageString(
43 const base::string16
& message
,
44 const std::vector
<base::string16
>& submessages
)
45 : message(message
), submessages(submessages
) {
48 PermissionMessageString::PermissionMessageString(const base::string16
& message
,
49 const base::string16
& details
)
51 base::SplitString(details
, base::char16('\n'), &submessages
);
54 PermissionMessageString::~PermissionMessageString() {
58 const PermissionMessageProvider
* PermissionMessageProvider::Get() {
59 return &(ExtensionsClient::Get()->GetPermissionMessageProvider());
62 PermissionMessageStrings
63 PermissionMessageProvider::GetPermissionMessageStrings(
64 const PermissionSet
* permissions
,
65 Manifest::Type extension_type
) const {
66 PermissionMessageStrings strings
;
67 if (IsNewPermissionMessageSystemEnabled()) {
68 CoalescedPermissionMessages messages
= GetCoalescedPermissionMessages(
69 GetAllPermissionIDs(permissions
, extension_type
));
70 for (const CoalescedPermissionMessage
& msg
: messages
)
71 strings
.push_back(PermissionMessageString(msg
));
73 std::vector
<base::string16
> messages
=
74 GetLegacyWarningMessages(permissions
, extension_type
);
75 std::vector
<base::string16
> details
=
76 GetLegacyWarningMessagesDetails(permissions
, extension_type
);
77 DCHECK_EQ(messages
.size(), details
.size());
78 for (size_t i
= 0; i
< messages
.size(); i
++)
79 strings
.push_back(PermissionMessageString(messages
[i
], details
[i
]));
84 } // namespace extensions