Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(1783)

Unified Diff: chrome/common/extensions/manifest_handlers/externally_connectable.cc

Issue 16174005: Implement externally_connectable! Web pages can now communicate directly with (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: jeffrey review Created 7 years, 6 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
Index: chrome/common/extensions/manifest_handlers/externally_connectable.cc
diff --git a/chrome/common/extensions/manifest_handlers/externally_connectable.cc b/chrome/common/extensions/manifest_handlers/externally_connectable.cc
index 2566b72b1cdd3a6aa8c1d4114e9eb7cef9307386..e4fcb9ae9125b57a560f143576d75ed153a03f6b 100644
--- a/chrome/common/extensions/manifest_handlers/externally_connectable.cc
+++ b/chrome/common/extensions/manifest_handlers/externally_connectable.cc
@@ -4,6 +4,9 @@
#include "chrome/common/extensions/manifest_handlers/externally_connectable.h"
+#include <algorithm>
+
+#include "base/stl_util.h"
#include "base/utf_string_conversions.h"
#include "chrome/common/extensions/api/manifest_types.h"
#include "chrome/common/extensions/extension_manifest_constants.h"
@@ -32,7 +35,16 @@ namespace errors = externally_connectable_errors;
using api::manifest_types::ExternallyConnectable;
namespace {
+
const char kAllIds[] = "*";
+
+template <typename T>
+std::vector<T> Sorted(const std::vector<T>& in) {
+ std::vector<T> out = in;
+ std::sort(out.begin(), out.end());
+ return out;
+}
+
}
ExternallyConnectableHandler::ExternallyConnectableHandler() {}
@@ -157,6 +169,13 @@ ExternallyConnectableInfo::ExternallyConnectableInfo(
const URLPatternSet& matches,
const std::vector<std::string>& ids,
bool matches_all_ids)
- : matches(matches), ids(ids), matches_all_ids(matches_all_ids) {}
+ : matches(matches), ids(Sorted(ids)), matches_all_ids(matches_all_ids) {}
+
+bool ExternallyConnectableInfo::MatchesIdOrAllIds(const std::string& id) {
+ if (matches_all_ids)
+ return true;
+ DCHECK(base::STLIsSorted(ids));
+ return std::binary_search(ids.begin(), ids.end(), id);
+}
} // namespace extensions

Powered by Google App Engine
This is Rietveld 408576698