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

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

Issue 2950353004: [Extensions Bindings] Check availability of custom API properties (Closed)
Patch Set: jbroman's 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
« no previous file with comments | « no previous file | extensions/renderer/bindings/api_binding_unittest.cc » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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..d5ee62f9c6a8a96aad011e315b1d69bb75a2cc5e 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";
+#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,23 @@ 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 this_platform = GetPlatformString();
+ auto is_this_platform = [&this_platform](const base::Value& platform) {
+ return platform.is_string() && platform.GetString() == this_platform;
+ };
+ if (std::none_of(platforms->begin(), platforms->end(), is_this_platform))
+ continue;
+ }
+
v8::Local<v8::String> v8_key = gin::StringToSymbol(isolate, iter.key());
std::string ref;
if (dict->GetString("$ref", &ref)) {
« no previous file with comments | « no previous file | extensions/renderer/bindings/api_binding_unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698