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

Unified Diff: extensions/renderer/bindings/api_binding.cc

Issue 2950353004: [Extensions Bindings] Check availability of custom API properties (Closed)
Patch Set: fix ifdef Created 3 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: extensions/renderer/bindings/api_binding.cc
diff --git a/extensions/renderer/bindings/api_binding.cc b/extensions/renderer/bindings/api_binding.cc
index e69eccab892f4b353b29b5c5192d380ccfb0b138..53c963b2eff6256337844969ad3611b571710354 100644
--- a/extensions/renderer/bindings/api_binding.cc
+++ b/extensions/renderer/bindings/api_binding.cc
@@ -30,6 +30,21 @@ namespace extensions {
namespace {
+std::string GetPlatformString() {
+#if defined(OS_CHROMEOS)
+ return "chromeos";
jbroman 2017/06/29 15:24:21 I assume you'll look into what's up with protected
Devlin 2017/06/29 21:00:51 Yep! This just puts it more inline with the end r
+#elif defined(OS_LINUX)
+ return "linux";
+#elif defined(OS_MACOSX)
+ return "mac";
+#elif defined(OS_WIN)
+ return "win";
+#else
+ NOTREACHED();
+ return std::string();
+#endif
+}
+
// Returns the name of the enum value for use in JavaScript; JS enum entries use
// SCREAMING_STYLE.
std::string GetJSEnumEntryName(const std::string& original) {
@@ -428,6 +443,28 @@ void APIBinding::DecorateTemplateWithProperties(
continue;
}
+ const base::ListValue* platforms = nullptr;
+ // TODO(devlin): This isn't great. It's bad to have availability primarily
+ // defined in the features files, and then partially defined within the
+ // API specification itself. Additionally, they aren't equivalent
+ // definitions. But given the rarity of property restrictions, and the fact
+ // that they are all limited by platform, it makes more sense to isolate
+ // this check here. If this becomes more common, we should really find a
+ // way of moving these checks to the features files.
+ if (dict->GetList("platforms", &platforms)) {
+ std::string platform_string = GetPlatformString();
+ bool allowed = false;
+ for (const auto& platform : *platforms) {
jbroman 2017/06/29 15:24:20 super-nit: your choice, but I mildly prefer <algor
Devlin 2017/06/29 21:00:51 Oh, forgot about none_of. I had a version that us
+ if (platform.is_string() && platform.GetString() == platform_string) {
+ allowed = true;
+ break;
+ }
+ }
+
+ if (!allowed)
+ continue;
+ }
+
v8::Local<v8::String> v8_key = gin::StringToSymbol(isolate, iter.key());
std::string ref;
if (dict->GetString("$ref", &ref)) {

Powered by Google App Engine
This is Rietveld 408576698