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 55 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
66 int id) { | 66 int id) { |
67 for (PermissionMessages::iterator it = messages.begin(); | 67 for (PermissionMessages::iterator it = messages.begin(); |
68 it != messages.end(); ++it) { | 68 it != messages.end(); ++it) { |
69 if (it->id() == id) | 69 if (it->id() == id) |
70 return it; | 70 return it; |
71 } | 71 } |
72 | 72 |
73 return messages.end(); | 73 return messages.end(); |
74 } | 74 } |
75 | 75 |
76 void SuppressMessage(PermissionMessages& messages, | |
77 int suppressing_message, | |
78 int suppressed_message) { | |
79 // If there is a warning for browsing history, don't show the warning for tabs | |
80 // permission because the texts are very similar. | |
81 PermissionMessages::iterator suppressed = | |
82 FindMessageByID(messages, suppressed_message); | |
83 if (suppressed != messages.end() && | |
84 FindMessageByID(messages, suppressing_message) != messages.end()) { | |
85 messages.erase(suppressed); | |
86 } | |
87 } | |
88 | |
76 } // namespace | 89 } // namespace |
77 | 90 |
78 ChromePermissionMessageProvider::ChromePermissionMessageProvider() { | 91 ChromePermissionMessageProvider::ChromePermissionMessageProvider() { |
79 } | 92 } |
80 | 93 |
81 ChromePermissionMessageProvider::~ChromePermissionMessageProvider() { | 94 ChromePermissionMessageProvider::~ChromePermissionMessageProvider() { |
82 } | 95 } |
83 | 96 |
84 // static | 97 // static |
85 PermissionMessages ChromePermissionMessageProvider::GetPermissionMessages( | 98 PermissionMessages ChromePermissionMessageProvider::GetPermissionMessages( |
(...skipping 13 matching lines...) Expand all Loading... | |
99 std::set<PermissionMessage> api_msgs = GetAPIPermissionMessages(permissions); | 112 std::set<PermissionMessage> api_msgs = GetAPIPermissionMessages(permissions); |
100 std::set<PermissionMessage> manifest_permission_msgs = | 113 std::set<PermissionMessage> manifest_permission_msgs = |
101 GetManifestPermissionMessages(permissions); | 114 GetManifestPermissionMessages(permissions); |
102 messages.insert(messages.end(), host_msgs.begin(), host_msgs.end()); | 115 messages.insert(messages.end(), host_msgs.begin(), host_msgs.end()); |
103 messages.insert(messages.end(), api_msgs.begin(), api_msgs.end()); | 116 messages.insert(messages.end(), api_msgs.begin(), api_msgs.end()); |
104 messages.insert(messages.end(), manifest_permission_msgs.begin(), | 117 messages.insert(messages.end(), manifest_permission_msgs.begin(), |
105 manifest_permission_msgs.end()); | 118 manifest_permission_msgs.end()); |
106 | 119 |
107 // Special hack: bookmarks permission message supersedes override bookmarks UI | 120 // Special hack: bookmarks permission message supersedes override bookmarks UI |
108 // permission message if both permissions are specified. | 121 // permission message if both permissions are specified. |
109 PermissionMessages::iterator override_bookmarks_ui = | 122 PermissionMessages::iterator override_bookmarks_ui = |
Devlin
2014/04/11 23:18:56
This code can be deleted now, yes? (It looks like
Devlin
2014/04/11 23:19:58
Oh, looks like you caught this one while I was rev
| |
110 FindMessageByID(messages, PermissionMessage::kOverrideBookmarksUI); | 123 FindMessageByID(messages, PermissionMessage::kOverrideBookmarksUI); |
111 if (override_bookmarks_ui != messages.end() && | 124 if (override_bookmarks_ui != messages.end() && |
112 FindMessageByID(messages, PermissionMessage::kBookmarks) != | 125 FindMessageByID(messages, PermissionMessage::kBookmarks) != |
113 messages.end()) { | 126 messages.end()) { |
114 messages.erase(override_bookmarks_ui); | 127 messages.erase(override_bookmarks_ui); |
115 } | 128 } |
116 | 129 |
130 SuppressMessage(messages, | |
131 PermissionMessage::kBookmarks, | |
132 PermissionMessage::kOverrideBookmarksUI); | |
133 SuppressMessage(messages, | |
134 PermissionMessage::kBrowsingHistory, | |
Devlin
2014/04/11 23:18:56
I think I'd rather have BrowsingHistory suppressed
meacer
2014/04/11 23:49:53
I actually think the scary one is browsing history
| |
135 PermissionMessage::kTabs); | |
117 return messages; | 136 return messages; |
118 } | 137 } |
119 | 138 |
120 // static | 139 // static |
121 std::vector<base::string16> ChromePermissionMessageProvider::GetWarningMessages( | 140 std::vector<base::string16> ChromePermissionMessageProvider::GetWarningMessages( |
122 const PermissionSet* permissions, | 141 const PermissionSet* permissions, |
123 Manifest::Type extension_type) const { | 142 Manifest::Type extension_type) const { |
124 std::vector<base::string16> message_strings; | 143 std::vector<base::string16> message_strings; |
125 PermissionMessages messages = | 144 PermissionMessages messages = |
126 GetPermissionMessages(permissions, extension_type); | 145 GetPermissionMessages(permissions, extension_type); |
(...skipping 111 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
238 if (permission_it->HasMessages()) { | 257 if (permission_it->HasMessages()) { |
239 PermissionMessages new_messages = permission_it->GetMessages(); | 258 PermissionMessages new_messages = permission_it->GetMessages(); |
240 messages.insert(new_messages.begin(), new_messages.end()); | 259 messages.insert(new_messages.begin(), new_messages.end()); |
241 } | 260 } |
242 } | 261 } |
243 | 262 |
244 // A special hack: If kFileSystemWriteDirectory would be displayed, hide | 263 // A special hack: If kFileSystemWriteDirectory would be displayed, hide |
245 // kFileSystemDirectory and and kFileSystemWrite as the write directory | 264 // kFileSystemDirectory and and kFileSystemWrite as the write directory |
246 // message implies the other two. | 265 // message implies the other two. |
247 // TODO(sammc): Remove this. See http://crbug.com/284849. | 266 // TODO(sammc): Remove this. See http://crbug.com/284849. |
248 std::set<PermissionMessage>::iterator write_directory_message = | 267 std::set<PermissionMessage>::iterator write_directory_message = |
Devlin
2014/04/11 23:18:56
More similar hacks that could use your function.
| |
249 messages.find(PermissionMessage( | 268 messages.find(PermissionMessage( |
250 PermissionMessage::kFileSystemWriteDirectory, base::string16())); | 269 PermissionMessage::kFileSystemWriteDirectory, base::string16())); |
251 if (write_directory_message != messages.end()) { | 270 if (write_directory_message != messages.end()) { |
252 messages.erase( | 271 messages.erase( |
253 PermissionMessage(PermissionMessage::kFileSystemWrite, | 272 PermissionMessage(PermissionMessage::kFileSystemWrite, |
254 base::string16())); | 273 base::string16())); |
255 messages.erase( | 274 messages.erase( |
256 PermissionMessage(PermissionMessage::kFileSystemDirectory, | 275 PermissionMessage(PermissionMessage::kFileSystemDirectory, |
257 base::string16())); | 276 base::string16())); |
258 } | 277 } |
(...skipping 134 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
393 std::set<std::string> old_hosts_set( | 412 std::set<std::string> old_hosts_set( |
394 permission_message_util::GetDistinctHosts(old_list, false, false)); | 413 permission_message_util::GetDistinctHosts(old_list, false, false)); |
395 std::set<std::string> new_hosts_only = | 414 std::set<std::string> new_hosts_only = |
396 base::STLSetDifference<std::set<std::string> >(new_hosts_set, | 415 base::STLSetDifference<std::set<std::string> >(new_hosts_set, |
397 old_hosts_set); | 416 old_hosts_set); |
398 | 417 |
399 return !new_hosts_only.empty(); | 418 return !new_hosts_only.empty(); |
400 } | 419 } |
401 | 420 |
402 } // namespace extensions | 421 } // namespace extensions |
OLD | NEW |