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