diff options
author | treib <treib@chromium.org> | 2015-08-04 09:36:48 -0700 |
---|---|---|
committer | Commit bot <commit-bot@chromium.org> | 2015-08-04 16:38:16 +0000 |
commit | 8d2de4875667830bd0d90a06b2596f4b0540c451 (patch) | |
tree | 29a276546e26178c7c7d0517382a8b50cba6ccf0 /chrome/common/extensions/permissions | |
parent | 8d8fbb032ad403df38514aa4353e7482e0152a8d (diff) | |
download | chromium_src-8d2de4875667830bd0d90a06b2596f4b0540c451.zip chromium_src-8d2de4875667830bd0d90a06b2596f4b0540c451.tar.gz chromium_src-8d2de4875667830bd0d90a06b2596f4b0540c451.tar.bz2 |
Extensions: Remove the intermediate PermissionMessageStrings interface
Switch all callers over to the new system (CoalescedPermissionMessages).
Also rename GetCoalescedPermissionMessages to GetPermissionMessages - it's the only way to get permission messages now.
[This is part 2 of operation "remove the old permission message system".]
TBRing trivial changes in ephemeral_app_launcher.cc and extension_install_dialog_view_browsertest.cc.
TBR=benwells@chromium.org
BUG=398257
Review URL: https://codereview.chromium.org/1218373003
Cr-Commit-Position: refs/heads/master@{#341734}
Diffstat (limited to 'chrome/common/extensions/permissions')
6 files changed, 88 insertions, 70 deletions
diff --git a/chrome/common/extensions/permissions/chrome_permission_message_provider.cc b/chrome/common/extensions/permissions/chrome_permission_message_provider.cc index 4b8fceb8..21aeb1f 100644 --- a/chrome/common/extensions/permissions/chrome_permission_message_provider.cc +++ b/chrome/common/extensions/permissions/chrome_permission_message_provider.cc @@ -32,7 +32,7 @@ ChromePermissionMessageProvider::~ChromePermissionMessageProvider() { } CoalescedPermissionMessages -ChromePermissionMessageProvider::GetCoalescedPermissionMessages( +ChromePermissionMessageProvider::GetPermissionMessages( const PermissionIDSet& permissions) const { std::vector<ChromePermissionMessageRule> rules = ChromePermissionMessageRule::GetAllRules(); @@ -50,8 +50,7 @@ ChromePermissionMessageProvider::GetCoalescedPermissionMessages( PermissionIDSet used_permissions = remaining_permissions.GetAllPermissionsWithIDs( rule.all_permissions()); - messages.push_back( - rule.formatter()->GetPermissionMessage(used_permissions)); + messages.push_back(rule.GetPermissionMessage(used_permissions)); remaining_permissions = PermissionIDSet::Difference(remaining_permissions, used_permissions); diff --git a/chrome/common/extensions/permissions/chrome_permission_message_provider.h b/chrome/common/extensions/permissions/chrome_permission_message_provider.h index 1208b5e..e2b1661 100644 --- a/chrome/common/extensions/permissions/chrome_permission_message_provider.h +++ b/chrome/common/extensions/permissions/chrome_permission_message_provider.h @@ -26,7 +26,7 @@ class ChromePermissionMessageProvider : public PermissionMessageProvider { ~ChromePermissionMessageProvider() override; // PermissionMessageProvider implementation. - CoalescedPermissionMessages GetCoalescedPermissionMessages( + CoalescedPermissionMessages GetPermissionMessages( const PermissionIDSet& permissions) const override; bool IsPrivilegeIncrease(const PermissionSet* old_permissions, const PermissionSet* new_permissions, diff --git a/chrome/common/extensions/permissions/chrome_permission_message_provider_unittest.cc b/chrome/common/extensions/permissions/chrome_permission_message_provider_unittest.cc index eca1705..37e4be9 100644 --- a/chrome/common/extensions/permissions/chrome_permission_message_provider_unittest.cc +++ b/chrome/common/extensions/permissions/chrome_permission_message_provider_unittest.cc @@ -32,12 +32,12 @@ class ChromePermissionMessageProviderUnittest : public testing::Test { ~ChromePermissionMessageProviderUnittest() override {} protected: - PermissionMessageStrings GetMessages(const APIPermissionSet& permissions, - Manifest::Type type) { + CoalescedPermissionMessages GetMessages(const APIPermissionSet& permissions, + Manifest::Type type) { scoped_refptr<const PermissionSet> permission_set = new PermissionSet( permissions, ManifestPermissionSet(), URLPatternSet(), URLPatternSet()); - return message_provider_->GetPermissionMessageStrings(permission_set.get(), - type); + return message_provider_->GetPermissionMessages( + message_provider_->GetAllPermissionIDs(permission_set.get(), type)); } private: @@ -50,32 +50,36 @@ class ChromePermissionMessageProviderUnittest : public testing::Test { // superset permission message is displayed if they are both present. TEST_F(ChromePermissionMessageProviderUnittest, SupersetOverridesSubsetPermission) { - APIPermissionSet permissions; - PermissionMessageStrings messages; - - permissions.clear(); - permissions.insert(APIPermission::kTab); - messages = GetMessages(permissions, Manifest::TYPE_PLATFORM_APP); - ASSERT_EQ(1U, messages.size()); - EXPECT_EQ( - l10n_util::GetStringUTF16(IDS_EXTENSION_PROMPT_WARNING_HISTORY_READ), - messages[0].message); - - permissions.clear(); - permissions.insert(APIPermission::kTopSites); - messages = GetMessages(permissions, Manifest::TYPE_PLATFORM_APP); - ASSERT_EQ(1U, messages.size()); - EXPECT_EQ(l10n_util::GetStringUTF16(IDS_EXTENSION_PROMPT_WARNING_TOPSITES), - messages[0].message); - - permissions.clear(); - permissions.insert(APIPermission::kTab); - permissions.insert(APIPermission::kTopSites); - messages = GetMessages(permissions, Manifest::TYPE_PLATFORM_APP); - ASSERT_EQ(1U, messages.size()); - EXPECT_EQ( - l10n_util::GetStringUTF16(IDS_EXTENSION_PROMPT_WARNING_HISTORY_READ), - messages[0].message); + { + APIPermissionSet permissions; + permissions.insert(APIPermission::kTab); + CoalescedPermissionMessages messages = + GetMessages(permissions, Manifest::TYPE_PLATFORM_APP); + ASSERT_EQ(1U, messages.size()); + EXPECT_EQ( + l10n_util::GetStringUTF16(IDS_EXTENSION_PROMPT_WARNING_HISTORY_READ), + messages.front().message()); + } + { + APIPermissionSet permissions; + permissions.insert(APIPermission::kTopSites); + CoalescedPermissionMessages messages = + GetMessages(permissions, Manifest::TYPE_PLATFORM_APP); + ASSERT_EQ(1U, messages.size()); + EXPECT_EQ(l10n_util::GetStringUTF16(IDS_EXTENSION_PROMPT_WARNING_TOPSITES), + messages.front().message()); + } + { + APIPermissionSet permissions; + permissions.insert(APIPermission::kTab); + permissions.insert(APIPermission::kTopSites); + CoalescedPermissionMessages messages = + GetMessages(permissions, Manifest::TYPE_PLATFORM_APP); + ASSERT_EQ(1U, messages.size()); + EXPECT_EQ( + l10n_util::GetStringUTF16(IDS_EXTENSION_PROMPT_WARNING_HISTORY_READ), + messages.front().message()); + } } // Checks that when permissions are merged into a single message, their details @@ -97,18 +101,21 @@ TEST_F(ChromePermissionMessageProviderUnittest, ASSERT_TRUE(usb->FromValue(devices_list.get(), nullptr, nullptr)); permissions.insert(usb.release()); - PermissionMessageStrings messages = + CoalescedPermissionMessages messages = GetMessages(permissions, Manifest::TYPE_EXTENSION); ASSERT_EQ(2U, messages.size()); + auto it = messages.begin(); + const CoalescedPermissionMessage& message0 = *it++; EXPECT_EQ( l10n_util::GetStringUTF16(IDS_EXTENSION_PROMPT_WARNING_USB_DEVICE_LIST), - messages[0].message); - EXPECT_FALSE(messages[0].submessages.empty()); + message0.message()); + EXPECT_FALSE(message0.submessages().empty()); + const CoalescedPermissionMessage& message1 = *it++; EXPECT_EQ( l10n_util::GetStringUTF16(IDS_EXTENSION_PROMPT_WARNING_HISTORY_READ), - messages[1].message); - EXPECT_TRUE(messages[1].submessages.empty()); + message1.message()); + EXPECT_TRUE(message1.submessages().empty()); } } // namespace extensions diff --git a/chrome/common/extensions/permissions/chrome_permission_message_rules.cc b/chrome/common/extensions/permissions/chrome_permission_message_rules.cc index 1083cff2..41215d6 100644 --- a/chrome/common/extensions/permissions/chrome_permission_message_rules.cc +++ b/chrome/common/extensions/permissions/chrome_permission_message_rules.cc @@ -27,7 +27,7 @@ class DefaultPermissionMessageFormatter ~DefaultPermissionMessageFormatter() override {} CoalescedPermissionMessage GetPermissionMessage( - PermissionIDSet permissions) const override { + const PermissionIDSet& permissions) const override { return CoalescedPermissionMessage(l10n_util::GetStringUTF16(message_id_), permissions); } @@ -35,7 +35,7 @@ class DefaultPermissionMessageFormatter private: int message_id_; - // DISALLOW_COPY_AND_ASSIGN(DefaultPermissionMessageFormatter); + DISALLOW_COPY_AND_ASSIGN(DefaultPermissionMessageFormatter); }; // A formatter that substitutes the parameter into the message using string @@ -47,7 +47,7 @@ class SingleParameterFormatter : public ChromePermissionMessageFormatter { ~SingleParameterFormatter() override {} CoalescedPermissionMessage GetPermissionMessage( - PermissionIDSet permissions) const override { + const PermissionIDSet& permissions) const override { DCHECK(permissions.size() > 0); std::vector<base::string16> parameters = permissions.GetAllPermissionParameters(); @@ -59,6 +59,8 @@ class SingleParameterFormatter : public ChromePermissionMessageFormatter { private: int message_id_; + + DISALLOW_COPY_AND_ASSIGN(SingleParameterFormatter); }; // Adds each parameter to a growing list, with the given |root_message_id| as @@ -70,7 +72,7 @@ class SimpleListFormatter : public ChromePermissionMessageFormatter { ~SimpleListFormatter() override {} CoalescedPermissionMessage GetPermissionMessage( - PermissionIDSet permissions) const override { + const PermissionIDSet& permissions) const override { DCHECK(permissions.size() > 0); return CoalescedPermissionMessage( l10n_util::GetStringUTF16(root_message_id_), permissions, @@ -79,6 +81,8 @@ class SimpleListFormatter : public ChromePermissionMessageFormatter { private: int root_message_id_; + + DISALLOW_COPY_AND_ASSIGN(SimpleListFormatter); }; // Creates a space-separated list of permissions with the given PermissionID. @@ -95,7 +99,7 @@ class SpaceSeparatedListFormatter : public ChromePermissionMessageFormatter { ~SpaceSeparatedListFormatter() override {} CoalescedPermissionMessage GetPermissionMessage( - PermissionIDSet permissions) const override { + const PermissionIDSet& permissions) const override { DCHECK(permissions.size() > 0); std::vector<base::string16> hostnames = permissions.GetAllPermissionParameters(); @@ -112,6 +116,8 @@ class SpaceSeparatedListFormatter : public ChromePermissionMessageFormatter { private: int message_id_for_one_host_; int message_id_for_multiple_hosts_; + + DISALLOW_COPY_AND_ASSIGN(SpaceSeparatedListFormatter); }; // Creates a comma-separated list of permissions with the given PermissionID. @@ -133,7 +139,7 @@ class CommaSeparatedListFormatter : public ChromePermissionMessageFormatter { ~CommaSeparatedListFormatter() override {} CoalescedPermissionMessage GetPermissionMessage( - PermissionIDSet permissions) const override { + const PermissionIDSet& permissions) const override { DCHECK(permissions.size() > 0); std::vector<base::string16> hostnames = permissions.GetAllPermissionParameters(); @@ -168,6 +174,8 @@ class CommaSeparatedListFormatter : public ChromePermissionMessageFormatter { int message_id_for_two_hosts_; int message_id_for_three_hosts_; int message_id_for_many_hosts_; + + DISALLOW_COPY_AND_ASSIGN(CommaSeparatedListFormatter); }; } // namespace @@ -201,10 +209,6 @@ std::set<APIPermission::ID> ChromePermissionMessageRule::optional_permissions() const { return optional_permissions_; } -ChromePermissionMessageFormatter* ChromePermissionMessageRule::formatter() - const { - return formatter_.get(); -} std::set<APIPermission::ID> ChromePermissionMessageRule::all_permissions() const { @@ -212,6 +216,11 @@ std::set<APIPermission::ID> ChromePermissionMessageRule::all_permissions() optional_permissions()); } +CoalescedPermissionMessage ChromePermissionMessageRule::GetPermissionMessage( + const PermissionIDSet& permissions) const { + return formatter_->GetPermissionMessage(permissions); +} + // static std::vector<ChromePermissionMessageRule> ChromePermissionMessageRule::GetAllRules() { @@ -609,11 +618,8 @@ ChromePermissionMessageRule::GetAllRules() { {IDS_EXTENSION_PROMPT_WARNING_FAVICON, {APIPermission::kFavicon}, {}}, }; - std::vector<ChromePermissionMessageRule> rules; - for (size_t i = 0; i < arraysize(rules_arr); i++) { - rules.push_back(rules_arr[i]); - } - return rules; + return std::vector<ChromePermissionMessageRule>( + rules_arr, rules_arr + arraysize(rules_arr)); } ChromePermissionMessageRule::PermissionIDSetInitializer:: diff --git a/chrome/common/extensions/permissions/chrome_permission_message_rules.h b/chrome/common/extensions/permissions/chrome_permission_message_rules.h index 689acd8..534322a 100644 --- a/chrome/common/extensions/permissions/chrome_permission_message_rules.h +++ b/chrome/common/extensions/permissions/chrome_permission_message_rules.h @@ -31,10 +31,10 @@ class ChromePermissionMessageFormatter { // |permissions| is guaranteed to have the IDs specified by the // required/optional permissions for the rule. The set will never be empty. virtual CoalescedPermissionMessage GetPermissionMessage( - PermissionIDSet permissions) const = 0; + const PermissionIDSet& permissions) const = 0; private: - // DISALLOW_COPY_AND_ASSIGN(ChromePermissionMessageFormatter); + DISALLOW_COPY_AND_ASSIGN(ChromePermissionMessageFormatter); }; // A simple rule to generate a coalesced permission message that stores the @@ -100,7 +100,9 @@ class ChromePermissionMessageRule { std::set<APIPermission::ID> required_permissions() const; std::set<APIPermission::ID> optional_permissions() const; std::set<APIPermission::ID> all_permissions() const; - ChromePermissionMessageFormatter* formatter() const; + + CoalescedPermissionMessage GetPermissionMessage( + const PermissionIDSet& permissions) const; private: std::set<APIPermission::ID> required_permissions_; diff --git a/chrome/common/extensions/permissions/permission_set_unittest.cc b/chrome/common/extensions/permissions/permission_set_unittest.cc index c7ee9d1..75002cb 100644 --- a/chrome/common/extensions/permissions/permission_set_unittest.cc +++ b/chrome/common/extensions/permissions/permission_set_unittest.cc @@ -41,11 +41,13 @@ static void AddPattern(URLPatternSet* extent, const std::string& pattern) { extent->AddPattern(URLPattern(schemes, pattern)); } -size_t IndexOf(const PermissionMessageStrings& warnings, +size_t IndexOf(const CoalescedPermissionMessages& warnings, const std::string& warning) { - for (size_t i = 0; i < warnings.size(); ++i) { - if (warnings[i].message == base::ASCIIToUTF16(warning)) + size_t i = 0; + for (const CoalescedPermissionMessage& msg : warnings) { + if (msg.message() == base::ASCIIToUTF16(warning)) return i; + ++i; } return warnings.size(); @@ -89,7 +91,7 @@ testing::AssertionResult PermissionSetProducesMessage( const PermissionIDSet& expected_ids) { const PermissionMessageProvider* provider = PermissionMessageProvider::Get(); - CoalescedPermissionMessages msgs = provider->GetCoalescedPermissionMessages( + CoalescedPermissionMessages msgs = provider->GetPermissionMessages( provider->GetAllPermissionIDs(permissions, extension_type)); if (msgs.size() != 1) { return testing::AssertionFailure() @@ -1133,8 +1135,8 @@ TEST(PermissionsTest, GetWarningMessages_AudioVideo) { EXPECT_FALSE(VerifyHasPermissionMessage(set, extension->GetType(), kAudio)); EXPECT_FALSE(VerifyHasPermissionMessage(set, extension->GetType(), kVideo)); EXPECT_TRUE(VerifyHasPermissionMessage(set, extension->GetType(), kBoth)); - PermissionMessageStrings warnings = - provider->GetPermissionMessageStrings(set, extension->GetType()); + CoalescedPermissionMessages warnings = provider->GetPermissionMessages( + provider->GetAllPermissionIDs(set, extension->GetType())); size_t combined_index = IndexOf(warnings, kBoth); size_t combined_size = warnings.size(); @@ -1143,9 +1145,10 @@ TEST(PermissionsTest, GetWarningMessages_AudioVideo) { EXPECT_TRUE(VerifyHasPermissionMessage(set, extension->GetType(), kAudio)); EXPECT_FALSE(VerifyHasPermissionMessage(set, extension->GetType(), kVideo)); EXPECT_FALSE(VerifyHasPermissionMessage(set, extension->GetType(), kBoth)); - warnings = provider->GetPermissionMessageStrings(set, extension->GetType()); - EXPECT_EQ(combined_size, warnings.size()); - EXPECT_EQ(combined_index, IndexOf(warnings, kAudio)); + CoalescedPermissionMessages warnings2 = provider->GetPermissionMessages( + provider->GetAllPermissionIDs(set, extension->GetType())); + EXPECT_EQ(combined_size, warnings2.size()); + EXPECT_EQ(combined_index, IndexOf(warnings2, kAudio)); // Just video present. set->apis_.erase(APIPermission::kAudioCapture); @@ -1153,9 +1156,10 @@ TEST(PermissionsTest, GetWarningMessages_AudioVideo) { EXPECT_FALSE(VerifyHasPermissionMessage(set, extension->GetType(), kAudio)); EXPECT_TRUE(VerifyHasPermissionMessage(set, extension->GetType(), kVideo)); EXPECT_FALSE(VerifyHasPermissionMessage(set, extension->GetType(), kBoth)); - warnings = provider->GetPermissionMessageStrings(set, extension->GetType()); - EXPECT_EQ(combined_size, warnings.size()); - EXPECT_EQ(combined_index, IndexOf(warnings, kVideo)); + CoalescedPermissionMessages warnings3 = provider->GetPermissionMessages( + provider->GetAllPermissionIDs(set, extension->GetType())); + EXPECT_EQ(combined_size, warnings3.size()); + EXPECT_EQ(combined_index, IndexOf(warnings3, kVideo)); } TEST(PermissionsTest, GetWarningMessages_CombinedSessions) { @@ -1761,7 +1765,7 @@ TEST(PermissionsTest, ChromeURLs) { scoped_refptr<PermissionSet> permissions( new PermissionSet(APIPermissionSet(), ManifestPermissionSet(), allowed_hosts, URLPatternSet())); - PermissionMessageProvider::Get()->GetCoalescedPermissionMessages( + PermissionMessageProvider::Get()->GetPermissionMessages( PermissionMessageProvider::Get()->GetAllPermissionIDs( permissions.get(), Manifest::TYPE_EXTENSION)); } |