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

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: absolute path... 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 10bdc7f35ada6b510d1d50fce2a9b8ed189a29b2..ab811688d17260e21b2a07226ffda0f0b2573ee7 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/strings/utf_string_conversions.h"
#include "chrome/common/extensions/api/manifest_types.h"
#include "chrome/common/extensions/extension_manifest_constants.h"
@@ -34,9 +37,18 @@ 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;
}
+} // namespace
+
ExternallyConnectableHandler::ExternallyConnectableHandler() {}
ExternallyConnectableHandler::~ExternallyConnectableHandler() {}
@@ -135,14 +147,14 @@ scoped_ptr<ExternallyConnectableInfo> ExternallyConnectableInfo::FromValue(
}
std::vector<std::string> ids;
- bool matches_all_ids = false;
+ bool all_ids = false;
if (externally_connectable->ids) {
for (std::vector<std::string>::iterator it =
externally_connectable->ids->begin();
it != externally_connectable->ids->end(); ++it) {
if (*it == kAllIds) {
- matches_all_ids = true;
+ all_ids = true;
} else if (Extension::IdIsValid(*it)) {
ids.push_back(*it);
} else {
@@ -154,7 +166,7 @@ scoped_ptr<ExternallyConnectableInfo> ExternallyConnectableInfo::FromValue(
}
return make_scoped_ptr(
- new ExternallyConnectableInfo(matches, ids, matches_all_ids));
+ new ExternallyConnectableInfo(matches, ids, all_ids));
}
ExternallyConnectableInfo::~ExternallyConnectableInfo() {}
@@ -162,7 +174,14 @@ ExternallyConnectableInfo::~ExternallyConnectableInfo() {}
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) {}
+ bool all_ids)
+ : matches(matches), ids(Sorted(ids)), all_ids(all_ids) {}
+
+bool ExternallyConnectableInfo::IdCanConnect(const std::string& id) {
+ if (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