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