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

Side by Side Diff: chrome/renderer/resources/extensions/utils.js

Issue 12647017: Lazily require types when validating Extensions API calls (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: more fixes Created 7 years, 9 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 unified diff | Download patch | Annotate | Revision Log
OLDNEW
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 var chrome = requireNative('chrome').GetChrome(); 5 var chrome = requireNative('chrome').GetChrome();
6 var schemaRegistry = requireNative('schema_registry');
7 var CHECK = requireNative('logging').CHECK;
6 8
7 function forEach(obj, f, self) { 9 function forEach(obj, f, self) {
8 // For arrays, make sure the indices are numbers not strings - and in that 10 // For arrays, make sure the indices are numbers not strings - and in that
9 // case this method can be more efficient by assuming the array isn't sparse. 11 // case this method can be more efficient by assuming the array isn't sparse.
10 // 12 //
11 // Note: not (instanceof Array) because the array might come from a different 13 // Note: not (instanceof Array) because the array might come from a different
12 // context than our own. 14 // context than our own.
13 if (obj.constructor && obj.constructor.name == 'Array') { 15 if (obj.constructor && obj.constructor.name == 'Array') {
14 for (var i = 0; i < obj.length; i++) 16 for (var i = 0; i < obj.length; i++)
15 f.call(self, i, obj[i]); 17 f.call(self, i, obj[i]);
(...skipping 14 matching lines...) Expand all
30 if (matches.length == 0) { 32 if (matches.length == 0) {
31 return undefined; 33 return undefined;
32 } else if (matches.length == 1) { 34 } else if (matches.length == 1) {
33 return matches[0] 35 return matches[0]
34 } else { 36 } else {
35 throw new Error("Failed lookup of field '" + field + "' with value '" + 37 throw new Error("Failed lookup of field '" + field + "' with value '" +
36 value + "'"); 38 value + "'");
37 } 39 }
38 } 40 }
39 41
40 // Specify |currentApi| if this should return an API for $refs in the current 42 function loadTypeSchema(typeName, defaultSchema) {
41 // namespace. 43 var parts = typeName.split('.');
42 function loadRefDependency(ref, currentApi) { 44 if (parts.length == 1) {
43 var parts = ref.split("."); 45 CHECK(defaultSchema, 'Trying to reference "' + typeName +
44 if (parts.length > 1) 46 '" with neither namespace nor default schema.');
45 return chrome[parts.slice(0, parts.length - 1).join(".")]; 47 var types = defaultSchema.types;
46 else 48 } else {
47 return currentApi; 49 var schemaName = parts.slice(0, parts.length - 1).join('.')
50 var types = schemaRegistry.GetSchema(schemaName).types;
51 }
52 for (var i = 0; i < types.length; ++i) {
53 if (types[i].id == typeName)
54 return types[i];
55 }
56 return null;
48 } 57 }
49 58
50 exports.forEach = forEach; 59 exports.forEach = forEach;
51 exports.loadRefDependency = loadRefDependency; 60 exports.loadTypeSchema = loadTypeSchema;
52 exports.lookup = lookup; 61 exports.lookup = lookup;
OLDNEW
« no previous file with comments | « chrome/renderer/resources/extensions/types_custom_bindings.js ('k') | chrome/renderer/resources/renderer_resources.grd » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698