Chromium Code Reviews| OLD | NEW |
|---|---|
| 1 // Copyright 2013 The Chromium Authors. All rights reserved. | 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 | 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/common/extensions/permissions/chrome_permission_message_provide r.h" | 5 #include "chrome/common/extensions/permissions/chrome_permission_message_provide r.h" |
| 6 | 6 |
| 7 #include "base/stl_util.h" | 7 #include "base/stl_util.h" |
| 8 #include "base/strings/stringprintf.h" | 8 #include "base/strings/stringprintf.h" |
| 9 #include "extensions/common/extensions_client.h" | 9 #include "extensions/common/extensions_client.h" |
| 10 #include "extensions/common/permissions/permission_message.h" | 10 #include "extensions/common/permissions/permission_message.h" |
| (...skipping 62 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 73 | 73 |
| 74 ChromePermissionMessageProvider::ChromePermissionMessageProvider() { | 74 ChromePermissionMessageProvider::ChromePermissionMessageProvider() { |
| 75 } | 75 } |
| 76 | 76 |
| 77 ChromePermissionMessageProvider::~ChromePermissionMessageProvider() { | 77 ChromePermissionMessageProvider::~ChromePermissionMessageProvider() { |
| 78 } | 78 } |
| 79 | 79 |
| 80 PermissionMessages ChromePermissionMessageProvider::GetPermissionMessages( | 80 PermissionMessages ChromePermissionMessageProvider::GetPermissionMessages( |
| 81 const PermissionSet* permissions, | 81 const PermissionSet* permissions, |
| 82 Manifest::Type extension_type) const { | 82 Manifest::Type extension_type) const { |
| 83 // Some warnings are more generic and/or powerful and superseed other | |
| 84 // warnings. In that case, the first message suppresses the second one. | |
| 85 const std::multimap<PermissionMessage::ID, | |
| 86 PermissionMessage::ID> kSuppressList = { | |
| 87 {PermissionMessage::kBluetooth, PermissionMessage::kBluetoothDevices}, | |
| 88 {PermissionMessage::kBookmarks, PermissionMessage::kOverrideBookmarksUI}, | |
| 89 // History already allows reading favicons. | |
| 90 {PermissionMessage::kBrowsingHistory, PermissionMessage::kFavicon}, | |
| 91 // History already allows tabs access. | |
| 92 {PermissionMessage::kBrowsingHistory, PermissionMessage::kTabs}, | |
| 93 // A special hack: If kFileSystemWriteDirectory would be displayed, hide | |
| 94 // kFileSystemDirectory as the write directory message implies it. | |
| 95 // TODO(sammc): Remove this. See http://crbug.com/284849. | |
|
meacer
2014/07/18 22:19:49
Would it make sense to make this comment similar t
mhm
2014/07/18 22:40:41
I am not sure what is needed for that bug.
| |
| 96 {PermissionMessage::kFileSystemWriteDirectory, | |
| 97 PermissionMessage::kFileSystemDirectory}, | |
| 98 // Full access already allows DeclarativeWebRequest. | |
| 99 {PermissionMessage::kHostsAll, PermissionMessage::kDeclarativeWebRequest}, | |
| 100 // Full access already covers tabs access. | |
| 101 {PermissionMessage::kHostsAll, PermissionMessage::kTabs}, | |
| 102 // Tabs already allows reading favicons. | |
| 103 {PermissionMessage::kTabs, PermissionMessage::kFavicon}}; | |
| 104 | |
| 83 PermissionMessages messages; | 105 PermissionMessages messages; |
| 84 | 106 |
| 85 if (permissions->HasEffectiveFullAccess()) { | 107 if (permissions->HasEffectiveFullAccess()) { |
| 86 messages.push_back(PermissionMessage( | 108 messages.push_back(PermissionMessage( |
| 87 PermissionMessage::kFullAccess, | 109 PermissionMessage::kFullAccess, |
| 88 l10n_util::GetStringUTF16(IDS_EXTENSION_PROMPT_WARNING_FULL_ACCESS))); | 110 l10n_util::GetStringUTF16(IDS_EXTENSION_PROMPT_WARNING_FULL_ACCESS))); |
| 89 return messages; | 111 return messages; |
| 90 } | 112 } |
| 91 | 113 |
| 92 PermissionMsgSet host_msgs = | 114 PermissionMsgSet host_msgs = |
| 93 GetHostPermissionMessages(permissions, extension_type); | 115 GetHostPermissionMessages(permissions, extension_type); |
| 94 PermissionMsgSet api_msgs = GetAPIPermissionMessages(permissions); | 116 PermissionMsgSet api_msgs = GetAPIPermissionMessages(permissions); |
| 95 PermissionMsgSet manifest_permission_msgs = | 117 PermissionMsgSet manifest_permission_msgs = |
| 96 GetManifestPermissionMessages(permissions); | 118 GetManifestPermissionMessages(permissions); |
| 97 messages.insert(messages.end(), host_msgs.begin(), host_msgs.end()); | 119 messages.insert(messages.end(), host_msgs.begin(), host_msgs.end()); |
| 98 messages.insert(messages.end(), api_msgs.begin(), api_msgs.end()); | 120 messages.insert(messages.end(), api_msgs.begin(), api_msgs.end()); |
| 99 messages.insert(messages.end(), manifest_permission_msgs.begin(), | 121 messages.insert(messages.end(), manifest_permission_msgs.begin(), |
| 100 manifest_permission_msgs.end()); | 122 manifest_permission_msgs.end()); |
| 101 | 123 |
| 102 // Some warnings are more generic and/or powerful and superseed other | 124 for (std::multimap<PermissionMessage::ID, |
| 103 // warnings. In that case, suppress the superseeded warning. | 125 PermissionMessage::ID>::const_iterator it = |
| 104 SuppressMessage(messages, | 126 kSuppressList.begin(); |
| 105 PermissionMessage::kBookmarks, | 127 it != kSuppressList.end(); |
| 106 PermissionMessage::kOverrideBookmarksUI); | 128 it++) { |
|
meacer
2014/07/18 22:19:49
nit: ++it instead of it++
mhm
2014/07/18 22:40:41
Done.
| |
| 107 // Both tabs and history already allow reading favicons. | 129 SuppressMessage(messages, it->first, it->second); |
| 108 SuppressMessage(messages, | 130 } |
| 109 PermissionMessage::kTabs, | |
| 110 PermissionMessage::kFavicon); | |
| 111 SuppressMessage(messages, | |
| 112 PermissionMessage::kBrowsingHistory, | |
| 113 PermissionMessage::kFavicon); | |
| 114 // Warning for history permission already covers warning for tabs permission. | |
| 115 SuppressMessage(messages, | |
| 116 PermissionMessage::kBrowsingHistory, | |
| 117 PermissionMessage::kTabs); | |
| 118 // Warning for full access permission already covers warning for tabs | |
| 119 // permission. | |
| 120 SuppressMessage(messages, | |
| 121 PermissionMessage::kHostsAll, | |
| 122 PermissionMessage::kTabs); | |
| 123 // Warning for full access already covers warning for DeclarativeWebRequest | |
| 124 // permission. | |
| 125 SuppressMessage(messages, | |
| 126 PermissionMessage::kHostsAll, | |
| 127 PermissionMessage::kDeclarativeWebRequest); | |
| 128 | 131 |
| 129 return messages; | 132 return messages; |
| 130 } | 133 } |
| 131 | 134 |
| 132 std::vector<base::string16> ChromePermissionMessageProvider::GetWarningMessages( | 135 std::vector<base::string16> ChromePermissionMessageProvider::GetWarningMessages( |
| 133 const PermissionSet* permissions, | 136 const PermissionSet* permissions, |
| 134 Manifest::Type extension_type) const { | 137 Manifest::Type extension_type) const { |
| 135 std::vector<base::string16> message_strings; | 138 std::vector<base::string16> message_strings; |
| 136 PermissionMessages messages = | 139 PermissionMessages messages = |
| 137 GetPermissionMessages(permissions, extension_type); | 140 GetPermissionMessages(permissions, extension_type); |
| 138 | 141 |
| 139 SuppressMessage(messages, | |
| 140 PermissionMessage::kBluetooth, | |
| 141 PermissionMessage::kBluetoothDevices); | |
| 142 | |
| 143 for (PermissionMessages::const_iterator i = messages.begin(); | 142 for (PermissionMessages::const_iterator i = messages.begin(); |
| 144 i != messages.end(); ++i) { | 143 i != messages.end(); ++i) { |
| 145 int id = i->id(); | 144 int id = i->id(); |
| 146 // Access to users' devices should provide a single warning message | 145 // Access to users' devices should provide a single warning message |
| 147 // specifying the transport method used; USB, serial and/or Bluetooth. | 146 // specifying the transport method used; USB, serial and/or Bluetooth. |
| 148 if (id == PermissionMessage::kBluetooth || | 147 if (id == PermissionMessage::kBluetooth || |
| 149 id == PermissionMessage::kSerial || | 148 id == PermissionMessage::kSerial || |
| 150 id == PermissionMessage::kUsb) { | 149 id == PermissionMessage::kUsb) { |
| 151 if (ContainsMessages(messages, | 150 if (ContainsMessages(messages, |
| 152 PermissionMessage::kBluetooth, | 151 PermissionMessage::kBluetooth, |
| (...skipping 156 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 309 PermissionMsgSet messages; | 308 PermissionMsgSet messages; |
| 310 for (APIPermissionSet::const_iterator permission_it = | 309 for (APIPermissionSet::const_iterator permission_it = |
| 311 permissions->apis().begin(); | 310 permissions->apis().begin(); |
| 312 permission_it != permissions->apis().end(); ++permission_it) { | 311 permission_it != permissions->apis().end(); ++permission_it) { |
| 313 if (permission_it->HasMessages()) { | 312 if (permission_it->HasMessages()) { |
| 314 PermissionMessages new_messages = permission_it->GetMessages(); | 313 PermissionMessages new_messages = permission_it->GetMessages(); |
| 315 messages.insert(new_messages.begin(), new_messages.end()); | 314 messages.insert(new_messages.begin(), new_messages.end()); |
| 316 } | 315 } |
| 317 } | 316 } |
| 318 | 317 |
| 319 // A special hack: If kFileSystemWriteDirectory would be displayed, hide | |
| 320 // kFileSystemDirectory as the write directory message implies it. | |
| 321 // TODO(sammc): Remove this. See http://crbug.com/284849. | |
| 322 SuppressMessage(messages, | |
| 323 PermissionMessage::kFileSystemWriteDirectory, | |
| 324 PermissionMessage::kFileSystemDirectory); | |
| 325 // A special hack: The warning message for declarativeWebRequest | 318 // A special hack: The warning message for declarativeWebRequest |
| 326 // permissions speaks about blocking parts of pages, which is a | 319 // permissions speaks about blocking parts of pages, which is a |
| 327 // subset of what the "<all_urls>" access allows. Therefore we | 320 // subset of what the "<all_urls>" access allows. Therefore we |
| 328 // display only the "<all_urls>" warning message if both permissions | 321 // display only the "<all_urls>" warning message if both permissions |
| 329 // are required. | 322 // are required. |
| 330 if (permissions->ShouldWarnAllHosts()) { | 323 if (permissions->ShouldWarnAllHosts()) { |
| 331 messages.erase( | 324 messages.erase( |
| 332 PermissionMessage( | 325 PermissionMessage( |
| 333 PermissionMessage::kDeclarativeWebRequest, base::string16())); | 326 PermissionMessage::kDeclarativeWebRequest, base::string16())); |
| 334 } | 327 } |
| (...skipping 116 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 451 std::set<std::string> old_hosts_set( | 444 std::set<std::string> old_hosts_set( |
| 452 permission_message_util::GetDistinctHosts(old_list, false, false)); | 445 permission_message_util::GetDistinctHosts(old_list, false, false)); |
| 453 std::set<std::string> new_hosts_only = | 446 std::set<std::string> new_hosts_only = |
| 454 base::STLSetDifference<std::set<std::string> >(new_hosts_set, | 447 base::STLSetDifference<std::set<std::string> >(new_hosts_set, |
| 455 old_hosts_set); | 448 old_hosts_set); |
| 456 | 449 |
| 457 return !new_hosts_only.empty(); | 450 return !new_hosts_only.empty(); |
| 458 } | 451 } |
| 459 | 452 |
| 460 } // namespace extensions | 453 } // namespace extensions |
| OLD | NEW |