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

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

Issue 1903273003: [Extensions] Sprinkle in some more null protos and defineProperty's (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Robs 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
« no previous file with comments | « no previous file | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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');
11 var lastError = require('lastError'); 11 var lastError = require('lastError');
12 var logActivity = requireNative('activityLogger'); 12 var logActivity = requireNative('activityLogger');
13 var logging = requireNative('logging'); 13 var logging = requireNative('logging');
14 var process = requireNative('process'); 14 var process = requireNative('process');
15 var schemaRegistry = requireNative('schema_registry'); 15 var schemaRegistry = requireNative('schema_registry');
16 var schemaUtils = require('schemaUtils'); 16 var schemaUtils = require('schemaUtils');
17 var utils = require('utils'); 17 var utils = require('utils');
18 var sendRequestHandler = require('sendRequest'); 18 var sendRequestHandler = require('sendRequest');
19 19
20 var contextType = process.GetContextType(); 20 var contextType = process.GetContextType();
21 var extensionId = process.GetExtensionId(); 21 var extensionId = process.GetExtensionId();
22 var manifestVersion = process.GetManifestVersion(); 22 var manifestVersion = process.GetManifestVersion();
23 var sendRequest = sendRequestHandler.sendRequest; 23 var sendRequest = sendRequestHandler.sendRequest;
24 24
25 // Stores the name and definition of each API function, with methods to 25 // Stores the name and definition of each API function, with methods to
26 // modify their behaviour (such as a custom way to handle requests to the 26 // modify their behaviour (such as a custom way to handle requests to the
27 // API, a custom callback, etc). 27 // API, a custom callback, etc).
28 function APIFunctions(namespace) { 28 function APIFunctions(namespace) {
29 this.apiFunctions_ = {}; 29 this.apiFunctions_ = { __proto__: null };
30 this.unavailableApiFunctions_ = {}; 30 this.unavailableApiFunctions_ = { __proto__: null };
31 this.namespace = namespace; 31 this.namespace = namespace;
32 } 32 }
33 33
34 APIFunctions.prototype = {
35 __proto__: null,
36 };
37
34 APIFunctions.prototype.register = function(apiName, apiFunction) { 38 APIFunctions.prototype.register = function(apiName, apiFunction) {
35 this.apiFunctions_[apiName] = apiFunction; 39 this.apiFunctions_[apiName] = apiFunction;
36 }; 40 };
37 41
38 // Registers a function as existing but not available, meaning that calls to 42 // Registers a function as existing but not available, meaning that calls to
39 // the set* methods that reference this function should be ignored rather 43 // the set* methods that reference this function should be ignored rather
40 // than throwing Errors. 44 // than throwing Errors.
41 APIFunctions.prototype.registerUnavailable = function(apiName) { 45 APIFunctions.prototype.registerUnavailable = function(apiName) {
42 this.unavailableApiFunctions_[apiName] = apiName; 46 this.unavailableApiFunctions_[apiName] = apiName;
43 }; 47 };
(...skipping 133 matching lines...) Expand 10 before | Expand all | Expand 10 after
177 } 181 }
178 182
179 var platform = getPlatform(); 183 var platform = getPlatform();
180 184
181 function Binding(apiName) { 185 function Binding(apiName) {
182 this.apiName_ = apiName; 186 this.apiName_ = apiName;
183 this.apiFunctions_ = new APIFunctions(apiName); 187 this.apiFunctions_ = new APIFunctions(apiName);
184 this.customHooks_ = []; 188 this.customHooks_ = [];
185 }; 189 };
186 190
187 Binding.create = function(apiName) { 191 $Object.defineProperty(Binding, 'create', {
188 return new Binding(apiName); 192 __proto__: null,
189 }; 193 configurable: false,
194 enumerable: false,
195 value: function(apiName) { return new Binding(apiName); },
196 writable: false,
197 });
190 198
191 Binding.prototype = { 199 Binding.prototype = {
192 // Sneaky workaround for Object.prototype getters/setters - our prototype 200 // Sneaky workaround for Object.prototype getters/setters - our prototype
193 // isn't Object.prototype. SafeBuiltins (e.g. $Object.hasOwnProperty()) 201 // isn't Object.prototype. SafeBuiltins (e.g. $Object.hasOwnProperty())
194 // should still work. 202 // should still work.
195 __proto__: null, 203 __proto__: null,
196 204
197 // Forward-declare properties. 205 // Forward-declare properties.
198 apiName_: undefined, 206 apiName_: undefined,
199 apiFunctions_: undefined, 207 apiFunctions_: undefined,
(...skipping 169 matching lines...) Expand 10 before | Expand all | Expand 10 after
369 if (functionDef.name in mod) { 377 if (functionDef.name in mod) {
370 throw new Error('Function ' + functionDef.name + 378 throw new Error('Function ' + functionDef.name +
371 ' already defined in ' + schema.namespace); 379 ' already defined in ' + schema.namespace);
372 } 380 }
373 381
374 if (!isSchemaNodeSupported(functionDef, platform, manifestVersion)) { 382 if (!isSchemaNodeSupported(functionDef, platform, manifestVersion)) {
375 this.apiFunctions_.registerUnavailable(functionDef.name); 383 this.apiFunctions_.registerUnavailable(functionDef.name);
376 return; 384 return;
377 } 385 }
378 386
379 var apiFunction = {}; 387 var apiFunction = { __proto__: null };
380 apiFunction.definition = functionDef; 388 apiFunction.definition = functionDef;
381 var apiFunctionName = schema.namespace + '.' + functionDef.name; 389 apiFunction.name = schema.namespace + '.' + functionDef.name;
382 apiFunction.name = apiFunctionName;
383 390
384 if (!GetAvailability(apiFunctionName).is_available || 391 if (!GetAvailability(apiFunction.name).is_available ||
385 (checkUnprivileged && !isSchemaAccessAllowed(functionDef))) { 392 (checkUnprivileged && !isSchemaAccessAllowed(functionDef))) {
386 this.apiFunctions_.registerUnavailable(functionDef.name); 393 this.apiFunctions_.registerUnavailable(functionDef.name);
387 return; 394 return;
388 } 395 }
389 396
390 // TODO(aa): It would be best to run this in a unit test, but in order 397 // TODO(aa): It would be best to run this in a unit test, but in order
391 // to do that we would need to better factor this code so that it 398 // to do that we would need to better factor this code so that it
392 // doesn't depend on so much v8::Extension machinery. 399 // doesn't depend on so much v8::Extension machinery.
393 if (logging.DCHECK_IS_ON() && 400 if (logging.DCHECK_IS_ON() &&
394 schemaUtils.isFunctionSignatureAmbiguous(apiFunction.definition)) { 401 schemaUtils.isFunctionSignatureAmbiguous(apiFunction.definition)) {
(...skipping 157 matching lines...) Expand 10 before | Expand all | Expand 10 after
552 availability.message); 559 availability.message);
553 return; 560 return;
554 } 561 }
555 562
556 this.runHooks_(mod, schema); 563 this.runHooks_(mod, schema);
557 return mod; 564 return mod;
558 } 565 }
559 }; 566 };
560 567
561 exports.$set('Binding', Binding); 568 exports.$set('Binding', Binding);
OLDNEW
« no previous file with comments | « no previous file | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698