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

Unified Diff: extensions/renderer/resources/binding.js

Issue 969063002: [Extensions] Expose enums on extension APIs. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 5 years, 10 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 | « chrome/test/data/extensions/api_test/bindings/api_enums/manifest.json ('k') | no next file » | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: extensions/renderer/resources/binding.js
diff --git a/extensions/renderer/resources/binding.js b/extensions/renderer/resources/binding.js
index b1a3efcaca5002bb03d2918acec145572dd74e81..22ccb7bdc212aa69000fa5d63b5a9d1462b66b56 100644
--- a/extensions/renderer/resources/binding.js
+++ b/extensions/renderer/resources/binding.js
@@ -275,13 +275,35 @@ Binding.prototype = {
mod = mod[name];
}
- // Add types to global schemaValidator, the types we depend on from other
- // namespaces will be added as needed.
if (schema.types) {
$Array.forEach(schema.types, function(t) {
if (!isSchemaNodeSupported(t, platform, manifestVersion))
return;
+
+ // Add types to global schemaValidator; the types we depend on from
+ // other namespaces will be added as needed.
schemaUtils.schemaValidator.addTypes(t);
+
+ // Generate symbols for enums.
+ var enumValues = t['enum'];
+ if (enumValues) {
+ // Type IDs are qualified with the namespace during compilation,
+ // unfortunately, so remove it here.
+ logging.DCHECK(
+ t.id.substr(0, schema.namespace.length) == schema.namespace);
+ // Note: + 1 because it ends in a '.', e.g., 'fooApi.Type'.
+ var id = t.id.substr(schema.namespace.length + 1);
+ mod[id] = {};
+ $Array.forEach(enumValues, function(enumValue) {
+ // Note: enums can be declared either as a list of strings
+ // ['foo', 'bar'] or as a list of objects
+ // [{'name': 'foo'}, {'name': 'bar'}].
+ enumValue =
+ enumValue.hasOwnProperty('name') ? enumValue.name : enumValue;
+ if (enumValue) // Avoid setting any empty enums.
+ mod[id][enumValue] = enumValue;
+ });
+ }
}, this);
}
« no previous file with comments | « chrome/test/data/extensions/api_test/bindings/api_enums/manifest.json ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698