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

Side by Side Diff: extensions/renderer/resources/binding.js

Issue 1906593002: [Extensions] Finish freezing schema (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 4 years, 8 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
OLDNEW
1 // Copyright 2014 The Chromium Authors. All rights reserved. 1 // Copyright 2014 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 Event = require('event_bindings').Event; 5 var Event = require('event_bindings').Event;
6 var forEach = require('utils').forEach; 6 var forEach = require('utils').forEach;
7 // Note: Beware sneaky getters/setters when using GetAvailbility(). Use safe/raw 7 // Note: Beware sneaky getters/setters when using GetAvailbility(). Use safe/raw
8 // variables as arguments. 8 // variables as arguments.
9 var GetAvailability = requireNative('v8_context').GetAvailability; 9 var GetAvailability = requireNative('v8_context').GetAvailability;
10 var exceptionHandler = require('uncaught_exception_handler'); 10 var exceptionHandler = require('uncaught_exception_handler');
(...skipping 463 matching lines...) Expand 10 before | Expand all | Expand 10 after
474 if (propertyName in m) 474 if (propertyName in m)
475 return; // TODO(kalman): be strict like functions/events somehow. 475 return; // TODO(kalman): be strict like functions/events somehow.
476 if (!isSchemaNodeSupported(propertyDef, platform, manifestVersion)) 476 if (!isSchemaNodeSupported(propertyDef, platform, manifestVersion))
477 return; 477 return;
478 if (!GetAvailability(schema.namespace + "." + 478 if (!GetAvailability(schema.namespace + "." +
479 propertyName).is_available || 479 propertyName).is_available ||
480 (checkUnprivileged && !isSchemaAccessAllowed(propertyDef))) { 480 (checkUnprivileged && !isSchemaAccessAllowed(propertyDef))) {
481 return; 481 return;
482 } 482 }
483 483
484 var value = propertyDef.value; 484 // |value| is eventually added to |m|, the exposed API. Make copies
485 // of everything from the schema. (The schema is also frozen, so as long
486 // as we don't make any modifications, shallow copies are fine.)
487 var value;
488 if ($Array.isArray(propertyDef.value))
489 value = $Array.slice(propertyDef.value);
490 else if (typeof propertyDef.value === 'object')
491 value = $Object.assign({}, propertyDef.value);
492 else
493 value = propertyDef.value;
494
485 if (value) { 495 if (value) {
486 // Values may just have raw types as defined in the JSON, such 496 // Values may just have raw types as defined in the JSON, such
487 // as "WINDOW_ID_NONE": { "value": -1 }. We handle this here. 497 // as "WINDOW_ID_NONE": { "value": -1 }. We handle this here.
488 // TODO(kalman): enforce that things with a "value" property can't 498 // TODO(kalman): enforce that things with a "value" property can't
489 // define their own types. 499 // define their own types.
490 var type = propertyDef.type || typeof(value); 500 var type = propertyDef.type || typeof(value);
491 if (type === 'integer' || type === 'number') { 501 if (type === 'integer' || type === 'number') {
492 value = parseInt(value); 502 value = parseInt(value);
493 } else if (type === 'boolean') { 503 } else if (type === 'boolean') {
494 value = value === 'true'; 504 value = value === 'true';
(...skipping 57 matching lines...) Expand 10 before | Expand all | Expand 10 after
552 availability.message); 562 availability.message);
553 return; 563 return;
554 } 564 }
555 565
556 this.runHooks_(mod, schema); 566 this.runHooks_(mod, schema);
557 return mod; 567 return mod;
558 } 568 }
559 }; 569 };
560 570
561 exports.$set('Binding', Binding); 571 exports.$set('Binding', Binding);
OLDNEW
« no previous file with comments | « chrome/test/data/extensions/api_test/stubs_app/background.js ('k') | extensions/renderer/resources/event.js » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698