Commit 490598e1 authored by mohammed@chromium.org's avatar mohammed@chromium.org

Cleaned up the code for suppressed messages

Permissions warning messages are suprressed around the code which make it hard to know which supress what. Put them in one DS the suppression is done in a single loop. This help visualize which suppress what and a neater place to add ones later.

BUG=384487
R=kalman, meacer

Review URL: https://codereview.chromium.org/404803004

git-svn-id: svn://svn.chromium.org/chrome/trunk/src@284771 0039d316-1c4b-4281-b951-d872f2087c98
parent e1d74ae7
......@@ -80,6 +80,33 @@ ChromePermissionMessageProvider::~ChromePermissionMessageProvider() {
PermissionMessages ChromePermissionMessageProvider::GetPermissionMessages(
const PermissionSet* permissions,
Manifest::Type extension_type) const {
// Some warnings are more generic and/or powerful and superseed other
// warnings. In that case, the first message suppresses the second one.
std::multimap<PermissionMessage::ID, PermissionMessage::ID> kSuppressList;
kSuppressList.insert(
{PermissionMessage::kBluetooth, PermissionMessage::kBluetoothDevices});
kSuppressList.insert(
{PermissionMessage::kBookmarks, PermissionMessage::kOverrideBookmarksUI});
// History already allows reading favicons.
kSuppressList.insert(
{PermissionMessage::kBrowsingHistory, PermissionMessage::kFavicon});
// History already allows tabs access.
kSuppressList.insert(
{PermissionMessage::kBrowsingHistory, PermissionMessage::kTabs});
// A special hack: If kFileSystemWriteDirectory would be displayed, hide
// kFileSystemDirectory as the write directory message implies it.
// TODO(sammc): Remove this. See http://crbug.com/284849.
kSuppressList.insert({PermissionMessage::kFileSystemWriteDirectory,
PermissionMessage::kFileSystemDirectory});
// Full access already allows DeclarativeWebRequest.
kSuppressList.insert({PermissionMessage::kHostsAll,
PermissionMessage::kDeclarativeWebRequest});
// Full access already covers tabs access.
kSuppressList.insert(
{PermissionMessage::kHostsAll, PermissionMessage::kTabs});
// Tabs already allows reading favicons.
kSuppressList.insert({PermissionMessage::kTabs, PermissionMessage::kFavicon});
PermissionMessages messages;
if (permissions->HasEffectiveFullAccess()) {
......@@ -99,32 +126,13 @@ PermissionMessages ChromePermissionMessageProvider::GetPermissionMessages(
messages.insert(messages.end(), manifest_permission_msgs.begin(),
manifest_permission_msgs.end());
// Some warnings are more generic and/or powerful and superseed other
// warnings. In that case, suppress the superseeded warning.
SuppressMessage(messages,
PermissionMessage::kBookmarks,
PermissionMessage::kOverrideBookmarksUI);
// Both tabs and history already allow reading favicons.
SuppressMessage(messages,
PermissionMessage::kTabs,
PermissionMessage::kFavicon);
SuppressMessage(messages,
PermissionMessage::kBrowsingHistory,
PermissionMessage::kFavicon);
// Warning for history permission already covers warning for tabs permission.
SuppressMessage(messages,
PermissionMessage::kBrowsingHistory,
PermissionMessage::kTabs);
// Warning for full access permission already covers warning for tabs
// permission.
SuppressMessage(messages,
PermissionMessage::kHostsAll,
PermissionMessage::kTabs);
// Warning for full access already covers warning for DeclarativeWebRequest
// permission.
SuppressMessage(messages,
PermissionMessage::kHostsAll,
PermissionMessage::kDeclarativeWebRequest);
for (std::multimap<PermissionMessage::ID,
PermissionMessage::ID>::const_iterator it =
kSuppressList.begin();
it != kSuppressList.end();
++it) {
SuppressMessage(messages, it->first, it->second);
}
return messages;
}
......@@ -136,10 +144,6 @@ std::vector<base::string16> ChromePermissionMessageProvider::GetWarningMessages(
PermissionMessages messages =
GetPermissionMessages(permissions, extension_type);
SuppressMessage(messages,
PermissionMessage::kBluetooth,
PermissionMessage::kBluetoothDevices);
for (PermissionMessages::const_iterator i = messages.begin();
i != messages.end(); ++i) {
int id = i->id();
......@@ -316,12 +320,6 @@ ChromePermissionMessageProvider::GetAPIPermissionMessages(
}
}
// A special hack: If kFileSystemWriteDirectory would be displayed, hide
// kFileSystemDirectory as the write directory message implies it.
// TODO(sammc): Remove this. See http://crbug.com/284849.
SuppressMessage(messages,
PermissionMessage::kFileSystemWriteDirectory,
PermissionMessage::kFileSystemDirectory);
// A special hack: The warning message for declarativeWebRequest
// permissions speaks about blocking parts of pages, which is a
// subset of what the "<all_urls>" access allows. Therefore we
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment